Merge "Update existing ECM settings to use new infrastructure" into main

This commit is contained in:
Hani Kazmi
2023-12-12 12:01:17 +00:00
committed by Android (Google) Code Review
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.
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 {

View File

@@ -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,8 +117,20 @@ public class ApprovalPreferenceController extends BasePreferenceController {
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) {

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 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)