Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6ca32df6 authored by Julia Reynolds's avatar Julia Reynolds Committed by Android (Google) Code Review
Browse files

Merge "Only show enhanced options for migrated apps" into sc-dev

parents c103d6a4 cc907ead
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -9030,6 +9030,7 @@
    <string name="notif_listener_excluded_app_title">See all apps</string>
    <string name="notif_listener_excluded_app_summary">Change notification settings for each app that can send notifications</string>
    <string name="notif_listener_excluded_app_screen_title">Apps shown on device</string>
    <string name="notif_listener_not_migrated">This app doesn\u2019t support enhanced settings</string>
    <!-- Title for managing VR (virtual reality) helper services. [CHAR LIMIT=50] -->
    <string name="vr_listeners_title">VR helper services</string>
+8 −1
Original line number Diff line number Diff line
@@ -62,6 +62,13 @@
        android:summary="@string/notif_listener_excluded_app_summary"
        android:fragment="com.android.settings.applications.specialaccess.notificationaccess.BridgedAppsSettings"
        settings:searchable="false"
        settings:controller="com.android.settings.applications.specialaccess.notificationaccess.BridgedAppsPreferenceController" />
        settings:controller="com.android.settings.applications.specialaccess.notificationaccess.BridgedAppsLinkPreferenceController" />

    <com.android.settingslib.widget.FooterPreference
        android:key="notif_listener_not_migrated"
        android:title="@string/notif_listener_not_migrated"
        settings:controller="com.android.settings.applications.specialaccess.notificationaccess.PreUpgradePreferenceController"
        android:selectable="false"
        settings:searchable="false"/>

</PreferenceScreen>
 No newline at end of file
+72 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the
 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */
package com.android.settings.applications.specialaccess.notificationaccess;

import android.content.ComponentName;
import android.content.Context;
import android.os.Build;
import android.service.notification.NotificationListenerFilter;

import com.android.settings.core.BasePreferenceController;
import com.android.settings.notification.NotificationBackend;


public class BridgedAppsLinkPreferenceController extends BasePreferenceController {

    private ComponentName mCn;
    private int mUserId;
    private NotificationBackend mNm;
    private NotificationListenerFilter mNlf;
    private int mTargetSdk;

    public BridgedAppsLinkPreferenceController(Context context, String key) {
        super(context, key);
    }


    public BridgedAppsLinkPreferenceController setCn(ComponentName cn) {
        mCn = cn;
        return this;
    }

    public BridgedAppsLinkPreferenceController setUserId(int userId) {
        mUserId = userId;
        return this;
    }

    public BridgedAppsLinkPreferenceController setNm(NotificationBackend nm) {
        mNm = nm;
        return this;
    }

    public BridgedAppsLinkPreferenceController setTargetSdk(int targetSdk) {
        mTargetSdk = targetSdk;
        return this;
    }

    @Override
    public int getAvailabilityStatus() {
        if (mNm.isNotificationListenerAccessGranted(mCn)) {
            if (mTargetSdk > Build.VERSION_CODES.S) {
                return AVAILABLE;
            }

            mNlf = mNm.getListenerFilter(mCn, mUserId);
            if (!mNlf.areAllTypesAllowed() || !mNlf.getDisallowedPackages().isEmpty()) {
                return AVAILABLE;
            }
        }
        return DISABLED_DEPENDENT_SETTING;
    }
}
+0 −11
Original line number Diff line number Diff line
@@ -16,14 +16,11 @@ package com.android.settings.applications.specialaccess.notificationaccess;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.VersionedPackage;
import android.os.UserHandle;
import android.service.notification.NotificationListenerFilter;

import androidx.annotation.VisibleForTesting;
import androidx.preference.CheckBoxPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;

import com.android.settings.applications.AppStateBaseBridge;
import com.android.settings.core.BasePreferenceController;
@@ -126,9 +123,6 @@ public class BridgedAppsPreferenceController extends BasePreferenceController im
        final int N = apps.size();
        for (int i = 0; i < N; i++) {
            final AppEntry entry = apps.get(i);
            if (!shouldAddPreference(entry)) {
                continue;
            }
            final String prefKey = entry.info.packageName + "|" + entry.info.uid;
            appsKeySet.add(prefKey);
            CheckBoxPreference preference = mScreen.findPreference(prefKey);
@@ -211,9 +205,4 @@ public class BridgedAppsPreferenceController extends BasePreferenceController im
            }
        }
    }

    @VisibleForTesting
    static boolean shouldAddPreference(AppEntry app) {
        return app != null && UserHandle.isApp(app.info.uid);
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ public class BridgedAppsSettings extends DashboardFragment {
            case MENU_SHOW_SYSTEM:
                mShowSystem = !mShowSystem;
                item.setTitle(mShowSystem ? R.string.menu_hide_system : R.string.menu_show_system);
                mFilter = mShowSystem ? ApplicationsState.FILTER_ALL_ENABLED
                mFilter = mShowSystem ? ApplicationsState.FILTER_NOT_HIDE
                        : ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER;

                use(BridgedAppsPreferenceController.class).setFilter(mFilter).rebuild();
Loading