Make sure profile owner is system app
For cases where an app wants to become the profile owner after setup has completed, make sure that it is a system app. Bug: 17004847 Change-Id: I88249f1ce3bf841ca4d87f33acfd07a7db906332
This commit is contained in:
@@ -32,7 +32,10 @@ import android.content.Context;
|
|||||||
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.ApplicationInfo;
|
||||||
|
import android.content.pm.PackageInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -103,6 +106,7 @@ public class DeviceAdminAdd extends Activity {
|
|||||||
|
|
||||||
mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
|
mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||||
mAppOps = (AppOpsManager)getSystemService(Context.APP_OPS_SERVICE);
|
mAppOps = (AppOpsManager)getSystemService(Context.APP_OPS_SERVICE);
|
||||||
|
PackageManager packageManager = getPackageManager();
|
||||||
|
|
||||||
if ((getIntent().getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
|
if ((getIntent().getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
|
||||||
Log.w(TAG, "Cannot start ADD_DEVICE_ADMIN as a new task");
|
Log.w(TAG, "Cannot start ADD_DEVICE_ADMIN as a new task");
|
||||||
@@ -120,6 +124,8 @@ public class DeviceAdminAdd extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (action != null && action.equals(DevicePolicyManager.ACTION_SET_PROFILE_OWNER)) {
|
if (action != null && action.equals(DevicePolicyManager.ACTION_SET_PROFILE_OWNER)) {
|
||||||
|
setResult(RESULT_CANCELED);
|
||||||
|
setFinishOnTouchOutside(true);
|
||||||
mAddingProfileOwner = true;
|
mAddingProfileOwner = true;
|
||||||
mProfileOwnerName =
|
mProfileOwnerName =
|
||||||
getIntent().getStringExtra(DevicePolicyManager.EXTRA_PROFILE_OWNER_NAME);
|
getIntent().getStringExtra(DevicePolicyManager.EXTRA_PROFILE_OWNER_NAME);
|
||||||
@@ -129,11 +135,23 @@ public class DeviceAdminAdd extends Activity {
|
|||||||
finish();
|
finish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
PackageInfo packageInfo = packageManager.getPackageInfo(callingPackage, 0);
|
||||||
|
if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
|
||||||
|
Log.e(TAG, "Cannot set a non-system app as a profile owner");
|
||||||
|
finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (NameNotFoundException nnfe) {
|
||||||
|
Log.e(TAG, "Cannot find the package " + callingPackage);
|
||||||
|
finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ActivityInfo ai;
|
ActivityInfo ai;
|
||||||
try {
|
try {
|
||||||
ai = getPackageManager().getReceiverInfo(who, PackageManager.GET_META_DATA);
|
ai = packageManager.getReceiverInfo(who, PackageManager.GET_META_DATA);
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
Log.w(TAG, "Unable to retrieve device policy " + who, e);
|
Log.w(TAG, "Unable to retrieve device policy " + who, e);
|
||||||
finish();
|
finish();
|
||||||
@@ -144,7 +162,7 @@ public class DeviceAdminAdd extends Activity {
|
|||||||
// No need to check this when deactivating, because it is safe to deactivate an active
|
// No need to check this when deactivating, because it is safe to deactivate an active
|
||||||
// invalid device admin.
|
// invalid device admin.
|
||||||
if (!mDPM.isAdminActive(who)) {
|
if (!mDPM.isAdminActive(who)) {
|
||||||
List<ResolveInfo> avail = getPackageManager().queryBroadcastReceivers(
|
List<ResolveInfo> avail = packageManager.queryBroadcastReceivers(
|
||||||
new Intent(DeviceAdminReceiver.ACTION_DEVICE_ADMIN_ENABLED),
|
new Intent(DeviceAdminReceiver.ACTION_DEVICE_ADMIN_ENABLED),
|
||||||
PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS);
|
PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS);
|
||||||
int count = avail == null ? 0 : avail.size();
|
int count = avail == null ? 0 : avail.size();
|
||||||
|
Reference in New Issue
Block a user