Override default assistant
When setting the default assistant, we now look for an override component value. if no component override exist, then we load the default. Fixes: 144774755 Test: atest NotificationManagerServicetest Change-Id: I395f7d6ea0999dc7d2b95ece32e67a1ed77c0897
This commit is contained in:
@@ -559,13 +559,6 @@ public class NotificationManagerService extends SystemService {
|
||||
|
||||
|
||||
ArraySet<String> assistants = new ArraySet<>();
|
||||
String deviceAssistant = DeviceConfig.getProperty(
|
||||
DeviceConfig.NAMESPACE_SYSTEMUI,
|
||||
SystemUiDeviceConfigFlags.NAS_DEFAULT_SERVICE);
|
||||
if (deviceAssistant != null) {
|
||||
assistants.addAll(Arrays.asList(deviceAssistant.split(
|
||||
ManagedServices.ENABLED_SERVICES_SEPARATOR)));
|
||||
}
|
||||
assistants.addAll(Arrays.asList(getContext().getResources().getString(
|
||||
com.android.internal.R.string.config_defaultAssistantAccessComponent)
|
||||
.split(ManagedServices.ENABLED_SERVICES_SEPARATOR)));
|
||||
@@ -594,6 +587,13 @@ public class NotificationManagerService extends SystemService {
|
||||
}
|
||||
|
||||
protected void setDefaultAssistantForUser(int userId) {
|
||||
String overrideDefaultAssistantString = DeviceConfig.getProperty(
|
||||
DeviceConfig.NAMESPACE_SYSTEMUI,
|
||||
SystemUiDeviceConfigFlags.NAS_DEFAULT_SERVICE);
|
||||
ComponentName overrideDefaultAssistant =
|
||||
ComponentName.unflattenFromString(overrideDefaultAssistantString);
|
||||
if (allowAssistant(userId, overrideDefaultAssistant)) return;
|
||||
|
||||
ArraySet<ComponentName> defaults = mAssistants.getDefaultComponents();
|
||||
// We should have only one default assistant by default
|
||||
// allowAssistant should execute once in practice
|
||||
|
||||
@@ -57,6 +57,7 @@ import static junit.framework.Assert.assertNull;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static junit.framework.Assert.fail;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.isNull;
|
||||
import static org.mockito.Matchers.anyBoolean;
|
||||
import static org.mockito.Matchers.anyLong;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
@@ -752,6 +753,43 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
|
||||
assertEquals(IMPORTANCE_HIGH, createdChannel.getImportance());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultAssistant_overrideDefault() {
|
||||
final int userId = 0;
|
||||
final String testComponent = "package/class";
|
||||
final List<UserInfo> userInfos = new ArrayList<>();
|
||||
userInfos.add(new UserInfo(0, "", 0));
|
||||
final ArraySet<ComponentName> validAssistants = new ArraySet<>();
|
||||
validAssistants.add(ComponentName.unflattenFromString(testComponent));
|
||||
final String originalComponent = DeviceConfig.getProperty(
|
||||
DeviceConfig.NAMESPACE_SYSTEMUI,
|
||||
SystemUiDeviceConfigFlags.NAS_DEFAULT_SERVICE
|
||||
);
|
||||
DeviceConfig.setProperty(
|
||||
DeviceConfig.NAMESPACE_SYSTEMUI,
|
||||
SystemUiDeviceConfigFlags.NAS_DEFAULT_SERVICE,
|
||||
testComponent,
|
||||
false
|
||||
);
|
||||
when(mActivityManager.isLowRamDevice()).thenReturn(false);
|
||||
when(mAssistants.queryPackageForServices(isNull(), anyInt(), anyInt()))
|
||||
.thenReturn(validAssistants);
|
||||
when(mAssistants.getDefaultComponents()).thenReturn(new ArraySet<>());
|
||||
when(mUm.getEnabledProfiles(anyInt())).thenReturn(userInfos);
|
||||
|
||||
mService.setDefaultAssistantForUser(userId);
|
||||
|
||||
verify(mAssistants).setPackageOrComponentEnabled(
|
||||
eq(testComponent), eq(userId), eq(true), eq(true));
|
||||
|
||||
DeviceConfig.setProperty(
|
||||
DeviceConfig.NAMESPACE_SYSTEMUI,
|
||||
SystemUiDeviceConfigFlags.NAS_DEFAULT_SERVICE,
|
||||
originalComponent,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateNotificationChannels_IdenticalChannelsInListIgnoresSecond()
|
||||
throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user