summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2017-01-31 03:17:45 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2017-01-31 03:17:49 +0000
commitc869ebff63439ec3e51fdcd4d8b157cdcc8014c1 (patch)
tree84e761e89db15535f38e272e1263abd1d6ea82c7 /core/java/android
parent541af7f69698d9969331cdcbf8e3390618994f2e (diff)
parent096d304ae3d85c1bfcda1a1d9cd4eb13d0815500 (diff)
Merge "Add instant cookie APIs"
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/app/ApplicationPackageManager.java31
-rw-r--r--core/java/android/content/pm/ApplicationInfo.java2
-rw-r--r--core/java/android/content/pm/IPackageManager.aidl12
-rw-r--r--core/java/android/content/pm/InstantAppInfo.aidl (renamed from core/java/android/content/pm/EphemeralApplicationInfo.aidl)2
-rw-r--r--core/java/android/content/pm/InstantAppInfo.java (renamed from core/java/android/content/pm/EphemeralApplicationInfo.java)53
-rw-r--r--core/java/android/content/pm/PackageManager.java83
-rw-r--r--core/java/android/content/pm/PackageManagerInternal.java6
-rw-r--r--core/java/android/content/pm/PermissionInfo.java1
-rwxr-xr-xcore/java/android/provider/Settings.java6
9 files changed, 112 insertions, 84 deletions
diff --git a/core/java/android/app/ApplicationPackageManager.java b/core/java/android/app/ApplicationPackageManager.java
index 2c2b279b6c65..0c6c4ba33ee3 100644
--- a/core/java/android/app/ApplicationPackageManager.java
+++ b/core/java/android/app/ApplicationPackageManager.java
@@ -17,7 +17,6 @@
package android.app;
import android.annotation.DrawableRes;
-import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.StringRes;
@@ -31,7 +30,7 @@ import android.content.IntentSender;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.ComponentInfo;
-import android.content.pm.EphemeralApplicationInfo;
+import android.content.pm.InstantAppInfo;
import android.content.pm.FeatureInfo;
import android.content.pm.IOnPermissionsChangeListener;
import android.content.pm.IPackageDataObserver;
@@ -766,10 +765,10 @@ public class ApplicationPackageManager extends PackageManager {
/** @hide */
@SuppressWarnings("unchecked")
@Override
- public List<EphemeralApplicationInfo> getEphemeralApplications() {
+ public List<InstantAppInfo> getInstantApps() {
try {
- ParceledListSlice<EphemeralApplicationInfo> slice =
- mPM.getEphemeralApplications(mContext.getUserId());
+ ParceledListSlice<InstantAppInfo> slice =
+ mPM.getInstantApps(mContext.getUserId());
if (slice != null) {
return slice.getList();
}
@@ -781,9 +780,9 @@ public class ApplicationPackageManager extends PackageManager {
/** @hide */
@Override
- public Drawable getEphemeralApplicationIcon(String packageName) {
+ public Drawable getInstantAppIcon(String packageName) {
try {
- Bitmap bitmap = mPM.getEphemeralApplicationIcon(
+ Bitmap bitmap = mPM.getInstantAppIcon(
packageName, mContext.getUserId());
if (bitmap != null) {
return new BitmapDrawable(null, bitmap);
@@ -795,26 +794,26 @@ public class ApplicationPackageManager extends PackageManager {
}
@Override
- public boolean isEphemeralApplication() {
+ public boolean isInstantApp() {
try {
- return mPM.isEphemeralApplication(
- mContext.getPackageName(), mContext.getUserId());
+ return mPM.isInstantApp(mContext.getPackageName(),
+ mContext.getUserId());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
@Override
- public int getEphemeralCookieMaxSizeBytes() {
+ public int getInstantAppCookieMaxSize() {
return Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.EPHEMERAL_COOKIE_MAX_SIZE_BYTES,
DEFAULT_EPHEMERAL_COOKIE_MAX_SIZE_BYTES);
}
@Override
- public @NonNull byte[] getEphemeralCookie() {
+ public @NonNull byte[] getInstantAppCookie() {
try {
- final byte[] cookie = mPM.getEphemeralApplicationCookie(
+ final byte[] cookie = mPM.getInstantAppCookie(
mContext.getPackageName(), mContext.getUserId());
if (cookie != null) {
return cookie;
@@ -827,10 +826,10 @@ public class ApplicationPackageManager extends PackageManager {
}
@Override
- public boolean setEphemeralCookie(@NonNull byte[] cookie) {
+ public boolean setInstantAppCookie(@NonNull byte[] cookie) {
try {
- return mPM.setEphemeralApplicationCookie(
- mContext.getPackageName(), cookie, mContext.getUserId());
+ return mPM.setInstantAppCookie(mContext.getPackageName(),
+ cookie, mContext.getUserId());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
diff --git a/core/java/android/content/pm/ApplicationInfo.java b/core/java/android/content/pm/ApplicationInfo.java
index b53792f00150..8465f0fd5571 100644
--- a/core/java/android/content/pm/ApplicationInfo.java
+++ b/core/java/android/content/pm/ApplicationInfo.java
@@ -1409,7 +1409,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
/**
* @hide
*/
- public boolean isEphemeralApp() {
+ public boolean isInstantApp() {
return (privateFlags & ApplicationInfo.PRIVATE_FLAG_EPHEMERAL) != 0;
}
diff --git a/core/java/android/content/pm/IPackageManager.aidl b/core/java/android/content/pm/IPackageManager.aidl
index 4cf65ab5092f..2754452fd759 100644
--- a/core/java/android/content/pm/IPackageManager.aidl
+++ b/core/java/android/content/pm/IPackageManager.aidl
@@ -23,7 +23,7 @@ import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.ContainerEncryptionParams;
-import android.content.pm.EphemeralApplicationInfo;
+import android.content.pm.InstantAppInfo;
import android.content.pm.FeatureInfo;
import android.content.pm.IPackageInstallObserver2;
import android.content.pm.IPackageInstaller;
@@ -599,11 +599,11 @@ interface IPackageManager {
String getPermissionControllerPackageName();
- ParceledListSlice getEphemeralApplications(int userId);
- byte[] getEphemeralApplicationCookie(String packageName, int userId);
- boolean setEphemeralApplicationCookie(String packageName, in byte[] cookie, int userId);
- Bitmap getEphemeralApplicationIcon(String packageName, int userId);
- boolean isEphemeralApplication(String packageName, int userId);
+ ParceledListSlice getInstantApps(int userId);
+ byte[] getInstantAppCookie(String packageName, int userId);
+ boolean setInstantAppCookie(String packageName, in byte[] cookie, int userId);
+ Bitmap getInstantAppIcon(String packageName, int userId);
+ boolean isInstantApp(String packageName, int userId);
boolean setRequiredForSystemUser(String packageName, boolean systemUserApp);
diff --git a/core/java/android/content/pm/EphemeralApplicationInfo.aidl b/core/java/android/content/pm/InstantAppInfo.aidl
index 5aaae7847c7e..a35892f9e0b0 100644
--- a/core/java/android/content/pm/EphemeralApplicationInfo.aidl
+++ b/core/java/android/content/pm/InstantAppInfo.aidl
@@ -16,4 +16,4 @@
package android.content.pm;
-parcelable EphemeralApplicationInfo;
+parcelable InstantAppInfo; \ No newline at end of file
diff --git a/core/java/android/content/pm/EphemeralApplicationInfo.java b/core/java/android/content/pm/InstantAppInfo.java
index 87663f12e637..898ee1101c07 100644
--- a/core/java/android/content/pm/EphemeralApplicationInfo.java
+++ b/core/java/android/content/pm/InstantAppInfo.java
@@ -23,11 +23,15 @@ import android.os.Parcel;
import android.os.Parcelable;
/**
- * This class represents the state of an ephemeral app.
+ * This class represents the state of an instant app. Instant apps can
+ * be installed or uninstalled. If the app is installed you can call
+ * {@link #getApplicationInfo()} to get the app info, otherwise this
+ * class provides APIs to get basic app info for showing it in the UI,
+ * such as permissions, label, package name.
*
* @hide
*/
-public final class EphemeralApplicationInfo implements Parcelable {
+public final class InstantAppInfo implements Parcelable {
private final ApplicationInfo mApplicationInfo;
private final String mPackageName;
@@ -36,7 +40,7 @@ public final class EphemeralApplicationInfo implements Parcelable {
private final String[] mRequestedPermissions;
private final String[] mGrantedPermissions;
- public EphemeralApplicationInfo(ApplicationInfo appInfo,
+ public InstantAppInfo(ApplicationInfo appInfo,
String[] requestedPermissions, String[] grantedPermissions) {
mApplicationInfo = appInfo;
mPackageName = null;
@@ -45,7 +49,7 @@ public final class EphemeralApplicationInfo implements Parcelable {
mGrantedPermissions = grantedPermissions;
}
- public EphemeralApplicationInfo(String packageName, CharSequence label,
+ public InstantAppInfo(String packageName, CharSequence label,
String[] requestedPermissions, String[] grantedPermissions) {
mApplicationInfo = null;
mPackageName = packageName;
@@ -54,7 +58,7 @@ public final class EphemeralApplicationInfo implements Parcelable {
mGrantedPermissions = grantedPermissions;
}
- private EphemeralApplicationInfo(Parcel parcel) {
+ private InstantAppInfo(Parcel parcel) {
mPackageName = parcel.readString();
mLabelText = parcel.readCharSequence();
mRequestedPermissions = parcel.readStringArray();
@@ -62,6 +66,17 @@ public final class EphemeralApplicationInfo implements Parcelable {
mApplicationInfo = parcel.readParcelable(null);
}
+ /**
+ * @return The application info if the app is installed,
+ * <code>null</code> otherwise,
+ */
+ public @Nullable ApplicationInfo getApplicationInfo() {
+ return mApplicationInfo;
+ }
+
+ /**
+ * @return The pakcage name.
+ */
public @NonNull String getPackageName() {
if (mApplicationInfo != null) {
return mApplicationInfo.packageName;
@@ -69,6 +84,10 @@ public final class EphemeralApplicationInfo implements Parcelable {
return mPackageName;
}
+ /**
+ * @param packageManager Package manager for loading resources.
+ * @return Loads the label if the app is installed or returns the cached one otherwise.
+ */
public @NonNull CharSequence loadLabel(@NonNull PackageManager packageManager) {
if (mApplicationInfo != null) {
return mApplicationInfo.loadLabel(packageManager);
@@ -76,17 +95,27 @@ public final class EphemeralApplicationInfo implements Parcelable {
return mLabelText;
}
+ /**
+ * @param packageManager Package manager for loading resources.
+ * @return Loads the icon if the app is installed or returns the cached one otherwise.
+ */
public @NonNull Drawable loadIcon(@NonNull PackageManager packageManager) {
if (mApplicationInfo != null) {
return mApplicationInfo.loadIcon(packageManager);
}
- return packageManager.getEphemeralApplicationIcon(mPackageName);
+ return packageManager.getInstantAppIcon(mPackageName);
}
+ /**
+ * @return The requested permissions.
+ */
public @Nullable String[] getRequestedPermissions() {
return mRequestedPermissions;
}
+ /**
+ * @return The granted permissions.
+ */
public @Nullable String[] getGrantedPermissions() {
return mGrantedPermissions;
}
@@ -105,16 +134,16 @@ public final class EphemeralApplicationInfo implements Parcelable {
parcel.writeParcelable(mApplicationInfo, flags);
}
- public static final Creator<EphemeralApplicationInfo> CREATOR =
- new Creator<EphemeralApplicationInfo>() {
+ public static final Creator<InstantAppInfo> CREATOR =
+ new Creator<InstantAppInfo>() {
@Override
- public EphemeralApplicationInfo createFromParcel(Parcel parcel) {
- return new EphemeralApplicationInfo(parcel);
+ public InstantAppInfo createFromParcel(Parcel parcel) {
+ return new InstantAppInfo(parcel);
}
@Override
- public EphemeralApplicationInfo[] newArray(int size) {
- return new EphemeralApplicationInfo[0];
+ public InstantAppInfo[] newArray(int size) {
+ return new InstantAppInfo[0];
}
};
}
diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java
index 76c69ca29e53..ab641c916441 100644
--- a/core/java/android/content/pm/PackageManager.java
+++ b/core/java/android/content/pm/PackageManager.java
@@ -20,7 +20,6 @@ import android.Manifest;
import android.annotation.CheckResult;
import android.annotation.DrawableRes;
import android.annotation.IntDef;
-import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
@@ -3422,7 +3421,6 @@ public abstract class PackageManager {
*/
public abstract void removePermission(String name);
-
/**
* Permission flags set when granting or revoking a permission.
*
@@ -3698,89 +3696,86 @@ public abstract class PackageManager {
@ApplicationInfoFlags int flags, @UserIdInt int userId);
/**
- * Gets the ephemeral applications the user recently used. Requires
- * holding "android.permission.ACCESS_EPHEMERAL_APPS".
+ * Gets the instant applications the user recently used. Requires
+ * holding "android.permission.ACCESS_INSTANT_APPS".
*
- * @return The ephemeral app list.
+ * @return The instant app list.
*
* @hide
*/
- @RequiresPermission(Manifest.permission.ACCESS_EPHEMERAL_APPS)
- public abstract List<EphemeralApplicationInfo> getEphemeralApplications();
+ @RequiresPermission(Manifest.permission.ACCESS_INSTANT_APPS)
+ public abstract @NonNull List<InstantAppInfo> getInstantApps();
/**
- * Gets the icon for an ephemeral application.
+ * Gets the icon for an instant application.
*
* @param packageName The app package name.
*
* @hide
*/
- public abstract Drawable getEphemeralApplicationIcon(String packageName);
+ @RequiresPermission(Manifest.permission.ACCESS_INSTANT_APPS)
+ public abstract @Nullable Drawable getInstantAppIcon(String packageName);
/**
- * Gets whether the caller is an ephemeral app.
- *
- * @return Whether caller is an ephemeral app.
+ * Gets whether the caller is an instant app.
*
- * @see #setEphemeralCookie(byte[])
- * @see #getEphemeralCookie()
- * @see #getEphemeralCookieMaxSizeBytes()
+ * @return Whether caller is an instant app.
*
- * @hide
+ * @see #setInstantAppCookie(byte[])
+ * @see #getInstantAppCookie()
+ * @see #getInstantAppCookieMaxSize()
*/
- public abstract boolean isEphemeralApplication();
+ public abstract boolean isInstantApp();
/**
- * Gets the maximum size in bytes of the cookie data an ephemeral app
+ * Gets the maximum size in bytes of the cookie data an instant app
* can store on the device.
*
* @return The max cookie size in bytes.
*
- * @see #isEphemeralApplication()
- * @see #setEphemeralCookie(byte[])
- * @see #getEphemeralCookie()
- *
- * @hide
+ * @see #isInstantApp()
+ * @see #setInstantAppCookie(byte[])
+ * @see #getInstantAppCookie()
*/
- public abstract int getEphemeralCookieMaxSizeBytes();
+ public abstract int getInstantAppCookieMaxSize();
/**
- * Gets the ephemeral application cookie for this app. Non
- * ephemeral apps and apps that were ephemeral but were upgraded
- * to non-ephemeral can still access this API. For ephemeral apps
+ * 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
* normal apps the cookie is deleted after the app is uninstalled.
* The cookie is always present while the app is installed.
*
* @return The cookie.
*
- * @see #isEphemeralApplication()
- * @see #setEphemeralCookie(byte[])
- * @see #getEphemeralCookieMaxSizeBytes()
- *
- * @hide
+ * @see #isInstantApp()
+ * @see #setInstantAppCookie(byte[])
+ * @see #getInstantAppCookieMaxSize()
*/
- public abstract @NonNull byte[] getEphemeralCookie();
+ public abstract @NonNull byte[] getInstantAppCookie();
/**
- * Sets the ephemeral application cookie for the calling app. Non
- * ephemeral apps and apps that were ephemeral but were upgraded
- * to non-ephemeral can still access this API. For ephemeral apps
+ * 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 #getEphemeralCookieMaxSizeBytes()}.
+ * 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 True if the cookie was set.
+ * @return Whether the cookie was set.
*
- * @see #isEphemeralApplication()
- * @see #getEphemeralCookieMaxSizeBytes()
- * @see #getEphemeralCookie()
- *
- * @hide
+ * @see #isInstantApp()
+ * @see #getInstantAppCookieMaxSize()
+ * @see #getInstantAppCookie()
*/
- public abstract boolean setEphemeralCookie(@NonNull byte[] cookie);
+ public abstract boolean setInstantAppCookie(@Nullable byte[] cookie);
/**
* Get a list of shared libraries that are available on the
diff --git a/core/java/android/content/pm/PackageManagerInternal.java b/core/java/android/content/pm/PackageManagerInternal.java
index e3e02b1f72a6..e4e0a195cb8d 100644
--- a/core/java/android/content/pm/PackageManagerInternal.java
+++ b/core/java/android/content/pm/PackageManagerInternal.java
@@ -243,6 +243,12 @@ public abstract class PackageManagerInternal {
int targetAppId, int ephemeralAppId);
/**
+ * Prunes instant apps and state associated with uninstalled
+ * instant apps according to the current platform policy.
+ */
+ public abstract void pruneInstantApps();
+
+ /**
* @return The SetupWizard package name.
*/
public abstract String getSetupWizardPackageName();
diff --git a/core/java/android/content/pm/PermissionInfo.java b/core/java/android/content/pm/PermissionInfo.java
index 6901ba1a21b6..0703138287ba 100644
--- a/core/java/android/content/pm/PermissionInfo.java
+++ b/core/java/android/content/pm/PermissionInfo.java
@@ -120,7 +120,6 @@ public class PermissionInfo extends PackageItemInfo implements Parcelable {
*/
public static final int PROTECTION_FLAG_SETUP = 0x800;
-
/**
* Additional flag for {@link #protectionLevel}, corresponding
* to the <code>ephemeral</code> value of
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index f7ebf99a9bd3..9bc7034d1e19 100755
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -9504,13 +9504,13 @@ public final class Settings {
public static final String ENABLE_EPHEMERAL_FEATURE = "enable_ephemeral_feature";
/**
- * The duration for caching uninstalled ephemeral apps.
+ * The duration for caching uninstalled instant apps.
* <p>
* Type: long
* @hide
*/
- public static final String UNINSTALLED_EPHEMERAL_APP_CACHE_DURATION_MILLIS =
- "uninstalled_ephemeral_app_cache_duration_millis";
+ public static final String UNINSTALLED_INSTANT_APP_CACHE_DURATION_MILLIS =
+ "uninstalled_instant_app_cache_duration_millis";
/**
* Allows switching users when system user is locked.