Commit 345ffa54 authored by Svetoslav Ganov's avatar Svetoslav Ganov

Address API council comments

Test: cookie CTS tests pass

bug:37327624
bug:37325276
bug:37323696

Change-Id: I52b10470759e471629ec6772e115df94482eb341
parent 0cb43ef6
......@@ -10570,6 +10570,7 @@ package android.content.pm {
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 @@ package android.content.pm {
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 @@ package android.content.pm {
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 @@ package android.test.mock {
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 @@ package android.test.mock {
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 @@ package android.test.mock {
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);
}
......@@ -45,6 +45,10 @@ package android.content.pm {
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();
......
......@@ -11241,6 +11241,7 @@ package android.content.pm {
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 @@ package android.content.pm {
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 @@ package android.content.pm {
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 @@ package android.test.mock {
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 @@ package android.test.mock {
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 @@ package android.test.mock {
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>);
......@@ -43,6 +43,10 @@ package android.content.pm {
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();
......
......@@ -10607,6 +10607,7 @@ package android.content.pm {
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 @@ package android.content.pm {
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 @@ package android.content.pm {
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 @@ package android.test.mock {
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 @@ package android.test.mock {
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 @@ package android.test.mock {
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);
}
......@@ -45,6 +45,10 @@ package android.content.pm {
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();
......
......@@ -818,13 +818,17 @@ public class ApplicationPackageManager extends PackageManager {
}
}
@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 {
......@@ -840,6 +844,25 @@ public class ApplicationPackageManager extends PackageManager {
}
}
@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 {
......
......@@ -2823,7 +2823,7 @@ public abstract class PackageManager {
* 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 @@ public abstract class PackageManager {
* @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 @@ public abstract class PackageManager {
* @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 @@ public abstract class PackageManager {
*
* @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 @@ public abstract class PackageManager {
* 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 @@ public abstract class PackageManager {
*
* @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
* Clears the instant application cookie for the calling app.
*
* @see #isInstantApp()
* @see #isInstantApp(String)
* @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 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. 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.
* cookie size is limited by {@link #getInstantAppCookieMaxBytes()}.
* Passing <code>null</code> or an empty array clears the cookie.
* </p>
*
* @param cookie The cookie data.
* @return Whether the cookie was set.
*
* @see #isInstantApp()
* @see #isInstantApp(String)
* @see #getInstantAppCookieMaxSize()
* @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 @@ public abstract class PackageManager {
* @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(
......
......@@ -142,7 +142,7 @@ class InstantAppRegistry {
@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);
......
......@@ -369,12 +369,30 @@ public class MockPackageManager extends PackageManager {
throw new UnsupportedOperationException();
}
/** @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) {
......
......@@ -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;
......@@ -327,11 +328,26 @@ public class BridgePackageManager extends PackageManager {
return false;
}
@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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment