Merge "Fix reset app preferences for work profile apps" into tm-dev am: 51204e3deb

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/18234983

Change-Id: I4875344328bc68d8ca069ed15f71aa8ce4abef8f
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Yanting Yang
2022-05-10 20:33:30 +00:00
committed by Automerger Merge Worker

View File

@@ -32,6 +32,8 @@ import android.os.Bundle;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserHandle;
import android.os.UserManager;
import android.util.Log;
import androidx.appcompat.app.AlertDialog;
@@ -44,6 +46,7 @@ public class ResetAppsHelper implements DialogInterface.OnClickListener,
DialogInterface.OnDismissListener {
private static final String EXTRA_RESET_DIALOG = "resetDialog";
private static final String TAG = "ResetAppsHelper";
private final PackageManager mPm;
private final IPackageManager mIPm;
@@ -51,6 +54,7 @@ public class ResetAppsHelper implements DialogInterface.OnClickListener,
private final NetworkPolicyManager mNpm;
private final AppOpsManager mAom;
private final Context mContext;
private final UserManager mUm;
private AlertDialog mResetDialog;
@@ -62,6 +66,7 @@ public class ResetAppsHelper implements DialogInterface.OnClickListener,
ServiceManager.getService(Context.NOTIFICATION_SERVICE));
mNpm = NetworkPolicyManager.from(context);
mAom = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
mUm = (UserManager) context.getSystemService(Context.USER_SERVICE);
}
public void onRestoreInstanceState(Bundle savedInstanceState) {
@@ -110,12 +115,13 @@ public class ResetAppsHelper implements DialogInterface.OnClickListener,
AsyncTask.execute(new Runnable() {
@Override
public void run() {
final List<ApplicationInfo> apps = mPm.getInstalledApplications(
PackageManager.GET_DISABLED_COMPONENTS);
final List<String> allowList = Arrays.asList(
mContext.getResources().getStringArray(
R.array.config_skip_reset_apps_package_name));
for (UserHandle userHandle : mUm.getEnabledProfiles()) {
final int userId = userHandle.getIdentifier();
final List<ApplicationInfo> apps = mPm.getInstalledApplicationsAsUser(
PackageManager.GET_DISABLED_COMPONENTS, userId);
for (int i = 0; i < apps.size(); i++) {
ApplicationInfo app = apps.get(i);
if (allowList.contains(app.packageName)) {
@@ -126,11 +132,18 @@ public class ResetAppsHelper implements DialogInterface.OnClickListener,
} catch (android.os.RemoteException ex) {
}
if (!app.enabled) {
if (mPm.getApplicationEnabledSetting(app.packageName)
try {
if (mIPm.getApplicationEnabledSetting(app.packageName, userId)
== PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) {
mPm.setApplicationEnabledSetting(app.packageName,
mIPm.setApplicationEnabledSetting(app.packageName,
PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,
PackageManager.DONT_KILL_APP);
PackageManager.DONT_KILL_APP,
userId,
mContext.getPackageName());
}
} catch (RemoteException e) {
Log.e(TAG, "Error during reset disabled apps.", e);
}
}
}
}