Merge "Check for MANAGE_DEVICE_ADMINS permission instead of uids."
This commit is contained in:
committed by
Android (Google) Code Review
commit
737dab827e
@@ -26,6 +26,7 @@ import android.content.ComponentName;
|
|||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
@@ -52,16 +53,10 @@ public class ShowAdminSupportDetailsDialog extends Activity
|
|||||||
int userId = UserHandle.myUserId();
|
int userId = UserHandle.myUserId();
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
if (intent != null) {
|
if (intent != null) {
|
||||||
IActivityManager am = ActivityManagerNative.getDefault();
|
// Only allow apps with MANAGE_DEVICE_ADMINS permission to specify admin and user.
|
||||||
try {
|
if (checkIfCallerHasPermission(android.Manifest.permission.MANAGE_DEVICE_ADMINS)) {
|
||||||
int uid = am.getLaunchedFromUid(getActivityToken());
|
admin = intent.getParcelableExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN);
|
||||||
// Only allow system to specify admin and user.
|
userId = intent.getIntExtra(Intent.EXTRA_USER_ID, UserHandle.myUserId());
|
||||||
if (UserHandle.isSameApp(uid, android.os.Process.myUid())) {
|
|
||||||
admin = intent.getParcelableExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN);
|
|
||||||
userId = intent.getIntExtra(Intent.EXTRA_USER_ID, UserHandle.myUserId());
|
|
||||||
}
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "Could not talk to activity manager.", e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,6 +71,18 @@ public class ShowAdminSupportDetailsDialog extends Activity
|
|||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean checkIfCallerHasPermission(String permission) {
|
||||||
|
IActivityManager am = ActivityManagerNative.getDefault();
|
||||||
|
try {
|
||||||
|
final int uid = am.getLaunchedFromUid(getActivityToken());
|
||||||
|
return AppGlobals.getPackageManager().checkUidPermission(permission, uid)
|
||||||
|
== PackageManager.PERMISSION_GRANTED;
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.e(TAG, "Could not talk to activity manager.", e);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private void setAdminSupportDetails(View root, final ComponentName admin, final int userId) {
|
private void setAdminSupportDetails(View root, final ComponentName admin, final int userId) {
|
||||||
if (admin != null) {
|
if (admin != null) {
|
||||||
CharSequence supportMessage = mDpm.getShortSupportMessageForUser(admin, userId);
|
CharSequence supportMessage = mDpm.getShortSupportMessageForUser(admin, userId);
|
||||||
|
Reference in New Issue
Block a user