int getIconMaxDimensions(String packageName, int userId);
void resetThrottling(); // system only API for developer opsions
+
+ byte[] getBackupPayload(int user);
+
+ void applyRestore(in byte[] payload, int user);
}
\ No newline at end of file
/**
* Launcher information used by {@link ShortcutService}.
*/
-class ShortcutLauncher implements ShortcutPackageItem {
+class ShortcutLauncher extends ShortcutPackageItem {
private static final String TAG = ShortcutService.TAG;
static final String TAG_ROOT = "launcher-pins";
private static final String ATTR_VALUE = "value";
private static final String ATTR_PACKAGE_NAME = "package-name";
- @UserIdInt
- private final int mUserId;
-
- @NonNull
- private final String mPackageName;
-
- @UserIdInt
- private final int mLauncherUserId;
+ private final int mOwnerUserId;
/**
* Package name -> IDs.
*/
final private ArrayMap<String, ArraySet<String>> mPinnedShortcuts = new ArrayMap<>();
- ShortcutLauncher(@UserIdInt int userId, @NonNull String packageName,
- @UserIdInt int launcherUserId) {
- mUserId = userId;
- mPackageName = packageName;
- mLauncherUserId = launcherUserId;
+ public ShortcutLauncher(@UserIdInt int ownerUserId, @NonNull String packageName,
+ @UserIdInt int launcherUserId, ShortcutPackageInfo spi) {
+ super(launcherUserId, packageName, spi != null ? spi : ShortcutPackageInfo.newEmpty());
+ mOwnerUserId = ownerUserId;
}
- @UserIdInt
- public int getUserId() {
- return mUserId;
+ public ShortcutLauncher(@UserIdInt int ownerUserId, @NonNull String packageName,
+ @UserIdInt int launcherUserId) {
+ this(launcherUserId, packageName, launcherUserId, null);
}
- @UserIdInt
- public int getLauncherUserId() {
- return mLauncherUserId;
+ @Override
+ public int getOwnerUserId() {
+ return mOwnerUserId;
}
- @NonNull
- public String getPackageName() {
- return mPackageName;
- }
+ public void pinShortcuts(@NonNull ShortcutService s, @UserIdInt int packageUserId,
+ @NonNull String packageName, @NonNull List<String> ids) {
+ final ShortcutPackage packageShortcuts =
+ s.getPackageShortcutsLocked(packageName, packageUserId);
- public void pinShortcuts(@NonNull ShortcutService s, @NonNull String packageName,
- @NonNull List<String> ids) {
final int idSize = ids.size();
if (idSize == 0) {
mPinnedShortcuts.remove(packageName);
// Pin shortcuts. Make sure only pin the ones that were visible to the caller.
// i.e. a non-dynamic, pinned shortcut by *other launchers* shouldn't be pinned here.
- final ShortcutPackage packageShortcuts =
- s.getPackageShortcutsLocked(packageName, mUserId);
final ArraySet<String> newSet = new ArraySet<>();
for (int i = 0; i < idSize; i++) {
}
mPinnedShortcuts.put(packageName, newSet);
}
- s.getPackageShortcutsLocked(packageName, mUserId).refreshPinnedFlags(s);
+ packageShortcuts.refreshPinnedFlags(s);
}
/**
/**
* Persist.
*/
- public void saveToXml(XmlSerializer out, boolean forBackup) throws IOException {
+ @Override
+ public void saveToXml(XmlSerializer out, boolean forBackup)
+ throws IOException {
final int size = mPinnedShortcuts.size();
if (size == 0) {
return; // Nothing to write.
}
out.startTag(null, TAG_ROOT);
- ShortcutService.writeAttr(out, ATTR_PACKAGE_NAME, mPackageName);
- ShortcutService.writeAttr(out, ATTR_LAUNCHER_USER_ID, mLauncherUserId);
+ ShortcutService.writeAttr(out, ATTR_PACKAGE_NAME, getPackageName());
+ ShortcutService.writeAttr(out, ATTR_LAUNCHER_USER_ID, getPackageUserId());
+ getPackageInfo().saveToXml(out);
for (int i = 0; i < size; i++) {
out.startTag(null, TAG_PACKAGE);
/**
* Load.
*/
- public static ShortcutLauncher loadFromXml(XmlPullParser parser, int ownerUserId)
- throws IOException, XmlPullParserException {
+ public static ShortcutLauncher loadFromXml(XmlPullParser parser, int ownerUserId,
+ boolean fromBackup) throws IOException, XmlPullParserException {
final String launcherPackageName = ShortcutService.parseStringAttribute(parser,
ATTR_PACKAGE_NAME);
- final int launcherUserId = ShortcutService.parseIntAttribute(parser,
- ATTR_LAUNCHER_USER_ID, ownerUserId);
+
+ // If restoring, just use the real user ID.
+ final int launcherUserId =
+ fromBackup ? ownerUserId
+ : ShortcutService.parseIntAttribute(parser, ATTR_LAUNCHER_USER_ID, ownerUserId);
final ShortcutLauncher ret = new ShortcutLauncher(launcherUserId, launcherPackageName,
launcherUserId);
+ ShortcutPackageInfo spi = null;
+
ArraySet<String> ids = null;
final int outerDepth = parser.getDepth();
int type;
}
final int depth = parser.getDepth();
final String tag = parser.getName();
- switch (tag) {
- case TAG_PACKAGE: {
- final String packageName = ShortcutService.parseStringAttribute(parser,
- ATTR_PACKAGE_NAME);
- ids = new ArraySet<>();
- ret.mPinnedShortcuts.put(packageName, ids);
- continue;
+ if (depth == outerDepth + 1) {
+ switch (tag) {
+ case ShortcutPackageInfo.TAG_ROOT:
+ spi = ShortcutPackageInfo.loadFromXml(parser);
+ continue;
+ case TAG_PACKAGE: {
+ final String packageName = ShortcutService.parseStringAttribute(parser,
+ ATTR_PACKAGE_NAME);
+ ids = new ArraySet<>();
+ ret.mPinnedShortcuts.put(packageName, ids);
+ continue;
+ }
}
- case TAG_PIN: {
- ids.add(ShortcutService.parseStringAttribute(parser,
- ATTR_VALUE));
- continue;
+ }
+ if (depth == outerDepth + 2) {
+ switch (tag) {
+ case TAG_PIN: {
+ ids.add(ShortcutService.parseStringAttribute(parser,
+ ATTR_VALUE));
+ continue;
+ }
}
}
- throw ShortcutService.throwForInvalidTag(depth, tag);
+ ShortcutService.warnForInvalidTag(depth, tag);
+ }
+ if (spi != null) {
+ ret.replacePackageInfo(spi);
}
return ret;
}
pw.print(prefix);
pw.print("Launcher: ");
- pw.print(mPackageName);
- pw.print(" UserId: ");
- pw.print(mLauncherUserId);
+ pw.print(getPackageName());
+ pw.print(" Package user: ");
+ pw.print(getPackageUserId());
+ pw.println();
+
+ getPackageInfo().dump(s, pw, prefix + " ");
pw.println();
final int size = mPinnedShortcuts.size();
import android.annotation.NonNull;
import android.annotation.Nullable;
-import android.annotation.UserIdInt;
import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.ShortcutInfo;
/**
* Package information used by {@link ShortcutService}.
*/
-class ShortcutPackage implements ShortcutPackageItem {
+class ShortcutPackage extends ShortcutPackageItem {
private static final String TAG = ShortcutService.TAG;
static final String TAG_ROOT = "package";
private static final String ATTR_ICON_RES = "icon-res";
private static final String ATTR_BITMAP_PATH = "bitmap-path";
- @UserIdInt
- private final int mUserId;
-
- @NonNull
- private final String mPackageName;
-
/**
* All the shortcuts from the package, keyed on IDs.
*/
*/
private long mLastResetTime;
- ShortcutPackage(int userId, String packageName) {
- mUserId = userId;
- mPackageName = packageName;
+ public ShortcutPackage(int packageUserId, String packageName, ShortcutPackageInfo spi) {
+ super(packageUserId, packageName, spi != null ? spi : ShortcutPackageInfo.newEmpty());
}
- @UserIdInt
- public int getUserId() {
- return mUserId;
+ public ShortcutPackage(int packageUserId, String packageName) {
+ this(packageUserId, packageName, null);
}
- @NonNull
- public String getPackageName() {
- return mPackageName;
+ @Override
+ public int getOwnerUserId() {
+ // For packages, always owner user == package user.
+ return getPackageUserId();
}
/**
@NonNull String id) {
final ShortcutInfo shortcut = mShortcuts.remove(id);
if (shortcut != null) {
- s.removeIcon(mUserId, shortcut);
+ s.removeIcon(getPackageUserId(), shortcut);
shortcut.clearFlags(ShortcutInfo.FLAG_DYNAMIC | ShortcutInfo.FLAG_PINNED);
}
return shortcut;
void addShortcut(@NonNull ShortcutService s, @NonNull ShortcutInfo newShortcut) {
deleteShortcut(s, newShortcut.getId());
- s.saveIconAndFixUpShortcut(mUserId, newShortcut);
+ s.saveIconAndFixUpShortcut(getPackageUserId(), newShortcut);
mShortcuts.put(newShortcut.getId(), newShortcut);
}
// Then, for the pinned set for each launcher, set the pin flag one by one.
final ArrayMap<ShortcutUser.PackageWithUser, ShortcutLauncher> launchers =
- s.getUserShortcutsLocked(mUserId).getAllLaunchers();
+ s.getUserShortcutsLocked(getPackageUserId()).getAllLaunchers();
for (int l = launchers.size() - 1; l >= 0; l--) {
final ShortcutLauncher launcherShortcuts = launchers.valueAt(l);
- final ArraySet<String> pinned = launcherShortcuts.getPinnedShortcutIds(mPackageName);
+ final ArraySet<String> pinned = launcherShortcuts.getPinnedShortcutIds(
+ getPackageName());
if (pinned == null || pinned.size() == 0) {
continue;
// Set of pinned shortcuts by the calling launcher.
final ArraySet<String> pinnedByCallerSet = (callingLauncher == null) ? null
- : s.getLauncherShortcuts(callingLauncher, mUserId, launcherUserId)
- .getPinnedShortcutIds(mPackageName);
+ : s.getLauncherShortcuts(callingLauncher, getPackageUserId(), launcherUserId)
+ .getPinnedShortcutIds(getPackageName());
for (int i = 0; i < mShortcuts.size(); i++) {
final ShortcutInfo si = mShortcuts.valueAt(i);
pw.print(prefix);
pw.print("Package: ");
- pw.print(mPackageName);
+ pw.print(getPackageName());
pw.println();
pw.print(prefix);
pw.print(s.formatTime(mLastResetTime));
pw.println();
+ getPackageInfo().dump(s, pw, prefix + " ");
+ pw.println();
+
pw.println(" Shortcuts:");
long totalBitmapSize = 0;
final ArrayMap<String, ShortcutInfo> shortcuts = mShortcuts;
pw.println(")");
}
+ @Override
public void saveToXml(@NonNull XmlSerializer out, boolean forBackup)
throws IOException, XmlPullParserException {
final int size = mShortcuts.size();
out.startTag(null, TAG_ROOT);
- ShortcutService.writeAttr(out, ATTR_NAME, mPackageName);
+ ShortcutService.writeAttr(out, ATTR_NAME, getPackageName());
ShortcutService.writeAttr(out, ATTR_DYNAMIC_COUNT, mDynamicShortcutCount);
ShortcutService.writeAttr(out, ATTR_CALL_COUNT, mApiCallCount);
ShortcutService.writeAttr(out, ATTR_LAST_RESET, mLastResetTime);
+ getPackageInfo().saveToXml(out);
for (int j = 0; j < size; j++) {
saveShortcut(out, mShortcuts.valueAt(j), forBackup);
out.endTag(null, TAG_SHORTCUT);
}
- public static ShortcutPackage loadFromXml(XmlPullParser parser, int userId)
+ public static ShortcutPackage loadFromXml(ShortcutService s, XmlPullParser parser,
+ int ownerUserId, boolean fromBackup)
throws IOException, XmlPullParserException {
final String packageName = ShortcutService.parseStringAttribute(parser,
ATTR_NAME);
- final ShortcutPackage ret = new ShortcutPackage(userId, packageName);
+ final ShortcutPackage ret = new ShortcutPackage(ownerUserId, packageName);
ret.mDynamicShortcutCount =
ShortcutService.parseIntAttribute(parser, ATTR_DYNAMIC_COUNT);
ShortcutService.parseIntAttribute(parser, ATTR_CALL_COUNT);
ret.mLastResetTime =
ShortcutService.parseLongAttribute(parser, ATTR_LAST_RESET);
+ ShortcutPackageInfo spi = null;
final int outerDepth = parser.getDepth();
int type;
}
final int depth = parser.getDepth();
final String tag = parser.getName();
- switch (tag) {
- case TAG_SHORTCUT:
- final ShortcutInfo si = parseShortcut(parser, packageName);
-
- // Don't use addShortcut(), we don't need to save the icon.
- ret.mShortcuts.put(si.getId(), si);
- continue;
+ if (depth == outerDepth + 1) {
+ switch (tag) {
+ case ShortcutPackageInfo.TAG_ROOT:
+ spi = ShortcutPackageInfo.loadFromXml(parser);
+ continue;
+ case TAG_SHORTCUT:
+ final ShortcutInfo si = parseShortcut(parser, packageName);
+
+ // Don't use addShortcut(), we don't need to save the icon.
+ ret.mShortcuts.put(si.getId(), si);
+ continue;
+ }
}
- throw ShortcutService.throwForInvalidTag(depth, tag);
+ ShortcutService.warnForInvalidTag(depth, tag);
+ }
+ if (spi != null) {
+ ret.replacePackageInfo(spi);
}
return ret;
}
title = ShortcutService.parseStringAttribute(parser, ATTR_TITLE);
intent = ShortcutService.parseIntentAttribute(parser, ATTR_INTENT);
weight = (int) ShortcutService.parseLongAttribute(parser, ATTR_WEIGHT);
- lastChangedTimestamp = (int) ShortcutService.parseLongAttribute(parser,
- ATTR_TIMESTAMP);
+ lastChangedTimestamp = ShortcutService.parseLongAttribute(parser, ATTR_TIMESTAMP);
flags = (int) ShortcutService.parseLongAttribute(parser, ATTR_FLAGS);
iconRes = (int) ShortcutService.parseLongAttribute(parser, ATTR_ICON_RES);
bitmapPath = ShortcutService.parseStringAttribute(parser, ATTR_BITMAP_PATH);
*/
package com.android.server.pm;
-import android.annotation.NonNull;
import android.annotation.UserIdInt;
-import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
-import android.content.pm.Signature;
import android.util.Slog;
-import com.android.internal.util.Preconditions;
+import com.android.server.backup.BackupUtils;
import libcore.io.Base64;
import libcore.util.HexEncoding;
import java.io.IOException;
import java.io.PrintWriter;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
-import java.util.Arrays;
/**
* Package information used by {@link android.content.pm.ShortcutManager} for backup / restore.
- *
- * TODO: The methods about signature hashes are copied from BackupManagerService, which is not
- * visible here. Unify the code.
*/
-class ShortcutPackageInfo implements ShortcutPackageItem {
+class ShortcutPackageInfo {
private static final String TAG = ShortcutService.TAG;
static final String TAG_ROOT = "package-info";
- private static final String ATTR_USER_ID = "user";
- private static final String ATTR_NAME = "name";
private static final String ATTR_VERSION = "version";
private static final String ATTR_SHADOW = "shadow";
private static final String TAG_SIGNATURE = "signature";
private static final String ATTR_SIGNATURE_HASH = "hash";
- private final String mPackageName;
- private final int mUserId;
-
/**
* When true, this package information was restored from the previous device, and the app hasn't
* been installed yet.
private int mVersionCode;
private ArrayList<byte[]> mSigHashes;
- private ShortcutPackageInfo(String packageName, int userId,
- int versionCode, ArrayList<byte[]> sigHashes, boolean isShadow) {
- mPackageName = Preconditions.checkNotNull(packageName);
- mUserId = userId;
+ private ShortcutPackageInfo(int versionCode, ArrayList<byte[]> sigHashes, boolean isShadow) {
mVersionCode = versionCode;
mIsShadow = isShadow;
mSigHashes = sigHashes;
}
- @NonNull
- public String getPackageName() {
- return mPackageName;
- }
-
- public int getUserId() {
- return mUserId;
+ public static ShortcutPackageInfo newEmpty() {
+ return new ShortcutPackageInfo(0, new ArrayList<>(0), /* isShadow */ false);
}
public boolean isShadow() {
return mVersionCode;
}
- private static byte[] hashSignature(Signature sig) {
- try {
- MessageDigest digest = MessageDigest.getInstance("SHA-256");
- digest.update(sig.toByteArray());
- return digest.digest();
- } catch (NoSuchAlgorithmException e) {
- Slog.w(TAG, "No SHA-256 algorithm found!");
- }
- return null;
- }
-
- private static ArrayList<byte[]> hashSignatureArray(Signature[] sigs) {
- if (sigs == null) {
- return null;
- }
-
- ArrayList<byte[]> hashes = new ArrayList<byte[]>(sigs.length);
- for (Signature s : sigs) {
- hashes.add(hashSignature(s));
- }
- return hashes;
- }
-
- private static boolean signaturesMatch(ArrayList<byte[]> storedSigHashes, PackageInfo target) {
- if (target == null) {
- return false;
- }
-
- // If the target resides on the system partition, we allow it to restore
- // data from the like-named package in a restore set even if the signatures
- // do not match. (Unlike general applications, those flashed to the system
- // partition will be signed with the device's platform certificate, so on
- // different phones the same system app will have different signatures.)
- if ((target.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
- return true;
- }
-
- // Allow unsigned apps, but not signed on one device and unsigned on the other
- // !!! TODO: is this the right policy?
- Signature[] deviceSigs = target.signatures;
- if ((storedSigHashes == null || storedSigHashes.size() == 0)
- && (deviceSigs == null || deviceSigs.length == 0)) {
- return true;
- }
- if (storedSigHashes == null || deviceSigs == null) {
- return false;
- }
-
- // !!! TODO: this demands that every stored signature match one
- // that is present on device, and does not demand the converse.
- // Is this this right policy?
- final int nStored = storedSigHashes.size();
- final int nDevice = deviceSigs.length;
-
- // hash each on-device signature
- ArrayList<byte[]> deviceHashes = new ArrayList<byte[]>(nDevice);
- for (int i = 0; i < nDevice; i++) {
- deviceHashes.add(hashSignature(deviceSigs[i]));
- }
-
- // now ensure that each stored sig (hash) matches an on-device sig (hash)
- for (int n = 0; n < nStored; n++) {
- boolean match = false;
- final byte[] storedHash = storedSigHashes.get(n);
- for (int i = 0; i < nDevice; i++) {
- if (Arrays.equals(storedHash, deviceHashes.get(i))) {
- match = true;
- break;
- }
- }
- // match is false when no on-device sig matched one of the stored ones
- if (!match) {
- return false;
- }
- }
-
- return true;
- }
-
public boolean canRestoreTo(PackageInfo target) {
if (target.versionCode < mVersionCode) {
Slog.w(TAG, String.format("Package current version %d < backed up version %d",
target.versionCode, mVersionCode));
return false;
}
- if (!signaturesMatch(mSigHashes, target)) {
+ if (!BackupUtils.signaturesMatch(mSigHashes, target)) {
Slog.w(TAG, "Package signature mismtach");
return false;
}
}
public static ShortcutPackageInfo generateForInstalledPackage(
- ShortcutService s, String packageName, @UserIdInt int userId) {
- final PackageInfo pi = s.getPackageInfoWithSignatures(packageName, userId);
+ ShortcutService s, String packageName, @UserIdInt int packageUserId) {
+ final PackageInfo pi = s.getPackageInfoWithSignatures(packageName, packageUserId);
if (pi.signatures == null || pi.signatures.length == 0) {
Slog.e(TAG, "Can't get signatures: package=" + packageName);
return null;
}
- final ShortcutPackageInfo ret = new ShortcutPackageInfo(packageName, userId, pi.versionCode,
- hashSignatureArray(pi.signatures), /* shadow=*/ false);
+ final ShortcutPackageInfo ret = new ShortcutPackageInfo(pi.versionCode,
+ BackupUtils.hashSignatureArray(pi.signatures), /* shadow=*/ false);
return ret;
}
- public void refreshAndSave(ShortcutService s, @UserIdInt int userId) {
- final PackageInfo pi = s.getPackageInfoWithSignatures(mPackageName, userId);
+ public void refresh(ShortcutService s, ShortcutPackageItem pkg) {
+ // Note use mUserId here, rather than userId.
+ final PackageInfo pi = s.getPackageInfoWithSignatures(
+ pkg.getPackageName(), pkg.getPackageUserId());
if (pi == null) {
- Slog.w(TAG, "Package not found: " + mPackageName);
+ Slog.w(TAG, "Package not found: " + pkg.getPackageName());
return;
}
mVersionCode = pi.versionCode;
- mSigHashes = hashSignatureArray(pi.signatures);
-
- s.scheduleSaveUser(userId);
+ mSigHashes = BackupUtils.hashSignatureArray(pi.signatures);
}
- public void saveToXml(XmlSerializer out, boolean forBackup)
- throws IOException, XmlPullParserException {
+ public void saveToXml(XmlSerializer out) throws IOException {
out.startTag(null, TAG_ROOT);
- ShortcutService.writeAttr(out, ATTR_NAME, mPackageName);
- ShortcutService.writeAttr(out, ATTR_USER_ID, mUserId);
ShortcutService.writeAttr(out, ATTR_VERSION, mVersionCode);
ShortcutService.writeAttr(out, ATTR_SHADOW, mIsShadow);
out.endTag(null, TAG_ROOT);
}
- public static ShortcutPackageInfo loadFromXml(XmlPullParser parser, int ownerUserId)
+ public static ShortcutPackageInfo loadFromXml(XmlPullParser parser)
throws IOException, XmlPullParserException {
- final String packageName = ShortcutService.parseStringAttribute(parser, ATTR_NAME);
- final int userId = ShortcutService.parseIntAttribute(parser, ATTR_USER_ID, ownerUserId);
final int versionCode = ShortcutService.parseIntAttribute(parser, ATTR_VERSION);
final boolean shadow = ShortcutService.parseBooleanAttribute(parser, ATTR_SHADOW);
}
final int depth = parser.getDepth();
final String tag = parser.getName();
- switch (tag) {
- case TAG_SIGNATURE: {
- final String hash = ShortcutService.parseStringAttribute(
- parser, ATTR_SIGNATURE_HASH);
- hashes.add(Base64.decode(hash.getBytes()));
- continue;
+
+ if (depth == outerDepth + 1) {
+ switch (tag) {
+ case TAG_SIGNATURE: {
+ final String hash = ShortcutService.parseStringAttribute(
+ parser, ATTR_SIGNATURE_HASH);
+ hashes.add(Base64.decode(hash.getBytes()));
+ continue;
+ }
}
}
- throw ShortcutService.throwForInvalidTag(depth, tag);
+ ShortcutService.warnForInvalidTag(depth, tag);
}
- return new ShortcutPackageInfo(packageName, userId, versionCode, hashes, shadow);
+ return new ShortcutPackageInfo(versionCode, hashes, shadow);
}
public void dump(ShortcutService s, PrintWriter pw, String prefix) {
pw.println();
pw.print(prefix);
- pw.print("PackageInfo: ");
- pw.print(mPackageName);
- pw.println();
-
- pw.print(prefix);
- pw.print(" User: ");
- pw.print(mUserId);
- pw.println();
+ pw.println("PackageInfo:");
pw.print(prefix);
pw.print(" IsShadow: ");
import android.annotation.NonNull;
+import com.android.internal.util.Preconditions;
+
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;
import java.io.IOException;
-public interface ShortcutPackageItem {
+abstract class ShortcutPackageItem {
+ private final int mPackageUserId;
+ private final String mPackageName;
+
+ private ShortcutPackageInfo mPackageInfo;
+
+ protected ShortcutPackageItem(int packageUserId, @NonNull String packageName,
+ @NonNull ShortcutPackageInfo packageInfo) {
+ mPackageUserId = packageUserId;
+ mPackageName = Preconditions.checkStringNotEmpty(packageName);
+ mPackageInfo = Preconditions.checkNotNull(packageInfo);
+ }
+
+ /**
+ * ID of the user who actually has this package running on. For {@link ShortcutPackage},
+ * this is the same thing as {@link #getOwnerUserId}, but if it's a {@link ShortcutLauncher} and
+ * {@link #getOwnerUserId} is of a work profile, then this ID could be the user who owns the
+ * profile.
+ */
+ public int getPackageUserId() {
+ return mPackageUserId;
+ }
+
+ /**
+ * ID of the user who sees the shortcuts from this instance.
+ */
+ public abstract int getOwnerUserId();
+
@NonNull
- String getPackageName();
+ public String getPackageName() {
+ return mPackageName;
+ }
+
+ public ShortcutPackageInfo getPackageInfo() {
+ return mPackageInfo;
+ }
+
+ /**
+ * Should be only used when loading from a file.o
+ */
+ protected void replacePackageInfo(@NonNull ShortcutPackageInfo packageInfo) {
+ mPackageInfo = Preconditions.checkNotNull(packageInfo);
+ }
+
+ public void refreshPackageInfoAndSave(ShortcutService s) {
+ mPackageInfo.refresh(s, this);
+ s.scheduleSaveUser(getOwnerUserId());
+ }
+
+ public void ensureNotShadowAndSave(ShortcutService s) {
+ if (mPackageInfo.isShadow()) {
+ mPackageInfo.setShadow(false);
+ s.scheduleSaveUser(getOwnerUserId());
+ }
+ }
- void saveToXml(@NonNull XmlSerializer out, boolean forBackup)
+ public abstract void saveToXml(@NonNull XmlSerializer out, boolean forBackup)
throws IOException, XmlPullParserException;
}
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.content.PackageMonitor;
import com.android.internal.os.BackgroundThread;
-import com.android.internal.util.ArrayUtils;
import com.android.internal.util.FastXmlSerializer;
import com.android.internal.util.Preconditions;
import com.android.server.LocalServices;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
*
* - Default launcher check does take a few ms. Worth caching.
*
- * - Don't backup launcher from different profile.
- *
* - Clear data -> remove all dynamic? but not the pinned?
*
* - Scan and remove orphan bitmaps (just in case).
}
path.mkdirs();
final AtomicFile file = new AtomicFile(path);
- FileOutputStream outs = null;
+ FileOutputStream os = null;
try {
- outs = file.startWrite();
-
- // Write to XML
- XmlSerializer out = new FastXmlSerializer();
- out.setOutput(outs, StandardCharsets.UTF_8.name());
- out.startDocument(null, true);
+ os = file.startWrite();
- getUserShortcutsLocked(userId).saveToXml(this, out, /* forBackup= */ false);
+ saveUserInternalLocked(userId, os, /* forBackup= */ false);
- out.endDocument();
-
- // Close.
- file.finishWrite(outs);
- } catch (IOException|XmlPullParserException e) {
+ file.finishWrite(os);
+ } catch (XmlPullParserException|IOException e) {
Slog.e(TAG, "Failed to write to file " + file.getBaseFile(), e);
- file.failWrite(outs);
+ file.failWrite(os);
}
}
+ private void saveUserInternalLocked(@UserIdInt int userId, OutputStream os,
+ boolean forBackup) throws IOException, XmlPullParserException {
+
+ final BufferedOutputStream bos = new BufferedOutputStream(os);
+
+ // Write to XML
+ XmlSerializer out = new FastXmlSerializer();
+ out.setOutput(bos, StandardCharsets.UTF_8.name());
+ out.startDocument(null, true);
+
+ getUserShortcutsLocked(userId).saveToXml(this, out, forBackup);
+
+ out.endDocument();
+
+ bos.flush();
+ os.flush();
+ }
+
static IOException throwForInvalidTag(int depth, String tag) throws IOException {
throw new IOException(String.format("Invalid tag '%s' found at depth %d", tag, depth));
}
+ static void warnForInvalidTag(int depth, String tag) throws IOException {
+ Slog.w(TAG, String.format("Invalid tag '%s' found at depth %d", tag, depth));
+ }
+
@Nullable
private ShortcutUser loadUserLocked(@UserIdInt int userId) {
final File path = new File(injectUserDataPath(userId), FILENAME_USER_PACKAGES);
}
return null;
}
- ShortcutUser ret = null;
try {
- XmlPullParser parser = Xml.newPullParser();
- parser.setInput(in, StandardCharsets.UTF_8.name());
-
- int type;
- while ((type = parser.next()) != XmlPullParser.END_DOCUMENT) {
- if (type != XmlPullParser.START_TAG) {
- continue;
- }
- final int depth = parser.getDepth();
-
- final String tag = parser.getName();
- if (DEBUG_LOAD) {
- Slog.d(TAG, String.format("depth=%d type=%d name=%s",
- depth, type, tag));
- }
- if ((depth == 1) && ShortcutUser.TAG_ROOT.equals(tag)) {
- ret = ShortcutUser.loadFromXml(parser, userId);
- continue;
- }
- throwForInvalidTag(depth, tag);
- }
- return ret;
+ return loadUserInternal(userId, in, /* forBackup= */ false);
} catch (IOException|XmlPullParserException e) {
Slog.e(TAG, "Failed to read file " + file.getBaseFile(), e);
return null;
}
}
+ private ShortcutUser loadUserInternal(@UserIdInt int userId, InputStream is,
+ boolean fromBackup) throws XmlPullParserException, IOException {
+
+ final BufferedInputStream bis = new BufferedInputStream(is);
+
+ ShortcutUser ret = null;
+ XmlPullParser parser = Xml.newPullParser();
+ parser.setInput(bis, StandardCharsets.UTF_8.name());
+
+ int type;
+ while ((type = parser.next()) != XmlPullParser.END_DOCUMENT) {
+ if (type != XmlPullParser.START_TAG) {
+ continue;
+ }
+ final int depth = parser.getDepth();
+
+ final String tag = parser.getName();
+ if (DEBUG_LOAD) {
+ Slog.d(TAG, String.format("depth=%d type=%d name=%s",
+ depth, type, tag));
+ }
+ if ((depth == 1) && ShortcutUser.TAG_ROOT.equals(tag)) {
+ ret = ShortcutUser.loadFromXml(this, parser, userId, fromBackup);
+ continue;
+ }
+ throwForInvalidTag(depth, tag);
+ }
+ return ret;
+ }
+
private void scheduleSaveBaseState() {
scheduleSaveInner(UserHandle.USER_NULL); // Special case -- use USER_NULL for base state.
}
Preconditions.checkState(isCallerShell(), "Caller must be shell");
}
+ private void enforceSystem() {
+ Preconditions.checkState(isCallerSystem(), "Caller must be system");
+ }
+
private void verifyCaller(@NonNull String packageName, @UserIdInt int userId) {
Preconditions.checkStringNotEmpty(packageName, "packageName");
final int size = newShortcuts.size();
synchronized (mLock) {
- getUserShortcutsLocked(userId).ensurePackageInfo(this, packageName, userId);
-
final ShortcutPackage ps = getPackageShortcutsLocked(packageName, userId);
+ ps.ensureNotShadowAndSave(this);
+
// Throttling.
if (!ps.tryApiCall(this)) {
return false;
final int size = newShortcuts.size();
synchronized (mLock) {
- getUserShortcutsLocked(userId).ensurePackageInfo(this, packageName, userId);
-
final ShortcutPackage ps = getPackageShortcutsLocked(packageName, userId);
+ ps.ensureNotShadowAndSave(this);
+
// Throttling.
if (!ps.tryApiCall(this)) {
return false;
verifyCaller(packageName, userId);
synchronized (mLock) {
- getUserShortcutsLocked(userId).ensurePackageInfo(this, packageName, userId);
-
final ShortcutPackage ps = getPackageShortcutsLocked(packageName, userId);
+ ps.ensureNotShadowAndSave(this);
+
// Throttling.
if (!ps.tryApiCall(this)) {
return false;
@VisibleForTesting
void cleanUpPackageLocked(String packageName, int owningUserId, int packageUserId) {
+
+ // TODO Don't remove shadow packages' information.
+
final boolean wasUserLoaded = isUserLoadedLocked(owningUserId);
final ShortcutUser mUser = getUserShortcutsLocked(owningUserId);
mUser.getPackages().valueAt(i).refreshPinnedFlags(this);
}
- // Remove the package info too.
- mUser.removePackageInfo(packageUserId, packageName);
-
scheduleSaveUser(owningUserId);
if (doNotify) {
Preconditions.checkNotNull(shortcutIds, "shortcutIds");
synchronized (mLock) {
- getUserShortcutsLocked(userId).ensurePackageInfo(
- ShortcutService.this, callingPackage, launcherUserId);
+ final ShortcutLauncher launcher =
+ getLauncherShortcuts(callingPackage, userId, launcherUserId);
- getLauncherShortcuts(callingPackage, userId, launcherUserId).pinShortcuts(
- ShortcutService.this, packageName, shortcutIds);
+ launcher.ensureNotShadowAndSave(ShortcutService.this);
+
+ launcher.pinShortcuts(
+ ShortcutService.this, userId, packageName, shortcutIds);
}
userPackageChanged(packageName, userId);
}
if (DEBUG) {
Slog.d(TAG, "cleanupGonePackages() userId=" + userId);
}
- ArrayList<PackageWithUser> gonePackages = null;
+ final ArrayList<PackageWithUser> gonePackages = new ArrayList<>();
synchronized (mLock) {
final ShortcutUser user = getUserShortcutsLocked(userId);
- final ArrayMap<PackageWithUser, ShortcutPackageInfo> infos = user.getAllPackageInfos();
- for (int i = infos.size() -1; i >= 0; i--) {
- final ShortcutPackageInfo info = infos.valueAt(i);
- if (info.isShadow()) {
- continue;
+
+ user.forAllPackageItems(spi -> {
+ if (spi.getPackageInfo().isShadow()) {
+ return; // Don't delete shadow information.
}
- if (isPackageInstalled(info.getPackageName(), info.getUserId())) {
- continue;
+ if (isPackageInstalled(spi.getPackageName(), spi.getPackageUserId())) {
+ return;
}
- gonePackages = ArrayUtils.add(gonePackages,
- PackageWithUser.of(info.getUserId(), info.getPackageName()));
- }
- if (gonePackages != null) {
+ gonePackages.add(PackageWithUser.of(spi));
+ });
+ if (gonePackages.size() > 0) {
for (int i = gonePackages.size() - 1; i >= 0; i--) {
final PackageWithUser pu = gonePackages.get(i);
cleanUpPackageLocked(pu.packageName, userId, pu.userId);
Slog.d(TAG, String.format("handlePackageAdded: %s user=%d", packageName, userId));
}
synchronized (mLock) {
- final ShortcutPackageInfo existing = getUserShortcutsLocked(userId)
- .getPackageInfo(userId, packageName);
-
- if (existing != null && existing.isShadow()) {
- Slog.w(TAG, "handlePackageAdded: TODO Restore not implemented");
- }
+ getUserShortcutsLocked(userId).unshadowPackage(this, packageName, userId);
}
}
private void handlePackageUpdateFinished(String packageName, @UserIdInt int userId) {
if (DEBUG) {
- Slog.d(TAG, String.format("handlePackageUpdateFinished: %s user=%d", packageName, userId));
+ Slog.d(TAG, String.format("handlePackageUpdateFinished: %s user=%d",
+ packageName, userId));
}
+
synchronized (mLock) {
- final ShortcutPackageInfo spi =
- getUserShortcutsLocked(userId).getPackageInfo(userId, packageName);
- if (spi != null) {
- spi.refreshAndSave(this, userId);
- }
+ getUserShortcutsLocked(userId).unshadowPackage(this, packageName, userId);
}
}
}
}
- // === Backup & restore ===
+ // === PackageManager interaction ===
PackageInfo getPackageInfoWithSignatures(String packageName, @UserIdInt int userId) {
return injectPackageInfo(packageName, userId, true);
}
int injectGetPackageUid(@NonNull String packageName, @UserIdInt int userId) {
+ final long token = injectClearCallingIdentity();
try {
return mIPackageManager.getPackageUid(packageName, PACKAGE_MATCH_FLAGS
, userId);
// Shouldn't happen.
Slog.wtf(TAG, "RemoteException", e);
return -1;
+ } finally {
+ injectRestoreCallingIdentity(token);
}
}
@VisibleForTesting
PackageInfo injectPackageInfo(String packageName, @UserIdInt int userId,
boolean getSignatures) {
+ final long token = injectClearCallingIdentity();
try {
return mIPackageManager.getPackageInfo(packageName, PACKAGE_MATCH_FLAGS
| (getSignatures ? PackageManager.GET_SIGNATURES : 0)
// Shouldn't happen.
Slog.wtf(TAG, "RemoteException", e);
return null;
+ } finally {
+ injectRestoreCallingIdentity(token);
}
}
@VisibleForTesting
ApplicationInfo injectApplicationInfo(String packageName, @UserIdInt int userId) {
+ final long token = injectClearCallingIdentity();
try {
return mIPackageManager.getApplicationInfo(packageName, PACKAGE_MATCH_FLAGS, userId);
} catch (RemoteException e) {
// Shouldn't happen.
Slog.wtf(TAG, "RemoteException", e);
return null;
+ } finally {
+ injectRestoreCallingIdentity(token);
}
}
return (ai != null) && ((ai.flags & flags) == flags);
}
+ private boolean isPackageInstalled(String packageName, int userId) {
+ return isApplicationFlagSet(packageName, userId, ApplicationInfo.FLAG_INSTALLED);
+ }
+
+ // === Backup & restore ===
+
boolean shouldBackupApp(String packageName, int userId) {
return isApplicationFlagSet(packageName, userId, ApplicationInfo.FLAG_ALLOW_BACKUP);
}
- private boolean isPackageInstalled(String packageName, int userId) {
- return isApplicationFlagSet(packageName, userId, ApplicationInfo.FLAG_INSTALLED);
+ @Override
+ public byte[] getBackupPayload(@UserIdInt int userId) throws RemoteException {
+ enforceSystem();
+ if (DEBUG) {
+ Slog.d(TAG, "Backing up user " + userId);
+ }
+ synchronized (mLock) {
+ final ShortcutUser user = getUserShortcutsLocked(userId);
+ if (user == null) {
+ Slog.w(TAG, "Can't backup: user not found: id=" + userId);
+ return null;
+ }
+
+ user.forAllPackageItems(spi -> spi.refreshPackageInfoAndSave(this));
+
+ // Then save.
+ final ByteArrayOutputStream os = new ByteArrayOutputStream(32 * 1024);
+ try {
+ saveUserInternalLocked(userId, os, /* forBackup */ true);
+ } catch (XmlPullParserException|IOException e) {
+ // Shouldn't happen.
+ Slog.w(TAG, "Backup failed.", e);
+ return null;
+ }
+ return os.toByteArray();
+ }
+ }
+
+ @Override
+ public void applyRestore(byte[] payload, @UserIdInt int userId) throws RemoteException {
+ enforceSystem();
+ if (DEBUG) {
+ Slog.d(TAG, "Restoring user " + userId);
+ }
+ final ShortcutUser user;
+ final ByteArrayInputStream is = new ByteArrayInputStream(payload);
+ try {
+ user = loadUserInternal(userId, is, /* fromBackup */ true);
+ } catch (XmlPullParserException|IOException e) {
+ Slog.w(TAG, "Restoration failed.", e);
+ return;
+ }
+ synchronized (mLock) {
+ mUsers.put(userId, user);
+ }
}
// === Dump ===
return pkg.findShortcutById(shortcutId);
}
}
-
- @VisibleForTesting
- ShortcutPackageInfo getPackageInfoForTest(String packageName, int userId) {
- return getPackageInfoForTest(packageName, userId, userId);
- }
-
- @VisibleForTesting
- ShortcutPackageInfo getPackageInfoForTest(String packageName, int userId, int packageUserId) {
- synchronized (mLock) {
- final ShortcutUser user = mUsers.get(userId);
- if (user == null) return null;
-
- return user.getPackageInfo(packageUserId, packageName);
- }
- }
}
import java.io.IOException;
import java.io.PrintWriter;
+import java.util.function.Consumer;
/**
* User information used by {@link ShortcutService}.
return new PackageWithUser(launcherUserId, packageName);
}
+ public static PackageWithUser of(ShortcutPackageItem spi) {
+ return new PackageWithUser(spi.getPackageUserId(), spi.getPackageName());
+ }
+
@Override
public int hashCode() {
return packageName.hashCode() ^ userId;
private final ArrayMap<PackageWithUser, ShortcutLauncher> mLaunchers = new ArrayMap<>();
- private final ArrayMap<PackageWithUser, ShortcutPackageInfo> mPackageInfos = new ArrayMap<>();
-
private ComponentName mLauncherComponent;
public ShortcutUser(int userId) {
return mLaunchers;
}
- public ShortcutLauncher getLauncher(@UserIdInt int userId, @NonNull String packageName) {
- return mLaunchers.get(PackageWithUser.of(userId, packageName));
- }
-
public void addLauncher(ShortcutLauncher launcher) {
- mLaunchers.put(PackageWithUser.of(launcher.getUserId(), launcher.getPackageName()),
- launcher);
+ mLaunchers.put(PackageWithUser.of(launcher.getPackageUserId(),
+ launcher.getPackageName()), launcher);
}
public ShortcutLauncher removeLauncher(
- @UserIdInt int userId, @NonNull String packageName) {
- return mLaunchers.remove(PackageWithUser.of(userId, packageName));
- }
-
- public ArrayMap<PackageWithUser, ShortcutPackageInfo> getAllPackageInfos() {
- return mPackageInfos;
- }
-
- public ShortcutPackageInfo getPackageInfo(@UserIdInt int userId, @NonNull String packageName) {
- return mPackageInfos.get(PackageWithUser.of(userId, packageName));
- }
-
- public void addPackageInfo(ShortcutPackageInfo spi) {
- mPackageInfos.put(PackageWithUser.of(spi.getUserId(), spi.getPackageName()), spi);
- }
-
- public ShortcutPackageInfo removePackageInfo(
- @UserIdInt int userId, @NonNull String packageName) {
- return mPackageInfos.remove(PackageWithUser.of(userId, packageName));
+ @UserIdInt int packageUserId, @NonNull String packageName) {
+ return mLaunchers.remove(PackageWithUser.of(packageUserId, packageName));
}
public ShortcutPackage getPackageShortcuts(@NonNull String packageName) {
return ret;
}
- public void ensurePackageInfo(ShortcutService s, String packageName, @UserIdInt int userId) {
- final PackageWithUser key = PackageWithUser.of(userId, packageName);
- final ShortcutPackageInfo existing = mPackageInfos.get(key);
-
- if (existing != null) {
- return;
+ public void forAllPackageItems(Consumer<ShortcutPackageItem> callback) {
+ {
+ final int size = mLaunchers.size();
+ for (int i = 0; i < size; i++) {
+ callback.accept(mLaunchers.valueAt(i));
+ }
}
- if (ShortcutService.DEBUG) {
- Slog.d(TAG, String.format("Fetching package info: %s user=%d", packageName, userId));
+ {
+ final int size = mPackages.size();
+ for (int i = 0; i < size; i++) {
+ callback.accept(mPackages.valueAt(i));
+ }
}
- final ShortcutPackageInfo newSpi = ShortcutPackageInfo.generateForInstalledPackage(
- s, packageName, userId);
- mPackageInfos.put(key, newSpi);
- s.scheduleSaveUser(mUserId);
+ }
+
+ public void unshadowPackage(ShortcutService s, @NonNull String packageName,
+ @UserIdInt int packageUserId) {
+ forPackageItem(packageName, packageUserId, spi -> {
+ Slog.i(TAG, String.format("Restoring for %s, user=%d", packageName, packageUserId));
+ spi.ensureNotShadowAndSave(s);
+ });
+ }
+
+ public void forPackageItem(@NonNull String packageName, @UserIdInt int packageUserId,
+ Consumer<ShortcutPackageItem> callback) {
+ forAllPackageItems(spi -> {
+ if ((spi.getPackageUserId() == packageUserId)
+ && spi.getPackageName().equals(packageName)) {
+ callback.accept(spi);
+ }
+ });
}
public void saveToXml(ShortcutService s, XmlSerializer out, boolean forBackup)
ShortcutService.writeTagValue(out, TAG_LAUNCHER,
mLauncherComponent);
- {
- final int size = mPackageInfos.size();
- for (int i = 0; i < size; i++) {
- saveShortcutPackageItem(s, out, mPackageInfos.valueAt(i), forBackup);
- }
- }
+ // Can't use forEachPackageItem due to the checked exceptions.
{
final int size = mLaunchers.size();
for (int i = 0; i < size; i++) {
private void saveShortcutPackageItem(ShortcutService s, XmlSerializer out,
ShortcutPackageItem spi, boolean forBackup) throws IOException, XmlPullParserException {
- if (forBackup && !s.shouldBackupApp(spi.getPackageName(), mUserId)) {
- return; // Don't save.
+ if (forBackup) {
+ if (!s.shouldBackupApp(spi.getPackageName(), spi.getPackageUserId())) {
+ return; // Don't save.
+ }
+ if (spi.getPackageUserId() != spi.getOwnerUserId()) {
+ return; // Don't save cross-user information.
+ }
}
spi.saveToXml(out, forBackup);
}
- public static ShortcutUser loadFromXml(XmlPullParser parser, int userId)
- throws IOException, XmlPullParserException {
+ public static ShortcutUser loadFromXml(ShortcutService s, XmlPullParser parser, int userId,
+ boolean fromBackup) throws IOException, XmlPullParserException {
final ShortcutUser ret = new ShortcutUser(userId);
final int outerDepth = parser.getDepth();
}
final int depth = parser.getDepth();
final String tag = parser.getName();
- switch (tag) {
- case TAG_LAUNCHER: {
- ret.mLauncherComponent = ShortcutService.parseComponentNameAttribute(
- parser, ATTR_VALUE);
- continue;
- }
- case ShortcutPackage.TAG_ROOT: {
- final ShortcutPackage shortcuts = ShortcutPackage.loadFromXml(parser, userId);
-
- // Don't use addShortcut(), we don't need to save the icon.
- ret.getPackages().put(shortcuts.getPackageName(), shortcuts);
- continue;
- }
-
- case ShortcutLauncher.TAG_ROOT: {
- ret.addLauncher(ShortcutLauncher.loadFromXml(parser, userId));
- continue;
- }
- case ShortcutPackageInfo.TAG_ROOT: {
- ret.addPackageInfo(ShortcutPackageInfo.loadFromXml(parser, userId));
- continue;
+ if (depth == outerDepth + 1) {
+ switch (tag) {
+ case TAG_LAUNCHER: {
+ ret.mLauncherComponent = ShortcutService.parseComponentNameAttribute(
+ parser, ATTR_VALUE);
+ continue;
+ }
+ case ShortcutPackage.TAG_ROOT: {
+ final ShortcutPackage shortcuts = ShortcutPackage.loadFromXml(
+ s, parser, userId, fromBackup);
+
+ // Don't use addShortcut(), we don't need to save the icon.
+ ret.getPackages().put(shortcuts.getPackageName(), shortcuts);
+ continue;
+ }
+
+ case ShortcutLauncher.TAG_ROOT: {
+ ret.addLauncher(ShortcutLauncher.loadFromXml(parser, userId, fromBackup));
+ continue;
+ }
}
}
- throw ShortcutService.throwForInvalidTag(depth, tag);
+ ShortcutService.warnForInvalidTag(depth, tag);
}
return ret;
}
for (int i = 0; i < mPackages.size(); i++) {
mPackages.valueAt(i).dump(s, pw, prefix + " ");
}
-
- for (int i = 0; i < mPackageInfos.size(); i++) {
- mPackageInfos.valueAt(i).dump(s, pw, prefix + " ");
- }
}
}
@NonNull
private List<ShortcutInfo> assertShortcutIds(@NonNull List<ShortcutInfo> actualShortcuts,
String... expectedIds) {
- assertEquals(expectedIds.length, actualShortcuts.size());
final HashSet<String> expected = new HashSet<>(list(expectedIds));
final HashSet<String> actual = new HashSet<>();
for (ShortcutInfo s : actualShortcuts) {
assertTrue(b == null || b.size() == 0);
}
- private void assertShortcutPackageInfo(String packageName, int userId, int expectedVersion) {
- ShortcutPackageInfo spi = mService.getPackageInfoForTest(packageName, userId);
- assertNotNull(spi);
- assertEquals(expectedVersion, spi.getVersionCode());
-
- assertTrue(spi.canRestoreTo(genPackage(packageName, /*uid*/ 0, 9999999, packageName)));
- }
-
- private void assertNoShortcutPackageInfo(String packageName, int userId) {
- assertNull(mService.getPackageInfoForTest(packageName, userId));
- }
-
private ShortcutInfo getPackageShortcut(String packageName, String shortcutId, int userId) {
return mService.getPackageShortcutForTest(packageName, shortcutId, userId);
}
"shortcut1", "shortcut2");
assertEquals(2, mManager.getRemainingCallCount());
- assertShortcutPackageInfo(CALLING_PACKAGE_1, USER_0, 1);
- assertNoShortcutPackageInfo(CALLING_PACKAGE_2, USER_0);
- assertNoShortcutPackageInfo(CALLING_PACKAGE_1, USER_10);
- assertNoShortcutPackageInfo(CALLING_PACKAGE_2, USER_10);
-
// TODO: Check fields
assertTrue(mManager.setDynamicShortcuts(list(si1)));
runWithCaller(CALLING_PACKAGE_2, USER_10, () -> {
assertTrue(mManager.setDynamicShortcuts(list(makeShortcut("s1"))));
-
- assertShortcutPackageInfo(CALLING_PACKAGE_1, USER_0, 1);
- assertNoShortcutPackageInfo(CALLING_PACKAGE_2, USER_0);
- assertNoShortcutPackageInfo(CALLING_PACKAGE_1, USER_10);
- assertShortcutPackageInfo(CALLING_PACKAGE_2, USER_10, 2);
});
}
runWithCaller(CALLING_PACKAGE_2, USER_10, () -> {
assertTrue(mManager.addDynamicShortcut(makeShortcut("s1")));
- assertShortcutPackageInfo(CALLING_PACKAGE_2, USER_10, 2);
});
}
Bitmap bmp;
setCaller(LAUNCHER_1);
-
// Check hasIconResource()/hasIconFile().
assertShortcutIds(assertAllHaveIconResId(mLauncherApps.getShortcutInfo(
CALLING_PACKAGE_1, list("res32x32"),
// TODO Check bitmap removal too.
runWithCaller(CALLING_PACKAGE_2, USER_11, () -> {
- assertNoShortcutPackageInfo(CALLING_PACKAGE_2, USER_11);
-
mManager.updateShortcuts(list());
-
- // Even an empty update call will populate the package info.
- assertShortcutPackageInfo(CALLING_PACKAGE_2, USER_11, 2);
});
}
assertTrue(mManager.setDynamicShortcuts(list(s2_2, s2_3, s2_4)));
setCaller(CALLING_PACKAGE_3);
- final ShortcutInfo s3_2 = makeShortcutWithTimestamp("s3", 5000);
+ final ShortcutInfo s3_2 = makeShortcutWithTimestamp("s3", START_TIME + 5000);
assertTrue(mManager.setDynamicShortcuts(list(s3_2)));
setCaller(LAUNCHER_1);
// Pin some.
runWithCaller(LAUNCHER_1, USER_0, () -> {
- assertNoShortcutPackageInfo(LAUNCHER_1, USER_0);
-
mLauncherApps.pinShortcuts(CALLING_PACKAGE_1,
list("s2", "s3"), getCallingUser());
- assertShortcutPackageInfo(LAUNCHER_1, USER_0, 4);
- assertNoShortcutPackageInfo(LAUNCHER_2, USER_0);
- assertNoShortcutPackageInfo(LAUNCHER_1, USER_10);
- assertNoShortcutPackageInfo(LAUNCHER_2, USER_10);
-
mLauncherApps.pinShortcuts(CALLING_PACKAGE_2,
list("s3", "s4", "s5"), getCallingUser());
dumpsysOnLogcat();
- assertNoShortcutPackageInfo(LAUNCHER_1, USER_0);
- assertNoShortcutPackageInfo(LAUNCHER_2, USER_0);
- assertNoShortcutPackageInfo(LAUNCHER_1, USER_10);
- assertNoShortcutPackageInfo(LAUNCHER_2, USER_10);
-
// Pin some.
runWithCaller(LAUNCHER_1, USER_0, () -> {
mLauncherApps.pinShortcuts(CALLING_PACKAGE_1,
list("s3", "s4"), getCallingUser());
- assertShortcutPackageInfo(LAUNCHER_1, USER_0, 4);
- assertNoShortcutPackageInfo(LAUNCHER_2, USER_0);
-
mLauncherApps.pinShortcuts(CALLING_PACKAGE_2,
list("s1", "s2", "s4"), getCallingUser());
});
| ShortcutQuery.FLAG_GET_DYNAMIC), getCallingUser())),
"s2");
- assertNoShortcutPackageInfo(LAUNCHER_2, USER_0);
- assertNoShortcutPackageInfo(LAUNCHER_2, USER_10);
-
// Now pin some.
mLauncherApps.pinShortcuts(CALLING_PACKAGE_1,
list("s1", "s2"), getCallingUser());
- assertShortcutPackageInfo(LAUNCHER_2, USER_0, 5);
- assertNoShortcutPackageInfo(LAUNCHER_2, USER_10);
-
mLauncherApps.pinShortcuts(CALLING_PACKAGE_2,
list("s1", "s2"), getCallingUser());
"s2");
});
- assertShortcutPackageInfo(CALLING_PACKAGE_1, USER_0, 1);
- assertShortcutPackageInfo(CALLING_PACKAGE_2, USER_0, 2);
- assertNoShortcutPackageInfo(CALLING_PACKAGE_3, USER_0);
- assertShortcutPackageInfo(LAUNCHER_1, USER_0, 4);
- assertShortcutPackageInfo(LAUNCHER_2, USER_0, 5);
-
// Re-initialize and load from the files.
mService.saveDirtyInfo();
initService();
mService.handleUnlockUser(USER_0);
// Make sure package info is restored too.
- assertShortcutPackageInfo(CALLING_PACKAGE_1, USER_0, 1);
- assertShortcutPackageInfo(CALLING_PACKAGE_2, USER_0, 2);
- assertNoShortcutPackageInfo(CALLING_PACKAGE_3, USER_0);
- assertShortcutPackageInfo(LAUNCHER_1, USER_0, 4);
- assertShortcutPackageInfo(LAUNCHER_2, USER_0, 5);
-
runWithCaller(LAUNCHER_1, USER_0, () -> {
assertShortcutIds(assertAllPinned(assertAllNotKeyFieldsOnly(
mLauncherApps.getShortcuts(buildQuery(/* time =*/ 0, CALLING_PACKAGE_1,
mService.getShortcutsForTest().get(UserHandle.USER_SYSTEM).setLauncherComponent(
mService, new ComponentName("pkg1", "class"));
- assertShortcutPackageInfo(CALLING_PACKAGE_1, USER_0, 1);
- assertShortcutPackageInfo(CALLING_PACKAGE_2, USER_0, 2);
- assertNoShortcutPackageInfo(CALLING_PACKAGE_3, USER_0);
-
// Restore.
mService.saveDirtyInfo();
initService();
// this will pre-load the per-user info.
mService.handleUnlockUser(UserHandle.USER_SYSTEM);
- assertShortcutPackageInfo(CALLING_PACKAGE_1, USER_0, 1);
- assertShortcutPackageInfo(CALLING_PACKAGE_2, USER_0, 2);
- assertNoShortcutPackageInfo(CALLING_PACKAGE_3, USER_0);
-
// Now it's loaded.
assertEquals(1, mService.getShortcutsForTest().size());
assertShortcutExists(CALLING_PACKAGE_1, "s10_1", USER_10);
assertShortcutExists(CALLING_PACKAGE_2, "s10_2", USER_10);
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_0));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_2, USER_0));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_10));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_2, USER_10));
-
mService.saveDirtyInfo();
// Nonexistent package.
assertShortcutExists(CALLING_PACKAGE_1, "s10_1", USER_10);
assertShortcutExists(CALLING_PACKAGE_2, "s10_2", USER_10);
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_0));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_2, USER_0));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_10));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_2, USER_10));
-
mService.saveDirtyInfo();
// Remove a package.
assertShortcutExists(CALLING_PACKAGE_1, "s10_1", USER_10);
assertShortcutExists(CALLING_PACKAGE_2, "s10_2", USER_10);
- assertNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_0));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_2, USER_0));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_10));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_2, USER_10));
-
mService.saveDirtyInfo();
// Remove a launcher.
assertShortcutExists(CALLING_PACKAGE_1, "s10_1", USER_10);
assertShortcutNotExists(CALLING_PACKAGE_2, "s10_2", USER_10);
- assertNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_0));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_2, USER_0));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_10));
- assertNull(mService.getPackageInfoForTest(CALLING_PACKAGE_2, USER_10));
-
mService.saveDirtyInfo();
// Remove the other launcher from user 10 too.
mService.saveDirtyInfo();
}
- public void testHandleGonePackage_crossProfile() {
+
+ public void testSaveAndLoadUser_forBackup() {
// Create some shortcuts.
runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
assertTrue(mManager.setDynamicShortcuts(list(
assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_10));
assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_10));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_0));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_P0));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_2, USER_0));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_10));
-
- // These two shouldn't exist
- assertNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_P0, USER_0));
- assertNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_0, USER_P0));
-
- assertNotNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_0, USER_0));
- assertNotNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_0, USER_P0));
- assertNotNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_P0, USER_0));
- assertNotNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_10, USER_10));
-
// Make sure all the information is persisted.
mService.saveDirtyInfo();
initService();
mService.handleUnlockUser(USER_0);
mService.handleUnlockUser(USER_P0);
mService.handleUnlockUser(USER_10);
+ }
+
+ public void testHandleGonePackage_crossProfile() {
+ // Create some shortcuts.
+ runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
+ assertTrue(mManager.setDynamicShortcuts(list(
+ makeShortcut("s1"), makeShortcut("s2"), makeShortcut("s3"))));
+ });
+ runWithCaller(CALLING_PACKAGE_1, USER_P0, () -> {
+ assertTrue(mManager.setDynamicShortcuts(list(
+ makeShortcut("s1"), makeShortcut("s2"), makeShortcut("s3"))));
+ });
+ runWithCaller(CALLING_PACKAGE_2, USER_0, () -> {
+ assertTrue(mManager.setDynamicShortcuts(list(
+ makeShortcut("s1"), makeShortcut("s2"), makeShortcut("s3"))));
+ });
+ runWithCaller(CALLING_PACKAGE_1, USER_10, () -> {
+ assertTrue(mManager.setDynamicShortcuts(list(
+ makeShortcut("s1"), makeShortcut("s2"), makeShortcut("s3"))));
+ });
+
+ assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_0));
+ assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_0));
+ assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_0));
+
+ assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_P0));
+ assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_P0));
+ assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_P0));
+
+ assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_2, "s1", USER_0));
+ assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_2, "s2", USER_0));
+ assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_2, "s3", USER_0));
+
+ assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_10));
+ assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_10));
+ assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_10));
+
+ // Pin some.
+
+ runWithCaller(LAUNCHER_1, USER_0, () -> {
+ mLauncherApps.pinShortcuts(CALLING_PACKAGE_1,
+ list("s1"), HANDLE_USER_0);
+
+ mLauncherApps.pinShortcuts(CALLING_PACKAGE_1,
+ list("s2"), UserHandle.of(USER_P0));
+
+ mLauncherApps.pinShortcuts(CALLING_PACKAGE_2,
+ list("s3"), HANDLE_USER_0);
+ });
+
+ runWithCaller(LAUNCHER_1, USER_P0, () -> {
+ mLauncherApps.pinShortcuts(CALLING_PACKAGE_1,
+ list("s2"), HANDLE_USER_0);
+
+ mLauncherApps.pinShortcuts(CALLING_PACKAGE_1,
+ list("s3"), UserHandle.of(USER_P0));
+
+ mLauncherApps.pinShortcuts(CALLING_PACKAGE_2,
+ list("s1"), HANDLE_USER_0);
+ });
+
+ runWithCaller(LAUNCHER_1, USER_10, () -> {
+ mLauncherApps.pinShortcuts(CALLING_PACKAGE_1,
+ list("s3"), HANDLE_USER_10);
+ });
+
+ // Check the state.
assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_0));
assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_0));
assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_10));
assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_10));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_0));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_P0));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_2, USER_0));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_10));
+ // Make sure all the information is persisted.
+ mService.saveDirtyInfo();
+ initService();
+ mService.handleUnlockUser(USER_0);
+ mService.handleUnlockUser(USER_P0);
+ mService.handleUnlockUser(USER_10);
- // These two shouldn't exist
- assertNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_P0, USER_0));
- assertNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_0, USER_P0));
+ assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_0));
+ assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_0));
+ assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_0));
- assertNotNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_0, USER_0));
- assertNotNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_0, USER_P0));
- assertNotNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_P0, USER_0));
- assertNotNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_10, USER_10));
+ assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_P0));
+ assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_P0));
+ assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_P0));
+ assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_2, "s1", USER_0));
+ assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_2, "s2", USER_0));
+ assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_2, "s3", USER_0));
+
+ assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_10));
+ assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_10));
+ assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_10));
// Start uninstalling.
uninstallPackage(USER_10, LAUNCHER_1);
assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_10));
assertDynamicOnly(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_10));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_0));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_P0));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_2, USER_0));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_10));
-
- assertNotNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_0, USER_0));
- assertNotNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_0, USER_P0));
- assertNotNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_P0, USER_0));
- assertNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_10, USER_10));
-
// Uninstall.
uninstallPackage(USER_10, CALLING_PACKAGE_1);
mService.cleanupGonePackages(USER_10);
assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_10));
assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_10));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_0));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_P0));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_2, USER_0));
- assertNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_10));
-
- assertNotNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_0, USER_0));
- assertNotNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_0, USER_P0));
- assertNotNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_P0, USER_0));
- assertNotNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_P0, USER_P0));
- assertNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_10, USER_10));
-
uninstallPackage(USER_P0, LAUNCHER_1);
mService.cleanupGonePackages(USER_0);
assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_10));
assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_10));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_0));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_P0));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_2, USER_0));
- assertNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_10));
-
- assertNotNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_0, USER_0));
- assertNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_0, USER_P0));
- assertNotNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_P0, USER_0));
- assertNotNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_P0, USER_P0));
- assertNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_10, USER_10));
-
mService.cleanupGonePackages(USER_P0);
assertDynamicAndPinned(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_0));
assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_10));
assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_10));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_0));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_P0));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_2, USER_0));
- assertNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_10));
-
- assertNotNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_0, USER_0));
- assertNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_0, USER_P0));
- assertNotNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_P0, USER_0));
- assertNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_P0, USER_P0));
- assertNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_10, USER_10));
-
uninstallPackage(USER_P0, CALLING_PACKAGE_1);
mService.saveDirtyInfo();
assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_10));
assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_10));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_0));
- assertNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_P0));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_2, USER_0));
- assertNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_10));
-
- assertNotNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_0, USER_0));
- assertNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_0, USER_P0));
- assertNotNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_P0, USER_0));
- assertNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_P0, USER_P0));
- assertNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_10, USER_10));
-
// Uninstall
uninstallPackage(USER_0, LAUNCHER_1);
assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_10));
assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_10));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_0));
- assertNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_P0));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_2, USER_0));
- assertNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_10));
-
- assertNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_0, USER_0));
- assertNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_0, USER_P0));
- assertNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_P0, USER_0));
- assertNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_P0, USER_P0));
- assertNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_10, USER_10));
-
uninstallPackage(USER_0, CALLING_PACKAGE_2);
mService.saveDirtyInfo();
assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s1", USER_10));
assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s2", USER_10));
assertNull(getPackageShortcut(CALLING_PACKAGE_1, "s3", USER_10));
-
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_0));
- assertNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_P0));
- assertNull(mService.getPackageInfoForTest(CALLING_PACKAGE_2, USER_0));
- assertNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_10));
-
- assertNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_0, USER_0));
- assertNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_0, USER_P0));
- assertNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_P0, USER_0));
- assertNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_P0, USER_P0));
- assertNull(mService.getPackageInfoForTest(LAUNCHER_1, USER_10, USER_10));
}
// TODO Detailed test for hasShortcutPermissionInner().
checkCanRestoreTo(false, spi2, 11, "x", "sig2x", "sig1", "y");
}
- public void testShortcutPackageInfoRefresh() {
- addPackage(CALLING_PACKAGE_1, CALLING_UID_1, 10, "sig1");
-
- final ShortcutPackageInfo spi1 = ShortcutPackageInfo.generateForInstalledPackage(
- mService, CALLING_PACKAGE_1, USER_0);
-
- checkCanRestoreTo(true, spi1, 10, "sig1");
-
- addPackage(CALLING_PACKAGE_1, CALLING_UID_1, 11, "sig1", "sig2");
-
- spi1.refreshAndSave(mService, USER_0);
-
- mService.handleCleanupUser(USER_0);
- initService();
-
- checkCanRestoreTo(false, spi1, 10, "sig1", "sig2");
- checkCanRestoreTo(false, spi1, 11, "sig", "sig2");
- checkCanRestoreTo(false, spi1, 11, "sig1", "sig");
- checkCanRestoreTo(true, spi1, 11, "sig1", "sig2");
- }
-
public void testHandlePackageDelete() {
setCaller(CALLING_PACKAGE_1, USER_0);
assertTrue(mManager.addDynamicShortcut(makeShortcut("s1")));
setCaller(CALLING_PACKAGE_3, USER_10);
assertTrue(mManager.addDynamicShortcut(makeShortcut("s1")));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_0));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_2, USER_0));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_3, USER_0));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_10));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_2, USER_10));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_3, USER_10));
+ assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "s1", USER_0));
+ assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_2, "s1", USER_0));
+ assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_3, "s1", USER_0));
+ assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "s1", USER_10));
+ assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_2, "s1", USER_10));
+ assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_3, "s1", USER_10));
mService.mPackageMonitor.onReceive(getTestContext(),
genPackageDeleteIntent(CALLING_PACKAGE_1, USER_0));
- assertNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_0));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_2, USER_0));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_3, USER_0));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_10));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_2, USER_10));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_3, USER_10));
+ assertNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "s1", USER_0));
+ assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_2, "s1", USER_0));
+ assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_3, "s1", USER_0));
+ assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "s1", USER_10));
+ assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_2, "s1", USER_10));
+ assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_3, "s1", USER_10));
mService.mPackageMonitor.onReceive(getTestContext(),
genPackageDeleteIntent(CALLING_PACKAGE_2, USER_10));
- assertNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_0));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_2, USER_0));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_3, USER_0));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_10));
- assertNull(mService.getPackageInfoForTest(CALLING_PACKAGE_2, USER_10));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_3, USER_10));
+ assertNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "s1", USER_0));
+ assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_2, "s1", USER_0));
+ assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_3, "s1", USER_0));
+ assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "s1", USER_10));
+ assertNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_2, "s1", USER_10));
+ assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_3, "s1", USER_10));
mInjectedPackages.remove(CALLING_PACKAGE_1);
mInjectedPackages.remove(CALLING_PACKAGE_3);
mService.handleUnlockUser(USER_0);
- assertNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_0));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_2, USER_0));
- assertNull(mService.getPackageInfoForTest(CALLING_PACKAGE_3, USER_0));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_10));
- assertNull(mService.getPackageInfoForTest(CALLING_PACKAGE_2, USER_10));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_3, USER_10));
+
+ assertNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "s1", USER_0));
+ assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_2, "s1", USER_0));
+ assertNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_3, "s1", USER_0));
+ assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "s1", USER_10));
+ assertNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_2, "s1", USER_10));
+ assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_3, "s1", USER_10));
mService.handleUnlockUser(USER_10);
- assertNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_0));
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_2, USER_0));
- assertNull(mService.getPackageInfoForTest(CALLING_PACKAGE_3, USER_0));
- assertNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_10));
- assertNull(mService.getPackageInfoForTest(CALLING_PACKAGE_2, USER_10));
- assertNull(mService.getPackageInfoForTest(CALLING_PACKAGE_3, USER_10));
+
+ assertNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "s1", USER_0));
+ assertNotNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_2, "s1", USER_0));
+ assertNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_3, "s1", USER_0));
+ assertNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "s1", USER_10));
+ assertNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_2, "s1", USER_10));
+ assertNull(mService.getPackageShortcutForTest(CALLING_PACKAGE_3, "s1", USER_10));
}
public void testHandlePackageUpdate() {
- setCaller(CALLING_PACKAGE_1, USER_0);
- assertTrue(mManager.addDynamicShortcut(makeShortcut("s1")));
-
- assertNotNull(mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_0));
- assertEquals(1, mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_0).getVersionCode());
-
- addPackage(CALLING_PACKAGE_1, CALLING_UID_1, 123);
-
- mService.mPackageMonitor.onReceive(getTestContext(),
- genPackageUpdateIntent("abc", USER_0));
- assertEquals(1, mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_0).getVersionCode());
-
- mService.mPackageMonitor.onReceive(getTestContext(),
- genPackageUpdateIntent("abc", USER_10));
- assertEquals(1, mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_0).getVersionCode());
-
- mService.mPackageMonitor.onReceive(getTestContext(),
- genPackageUpdateIntent(CALLING_PACKAGE_1, USER_0));
- assertEquals(123, mService.getPackageInfoForTest(CALLING_PACKAGE_1, USER_0)
- .getVersionCode());
+ // TODO: Make sure unshadow is called.
}
}