Only update mutable shortcuts.

When trying to update the flags for the existing shortcuts, check and
skip the immutable shortcuts, since they should not be modified.

Change-Id: Iee70ed92f45c1b0b0f0c5b902069c017acfa4990
Fixes: 119119713
Test: make RunSettingsRoboTests
This commit is contained in:
Doris Ling
2018-11-15 16:29:53 -08:00
parent 4fa2b88556
commit 79848abfbd
2 changed files with 22 additions and 0 deletions

View File

@@ -128,6 +128,9 @@ public class SettingsInitialize extends BroadcastReceiver {
final List<ShortcutInfo> pinnedShortcuts = shortcutManager.getPinnedShortcuts();
final List<ShortcutInfo> updates = new ArrayList<>();
for (ShortcutInfo info : pinnedShortcuts) {
if (info.isImmutable()) {
continue;
}
final Intent shortcutIntent = info.getIntent();
shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
final ShortcutInfo updatedInfo = new ShortcutInfo.Builder(context, info.getId())

View File

@@ -78,4 +78,23 @@ public class SettingsInitializeTest {
assertThat(flags & Intent.FLAG_ACTIVITY_CLEAR_TOP).isEqualTo(
Intent.FLAG_ACTIVITY_CLEAR_TOP);
}
@Test
public void refreshExistingShortcuts_shouldNotUpdateImmutableShortcut() {
final String id = "test_shortcut_id";
final ShortcutInfo info = new ShortcutInfo.Builder(mContext, id)
.setShortLabel("test123")
.setIntent(new Intent(Intent.ACTION_DEFAULT))
.build();
info.addFlags(ShortcutInfo.FLAG_IMMUTABLE);
final List<ShortcutInfo> shortcuts = new ArrayList<>();
shortcuts.add(info);
ShadowShortcutManager.get().setPinnedShortcuts(shortcuts);
mSettingsInitialize.refreshExistingShortcuts(mContext);
final List<ShortcutInfo> updatedShortcuts =
ShadowShortcutManager.get().getLastUpdatedShortcuts();
assertThat(updatedShortcuts).isEmpty();
}
}