Merge "Don't allow non-admins to adopt sd card for internal storage" into mnc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
2b64ec470c
@@ -571,6 +571,16 @@ public class UserManager {
|
||||
return UserHandle.myUserId() == UserHandle.USER_OWNER;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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.
|
||||
|
||||
@@ -1202,6 +1202,21 @@ class MountService extends IMountService.Stub
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
*
|
||||
@@ -1537,6 +1552,7 @@ class MountService extends IMountService.Stub
|
||||
@Override
|
||||
public void partitionPrivate(String diskId) {
|
||||
enforcePermission(android.Manifest.permission.MOUNT_FORMAT_FILESYSTEMS);
|
||||
enforceAdminUser();
|
||||
waitForReady();
|
||||
|
||||
final CountDownLatch latch = findOrCreateDiskScanLatch(diskId);
|
||||
@@ -1551,6 +1567,7 @@ class MountService extends IMountService.Stub
|
||||
@Override
|
||||
public void partitionMixed(String diskId, int ratio) {
|
||||
enforcePermission(android.Manifest.permission.MOUNT_FORMAT_FILESYSTEMS);
|
||||
enforceAdminUser();
|
||||
waitForReady();
|
||||
|
||||
final CountDownLatch latch = findOrCreateDiskScanLatch(diskId);
|
||||
|
||||
Reference in New Issue
Block a user