Merge "Automatically show Safety Tile" into tm-dev

This commit is contained in:
Nate Myren
2022-02-24 17:31:09 +00:00
committed by Android (Google) Code Review
3 changed files with 49 additions and 1 deletions

View File

@@ -74,7 +74,12 @@
<!-- The default tiles to display in QuickSettings --> <!-- The default tiles to display in QuickSettings -->
<string name="quick_settings_tiles_default" translatable="false"> <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> </string>
<!-- The minimum number of tiles to display in QuickSettings --> <!-- The minimum number of tiles to display in QuickSettings -->

View File

@@ -68,6 +68,7 @@ public class AutoTileManager implements UserAwareController {
private UserHandle mCurrentUser; private UserHandle mCurrentUser;
private boolean mInitialized; private boolean mInitialized;
private final String mSafetySpec;
protected final Context mContext; protected final Context mContext;
protected final QSTileHost mHost; protected final QSTileHost mHost;
@@ -113,6 +114,13 @@ public class AutoTileManager implements UserAwareController {
mIsReduceBrightColorsAvailable = isReduceBrightColorsAvailable; mIsReduceBrightColorsAvailable = isReduceBrightColorsAvailable;
mDeviceControlsController = deviceControlsController; mDeviceControlsController = deviceControlsController;
mWalletController = walletController; 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)) { if (!mAutoTracker.isAdded(WALLET)) {
initWalletController(); initWalletController();
} }
if (mSafetySpec != null && !mAutoTracker.isAdded(mSafetySpec)) {
initSafetyTile();
}
int settingsN = mAutoAddSettingList.size(); int settingsN = mAutoAddSettingList.size();
for (int i = 0; i < settingsN; i++) { 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 @VisibleForTesting
final NightDisplayListener.Callback mNightDisplayCallback = final NightDisplayListener.Callback mNightDisplayCallback =
new NightDisplayListener.Callback() { 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.QSTileHost;
import com.android.systemui.qs.ReduceBrightColorsController; import com.android.systemui.qs.ReduceBrightColorsController;
import com.android.systemui.qs.SettingObserver; 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;
import com.android.systemui.statusbar.policy.CastController.CastDevice; import com.android.systemui.statusbar.policy.CastController.CastDevice;
import com.android.systemui.statusbar.policy.DataSaverController; 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_SETTING_COMPONENT = "setting_component";
private static final String TEST_COMPONENT = "test_pkg/test_cls"; 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_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 String SEPARATOR = AutoTileManager.SETTING_SEPARATOR;
private static final int USER = 0; private static final int USER = 0;
@@ -121,6 +123,8 @@ public class AutoTileManagerTest extends SysuiTestCase {
); );
mContext.getOrCreateTestableResources().addOverride( mContext.getOrCreateTestableResources().addOverride(
com.android.internal.R.bool.config_nightDisplayAvailable, true); 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(mAutoAddTrackerBuilder.build()).thenReturn(mAutoAddTracker);
when(mQsTileHost.getUserContext()).thenReturn(mUserContext); when(mQsTileHost.getUserContext()).thenReturn(mUserContext);
@@ -434,6 +438,25 @@ public class AutoTileManagerTest extends SysuiTestCase {
verify(mQsTileHost, never()).addTile(TEST_SPEC); 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 @Test
public void testEmptyArray_doesNotCrash() { public void testEmptyArray_doesNotCrash() {
mContext.getOrCreateTestableResources().addOverride( mContext.getOrCreateTestableResources().addOverride(