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

Commit 3309398c authored by Songchun Fan's avatar Songchun Fan
Browse files

[incremental/pm] app states and transitions

Based on go/incremental-states-design with basic
setter/getters.

Defines IncrementalStates class which handles state transitions.

New (internal) Intent actions: PACKAGE_FULLY_LOADED, PACKAGE_STARTABLE,
PACKAGE_UNSTARTABLE.

BUG: 168043976
Test: unit tests
Change-Id: I7b0ec2dd9f028ee620a9307a1e71ddf12ea5a9af
parent f2c9466e
Loading
Loading
Loading
Loading
+48 −0
Original line number Diff line number Diff line
@@ -2731,6 +2731,54 @@ public class Intent implements Parcelable, Cloneable {
    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    public static final String ACTION_MY_PACKAGE_UNSUSPENDED = "android.intent.action.MY_PACKAGE_UNSUSPENDED";

    /**
     * Broadcast Action: Sent to indicate that the package becomes startable.
     * The intent will have the following extra values:
     * <ul>
     * <li> {@link #EXTRA_UID} containing the integer uid assigned to the package. </li>
     * <li> {@link #EXTRA_PACKAGE_NAME} containing the package name. </li>
     * </li>
     * </ul>
     *
     * <p class="note">This is a protected intent that can only be sent by the system.
     * @hide
     */
    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    public static final String ACTION_PACKAGE_STARTABLE = "android.intent.action.PACKAGE_STARTABLE";

    /**
     * Broadcast Action: Sent to indicate that the package becomes unstartable.
     * The intent will have the following extra values:
     * <ul>
     * <li> {@link #EXTRA_UID} containing the integer uid assigned to the package. </li>
     * <li> {@link #EXTRA_PACKAGE_NAME} containing the package name. </li>
     * <li> {@link #EXTRA_REASON} containing the integer indicating the reason for the state change,
     * @see PackageManager.UnstartableReason
     * </li>
     * </ul>
     *
     * <p class="note">This is a protected intent that can only be sent by the system.
     * @hide
     */
    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    public static final String ACTION_PACKAGE_UNSTARTABLE =
            "android.intent.action.PACKAGE_UNSTARTABLE";

    /**
     * Broadcast Action: Sent to indicate that the package is fully loaded.
     * <ul>
     * <li> {@link #EXTRA_UID} containing the integer uid assigned to the package. </li>
     * <li> {@link #EXTRA_PACKAGE_NAME} containing the package name. </li>
     * </li>
     * </ul>
     *
     * <p class="note">This is a protected intent that can only be sent by the system.
     * @hide
     */
    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    public static final String ACTION_PACKAGE_FULLY_LOADED =
            "android.intent.action.PACKAGE_FULLY_LOADED";

    /**
     * Broadcast Action: A user ID has been removed from the system.  The user
     * ID number is stored in the extra data under {@link #EXTRA_UID}.
+23 −0
Original line number Diff line number Diff line
@@ -50,7 +50,30 @@ oneway interface IDataLoaderStatusListener {
    *            fail and all retry limits are exceeded. */
    const int DATA_LOADER_UNRECOVERABLE = 8;

    /** There are no known issues with the data stream. */
    const int STREAM_HEALTHY = 0;

    /** There are issues with the current transport layer (network, adb connection, etc.) that may
     * recover automatically or could eventually require user intervention. */
    const int STREAM_TRANSPORT_ERROR = 1;

    /** Integrity failures in the data stream, this could be due to file corruption, decompression
     * issues or similar. This indicates a likely unrecoverable error. */
    const int STREAM_INTEGRITY_ERROR = 2;

    /** There are issues with the source of the data, e.g., backend availability issues, account
     * issues. This indicates a potentially recoverable error, but one that may take a long time to
     * resolve. */
    const int STREAM_SOURCE_ERROR = 3;

    /** The device or app is low on storage and cannot complete the stream as a result.
      * A subsequent page miss resulting in app failure will transition app to unstartable state. */
    const int STREAM_STORAGE_ERROR = 4;

    /** Data loader status callback */
    void onStatusChanged(in int dataLoaderId, in int status);

    /** Callback to report streaming health status of a specific data loader */
    void reportStreamHealth(in int dataLoaderId, in int streamStatus);
}
+20 −0
Original line number Diff line number Diff line
/*
**
** Copyright 2020, 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 com.android.server.pm;

parcelable IncrementalStatesInfo;
 No newline at end of file
+76 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * Info about a package's states in Parcelable format.
 * @hide
 */
public class IncrementalStatesInfo implements Parcelable {
    private boolean mIsStartable;
    private boolean mIsLoading;
    private float mProgress;

    public IncrementalStatesInfo(boolean isStartable, boolean isLoading, float progress) {
        mIsStartable = isStartable;
        mIsLoading = isLoading;
        mProgress = progress;
    }

    private IncrementalStatesInfo(Parcel source) {
        mIsStartable = source.readBoolean();
        mIsLoading = source.readBoolean();
        mProgress = source.readFloat();
    }

    public boolean isStartable() {
        return mIsStartable;
    }

    public boolean isLoading() {
        return mIsLoading;
    }

    public float getProgress() {
        return mProgress;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeBoolean(mIsStartable);
        dest.writeBoolean(mIsLoading);
        dest.writeFloat(mProgress);
    }

    public static final @android.annotation.NonNull Creator<IncrementalStatesInfo> CREATOR =
            new Creator<IncrementalStatesInfo>() {
                public IncrementalStatesInfo createFromParcel(Parcel source) {
                    return new IncrementalStatesInfo(source);
                }
                public IncrementalStatesInfo[] newArray(int size) {
                    return new IncrementalStatesInfo[size];
                }
            };
}
+33 −0
Original line number Diff line number Diff line
@@ -3738,6 +3738,39 @@ public abstract class PackageManager {
     */
    public static final int SYSTEM_APP_STATE_UNINSTALLED = 3;

    /**
     * Reasons for why a package is unstartable.
     * @hide
     */
    @IntDef({UNSTARTABLE_REASON_UNKNOWN,
            UNSTARTABLE_REASON_DATALOADER_TRANSPORT,
            UNSTARTABLE_REASON_DATALOADER_STORAGE
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface UnstartableReason {}

    /**
     * Unstartable state with no root cause specified. E.g., data loader seeing missing pages but
     * unclear about the cause. This corresponds to a generic alert window shown to the user when
     * the user attempts to launch the app.
     * @hide
     */
    public static final int UNSTARTABLE_REASON_UNKNOWN = 0;

    /**
     * Unstartable state after hint from dataloader of issues with the transport layer.
     * This corresponds to an alert window shown to the user indicating network errors.
     * @hide
     */
    public static final int UNSTARTABLE_REASON_DATALOADER_TRANSPORT = 1;

    /**
     * Unstartable state after encountering storage limitations.
     * This corresponds to an alert window indicating limited storage.
     * @hide
     */
    public static final int UNSTARTABLE_REASON_DATALOADER_STORAGE = 2;

    /** {@hide} */
    public int getUserId() {
        return UserHandle.myUserId();
Loading