Merge "Allow admin users to have bugreport icon in the power menu"

This commit is contained in:
Nikhil Kumar
2022-12-13 10:23:05 +00:00
committed by Android (Google) Code Review
3 changed files with 34 additions and 8 deletions

View File

@@ -733,7 +733,7 @@ public class GlobalActionsDialogLite implements DialogInterface.OnDismissListene
@VisibleForTesting
boolean shouldDisplayBugReport(UserInfo currentUser) {
return mGlobalSettings.getInt(Settings.Global.BUGREPORT_IN_POWER_MENU, 0) != 0
&& (currentUser == null || currentUser.isPrimary());
&& (currentUser == null || currentUser.isAdmin());
}
@Override
@@ -1058,8 +1058,9 @@ public class GlobalActionsDialogLite implements DialogInterface.OnDismissListene
@Override
public boolean showBeforeProvisioning() {
return Build.isDebuggable() && mGlobalSettings.getInt(
Settings.Global.BUGREPORT_IN_POWER_MENU, 0) != 0;
return Build.isDebuggable() && mGlobalSettings.getIntForUser(
Settings.Global.BUGREPORT_IN_POWER_MENU, 0, getCurrentUser().id) != 0
&& getCurrentUser().isAdmin();
}
}

View File

@@ -16,11 +16,12 @@
package com.android.systemui.globalactions;
import static android.content.pm.UserInfo.FLAG_ADMIN;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
@@ -32,11 +33,13 @@ import android.app.IActivityManager;
import android.app.admin.DevicePolicyManager;
import android.app.trust.TrustManager;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.content.res.Resources;
import android.graphics.Color;
import android.media.AudioManager;
import android.os.Handler;
import android.os.UserManager;
import android.provider.Settings;
import android.service.dreams.IDreamManager;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
@@ -552,10 +555,32 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {
@Test
public void testBugreportAction_whenDebugMode_shouldOfferBugreportButtonBeforeProvisioning() {
doReturn(1).when(mGlobalSettings).getInt(anyString(), anyInt());
UserInfo currentUser = mockCurrentUser(FLAG_ADMIN);
when(mGlobalActionsDialogLite.getCurrentUser()).thenReturn(currentUser);
doReturn(1).when(mGlobalSettings)
.getIntForUser(Settings.Global.BUGREPORT_IN_POWER_MENU, 0, currentUser.id);
GlobalActionsDialogLite.BugReportAction bugReportAction =
mGlobalActionsDialogLite.makeBugReportActionForTesting();
assertThat(bugReportAction.showBeforeProvisioning()).isTrue();
}
@Test
public void testBugreportAction_whenUserIsNotAdmin_noBugReportActionBeforeProvisioning() {
UserInfo currentUser = mockCurrentUser(0);
when(mGlobalActionsDialogLite.getCurrentUser()).thenReturn(currentUser);
doReturn(1).when(mGlobalSettings)
.getIntForUser(Settings.Global.BUGREPORT_IN_POWER_MENU, 0, currentUser.id);
GlobalActionsDialogLite.BugReportAction bugReportAction =
mGlobalActionsDialogLite.makeBugReportActionForTesting();
assertThat(bugReportAction.showBeforeProvisioning()).isFalse();
}
private UserInfo mockCurrentUser(int flags) {
return new UserInfo(10, "A User", flags);
}
}

View File

@@ -283,7 +283,7 @@ class LegacyGlobalActions implements DialogInterface.OnDismissListener, DialogIn
mItems.add(mAirplaneModeOn);
} else if (GLOBAL_ACTION_KEY_BUGREPORT.equals(actionKey)) {
if (Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.BUGREPORT_IN_POWER_MENU, 0) != 0 && isCurrentUserOwner()) {
Settings.Global.BUGREPORT_IN_POWER_MENU, 0) != 0 && isCurrentUserAdmin()) {
mItems.add(new BugReportAction());
}
} else if (GLOBAL_ACTION_KEY_SILENT.equals(actionKey)) {
@@ -535,9 +535,9 @@ class LegacyGlobalActions implements DialogInterface.OnDismissListener, DialogIn
}
}
private boolean isCurrentUserOwner() {
private boolean isCurrentUserAdmin() {
UserInfo currentUser = getCurrentUser();
return currentUser == null || currentUser.isPrimary();
return currentUser == null || currentUser.isAdmin();
}
private void addUsersToMenu(ArrayList<Action> items) {