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
This commit is contained in:
Pavel Grafov
2022-02-08 14:18:41 +00:00
parent 7ad0982839
commit 6125331ef2
2 changed files with 18 additions and 15 deletions

View File

@@ -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;
}
/**

View File

@@ -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);