Loading packages/SystemUI/res/values/config.xml +6 −1 Original line number Diff line number Diff line Loading @@ -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 --> Loading packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoTileManager.java +20 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; } /** Loading Loading @@ -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++) { Loading Loading @@ -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() { Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/AutoTileManagerTest.java +23 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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); Loading Loading @@ -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( Loading Loading
packages/SystemUI/res/values/config.xml +6 −1 Original line number Diff line number Diff line Loading @@ -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 --> Loading
packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoTileManager.java +20 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; } /** Loading Loading @@ -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++) { Loading Loading @@ -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() { Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/AutoTileManagerTest.java +23 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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); Loading Loading @@ -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( Loading