}
/**
+ * @hide
+ * Returns whether the caller is running as an admin user. There can be more than one admin
+ * user.
+ */
+ public boolean isAdminUser() {
+ UserInfo user = getUserInfo(UserHandle.myUserId());
+ return user != null ? user.isAdmin() : false;
+ }
+
+ /**
* Used to check if the user making this call is linked to another user. Linked users may have
* a reduced number of available apps, app restrictions and account restrictions.
* @return whether the user making this call is a linked user
}
}
+ private void enforceAdminUser() {
+ UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
+ final int callingUserId = UserHandle.getCallingUserId();
+ boolean isAdmin;
+ long token = Binder.clearCallingIdentity();
+ try {
+ isAdmin = um.getUserInfo(callingUserId).isAdmin();
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
+ if (!isAdmin) {
+ throw new SecurityException("Only admin users can adopt sd cards");
+ }
+ }
+
/**
* Constructs a new MountService instance
*
@Override
public void partitionPrivate(String diskId) {
enforcePermission(android.Manifest.permission.MOUNT_FORMAT_FILESYSTEMS);
+ enforceAdminUser();
waitForReady();
final CountDownLatch latch = findOrCreateDiskScanLatch(diskId);
@Override
public void partitionMixed(String diskId, int ratio) {
enforcePermission(android.Manifest.permission.MOUNT_FORMAT_FILESYSTEMS);
+ enforceAdminUser();
waitForReady();
final CountDownLatch latch = findOrCreateDiskScanLatch(diskId);