Update Safety Tile config value
The class moved, so the config must update. Also changes the config to
be just the class name, and to derive the package name from
PackageManager.getPermissionControllerPackageName
Bug: 233254005
Test: atest AutoTileManagerTest
Change-Id: I0e59705946677215a95a3d470a84ca874db1a48c
diff --git a/packages/SystemUI/res/values/config.xml b/packages/SystemUI/res/values/config.xml
index c8fff39..74e4693 100644
--- a/packages/SystemUI/res/values/config.xml
+++ b/packages/SystemUI/res/values/config.xml
@@ -77,9 +77,9 @@
internet,bt,flashlight,dnd,alarm,airplane,controls,wallet,rotation,battery,cast,screenrecord,mictoggle,cameratoggle,custom(com.android.permissioncontroller/.permission.service.SafetyCenterQsTileService)
</string>
- <!-- The component name of the Safety Quick Settings Tile -->
- <string name="safety_quick_settings_tile" translatable="false">
- custom(com.android.permissioncontroller/.permission.service.SafetyCenterQsTileService)
+ <!-- The class path of the Safety Quick Settings Tile -->
+ <string name="safety_quick_settings_tile_class" translatable="false">
+ com.android.permissioncontroller.permission.service.v33.SafetyCenterQsTileService
</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 61780cd..8782be5 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoTileManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoTileManager.java
@@ -17,6 +17,7 @@
import static com.android.systemui.qs.dagger.QSFlagsModule.RBC_AVAILABLE;
import android.annotation.Nullable;
+import android.content.ComponentName;
import android.content.Context;
import android.content.res.Resources;
import android.hardware.display.ColorDisplayManager;
@@ -118,13 +119,18 @@
mDeviceControlsController = deviceControlsController;
mWalletController = walletController;
mSafetyController = safetyController;
- String safetySpecRes;
+ String safetySpecClass;
try {
- safetySpecRes = context.getResources().getString(R.string.safety_quick_settings_tile);
+ safetySpecClass =
+ context.getResources().getString(R.string.safety_quick_settings_tile_class);
+ if (safetySpecClass.length() == 0) {
+ safetySpecClass = null;
+ }
} catch (Resources.NotFoundException | NullPointerException e) {
- safetySpecRes = null;
+ safetySpecClass = null;
}
- mSafetySpec = safetySpecRes;
+ mSafetySpec = safetySpecClass != null ? CustomTile.toSpec(new ComponentName(mContext
+ .getPackageManager().getPermissionControllerPackageName(), safetySpecClass)) : null;
}
/**
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 03a6c19..371119c 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
@@ -36,6 +36,7 @@
import android.content.ComponentName;
import android.content.Context;
+import android.content.pm.PackageManager;
import android.hardware.display.ColorDisplayManager;
import android.hardware.display.NightDisplayListener;
import android.os.Handler;
@@ -70,7 +71,9 @@
import org.mockito.Answers;
import org.mockito.InOrder;
import org.mockito.Mock;
+import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
+import org.mockito.Spy;
import java.util.Collections;
import java.util.List;
@@ -87,7 +90,10 @@
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 TEST_CUSTOM_SAFETY_CLASS = "safety_cls";
+ private static final String TEST_CUSTOM_SAFETY_PKG = "safety_pkg";
+ private static final String TEST_CUSTOM_SAFETY_SPEC = CustomTile.toSpec(new ComponentName(
+ TEST_CUSTOM_SAFETY_PKG, TEST_CUSTOM_SAFETY_CLASS));
private static final String SEPARATOR = AutoTileManager.SETTING_SEPARATOR;
private static final int USER = 0;
@@ -106,6 +112,7 @@
@Mock(answer = Answers.RETURNS_SELF)
private AutoAddTracker.Builder mAutoAddTrackerBuilder;
@Mock private Context mUserContext;
+ @Spy private PackageManager mPackageManager;
private final boolean mIsReduceBrightColorsAvailable = true;
private AutoTileManager mAutoTileManager;
@@ -126,13 +133,18 @@
mContext.getOrCreateTestableResources().addOverride(
com.android.internal.R.bool.config_nightDisplayAvailable, true);
mContext.getOrCreateTestableResources().addOverride(
- R.string.safety_quick_settings_tile, TEST_CUSTOM_SAFETY_SPEC);
+ R.string.safety_quick_settings_tile_class, TEST_CUSTOM_SAFETY_CLASS);
when(mAutoAddTrackerBuilder.build()).thenReturn(mAutoAddTracker);
when(mQsTileHost.getUserContext()).thenReturn(mUserContext);
when(mUserContext.getUser()).thenReturn(UserHandle.of(USER));
+ mPackageManager = Mockito.spy(mContext.getPackageManager());
+ when(mPackageManager.getPermissionControllerPackageName())
+ .thenReturn(TEST_CUSTOM_SAFETY_PKG);
+ Context context = Mockito.spy(mContext);
+ when(context.getPackageManager()).thenReturn(mPackageManager);
- mAutoTileManager = createAutoTileManager(mContext);
+ mAutoTileManager = createAutoTileManager(context);
mAutoTileManager.init();
}