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

Commit 0f8da178 authored by Wilson Wu's avatar Wilson Wu
Browse files

Add user aware getPermittedInputMethods in DPM

In order to make on-screen keyboard settings
support tab layout. It's needed to get the
permitted input method list as work profile
user.

Add this @hide API in DevicePolicyManager which
should only be used in system.

This change only add the API first for further
usage, there is no user-facing changes.

Bug: 197707782
Test: atest com.android.server.devicepolicy.DevicePolicyManagerTest
      atest com.android.cts.devicepolicy.OrgOwnedProfileOwnerTest#testPermittedInputMethods
      atest com.android.cts.devicepolicy.OrgOwnedProfileOwnerTest#testPermittedInputMethodsLogged
Change-Id: I8ee9f523d2b25af7bfea2a138dba601f9678b8aa
parent b9254c2b
Loading
Loading
Loading
Loading
+29 −1
Original line number Diff line number Diff line
@@ -9246,7 +9246,7 @@ public class DevicePolicyManager {
        throwIfParentInstance("getPermittedInputMethodsForCurrentUser");
        if (mService != null) {
            try {
                return mService.getPermittedInputMethodsForCurrentUser();
                return mService.getPermittedInputMethodsAsUser(UserHandle.myUserId());
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
@@ -9254,6 +9254,34 @@ public class DevicePolicyManager {
        return null;
    }
    /**
     * Returns the list of input methods permitted.
     *
     * <p>When this method returns empty list means all input methods are allowed, if a non-empty
     * list is returned it will contain the intersection of the permitted lists for any device or
     * profile owners that apply to this user. It will also include any system input methods.
     *
     * @return List of input method package names.
     * @hide
     */
    @UserHandleAware
    @RequiresPermission(allOf = {
            android.Manifest.permission.INTERACT_ACROSS_USERS_FULL,
            android.Manifest.permission.MANAGE_USERS
            }, conditional = true)
    public @NonNull List<String> getPermittedInputMethods() {
        throwIfParentInstance("getPermittedInputMethods");
        List<String> result = null;
        if (mService != null) {
            try {
                result = mService.getPermittedInputMethodsAsUser(myUserId());
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
        }
        return result != null ? result : Collections.emptyList();
    }
    /**
     * Called by a profile owner of a managed profile to set the packages that are allowed to use
     * a {@link android.service.notification.NotificationListenerService} in the primary user to
+1 −1
Original line number Diff line number Diff line
@@ -243,7 +243,7 @@ interface IDevicePolicyManager {

    boolean setPermittedInputMethods(in ComponentName admin,in List<String> packageList, boolean parent);
    List<String> getPermittedInputMethods(in ComponentName admin, boolean parent);
    List<String> getPermittedInputMethodsForCurrentUser();
    List<String> getPermittedInputMethodsAsUser(int userId);
    boolean isInputMethodPermittedByAdmin(in ComponentName admin, String packageName, int userId, boolean parent);

    boolean setPermittedCrossProfileNotificationListeners(in ComponentName admin, in List<String> packageList);
+12 −3
Original line number Diff line number Diff line
@@ -10352,14 +10352,23 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    }
    @Override
    public List<String> getPermittedInputMethodsForCurrentUser() {
    public @Nullable List<String> getPermittedInputMethodsAsUser(@UserIdInt int userId) {
        final CallerIdentity caller = getCallerIdentity();
        Preconditions.checkCallAuthorization(hasFullCrossUsersPermission(caller, userId));
        Preconditions.checkCallAuthorization(canManageUsers(caller));
        final long callingIdentity = Binder.clearCallingIdentity();
        try {
            return getPermittedInputMethodsUnchecked(userId);
        } finally {
            Binder.restoreCallingIdentity(callingIdentity);
        }
    }
    private @Nullable List<String> getPermittedInputMethodsUnchecked(@UserIdInt int userId) {
        synchronized (getLockObject()) {
            List<String> result = null;
            // Only device or profile owners can have permitted lists set.
            List<ActiveAdmin> admins = getActiveAdminsForAffectedUserLocked(caller.getUserId());
            List<ActiveAdmin> admins = getActiveAdminsForAffectedUserLocked(userId);
            for (ActiveAdmin admin: admins) {
                List<String> fromAdmin = admin.permittedInputMethods;
                if (fromAdmin != null) {
@@ -10374,7 +10383,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
            // If we have a permitted list add all system input methods.
            if (result != null) {
                List<InputMethodInfo> imes = InputMethodManagerInternal
                        .get().getInputMethodListAsUser(caller.getUserId());
                        .get().getInputMethodListAsUser(userId);
                if (imes != null) {
                    for (InputMethodInfo ime : imes) {
                        ServiceInfo serviceInfo = ime.getServiceInfo();