Merge "Add user aware getPermittedInputMethods in DPM"
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java
index 57b3196..32d1060 100644
--- a/core/java/android/app/admin/DevicePolicyManager.java
+++ b/core/java/android/app/admin/DevicePolicyManager.java
@@ -9279,7 +9279,7 @@
throwIfParentInstance("getPermittedInputMethodsForCurrentUser");
if (mService != null) {
try {
- return mService.getPermittedInputMethodsForCurrentUser();
+ return mService.getPermittedInputMethodsAsUser(UserHandle.myUserId());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
@@ -9288,6 +9288,34 @@
}
/**
+ * 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
* see notifications from the managed profile. By default all packages are permitted by this
diff --git a/core/java/android/app/admin/IDevicePolicyManager.aidl b/core/java/android/app/admin/IDevicePolicyManager.aidl
index cf48594..b9fcdf5 100644
--- a/core/java/android/app/admin/IDevicePolicyManager.aidl
+++ b/core/java/android/app/admin/IDevicePolicyManager.aidl
@@ -243,7 +243,7 @@
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);
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
index efac4d5..be74ed8 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -10399,14 +10399,23 @@
}
@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) {
@@ -10421,7 +10430,7 @@
// 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();