Search in sources :

Example 71 with BgDataModel

use of com.android.launcher3.model.BgDataModel in project android_packages_apps_Launcher3 by crdroidandroid.

the class LauncherModelHelper method executeTaskForTest.

/**
 * Synchronously executes the task and returns all the UI callbacks posted.
 */
public List<Runnable> executeTaskForTest(ModelUpdateTask task) throws Exception {
    LauncherModel model = getModel();
    if (!model.isModelLoaded()) {
        ReflectionHelpers.setField(model, "mModelLoaded", true);
    }
    Executor mockExecutor = mock(Executor.class);
    model.enqueueModelUpdateTask(new ModelUpdateTask() {

        @Override
        public void init(LauncherAppState app, LauncherModel model, BgDataModel dataModel, AllAppsList allAppsList, Executor uiExecutor) {
            task.init(app, model, dataModel, allAppsList, mockExecutor);
        }

        @Override
        public void run() {
            task.run();
        }
    });
    MODEL_EXECUTOR.submit(() -> null).get();
    ArgumentCaptor<Runnable> captor = ArgumentCaptor.forClass(Runnable.class);
    verify(mockExecutor, atLeast(0)).execute(captor.capture());
    return captor.getAllValues();
}
Also used : LauncherModel(com.android.launcher3.LauncherModel) ModelUpdateTask(com.android.launcher3.LauncherModel.ModelUpdateTask) ShadowLooperExecutor(com.android.launcher3.shadows.ShadowLooperExecutor) Executor(java.util.concurrent.Executor) LauncherAppState(com.android.launcher3.LauncherAppState) BgDataModel(com.android.launcher3.model.BgDataModel) AllAppsList(com.android.launcher3.model.AllAppsList)

Example 72 with BgDataModel

use of com.android.launcher3.model.BgDataModel in project Neo-Launcher by NeoApplications.

the class AddWorkspaceItemsTaskTest method testFindSpaceForItem_adds_new_screen.

@Test
public void testFindSpaceForItem_adds_new_screen() throws Exception {
    // First screen has 2 holes of sizes 3x2 and 2x3
    setupWorkspaceWithHoles(1, 1, new Rect(2, 0, 5, 2), new Rect(0, 2, 2, 5));
    IntArray oldScreens = existingScreens.clone();
    int[] spaceFound = newTask().findSpaceForItem(appState, bgDataModel, existingScreens, newScreens, 3, 3);
    assertFalse(oldScreens.contains(spaceFound[0]));
    assertTrue(newScreens.contains(spaceFound[0]));
}
Also used : Rect(android.graphics.Rect) IntArray(com.android.launcher3.util.IntArray) Test(org.junit.Test)

Example 73 with BgDataModel

use of com.android.launcher3.model.BgDataModel in project Neo-Launcher by NeoApplications.

the class BaseModelUpdateTaskTestCase method setUp.

@Before
public void setUp() throws Exception {
    ShadowLog.stream = System.out;
    mProvider = Robolectric.setupContentProvider(TestLauncherProvider.class);
    ShadowContentResolver.registerProviderInternal(LauncherProvider.AUTHORITY, mProvider);
    callbacks = mock(Callbacks.class);
    appState = mock(LauncherAppState.class);
    model = mock(LauncherModel.class);
    modelWriter = mock(ModelWriter.class);
    when(appState.getModel()).thenReturn(model);
    when(model.getWriter(anyBoolean(), anyBoolean())).thenReturn(modelWriter);
    when(model.getCallback()).thenReturn(callbacks);
    myUser = Process.myUserHandle();
    bgDataModel = new BgDataModel();
    targetContext = RuntimeEnvironment.application;
    idp = new InvariantDeviceProfile();
    iconCache = new MyIconCache(targetContext, idp);
    allAppsList = new AllAppsList(iconCache, new AppFilter());
    when(appState.getIconCache()).thenReturn(iconCache);
    when(appState.getInvariantDeviceProfile()).thenReturn(idp);
    when(appState.getContext()).thenReturn(targetContext);
}
Also used : LauncherModel(com.android.launcher3.LauncherModel) AppFilter(com.android.launcher3.AppFilter) Callbacks(com.android.launcher3.model.BgDataModel.Callbacks) LauncherAppState(com.android.launcher3.LauncherAppState) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) TestLauncherProvider(com.android.launcher3.util.TestLauncherProvider) Before(org.junit.Before)

Example 74 with BgDataModel

use of com.android.launcher3.model.BgDataModel in project Neo-Launcher by NeoApplications.

the class AddWorkspaceItemsTask method shortcutExists.

/**
 * Returns true if the shortcuts already exists on the workspace. This must be called after
 * the workspace has been loaded. We identify a shortcut by its intent.
 */
protected boolean shortcutExists(BgDataModel dataModel, Intent intent, UserHandle user) {
    final String compPkgName, intentWithPkg, intentWithoutPkg;
    if (intent == null) {
        // Skip items with null intents
        return true;
    }
    if (intent.getComponent() != null) {
        // If component is not null, an intent with null package will produce
        // the same result and should also be a match.
        compPkgName = intent.getComponent().getPackageName();
        if (intent.getPackage() != null) {
            intentWithPkg = intent.toUri(0);
            intentWithoutPkg = new Intent(intent).setPackage(null).toUri(0);
        } else {
            intentWithPkg = new Intent(intent).setPackage(compPkgName).toUri(0);
            intentWithoutPkg = intent.toUri(0);
        }
    } else {
        compPkgName = null;
        intentWithPkg = intent.toUri(0);
        intentWithoutPkg = intent.toUri(0);
    }
    boolean isLauncherAppTarget = PackageManagerHelper.isLauncherAppTarget(intent);
    synchronized (dataModel) {
        for (ItemInfo item : dataModel.itemsIdMap) {
            if (item instanceof WorkspaceItemInfo) {
                WorkspaceItemInfo info = (WorkspaceItemInfo) item;
                if (item.getIntent() != null && info.user.equals(user)) {
                    Intent copyIntent = new Intent(item.getIntent());
                    copyIntent.setSourceBounds(intent.getSourceBounds());
                    String s = copyIntent.toUri(0);
                    if (intentWithPkg.equals(s) || intentWithoutPkg.equals(s)) {
                        return true;
                    }
                    // checking for existing promise icon with same package name
                    if (isLauncherAppTarget && info.isPromise() && info.hasStatusFlag(WorkspaceItemInfo.FLAG_AUTOINSTALL_ICON) && info.getTargetComponent() != null && compPkgName != null && compPkgName.equals(info.getTargetComponent().getPackageName())) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : ItemInfo(com.android.launcher3.ItemInfo) WorkspaceItemInfo(com.android.launcher3.WorkspaceItemInfo) Intent(android.content.Intent) WorkspaceItemInfo(com.android.launcher3.WorkspaceItemInfo)

Example 75 with BgDataModel

use of com.android.launcher3.model.BgDataModel in project Neo-Launcher by NeoApplications.

the class UserLockStateChangedTask method execute.

@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
    Context context = app.getContext();
    boolean isUserUnlocked = UserManagerCompat.getInstance(context).isUserUnlocked(mUser);
    DeepShortcutManager deepShortcutManager = DeepShortcutManager.getInstance(context);
    HashMap<ShortcutKey, ShortcutInfo> pinnedShortcuts = new HashMap<>();
    if (isUserUnlocked) {
        DeepShortcutManager.QueryResult shortcuts = deepShortcutManager.queryForPinnedShortcuts(null, mUser);
        if (shortcuts.wasSuccess()) {
            for (ShortcutInfo shortcut : shortcuts) {
                pinnedShortcuts.put(ShortcutKey.fromInfo(shortcut), shortcut);
            }
        } else {
            // Shortcut manager can fail due to some race condition when the lock state
            // changes too frequently. For the purpose of the update,
            // consider it as still locked.
            isUserUnlocked = false;
        }
    }
    // Update the workspace to reflect the changes to updated shortcuts residing on it.
    ArrayList<WorkspaceItemInfo> updatedWorkspaceItemInfos = new ArrayList<>();
    HashSet<ShortcutKey> removedKeys = new HashSet<>();
    for (ItemInfo itemInfo : dataModel.itemsIdMap) {
        if (itemInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT && mUser.equals(itemInfo.user)) {
            WorkspaceItemInfo si = (WorkspaceItemInfo) itemInfo;
            if (isUserUnlocked) {
                ShortcutKey key = ShortcutKey.fromItemInfo(si);
                ShortcutInfo shortcut = pinnedShortcuts.get(key);
                // (probably due to clear data), delete the workspace item as well
                if (shortcut == null) {
                    removedKeys.add(key);
                    continue;
                }
                si.runtimeStatusFlags &= ~FLAG_DISABLED_LOCKED_USER;
                si.updateFromDeepShortcutInfo(shortcut, context);
                // If the shortcut is pinned but no longer has an icon in the system,
                // keep the current icon instead of reverting to the default icon.
                LauncherIcons li = LauncherIcons.obtain(context);
                si.applyFrom(li.createShortcutIcon(shortcut, true, () -> si));
                li.recycle();
            } else {
                si.runtimeStatusFlags |= FLAG_DISABLED_LOCKED_USER;
            }
            updatedWorkspaceItemInfos.add(si);
        }
    }
    bindUpdatedWorkspaceItems(updatedWorkspaceItemInfos);
    if (!removedKeys.isEmpty()) {
        deleteAndBindComponentsRemoved(ItemInfoMatcher.ofShortcutKeys(removedKeys));
    }
    // Remove shortcut id map for that user
    Iterator<ComponentKey> keysIter = dataModel.deepShortcutMap.keySet().iterator();
    while (keysIter.hasNext()) {
        if (keysIter.next().user.equals(mUser)) {
            keysIter.remove();
        }
    }
    if (isUserUnlocked) {
        dataModel.updateDeepShortcutCounts(null, mUser, deepShortcutManager.queryForAllShortcuts(mUser));
    }
    bindDeepShortcuts(dataModel);
}
Also used : Context(android.content.Context) ShortcutInfo(android.content.pm.ShortcutInfo) HashMap(java.util.HashMap) ItemInfo(com.android.launcher3.ItemInfo) WorkspaceItemInfo(com.android.launcher3.WorkspaceItemInfo) ArrayList(java.util.ArrayList) ComponentKey(com.android.launcher3.util.ComponentKey) ShortcutKey(com.android.launcher3.shortcuts.ShortcutKey) LauncherIcons(com.android.launcher3.icons.LauncherIcons) DeepShortcutManager(com.android.launcher3.shortcuts.DeepShortcutManager) WorkspaceItemInfo(com.android.launcher3.WorkspaceItemInfo) HashSet(java.util.HashSet)

Aggregations

WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)66 ArrayList (java.util.ArrayList)63 ItemInfo (com.android.launcher3.model.data.ItemInfo)45 Context (android.content.Context)33 HashSet (java.util.HashSet)33 LauncherAppState (com.android.launcher3.LauncherAppState)28 AppInfo (com.android.launcher3.model.data.AppInfo)27 ComponentName (android.content.ComponentName)26 ShortcutInfo (android.content.pm.ShortcutInfo)26 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)23 BgDataModel (com.android.launcher3.model.BgDataModel)22 AppTarget (android.app.prediction.AppTarget)20 FixedContainerItems (com.android.launcher3.model.BgDataModel.FixedContainerItems)20 List (java.util.List)20 ShortcutRequest (com.android.launcher3.shortcuts.ShortcutRequest)18 HashMap (java.util.HashMap)18 LauncherActivityInfo (android.content.pm.LauncherActivityInfo)17 LauncherApps (android.content.pm.LauncherApps)17 AllAppsList (com.android.launcher3.model.AllAppsList)17 Set (java.util.Set)15