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

Commit 6b25e726 authored by Svetoslav's avatar Svetoslav
Browse files

Remove a workaround for accessibility managers that works across users.

The system and some processes such as the keyguard and system UI
run across users. Hence, the local accessibility manager should call
into the backing system service with the id of the current user.
For all other processes the local manager uses the current user id.
There was a method that is to be called before the local accessibility
manager has been accessed to initialize it to work across users.
This had to be done for keyguard and system UI.

This change removed the workaround and now the local accessibility
manager determines under the hood which user id to use while calling
into the system. If the local manager is in the system process or
its process has permissions to work across uses, the manager uses
UserHandle.USER_CURRENT, otherwise it uses the user if its process.

Change-Id: I3e97fe98805adca01c1a0127a276828e90926f95
parent 32e18d9f
Loading
Loading
Loading
Loading
+18 −36
Original line number Diff line number Diff line
@@ -16,14 +16,17 @@

package android.view.accessibility;

import android.Manifest;
import android.accessibilityservice.AccessibilityServiceInfo;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.ServiceInfo;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.os.Process;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
@@ -131,29 +134,6 @@ public final class AccessibilityManager {
        }
    }

    /**
     * Creates the singleton AccessibilityManager to be shared across users. This
     * has to be called before the local AccessibilityManager is created to ensure
     * it registers itself in the system correctly.
     * <p>
     * Note: Calling this method requires INTERACT_ACROSS_USERS_FULL or
     *       INTERACT_ACROSS_USERS permission.
     * </p>
     * @param context Context in which this manager operates.
     * @throws IllegalStateException if not called before the local
     *     AccessibilityManager is instantiated.
     *
     * @hide
     */
    public static void createAsSharedAcrossUsers(Context context) {
        synchronized (sInstanceSync) {
            if (sInstance != null) {
                throw new IllegalStateException("AccessibilityManager already created.");
            }
            createSingletonInstance(context, UserHandle.USER_CURRENT);
        }
    }

    /**
     * Get an AccessibilityManager instance (create one if necessary).
     *
@@ -164,23 +144,25 @@ public final class AccessibilityManager {
    public static AccessibilityManager getInstance(Context context) {
        synchronized (sInstanceSync) {
            if (sInstance == null) {
                createSingletonInstance(context, UserHandle.myUserId());
                final int userId;
                if (Binder.getCallingUid() == Process.SYSTEM_UID
                        || context.checkCallingOrSelfPermission(
                                Manifest.permission.INTERACT_ACROSS_USERS)
                                        == PackageManager.PERMISSION_GRANTED
                        || context.checkCallingOrSelfPermission(
                                Manifest.permission.INTERACT_ACROSS_USERS_FULL)
                                        == PackageManager.PERMISSION_GRANTED) {
                    userId = UserHandle.USER_CURRENT;
                } else {
                    userId = UserHandle.myUserId();
                }
        }
        return sInstance;
    }

    /**
     * Creates the singleton instance.
     *
     * @param context Context in which this manager operates.
     * @param userId The user id under which to operate.
     */
    private static void createSingletonInstance(Context context, int userId) {
                IBinder iBinder = ServiceManager.getService(Context.ACCESSIBILITY_SERVICE);
                IAccessibilityManager service = IAccessibilityManager.Stub.asInterface(iBinder);
                sInstance = new AccessibilityManager(context, service, userId);
            }
        }
        return sInstance;
    }

    /**
     * Create an instance.
+0 −10
Original line number Diff line number Diff line
@@ -20,19 +20,13 @@ import java.io.FileDescriptor;
import java.io.PrintWriter;

import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.os.Binder;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Slog;
import android.view.IWindowManager;
import android.view.WindowManagerGlobal;
import android.view.accessibility.AccessibilityManager;

public class SystemUIService extends Service {
    static final String TAG = "SystemUIService";
@@ -69,10 +63,6 @@ public class SystemUIService extends Service {

    @Override
    public void onCreate() {
        // Tell the accessibility layer that this process will
        // run as the current user, i.e. run across users.
        AccessibilityManager.createAsSharedAcrossUsers(this);

        // Pick status bar or system bar.
        IWindowManager wm = WindowManagerGlobal.getWindowManagerService();
        try {