OSDN Git Service

Add an utility method to get device owner.
authorSudheer Shanka <sudheersai@google.com>
Wed, 3 Feb 2016 00:25:50 +0000 (00:25 +0000)
committerSudheer Shanka <sudheersai@google.com>
Wed, 3 Feb 2016 00:25:50 +0000 (00:25 +0000)
Change-Id: I0856d220aa8e4b8d17b83c04b9530dc2d085d94d

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

index 85cc3e4..78c530c 100644 (file)
@@ -427,6 +427,19 @@ public class RestrictedLockUtils {
         return null;
     }
 
+    public static EnforcedAdmin getDeviceOwner(Context context) {
+        final DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(
+                Context.DEVICE_POLICY_SERVICE);
+        if (dpm == null) {
+            return null;
+        }
+        ComponentName adminComponent = dpm.getDeviceOwnerComponentOnAnyUser();
+        if (adminComponent != null) {
+            return new EnforcedAdmin(adminComponent, dpm.getDeviceOwnerUserId());
+        }
+        return null;
+    }
+
     /**
      * Set the menu item as disabled by admin by adding a restricted padlock at the end of the
      * text and set the click listener which will send an intent to show the admin support details