diff --git a/src/com/android/settings/bugreporthandler/BugReportHandlerUtil.java b/src/com/android/settings/bugreporthandler/BugReportHandlerUtil.java index 266a44929ea..aefa3b7ecae 100644 --- a/src/com/android/settings/bugreporthandler/BugReportHandlerUtil.java +++ b/src/com/android/settings/bugreporthandler/BugReportHandlerUtil.java @@ -78,7 +78,7 @@ public class BugReportHandlerUtil { boolean needToResetOutdatedSettings = false; if (!isBugreportAllowlistedApp(handlerApp)) { handlerApp = getDefaultBugReportHandlerApp(context); - handlerUser = UserHandle.USER_SYSTEM; + handlerUser = context.getUserId(); } else if (getBugReportHandlerAppReceivers(context, handlerApp, handlerUser).isEmpty()) { // It looks like the settings are outdated, need to reset outdated settings. // @@ -89,7 +89,7 @@ public class BugReportHandlerUtil { // The chosen bugreport handler app is outdated because the profile is removed, // so need to reset outdated settings handlerApp = getDefaultBugReportHandlerApp(context); - handlerUser = UserHandle.USER_SYSTEM; + handlerUser = context.getUserId(); needToResetOutdatedSettings = true; } @@ -99,7 +99,7 @@ public class BugReportHandlerUtil { // bugreport, so change to let shell to handle a bugreport and need to reset // settings. handlerApp = SHELL_APP_PACKAGE; - handlerUser = UserHandle.USER_SYSTEM; + handlerUser = context.getUserId(); needToResetOutdatedSettings = true; } @@ -112,13 +112,13 @@ public class BugReportHandlerUtil { private String getCustomBugReportHandlerApp(Context context) { // Get the package of custom bugreport handler app - return Settings.Global.getString(context.getContentResolver(), - Settings.Global.CUSTOM_BUGREPORT_HANDLER_APP); + return Settings.Secure.getString(context.getContentResolver(), + Settings.Secure.CUSTOM_BUGREPORT_HANDLER_APP); } private int getCustomBugReportHandlerUser(Context context) { - return Settings.Global.getInt(context.getContentResolver(), - Settings.Global.CUSTOM_BUGREPORT_HANDLER_USER, UserHandle.USER_NULL); + return Settings.Secure.getInt(context.getContentResolver(), + Settings.Secure.CUSTOM_BUGREPORT_HANDLER_USER, UserHandle.USER_NULL); } private String getDefaultBugReportHandlerApp(Context context) { @@ -164,22 +164,24 @@ public class BugReportHandlerUtil { return validBugReportHandlerApplicationInfos; } - // Add "Shell with system user" as System default preference on top of screen + int currentUser = UserHandle.getCallingUserId(); + + // Add "Shell" as user's default preference on top of screen if (bugreportAllowlistedPackages.contains(SHELL_APP_PACKAGE) && !getBugReportHandlerAppReceivers(context, SHELL_APP_PACKAGE, - UserHandle.USER_SYSTEM).isEmpty()) { + currentUser).isEmpty()) { try { validBugReportHandlerApplicationInfos.add( Pair.create( context.getPackageManager().getApplicationInfo(SHELL_APP_PACKAGE, - PackageManager.MATCH_ANY_USER), UserHandle.USER_SYSTEM) + PackageManager.MATCH_ANY_USER), currentUser) ); } catch (PackageManager.NameNotFoundException e) { } } final UserManager userManager = context.getSystemService(UserManager.class); - final List profileList = userManager.getProfiles(UserHandle.getCallingUserId()); + final List profileList = userManager.getProfiles(currentUser); // Only add non-Shell app as normal preference final List nonShellPackageList = bugreportAllowlistedPackages.stream() .filter(pkg -> !SHELL_APP_PACKAGE.equals(pkg)).collect(Collectors.toList()); @@ -228,11 +230,11 @@ public class BugReportHandlerUtil { private void setBugreportHandlerAppAndUser(Context context, String handlerApp, int handlerUser) { - Settings.Global.putString(context.getContentResolver(), - Settings.Global.CUSTOM_BUGREPORT_HANDLER_APP, + Settings.Secure.putString(context.getContentResolver(), + Settings.Secure.CUSTOM_BUGREPORT_HANDLER_APP, handlerApp); - Settings.Global.putInt(context.getContentResolver(), - Settings.Global.CUSTOM_BUGREPORT_HANDLER_USER, handlerUser); + Settings.Secure.putInt(context.getContentResolver(), + Settings.Secure.CUSTOM_BUGREPORT_HANDLER_USER, handlerUser); } /** diff --git a/src/com/android/settings/development/BugReportInPowerPreferenceController.java b/src/com/android/settings/development/BugReportInPowerPreferenceController.java index 99ced773255..5ad63e0ac96 100644 --- a/src/com/android/settings/development/BugReportInPowerPreferenceController.java +++ b/src/com/android/settings/development/BugReportInPowerPreferenceController.java @@ -59,7 +59,7 @@ public class BugReportInPowerPreferenceController extends public boolean onPreferenceChange(Preference preference, Object newValue) { final boolean isEnabled = (Boolean) newValue; Settings.Secure.putInt(mContext.getContentResolver(), - Settings.Global.BUGREPORT_IN_POWER_MENU, + Settings.Secure.BUGREPORT_IN_POWER_MENU, isEnabled ? SETTING_VALUE_ON : SETTING_VALUE_OFF); return true; } @@ -67,7 +67,7 @@ public class BugReportInPowerPreferenceController extends @Override public void updateState(Preference preference) { final int mode = Settings.Secure.getInt(mContext.getContentResolver(), - Settings.Global.BUGREPORT_IN_POWER_MENU, SETTING_VALUE_OFF); + Settings.Secure.BUGREPORT_IN_POWER_MENU, SETTING_VALUE_OFF); ((SwitchPreference) mPreference).setChecked(mode != SETTING_VALUE_OFF); } @@ -75,7 +75,7 @@ public class BugReportInPowerPreferenceController extends protected void onDeveloperOptionsSwitchDisabled() { super.onDeveloperOptionsSwitchDisabled(); Settings.Secure.putInt(mContext.getContentResolver(), - Settings.Global.BUGREPORT_IN_POWER_MENU, SETTING_VALUE_OFF); + Settings.Secure.BUGREPORT_IN_POWER_MENU, SETTING_VALUE_OFF); ((SwitchPreference) mPreference).setChecked(false); } } diff --git a/tests/robotests/src/com/android/settings/development/BugReportInPowerPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/BugReportInPowerPreferenceControllerTest.java index 604dcb7a783..462ed16074b 100644 --- a/tests/robotests/src/com/android/settings/development/BugReportInPowerPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/development/BugReportInPowerPreferenceControllerTest.java @@ -99,7 +99,7 @@ public class BugReportInPowerPreferenceControllerTest { mController.onPreferenceChange(mPreference, false /* new value */); int mode = Settings.Secure.getInt(mContext.getContentResolver(), - Settings.Global.BUGREPORT_IN_POWER_MENU, -1 /* default */); + Settings.Secure.BUGREPORT_IN_POWER_MENU, -1 /* default */); assertThat(mode).isEqualTo(SETTING_VALUE_OFF); } @@ -111,7 +111,7 @@ public class BugReportInPowerPreferenceControllerTest { mController.onPreferenceChange(mPreference, true /* new value */); int mode = Settings.Secure.getInt(mContext.getContentResolver(), - Settings.Global.BUGREPORT_IN_POWER_MENU, -1 /* default */); + Settings.Secure.BUGREPORT_IN_POWER_MENU, -1 /* default */); assertThat(mode).isEqualTo(SETTING_VALUE_ON); } @@ -121,7 +121,7 @@ public class BugReportInPowerPreferenceControllerTest { public void updateState_settingsOn_preferenceShouldBeChecked() { when(mUserManager.hasUserRestriction(anyString())).thenReturn(false); Settings.Secure.putInt(mContext.getContentResolver(), - Settings.Global.BUGREPORT_IN_POWER_MENU, SETTING_VALUE_ON); + Settings.Secure.BUGREPORT_IN_POWER_MENU, SETTING_VALUE_ON); mController.displayPreference(mScreen); mController.updateState(mPreference); @@ -133,7 +133,7 @@ public class BugReportInPowerPreferenceControllerTest { public void updateState_settingsOff_preferenceShouldNotBeChecked() { when(mUserManager.hasUserRestriction(anyString())).thenReturn(false); Settings.Secure.putInt(mContext.getContentResolver(), - Settings.Global.BUGREPORT_IN_POWER_MENU, SETTING_VALUE_OFF); + Settings.Secure.BUGREPORT_IN_POWER_MENU, SETTING_VALUE_OFF); mController.displayPreference(mScreen); mController.updateState(mPreference); @@ -148,7 +148,7 @@ public class BugReportInPowerPreferenceControllerTest { mController.onDeveloperOptionsSwitchDisabled(); int mode = Settings.Secure.getInt(mContext.getContentResolver(), - Settings.Global.BUGREPORT_IN_POWER_MENU, -1 /* default */); + Settings.Secure.BUGREPORT_IN_POWER_MENU, -1 /* default */); assertThat(mode).isEqualTo(SETTING_VALUE_OFF); verify(mPreference).setChecked(false);