diff options
| author | Winson <chiuwinson@google.com> | 2021-10-05 14:21:42 -0700 |
|---|---|---|
| committer | Winson <chiuwinson@google.com> | 2021-11-02 13:18:58 -0700 |
| commit | 11aff8d1b6818bd4deaee42dcbc4c231f68b453d (patch) | |
| tree | 8f65dc9f56ffa7f3515a44fa74a313ae649990bb /core/java | |
| parent | da66fe32373243f8aea362efb716c0cf8ef5248c (diff) | |
Update package data API docs
Fills some holes in missing documentation, mostly for internal
APIs.
Bug: 198306069
Test: none, docs change with no logical changes
Change-Id: I6fca53054f83f634c320197656876818c1716f5c
Diffstat (limited to 'core/java')
7 files changed, 310 insertions, 176 deletions
diff --git a/core/java/android/content/pm/PackageInfo.java b/core/java/android/content/pm/PackageInfo.java index 0462a4b2b681..eefa63f5b8fa 100644 --- a/core/java/android/content/pm/PackageInfo.java +++ b/core/java/android/content/pm/PackageInfo.java @@ -346,20 +346,44 @@ public class PackageInfo implements Parcelable { */ public int installLocation = INSTALL_LOCATION_INTERNAL_ONLY; - /** @hide */ + /** + * Whether or not the package is a stub and should be replaced by a full version of the app. + * + * @hide + */ public boolean isStub; - /** @hide */ + /** + * Whether the app is included when the device is booted into a minimal state. Set through the + * non-namespaced "coreApp" attribute of the manifest tag. + * + * @hide + */ @UnsupportedAppUsage public boolean coreApp; - /** @hide */ + /** + * Signals that this app is required for all users on the device. + * + * When a restricted user profile is created, the user is prompted with a list of apps to + * install on that user. Settings uses this field to determine obligatory apps which cannot be + * deselected. + * + * This restriction is not handled by the framework itself. + * @hide + */ public boolean requiredForAllUsers; - /** @hide */ + /** + * The restricted account authenticator type that is used by this application. + * @hide + */ public String restrictedAccountType; - /** @hide */ + /** + * The required account type without which this application will not function. + * @hide + */ public String requiredAccountType; /** diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java index 07151ecaaee5..b1777a0d1f91 100644 --- a/core/java/android/content/pm/PackageManager.java +++ b/core/java/android/content/pm/PackageManager.java @@ -49,7 +49,6 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.IntentSender; import android.content.pm.dex.ArtManager; -import android.content.pm.pkg.PackageUserState; import android.content.pm.verify.domain.DomainVerificationManager; import android.content.res.Configuration; import android.content.res.Resources; @@ -4479,6 +4478,20 @@ public abstract class PackageManager { @TestApi public static final String SYSTEM_SHARED_LIBRARY_SHARED = "android.ext.shared"; + /** @hide */ + @IntDef({ + NOTIFY_PACKAGE_USE_ACTIVITY, + NOTIFY_PACKAGE_USE_SERVICE, + NOTIFY_PACKAGE_USE_FOREGROUND_SERVICE, + NOTIFY_PACKAGE_USE_BROADCAST_RECEIVER, + NOTIFY_PACKAGE_USE_CONTENT_PROVIDER, + NOTIFY_PACKAGE_USE_BACKUP, + NOTIFY_PACKAGE_USE_CROSS_PACKAGE, + NOTIFY_PACKAGE_USE_INSTRUMENTATION, + }) + public @interface NotifyReason { + } + /** * Used when starting a process for an Activity. * diff --git a/core/java/android/content/pm/parsing/PkgWithoutStatePackageInfo.java b/core/java/android/content/pm/parsing/PkgWithoutStatePackageInfo.java index b10e6fe5014d..7a3450032b57 100644 --- a/core/java/android/content/pm/parsing/PkgWithoutStatePackageInfo.java +++ b/core/java/android/content/pm/parsing/PkgWithoutStatePackageInfo.java @@ -18,6 +18,7 @@ package android.content.pm.parsing; import android.annotation.NonNull; import android.annotation.Nullable; +import android.content.ComponentName; import android.content.pm.ActivityInfo; import android.content.pm.ApplicationInfo; import android.content.pm.ConfigurationInfo; @@ -74,6 +75,14 @@ import java.util.List; public interface PkgWithoutStatePackageInfo { /** + * Set of Activities parsed from the manifest. + * + * This contains minimal system state and does not + * provide the same information as {@link ActivityInfo}. Effective state can be queried through + * {@link android.content.pm.PackageManager#getActivityInfo(ComponentName, int)} or by + * combining state from from com.android.server.pm.pkg.PackageState and + * {@link android.content.pm.pkg.PackageUserState}. + * * @see ActivityInfo * @see PackageInfo#activities */ @@ -137,6 +146,14 @@ public interface PkgWithoutStatePackageInfo { List<ParsedPermission> getPermissions(); /** + * Set of {@link android.content.ContentProvider ContentProviders} parsed from the manifest. + * + * This contains minimal system state and does not + * provide the same information as {@link ProviderInfo}. Effective state can be queried through + * {@link android.content.pm.PackageManager#getProviderInfo(ComponentName, int)} or by + * combining state from from com.android.server.pm.pkg.PackageState and + * {@link android.content.pm.pkg.PackageUserState}. + * * @see ProviderInfo * @see PackageInfo#providers */ @@ -144,9 +161,18 @@ public interface PkgWithoutStatePackageInfo { List<ParsedProvider> getProviders(); /** + * Set of {@link android.content.BroadcastReceiver BroadcastReceivers} parsed from the manifest. + * + * This contains minimal system state and does not + * provide the same information as {@link ActivityInfo}. Effective state can be queried through + * {@link android.content.pm.PackageManager#getReceiverInfo(ComponentName, int)} or by + * combining state from from com.android.server.pm.pkg.PackageState and + * {@link android.content.pm.pkg.PackageUserState}. + * * Since they share several attributes, receivers are parsed as {@link ParsedActivity}, even - * though they represent different functionality. TODO(b/135203078): Reconsider this and maybe - * make ParsedReceiver so it's not so confusing + * though they represent different functionality. + * + * TODO(b/135203078): Reconsider this and maybe make ParsedReceiver so it's not so confusing * * @see ActivityInfo * @see PackageInfo#receivers @@ -173,8 +199,6 @@ public interface PkgWithoutStatePackageInfo { List<String> getRequestedPermissions(); /** - * The required account type without which this application will not function. - * * @see PackageInfo#requiredAccountType * @see R.styleable#AndroidManifestApplication_requiredAccountType */ @@ -182,7 +206,7 @@ public interface PkgWithoutStatePackageInfo { String getRequiredAccountType(); /** - * The restricted account authenticator type that is used by this application + * The restricted account authenticator type that is used by this application. * * @see PackageInfo#restrictedAccountType * @see R.styleable#AndroidManifestApplication_restrictedAccountType @@ -191,6 +215,14 @@ public interface PkgWithoutStatePackageInfo { String getRestrictedAccountType(); /** + * Set of {@link android.app.Service Services} parsed from the manifest. + * + * This contains minimal system state and does not + * provide the same information as {@link ServiceInfo}. Effective state can be queried through + * {@link android.content.pm.PackageManager#getServiceInfo(ComponentName, int)} or by + * combining state from from com.android.server.pm.pkg.PackageState and + * {@link android.content.pm.pkg.PackageUserState}. + * * @see ServiceInfo * @see PackageInfo#services */ diff --git a/core/java/android/content/pm/pkg/PackageUserState.java b/core/java/android/content/pm/pkg/PackageUserState.java index e0d1eead903d..370dabe2ca87 100644 --- a/core/java/android/content/pm/pkg/PackageUserState.java +++ b/core/java/android/content/pm/pkg/PackageUserState.java @@ -18,34 +18,17 @@ package android.content.pm.pkg; import android.annotation.NonNull; import android.annotation.Nullable; -import android.annotation.SystemApi; import android.content.pm.PackageManager; -import android.content.pm.SuspendDialogInfo; import android.content.pm.overlay.OverlayPaths; -import android.os.BaseBundle; -import android.os.PersistableBundle; -import android.util.Slog; -import android.util.TypedXmlPullParser; -import android.util.TypedXmlSerializer; +import android.os.UserHandle; -import org.xmlpull.v1.XmlPullParser; -import org.xmlpull.v1.XmlPullParserException; -import org.xmlpull.v1.XmlSerializer; - -import java.io.IOException; -import java.util.Collections; import java.util.Map; -import java.util.Objects; import java.util.Set; /** * The API surface for a {@link PackageUserStateImpl}. Methods are expected to return * immutable objects. This may mean copying data on each invocation until related classes are * refactored to be immutable. - * <p> - * TODO: Replace implementation usage with the interface. Currently the name overlap is intentional. - * <p> - * * @hide */ // TODO(b/173807334): Expose API @@ -55,7 +38,7 @@ public interface PackageUserState { PackageUserState DEFAULT = new PackageUserStateDefault(); /** - * {@link #getOverlayPaths()} but also include shared library overlay paths. + * Combination of {@link #getOverlayPaths()} and {@link #getSharedLibraryOverlayPaths()} */ @Nullable OverlayPaths getAllOverlayPaths(); @@ -65,23 +48,39 @@ public interface PackageUserState { */ long getCeDataInode(); + /** + * Fully qualified class names of components explicitly disabled. + */ @NonNull Set<String> getDisabledComponents(); @PackageManager.DistractionRestriction int getDistractionFlags(); + /** + * Fully qualified class names of components explicitly enabled. + */ @NonNull Set<String> getEnabledComponents(); + /** + * Retrieve the effective enabled state of the package itself. + */ + @PackageManager.EnabledState int getEnabledState(); + /** + * @see PackageManager#setHarmfulAppWarning(String, CharSequence) + */ @Nullable String getHarmfulAppWarning(); @PackageManager.InstallReason int getInstallReason(); + /** + * Tracks the last calling package to set a specific enabled state for the package. + */ @Nullable String getLastDisableAppCaller(); @@ -94,169 +93,60 @@ public interface PackageUserState { @PackageManager.UninstallReason int getUninstallReason(); + /** + * @return whether the given fully qualified class name is explicitly enabled + */ boolean isComponentEnabled(@NonNull String componentName); + /** + * @return {@link #isComponentEnabled(String)} but for explicitly disabled + */ boolean isComponentDisabled(@NonNull String componentName); + /** + * @see PackageManager#setApplicationHiddenSettingAsUser(String, boolean, UserHandle) + */ boolean isHidden(); + /** + * @return whether the package is marked as installed for all users + */ boolean isInstalled(); + /** + * @return whether the package is marked as an ephemeral app, which restricts permissions, + * features, visibility + */ boolean isInstantApp(); + /** + * @return whether the package has not been launched since being explicitly stopped + */ boolean isNotLaunched(); + /** + * @return whether the package has been stopped, which can occur if it's force-stopped, data + * cleared, or just been installed + */ boolean isStopped(); + /** + * @return whether the package has been suspended, maybe by the device admin, disallowing its + * launch + */ boolean isSuspended(); + /** + * @return whether the package was installed as a virtual preload, which may be done as part + * of device infrastructure auto installation outside of the initial device image + */ boolean isVirtualPreload(); - @Nullable - String getSplashScreenTheme(); - /** - * Container to describe suspension parameters. + * The "package:type/entry" form of the theme resource ID previously set as the splash screen. + * @see android.window.SplashScreen#setSplashScreenTheme(int) + * @see android.content.res.Resources#getResourceName(int) */ - final class SuspendParams { - - private static final String LOG_TAG = "PackageUserState"; - private static final String TAG_DIALOG_INFO = "dialog-info"; - private static final String TAG_APP_EXTRAS = "app-extras"; - private static final String TAG_LAUNCHER_EXTRAS = "launcher-extras"; - - public SuspendDialogInfo dialogInfo; - public PersistableBundle appExtras; - public PersistableBundle launcherExtras; - - private SuspendParams() { - } - - /** - * Returns a {@link SuspendParams} object with the given fields. Returns {@code null} if all - * the fields are {@code null}. - * - * @param dialogInfo - * @param appExtras - * @param launcherExtras - * @return A {@link SuspendParams} object or {@code null}. - */ - public static SuspendParams getInstanceOrNull(SuspendDialogInfo dialogInfo, - PersistableBundle appExtras, PersistableBundle launcherExtras) { - if (dialogInfo == null && appExtras == null && launcherExtras == null) { - return null; - } - final SuspendParams instance = new SuspendParams(); - instance.dialogInfo = dialogInfo; - instance.appExtras = appExtras; - instance.launcherExtras = launcherExtras; - return instance; - } - - @Override - public boolean equals(@Nullable Object obj) { - if (this == obj) { - return true; - } - if (!(obj instanceof SuspendParams)) { - return false; - } - final SuspendParams other = (SuspendParams) obj; - if (!Objects.equals(dialogInfo, other.dialogInfo)) { - return false; - } - if (!BaseBundle.kindofEquals(appExtras, other.appExtras)) { - return false; - } - if (!BaseBundle.kindofEquals(launcherExtras, other.launcherExtras)) { - return false; - } - return true; - } - - @Override - public int hashCode() { - int hashCode = Objects.hashCode(dialogInfo); - hashCode = 31 * hashCode + ((appExtras != null) ? appExtras.size() : 0); - hashCode = 31 * hashCode + ((launcherExtras != null) ? launcherExtras.size() : 0); - return hashCode; - } - - /** - * Serializes this object into an xml format - * @param out the {@link XmlSerializer} object - * @throws IOException - */ - public void saveToXml(TypedXmlSerializer out) throws IOException { - if (dialogInfo != null) { - out.startTag(null, TAG_DIALOG_INFO); - dialogInfo.saveToXml(out); - out.endTag(null, TAG_DIALOG_INFO); - } - if (appExtras != null) { - out.startTag(null, TAG_APP_EXTRAS); - try { - appExtras.saveToXml(out); - } catch (XmlPullParserException e) { - Slog.e(LOG_TAG, "Exception while trying to write appExtras." - + " Will be lost on reboot", e); - } - out.endTag(null, TAG_APP_EXTRAS); - } - if (launcherExtras != null) { - out.startTag(null, TAG_LAUNCHER_EXTRAS); - try { - launcherExtras.saveToXml(out); - } catch (XmlPullParserException e) { - Slog.e(LOG_TAG, "Exception while trying to write launcherExtras." - + " Will be lost on reboot", e); - } - out.endTag(null, TAG_LAUNCHER_EXTRAS); - } - } - - /** - * Parses this object from the xml format. Returns {@code null} if no object related - * information could be read. - * @param in the reader - * @return - */ - public static SuspendParams restoreFromXml(TypedXmlPullParser in) throws IOException { - SuspendDialogInfo readDialogInfo = null; - PersistableBundle readAppExtras = null; - PersistableBundle readLauncherExtras = null; - - final int currentDepth = in.getDepth(); - int type; - try { - while ((type = in.next()) != XmlPullParser.END_DOCUMENT - && (type != XmlPullParser.END_TAG - || in.getDepth() > currentDepth)) { - if (type == XmlPullParser.END_TAG - || type == XmlPullParser.TEXT) { - continue; - } - switch (in.getName()) { - case TAG_DIALOG_INFO: - readDialogInfo = SuspendDialogInfo.restoreFromXml(in); - break; - case TAG_APP_EXTRAS: - readAppExtras = PersistableBundle.restoreFromXml(in); - break; - case TAG_LAUNCHER_EXTRAS: - readLauncherExtras = PersistableBundle.restoreFromXml(in); - break; - default: - Slog.w(LOG_TAG, "Unknown tag " + in.getName() - + " in SuspendParams. Ignoring"); - break; - } - } - } catch (XmlPullParserException e) { - Slog.e(LOG_TAG, "Exception while trying to parse SuspendParams," - + " some fields may default", e); - } - return getInstanceOrNull(readDialogInfo, readAppExtras, readLauncherExtras); - } - } + @Nullable + String getSplashScreenTheme(); } diff --git a/core/java/android/content/pm/pkg/PackageUserStateDefault.java b/core/java/android/content/pm/pkg/PackageUserStateDefault.java index 6bee8c858a5c..9d4deed6c641 100644 --- a/core/java/android/content/pm/pkg/PackageUserStateDefault.java +++ b/core/java/android/content/pm/pkg/PackageUserStateDefault.java @@ -139,6 +139,7 @@ class PackageUserStateDefault implements PackageUserState { return false; } + @Nullable @Override public OverlayPaths getAllOverlayPaths() { return null; diff --git a/core/java/android/content/pm/pkg/PackageUserStateImpl.java b/core/java/android/content/pm/pkg/PackageUserStateImpl.java index 4d1b236f0b95..e02061cac7c1 100644 --- a/core/java/android/content/pm/pkg/PackageUserStateImpl.java +++ b/core/java/android/content/pm/pkg/PackageUserStateImpl.java @@ -130,7 +130,6 @@ public class PackageUserStateImpl implements PackageUserState { } - // Code below generated by codegen v1.0.23. // // DO NOT MODIFY! diff --git a/core/java/android/content/pm/pkg/SuspendParams.java b/core/java/android/content/pm/pkg/SuspendParams.java new file mode 100644 index 000000000000..d166ee72f24f --- /dev/null +++ b/core/java/android/content/pm/pkg/SuspendParams.java @@ -0,0 +1,175 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.content.pm.pkg; + +import android.annotation.Nullable; +import android.content.pm.SuspendDialogInfo; +import android.os.BaseBundle; +import android.os.PersistableBundle; +import android.util.Slog; +import android.util.TypedXmlPullParser; +import android.util.TypedXmlSerializer; + +import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; +import org.xmlpull.v1.XmlSerializer; + +import java.io.IOException; +import java.util.Objects; + +/** + * Container to describe suspension parameters. + * @hide + */ +public final class SuspendParams { + + private static final String LOG_TAG = "PackageUserState"; + private static final String TAG_DIALOG_INFO = "dialog-info"; + private static final String TAG_APP_EXTRAS = "app-extras"; + private static final String TAG_LAUNCHER_EXTRAS = "launcher-extras"; + + public SuspendDialogInfo dialogInfo; + public PersistableBundle appExtras; + public PersistableBundle launcherExtras; + + private SuspendParams() { + } + + /** + * Returns a {@link SuspendParams} object with the given fields. Returns {@code null} if all + * the fields are {@code null}. + * + * @return A {@link SuspendParams} object or {@code null}. + */ + public static SuspendParams getInstanceOrNull(SuspendDialogInfo dialogInfo, + PersistableBundle appExtras, PersistableBundle launcherExtras) { + if (dialogInfo == null && appExtras == null && launcherExtras == null) { + return null; + } + final SuspendParams instance = new SuspendParams(); + instance.dialogInfo = dialogInfo; + instance.appExtras = appExtras; + instance.launcherExtras = launcherExtras; + return instance; + } + + @Override + public boolean equals(@Nullable Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof SuspendParams)) { + return false; + } + final SuspendParams other = (SuspendParams) obj; + if (!Objects.equals(dialogInfo, other.dialogInfo)) { + return false; + } + if (!BaseBundle.kindofEquals(appExtras, other.appExtras)) { + return false; + } + if (!BaseBundle.kindofEquals(launcherExtras, other.launcherExtras)) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int hashCode = Objects.hashCode(dialogInfo); + hashCode = 31 * hashCode + ((appExtras != null) ? appExtras.size() : 0); + hashCode = 31 * hashCode + ((launcherExtras != null) ? launcherExtras.size() : 0); + return hashCode; + } + + /** + * Serializes this object into an xml format + * + * @param out the {@link XmlSerializer} object + */ + public void saveToXml(TypedXmlSerializer out) throws IOException { + if (dialogInfo != null) { + out.startTag(null, TAG_DIALOG_INFO); + dialogInfo.saveToXml(out); + out.endTag(null, TAG_DIALOG_INFO); + } + if (appExtras != null) { + out.startTag(null, TAG_APP_EXTRAS); + try { + appExtras.saveToXml(out); + } catch (XmlPullParserException e) { + Slog.e(LOG_TAG, "Exception while trying to write appExtras." + + " Will be lost on reboot", e); + } + out.endTag(null, TAG_APP_EXTRAS); + } + if (launcherExtras != null) { + out.startTag(null, TAG_LAUNCHER_EXTRAS); + try { + launcherExtras.saveToXml(out); + } catch (XmlPullParserException e) { + Slog.e(LOG_TAG, "Exception while trying to write launcherExtras." + + " Will be lost on reboot", e); + } + out.endTag(null, TAG_LAUNCHER_EXTRAS); + } + } + + /** + * Parses this object from the xml format. Returns {@code null} if no object related + * information could be read. + * + * @param in the reader + */ + public static SuspendParams restoreFromXml(TypedXmlPullParser in) throws IOException { + SuspendDialogInfo readDialogInfo = null; + PersistableBundle readAppExtras = null; + PersistableBundle readLauncherExtras = null; + + final int currentDepth = in.getDepth(); + int type; + try { + while ((type = in.next()) != XmlPullParser.END_DOCUMENT + && (type != XmlPullParser.END_TAG + || in.getDepth() > currentDepth)) { + if (type == XmlPullParser.END_TAG + || type == XmlPullParser.TEXT) { + continue; + } + switch (in.getName()) { + case TAG_DIALOG_INFO: + readDialogInfo = SuspendDialogInfo.restoreFromXml(in); + break; + case TAG_APP_EXTRAS: + readAppExtras = PersistableBundle.restoreFromXml(in); + break; + case TAG_LAUNCHER_EXTRAS: + readLauncherExtras = PersistableBundle.restoreFromXml(in); + break; + default: + Slog.w(LOG_TAG, "Unknown tag " + in.getName() + + " in SuspendParams. Ignoring"); + break; + } + } + } catch (XmlPullParserException e) { + Slog.e(LOG_TAG, "Exception while trying to parse SuspendParams," + + " some fields may default", e); + } + return getInstanceOrNull(readDialogInfo, readAppExtras, readLauncherExtras); + } +} |
