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

Commit ded1cd59 authored by Hani Kazmi's avatar Hani Kazmi
Browse files

Update existing ECM settings to use new infrastructure

1. Update Notification Listener and A11y settings to call
   RestrictedLockUtilsInternal rather than checking appOp themselves

2. Rename ecm related methods to include Ecm rather than AppOp -
   implementation details are being moved to permissions module and may
   change.

Bug: 297372999
Test: Manually tested on device. Automaated tests to follow
Change-Id: Ie3e16b502993b21a7e34eab0d661f98814b3cfd5
parent 291e6043
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -234,6 +234,32 @@ public class RestrictedPreferenceHelper {
        // permittedServices null means all accessibility services are allowed.
        boolean serviceAllowed = permittedServices == null || permittedServices.contains(
                preference.getPackageName());

        if (android.security.Flags.extendEcmToAllSettings()) {
            preference.checkEcmRestrictionAndSetDisabled(
                    AppOpsManager.OPSTR_BIND_ACCESSIBILITY_SERVICE,
                    preference.getPackageName(), preference.getUid());
            if (preference.isDisabledByEcm()) {
                serviceAllowed = false;
            }

            if (serviceAllowed || serviceEnabled) {
                preference.setEnabled(true);
            } else {
                // Disable accessibility service that are not permitted.
                final RestrictedLockUtils.EnforcedAdmin admin =
                        RestrictedLockUtilsInternal.checkIfAccessibilityServiceDisallowed(
                                mContext, preference.getPackageName(), UserHandle.myUserId());

                if (admin != null) {
                    preference.setDisabledByAdmin(admin);
                } else if (!preference.isDisabledByEcm()) {
                    preference.setEnabled(false);
                }
            }
            return;
        }

        boolean appOpsAllowed;
        if (serviceAllowed) {
            try {
+24 −2
Original line number Diff line number Diff line
@@ -41,6 +41,8 @@ public class ApprovalPreferenceController extends BasePreferenceController {
    private PreferenceFragmentCompat mParent;
    private NotificationManager mNm;
    private PackageManager mPm;
    // The appOp representing this preference
    private String mAppOpStr;

    public ApprovalPreferenceController(Context context, String key) {
        super(context, key);
@@ -71,6 +73,14 @@ public class ApprovalPreferenceController extends BasePreferenceController {
        return this;
    }

    /**
     * Set the associated appOp for the Setting
     */
    public ApprovalPreferenceController setAppOpStr(String appOpStr) {
        mAppOpStr = appOpStr;
        return this;
    }

    @Override
    public int getAvailabilityStatus() {
        return AVAILABLE;
@@ -107,9 +117,21 @@ public class ApprovalPreferenceController extends BasePreferenceController {
                return false;
            }
        });

        if (android.security.Flags.extendEcmToAllSettings()) {
            if (!isAllowedCn && !isEnabled) {
                preference.setEnabled(false);
            } else if (isEnabled) {
                preference.setEnabled(true);
            } else {
                preference.checkEcmRestrictionAndSetDisabled(mAppOpStr,
                        mCn.getPackageName(), mPkgInfo.applicationInfo.uid);
            }
        } else {
            preference.updateState(
                    mCn.getPackageName(), mPkgInfo.applicationInfo.uid, isAllowedCn, isEnabled);
        }
    }

    public void disable(final ComponentName cn) {
        logSpecialPermissionChange(true, cn.getPackageName());
+2 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static com.android.settings.applications.AppInfoBase.ARG_PACKAGE_NAME;

import android.Manifest;
import android.app.AppOpsManager;
import android.app.NotificationManager;
import android.app.settings.SettingsEnums;
import android.companion.ICompanionDeviceManager;
@@ -102,6 +103,7 @@ public class NotificationAccessDetails extends DashboardFragment {
                .setCn(mComponentName)
                .setNm(context.getSystemService(NotificationManager.class))
                .setPm(mPm)
                .setAppOpStr(AppOpsManager.OPSTR_ACCESS_NOTIFICATIONS)
                .setParent(this);
        use(HeaderPreferenceController.class)
                .setFragment(this)