Merge "Don't allow an external service to be an A11y service" into tm-dev am: 9172a68c1a

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17394616

Change-Id: I08b21cc2ec4faa6e713afb40ea974f490acd9e5d
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
TreeHugger Robot
2022-03-31 17:54:55 +00:00
committed by Automerger Merge Worker
2 changed files with 20 additions and 0 deletions

View File

@@ -647,6 +647,14 @@ public class AccessibilitySecurityPolicy {
return false;
}
if ((serviceInfo.flags & ServiceInfo.FLAG_EXTERNAL_SERVICE) != 0) {
Slog.w(LOG_TAG, "Skipping accessibility service " + new ComponentName(
serviceInfo.packageName, serviceInfo.name).flattenToShortString()
+ ": the service is the external one and doesn't allow to register as "
+ "an accessibility service ");
return false;
}
int servicePackageUid = serviceInfo.applicationInfo.uid;
if (mAppOpsManager.noteOpNoThrow(AppOpsManager.OPSTR_BIND_ACCESSIBILITY_SERVICE,
servicePackageUid, serviceInfo.packageName, null, null)

View File

@@ -572,6 +572,18 @@ public class AccessibilitySecurityPolicyTest {
serviceInfo.applicationInfo.uid, serviceInfo.packageName, null, null);
}
@Test
public void canRegisterService_isExternalService_returnFalse() {
final ServiceInfo serviceInfo = new ServiceInfo();
serviceInfo.applicationInfo = new ApplicationInfo();
serviceInfo.packageName = PACKAGE_NAME;
serviceInfo.name = AccessibilitySecurityPolicyTest.class.getSimpleName();
serviceInfo.permission = android.Manifest.permission.BIND_ACCESSIBILITY_SERVICE;
serviceInfo.flags |= ServiceInfo.FLAG_EXTERNAL_SERVICE;
assertFalse(mA11ySecurityPolicy.canRegisterService(serviceInfo));
}
@Test
public void checkAccessibilityAccess_shouldCheckAppOps() {
final AccessibilityServiceInfo mockServiceInfo = Mockito.mock(