OSDN Git Service

RestrictedLockUtils - introduce check for suspended apps
authorAndrei Stingaceanu <stg@google.com>
Thu, 28 Jan 2016 20:03:41 +0000 (20:03 +0000)
committerAndrei Stingaceanu <stg@google.com>
Thu, 28 Jan 2016 20:56:04 +0000 (20:56 +0000)
Used in Settings for restricting preferences.

Bug: 22776761
Change-Id: I6aad4400981cee00c734060ea3d6cf2641a721d9

packages/SettingsLib/src/com/android/settingslib/RestrictedLockUtils.java

index d3c1364..4454e41 100644 (file)
@@ -21,6 +21,7 @@ import android.app.admin.DevicePolicyManager;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
+import android.content.pm.ApplicationInfo;
 import android.content.pm.IPackageManager;
 import android.content.pm.UserInfo;
 import android.graphics.Color;
@@ -227,6 +228,26 @@ public class RestrictedLockUtils {
     }
 
     /**
+     * Check if an application is suspended.
+     *
+     * @return EnforcedAdmin Object containing the enforced admin component and admin user details,
+     * or {@code null} if the application is not suspended.
+     */
+    public static EnforcedAdmin checkIfApplicationIsSuspended(Context context, String packageName,
+            int userId) {
+        IPackageManager ipm = AppGlobals.getPackageManager();
+        try {
+            ApplicationInfo ai = ipm.getApplicationInfo(packageName, 0, userId);
+            if (ai != null && ((ai.flags & ApplicationInfo.FLAG_SUSPENDED) != 0)) {
+                return getProfileOrDeviceOwnerOnCallingUser(context);
+            }
+        } catch (RemoteException e) {
+            // Nothing to do
+        }
+        return null;
+    }
+
+    /**
      * Check if account management for a specific type of account is disabled by admin.
      * Only a profile or device owner can disable account management. So, we check if account
      * management is disabled and return profile or device owner on the calling user.