Merge "Automatically show Safety Tile" into tm-dev am: 2606f9c4ed

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/16981753

Change-Id: Id9afe1dcfe1a37038de6593eb7f699ffe86d65a0
This commit is contained in:
Nate Myren
2022-02-24 17:53:28 +00:00
committed by Automerger Merge Worker
3 changed files with 49 additions and 1 deletions

View File

@@ -74,7 +74,12 @@
<!-- The default tiles to display in QuickSettings -->
<string name="quick_settings_tiles_default" translatable="false">
internet,bt,flashlight,dnd,alarm,airplane,controls,wallet,rotation,battery,cast,screenrecord,mictoggle,cameratoggle
internet,bt,flashlight,dnd,alarm,airplane,controls,wallet,rotation,battery,cast,screenrecord,mictoggle,cameratoggle,custom(com.android.permissioncontroller/.permission.service.SafetyHubQsTileService)
</string>
<!-- The component name of the Safety Quick Settings Tile -->
<string name="safety_quick_settings_tile" translatable="false">
custom(com.android.permissioncontroller/.permission.service.SafetyHubQsTileService)
</string>
<!-- The minimum number of tiles to display in QuickSettings -->

View File

@@ -68,6 +68,7 @@ public class AutoTileManager implements UserAwareController {
private UserHandle mCurrentUser;
private boolean mInitialized;
private final String mSafetySpec;
protected final Context mContext;
protected final QSTileHost mHost;
@@ -113,6 +114,13 @@ public class AutoTileManager implements UserAwareController {
mIsReduceBrightColorsAvailable = isReduceBrightColorsAvailable;
mDeviceControlsController = deviceControlsController;
mWalletController = walletController;
String safetySpecRes;
try {
safetySpecRes = context.getResources().getString(R.string.safety_quick_settings_tile);
} catch (Resources.NotFoundException | NullPointerException e) {
safetySpecRes = null;
}
mSafetySpec = safetySpecRes;
}
/**
@@ -155,6 +163,9 @@ public class AutoTileManager implements UserAwareController {
if (!mAutoTracker.isAdded(WALLET)) {
initWalletController();
}
if (mSafetySpec != null && !mAutoTracker.isAdded(mSafetySpec)) {
initSafetyTile();
}
int settingsN = mAutoAddSettingList.size();
for (int i = 0; i < settingsN; i++) {
@@ -315,6 +326,15 @@ public class AutoTileManager implements UserAwareController {
}
}
private void initSafetyTile() {
if (mSafetySpec == null) {
return;
}
if (mAutoTracker.isAdded(mSafetySpec)) return;
mHost.addTile(CustomTile.getComponentFromSpec(mSafetySpec), true);
mAutoTracker.setTileAdded(mSafetySpec);
}
@VisibleForTesting
final NightDisplayListener.Callback mNightDisplayCallback =
new NightDisplayListener.Callback() {

View File

@@ -52,6 +52,7 @@ import com.android.systemui.qs.AutoAddTracker;
import com.android.systemui.qs.QSTileHost;
import com.android.systemui.qs.ReduceBrightColorsController;
import com.android.systemui.qs.SettingObserver;
import com.android.systemui.qs.external.CustomTile;
import com.android.systemui.statusbar.policy.CastController;
import com.android.systemui.statusbar.policy.CastController.CastDevice;
import com.android.systemui.statusbar.policy.DataSaverController;
@@ -85,6 +86,7 @@ public class AutoTileManagerTest extends SysuiTestCase {
private static final String TEST_SETTING_COMPONENT = "setting_component";
private static final String TEST_COMPONENT = "test_pkg/test_cls";
private static final String TEST_CUSTOM_SPEC = "custom(" + TEST_COMPONENT + ")";
private static final String TEST_CUSTOM_SAFETY_SPEC = "custom(safety_pkg/safety_cls)";
private static final String SEPARATOR = AutoTileManager.SETTING_SEPARATOR;
private static final int USER = 0;
@@ -121,6 +123,8 @@ public class AutoTileManagerTest extends SysuiTestCase {
);
mContext.getOrCreateTestableResources().addOverride(
com.android.internal.R.bool.config_nightDisplayAvailable, true);
mContext.getOrCreateTestableResources().addOverride(
R.string.safety_quick_settings_tile, TEST_CUSTOM_SAFETY_SPEC);
when(mAutoAddTrackerBuilder.build()).thenReturn(mAutoAddTracker);
when(mQsTileHost.getUserContext()).thenReturn(mUserContext);
@@ -434,6 +438,25 @@ public class AutoTileManagerTest extends SysuiTestCase {
verify(mQsTileHost, never()).addTile(TEST_SPEC);
}
@Test
public void testSafetyTileNotAdded_ifPreviouslyAdded() {
ComponentName safetyComponent = CustomTile.getComponentFromSpec(TEST_CUSTOM_SAFETY_SPEC);
mAutoTileManager.init();
verify(mQsTileHost, times(1)).addTile(safetyComponent, true);
when(mAutoAddTracker.isAdded(TEST_CUSTOM_SAFETY_SPEC)).thenReturn(true);
mAutoTileManager.init();
verify(mQsTileHost, times(1)).addTile(safetyComponent, true);
}
@Test
public void testSafetyTileAdded_onUserChange() {
ComponentName safetyComponent = CustomTile.getComponentFromSpec(TEST_CUSTOM_SAFETY_SPEC);
mAutoTileManager.init();
verify(mQsTileHost, times(1)).addTile(safetyComponent, true);
when(mAutoAddTracker.isAdded(TEST_CUSTOM_SAFETY_SPEC)).thenReturn(false);
mAutoTileManager.changeUser(UserHandle.of(USER + 1));
verify(mQsTileHost, times(2)).addTile(safetyComponent, true);
}
@Test
public void testEmptyArray_doesNotCrash() {
mContext.getOrCreateTestableResources().addOverride(