Add an utility method to get device owner.

Change-Id: I0856d220aa8e4b8d17b83c04b9530dc2d085d94d
This commit is contained in:
Sudheer Shanka
2016-02-03 00:25:50 +00:00
parent 4fb2d18c46
commit 1d0169bd9d

View 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