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;
|
2016-12-15 15:53:17 -08:00
|
|
|
import android.os.UserHandle;
|
2016-09-09 15:47:55 -07:00
|
|
|
|
|
|
|
|
import com.android.launcher3.AllAppsList;
|
|
|
|
|
import com.android.launcher3.ItemInfo;
|
|
|
|
|
import com.android.launcher3.LauncherAppState;
|
|
|
|
|
import com.android.launcher3.LauncherSettings;
|
|
|
|
|
import com.android.launcher3.ShortcutInfo;
|
2017-01-18 11:30:23 -08:00
|
|
|
import com.android.launcher3.graphics.LauncherIcons;
|
2016-09-09 15:47:55 -07:00
|
|
|
import com.android.launcher3.shortcuts.DeepShortcutManager;
|
|
|
|
|
import com.android.launcher3.shortcuts.ShortcutInfoCompat;
|
2017-08-17 03:01:19 -07:00
|
|
|
import com.android.launcher3.shortcuts.ShortcutKey;
|
|
|
|
|
import com.android.launcher3.util.ItemInfoMatcher;
|
2016-09-09 15:47:55 -07:00
|
|
|
import com.android.launcher3.util.MultiHashMap;
|
2017-12-19 16:49:24 -08:00
|
|
|
import com.android.launcher3.util.Provider;
|
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;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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;
|
|
|
|
|
private final List<ShortcutInfoCompat> 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;
|
|
|
|
|
|
|
|
|
|
public ShortcutsChangedTask(String packageName, List<ShortcutInfoCompat> 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();
|
|
|
|
|
DeepShortcutManager deepShortcutManager = DeepShortcutManager.getInstance(context);
|
2016-09-09 15:47:55 -07:00
|
|
|
deepShortcutManager.onShortcutsChanged(mShortcuts);
|
|
|
|
|
|
|
|
|
|
// Find ShortcutInfo's that have changed on the workspace.
|
2017-08-17 03:01:19 -07:00
|
|
|
HashSet<ShortcutKey> removedKeys = new HashSet<>();
|
|
|
|
|
MultiHashMap<ShortcutKey, ShortcutInfo> keyToShortcutInfo = new MultiHashMap<>();
|
|
|
|
|
HashSet<String> allIds = new HashSet<>();
|
|
|
|
|
|
2016-09-09 15:47:55 -07:00
|
|
|
for (ItemInfo itemInfo : dataModel.itemsIdMap) {
|
|
|
|
|
if (itemInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
|
|
|
|
|
ShortcutInfo si = (ShortcutInfo) itemInfo;
|
2017-08-17 03:01:19 -07:00
|
|
|
if (si.getIntent().getPackage().equals(mPackageName) && si.user.equals(mUser)) {
|
|
|
|
|
keyToShortcutInfo.addToList(ShortcutKey.fromItemInfo(si), si);
|
|
|
|
|
allIds.add(si.getDeepShortcutId());
|
2016-09-09 15:47:55 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final ArrayList<ShortcutInfo> updatedShortcutInfos = new ArrayList<>();
|
2017-08-17 03:01:19 -07:00
|
|
|
if (!keyToShortcutInfo.isEmpty()) {
|
2016-09-09 15:47:55 -07:00
|
|
|
// Update the workspace to reflect the changes to updated shortcuts residing on it.
|
|
|
|
|
List<ShortcutInfoCompat> shortcuts = deepShortcutManager.queryForFullDetails(
|
2017-08-17 03:01:19 -07:00
|
|
|
mPackageName, new ArrayList<>(allIds), mUser);
|
2016-09-09 15:47:55 -07:00
|
|
|
for (ShortcutInfoCompat fullDetails : shortcuts) {
|
2017-08-17 03:01:19 -07:00
|
|
|
ShortcutKey key = ShortcutKey.fromInfo(fullDetails);
|
|
|
|
|
List<ShortcutInfo> shortcutInfos = keyToShortcutInfo.remove(key);
|
2016-09-09 15:47:55 -07:00
|
|
|
if (!fullDetails.isPinned()) {
|
|
|
|
|
// The shortcut was previously pinned but is no longer, so remove it from
|
|
|
|
|
// the workspace and our pinned shortcut counts.
|
|
|
|
|
// Note that we put this check here, after querying for full details,
|
|
|
|
|
// because there's a possible race condition between pinning and
|
|
|
|
|
// receiving this callback.
|
2017-08-17 03:01:19 -07:00
|
|
|
removedKeys.add(key);
|
2016-09-09 15:47:55 -07:00
|
|
|
continue;
|
|
|
|
|
}
|
2017-07-28 16:11:36 -07:00
|
|
|
for (final ShortcutInfo shortcutInfo : shortcutInfos) {
|
2016-09-09 15:47:55 -07:00
|
|
|
shortcutInfo.updateFromDeepShortcutInfo(fullDetails, context);
|
2017-12-19 16:49:24 -08:00
|
|
|
// 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.
|
2018-01-09 15:34:38 -08:00
|
|
|
LauncherIcons li = LauncherIcons.obtain(context);
|
|
|
|
|
li.createShortcutIcon(fullDetails, true, Provider.of(shortcutInfo.iconBitmap))
|
|
|
|
|
.applyTo(shortcutInfo);
|
|
|
|
|
li.recycle();
|
2016-09-09 15:47:55 -07:00
|
|
|
updatedShortcutInfos.add(shortcutInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-17 03:01:19 -07:00
|
|
|
// If there are still entries in keyToShortcutInfo, that means that
|
2016-09-09 15:47:55 -07:00
|
|
|
// the corresponding shortcuts weren't passed in onShortcutsChanged(). This
|
|
|
|
|
// means they were cleared, so we remove and unpin them now.
|
2017-08-17 03:01:19 -07:00
|
|
|
removedKeys.addAll(keyToShortcutInfo.keySet());
|
2016-09-09 15:47:55 -07:00
|
|
|
|
2017-08-17 03:01:19 -07:00
|
|
|
bindUpdatedShortcuts(updatedShortcutInfos, mUser);
|
|
|
|
|
if (!keyToShortcutInfo.isEmpty()) {
|
|
|
|
|
deleteAndBindComponentsRemoved(ItemInfoMatcher.ofShortcutKeys(removedKeys));
|
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.
|
|
|
|
|
dataModel.updateDeepShortcutMap(mPackageName, mUser, mShortcuts);
|
|
|
|
|
bindDeepShortcuts(dataModel);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|