1 package com.android.launcher3.model; 2 3 import com.android.launcher3.ItemInfo; 4 import com.android.launcher3.LauncherAppWidgetInfo; 5 import com.android.launcher3.ShortcutInfo; 6 import com.android.launcher3.compat.PackageInstallerCompat; 7 import com.android.launcher3.compat.PackageInstallerCompat.PackageInstallInfo; 8 9 import java.util.Arrays; 10 import java.util.HashSet; 11 12 /** 13 * Tests for {@link PackageInstallStateChangedTask} 14 */ 15 public class PackageInstallStateChangedTaskTest extends BaseModelUpdateTaskTestCase { 16 17 @Override setUp()18 protected void setUp() throws Exception { 19 super.setUp(); 20 initializeData("package_install_state_change_task_data"); 21 } 22 newTask(String pkg, int progress)23 private PackageInstallStateChangedTask newTask(String pkg, int progress) { 24 int state = PackageInstallerCompat.STATUS_INSTALLING; 25 PackageInstallInfo installInfo = new PackageInstallInfo(pkg, state, progress); 26 return new PackageInstallStateChangedTask(installInfo); 27 } 28 testSessionUpdate_ignore_installed()29 public void testSessionUpdate_ignore_installed() throws Exception { 30 executeTaskForTest(newTask("app1", 30)); 31 32 // No shortcuts were updated 33 verifyProgressUpdate(0); 34 } 35 testSessionUpdate_shortcuts_updated()36 public void testSessionUpdate_shortcuts_updated() throws Exception { 37 executeTaskForTest(newTask("app3", 30)); 38 39 verifyProgressUpdate(30, 5L, 6L, 7L); 40 } 41 testSessionUpdate_widgets_updated()42 public void testSessionUpdate_widgets_updated() throws Exception { 43 executeTaskForTest(newTask("app4", 30)); 44 45 verifyProgressUpdate(30, 8L, 9L); 46 } 47 verifyProgressUpdate(int progress, Long... idsUpdated)48 private void verifyProgressUpdate(int progress, Long... idsUpdated) { 49 HashSet<Long> updates = new HashSet<>(Arrays.asList(idsUpdated)); 50 for (ItemInfo info : bgDataModel.itemsIdMap) { 51 if (info instanceof ShortcutInfo) { 52 assertEquals(updates.contains(info.id) ? progress: 0, 53 ((ShortcutInfo) info).getInstallProgress()); 54 } else { 55 assertEquals(updates.contains(info.id) ? progress: -1, 56 ((LauncherAppWidgetInfo) info).installProgress); 57 } 58 } 59 } 60 } 61