Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 11aff8d1 authored by Winson's avatar Winson
Browse files

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
parent da66fe32
Loading
Loading
Loading
Loading
+29 −5
Original line number Diff line number Diff line
@@ -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;

    /**
+14 −1
Original line number Diff line number Diff line
@@ -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.
     *
+37 −5
Original line number Diff line number Diff line
@@ -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
     */
+54 −164
Original line number Diff line number Diff line
@@ -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();

    boolean isStopped();

    boolean isSuspended();

    boolean isVirtualPreload();

    @Nullable
    String getSplashScreenTheme();

    /**
     * Container to describe suspension parameters.
     * @return whether the package has been stopped, which can occur if it's force-stopped, data
     * cleared, or just been installed
     */
    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() {
        }
    boolean isStopped();

    /**
         * 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}.
     * @return whether the package has been suspended, maybe by the device admin, disallowing its
     * launch
     */
        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;
        }
    boolean isSuspended();

    /**
         * Serializes this object into an xml format
         * @param out the {@link XmlSerializer} object
         * @throws IOException
     * @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
     */
        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);
            }
        }
    boolean isVirtualPreload();

    /**
         * Parses this object from the xml format. Returns {@code null} if no object related
         * information could be read.
         * @param in the reader
         * @return
     * 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)
     */
        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();
}
+1 −0
Original line number Diff line number Diff line
@@ -139,6 +139,7 @@ class PackageUserStateDefault implements PackageUserState {
        return false;
    }

    @Nullable
    @Override
    public OverlayPaths getAllOverlayPaths() {
        return null;
Loading