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

Commit 6125331e authored by Pavel Grafov's avatar Pavel Grafov
Browse files

Make distinction between null and empty IM list.

* null means no policy is enfrced, any IM is allowed.
* empty means no IMs is allowed except system IMs.

+ also use the correct user in InputMethodPreferences when checking for
  enforcing admin

Bug: 211063191
Test: manual, CtsVerifier/BYOD managed provisioning/Policy transparency
Change-Id: Ie8bf6de2d53c80b0f2f91e7e96479764834d55ef
parent 7ad09828
Loading
Loading
Loading
Loading
+16 −13
Original line number Diff line number Diff line
@@ -9592,9 +9592,9 @@ public class DevicePolicyManager {
     * service. When zero or more packages have been added, accessibility services that are not in
     * the list and not part of the system can not be enabled by the user.
     * <p>
     * Calling with a null value for the list disables the restriction so that all services can be
     * used, calling with an empty list only allows the built-in system services. Any non-system
     * accessibility service that's currently enabled must be included in the list.
     * Calling with a {@code null} value for the list disables the restriction so that all services
     * can be used, calling with an empty list only allows the built-in system services. Any
     * non-system accessibility service that's currently enabled must be included in the list.
     * <p>
     * System accessibility services are always available to the user and this method can't
     * disable them.
@@ -9620,8 +9620,8 @@ public class DevicePolicyManager {
    /**
     * Returns the list of permitted accessibility services set by this device or profile owner.
     * <p>
     * An empty list means no accessibility services except system services are allowed. Null means
     * all accessibility services are allowed.
     * An empty list means no accessibility services except system services are allowed.
     * {@code null} means all accessibility services are allowed.
     *
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
     * @return List of accessiblity service package names.
@@ -9666,7 +9666,7 @@ public class DevicePolicyManager {
     * Returns the list of accessibility services permitted by the device or profiles
     * owners of this user.
     *
     * <p>Null means all accessibility services are allowed, if a non-null list is returned
     * <p>{@code null} means all accessibility services are allowed, if a non-null 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 accessibility services.
     *
@@ -9812,6 +9812,8 @@ public class DevicePolicyManager {
     *
     * @return List of input method package names.
     * @hide
     *
     * @see #setPermittedAccessibilityServices(ComponentName, List)
     */
    @SystemApi
    @RequiresPermission(anyOf = {
@@ -9832,29 +9834,30 @@ public class DevicePolicyManager {
    /**
     * 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.
     * <p>{@code null} means all input methods are allowed, if a non-null 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
     *
     * @see #setPermittedAccessibilityServices(ComponentName, List)
     */
    @UserHandleAware
    @RequiresPermission(allOf = {
            android.Manifest.permission.INTERACT_ACROSS_USERS_FULL,
            android.Manifest.permission.MANAGE_USERS
            }, conditional = true)
    public @NonNull List<String> getPermittedInputMethods() {
    public @Nullable List<String> getPermittedInputMethods() {
        throwIfParentInstance("getPermittedInputMethods");
        List<String> result = null;
        if (mService != null) {
            try {
                result = mService.getPermittedInputMethodsAsUser(myUserId());
                return mService.getPermittedInputMethodsAsUser(myUserId());
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
        }
        return result != null ? result : Collections.emptyList();
        return null;
    }
    /**
+2 −2
Original line number Diff line number Diff line
@@ -226,8 +226,8 @@ public class InputMethodPreference extends PrimarySwitchPreference
            setSwitchEnabled(false);
        } else if (!mIsAllowedByOrganization) {
            EnforcedAdmin admin =
                    RestrictedLockUtilsInternal.checkIfInputMethodDisallowed(getContext(),
                            mImi.getPackageName(), UserHandle.myUserId());
                    RestrictedLockUtilsInternal.checkIfInputMethodDisallowed(
                            getContext(), mImi.getPackageName(), mUserId);
            setDisabledByAdmin(admin);
        } else {
            setEnabled(true);