Merge "Avoid A11y features blocked by IT admin can be allowed to bind at the system level" into udc-dev
This commit is contained in:
@@ -2263,6 +2263,15 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
|
|||||||
}
|
}
|
||||||
if (userState.mEnabledServices.contains(componentName)
|
if (userState.mEnabledServices.contains(componentName)
|
||||||
&& !mUiAutomationManager.suppressingAccessibilityServicesLocked()) {
|
&& !mUiAutomationManager.suppressingAccessibilityServicesLocked()) {
|
||||||
|
// Skip the enabling service disallowed by device admin policy.
|
||||||
|
if (!isAccessibilityTargetAllowed(componentName.getPackageName(),
|
||||||
|
installedService.getResolveInfo().serviceInfo.applicationInfo.uid,
|
||||||
|
userState.mUserId)) {
|
||||||
|
Slog.d(LOG_TAG, "Skipping enabling service disallowed by device admin policy: "
|
||||||
|
+ componentName);
|
||||||
|
disableAccessibilityServiceLocked(componentName, userState.mUserId);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (service == null) {
|
if (service == null) {
|
||||||
service = new AccessibilityServiceConnection(userState, mContext, componentName,
|
service = new AccessibilityServiceConnection(userState, mContext, componentName,
|
||||||
installedService, sIdCounter++, mMainHandler, mLock, mSecurityPolicy,
|
installedService, sIdCounter++, mMainHandler, mLock, mSecurityPolicy,
|
||||||
@@ -3875,32 +3884,29 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@RequiresPermission(anyOf = {
|
|
||||||
android.Manifest.permission.MANAGE_USERS,
|
|
||||||
android.Manifest.permission.QUERY_ADMIN_POLICY})
|
|
||||||
public boolean isAccessibilityTargetAllowed(String packageName, int uid, int userId) {
|
public boolean isAccessibilityTargetAllowed(String packageName, int uid, int userId) {
|
||||||
final DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class);
|
final long identity = Binder.clearCallingIdentity();
|
||||||
final List<String> permittedServices = dpm.getPermittedAccessibilityServices(userId);
|
try {
|
||||||
|
final DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class);
|
||||||
|
final List<String> permittedServices = dpm.getPermittedAccessibilityServices(userId);
|
||||||
|
|
||||||
// permittedServices null means all accessibility services are allowed.
|
// permittedServices null means all accessibility services are allowed.
|
||||||
boolean allowed = permittedServices == null || permittedServices.contains(packageName);
|
boolean allowed = permittedServices == null || permittedServices.contains(packageName);
|
||||||
if (allowed) {
|
if (allowed) {
|
||||||
final AppOpsManager appOps = mContext.getSystemService(AppOpsManager.class);
|
final AppOpsManager appOps = mContext.getSystemService(AppOpsManager.class);
|
||||||
final int mode = appOps.noteOpNoThrow(
|
final int mode = appOps.noteOpNoThrow(
|
||||||
AppOpsManager.OP_ACCESS_RESTRICTED_SETTINGS,
|
AppOpsManager.OP_ACCESS_RESTRICTED_SETTINGS,
|
||||||
uid, packageName, /* attributionTag= */ null, /* message= */ null);
|
uid, packageName, /* attributionTag= */ null, /* message= */ null);
|
||||||
final boolean ecmEnabled = mContext.getResources().getBoolean(
|
final boolean ecmEnabled = mContext.getResources().getBoolean(
|
||||||
R.bool.config_enhancedConfirmationModeEnabled);
|
R.bool.config_enhancedConfirmationModeEnabled);
|
||||||
return !ecmEnabled || mode == AppOpsManager.MODE_ALLOWED;
|
return !ecmEnabled || mode == AppOpsManager.MODE_ALLOWED;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
Binder.restoreCallingIdentity(identity);
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@RequiresPermission(anyOf = {
|
|
||||||
android.Manifest.permission.MANAGE_USERS,
|
|
||||||
android.Manifest.permission.QUERY_ADMIN_POLICY})
|
|
||||||
public boolean sendRestrictedDialogIntent(String packageName, int uid, int userId) {
|
public boolean sendRestrictedDialogIntent(String packageName, int uid, int userId) {
|
||||||
// The accessibility service is allowed. Don't show the restricted dialog.
|
// The accessibility service is allowed. Don't show the restricted dialog.
|
||||||
if (isAccessibilityTargetAllowed(packageName, uid, userId)) {
|
if (isAccessibilityTargetAllowed(packageName, uid, userId)) {
|
||||||
|
|||||||
@@ -11779,6 +11779,20 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
|
|||||||
final CallerIdentity caller = getCallerIdentity();
|
final CallerIdentity caller = getCallerIdentity();
|
||||||
Preconditions.checkCallAuthorization(canManageUsers(caller) || canQueryAdminPolicy(caller));
|
Preconditions.checkCallAuthorization(canManageUsers(caller) || canQueryAdminPolicy(caller));
|
||||||
|
|
||||||
|
// Move AccessibilityManager out of lock to prevent potential deadlock
|
||||||
|
final List<AccessibilityServiceInfo> installedServices;
|
||||||
|
long id = mInjector.binderClearCallingIdentity();
|
||||||
|
try {
|
||||||
|
UserInfo user = getUserInfo(userId);
|
||||||
|
if (user.isManagedProfile()) {
|
||||||
|
userId = user.profileGroupId;
|
||||||
|
}
|
||||||
|
installedServices = withAccessibilityManager(userId,
|
||||||
|
AccessibilityManager::getInstalledAccessibilityServiceList);
|
||||||
|
} finally {
|
||||||
|
mInjector.binderRestoreCallingIdentity(id);
|
||||||
|
}
|
||||||
|
|
||||||
synchronized (getLockObject()) {
|
synchronized (getLockObject()) {
|
||||||
List<String> result = null;
|
List<String> result = null;
|
||||||
// If we have multiple profiles we return the intersection of the
|
// If we have multiple profiles we return the intersection of the
|
||||||
@@ -11805,27 +11819,14 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
|
|||||||
|
|
||||||
// If we have a permitted list add all system accessibility services.
|
// If we have a permitted list add all system accessibility services.
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
long id = mInjector.binderClearCallingIdentity();
|
if (installedServices != null) {
|
||||||
try {
|
for (AccessibilityServiceInfo service : installedServices) {
|
||||||
UserInfo user = getUserInfo(userId);
|
ServiceInfo serviceInfo = service.getResolveInfo().serviceInfo;
|
||||||
if (user.isManagedProfile()) {
|
ApplicationInfo applicationInfo = serviceInfo.applicationInfo;
|
||||||
userId = user.profileGroupId;
|
if ((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
|
||||||
}
|
result.add(serviceInfo.packageName);
|
||||||
final List<AccessibilityServiceInfo> installedServices =
|
|
||||||
withAccessibilityManager(userId,
|
|
||||||
AccessibilityManager::getInstalledAccessibilityServiceList);
|
|
||||||
|
|
||||||
if (installedServices != null) {
|
|
||||||
for (AccessibilityServiceInfo service : installedServices) {
|
|
||||||
ServiceInfo serviceInfo = service.getResolveInfo().serviceInfo;
|
|
||||||
ApplicationInfo applicationInfo = serviceInfo.applicationInfo;
|
|
||||||
if ((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
|
|
||||||
result.add(serviceInfo.packageName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
mInjector.binderRestoreCallingIdentity(id);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user