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
This commit is contained in:
Hani Kazmi
2023-11-01 16:16:10 +00:00
parent 291e6043bf
commit ded1cd59c9
3 changed files with 52 additions and 2 deletions

View File

@@ -234,6 +234,32 @@ public class RestrictedPreferenceHelper {
// permittedServices null means all accessibility services are allowed. // permittedServices null means all accessibility services are allowed.
boolean serviceAllowed = permittedServices == null || permittedServices.contains( boolean serviceAllowed = permittedServices == null || permittedServices.contains(
preference.getPackageName()); 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; boolean appOpsAllowed;
if (serviceAllowed) { if (serviceAllowed) {
try { try {

View File

@@ -41,6 +41,8 @@ public class ApprovalPreferenceController extends BasePreferenceController {
private PreferenceFragmentCompat mParent; private PreferenceFragmentCompat mParent;
private NotificationManager mNm; private NotificationManager mNm;
private PackageManager mPm; private PackageManager mPm;
// The appOp representing this preference
private String mAppOpStr;
public ApprovalPreferenceController(Context context, String key) { public ApprovalPreferenceController(Context context, String key) {
super(context, key); super(context, key);
@@ -71,6 +73,14 @@ public class ApprovalPreferenceController extends BasePreferenceController {
return this; return this;
} }
/**
* Set the associated appOp for the Setting
*/
public ApprovalPreferenceController setAppOpStr(String appOpStr) {
mAppOpStr = appOpStr;
return this;
}
@Override @Override
public int getAvailabilityStatus() { public int getAvailabilityStatus() {
return AVAILABLE; return AVAILABLE;
@@ -107,8 +117,20 @@ public class ApprovalPreferenceController extends BasePreferenceController {
return false; return false;
} }
}); });
preference.updateState(
mCn.getPackageName(), mPkgInfo.applicationInfo.uid, isAllowedCn, isEnabled); 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) { public void disable(final ComponentName cn) {

View File

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