Fix reset app preferences for work profile apps
In the past, Settings didn't support resetting the disable status of work profile apps, it doesn’t follow the behavior that the reset dialog mentioned. To fix it, we are going to check apps by enabling user profiles and user id. If the work profile is enabled, we will also reset them when users select to reset app preferences. Bug: 187387211 Test: manual Change-Id: I25fd0129335539a23ed2ee0af57fdd9714eddf74
This commit is contained in:
@@ -32,6 +32,8 @@ import android.os.Bundle;
|
|||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
|
import android.os.UserManager;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
|
||||||
@@ -44,6 +46,7 @@ public class ResetAppsHelper implements DialogInterface.OnClickListener,
|
|||||||
DialogInterface.OnDismissListener {
|
DialogInterface.OnDismissListener {
|
||||||
|
|
||||||
private static final String EXTRA_RESET_DIALOG = "resetDialog";
|
private static final String EXTRA_RESET_DIALOG = "resetDialog";
|
||||||
|
private static final String TAG = "ResetAppsHelper";
|
||||||
|
|
||||||
private final PackageManager mPm;
|
private final PackageManager mPm;
|
||||||
private final IPackageManager mIPm;
|
private final IPackageManager mIPm;
|
||||||
@@ -51,6 +54,7 @@ public class ResetAppsHelper implements DialogInterface.OnClickListener,
|
|||||||
private final NetworkPolicyManager mNpm;
|
private final NetworkPolicyManager mNpm;
|
||||||
private final AppOpsManager mAom;
|
private final AppOpsManager mAom;
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
|
private final UserManager mUm;
|
||||||
|
|
||||||
private AlertDialog mResetDialog;
|
private AlertDialog mResetDialog;
|
||||||
|
|
||||||
@@ -62,6 +66,7 @@ public class ResetAppsHelper implements DialogInterface.OnClickListener,
|
|||||||
ServiceManager.getService(Context.NOTIFICATION_SERVICE));
|
ServiceManager.getService(Context.NOTIFICATION_SERVICE));
|
||||||
mNpm = NetworkPolicyManager.from(context);
|
mNpm = NetworkPolicyManager.from(context);
|
||||||
mAom = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
|
mAom = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
|
||||||
|
mUm = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onRestoreInstanceState(Bundle savedInstanceState) {
|
public void onRestoreInstanceState(Bundle savedInstanceState) {
|
||||||
@@ -110,12 +115,13 @@ public class ResetAppsHelper implements DialogInterface.OnClickListener,
|
|||||||
AsyncTask.execute(new Runnable() {
|
AsyncTask.execute(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final List<ApplicationInfo> apps = mPm.getInstalledApplications(
|
|
||||||
PackageManager.GET_DISABLED_COMPONENTS);
|
|
||||||
final List<String> allowList = Arrays.asList(
|
final List<String> allowList = Arrays.asList(
|
||||||
mContext.getResources().getStringArray(
|
mContext.getResources().getStringArray(
|
||||||
R.array.config_skip_reset_apps_package_name));
|
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++) {
|
for (int i = 0; i < apps.size(); i++) {
|
||||||
ApplicationInfo app = apps.get(i);
|
ApplicationInfo app = apps.get(i);
|
||||||
if (allowList.contains(app.packageName)) {
|
if (allowList.contains(app.packageName)) {
|
||||||
@@ -126,11 +132,18 @@ public class ResetAppsHelper implements DialogInterface.OnClickListener,
|
|||||||
} catch (android.os.RemoteException ex) {
|
} catch (android.os.RemoteException ex) {
|
||||||
}
|
}
|
||||||
if (!app.enabled) {
|
if (!app.enabled) {
|
||||||
if (mPm.getApplicationEnabledSetting(app.packageName)
|
try {
|
||||||
|
if (mIPm.getApplicationEnabledSetting(app.packageName, userId)
|
||||||
== PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) {
|
== PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) {
|
||||||
mPm.setApplicationEnabledSetting(app.packageName,
|
mIPm.setApplicationEnabledSetting(app.packageName,
|
||||||
PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user