Merge "Uninstall DO after COMP -> COPE migration." into rvc-dev am: a876116967 am: 4ecde6af45
Change-Id: I9c2688548a9f1c702f777745b72bafcf79c62799
This commit is contained in:
@@ -161,8 +161,11 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.IIntentReceiver;
|
||||
import android.content.IIntentSender;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.IntentSender;
|
||||
import android.content.PermissionChecker;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
@@ -171,6 +174,7 @@ import android.content.pm.CrossProfileAppsInternal;
|
||||
import android.content.pm.IPackageDataObserver;
|
||||
import android.content.pm.IPackageManager;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageInstaller;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.pm.PackageManagerInternal;
|
||||
@@ -2704,6 +2708,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
|
||||
clearDeviceOwnerLocked(doAdmin, doUserId);
|
||||
Slog.i(LOG_TAG, "Removing admin artifacts...");
|
||||
removeAdminArtifacts(doAdminReceiver, doUserId);
|
||||
Slog.i(LOG_TAG, "Uninstalling the DO...");
|
||||
uninstallOrDisablePackage(doAdminComponent.getPackageName(), doUserId);
|
||||
Slog.i(LOG_TAG, "Migration complete.");
|
||||
|
||||
// Note: KeyChain keys are not removed and will remain accessible for the apps that have
|
||||
@@ -2715,6 +2721,47 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
|
||||
.write();
|
||||
}
|
||||
|
||||
private void uninstallOrDisablePackage(String packageName, int userHandle) {
|
||||
final ApplicationInfo appInfo;
|
||||
try {
|
||||
appInfo = mIPackageManager.getApplicationInfo(
|
||||
packageName, MATCH_DIRECT_BOOT_AWARE | MATCH_DIRECT_BOOT_UNAWARE, userHandle);
|
||||
} catch (RemoteException e) {
|
||||
// Shouldn't happen.
|
||||
return;
|
||||
}
|
||||
if (appInfo == null) {
|
||||
Slog.wtf(LOG_TAG, "Failed to get package info for " + packageName);
|
||||
return;
|
||||
}
|
||||
if ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
|
||||
Slog.i(LOG_TAG, String.format(
|
||||
"Package %s is pre-installed, marking disabled until used", packageName));
|
||||
mContext.getPackageManager().setApplicationEnabledSetting(packageName,
|
||||
PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED, 0 /* flags */);
|
||||
return;
|
||||
}
|
||||
|
||||
final IIntentSender.Stub mLocalSender = new IIntentSender.Stub() {
|
||||
@Override
|
||||
public void send(int code, Intent intent, String resolvedType, IBinder whitelistToken,
|
||||
IIntentReceiver finishedReceiver, String requiredPermission, Bundle options) {
|
||||
final int status = intent.getIntExtra(
|
||||
PackageInstaller.EXTRA_STATUS, PackageInstaller.STATUS_FAILURE);
|
||||
if (status == PackageInstaller.STATUS_SUCCESS) {
|
||||
Slog.i(LOG_TAG, String.format(
|
||||
"Package %s uninstalled for user %d", packageName, userHandle));
|
||||
} else {
|
||||
Slog.e(LOG_TAG, String.format(
|
||||
"Failed to uninstall %s; status: %d", packageName, status));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
final PackageInstaller pi = mInjector.getPackageManager(userHandle).getPackageInstaller();
|
||||
pi.uninstall(packageName, 0 /* flags */, new IntentSender((IIntentSender) mLocalSender));
|
||||
}
|
||||
|
||||
private void moveDoPoliciesToProfileParentAdmin(ActiveAdmin doAdmin, ActiveAdmin parentAdmin) {
|
||||
// The following policies can be already controlled via parent instance, skip if so.
|
||||
if (parentAdmin.mPasswordPolicy.quality == PASSWORD_QUALITY_UNSPECIFIED) {
|
||||
|
||||
Reference in New Issue
Block a user