2016-09-09 15:47:55 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2016 The Android Open Source Project
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
package com.android.launcher3.model;
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
2019-04-17 18:38:52 -07:00
|
|
|
import android.content.pm.ShortcutInfo;
|
2016-12-15 15:53:17 -08:00
|
|
|
import android.os.UserHandle;
|
2016-09-09 15:47:55 -07:00
|
|
|
|
|
|
|
|
import com.android.launcher3.LauncherAppState;
|
|
|
|
|
import com.android.launcher3.LauncherSettings;
|
2020-04-06 15:11:17 -07:00
|
|
|
import com.android.launcher3.model.data.WorkspaceItemInfo;
|
2017-08-17 03:01:19 -07:00
|
|
|
import com.android.launcher3.shortcuts.ShortcutKey;
|
2019-12-11 10:00:47 -08:00
|
|
|
import com.android.launcher3.shortcuts.ShortcutRequest;
|
2017-08-17 03:01:19 -07:00
|
|
|
import com.android.launcher3.util.ItemInfoMatcher;
|
2021-02-11 16:47:26 -08:00
|
|
|
import com.android.launcher3.util.PackageManagerHelper;
|
2016-09-09 15:47:55 -07:00
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2017-08-17 03:01:19 -07:00
|
|
|
import java.util.HashSet;
|
2016-09-09 15:47:55 -07:00
|
|
|
import java.util.List;
|
2020-08-22 02:09:42 -07:00
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.stream.Collectors;
|
2016-09-09 15:47:55 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handles changes due to shortcut manager updates (deep shortcut changes)
|
|
|
|
|
*/
|
2017-06-06 14:33:18 -07:00
|
|
|
public class ShortcutsChangedTask extends BaseModelUpdateTask {
|
2016-09-09 15:47:55 -07:00
|
|
|
|
|
|
|
|
private final String mPackageName;
|
2019-04-17 18:38:52 -07:00
|
|
|
private final List<ShortcutInfo> mShortcuts;
|
2016-12-15 15:53:17 -08:00
|
|
|
private final UserHandle mUser;
|
2016-09-09 15:47:55 -07:00
|
|
|
private final boolean mUpdateIdMap;
|
|
|
|
|
|
2019-04-17 18:38:52 -07:00
|
|
|
public ShortcutsChangedTask(String packageName, List<ShortcutInfo> shortcuts,
|
2016-12-15 15:53:17 -08:00
|
|
|
UserHandle user, boolean updateIdMap) {
|
2016-09-09 15:47:55 -07:00
|
|
|
mPackageName = packageName;
|
|
|
|
|
mShortcuts = shortcuts;
|
|
|
|
|
mUser = user;
|
|
|
|
|
mUpdateIdMap = updateIdMap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
|
2016-11-21 16:02:39 +05:30
|
|
|
final Context context = app.getContext();
|
2019-03-27 16:03:06 -07:00
|
|
|
// Find WorkspaceItemInfo's that have changed on the workspace.
|
2020-08-22 02:09:42 -07:00
|
|
|
ArrayList<WorkspaceItemInfo> matchingWorkspaceItems = new ArrayList<>();
|
2017-08-17 03:01:19 -07:00
|
|
|
|
2020-07-09 19:31:40 -07:00
|
|
|
synchronized (dataModel) {
|
|
|
|
|
dataModel.forAllWorkspaceItemInfos(mUser, si -> {
|
|
|
|
|
if ((si.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT)
|
|
|
|
|
&& mPackageName.equals(si.getIntent().getPackage())) {
|
2020-08-22 02:09:42 -07:00
|
|
|
matchingWorkspaceItems.add(si);
|
2016-09-09 15:47:55 -07:00
|
|
|
}
|
2020-07-09 19:31:40 -07:00
|
|
|
});
|
2016-09-09 15:47:55 -07:00
|
|
|
}
|
|
|
|
|
|
2020-08-22 02:09:42 -07:00
|
|
|
if (!matchingWorkspaceItems.isEmpty()) {
|
2021-02-11 16:47:26 -08:00
|
|
|
if (mShortcuts.isEmpty()) {
|
|
|
|
|
// Verify that the app is indeed installed.
|
|
|
|
|
if (!new PackageManagerHelper(app.getContext())
|
|
|
|
|
.isAppInstalled(mPackageName, mUser)) {
|
|
|
|
|
// App is not installed, ignoring package events
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-09 15:47:55 -07:00
|
|
|
// Update the workspace to reflect the changes to updated shortcuts residing on it.
|
2020-08-22 02:09:42 -07:00
|
|
|
List<String> allLauncherKnownIds = matchingWorkspaceItems.stream()
|
|
|
|
|
.map(WorkspaceItemInfo::getDeepShortcutId)
|
|
|
|
|
.distinct()
|
|
|
|
|
.collect(Collectors.toList());
|
2019-12-11 10:00:47 -08:00
|
|
|
List<ShortcutInfo> shortcuts = new ShortcutRequest(context, mUser)
|
2020-08-22 02:09:42 -07:00
|
|
|
.forPackage(mPackageName, allLauncherKnownIds)
|
2019-12-11 10:00:47 -08:00
|
|
|
.query(ShortcutRequest.ALL);
|
2020-08-22 02:09:42 -07:00
|
|
|
|
|
|
|
|
Set<String> nonPinnedIds = new HashSet<>(allLauncherKnownIds);
|
|
|
|
|
ArrayList<WorkspaceItemInfo> updatedWorkspaceItemInfos = new ArrayList<>();
|
2019-04-17 18:38:52 -07:00
|
|
|
for (ShortcutInfo fullDetails : shortcuts) {
|
2016-09-09 15:47:55 -07:00
|
|
|
if (!fullDetails.isPinned()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-22 02:09:42 -07:00
|
|
|
String sid = fullDetails.getId();
|
|
|
|
|
nonPinnedIds.remove(sid);
|
|
|
|
|
matchingWorkspaceItems
|
|
|
|
|
.stream()
|
|
|
|
|
.filter(itemInfo -> sid.equals(itemInfo.getDeepShortcutId()))
|
|
|
|
|
.forEach(workspaceItemInfo -> {
|
|
|
|
|
workspaceItemInfo.updateFromDeepShortcutInfo(fullDetails, context);
|
|
|
|
|
app.getIconCache().getShortcutIcon(workspaceItemInfo, fullDetails);
|
|
|
|
|
updatedWorkspaceItemInfos.add(workspaceItemInfo);
|
|
|
|
|
});
|
|
|
|
|
}
|
2016-09-09 15:47:55 -07:00
|
|
|
|
2020-08-22 02:09:42 -07:00
|
|
|
bindUpdatedWorkspaceItems(updatedWorkspaceItemInfos);
|
|
|
|
|
if (!nonPinnedIds.isEmpty()) {
|
|
|
|
|
deleteAndBindComponentsRemoved(ItemInfoMatcher.ofShortcutKeys(
|
|
|
|
|
nonPinnedIds.stream()
|
|
|
|
|
.map(id -> new ShortcutKey(mPackageName, mUser, id))
|
2022-05-10 23:47:36 +00:00
|
|
|
.collect(Collectors.toSet())),
|
|
|
|
|
"removed because the shortcut is no longer available in shortcut service");
|
2020-08-22 02:09:42 -07:00
|
|
|
}
|
2016-09-09 15:47:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mUpdateIdMap) {
|
|
|
|
|
// Update the deep shortcut map if the list of ids has changed for an activity.
|
2018-10-19 14:21:05 -07:00
|
|
|
dataModel.updateDeepShortcutCounts(mPackageName, mUser, mShortcuts);
|
2016-09-09 15:47:55 -07:00
|
|
|
bindDeepShortcuts(dataModel);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|