Address API council comments
Test: cookie CTS tests pass
bug:37327624
bug:37325276
bug:37323696
Change-Id: I52b10470759e471629ec6772e115df94482eb341
diff --git a/api/current.txt b/api/current.txt
index e488620..67d6e25 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -10570,6 +10570,7 @@
method public abstract int checkPermission(java.lang.String, java.lang.String);
method public abstract int checkSignatures(java.lang.String, java.lang.String);
method public abstract int checkSignatures(int, int);
+ method public abstract void clearInstantAppCookie();
method public abstract void clearPackagePreferredActivities(java.lang.String);
method public abstract java.lang.String[] currentToCanonicalPackageNames(java.lang.String[]);
method public abstract void extendVerificationTimeout(int, int, long);
@@ -10598,7 +10599,7 @@
method public abstract java.util.List<android.content.pm.PackageInfo> getInstalledPackages(int);
method public abstract java.lang.String getInstallerPackageName(java.lang.String);
method public abstract byte[] getInstantAppCookie();
- method public abstract int getInstantAppCookieMaxSize();
+ method public abstract int getInstantAppCookieMaxBytes();
method public abstract android.content.pm.InstrumentationInfo getInstrumentationInfo(android.content.ComponentName, int) throws android.content.pm.PackageManager.NameNotFoundException;
method public abstract android.content.Intent getLaunchIntentForPackage(java.lang.String);
method public abstract android.content.Intent getLeanbackLaunchIntentForPackage(java.lang.String);
@@ -10653,7 +10654,7 @@
method public abstract void setApplicationEnabledSetting(java.lang.String, int, int);
method public abstract void setComponentEnabledSetting(android.content.ComponentName, int, int);
method public abstract void setInstallerPackageName(java.lang.String, java.lang.String);
- method public abstract boolean setInstantAppCookie(byte[]);
+ method public abstract void updateInstantAppCookie(byte[]);
method public abstract void verifyPendingInstall(int, int);
field public static final int COMPONENT_ENABLED_STATE_DEFAULT = 0; // 0x0
field public static final int COMPONENT_ENABLED_STATE_DISABLED = 2; // 0x2
@@ -40988,6 +40989,7 @@
method public int checkPermission(java.lang.String, java.lang.String);
method public int checkSignatures(java.lang.String, java.lang.String);
method public int checkSignatures(int, int);
+ method public void clearInstantAppCookie();
method public void clearPackagePreferredActivities(java.lang.String);
method public java.lang.String[] currentToCanonicalPackageNames(java.lang.String[]);
method public void extendVerificationTimeout(int, int, long);
@@ -41017,7 +41019,7 @@
method public java.util.List<android.content.pm.PackageInfo> getInstalledPackages(int);
method public java.lang.String getInstallerPackageName(java.lang.String);
method public byte[] getInstantAppCookie();
- method public int getInstantAppCookieMaxSize();
+ method public int getInstantAppCookieMaxBytes();
method public android.content.pm.InstrumentationInfo getInstrumentationInfo(android.content.ComponentName, int) throws android.content.pm.PackageManager.NameNotFoundException;
method public android.content.Intent getLaunchIntentForPackage(java.lang.String);
method public android.content.Intent getLeanbackLaunchIntentForPackage(java.lang.String);
@@ -41071,7 +41073,7 @@
method public void setApplicationEnabledSetting(java.lang.String, int, int);
method public void setComponentEnabledSetting(android.content.ComponentName, int, int);
method public void setInstallerPackageName(java.lang.String, java.lang.String);
- method public boolean setInstantAppCookie(byte[]);
+ method public void updateInstantAppCookie(byte[]);
method public void verifyPendingInstall(int, int);
}
diff --git a/api/removed.txt b/api/removed.txt
index acd102c..acd5e43 100644
--- a/api/removed.txt
+++ b/api/removed.txt
@@ -45,6 +45,10 @@
field public static final int REQUESTED_PERMISSION_REQUIRED = 1; // 0x1
}
+ public abstract class PackageManager {
+ method public abstract boolean setInstantAppCookie(byte[]);
+ }
+
public final class SharedLibraryInfo implements android.os.Parcelable {
method public boolean isBuiltin();
method public boolean isDynamic();
diff --git a/api/system-current.txt b/api/system-current.txt
index 4d211ef..a4811ac 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -11241,6 +11241,7 @@
method public abstract int checkPermission(java.lang.String, java.lang.String);
method public abstract int checkSignatures(java.lang.String, java.lang.String);
method public abstract int checkSignatures(int, int);
+ method public abstract void clearInstantAppCookie();
method public abstract void clearPackagePreferredActivities(java.lang.String);
method public abstract java.lang.String[] currentToCanonicalPackageNames(java.lang.String[]);
method public abstract void extendVerificationTimeout(int, int, long);
@@ -11272,7 +11273,7 @@
method public abstract java.util.List<android.content.pm.PackageInfo> getInstalledPackagesAsUser(int, int);
method public abstract java.lang.String getInstallerPackageName(java.lang.String);
method public abstract byte[] getInstantAppCookie();
- method public abstract int getInstantAppCookieMaxSize();
+ method public abstract int getInstantAppCookieMaxBytes();
method public abstract android.graphics.drawable.Drawable getInstantAppIcon(java.lang.String);
method public abstract android.content.ComponentName getInstantAppInstallerComponent();
method public abstract android.content.ComponentName getInstantAppResolverSettingsComponent();
@@ -11339,8 +11340,8 @@
method public abstract void setComponentEnabledSetting(android.content.ComponentName, int, int);
method public abstract boolean setDefaultBrowserPackageNameAsUser(java.lang.String, int);
method public abstract void setInstallerPackageName(java.lang.String, java.lang.String);
- method public abstract boolean setInstantAppCookie(byte[]);
method public abstract void setUpdateAvailable(java.lang.String, boolean);
+ method public abstract void updateInstantAppCookie(byte[]);
method public abstract boolean updateIntentVerificationStatusAsUser(java.lang.String, int, int);
method public abstract void updatePermissionFlags(java.lang.String, java.lang.String, int, int, android.os.UserHandle);
method public abstract void verifyIntentFilter(int, int, java.util.List<java.lang.String>);
@@ -44543,6 +44544,7 @@
method public int checkPermission(java.lang.String, java.lang.String);
method public int checkSignatures(java.lang.String, java.lang.String);
method public int checkSignatures(int, int);
+ method public void clearInstantAppCookie();
method public void clearPackagePreferredActivities(java.lang.String);
method public java.lang.String[] currentToCanonicalPackageNames(java.lang.String[]);
method public void extendVerificationTimeout(int, int, long);
@@ -44574,7 +44576,7 @@
method public java.util.List<android.content.pm.PackageInfo> getInstalledPackagesAsUser(int, int);
method public java.lang.String getInstallerPackageName(java.lang.String);
method public byte[] getInstantAppCookie();
- method public int getInstantAppCookieMaxSize();
+ method public int getInstantAppCookieMaxBytes();
method public android.graphics.drawable.Drawable getInstantAppIcon(java.lang.String);
method public android.content.ComponentName getInstantAppInstallerComponent();
method public android.content.ComponentName getInstantAppResolverSettingsComponent();
@@ -44639,8 +44641,8 @@
method public void setComponentEnabledSetting(android.content.ComponentName, int, int);
method public boolean setDefaultBrowserPackageNameAsUser(java.lang.String, int);
method public void setInstallerPackageName(java.lang.String, java.lang.String);
- method public boolean setInstantAppCookie(byte[]);
method public void setUpdateAvailable(java.lang.String, boolean);
+ method public void updateInstantAppCookie(byte[]);
method public boolean updateIntentVerificationStatusAsUser(java.lang.String, int, int);
method public void updatePermissionFlags(java.lang.String, java.lang.String, int, int, android.os.UserHandle);
method public void verifyIntentFilter(int, int, java.util.List<java.lang.String>);
diff --git a/api/system-removed.txt b/api/system-removed.txt
index 06165be..9f1d1a9 100644
--- a/api/system-removed.txt
+++ b/api/system-removed.txt
@@ -43,6 +43,10 @@
field public static final int REQUESTED_PERMISSION_REQUIRED = 1; // 0x1
}
+ public abstract class PackageManager {
+ method public abstract boolean setInstantAppCookie(byte[]);
+ }
+
public final class SharedLibraryInfo implements android.os.Parcelable {
method public boolean isBuiltin();
method public boolean isDynamic();
diff --git a/api/test-current.txt b/api/test-current.txt
index 04a4982..7bf67f9 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -10607,6 +10607,7 @@
method public abstract int checkPermission(java.lang.String, java.lang.String);
method public abstract int checkSignatures(java.lang.String, java.lang.String);
method public abstract int checkSignatures(int, int);
+ method public abstract void clearInstantAppCookie();
method public abstract void clearPackagePreferredActivities(java.lang.String);
method public abstract java.lang.String[] currentToCanonicalPackageNames(java.lang.String[]);
method public abstract void extendVerificationTimeout(int, int, long);
@@ -10637,7 +10638,7 @@
method public abstract java.util.List<android.content.pm.PackageInfo> getInstalledPackages(int);
method public abstract java.lang.String getInstallerPackageName(java.lang.String);
method public abstract byte[] getInstantAppCookie();
- method public abstract int getInstantAppCookieMaxSize();
+ method public abstract int getInstantAppCookieMaxBytes();
method public abstract android.content.pm.InstrumentationInfo getInstrumentationInfo(android.content.ComponentName, int) throws android.content.pm.PackageManager.NameNotFoundException;
method public abstract android.content.Intent getLaunchIntentForPackage(java.lang.String);
method public abstract android.content.Intent getLeanbackLaunchIntentForPackage(java.lang.String);
@@ -10693,7 +10694,7 @@
method public abstract void setApplicationEnabledSetting(java.lang.String, int, int);
method public abstract void setComponentEnabledSetting(android.content.ComponentName, int, int);
method public abstract void setInstallerPackageName(java.lang.String, java.lang.String);
- method public abstract boolean setInstantAppCookie(byte[]);
+ method public abstract void updateInstantAppCookie(byte[]);
method public abstract void verifyPendingInstall(int, int);
field public static final int COMPONENT_ENABLED_STATE_DEFAULT = 0; // 0x0
field public static final int COMPONENT_ENABLED_STATE_DISABLED = 2; // 0x2
@@ -41183,6 +41184,7 @@
method public int checkPermission(java.lang.String, java.lang.String);
method public int checkSignatures(java.lang.String, java.lang.String);
method public int checkSignatures(int, int);
+ method public void clearInstantAppCookie();
method public void clearPackagePreferredActivities(java.lang.String);
method public java.lang.String[] currentToCanonicalPackageNames(java.lang.String[]);
method public void extendVerificationTimeout(int, int, long);
@@ -41214,7 +41216,7 @@
method public java.util.List<android.content.pm.PackageInfo> getInstalledPackages(int);
method public java.lang.String getInstallerPackageName(java.lang.String);
method public byte[] getInstantAppCookie();
- method public int getInstantAppCookieMaxSize();
+ method public int getInstantAppCookieMaxBytes();
method public android.content.pm.InstrumentationInfo getInstrumentationInfo(android.content.ComponentName, int) throws android.content.pm.PackageManager.NameNotFoundException;
method public android.content.Intent getLaunchIntentForPackage(java.lang.String);
method public android.content.Intent getLeanbackLaunchIntentForPackage(java.lang.String);
@@ -41269,7 +41271,7 @@
method public void setApplicationEnabledSetting(java.lang.String, int, int);
method public void setComponentEnabledSetting(android.content.ComponentName, int, int);
method public void setInstallerPackageName(java.lang.String, java.lang.String);
- method public boolean setInstantAppCookie(byte[]);
+ method public void updateInstantAppCookie(byte[]);
method public void verifyPendingInstall(int, int);
}
diff --git a/api/test-removed.txt b/api/test-removed.txt
index acd102c..acd5e43 100644
--- a/api/test-removed.txt
+++ b/api/test-removed.txt
@@ -45,6 +45,10 @@
field public static final int REQUESTED_PERMISSION_REQUIRED = 1; // 0x1
}
+ public abstract class PackageManager {
+ method public abstract boolean setInstantAppCookie(byte[]);
+ }
+
public final class SharedLibraryInfo implements android.os.Parcelable {
method public boolean isBuiltin();
method public boolean isDynamic();
diff --git a/core/java/android/app/ApplicationPackageManager.java b/core/java/android/app/ApplicationPackageManager.java
index e07b7e4..0657bc1 100644
--- a/core/java/android/app/ApplicationPackageManager.java
+++ b/core/java/android/app/ApplicationPackageManager.java
@@ -818,14 +818,18 @@
}
}
- @Override
- public int getInstantAppCookieMaxSize() {
+ public int getInstantAppCookieMaxBytes() {
return Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.EPHEMERAL_COOKIE_MAX_SIZE_BYTES,
DEFAULT_EPHEMERAL_COOKIE_MAX_SIZE_BYTES);
}
@Override
+ public int getInstantAppCookieMaxSize() {
+ return getInstantAppCookieMaxBytes();
+ }
+
+ @Override
public @NonNull byte[] getInstantAppCookie() {
try {
final byte[] cookie = mPM.getInstantAppCookie(
@@ -841,6 +845,25 @@
}
@Override
+ public void clearInstantAppCookie() {
+ updateInstantAppCookie(null);
+ }
+
+ @Override
+ public void updateInstantAppCookie(@NonNull byte[] cookie) {
+ if (cookie != null && cookie.length > getInstantAppCookieMaxBytes()) {
+ throw new IllegalArgumentException("instant cookie longer than "
+ + getInstantAppCookieMaxBytes());
+ }
+ try {
+ mPM.setInstantAppCookie(mContext.getPackageName(),
+ cookie, mContext.getUserId());
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
+ @Override
public boolean setInstantAppCookie(@NonNull byte[] cookie) {
try {
return mPM.setInstantAppCookie(mContext.getPackageName(),
diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java
index 09906be..4293dd6 100644
--- a/core/java/android/content/pm/PackageManager.java
+++ b/core/java/android/content/pm/PackageManager.java
@@ -2823,7 +2823,7 @@
* by passing {@link #VERSION_CODE_HIGHEST} in the {@link VersionedPackage}
* constructor.
*
- * @param versionedPackage The versioned packages for which to query.
+ * @param versionedPackage The versioned package for which to query.
* @param flags Additional option flags. Use any combination of
* {@link #GET_ACTIVITIES}, {@link #GET_CONFIGURATIONS},
* {@link #GET_GIDS}, {@link #GET_INSTRUMENTATION},
@@ -3845,9 +3845,9 @@
* @return Whether caller is an instant app.
*
* @see #isInstantApp(String)
- * @see #setInstantAppCookie(byte[])
+ * @see #updateInstantAppCookie(byte[])
* @see #getInstantAppCookie()
- * @see #getInstantAppCookieMaxSize()
+ * @see #getInstantAppCookieMaxBytes()
*/
public abstract boolean isInstantApp();
@@ -3858,9 +3858,10 @@
* @return Whether the given package is an instant app.
*
* @see #isInstantApp()
- * @see #setInstantAppCookie(byte[])
+ * @see #updateInstantAppCookie(byte[])
* @see #getInstantAppCookie()
- * @see #getInstantAppCookieMaxSize()
+ * @see #getInstantAppCookieMaxBytes()
+ * @see #clearInstantAppCookie()
*/
public abstract boolean isInstantApp(String packageName);
@@ -3872,8 +3873,15 @@
*
* @see #isInstantApp()
* @see #isInstantApp(String)
- * @see #setInstantAppCookie(byte[])
+ * @see #updateInstantAppCookie(byte[])
* @see #getInstantAppCookie()
+ * @see #clearInstantAppCookie()
+ */
+ public abstract int getInstantAppCookieMaxBytes();
+
+ /**
+ * @deprecated
+ * @hide
*/
public abstract int getInstantAppCookieMaxSize();
@@ -3881,7 +3889,7 @@
* Gets the instant application cookie for this app. Non
* instant apps and apps that were instant but were upgraded
* to normal apps can still access this API. For instant apps
- * this cooke is cached for some time after uninstall while for
+ * this cookie is cached for some time after uninstall while for
* normal apps the cookie is deleted after the app is uninstalled.
* The cookie is always present while the app is installed.
*
@@ -3889,31 +3897,49 @@
*
* @see #isInstantApp()
* @see #isInstantApp(String)
- * @see #setInstantAppCookie(byte[])
- * @see #getInstantAppCookieMaxSize()
+ * @see #updateInstantAppCookie(byte[])
+ * @see #getInstantAppCookieMaxBytes()
+ * @see #clearInstantAppCookie()
*/
public abstract @NonNull byte[] getInstantAppCookie();
/**
- * Sets the instant application cookie for the calling app. Non
- * instant apps and apps that were instant but were upgraded
- * to normal apps can still access this API. For instant apps
- * this cooke is cached for some time after uninstall while for
- * normal apps the cookie is deleted after the app is uninstalled.
- * The cookie is always present while the app is installed. The
- * cookie size is limited by {@link #getInstantAppCookieMaxSize()}.
- * If the provided cookie size is over the limit this method
- * returns <code>false</code>. Passing <code>null</code> or an empty
- * array clears the cookie.
- * </p>
- *
- * @param cookie The cookie data.
- * @return Whether the cookie was set.
+ * Clears the instant application cookie for the calling app.
*
* @see #isInstantApp()
* @see #isInstantApp(String)
- * @see #getInstantAppCookieMaxSize()
+ * @see #getInstantAppCookieMaxBytes()
* @see #getInstantAppCookie()
+ * @see #clearInstantAppCookie()
+ */
+ public abstract void clearInstantAppCookie();
+
+ /**
+ * Updates the instant application cookie for the calling app. Non
+ * instant apps and apps that were instant but were upgraded
+ * to normal apps can still access this API. For instant apps
+ * this cookie is cached for some time after uninstall while for
+ * normal apps the cookie is deleted after the app is uninstalled.
+ * The cookie is always present while the app is installed. The
+ * cookie size is limited by {@link #getInstantAppCookieMaxBytes()}.
+ * Passing <code>null</code> or an empty array clears the cookie.
+ * </p>
+ *
+ * @param cookie The cookie data.
+ *
+ * @see #isInstantApp()
+ * @see #isInstantApp(String)
+ * @see #getInstantAppCookieMaxBytes()
+ * @see #getInstantAppCookie()
+ * @see #clearInstantAppCookie()
+ *
+ * @throws IllegalArgumentException if the array exceeds max cookie size.
+ */
+ public abstract void updateInstantAppCookie(@Nullable byte[] cookie);
+
+ /**
+ * @removed
+ * @hide
*/
public abstract boolean setInstantAppCookie(@Nullable byte[] cookie);
@@ -3933,9 +3959,6 @@
* @param flags To filter the libraries to return.
* @return The shared library list.
*
- * @see #MATCH_FACTORY_ONLY
- * @see #MATCH_KNOWN_PACKAGES
- * @see #MATCH_ANY_USER
* @see #MATCH_UNINSTALLED_PACKAGES
*/
public abstract @NonNull List<SharedLibraryInfo> getSharedLibraries(
diff --git a/services/core/java/com/android/server/pm/InstantAppRegistry.java b/services/core/java/com/android/server/pm/InstantAppRegistry.java
index 89a303d..2fa03fb 100644
--- a/services/core/java/com/android/server/pm/InstantAppRegistry.java
+++ b/services/core/java/com/android/server/pm/InstantAppRegistry.java
@@ -142,7 +142,7 @@
@Nullable byte[] cookie, @UserIdInt int userId) {
if (cookie != null && cookie.length > 0) {
final int maxCookieSize = mService.mContext.getPackageManager()
- .getInstantAppCookieMaxSize();
+ .getInstantAppCookieMaxBytes();
if (cookie.length > maxCookieSize) {
Slog.e(LOG_TAG, "Instant app cookie for package " + packageName + " size "
+ cookie.length + " bytes while max size is " + maxCookieSize);
diff --git a/test-runner/src/android/test/mock/MockPackageManager.java b/test-runner/src/android/test/mock/MockPackageManager.java
index 20392e7..563f8ff 100644
--- a/test-runner/src/android/test/mock/MockPackageManager.java
+++ b/test-runner/src/android/test/mock/MockPackageManager.java
@@ -371,12 +371,30 @@
/** @hide */
@Override
+ public int getInstantAppCookieMaxBytes() {
+ throw new UnsupportedOperationException();
+ }
+
+ /** @hide */
+ @Override
public int getInstantAppCookieMaxSize() {
throw new UnsupportedOperationException();
}
/** @hide */
@Override
+ public void clearInstantAppCookie() {
+ throw new UnsupportedOperationException();
+ }
+
+ /** @hide */
+ @Override
+ public void updateInstantAppCookie(@NonNull byte[] cookie) {
+ throw new UnsupportedOperationException();
+ }
+
+ /** @hide */
+ @Override
public boolean setInstantAppCookie(@NonNull byte[] cookie) {
throw new UnsupportedOperationException();
}
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgePackageManager.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgePackageManager.java
index ad26bc8..9ec9e03 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgePackageManager.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgePackageManager.java
@@ -17,6 +17,7 @@
package com.android.layoutlib.bridge.android;
import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.app.PackageInstallObserver;
import android.content.ComponentName;
import android.content.Intent;
@@ -328,11 +329,26 @@
}
@Override
+ public int getInstantAppCookieMaxBytes() {
+ return 0;
+ }
+
+ @Override
public int getInstantAppCookieMaxSize() {
return 0;
}
@Override
+ public void clearInstantAppCookie() {;
+
+ }
+
+ @Override
+ public void updateInstantAppCookie(@Nullable byte[] cookie) {
+
+ }
+
+ @Override
public boolean setInstantAppCookie(@NonNull byte[] cookie) {
return false;
}