Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package com.android.server.pm; |
| 17 | |
| 18 | import android.annotation.NonNull; |
Makoto Onuki | 2d895c3 | 2016-12-02 15:48:40 -0800 | [diff] [blame] | 19 | import android.annotation.Nullable; |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 20 | import android.annotation.UserIdInt; |
Makoto Onuki | c8c3329 | 2016-09-12 16:36:59 -0700 | [diff] [blame] | 21 | import android.content.pm.PackageInfo; |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 22 | import android.content.pm.ShortcutInfo; |
| 23 | import android.util.ArrayMap; |
| 24 | import android.util.ArraySet; |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 25 | import android.util.Slog; |
| 26 | |
| 27 | import com.android.internal.annotations.VisibleForTesting; |
Makoto Onuki | 20b8221 | 2017-10-04 15:03:50 -0700 | [diff] [blame] | 28 | import com.android.server.pm.ShortcutService.DumpFilter; |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 29 | import com.android.server.pm.ShortcutUser.PackageWithUser; |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 30 | |
Makoto Onuki | 7626992 | 2016-07-15 14:58:54 -0700 | [diff] [blame] | 31 | import org.json.JSONException; |
| 32 | import org.json.JSONObject; |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 33 | import org.xmlpull.v1.XmlPullParser; |
| 34 | import org.xmlpull.v1.XmlPullParserException; |
| 35 | import org.xmlpull.v1.XmlSerializer; |
| 36 | |
| 37 | import java.io.IOException; |
| 38 | import java.io.PrintWriter; |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 39 | import java.util.ArrayList; |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 40 | import java.util.List; |
| 41 | |
| 42 | /** |
| 43 | * Launcher information used by {@link ShortcutService}. |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 44 | * |
| 45 | * All methods should be guarded by {@code #mShortcutUser.mService.mLock}. |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 46 | */ |
Makoto Onuki | 9da23fc | 2016-03-29 11:14:42 -0700 | [diff] [blame] | 47 | class ShortcutLauncher extends ShortcutPackageItem { |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 48 | private static final String TAG = ShortcutService.TAG; |
| 49 | |
| 50 | static final String TAG_ROOT = "launcher-pins"; |
| 51 | |
| 52 | private static final String TAG_PACKAGE = "package"; |
| 53 | private static final String TAG_PIN = "pin"; |
| 54 | |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 55 | private static final String ATTR_LAUNCHER_USER_ID = "launcher-user"; |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 56 | private static final String ATTR_VALUE = "value"; |
| 57 | private static final String ATTR_PACKAGE_NAME = "package-name"; |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 58 | private static final String ATTR_PACKAGE_USER_ID = "package-user"; |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 59 | |
Makoto Onuki | 9da23fc | 2016-03-29 11:14:42 -0700 | [diff] [blame] | 60 | private final int mOwnerUserId; |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 61 | |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 62 | /** |
| 63 | * Package name -> IDs. |
| 64 | */ |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 65 | final private ArrayMap<PackageWithUser, ArraySet<String>> mPinnedShortcuts = new ArrayMap<>(); |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 66 | |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 67 | private ShortcutLauncher(@NonNull ShortcutUser shortcutUser, |
| 68 | @UserIdInt int ownerUserId, @NonNull String packageName, |
Makoto Onuki | 9da23fc | 2016-03-29 11:14:42 -0700 | [diff] [blame] | 69 | @UserIdInt int launcherUserId, ShortcutPackageInfo spi) { |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 70 | super(shortcutUser, launcherUserId, packageName, |
| 71 | spi != null ? spi : ShortcutPackageInfo.newEmpty()); |
Makoto Onuki | 9da23fc | 2016-03-29 11:14:42 -0700 | [diff] [blame] | 72 | mOwnerUserId = ownerUserId; |
| 73 | } |
| 74 | |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 75 | public ShortcutLauncher(@NonNull ShortcutUser shortcutUser, |
| 76 | @UserIdInt int ownerUserId, @NonNull String packageName, |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 77 | @UserIdInt int launcherUserId) { |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 78 | this(shortcutUser, ownerUserId, packageName, launcherUserId, null); |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Makoto Onuki | 9da23fc | 2016-03-29 11:14:42 -0700 | [diff] [blame] | 81 | @Override |
| 82 | public int getOwnerUserId() { |
| 83 | return mOwnerUserId; |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 86 | @Override |
| 87 | protected boolean canRestoreAnyVersion() { |
| 88 | // Launcher's pinned shortcuts can be restored to an older version. |
| 89 | return true; |
| 90 | } |
| 91 | |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 92 | /** |
| 93 | * Called when the new package can't receive the backup, due to signature or version mismatch. |
| 94 | */ |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 95 | private void onRestoreBlocked() { |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 96 | final ArrayList<PackageWithUser> pinnedPackages = |
| 97 | new ArrayList<>(mPinnedShortcuts.keySet()); |
| 98 | mPinnedShortcuts.clear(); |
| 99 | for (int i = pinnedPackages.size() - 1; i >= 0; i--) { |
| 100 | final PackageWithUser pu = pinnedPackages.get(i); |
Makoto Onuki | c51b287 | 2016-05-04 15:24:50 -0700 | [diff] [blame] | 101 | final ShortcutPackage p = mShortcutUser.getPackageShortcutsIfExists(pu.packageName); |
| 102 | if (p != null) { |
| 103 | p.refreshPinnedFlags(); |
| 104 | } |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 105 | } |
| 106 | } |
| 107 | |
| 108 | @Override |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 109 | protected void onRestored(int restoreBlockReason) { |
| 110 | // For launcher, possible reasons here are DISABLED_REASON_SIGNATURE_MISMATCH or |
| 111 | // DISABLED_REASON_BACKUP_NOT_SUPPORTED. |
| 112 | // DISABLED_REASON_VERSION_LOWER will NOT happen because we don't check version |
| 113 | // code for launchers. |
| 114 | if (restoreBlockReason != ShortcutInfo.DISABLED_REASON_NOT_DISABLED) { |
| 115 | onRestoreBlocked(); |
| 116 | } |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Makoto Onuki | 2d895c3 | 2016-12-02 15:48:40 -0800 | [diff] [blame] | 119 | /** |
| 120 | * Pin the given shortcuts, replacing the current pinned ones. |
| 121 | */ |
Makoto Onuki | c51b287 | 2016-05-04 15:24:50 -0700 | [diff] [blame] | 122 | public void pinShortcuts(@UserIdInt int packageUserId, |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 123 | @NonNull String packageName, @NonNull List<String> ids, boolean forPinRequest) { |
Makoto Onuki | 9da23fc | 2016-03-29 11:14:42 -0700 | [diff] [blame] | 124 | final ShortcutPackage packageShortcuts = |
Makoto Onuki | c51b287 | 2016-05-04 15:24:50 -0700 | [diff] [blame] | 125 | mShortcutUser.getPackageShortcutsIfExists(packageName); |
| 126 | if (packageShortcuts == null) { |
| 127 | return; // No need to instantiate. |
| 128 | } |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 129 | |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 130 | final PackageWithUser pu = PackageWithUser.of(packageUserId, packageName); |
| 131 | |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 132 | final int idSize = ids.size(); |
| 133 | if (idSize == 0) { |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 134 | mPinnedShortcuts.remove(pu); |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 135 | } else { |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 136 | final ArraySet<String> prevSet = mPinnedShortcuts.get(pu); |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 137 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 138 | // Actually pin shortcuts. |
| 139 | // This logic here is to make sure a launcher cannot pin a shortcut that is floating |
| 140 | // (i.e. not dynamic nor manifest but is pinned) and pinned by another launcher. |
| 141 | // In this case, technically the shortcut doesn't exist to this launcher, so it can't |
| 142 | // pin it. |
| 143 | // (Maybe unnecessarily strict...) |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 144 | |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 145 | final ArraySet<String> newSet = new ArraySet<>(); |
| 146 | |
| 147 | for (int i = 0; i < idSize; i++) { |
| 148 | final String id = ids.get(i); |
| 149 | final ShortcutInfo si = packageShortcuts.findShortcutById(id); |
| 150 | if (si == null) { |
| 151 | continue; |
| 152 | } |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 153 | if (si.isDynamic() |
| 154 | || si.isManifestShortcut() |
| 155 | || (prevSet != null && prevSet.contains(id)) |
| 156 | || forPinRequest) { |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 157 | newSet.add(id); |
| 158 | } |
| 159 | } |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 160 | mPinnedShortcuts.put(pu, newSet); |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 161 | } |
Makoto Onuki | c51b287 | 2016-05-04 15:24:50 -0700 | [diff] [blame] | 162 | packageShortcuts.refreshPinnedFlags(); |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | /** |
| 166 | * Return the pinned shortcut IDs for the publisher package. |
| 167 | */ |
Makoto Onuki | 2d895c3 | 2016-12-02 15:48:40 -0800 | [diff] [blame] | 168 | @Nullable |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 169 | public ArraySet<String> getPinnedShortcutIds(@NonNull String packageName, |
| 170 | @UserIdInt int packageUserId) { |
| 171 | return mPinnedShortcuts.get(PackageWithUser.of(packageUserId, packageName)); |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Makoto Onuki | 2d895c3 | 2016-12-02 15:48:40 -0800 | [diff] [blame] | 174 | /** |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 175 | * Return true if the given shortcut is pinned by this launcher.<code></code> |
Makoto Onuki | 2d895c3 | 2016-12-02 15:48:40 -0800 | [diff] [blame] | 176 | */ |
| 177 | public boolean hasPinned(ShortcutInfo shortcut) { |
| 178 | final ArraySet<String> pinned = |
| 179 | getPinnedShortcutIds(shortcut.getPackage(), shortcut.getUserId()); |
| 180 | return (pinned != null) && pinned.contains(shortcut.getId()); |
| 181 | } |
| 182 | |
| 183 | /** |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 184 | * Additionally pin a shortcut. c.f. {@link #pinShortcuts(int, String, List, boolean)} |
Makoto Onuki | 2d895c3 | 2016-12-02 15:48:40 -0800 | [diff] [blame] | 185 | */ |
| 186 | public void addPinnedShortcut(@NonNull String packageName, @UserIdInt int packageUserId, |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 187 | String id, boolean forPinRequest) { |
Makoto Onuki | 2d895c3 | 2016-12-02 15:48:40 -0800 | [diff] [blame] | 188 | final ArraySet<String> pinnedSet = getPinnedShortcutIds(packageName, packageUserId); |
| 189 | final ArrayList<String> pinnedList; |
| 190 | if (pinnedSet != null) { |
| 191 | pinnedList = new ArrayList<>(pinnedSet.size() + 1); |
| 192 | pinnedList.addAll(pinnedSet); |
| 193 | } else { |
| 194 | pinnedList = new ArrayList<>(1); |
| 195 | } |
| 196 | pinnedList.add(id); |
| 197 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 198 | pinShortcuts(packageUserId, packageName, pinnedList, forPinRequest); |
Makoto Onuki | 2d895c3 | 2016-12-02 15:48:40 -0800 | [diff] [blame] | 199 | } |
| 200 | |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 201 | boolean cleanUpPackage(String packageName, @UserIdInt int packageUserId) { |
| 202 | return mPinnedShortcuts.remove(PackageWithUser.of(packageUserId, packageName)) != null; |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 205 | public void ensurePackageInfo() { |
Makoto Onuki | c8c3329 | 2016-09-12 16:36:59 -0700 | [diff] [blame] | 206 | final PackageInfo pi = mShortcutUser.mService.getPackageInfoWithSignatures( |
| 207 | getPackageName(), getPackageUserId()); |
| 208 | if (pi == null) { |
| 209 | Slog.w(TAG, "Package not found: " + getPackageName()); |
| 210 | return; |
| 211 | } |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 212 | getPackageInfo().updateFromPackageInfo(pi); |
Makoto Onuki | c8c3329 | 2016-09-12 16:36:59 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 215 | /** |
| 216 | * Persist. |
| 217 | */ |
Makoto Onuki | 9da23fc | 2016-03-29 11:14:42 -0700 | [diff] [blame] | 218 | @Override |
| 219 | public void saveToXml(XmlSerializer out, boolean forBackup) |
| 220 | throws IOException { |
Makoto Onuki | a4f89b1 | 2017-10-05 10:37:55 -0700 | [diff] [blame] | 221 | if (forBackup && !getPackageInfo().isBackupAllowed()) { |
| 222 | // If an launcher app doesn't support backup&restore, then nothing to do. |
| 223 | return; |
| 224 | } |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 225 | final int size = mPinnedShortcuts.size(); |
| 226 | if (size == 0) { |
| 227 | return; // Nothing to write. |
| 228 | } |
| 229 | |
| 230 | out.startTag(null, TAG_ROOT); |
Makoto Onuki | 9da23fc | 2016-03-29 11:14:42 -0700 | [diff] [blame] | 231 | ShortcutService.writeAttr(out, ATTR_PACKAGE_NAME, getPackageName()); |
| 232 | ShortcutService.writeAttr(out, ATTR_LAUNCHER_USER_ID, getPackageUserId()); |
Makoto Onuki | e3fffa9 | 2018-02-28 16:25:40 -0800 | [diff] [blame] | 233 | getPackageInfo().saveToXml(mShortcutUser.mService, out, forBackup); |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 234 | |
| 235 | for (int i = 0; i < size; i++) { |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 236 | final PackageWithUser pu = mPinnedShortcuts.keyAt(i); |
| 237 | |
| 238 | if (forBackup && (pu.userId != getOwnerUserId())) { |
| 239 | continue; // Target package on a different user, skip. (i.e. work profile) |
| 240 | } |
| 241 | |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 242 | out.startTag(null, TAG_PACKAGE); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 243 | ShortcutService.writeAttr(out, ATTR_PACKAGE_NAME, pu.packageName); |
| 244 | ShortcutService.writeAttr(out, ATTR_PACKAGE_USER_ID, pu.userId); |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 245 | |
| 246 | final ArraySet<String> ids = mPinnedShortcuts.valueAt(i); |
| 247 | final int idSize = ids.size(); |
| 248 | for (int j = 0; j < idSize; j++) { |
| 249 | ShortcutService.writeTagValue(out, TAG_PIN, ids.valueAt(j)); |
| 250 | } |
| 251 | out.endTag(null, TAG_PACKAGE); |
| 252 | } |
| 253 | |
| 254 | out.endTag(null, TAG_ROOT); |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * Load. |
| 259 | */ |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 260 | public static ShortcutLauncher loadFromXml(XmlPullParser parser, ShortcutUser shortcutUser, |
| 261 | int ownerUserId, boolean fromBackup) throws IOException, XmlPullParserException { |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 262 | final String launcherPackageName = ShortcutService.parseStringAttribute(parser, |
| 263 | ATTR_PACKAGE_NAME); |
Makoto Onuki | 9da23fc | 2016-03-29 11:14:42 -0700 | [diff] [blame] | 264 | |
| 265 | // If restoring, just use the real user ID. |
| 266 | final int launcherUserId = |
| 267 | fromBackup ? ownerUserId |
| 268 | : ShortcutService.parseIntAttribute(parser, ATTR_LAUNCHER_USER_ID, ownerUserId); |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 269 | |
Makoto Onuki | c8c3329 | 2016-09-12 16:36:59 -0700 | [diff] [blame] | 270 | final ShortcutLauncher ret = new ShortcutLauncher(shortcutUser, ownerUserId, |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 271 | launcherPackageName, launcherUserId); |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 272 | |
| 273 | ArraySet<String> ids = null; |
| 274 | final int outerDepth = parser.getDepth(); |
| 275 | int type; |
| 276 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 277 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 278 | if (type != XmlPullParser.START_TAG) { |
| 279 | continue; |
| 280 | } |
| 281 | final int depth = parser.getDepth(); |
| 282 | final String tag = parser.getName(); |
Makoto Onuki | 9da23fc | 2016-03-29 11:14:42 -0700 | [diff] [blame] | 283 | if (depth == outerDepth + 1) { |
| 284 | switch (tag) { |
| 285 | case ShortcutPackageInfo.TAG_ROOT: |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 286 | ret.getPackageInfo().loadFromXml(parser, fromBackup); |
Makoto Onuki | 9da23fc | 2016-03-29 11:14:42 -0700 | [diff] [blame] | 287 | continue; |
| 288 | case TAG_PACKAGE: { |
| 289 | final String packageName = ShortcutService.parseStringAttribute(parser, |
| 290 | ATTR_PACKAGE_NAME); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 291 | final int packageUserId = fromBackup ? ownerUserId |
| 292 | : ShortcutService.parseIntAttribute(parser, |
| 293 | ATTR_PACKAGE_USER_ID, ownerUserId); |
Makoto Onuki | 9da23fc | 2016-03-29 11:14:42 -0700 | [diff] [blame] | 294 | ids = new ArraySet<>(); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 295 | ret.mPinnedShortcuts.put( |
| 296 | PackageWithUser.of(packageUserId, packageName), ids); |
Makoto Onuki | 9da23fc | 2016-03-29 11:14:42 -0700 | [diff] [blame] | 297 | continue; |
| 298 | } |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 299 | } |
| 300 | } |
Makoto Onuki | 9da23fc | 2016-03-29 11:14:42 -0700 | [diff] [blame] | 301 | if (depth == outerDepth + 2) { |
| 302 | switch (tag) { |
| 303 | case TAG_PIN: { |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 304 | if (ids == null) { |
| 305 | Slog.w(TAG, TAG_PIN + " in invalid place"); |
| 306 | } else { |
| 307 | ids.add(ShortcutService.parseStringAttribute(parser, ATTR_VALUE)); |
| 308 | } |
Makoto Onuki | 9da23fc | 2016-03-29 11:14:42 -0700 | [diff] [blame] | 309 | continue; |
| 310 | } |
| 311 | } |
| 312 | } |
| 313 | ShortcutService.warnForInvalidTag(depth, tag); |
| 314 | } |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 315 | return ret; |
| 316 | } |
| 317 | |
Makoto Onuki | 20b8221 | 2017-10-04 15:03:50 -0700 | [diff] [blame] | 318 | public void dump(@NonNull PrintWriter pw, @NonNull String prefix, DumpFilter filter) { |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 319 | pw.println(); |
| 320 | |
| 321 | pw.print(prefix); |
| 322 | pw.print("Launcher: "); |
Makoto Onuki | 9da23fc | 2016-03-29 11:14:42 -0700 | [diff] [blame] | 323 | pw.print(getPackageName()); |
| 324 | pw.print(" Package user: "); |
| 325 | pw.print(getPackageUserId()); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 326 | pw.print(" Owner user: "); |
| 327 | pw.print(getOwnerUserId()); |
Makoto Onuki | 9da23fc | 2016-03-29 11:14:42 -0700 | [diff] [blame] | 328 | pw.println(); |
| 329 | |
Makoto Onuki | c51b287 | 2016-05-04 15:24:50 -0700 | [diff] [blame] | 330 | getPackageInfo().dump(pw, prefix + " "); |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 331 | pw.println(); |
| 332 | |
| 333 | final int size = mPinnedShortcuts.size(); |
| 334 | for (int i = 0; i < size; i++) { |
| 335 | pw.println(); |
| 336 | |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 337 | final PackageWithUser pu = mPinnedShortcuts.keyAt(i); |
| 338 | |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 339 | pw.print(prefix); |
| 340 | pw.print(" "); |
| 341 | pw.print("Package: "); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 342 | pw.print(pu.packageName); |
| 343 | pw.print(" User: "); |
| 344 | pw.println(pu.userId); |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 345 | |
| 346 | final ArraySet<String> ids = mPinnedShortcuts.valueAt(i); |
| 347 | final int idSize = ids.size(); |
| 348 | |
| 349 | for (int j = 0; j < idSize; j++) { |
| 350 | pw.print(prefix); |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 351 | pw.print(" Pinned: "); |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 352 | pw.print(ids.valueAt(j)); |
| 353 | pw.println(); |
| 354 | } |
| 355 | } |
| 356 | } |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 357 | |
Makoto Onuki | 7626992 | 2016-07-15 14:58:54 -0700 | [diff] [blame] | 358 | @Override |
| 359 | public JSONObject dumpCheckin(boolean clear) throws JSONException { |
| 360 | final JSONObject result = super.dumpCheckin(clear); |
| 361 | |
| 362 | // Nothing really interesting to dump. |
| 363 | |
| 364 | return result; |
| 365 | } |
| 366 | |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 367 | @VisibleForTesting |
| 368 | ArraySet<String> getAllPinnedShortcutsForTest(String packageName, int packageUserId) { |
| 369 | return new ArraySet<>(mPinnedShortcuts.get(PackageWithUser.of(packageUserId, packageName))); |
| 370 | } |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 371 | } |