Removing support for lagacy shortcuts
> Addition/removal of shortcus is already removed. This just cleans up the unused code path Bug: 275875209 Test: Updated tests Flag: N/A Change-Id: I8ab7f57b693f996920e50e8beecafcffab5167e9
This commit is contained in:
@@ -1,32 +1,31 @@
|
||||
package com.android.launcher3.model;
|
||||
|
||||
import static android.os.Process.myUserHandle;
|
||||
|
||||
import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
|
||||
import static com.android.launcher3.util.LauncherModelHelper.TEST_ACTIVITY;
|
||||
import static com.android.launcher3.util.LauncherModelHelper.TEST_ACTIVITY2;
|
||||
import static com.android.launcher3.util.LauncherModelHelper.TEST_ACTIVITY3;
|
||||
import static com.android.launcher3.util.LauncherModelHelper.TEST_PACKAGE;
|
||||
import static com.android.launcher3.util.TestUtil.runOnExecutorSync;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Bitmap.Config;
|
||||
import android.graphics.Color;
|
||||
import android.os.Process;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.launcher3.LauncherAppState;
|
||||
import com.android.launcher3.icons.BitmapInfo;
|
||||
import com.android.launcher3.icons.IconCache;
|
||||
import com.android.launcher3.icons.cache.CachingLogic;
|
||||
import com.android.launcher3.model.data.AppInfo;
|
||||
import com.android.launcher3.model.data.ItemInfo;
|
||||
import com.android.launcher3.model.data.FolderInfo;
|
||||
import com.android.launcher3.model.data.WorkspaceItemInfo;
|
||||
import com.android.launcher3.util.IntSet;
|
||||
import com.android.launcher3.util.LauncherLayoutBuilder;
|
||||
import com.android.launcher3.util.LauncherModelHelper;
|
||||
import com.android.launcher3.util.PackageUserKey;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -35,6 +34,7 @@ import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Tests for {@link CacheDataUpdatedTask}
|
||||
@@ -43,49 +43,40 @@ import java.util.HashSet;
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class CacheDataUpdatedTaskTest {
|
||||
|
||||
private static final String NEW_LABEL_PREFIX = "new-label-";
|
||||
private static final String PENDING_APP_1 = TEST_PACKAGE + ".pending1";
|
||||
private static final String PENDING_APP_2 = TEST_PACKAGE + ".pending2";
|
||||
|
||||
private LauncherModelHelper mModelHelper;
|
||||
private Context mContext;
|
||||
|
||||
private int mSession1;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
mModelHelper = new LauncherModelHelper();
|
||||
mModelHelper.initializeData("cache_data_updated_task_data");
|
||||
mContext = mModelHelper.sandboxContext;
|
||||
mSession1 = mModelHelper.createInstallerSession(PENDING_APP_1);
|
||||
mModelHelper.createInstallerSession(PENDING_APP_2);
|
||||
|
||||
// Add placeholder entries in the cache to simulate update
|
||||
Context context = mModelHelper.sandboxContext;
|
||||
IconCache iconCache = LauncherAppState.getInstance(context).getIconCache();
|
||||
CachingLogic<ItemInfo> placeholderLogic = new CachingLogic<ItemInfo>() {
|
||||
@Override
|
||||
@NonNull
|
||||
public ComponentName getComponent(@NonNull ItemInfo info) {
|
||||
return info.getTargetComponent();
|
||||
}
|
||||
LauncherLayoutBuilder builder = new LauncherLayoutBuilder()
|
||||
.atHotseat(1).putFolder("MyFolder")
|
||||
.addApp(TEST_PACKAGE, TEST_ACTIVITY) // 2
|
||||
.addApp(TEST_PACKAGE, TEST_ACTIVITY2) // 3
|
||||
.addApp(TEST_PACKAGE, TEST_ACTIVITY3) // 4
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public UserHandle getUser(@NonNull ItemInfo info) {
|
||||
return info.user;
|
||||
}
|
||||
// Pending App 1
|
||||
.addApp(PENDING_APP_1, TEST_ACTIVITY) // 5
|
||||
.addApp(PENDING_APP_1, TEST_ACTIVITY2) // 6
|
||||
.addApp(PENDING_APP_1, TEST_ACTIVITY3) // 7
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public CharSequence getLabel(@NonNull ItemInfo info) {
|
||||
return NEW_LABEL_PREFIX + info.id;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public BitmapInfo loadIcon(@NonNull Context context, @NonNull ItemInfo info) {
|
||||
return BitmapInfo.of(Bitmap.createBitmap(1, 1, Config.ARGB_8888), Color.RED);
|
||||
}
|
||||
};
|
||||
|
||||
UserManager um = context.getSystemService(UserManager.class);
|
||||
for (ItemInfo info : mModelHelper.getBgDataModel().itemsIdMap) {
|
||||
iconCache.addIconToDBAndMemCache(info, placeholderLogic, new PackageInfo(),
|
||||
um.getSerialNumberForUser(info.user), true);
|
||||
}
|
||||
// Pending App 2
|
||||
.addApp(PENDING_APP_2, TEST_ACTIVITY) // 8
|
||||
.addApp(PENDING_APP_2, TEST_ACTIVITY2) // 9
|
||||
.addApp(PENDING_APP_2, TEST_ACTIVITY3) // 10
|
||||
.build();
|
||||
mModelHelper.setupDefaultLayoutProvider(builder);
|
||||
mModelHelper.loadModelSync();
|
||||
assertEquals(10, mModelHelper.getBgDataModel().itemsIdMap.size());
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -94,27 +85,63 @@ public class CacheDataUpdatedTaskTest {
|
||||
}
|
||||
|
||||
private CacheDataUpdatedTask newTask(int op, String... pkg) {
|
||||
return new CacheDataUpdatedTask(op, Process.myUserHandle(),
|
||||
return new CacheDataUpdatedTask(op, myUserHandle(),
|
||||
new HashSet<>(Arrays.asList(pkg)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCacheUpdate_update_apps() throws Exception {
|
||||
// Clear all icons from apps list so that its easy to check what was updated
|
||||
for (AppInfo info : mModelHelper.getAllAppsList().data) {
|
||||
info.bitmap = BitmapInfo.LOW_RES_INFO;
|
||||
}
|
||||
public void testCacheUpdate_update_apps() {
|
||||
// Run on model executor so that no other task runs in the middle.
|
||||
runOnExecutorSync(MODEL_EXECUTOR, () -> {
|
||||
// Clear all icons from apps list so that its easy to check what was updated
|
||||
allItems().forEach(wi -> wi.bitmap = BitmapInfo.LOW_RES_INFO);
|
||||
|
||||
mModelHelper.executeTaskForTest(newTask(CacheDataUpdatedTask.OP_CACHE_UPDATE, "app1"));
|
||||
mModelHelper.getModel().enqueueModelUpdateTask(
|
||||
newTask(CacheDataUpdatedTask.OP_CACHE_UPDATE, TEST_PACKAGE));
|
||||
|
||||
// Verify that only the app icons of app1 (id 1 & 2) are updated. Custom shortcut (id 7)
|
||||
// is not updated
|
||||
verifyUpdate(1, 2);
|
||||
// Verify that only the app icons of TEST_PACKAGE (id 2, 3, 4) are updated.
|
||||
verifyUpdate(2, 3, 4);
|
||||
});
|
||||
}
|
||||
|
||||
// Verify that only app1 var updated in allAppsList
|
||||
assertFalse(mModelHelper.getAllAppsList().data.isEmpty());
|
||||
for (AppInfo info : mModelHelper.getAllAppsList().data) {
|
||||
if (info.componentName.getPackageName().equals("app1")) {
|
||||
@Test
|
||||
public void testSessionUpdate_ignores_normal_apps() {
|
||||
// Run on model executor so that no other task runs in the middle.
|
||||
runOnExecutorSync(MODEL_EXECUTOR, () -> {
|
||||
// Clear all icons from apps list so that its easy to check what was updated
|
||||
allItems().forEach(wi -> wi.bitmap = BitmapInfo.LOW_RES_INFO);
|
||||
|
||||
mModelHelper.getModel().enqueueModelUpdateTask(
|
||||
newTask(CacheDataUpdatedTask.OP_SESSION_UPDATE, TEST_PACKAGE));
|
||||
|
||||
// TEST_PACKAGE has no restored shortcuts. Verify that nothing was updated.
|
||||
verifyUpdate();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSessionUpdate_updates_pending_apps() {
|
||||
// Run on model executor so that no other task runs in the middle.
|
||||
runOnExecutorSync(MODEL_EXECUTOR, () -> {
|
||||
LauncherAppState.getInstance(mContext).getIconCache().updateSessionCache(
|
||||
new PackageUserKey(PENDING_APP_1, myUserHandle()),
|
||||
mContext.getPackageManager().getPackageInstaller().getSessionInfo(mSession1));
|
||||
|
||||
// Clear all icons from apps list so that its easy to check what was updated
|
||||
allItems().forEach(wi -> wi.bitmap = BitmapInfo.LOW_RES_INFO);
|
||||
|
||||
mModelHelper.getModel().enqueueModelUpdateTask(
|
||||
newTask(CacheDataUpdatedTask.OP_SESSION_UPDATE, PENDING_APP_1));
|
||||
|
||||
// Only restored apps from PENDING_APP_1 (id 5, 6, 7) are updated
|
||||
verifyUpdate(5, 6, 7);
|
||||
});
|
||||
}
|
||||
|
||||
private void verifyUpdate(int... idsUpdated) {
|
||||
IntSet updates = IntSet.wrap(idsUpdated);
|
||||
for (WorkspaceItemInfo info : allItems()) {
|
||||
if (updates.contains(info.id)) {
|
||||
assertFalse(info.bitmap.isNullOrLowRes());
|
||||
} else {
|
||||
assertTrue(info.bitmap.isNullOrLowRes());
|
||||
@@ -122,33 +149,7 @@ public class CacheDataUpdatedTaskTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSessionUpdate_ignores_normal_apps() throws Exception {
|
||||
mModelHelper.executeTaskForTest(newTask(CacheDataUpdatedTask.OP_SESSION_UPDATE, "app1"));
|
||||
|
||||
// app1 has no restored shortcuts. Verify that nothing was updated.
|
||||
verifyUpdate();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSessionUpdate_updates_pending_apps() throws Exception {
|
||||
mModelHelper.executeTaskForTest(newTask(CacheDataUpdatedTask.OP_SESSION_UPDATE, "app3"));
|
||||
|
||||
// app3 has only restored apps (id 5, 6) and shortcuts (id 9). Verify that only apps were
|
||||
// were updated
|
||||
verifyUpdate(5, 6);
|
||||
}
|
||||
|
||||
private void verifyUpdate(Integer... idsUpdated) {
|
||||
HashSet<Integer> updates = new HashSet<>(Arrays.asList(idsUpdated));
|
||||
for (ItemInfo info : mModelHelper.getBgDataModel().itemsIdMap) {
|
||||
if (updates.contains(info.id)) {
|
||||
assertEquals(NEW_LABEL_PREFIX + info.id, info.title);
|
||||
assertFalse(((WorkspaceItemInfo) info).bitmap.isNullOrLowRes());
|
||||
} else {
|
||||
assertNotSame(NEW_LABEL_PREFIX + info.id, info.title);
|
||||
assertTrue(((WorkspaceItemInfo) info).bitmap.isNullOrLowRes());
|
||||
}
|
||||
}
|
||||
private List<WorkspaceItemInfo> allItems() {
|
||||
return ((FolderInfo) mModelHelper.getBgDataModel().itemsIdMap.get(1)).contents;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user