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 | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 86 | /** |
| 87 | * Called when the new package can't receive the backup, due to signature or version mismatch. |
| 88 | */ |
| 89 | @Override |
Makoto Onuki | c51b287 | 2016-05-04 15:24:50 -0700 | [diff] [blame] | 90 | protected void onRestoreBlocked() { |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 91 | final ArrayList<PackageWithUser> pinnedPackages = |
| 92 | new ArrayList<>(mPinnedShortcuts.keySet()); |
| 93 | mPinnedShortcuts.clear(); |
| 94 | for (int i = pinnedPackages.size() - 1; i >= 0; i--) { |
| 95 | final PackageWithUser pu = pinnedPackages.get(i); |
Makoto Onuki | c51b287 | 2016-05-04 15:24:50 -0700 | [diff] [blame] | 96 | final ShortcutPackage p = mShortcutUser.getPackageShortcutsIfExists(pu.packageName); |
| 97 | if (p != null) { |
| 98 | p.refreshPinnedFlags(); |
| 99 | } |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 100 | } |
| 101 | } |
| 102 | |
| 103 | @Override |
Makoto Onuki | c51b287 | 2016-05-04 15:24:50 -0700 | [diff] [blame] | 104 | protected void onRestored() { |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 105 | // Nothing to do. |
| 106 | } |
| 107 | |
Makoto Onuki | 2d895c3 | 2016-12-02 15:48:40 -0800 | [diff] [blame] | 108 | /** |
| 109 | * Pin the given shortcuts, replacing the current pinned ones. |
| 110 | */ |
Makoto Onuki | c51b287 | 2016-05-04 15:24:50 -0700 | [diff] [blame] | 111 | public void pinShortcuts(@UserIdInt int packageUserId, |
Makoto Onuki | 9da23fc | 2016-03-29 11:14:42 -0700 | [diff] [blame] | 112 | @NonNull String packageName, @NonNull List<String> ids) { |
| 113 | final ShortcutPackage packageShortcuts = |
Makoto Onuki | c51b287 | 2016-05-04 15:24:50 -0700 | [diff] [blame] | 114 | mShortcutUser.getPackageShortcutsIfExists(packageName); |
| 115 | if (packageShortcuts == null) { |
| 116 | return; // No need to instantiate. |
| 117 | } |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 118 | |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 119 | final PackageWithUser pu = PackageWithUser.of(packageUserId, packageName); |
| 120 | |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 121 | final int idSize = ids.size(); |
| 122 | if (idSize == 0) { |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 123 | mPinnedShortcuts.remove(pu); |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 124 | } else { |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 125 | final ArraySet<String> prevSet = mPinnedShortcuts.get(pu); |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 126 | |
| 127 | // Pin shortcuts. Make sure only pin the ones that were visible to the caller. |
| 128 | // i.e. a non-dynamic, pinned shortcut by *other launchers* shouldn't be pinned here. |
| 129 | |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 130 | final ArraySet<String> newSet = new ArraySet<>(); |
| 131 | |
| 132 | for (int i = 0; i < idSize; i++) { |
| 133 | final String id = ids.get(i); |
| 134 | final ShortcutInfo si = packageShortcuts.findShortcutById(id); |
| 135 | if (si == null) { |
| 136 | continue; |
| 137 | } |
Makoto Onuki | 22fcc68 | 2016-05-17 14:52:19 -0700 | [diff] [blame] | 138 | if (si.isDynamic() || si.isManifestShortcut() |
| 139 | || (prevSet != null && prevSet.contains(id))) { |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 140 | newSet.add(id); |
| 141 | } |
| 142 | } |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 143 | mPinnedShortcuts.put(pu, newSet); |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 144 | } |
Makoto Onuki | c51b287 | 2016-05-04 15:24:50 -0700 | [diff] [blame] | 145 | packageShortcuts.refreshPinnedFlags(); |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Return the pinned shortcut IDs for the publisher package. |
| 150 | */ |
Makoto Onuki | 2d895c3 | 2016-12-02 15:48:40 -0800 | [diff] [blame] | 151 | @Nullable |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 152 | public ArraySet<String> getPinnedShortcutIds(@NonNull String packageName, |
| 153 | @UserIdInt int packageUserId) { |
| 154 | return mPinnedShortcuts.get(PackageWithUser.of(packageUserId, packageName)); |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Makoto Onuki | 2d895c3 | 2016-12-02 15:48:40 -0800 | [diff] [blame] | 157 | /** |
| 158 | * Return true if the given shortcut is pinned by this launcher. |
| 159 | */ |
| 160 | public boolean hasPinned(ShortcutInfo shortcut) { |
| 161 | final ArraySet<String> pinned = |
| 162 | getPinnedShortcutIds(shortcut.getPackage(), shortcut.getUserId()); |
| 163 | return (pinned != null) && pinned.contains(shortcut.getId()); |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Additionally pin a shortcut. c.f. {@link #pinShortcuts(int, String, List)} |
| 168 | */ |
| 169 | public void addPinnedShortcut(@NonNull String packageName, @UserIdInt int packageUserId, |
| 170 | String id) { |
| 171 | final ArraySet<String> pinnedSet = getPinnedShortcutIds(packageName, packageUserId); |
| 172 | final ArrayList<String> pinnedList; |
| 173 | if (pinnedSet != null) { |
| 174 | pinnedList = new ArrayList<>(pinnedSet.size() + 1); |
| 175 | pinnedList.addAll(pinnedSet); |
| 176 | } else { |
| 177 | pinnedList = new ArrayList<>(1); |
| 178 | } |
| 179 | pinnedList.add(id); |
| 180 | |
| 181 | pinShortcuts(packageUserId, packageName, pinnedList); |
| 182 | } |
| 183 | |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 184 | boolean cleanUpPackage(String packageName, @UserIdInt int packageUserId) { |
| 185 | return mPinnedShortcuts.remove(PackageWithUser.of(packageUserId, packageName)) != null; |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Makoto Onuki | c8c3329 | 2016-09-12 16:36:59 -0700 | [diff] [blame] | 188 | public void ensureVersionInfo() { |
| 189 | final PackageInfo pi = mShortcutUser.mService.getPackageInfoWithSignatures( |
| 190 | getPackageName(), getPackageUserId()); |
| 191 | if (pi == null) { |
| 192 | Slog.w(TAG, "Package not found: " + getPackageName()); |
| 193 | return; |
| 194 | } |
| 195 | getPackageInfo().updateVersionInfo(pi); |
| 196 | } |
| 197 | |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 198 | /** |
| 199 | * Persist. |
| 200 | */ |
Makoto Onuki | 9da23fc | 2016-03-29 11:14:42 -0700 | [diff] [blame] | 201 | @Override |
| 202 | public void saveToXml(XmlSerializer out, boolean forBackup) |
| 203 | throws IOException { |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 204 | final int size = mPinnedShortcuts.size(); |
| 205 | if (size == 0) { |
| 206 | return; // Nothing to write. |
| 207 | } |
| 208 | |
| 209 | out.startTag(null, TAG_ROOT); |
Makoto Onuki | 9da23fc | 2016-03-29 11:14:42 -0700 | [diff] [blame] | 210 | ShortcutService.writeAttr(out, ATTR_PACKAGE_NAME, getPackageName()); |
| 211 | ShortcutService.writeAttr(out, ATTR_LAUNCHER_USER_ID, getPackageUserId()); |
| 212 | getPackageInfo().saveToXml(out); |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 213 | |
| 214 | for (int i = 0; i < size; i++) { |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 215 | final PackageWithUser pu = mPinnedShortcuts.keyAt(i); |
| 216 | |
| 217 | if (forBackup && (pu.userId != getOwnerUserId())) { |
| 218 | continue; // Target package on a different user, skip. (i.e. work profile) |
| 219 | } |
| 220 | |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 221 | out.startTag(null, TAG_PACKAGE); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 222 | ShortcutService.writeAttr(out, ATTR_PACKAGE_NAME, pu.packageName); |
| 223 | ShortcutService.writeAttr(out, ATTR_PACKAGE_USER_ID, pu.userId); |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 224 | |
| 225 | final ArraySet<String> ids = mPinnedShortcuts.valueAt(i); |
| 226 | final int idSize = ids.size(); |
| 227 | for (int j = 0; j < idSize; j++) { |
| 228 | ShortcutService.writeTagValue(out, TAG_PIN, ids.valueAt(j)); |
| 229 | } |
| 230 | out.endTag(null, TAG_PACKAGE); |
| 231 | } |
| 232 | |
| 233 | out.endTag(null, TAG_ROOT); |
| 234 | } |
| 235 | |
| 236 | /** |
| 237 | * Load. |
| 238 | */ |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 239 | public static ShortcutLauncher loadFromXml(XmlPullParser parser, ShortcutUser shortcutUser, |
| 240 | int ownerUserId, boolean fromBackup) throws IOException, XmlPullParserException { |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 241 | final String launcherPackageName = ShortcutService.parseStringAttribute(parser, |
| 242 | ATTR_PACKAGE_NAME); |
Makoto Onuki | 9da23fc | 2016-03-29 11:14:42 -0700 | [diff] [blame] | 243 | |
| 244 | // If restoring, just use the real user ID. |
| 245 | final int launcherUserId = |
| 246 | fromBackup ? ownerUserId |
| 247 | : ShortcutService.parseIntAttribute(parser, ATTR_LAUNCHER_USER_ID, ownerUserId); |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 248 | |
Makoto Onuki | c8c3329 | 2016-09-12 16:36:59 -0700 | [diff] [blame] | 249 | final ShortcutLauncher ret = new ShortcutLauncher(shortcutUser, ownerUserId, |
Makoto Onuki | 4d36b3a | 2016-04-27 12:00:17 -0700 | [diff] [blame] | 250 | launcherPackageName, launcherUserId); |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 251 | |
| 252 | ArraySet<String> ids = null; |
| 253 | final int outerDepth = parser.getDepth(); |
| 254 | int type; |
| 255 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 256 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 257 | if (type != XmlPullParser.START_TAG) { |
| 258 | continue; |
| 259 | } |
| 260 | final int depth = parser.getDepth(); |
| 261 | final String tag = parser.getName(); |
Makoto Onuki | 9da23fc | 2016-03-29 11:14:42 -0700 | [diff] [blame] | 262 | if (depth == outerDepth + 1) { |
| 263 | switch (tag) { |
| 264 | case ShortcutPackageInfo.TAG_ROOT: |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 265 | ret.getPackageInfo().loadFromXml(parser, fromBackup); |
Makoto Onuki | 9da23fc | 2016-03-29 11:14:42 -0700 | [diff] [blame] | 266 | continue; |
| 267 | case TAG_PACKAGE: { |
| 268 | final String packageName = ShortcutService.parseStringAttribute(parser, |
| 269 | ATTR_PACKAGE_NAME); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 270 | final int packageUserId = fromBackup ? ownerUserId |
| 271 | : ShortcutService.parseIntAttribute(parser, |
| 272 | ATTR_PACKAGE_USER_ID, ownerUserId); |
Makoto Onuki | 9da23fc | 2016-03-29 11:14:42 -0700 | [diff] [blame] | 273 | ids = new ArraySet<>(); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 274 | ret.mPinnedShortcuts.put( |
| 275 | PackageWithUser.of(packageUserId, packageName), ids); |
Makoto Onuki | 9da23fc | 2016-03-29 11:14:42 -0700 | [diff] [blame] | 276 | continue; |
| 277 | } |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 278 | } |
| 279 | } |
Makoto Onuki | 9da23fc | 2016-03-29 11:14:42 -0700 | [diff] [blame] | 280 | if (depth == outerDepth + 2) { |
| 281 | switch (tag) { |
| 282 | case TAG_PIN: { |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 283 | if (ids == null) { |
| 284 | Slog.w(TAG, TAG_PIN + " in invalid place"); |
| 285 | } else { |
| 286 | ids.add(ShortcutService.parseStringAttribute(parser, ATTR_VALUE)); |
| 287 | } |
Makoto Onuki | 9da23fc | 2016-03-29 11:14:42 -0700 | [diff] [blame] | 288 | continue; |
| 289 | } |
| 290 | } |
| 291 | } |
| 292 | ShortcutService.warnForInvalidTag(depth, tag); |
| 293 | } |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 294 | return ret; |
| 295 | } |
| 296 | |
Makoto Onuki | 20b8221 | 2017-10-04 15:03:50 -0700 | [diff] [blame^] | 297 | public void dump(@NonNull PrintWriter pw, @NonNull String prefix, DumpFilter filter) { |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 298 | pw.println(); |
| 299 | |
| 300 | pw.print(prefix); |
| 301 | pw.print("Launcher: "); |
Makoto Onuki | 9da23fc | 2016-03-29 11:14:42 -0700 | [diff] [blame] | 302 | pw.print(getPackageName()); |
| 303 | pw.print(" Package user: "); |
| 304 | pw.print(getPackageUserId()); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 305 | pw.print(" Owner user: "); |
| 306 | pw.print(getOwnerUserId()); |
Makoto Onuki | 9da23fc | 2016-03-29 11:14:42 -0700 | [diff] [blame] | 307 | pw.println(); |
| 308 | |
Makoto Onuki | c51b287 | 2016-05-04 15:24:50 -0700 | [diff] [blame] | 309 | getPackageInfo().dump(pw, prefix + " "); |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 310 | pw.println(); |
| 311 | |
| 312 | final int size = mPinnedShortcuts.size(); |
| 313 | for (int i = 0; i < size; i++) { |
| 314 | pw.println(); |
| 315 | |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 316 | final PackageWithUser pu = mPinnedShortcuts.keyAt(i); |
| 317 | |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 318 | pw.print(prefix); |
| 319 | pw.print(" "); |
| 320 | pw.print("Package: "); |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 321 | pw.print(pu.packageName); |
| 322 | pw.print(" User: "); |
| 323 | pw.println(pu.userId); |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 324 | |
| 325 | final ArraySet<String> ids = mPinnedShortcuts.valueAt(i); |
| 326 | final int idSize = ids.size(); |
| 327 | |
| 328 | for (int j = 0; j < idSize; j++) { |
| 329 | pw.print(prefix); |
Makoto Onuki | 0acbb14 | 2016-03-22 17:02:57 -0700 | [diff] [blame] | 330 | pw.print(" Pinned: "); |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 331 | pw.print(ids.valueAt(j)); |
| 332 | pw.println(); |
| 333 | } |
| 334 | } |
| 335 | } |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 336 | |
Makoto Onuki | 7626992 | 2016-07-15 14:58:54 -0700 | [diff] [blame] | 337 | @Override |
| 338 | public JSONObject dumpCheckin(boolean clear) throws JSONException { |
| 339 | final JSONObject result = super.dumpCheckin(clear); |
| 340 | |
| 341 | // Nothing really interesting to dump. |
| 342 | |
| 343 | return result; |
| 344 | } |
| 345 | |
Makoto Onuki | 2e210c4 | 2016-03-30 08:30:36 -0700 | [diff] [blame] | 346 | @VisibleForTesting |
| 347 | ArraySet<String> getAllPinnedShortcutsForTest(String packageName, int packageUserId) { |
| 348 | return new ArraySet<>(mPinnedShortcuts.get(PackageWithUser.of(packageUserId, packageName))); |
| 349 | } |
Makoto Onuki | 3145924 | 2016-03-22 11:12:18 -0700 | [diff] [blame] | 350 | } |