summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/res/values/config.xml7
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoTileManager.java20
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/AutoTileManagerTest.java23
3 files changed, 49 insertions, 1 deletions
diff --git a/packages/SystemUI/res/values/config.xml b/packages/SystemUI/res/values/config.xml
index 178f93ae3c93..73ef37ca02ed 100644
--- a/packages/SystemUI/res/values/config.xml
+++ b/packages/SystemUI/res/values/config.xml
@@ -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 -->
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoTileManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoTileManager.java
index 244103cf419e..ccb37aeb18a9 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoTileManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoTileManager.java
@@ -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() {
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/AutoTileManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/AutoTileManagerTest.java
index 22899367afce..0e12c2adc09a 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/AutoTileManagerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/AutoTileManagerTest.java
@@ -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);
@@ -435,6 +439,25 @@ public class AutoTileManagerTest extends SysuiTestCase {
}
@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(
R.array.config_quickSettingsAutoAdd, new String[0]);