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 PackageInstallInfo installInfo = new PackageInstallInfo(pkg); 25 installInfo.progress = progress; 26 installInfo.state = PackageInstallerCompat.STATUS_INSTALLING; 27 return new PackageInstallStateChangedTask(installInfo); 28 } 29 testSessionUpdate_ignore_installed()30 public void testSessionUpdate_ignore_installed() throws Exception { 31 executeTaskForTest(newTask("app1", 30)); 32 33 // No shortcuts were updated 34 verifyProgressUpdate(0); 35 } 36 testSessionUpdate_shortcuts_updated()37 public void testSessionUpdate_shortcuts_updated() throws Exception { 38 executeTaskForTest(newTask("app3", 30)); 39 40 verifyProgressUpdate(30, 5L, 6L, 7L); 41 } 42 testSessionUpdate_widgets_updated()43 public void testSessionUpdate_widgets_updated() throws Exception { 44 executeTaskForTest(newTask("app4", 30)); 45 46 verifyProgressUpdate(30, 8L, 9L); 47 } 48 verifyProgressUpdate(int progress, Long... idsUpdated)49 private void verifyProgressUpdate(int progress, Long... idsUpdated) { 50 HashSet<Long> updates = new HashSet<>(Arrays.asList(idsUpdated)); 51 for (ItemInfo info : bgDataModel.itemsIdMap) { 52 if (info instanceof ShortcutInfo) { 53 assertEquals(updates.contains(info.id) ? progress: 0, 54 ((ShortcutInfo) info).getInstallProgress()); 55 } else { 56 assertEquals(updates.contains(info.id) ? progress: -1, 57 ((LauncherAppWidgetInfo) info).installProgress); 58 } 59 } 60 } 61 } 62