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

Commit 1195083c authored by Peter Visontay's avatar Peter Visontay
Browse files

Log an App Op when an accessibility service is registered.

Bug: 63907873
Test: manually tested that the app op is being logged for TalkBack when it's being registered as an accessibility service.
Change-Id: I10f36a86067950ef57c7afc7bf2f01efff46689c
parent ba5aaf18
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -258,8 +258,10 @@ public class AppOpsManager {
    public static final int OP_CHANGE_WIFI_STATE = 71;
    /** @hide Request package deletion through package installer */
    public static final int OP_REQUEST_DELETE_PACKAGES = 72;
    /** @hide Bind an accessibility service. */
    public static final int OP_BIND_ACCESSIBILITY_SERVICE = 73;
    /** @hide */
    public static final int _NUM_OP = 73;
    public static final int _NUM_OP = 74;

    /** Access to coarse location information. */
    public static final String OPSTR_COARSE_LOCATION = "android:coarse_location";
@@ -503,6 +505,7 @@ public class AppOpsManager {
            OP_RUN_ANY_IN_BACKGROUND,
            OP_CHANGE_WIFI_STATE,
            OP_REQUEST_DELETE_PACKAGES,
            OP_BIND_ACCESSIBILITY_SERVICE,
    };

    /**
@@ -583,6 +586,7 @@ public class AppOpsManager {
            null, // OP_RUN_ANY_IN_BACKGROUND
            null, // OP_CHANGE_WIFI_STATE
            null, // OP_REQUEST_DELETE_PACKAGES
            null, // OP_BIND_ACCESSIBILITY_SERVICE
    };

    /**
@@ -663,6 +667,7 @@ public class AppOpsManager {
            "RUN_ANY_IN_BACKGROUND",
            "CHANGE_WIFI_STATE",
            "REQUEST_DELETE_PACKAGES",
            "BIND_ACCESSIBILITY_SERVICE",
    };

    /**
@@ -743,6 +748,7 @@ public class AppOpsManager {
            null, // no permission for OP_RUN_ANY_IN_BACKGROUND
            Manifest.permission.CHANGE_WIFI_STATE,
            Manifest.permission.REQUEST_DELETE_PACKAGES,
            Manifest.permission.BIND_ACCESSIBILITY_SERVICE,
    };

    /**
@@ -824,6 +830,7 @@ public class AppOpsManager {
            null, // OP_RUN_ANY_IN_BACKGROUND
            null, // OP_CHANGE_WIFI_STATE
            null, // REQUEST_DELETE_PACKAGES
            null, // OP_BIND_ACCESSIBILITY_SERVICE
    };

    /**
@@ -904,6 +911,7 @@ public class AppOpsManager {
            false, // OP_RUN_ANY_IN_BACKGROUND
            false, // OP_CHANGE_WIFI_STATE
            false, // OP_REQUEST_DELETE_PACKAGES
            false, // OP_BIND_ACCESSIBILITY_SERVICE
    };

    /**
@@ -983,6 +991,7 @@ public class AppOpsManager {
            AppOpsManager.MODE_ALLOWED,  // OP_RUN_ANY_IN_BACKGROUND
            AppOpsManager.MODE_ALLOWED,  // OP_CHANGE_WIFI_STATE
            AppOpsManager.MODE_ALLOWED,  // REQUEST_DELETE_PACKAGES
            AppOpsManager.MODE_ALLOWED,  // OP_BIND_ACCESSIBILITY_SERVICE
    };

    /**
@@ -1066,6 +1075,7 @@ public class AppOpsManager {
            false, // OP_RUN_ANY_IN_BACKGROUND
            false, // OP_CHANGE_WIFI_STATE
            false, // OP_REQUEST_DELETE_PACKAGES
            false, // OP_BIND_ACCESSIBILITY_SERVICE
    };

    /**
+29 −6
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ActivityManagerInternal;
import android.app.AlertDialog;
import android.app.AppOpsManager;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManagerInternal;
import android.content.BroadcastReceiver;
@@ -193,6 +194,8 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub

    private final SecurityPolicy mSecurityPolicy;

    private final AppOpsManager mAppOpsManager;

    private final MainHandler mMainHandler;

    private final GlobalActionPerformer mGlobalActionPerformer;
@@ -261,6 +264,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
        mWindowManagerService = LocalServices.getService(WindowManagerInternal.class);
        mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
        mSecurityPolicy = new SecurityPolicy();
        mAppOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
        mMainHandler = new MainHandler(mContext.getMainLooper());
        mGlobalActionPerformer = new GlobalActionPerformer(mContext, mWindowManagerService);

@@ -1223,14 +1227,11 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
        for (int i = 0, count = installedServices.size(); i < count; i++) {
            ResolveInfo resolveInfo = installedServices.get(i);
            ServiceInfo serviceInfo = resolveInfo.serviceInfo;
            if (!android.Manifest.permission.BIND_ACCESSIBILITY_SERVICE.equals(
                    serviceInfo.permission)) {
                Slog.w(LOG_TAG, "Skipping accessibilty service " + new ComponentName(
                        serviceInfo.packageName, serviceInfo.name).flattenToShortString()
                        + ": it does not require the permission "
                        + android.Manifest.permission.BIND_ACCESSIBILITY_SERVICE);

            if (!canRegisterService(serviceInfo)) {
                continue;
            }

            AccessibilityServiceInfo accessibilityServiceInfo;
            try {
                accessibilityServiceInfo = new AccessibilityServiceInfo(resolveInfo, mContext);
@@ -1251,6 +1252,28 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
        return false;
    }

    private boolean canRegisterService(ServiceInfo serviceInfo) {
        if (!android.Manifest.permission.BIND_ACCESSIBILITY_SERVICE.equals(
                serviceInfo.permission)) {
            Slog.w(LOG_TAG, "Skipping accessibility service " + new ComponentName(
                    serviceInfo.packageName, serviceInfo.name).flattenToShortString()
                    + ": it does not require the permission "
                    + android.Manifest.permission.BIND_ACCESSIBILITY_SERVICE);
            return false;
        }

        int servicePackageUid = serviceInfo.applicationInfo.uid;
        if (mAppOpsManager.noteOpNoThrow(AppOpsManager.OP_BIND_ACCESSIBILITY_SERVICE,
                servicePackageUid, serviceInfo.packageName) != AppOpsManager.MODE_ALLOWED) {
            Slog.w(LOG_TAG, "Skipping accessibility service " + new ComponentName(
                    serviceInfo.packageName, serviceInfo.name).flattenToShortString()
                    + ": disallowed by AppOps");
            return false;
        }

        return true;
    }

    private boolean readEnabledAccessibilityServicesLocked(UserState userState) {
        mTempComponentNameSet.clear();
        readComponentNamesFromSettingLocked(Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES,