13a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey/*
23a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey * Copyright (C) 2014 The Android Open Source Project
33a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey *
43a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey * Licensed under the Apache License, Version 2.0 (the "License");
53a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey * you may not use this file except in compliance with the License.
63a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey * You may obtain a copy of the License at
73a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey *
83a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey *      http://www.apache.org/licenses/LICENSE-2.0
93a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey *
103a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey * Unless required by applicable law or agreed to in writing, software
113a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey * distributed under the License is distributed on an "AS IS" BASIS,
123a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
133a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey * See the License for the specific language governing permissions and
143a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey * limitations under the License.
153a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey */
163a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey
173a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkeypackage android.content.pm;
183a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey
1916c8e3f49497b6046972ae650772f65768366be8Jeff Sharkeyimport android.annotation.NonNull;
2016c8e3f49497b6046972ae650772f65768366be8Jeff Sharkeyimport android.annotation.Nullable;
217121e18595d4c559044e26bfe6035406a862f466Svet Ganovimport android.annotation.RequiresPermission;
221cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkeyimport android.annotation.SdkConstant;
231cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkeyimport android.annotation.SdkConstant.SdkConstantType;
247121e18595d4c559044e26bfe6035406a862f466Svet Ganovimport android.annotation.SystemApi;
25a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkeyimport android.app.ActivityManager;
26a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkeyimport android.content.Context;
27fbd0e9fa37fc17ccd25e4c1f16195bbd27de3c4cJeff Sharkeyimport android.content.Intent;
28a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkeyimport android.content.IntentSender;
29a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkeyimport android.graphics.Bitmap;
30a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkeyimport android.net.Uri;
3178cc340c2de873d6995c283b777476f7237d690fJeff Sharkeyimport android.os.FileBridge;
3216c8e3f49497b6046972ae650772f65768366be8Jeff Sharkeyimport android.os.Handler;
3316c8e3f49497b6046972ae650772f65768366be8Jeff Sharkeyimport android.os.Looper;
3416c8e3f49497b6046972ae650772f65768366be8Jeff Sharkeyimport android.os.Message;
35a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkeyimport android.os.Parcel;
363a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkeyimport android.os.ParcelFileDescriptor;
37a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkeyimport android.os.Parcelable;
383a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkeyimport android.os.RemoteException;
39a10311434778ea1be1621c2251c0c8c2966f337bJeff Sharkeyimport android.util.ExceptionUtils;
40a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkeyimport android.util.Log;
41a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey
42a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkeyimport com.android.internal.util.IndentingPrintWriter;
433a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey
44ec55ef0934b8e0d1bb705434947de817f7be57f1Jeff Sharkeyimport java.io.Closeable;
45a10311434778ea1be1621c2251c0c8c2966f337bJeff Sharkeyimport java.io.IOException;
461cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkeyimport java.io.InputStream;
4778cc340c2de873d6995c283b777476f7237d690fJeff Sharkeyimport java.io.OutputStream;
481cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkeyimport java.security.MessageDigest;
4916c8e3f49497b6046972ae650772f65768366be8Jeff Sharkeyimport java.util.ArrayList;
50941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkeyimport java.util.Collections;
5116c8e3f49497b6046972ae650772f65768366be8Jeff Sharkeyimport java.util.Iterator;
52bb580670350b76fa2fcc5ee873f99b7970759cbfJeff Sharkeyimport java.util.List;
5378cc340c2de873d6995c283b777476f7237d690fJeff Sharkey
546c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey/**
556c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey * Offers the ability to install, upgrade, and remove applications on the
566c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey * device. This includes support for apps packaged either as a single
576c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey * "monolithic" APK, or apps packaged as multiple "split" APKs.
586c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey * <p>
596c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey * An app is delivered for installation through a
606c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey * {@link PackageInstaller.Session}, which any app can create. Once the session
616c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey * is created, the installer can stream one or more APKs into place until it
626c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey * decides to either commit or destroy the session. Committing may require user
636c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey * intervention to complete the installation.
646c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey * <p>
656c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey * Sessions can install brand new apps, upgrade existing apps, or add new splits
66da96e137bcc8191c584ada7b5de31eaae92f244fJeff Sharkey * into an existing app.
676c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey * <p>
68da96e137bcc8191c584ada7b5de31eaae92f244fJeff Sharkey * Apps packaged as multiple split APKs always consist of a single "base" APK
696c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey * (with a {@code null} split name) and zero or more "split" APKs (with unique
706c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey * split names). Any subset of these APKs can be installed together, as long as
716c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey * the following constraints are met:
726c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey * <ul>
736c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey * <li>All APKs must have the exact same package name, version code, and signing
746c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey * certificates.
756c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey * <li>All APKs must have unique split names.
76da96e137bcc8191c584ada7b5de31eaae92f244fJeff Sharkey * <li>All installations must contain a single base APK.
776c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey * </ul>
786c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey */
793a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkeypublic class PackageInstaller {
80a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey    private static final String TAG = "PackageInstaller";
81a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey
821cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey    /**
831cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey     * Activity Action: Show details about a particular install session. This
841cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey     * may surface actions such as pause, resume, or cancel.
851cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey     * <p>
861cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey     * This should always be scoped to the installer package that owns the
87de74231f245c90e5861ec84a9880b5b4ec247480Jeff Sharkey     * session. Clients should use {@link SessionInfo#createDetailsIntent()} to
88a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * build this intent correctly.
891cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey     * <p>
901cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey     * In some cases, a matching Activity may not exist, so ensure you safeguard
911cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey     * against this.
92941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     * <p>
93941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     * The session to show details for is defined in {@link #EXTRA_SESSION_ID}.
941cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey     */
951cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
961cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey    public static final String ACTION_SESSION_DETAILS = "android.content.pm.action.SESSION_DETAILS";
971cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey
987328a1b39b3dae1c0cd390c0a3695c6a46b8e9d8Jeff Sharkey    /** {@hide} */
997328a1b39b3dae1c0cd390c0a3695c6a46b8e9d8Jeff Sharkey    public static final String
1007328a1b39b3dae1c0cd390c0a3695c6a46b8e9d8Jeff Sharkey            ACTION_CONFIRM_PERMISSIONS = "android.content.pm.action.CONFIRM_PERMISSIONS";
1017328a1b39b3dae1c0cd390c0a3695c6a46b8e9d8Jeff Sharkey
1021cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey    /**
103941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     * An integer session ID that an operation is working with.
1041cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey     *
105941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     * @see Intent#getIntExtra(String, int)
1061cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey     */
1071cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey    public static final String EXTRA_SESSION_ID = "android.content.pm.extra.SESSION_ID";
1081cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey
109941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey    /**
110941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     * Package name that an operation is working with.
111941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     *
112941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     * @see Intent#getStringExtra(String)
113941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     */
114941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey    public static final String EXTRA_PACKAGE_NAME = "android.content.pm.extra.PACKAGE_NAME";
115941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey
116941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey    /**
117941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     * Current status of an operation. Will be one of
118941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     * {@link #STATUS_PENDING_USER_ACTION}, {@link #STATUS_SUCCESS},
119941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     * {@link #STATUS_FAILURE}, {@link #STATUS_FAILURE_ABORTED},
120941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     * {@link #STATUS_FAILURE_BLOCKED}, {@link #STATUS_FAILURE_CONFLICT},
121941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     * {@link #STATUS_FAILURE_INCOMPATIBLE}, {@link #STATUS_FAILURE_INVALID}, or
122941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     * {@link #STATUS_FAILURE_STORAGE}.
123941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     * <p>
124941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     * More information about a status may be available through additional
125941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     * extras; see the individual status documentation for details.
126941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     *
127941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     * @see Intent#getIntExtra(String, int)
128941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     */
129a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey    public static final String EXTRA_STATUS = "android.content.pm.extra.STATUS";
130941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey
131941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey    /**
132941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     * Detailed string representation of the status, including raw details that
133941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     * are useful for debugging.
134941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     *
135941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     * @see Intent#getStringExtra(String)
136941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     */
137a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey    public static final String EXTRA_STATUS_MESSAGE = "android.content.pm.extra.STATUS_MESSAGE";
138a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey
139a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey    /**
140941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     * Another package name relevant to a status. This is typically the package
141941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     * responsible for causing an operation failure.
142a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     *
143bb7b7bea19223c1eba74f525c7fe87ca3911813bJeff Sharkey     * @see Intent#getStringExtra(String)
144a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     */
145941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey    public static final String
146941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey            EXTRA_OTHER_PACKAGE_NAME = "android.content.pm.extra.OTHER_PACKAGE_NAME";
147941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey
148941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey    /**
149941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     * Storage path relevant to a status.
150941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     *
151941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     * @see Intent#getStringExtra(String)
152941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     */
153941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey    public static final String EXTRA_STORAGE_PATH = "android.content.pm.extra.STORAGE_PATH";
154bb7b7bea19223c1eba74f525c7fe87ca3911813bJeff Sharkey
155bb7b7bea19223c1eba74f525c7fe87ca3911813bJeff Sharkey    /** {@hide} */
156bb7b7bea19223c1eba74f525c7fe87ca3911813bJeff Sharkey    @Deprecated
157a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey    public static final String EXTRA_PACKAGE_NAMES = "android.content.pm.extra.PACKAGE_NAMES";
158a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey
159a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey    /** {@hide} */
160a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey    public static final String EXTRA_LEGACY_STATUS = "android.content.pm.extra.LEGACY_STATUS";
161a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey    /** {@hide} */
162a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey    public static final String EXTRA_LEGACY_BUNDLE = "android.content.pm.extra.LEGACY_BUNDLE";
163f06009542390472872da986486d385001e91a2a7Jeff Sharkey    /** {@hide} */
164f06009542390472872da986486d385001e91a2a7Jeff Sharkey    public static final String EXTRA_CALLBACK = "android.content.pm.extra.CALLBACK";
165f06009542390472872da986486d385001e91a2a7Jeff Sharkey
166a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey    /**
167a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * User action is currently required to proceed. You can launch the intent
168a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * activity described by {@link Intent#EXTRA_INTENT} to involve the user and
169a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * continue.
170a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * <p>
171a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * You may choose to immediately launch the intent if the user is actively
172a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * using your app. Otherwise, you should use a notification to guide the
173a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * user back into your app before launching.
174a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     *
175a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * @see Intent#getParcelableExtra(String)
176a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     */
177742e790294b3441b79f715fe447069b63c6065dbJeff Sharkey    public static final int STATUS_PENDING_USER_ACTION = -1;
178a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey
179a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey    /**
180a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * The operation succeeded.
181a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     */
182a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey    public static final int STATUS_SUCCESS = 0;
183a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey
184a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey    /**
185a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * The operation failed in a generic way. The system will always try to
186a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * provide a more specific failure reason, but in some rare cases this may
187a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * be delivered.
188a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     *
189a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * @see #EXTRA_STATUS_MESSAGE
190a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     */
191a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey    public static final int STATUS_FAILURE = 1;
192a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey
193a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey    /**
194a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * The operation failed because it was blocked. For example, a device policy
195a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * may be blocking the operation, a package verifier may have blocked the
196a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * operation, or the app may be required for core system operation.
197941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     * <p>
198941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     * The result may also contain {@link #EXTRA_OTHER_PACKAGE_NAME} with the
199941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     * specific package blocking the install.
200a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     *
201a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * @see #EXTRA_STATUS_MESSAGE
202941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     * @see #EXTRA_OTHER_PACKAGE_NAME
203a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     */
204742e790294b3441b79f715fe447069b63c6065dbJeff Sharkey    public static final int STATUS_FAILURE_BLOCKED = 2;
205a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey
206a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey    /**
207a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * The operation failed because it was actively aborted. For example, the
208a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * user actively declined requested permissions, or the session was
209a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * abandoned.
210a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     *
211a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * @see #EXTRA_STATUS_MESSAGE
212a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     */
213742e790294b3441b79f715fe447069b63c6065dbJeff Sharkey    public static final int STATUS_FAILURE_ABORTED = 3;
214a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey
215a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey    /**
216a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * The operation failed because one or more of the APKs was invalid. For
217a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * example, they might be malformed, corrupt, incorrectly signed,
218a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * mismatched, etc.
219a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     *
220a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * @see #EXTRA_STATUS_MESSAGE
221a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     */
222742e790294b3441b79f715fe447069b63c6065dbJeff Sharkey    public static final int STATUS_FAILURE_INVALID = 4;
223a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey
224a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey    /**
225a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * The operation failed because it conflicts (or is inconsistent with) with
226a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * another package already installed on the device. For example, an existing
227a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * permission, incompatible certificates, etc. The user may be able to
228a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * uninstall another app to fix the issue.
229a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * <p>
230941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     * The result may also contain {@link #EXTRA_OTHER_PACKAGE_NAME} with the
231bb7b7bea19223c1eba74f525c7fe87ca3911813bJeff Sharkey     * specific package identified as the cause of the conflict.
232a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     *
233a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * @see #EXTRA_STATUS_MESSAGE
234941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     * @see #EXTRA_OTHER_PACKAGE_NAME
235a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     */
236742e790294b3441b79f715fe447069b63c6065dbJeff Sharkey    public static final int STATUS_FAILURE_CONFLICT = 5;
237a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey
238a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey    /**
239a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * The operation failed because of storage issues. For example, the device
240a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * may be running low on space, or external media may be unavailable. The
241a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * user may be able to help free space or insert different external media.
242941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     * <p>
243941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     * The result may also contain {@link #EXTRA_STORAGE_PATH} with the path to
244941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     * the storage device that caused the failure.
245a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     *
246a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * @see #EXTRA_STATUS_MESSAGE
247941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey     * @see #EXTRA_STORAGE_PATH
248a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     */
249742e790294b3441b79f715fe447069b63c6065dbJeff Sharkey    public static final int STATUS_FAILURE_STORAGE = 6;
250a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey
251a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey    /**
252a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * The operation failed because it is fundamentally incompatible with this
253a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * device. For example, the app may require a hardware feature that doesn't
254a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * exist, it may be missing native code for the ABIs supported by the
255a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * device, or it requires a newer SDK version, etc.
256a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     *
257a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * @see #EXTRA_STATUS_MESSAGE
258a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     */
259742e790294b3441b79f715fe447069b63c6065dbJeff Sharkey    public static final int STATUS_FAILURE_INCOMPATIBLE = 7;
260a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey
261a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey    private final Context mContext;
2623a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey    private final PackageManager mPm;
2633a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey    private final IPackageInstaller mInstaller;
2643a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey    private final int mUserId;
2653a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey    private final String mInstallerPackageName;
2663a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey
26716c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey    private final ArrayList<SessionCallbackDelegate> mDelegates = new ArrayList<>();
26816c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey
2693a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey    /** {@hide} */
270a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey    public PackageInstaller(Context context, PackageManager pm, IPackageInstaller installer,
271ec55ef0934b8e0d1bb705434947de817f7be57f1Jeff Sharkey            String installerPackageName, int userId) {
272a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        mContext = context;
2733a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey        mPm = pm;
2743a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey        mInstaller = installer;
2753a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey        mInstallerPackageName = installerPackageName;
276ec55ef0934b8e0d1bb705434947de817f7be57f1Jeff Sharkey        mUserId = userId;
2773a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey    }
2783a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey
2796c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey    /**
2806c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey     * Create a new session using the given parameters, returning a unique ID
2816c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey     * that represents the session. Once created, the session can be opened
2826c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey     * multiple times across multiple device boots.
2836c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey     * <p>
2846c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey     * The system may automatically destroy sessions that have not been
2856c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey     * finalized (either committed or abandoned) within a reasonable period of
2866c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey     * time, typically on the order of a day.
2876c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey     *
2886c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey     * @throws IOException if parameters were unsatisfiable, such as lack of
2896c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey     *             disk space or unavailable media.
29077d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey     * @throws SecurityException when installation services are unavailable,
29177d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey     *             such as when called from a restricted user.
29277d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey     * @throws IllegalArgumentException when {@link SessionParams} is invalid.
293f174c6e6de6ba863179401aa7b3d55d91ceed707Jeff Sharkey     * @return positive, non-zero unique ID that represents the created session.
294f174c6e6de6ba863179401aa7b3d55d91ceed707Jeff Sharkey     *         This ID remains consistent across device reboots until the
295f174c6e6de6ba863179401aa7b3d55d91ceed707Jeff Sharkey     *         session is finalized. IDs are not reused during a given boot.
2966c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey     */
297a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey    public int createSession(@NonNull SessionParams params) throws IOException {
2983a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey        try {
29916c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey            return mInstaller.createSession(params, mInstallerPackageName, mUserId);
300a10311434778ea1be1621c2251c0c8c2966f337bJeff Sharkey        } catch (RuntimeException e) {
301a10311434778ea1be1621c2251c0c8c2966f337bJeff Sharkey            ExceptionUtils.maybeUnwrapIOException(e);
302a10311434778ea1be1621c2251c0c8c2966f337bJeff Sharkey            throw e;
3033a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey        } catch (RemoteException e) {
3043a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey            throw e.rethrowAsRuntimeException();
3053a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey        }
3063a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey    }
3073a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey
3086c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey    /**
30916c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey     * Open an existing session to actively perform work. To succeed, the caller
31016c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey     * must be the owner of the install session.
31177d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey     *
31277d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey     * @throws IOException if parameters were unsatisfiable, such as lack of
31377d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey     *             disk space or unavailable media.
31477d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey     * @throws SecurityException when the caller does not own the session, or
31577d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey     *             the session is invalid.
3166c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey     */
317bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey    public @NonNull Session openSession(int sessionId) throws IOException {
3183a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey        try {
3193a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey            return new Session(mInstaller.openSession(sessionId));
320bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey        } catch (RuntimeException e) {
321bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey            ExceptionUtils.maybeUnwrapIOException(e);
322bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey            throw e;
3233a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey        } catch (RemoteException e) {
3243a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey            throw e.rethrowAsRuntimeException();
3253a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey        }
326381d94b712605112b35d7f70064b0d18bd877877Jeff Sharkey    }
327381d94b712605112b35d7f70064b0d18bd877877Jeff Sharkey
328ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey    /**
329ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey     * Update the icon representing the app being installed in a specific
330ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey     * session. This should be roughly
331ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey     * {@link ActivityManager#getLauncherLargeIconSize()} in both dimensions.
33277d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey     *
33377d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey     * @throws SecurityException when the caller does not own the session, or
33477d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey     *             the session is invalid.
335ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey     */
336ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey    public void updateSessionAppIcon(int sessionId, @Nullable Bitmap appIcon) {
337ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey        try {
338ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey            mInstaller.updateSessionAppIcon(sessionId, appIcon);
339ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey        } catch (RemoteException e) {
340ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey            throw e.rethrowAsRuntimeException();
341ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey        }
342ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey    }
343ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey
344ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey    /**
345ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey     * Update the label representing the app being installed in a specific
346ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey     * session.
34777d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey     *
34877d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey     * @throws SecurityException when the caller does not own the session, or
34977d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey     *             the session is invalid.
350ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey     */
351ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey    public void updateSessionAppLabel(int sessionId, @Nullable CharSequence appLabel) {
352ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey        try {
353ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey            final String val = (appLabel != null) ? appLabel.toString() : null;
354ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey            mInstaller.updateSessionAppLabel(sessionId, val);
355ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey        } catch (RemoteException e) {
356ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey            throw e.rethrowAsRuntimeException();
357ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey        }
358ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey    }
359ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey
36077d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey    /**
36177d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey     * Completely abandon the given session, destroying all staged data and
36277d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey     * rendering it invalid. Abandoned sessions will be reported to
36377d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey     * {@link SessionCallback} listeners as failures. This is equivalent to
36477d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey     * opening the session and calling {@link Session#abandon()}.
36577d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey     *
36677d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey     * @throws SecurityException when the caller does not own the session, or
36777d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey     *             the session is invalid.
36877d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey     */
369381d94b712605112b35d7f70064b0d18bd877877Jeff Sharkey    public void abandonSession(int sessionId) {
370381d94b712605112b35d7f70064b0d18bd877877Jeff Sharkey        try {
371381d94b712605112b35d7f70064b0d18bd877877Jeff Sharkey            mInstaller.abandonSession(sessionId);
372381d94b712605112b35d7f70064b0d18bd877877Jeff Sharkey        } catch (RemoteException e) {
373381d94b712605112b35d7f70064b0d18bd877877Jeff Sharkey            throw e.rethrowAsRuntimeException();
374381d94b712605112b35d7f70064b0d18bd877877Jeff Sharkey        }
3753a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey    }
3763a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey
3776c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey    /**
37877d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey     * Return details for a specific session. No special permissions are
37977d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey     * required to retrieve these details.
38077d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey     *
38177d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey     * @return details for the requested session, or {@code null} if the session
38277d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey     *         does not exist.
3836c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey     */
384a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey    public @Nullable SessionInfo getSessionInfo(int sessionId) {
3853a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey        try {
38616c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey            return mInstaller.getSessionInfo(sessionId);
38716c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey        } catch (RemoteException e) {
38816c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey            throw e.rethrowAsRuntimeException();
38916c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey        }
39016c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey    }
39116c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey
39216c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey    /**
39377d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey     * Return list of all known install sessions, regardless of the installer.
39416c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey     */
395a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey    public @NonNull List<SessionInfo> getAllSessions() {
396941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey        final ApplicationInfo info = mContext.getApplicationInfo();
397941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey        if ("com.google.android.googlequicksearchbox".equals(info.packageName)
398bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey                && info.versionCode <= 300400110) {
399941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey            Log.d(TAG, "Ignoring callback request from old prebuilt");
400941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey            return Collections.EMPTY_LIST;
401941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey        }
402941a8ba1a6043cf84a7bf622e44a0b4f7abd0178Jeff Sharkey
40316c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey        try {
40497d47ed036ff7bd3d7d2ddc1c6df1104ec237559Jeff Sharkey            return mInstaller.getAllSessions(mUserId).getList();
40516c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey        } catch (RemoteException e) {
40616c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey            throw e.rethrowAsRuntimeException();
40716c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey        }
40816c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey    }
40916c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey
41016c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey    /**
41177d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey     * Return list of all known install sessions owned by the calling app.
41216c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey     */
413a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey    public @NonNull List<SessionInfo> getMySessions() {
41416c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey        try {
41597d47ed036ff7bd3d7d2ddc1c6df1104ec237559Jeff Sharkey            return mInstaller.getMySessions(mInstallerPackageName, mUserId).getList();
4163a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey        } catch (RemoteException e) {
4173a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey            throw e.rethrowAsRuntimeException();
4183a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey        }
4193a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey    }
4203a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey
4216c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey    /**
4226c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey     * Uninstall the given package, removing it completely from the device. This
4236c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey     * method is only available to the current "installer of record" for the
4246c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey     * package.
4256c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey     */
426a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey    public void uninstall(@NonNull String packageName, @NonNull IntentSender statusReceiver) {
4273a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey        try {
42839fb7fd730dc2113ced7e663d7a35e48a4c6b1aeBenjamin Franz            mInstaller.uninstall(packageName, mInstallerPackageName, 0, statusReceiver, mUserId);
429bb580670350b76fa2fcc5ee873f99b7970759cbfJeff Sharkey        } catch (RemoteException e) {
430bb580670350b76fa2fcc5ee873f99b7970759cbfJeff Sharkey            throw e.rethrowAsRuntimeException();
431bb580670350b76fa2fcc5ee873f99b7970759cbfJeff Sharkey        }
432bb580670350b76fa2fcc5ee873f99b7970759cbfJeff Sharkey    }
433bb580670350b76fa2fcc5ee873f99b7970759cbfJeff Sharkey
4347328a1b39b3dae1c0cd390c0a3695c6a46b8e9d8Jeff Sharkey    /** {@hide} */
4357328a1b39b3dae1c0cd390c0a3695c6a46b8e9d8Jeff Sharkey    public void setPermissionsResult(int sessionId, boolean accepted) {
4367328a1b39b3dae1c0cd390c0a3695c6a46b8e9d8Jeff Sharkey        try {
4377328a1b39b3dae1c0cd390c0a3695c6a46b8e9d8Jeff Sharkey            mInstaller.setPermissionsResult(sessionId, accepted);
4387328a1b39b3dae1c0cd390c0a3695c6a46b8e9d8Jeff Sharkey        } catch (RemoteException e) {
4397328a1b39b3dae1c0cd390c0a3695c6a46b8e9d8Jeff Sharkey            throw e.rethrowAsRuntimeException();
4407328a1b39b3dae1c0cd390c0a3695c6a46b8e9d8Jeff Sharkey        }
4417328a1b39b3dae1c0cd390c0a3695c6a46b8e9d8Jeff Sharkey    }
4427328a1b39b3dae1c0cd390c0a3695c6a46b8e9d8Jeff Sharkey
4436c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey    /**
4446c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey     * Events for observing session lifecycle.
4451cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey     * <p>
4461cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey     * A typical session lifecycle looks like this:
4471cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey     * <ul>
4481cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey     * <li>An installer creates a session to indicate pending app delivery. All
4491cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey     * install details are available at this point.
4501cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey     * <li>The installer opens the session to deliver APK data. Note that a
4511cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey     * session may be opened and closed multiple times as network connectivity
4521cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey     * changes. The installer may deliver periodic progress updates.
4531cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey     * <li>The installer commits or abandons the session, resulting in the
4541cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey     * session being finished.
4551cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey     * </ul>
4566c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey     */
45716c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey    public static abstract class SessionCallback {
4586c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey        /**
4591cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey         * New session has been created. Details about the session can be
4601cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey         * obtained from {@link PackageInstaller#getSessionInfo(int)}.
4616c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey         */
46216c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey        public abstract void onCreated(int sessionId);
4636c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey
4646c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey        /**
465ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey         * Badging details for an existing session has changed. For example, the
466ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey         * app icon or label has been updated.
467ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey         */
468ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey        public abstract void onBadgingChanged(int sessionId);
469ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey
470ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey        /**
471bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey         * Active state for session has been changed.
472bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey         * <p>
473bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey         * A session is considered active whenever there is ongoing forward
474bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey         * progress being made, such as the installer holding an open
475bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey         * {@link Session} instance while streaming data into place, or the
476bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey         * system optimizing code as the result of
477bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey         * {@link Session#commit(IntentSender)}.
478bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey         * <p>
479bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey         * If the installer closes the {@link Session} without committing, the
480bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey         * session is considered inactive until the installer opens the session
481bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey         * again.
4821cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey         */
483bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey        public abstract void onActiveChanged(int sessionId, boolean active);
4841cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey
4851cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey        /**
4866c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey         * Progress for given session has been updated.
4876c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey         * <p>
4886c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey         * Note that this progress may not directly correspond to the value
489bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey         * reported by
490bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey         * {@link PackageInstaller.Session#setStagingProgress(float)}, as the
491bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey         * system may carve out a portion of the overall progress to represent
492bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey         * its own internal installation work.
4936c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey         */
49416c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey        public abstract void onProgressChanged(int sessionId, float progress);
4956c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey
4966c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey        /**
49716c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey         * Session has completely finished, either with success or failure.
4986c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey         */
49916c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey        public abstract void onFinished(int sessionId, boolean success);
50016c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey    }
50116c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey
50216c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey    /** {@hide} */
50316c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey    private static class SessionCallbackDelegate extends IPackageInstallerCallback.Stub implements
50416c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey            Handler.Callback {
50516c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey        private static final int MSG_SESSION_CREATED = 1;
506ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey        private static final int MSG_SESSION_BADGING_CHANGED = 2;
507bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey        private static final int MSG_SESSION_ACTIVE_CHANGED = 3;
508ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey        private static final int MSG_SESSION_PROGRESS_CHANGED = 4;
509bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey        private static final int MSG_SESSION_FINISHED = 5;
51016c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey
51116c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey        final SessionCallback mCallback;
51216c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey        final Handler mHandler;
51316c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey
51416c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey        public SessionCallbackDelegate(SessionCallback callback, Looper looper) {
51516c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey            mCallback = callback;
51616c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey            mHandler = new Handler(looper, this);
51716c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey        }
51816c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey
51916c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey        @Override
52016c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey        public boolean handleMessage(Message msg) {
521bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey            final int sessionId = msg.arg1;
52216c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey            switch (msg.what) {
52316c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey                case MSG_SESSION_CREATED:
524bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey                    mCallback.onCreated(sessionId);
52516c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey                    return true;
526ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey                case MSG_SESSION_BADGING_CHANGED:
527bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey                    mCallback.onBadgingChanged(sessionId);
528ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey                    return true;
529bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey                case MSG_SESSION_ACTIVE_CHANGED:
530bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey                    final boolean active = msg.arg2 != 0;
531bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey                    mCallback.onActiveChanged(sessionId, active);
5321cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey                    return true;
53316c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey                case MSG_SESSION_PROGRESS_CHANGED:
534bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey                    mCallback.onProgressChanged(sessionId, (float) msg.obj);
5351cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey                    return true;
53616c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey                case MSG_SESSION_FINISHED:
537bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey                    mCallback.onFinished(sessionId, msg.arg2 != 0);
53816c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey                    return true;
53916c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey            }
54016c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey            return false;
54116c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey        }
54216c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey
54316c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey        @Override
54416c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey        public void onSessionCreated(int sessionId) {
54516c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey            mHandler.obtainMessage(MSG_SESSION_CREATED, sessionId, 0).sendToTarget();
54616c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey        }
54716c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey
54816c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey        @Override
549ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey        public void onSessionBadgingChanged(int sessionId) {
550ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey            mHandler.obtainMessage(MSG_SESSION_BADGING_CHANGED, sessionId, 0).sendToTarget();
551ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey        }
552ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey
553ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey        @Override
554bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey        public void onSessionActiveChanged(int sessionId, boolean active) {
555bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey            mHandler.obtainMessage(MSG_SESSION_ACTIVE_CHANGED, sessionId, active ? 1 : 0)
556bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey                    .sendToTarget();
5571cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey        }
5581cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey
5591cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey        @Override
56016c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey        public void onSessionProgressChanged(int sessionId, float progress) {
56116c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey            mHandler.obtainMessage(MSG_SESSION_PROGRESS_CHANGED, sessionId, 0, progress)
56216c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey                    .sendToTarget();
56316c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey        }
56416c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey
56516c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey        @Override
56616c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey        public void onSessionFinished(int sessionId, boolean success) {
56716c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey            mHandler.obtainMessage(MSG_SESSION_FINISHED, sessionId, success ? 1 : 0)
56816c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey                    .sendToTarget();
56916c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey        }
570bb580670350b76fa2fcc5ee873f99b7970759cbfJeff Sharkey    }
571bb580670350b76fa2fcc5ee873f99b7970759cbfJeff Sharkey
572ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey    /** {@hide} */
573ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey    @Deprecated
574ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey    public void addSessionCallback(@NonNull SessionCallback callback) {
575ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey        registerSessionCallback(callback);
576ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey    }
577ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey
5786c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey    /**
57977d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey     * Register to watch for session lifecycle events. No special permissions
58077d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey     * are required to watch for these events.
5816c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey     */
582ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey    public void registerSessionCallback(@NonNull SessionCallback callback) {
583ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey        registerSessionCallback(callback, new Handler());
584ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey    }
585ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey
586ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey    /** {@hide} */
587ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey    @Deprecated
588ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey    public void addSessionCallback(@NonNull SessionCallback callback, @NonNull Handler handler) {
589ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey        registerSessionCallback(callback, handler);
59016c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey    }
59116c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey
59216c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey    /**
59377d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey     * Register to watch for session lifecycle events. No special permissions
59477d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey     * are required to watch for these events.
59516c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey     *
59616c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey     * @param handler to dispatch callback events through, otherwise uses
59716c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey     *            calling thread.
59816c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey     */
599ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey    public void registerSessionCallback(@NonNull SessionCallback callback, @NonNull Handler handler) {
600a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        // TODO: remove this temporary guard once we have new prebuilts
601a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        final ApplicationInfo info = mContext.getApplicationInfo();
602a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        if ("com.google.android.googlequicksearchbox".equals(info.packageName)
603bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey                && info.versionCode <= 300400110) {
604a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            Log.d(TAG, "Ignoring callback request from old prebuilt");
605a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            return;
606a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        }
607a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey
60816c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey        synchronized (mDelegates) {
60916c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey            final SessionCallbackDelegate delegate = new SessionCallbackDelegate(callback,
61016c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey                    handler.getLooper());
61116c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey            try {
61216c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey                mInstaller.registerCallback(delegate, mUserId);
61316c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey            } catch (RemoteException e) {
61416c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey                throw e.rethrowAsRuntimeException();
61516c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey            }
61616c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey            mDelegates.add(delegate);
617bb580670350b76fa2fcc5ee873f99b7970759cbfJeff Sharkey        }
618bb580670350b76fa2fcc5ee873f99b7970759cbfJeff Sharkey    }
619bb580670350b76fa2fcc5ee873f99b7970759cbfJeff Sharkey
620ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey    /** {@hide} */
621ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey    @Deprecated
622ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey    public void removeSessionCallback(@NonNull SessionCallback callback) {
623ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey        unregisterSessionCallback(callback);
624ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey    }
625ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey
6266c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey    /**
62777d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey     * Unregister a previously registered callback.
6286c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey     */
629ec9bad2015c6d3bc91bab66f0824043c1e24d013Jeff Sharkey    public void unregisterSessionCallback(@NonNull SessionCallback callback) {
63016c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey        synchronized (mDelegates) {
63116c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey            for (Iterator<SessionCallbackDelegate> i = mDelegates.iterator(); i.hasNext();) {
63216c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey                final SessionCallbackDelegate delegate = i.next();
63316c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey                if (delegate.mCallback == callback) {
63416c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey                    try {
63516c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey                        mInstaller.unregisterCallback(delegate);
63616c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey                    } catch (RemoteException e) {
63716c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey                        throw e.rethrowAsRuntimeException();
63816c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey                    }
63916c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey                    i.remove();
64016c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey                }
64116c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey            }
6423a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey        }
6433a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey    }
6443a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey
6453a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey    /**
6463a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey     * An installation that is being actively staged. For an install to succeed,
6473a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey     * all existing and new packages must have identical package names, version
6483a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey     * codes, and signing certificates.
6493a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey     * <p>
6503a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey     * A session may contain any number of split packages. If the application
6513a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey     * does not yet exist, this session must include a base package.
6523a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey     * <p>
65316c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey     * If an APK included in this session is already defined by the existing
65416c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey     * installation (for example, the same split name), the APK in this session
65516c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey     * will replace the existing APK.
6563a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey     */
657ec55ef0934b8e0d1bb705434947de817f7be57f1Jeff Sharkey    public static class Session implements Closeable {
6583a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey        private IPackageInstallerSession mSession;
6593a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey
6603a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey        /** {@hide} */
6613a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey        public Session(IPackageInstallerSession session) {
6623a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey            mSession = session;
6633a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey        }
6643a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey
665bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey        /** {@hide} */
666bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey        @Deprecated
667bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey        public void setProgress(float progress) {
668bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey            setStagingProgress(progress);
669bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey        }
670bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey
6716c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey        /**
672bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey         * Set current progress of staging this session. Valid values are
673bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey         * anywhere between 0 and 1.
674bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey         * <p>
675bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey         * Note that this progress may not directly correspond to the value
676bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey         * reported by {@link SessionCallback#onProgressChanged(int, float)}, as
677bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey         * the system may carve out a portion of the overall progress to
678bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey         * represent its own internal installation work.
6796c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey         */
680bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey        public void setStagingProgress(float progress) {
6813a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey            try {
682a10311434778ea1be1621c2251c0c8c2966f337bJeff Sharkey                mSession.setClientProgress(progress);
683a10311434778ea1be1621c2251c0c8c2966f337bJeff Sharkey            } catch (RemoteException e) {
684a10311434778ea1be1621c2251c0c8c2966f337bJeff Sharkey                throw e.rethrowAsRuntimeException();
685a10311434778ea1be1621c2251c0c8c2966f337bJeff Sharkey            }
686a10311434778ea1be1621c2251c0c8c2966f337bJeff Sharkey        }
687a10311434778ea1be1621c2251c0c8c2966f337bJeff Sharkey
688a10311434778ea1be1621c2251c0c8c2966f337bJeff Sharkey        /** {@hide} */
68916c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey        public void addProgress(float progress) {
690a10311434778ea1be1621c2251c0c8c2966f337bJeff Sharkey            try {
691a10311434778ea1be1621c2251c0c8c2966f337bJeff Sharkey                mSession.addClientProgress(progress);
6923a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey            } catch (RemoteException e) {
6933a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey                throw e.rethrowAsRuntimeException();
6943a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey            }
6953a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey        }
6963a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey
69778cc340c2de873d6995c283b777476f7237d690fJeff Sharkey        /**
69816c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey         * Open a stream to write an APK file into the session.
69916c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey         * <p>
70016c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey         * The returned stream will start writing data at the requested offset
70116c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey         * in the underlying file, which can be used to resume a partially
70216c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey         * written file. If a valid file length is specified, the system will
70316c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey         * preallocate the underlying disk space to optimize placement on disk.
70416c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey         * It's strongly recommended to provide a valid file length when known.
70516c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey         * <p>
70616c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey         * You can write data into the returned stream, optionally call
70716c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey         * {@link #fsync(OutputStream)} as needed to ensure bytes have been
70816c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey         * persisted to disk, and then close when finished. All streams must be
709a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * closed before calling {@link #commit(IntentSender)}.
71016c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey         *
71116c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey         * @param name arbitrary, unique name of your choosing to identify the
71216c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey         *            APK being written. You can open a file again for
71316c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey         *            additional writes (such as after a reboot) by using the
71416c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey         *            same name. This name is only meaningful within the context
71516c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey         *            of a single install session.
71616c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey         * @param offsetBytes offset into the file to begin writing at, or 0 to
71716c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey         *            start at the beginning of the file.
71816c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey         * @param lengthBytes total size of the file being written, used to
71916c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey         *            preallocate the underlying disk space, or -1 if unknown.
72077d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey         *            The system may clear various caches as needed to allocate
72177d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey         *            this space.
72277d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey         * @throws IOException if trouble opening the file for writing, such as
72377d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey         *             lack of disk space or unavailable media.
72477d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey         * @throws SecurityException if called after the session has been
72577d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey         *             committed or abandoned.
72678cc340c2de873d6995c283b777476f7237d690fJeff Sharkey         */
72716c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey        public @NonNull OutputStream openWrite(@NonNull String name, long offsetBytes,
72816c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey                long lengthBytes) throws IOException {
7293a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey            try {
73016c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey                final ParcelFileDescriptor clientSocket = mSession.openWrite(name,
73178cc340c2de873d6995c283b777476f7237d690fJeff Sharkey                        offsetBytes, lengthBytes);
7329a1507aa10577badabcbe00396613a967302e456Jeff Sharkey                return new FileBridge.FileBridgeOutputStream(clientSocket);
733a10311434778ea1be1621c2251c0c8c2966f337bJeff Sharkey            } catch (RuntimeException e) {
734a10311434778ea1be1621c2251c0c8c2966f337bJeff Sharkey                ExceptionUtils.maybeUnwrapIOException(e);
735a10311434778ea1be1621c2251c0c8c2966f337bJeff Sharkey                throw e;
7363a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey            } catch (RemoteException e) {
7371cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey                throw e.rethrowAsRuntimeException();
7383a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey            }
7393a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey        }
7403a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey
7416c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey        /**
7426c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey         * Ensure that any outstanding data for given stream has been committed
7436c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey         * to disk. This is only valid for streams returned from
7446c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey         * {@link #openWrite(String, long, long)}.
7456c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey         */
74616c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey        public void fsync(@NonNull OutputStream out) throws IOException {
747a10311434778ea1be1621c2251c0c8c2966f337bJeff Sharkey            if (out instanceof FileBridge.FileBridgeOutputStream) {
748a10311434778ea1be1621c2251c0c8c2966f337bJeff Sharkey                ((FileBridge.FileBridgeOutputStream) out).fsync();
749a10311434778ea1be1621c2251c0c8c2966f337bJeff Sharkey            } else {
750a10311434778ea1be1621c2251c0c8c2966f337bJeff Sharkey                throw new IllegalArgumentException("Unrecognized stream");
751a10311434778ea1be1621c2251c0c8c2966f337bJeff Sharkey            }
752a10311434778ea1be1621c2251c0c8c2966f337bJeff Sharkey        }
753a10311434778ea1be1621c2251c0c8c2966f337bJeff Sharkey
7546c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey        /**
755a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * Return all APK names contained in this session.
7561cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey         * <p>
7571cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey         * This returns all names which have been previously written through
7581cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey         * {@link #openWrite(String, long, long)} as part of this session.
75977d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey         *
76077d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey         * @throws SecurityException if called after the session has been
76177d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey         *             committed or abandoned.
7621cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey         */
763742e790294b3441b79f715fe447069b63c6065dbJeff Sharkey        public @NonNull String[] getNames() throws IOException {
7641cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey            try {
765a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey                return mSession.getNames();
766742e790294b3441b79f715fe447069b63c6065dbJeff Sharkey            } catch (RuntimeException e) {
767742e790294b3441b79f715fe447069b63c6065dbJeff Sharkey                ExceptionUtils.maybeUnwrapIOException(e);
768742e790294b3441b79f715fe447069b63c6065dbJeff Sharkey                throw e;
7691cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey            } catch (RemoteException e) {
7701cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey                throw e.rethrowAsRuntimeException();
7711cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey            }
7721cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey        }
7731cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey
7741cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey        /**
7751cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey         * Open a stream to read an APK file from the session.
7761cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey         * <p>
7771cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey         * This is only valid for names which have been previously written
7781cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey         * through {@link #openWrite(String, long, long)} as part of this
7791cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey         * session. For example, this stream may be used to calculate a
7801cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey         * {@link MessageDigest} of a written APK before committing.
78177d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey         *
78277d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey         * @throws SecurityException if called after the session has been
78377d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey         *             committed or abandoned.
7841cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey         */
7851cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey        public @NonNull InputStream openRead(@NonNull String name) throws IOException {
7861cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey            try {
7871cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey                final ParcelFileDescriptor pfd = mSession.openRead(name);
7881cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey                return new ParcelFileDescriptor.AutoCloseInputStream(pfd);
7891cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey            } catch (RuntimeException e) {
7901cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey                ExceptionUtils.maybeUnwrapIOException(e);
7911cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey                throw e;
7921cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey            } catch (RemoteException e) {
7931cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey                throw e.rethrowAsRuntimeException();
7941cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey            }
7951cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey        }
7961cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey
7971cb2d0d4bba387665128c62c342e59103ea4be26Jeff Sharkey        /**
7986c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey         * Attempt to commit everything staged in this session. This may require
7996c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey         * user intervention, and so it may not happen immediately. The final
8006c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey         * result of the commit will be reported through the given callback.
8016c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey         * <p>
8026c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey         * Once this method is called, no additional mutations may be performed
8036c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey         * on the session. If the device reboots before the session has been
8046c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey         * finalized, you may commit the session again.
80577d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey         *
80677d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey         * @throws SecurityException if streams opened through
80777d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey         *             {@link #openWrite(String, long, long)} are still open.
8086c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey         */
809a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public void commit(@NonNull IntentSender statusReceiver) {
8103a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey            try {
811a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey                mSession.commit(statusReceiver);
8123a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey            } catch (RemoteException e) {
8133a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey                throw e.rethrowAsRuntimeException();
8143a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey            }
8153a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey        }
8163a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey
8176c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey        /**
8186c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey         * Release this session object. You can open the session again if it
8196c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey         * hasn't been finalized.
8206c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey         */
821ec55ef0934b8e0d1bb705434947de817f7be57f1Jeff Sharkey        @Override
8223a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey        public void close() {
82316c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey            try {
82416c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey                mSession.close();
82516c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey            } catch (RemoteException e) {
82616c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey                throw e.rethrowAsRuntimeException();
82716c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey            }
8283a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey        }
8293a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey
8306c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey        /**
83116c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey         * Completely abandon this session, destroying all staged data and
83277d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey         * rendering it invalid. Abandoned sessions will be reported to
83377d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey         * {@link SessionCallback} listeners as failures. This is equivalent to
83477d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey         * opening the session and calling {@link Session#abandon()}.
8356c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey         */
83616c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey        public void abandon() {
8373a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey            try {
83816c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey                mSession.abandon();
8393a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey            } catch (RemoteException e) {
8403a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey                throw e.rethrowAsRuntimeException();
8413a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey            }
8423a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey        }
8433a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey    }
844bb580670350b76fa2fcc5ee873f99b7970759cbfJeff Sharkey
8456c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey    /**
846a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * Parameters for creating a new {@link PackageInstaller.Session}.
8476c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey     */
848a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey    public static class SessionParams implements Parcelable {
849a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey
850a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        /** {@hide} */
851a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public static final int MODE_INVALID = -1;
852a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey
853a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        /**
854a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * Mode for an install session whose staged APKs should fully replace any
855a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * existing APKs for the target app.
856a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         */
857a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public static final int MODE_FULL_INSTALL = 1;
858a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey
859a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        /**
860a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * Mode for an install session that should inherit any existing APKs for the
861a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * target app, unless they have been explicitly overridden (based on split
862a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * name) by the session. For example, this can be used to add one or more
863a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * split APKs to an existing installation.
864a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * <p>
865a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * If there are no existing APKs for the target app, this behaves like
866a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * {@link #MODE_FULL_INSTALL}.
867a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         */
868a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public static final int MODE_INHERIT_EXISTING = 2;
869a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey
870a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        /** {@hide} */
871a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public int mode = MODE_INVALID;
872a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        /** {@hide} */
873a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public int installFlags;
874a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        /** {@hide} */
875a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public int installLocation = PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY;
876a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        /** {@hide} */
877a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public long sizeBytes = -1;
878a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        /** {@hide} */
879a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public String appPackageName;
880a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        /** {@hide} */
881a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public Bitmap appIcon;
882a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        /** {@hide} */
883a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public String appLabel;
884a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        /** {@hide} */
88502bd78490d8594d225ecc70a74b2058cb968a657Jeff Sharkey        public long appIconLastModified = -1;
88602bd78490d8594d225ecc70a74b2058cb968a657Jeff Sharkey        /** {@hide} */
887a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public Uri originatingUri;
888a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        /** {@hide} */
889a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public Uri referrerUri;
890a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        /** {@hide} */
891a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public String abiOverride;
892b2b9ab8354da1485178cd8d8e9d89ac915b3f269Jeff Sharkey        /** {@hide} */
893b2b9ab8354da1485178cd8d8e9d89ac915b3f269Jeff Sharkey        public String volumeUuid;
8947121e18595d4c559044e26bfe6035406a862f466Svet Ganov        /** {@hide} */
8957121e18595d4c559044e26bfe6035406a862f466Svet Ganov        public String[] grantedRuntimePermissions;
896a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey
897fbd0e9fa37fc17ccd25e4c1f16195bbd27de3c4cJeff Sharkey        /**
898a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * Construct parameters for a new package install session.
899a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         *
900a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * @param mode one of {@link #MODE_FULL_INSTALL} or
901a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         *            {@link #MODE_INHERIT_EXISTING} describing how the session
902a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         *            should interact with an existing app.
903f06009542390472872da986486d385001e91a2a7Jeff Sharkey         */
904a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public SessionParams(int mode) {
905a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            this.mode = mode;
906a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        }
907a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey
908a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        /** {@hide} */
909a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public SessionParams(Parcel source) {
910a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            mode = source.readInt();
911a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            installFlags = source.readInt();
912a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            installLocation = source.readInt();
913a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            sizeBytes = source.readLong();
914a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            appPackageName = source.readString();
915a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            appIcon = source.readParcelable(null);
916a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            appLabel = source.readString();
917a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            originatingUri = source.readParcelable(null);
918a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            referrerUri = source.readParcelable(null);
919a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            abiOverride = source.readString();
920b2b9ab8354da1485178cd8d8e9d89ac915b3f269Jeff Sharkey            volumeUuid = source.readString();
9217121e18595d4c559044e26bfe6035406a862f466Svet Ganov            grantedRuntimePermissions = source.readStringArray();
922a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        }
923f06009542390472872da986486d385001e91a2a7Jeff Sharkey
924f06009542390472872da986486d385001e91a2a7Jeff Sharkey        /**
925a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * Provide value of {@link PackageInfo#installLocation}, which may be used
926a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * to determine where the app will be staged. Defaults to
927a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * {@link PackageInfo#INSTALL_LOCATION_INTERNAL_ONLY}.
928f06009542390472872da986486d385001e91a2a7Jeff Sharkey         */
929a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public void setInstallLocation(int installLocation) {
930a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            this.installLocation = installLocation;
931a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        }
932f06009542390472872da986486d385001e91a2a7Jeff Sharkey
933f06009542390472872da986486d385001e91a2a7Jeff Sharkey        /**
934a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * Optionally indicate the total size (in bytes) of all APKs that will be
935a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * delivered in this session. The system may use this to ensure enough disk
936a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * space exists before proceeding, or to estimate container size for
937a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * installations living on external storage.
938a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         *
939a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * @see PackageInfo#INSTALL_LOCATION_AUTO
940a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * @see PackageInfo#INSTALL_LOCATION_PREFER_EXTERNAL
941f06009542390472872da986486d385001e91a2a7Jeff Sharkey         */
942a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public void setSize(long sizeBytes) {
943a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            this.sizeBytes = sizeBytes;
944a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        }
945f06009542390472872da986486d385001e91a2a7Jeff Sharkey
946f06009542390472872da986486d385001e91a2a7Jeff Sharkey        /**
947a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * Optionally set the package name of the app being installed. It's strongly
948a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * recommended that you provide this value when known, so that observers can
949a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * communicate installing apps to users.
950fbd0e9fa37fc17ccd25e4c1f16195bbd27de3c4cJeff Sharkey         * <p>
951a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * If the APKs staged in the session aren't consistent with this package
952a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * name, the install will fail. Regardless of this value, all APKs in the
953a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * app must have the same package name.
954fbd0e9fa37fc17ccd25e4c1f16195bbd27de3c4cJeff Sharkey         */
955a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public void setAppPackageName(@Nullable String appPackageName) {
956a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            this.appPackageName = appPackageName;
957a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        }
958fbd0e9fa37fc17ccd25e4c1f16195bbd27de3c4cJeff Sharkey
959a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        /**
960a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * Optionally set an icon representing the app being installed. This should
961a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * be roughly {@link ActivityManager#getLauncherLargeIconSize()} in both
962a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * dimensions.
963a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         */
964a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public void setAppIcon(@Nullable Bitmap appIcon) {
965a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            this.appIcon = appIcon;
966a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        }
967bb580670350b76fa2fcc5ee873f99b7970759cbfJeff Sharkey
968a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        /**
969a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * Optionally set a label representing the app being installed.
970a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         */
971a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public void setAppLabel(@Nullable CharSequence appLabel) {
972a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            this.appLabel = (appLabel != null) ? appLabel.toString() : null;
973a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        }
974bb580670350b76fa2fcc5ee873f99b7970759cbfJeff Sharkey
975a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        /**
976a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * Optionally set the URI where this package was downloaded from. Used for
977a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * verification purposes.
978a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         *
979a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * @see Intent#EXTRA_ORIGINATING_URI
980a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         */
981a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public void setOriginatingUri(@Nullable Uri originatingUri) {
982a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            this.originatingUri = originatingUri;
983bb580670350b76fa2fcc5ee873f99b7970759cbfJeff Sharkey        }
984bb580670350b76fa2fcc5ee873f99b7970759cbfJeff Sharkey
985a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        /**
986a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * Optionally set the URI that referred you to install this package. Used
987a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * for verification purposes.
988a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         *
989a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * @see Intent#EXTRA_REFERRER
990a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         */
991a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public void setReferrerUri(@Nullable Uri referrerUri) {
992a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            this.referrerUri = referrerUri;
993a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        }
994a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey
9957121e18595d4c559044e26bfe6035406a862f466Svet Ganov        /**
9967121e18595d4c559044e26bfe6035406a862f466Svet Ganov         * Sets which runtime permissions to be granted to the package at installation.
9977121e18595d4c559044e26bfe6035406a862f466Svet Ganov         * Using this API requires holding {@link android.Manifest.permission
9987121e18595d4c559044e26bfe6035406a862f466Svet Ganov         * #INSTALL_GRANT_RUNTIME_PERMISSIONS}
9997121e18595d4c559044e26bfe6035406a862f466Svet Ganov         *
10007121e18595d4c559044e26bfe6035406a862f466Svet Ganov         * @param permissions The permissions to grant or null to grant all runtime
10017121e18595d4c559044e26bfe6035406a862f466Svet Ganov         *     permissions.
10027121e18595d4c559044e26bfe6035406a862f466Svet Ganov         *
10037121e18595d4c559044e26bfe6035406a862f466Svet Ganov         * @hide
10047121e18595d4c559044e26bfe6035406a862f466Svet Ganov         */
10057121e18595d4c559044e26bfe6035406a862f466Svet Ganov        @SystemApi
10067121e18595d4c559044e26bfe6035406a862f466Svet Ganov        @RequiresPermission(android.Manifest.permission.INSTALL_GRANT_RUNTIME_PERMISSIONS)
10077121e18595d4c559044e26bfe6035406a862f466Svet Ganov        public void setGrantedRuntimePermissions(String[] permissions) {
10087121e18595d4c559044e26bfe6035406a862f466Svet Ganov            installFlags |= PackageManager.INSTALL_GRANT_RUNTIME_PERMISSIONS;
10097121e18595d4c559044e26bfe6035406a862f466Svet Ganov            this.grantedRuntimePermissions = permissions;
10107121e18595d4c559044e26bfe6035406a862f466Svet Ganov        }
10117121e18595d4c559044e26bfe6035406a862f466Svet Ganov
1012a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        /** {@hide} */
101377d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey        public void setInstallFlagsInternal() {
101477d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey            installFlags |= PackageManager.INSTALL_INTERNAL;
101577d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey            installFlags &= ~PackageManager.INSTALL_EXTERNAL;
101677d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey        }
101777d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey
101877d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey        /** {@hide} */
101977d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey        public void setInstallFlagsExternal() {
102077d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey            installFlags |= PackageManager.INSTALL_EXTERNAL;
102177d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey            installFlags &= ~PackageManager.INSTALL_INTERNAL;
102277d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey        }
102377d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey
102477d218e1869e69c8d436b09cd11dcfe45e50b2cfJeff Sharkey        /** {@hide} */
1025a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public void dump(IndentingPrintWriter pw) {
1026a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            pw.printPair("mode", mode);
1027a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            pw.printHexPair("installFlags", installFlags);
1028a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            pw.printPair("installLocation", installLocation);
1029a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            pw.printPair("sizeBytes", sizeBytes);
1030a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            pw.printPair("appPackageName", appPackageName);
1031a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            pw.printPair("appIcon", (appIcon != null));
1032a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            pw.printPair("appLabel", appLabel);
1033a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            pw.printPair("originatingUri", originatingUri);
1034a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            pw.printPair("referrerUri", referrerUri);
1035a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            pw.printPair("abiOverride", abiOverride);
1036b2b9ab8354da1485178cd8d8e9d89ac915b3f269Jeff Sharkey            pw.printPair("volumeUuid", volumeUuid);
10377121e18595d4c559044e26bfe6035406a862f466Svet Ganov            pw.printPair("grantedRuntimePermissions", grantedRuntimePermissions);
1038a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            pw.println();
1039fbd0e9fa37fc17ccd25e4c1f16195bbd27de3c4cJeff Sharkey        }
1040fbd0e9fa37fc17ccd25e4c1f16195bbd27de3c4cJeff Sharkey
1041fbd0e9fa37fc17ccd25e4c1f16195bbd27de3c4cJeff Sharkey        @Override
1042a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public int describeContents() {
1043a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            return 0;
1044bb580670350b76fa2fcc5ee873f99b7970759cbfJeff Sharkey        }
1045a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey
1046a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        @Override
1047a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public void writeToParcel(Parcel dest, int flags) {
1048a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            dest.writeInt(mode);
1049a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            dest.writeInt(installFlags);
1050a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            dest.writeInt(installLocation);
1051a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            dest.writeLong(sizeBytes);
1052a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            dest.writeString(appPackageName);
1053a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            dest.writeParcelable(appIcon, flags);
1054a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            dest.writeString(appLabel);
1055a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            dest.writeParcelable(originatingUri, flags);
1056a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            dest.writeParcelable(referrerUri, flags);
1057a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            dest.writeString(abiOverride);
1058b2b9ab8354da1485178cd8d8e9d89ac915b3f269Jeff Sharkey            dest.writeString(volumeUuid);
10597121e18595d4c559044e26bfe6035406a862f466Svet Ganov            dest.writeStringArray(grantedRuntimePermissions);
1060a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        }
1061a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey
1062a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public static final Parcelable.Creator<SessionParams>
1063a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey                CREATOR = new Parcelable.Creator<SessionParams>() {
1064a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey                    @Override
1065a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey                    public SessionParams createFromParcel(Parcel p) {
1066a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey                        return new SessionParams(p);
1067a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey                    }
1068a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey
1069a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey                    @Override
1070a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey                    public SessionParams[] newArray(int size) {
1071a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey                        return new SessionParams[size];
1072a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey                    }
1073a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey                };
1074bb580670350b76fa2fcc5ee873f99b7970759cbfJeff Sharkey    }
1075bb580670350b76fa2fcc5ee873f99b7970759cbfJeff Sharkey
10766c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey    /**
1077a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey     * Details for an active install session.
10786c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey     */
1079a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey    public static class SessionInfo implements Parcelable {
1080a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey
1081a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        /** {@hide} */
1082a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public int sessionId;
1083a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        /** {@hide} */
1084a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public String installerPackageName;
1085a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        /** {@hide} */
1086a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public String resolvedBaseCodePath;
1087a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        /** {@hide} */
1088a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public float progress;
1089a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        /** {@hide} */
1090a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public boolean sealed;
1091a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        /** {@hide} */
1092bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey        public boolean active;
1093a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey
1094a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        /** {@hide} */
1095a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public int mode;
1096a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        /** {@hide} */
1097a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public long sizeBytes;
1098a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        /** {@hide} */
1099a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public String appPackageName;
1100a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        /** {@hide} */
1101a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public Bitmap appIcon;
1102a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        /** {@hide} */
1103a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public CharSequence appLabel;
1104a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey
1105a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        /** {@hide} */
1106a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public SessionInfo() {
1107a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        }
1108a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey
1109a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        /** {@hide} */
1110a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public SessionInfo(Parcel source) {
1111a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            sessionId = source.readInt();
1112a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            installerPackageName = source.readString();
1113a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            resolvedBaseCodePath = source.readString();
1114a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            progress = source.readFloat();
1115a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            sealed = source.readInt() != 0;
1116bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey            active = source.readInt() != 0;
1117a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey
1118a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            mode = source.readInt();
1119a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            sizeBytes = source.readLong();
1120a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            appPackageName = source.readString();
1121a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            appIcon = source.readParcelable(null);
1122a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            appLabel = source.readString();
1123a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        }
1124a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey
11256c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey        /**
1126a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * Return the ID for this session.
11276c833e07a05c48ca60ee4d72421bf8b1e78dc710Jeff Sharkey         */
1128a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public int getSessionId() {
1129a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            return sessionId;
1130a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        }
1131bb580670350b76fa2fcc5ee873f99b7970759cbfJeff Sharkey
1132bb580670350b76fa2fcc5ee873f99b7970759cbfJeff Sharkey        /**
1133a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * Return the package name of the app that owns this session.
1134bb580670350b76fa2fcc5ee873f99b7970759cbfJeff Sharkey         */
1135a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public @Nullable String getInstallerPackageName() {
1136a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            return installerPackageName;
1137a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        }
1138bb580670350b76fa2fcc5ee873f99b7970759cbfJeff Sharkey
1139bb580670350b76fa2fcc5ee873f99b7970759cbfJeff Sharkey        /**
1140a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * Return current overall progress of this session, between 0 and 1.
114116c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey         * <p>
1142bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey         * Note that this progress may not directly correspond to the value
1143bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey         * reported by
1144bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey         * {@link PackageInstaller.Session#setStagingProgress(float)}, as the
1145bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey         * system may carve out a portion of the overall progress to represent
1146bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey         * its own internal installation work.
1147bb580670350b76fa2fcc5ee873f99b7970759cbfJeff Sharkey         */
1148a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public float getProgress() {
1149a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            return progress;
1150a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        }
1151bb580670350b76fa2fcc5ee873f99b7970759cbfJeff Sharkey
1152bb580670350b76fa2fcc5ee873f99b7970759cbfJeff Sharkey        /**
1153bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey         * Return if this session is currently active.
1154bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey         * <p>
1155bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey         * A session is considered active whenever there is ongoing forward
1156bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey         * progress being made, such as the installer holding an open
1157bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey         * {@link Session} instance while streaming data into place, or the
1158bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey         * system optimizing code as the result of
1159bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey         * {@link Session#commit(IntentSender)}.
1160bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey         * <p>
1161bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey         * If the installer closes the {@link Session} without committing, the
1162bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey         * session is considered inactive until the installer opens the session
1163bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey         * again.
1164bb580670350b76fa2fcc5ee873f99b7970759cbfJeff Sharkey         */
1165bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey        public boolean isActive() {
1166bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey            return active;
1167bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey        }
1168bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey
1169bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey        /** {@hide} */
1170bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey        @Deprecated
1171a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public boolean isOpen() {
1172bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey            return isActive();
1173a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        }
1174bb580670350b76fa2fcc5ee873f99b7970759cbfJeff Sharkey
1175bb580670350b76fa2fcc5ee873f99b7970759cbfJeff Sharkey        /**
1176a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * Return the package name this session is working with. May be {@code null}
1177a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * if unknown.
1178bb580670350b76fa2fcc5ee873f99b7970759cbfJeff Sharkey         */
1179a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public @Nullable String getAppPackageName() {
1180a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            return appPackageName;
1181a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        }
118216c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey
11837328a1b39b3dae1c0cd390c0a3695c6a46b8e9d8Jeff Sharkey        /**
1184a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * Return an icon representing the app being installed. May be {@code null}
1185a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * if unavailable.
11867328a1b39b3dae1c0cd390c0a3695c6a46b8e9d8Jeff Sharkey         */
1187a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public @Nullable Bitmap getAppIcon() {
1188a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            return appIcon;
1189a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        }
11907328a1b39b3dae1c0cd390c0a3695c6a46b8e9d8Jeff Sharkey
1191a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        /**
1192a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * Return a label representing the app being installed. May be {@code null}
1193a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * if unavailable.
1194a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         */
1195a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public @Nullable CharSequence getAppLabel() {
1196a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            return appLabel;
1197a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        }
119816c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey
1199fbd0e9fa37fc17ccd25e4c1f16195bbd27de3c4cJeff Sharkey        /**
1200a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * Return an Intent that can be started to view details about this install
1201a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * session. This may surface actions such as pause, resume, or cancel.
1202fbd0e9fa37fc17ccd25e4c1f16195bbd27de3c4cJeff Sharkey         * <p>
1203a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * In some cases, a matching Activity may not exist, so ensure you safeguard
1204a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * against this.
1205a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         *
1206a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey         * @see PackageInstaller#ACTION_SESSION_DETAILS
1207fbd0e9fa37fc17ccd25e4c1f16195bbd27de3c4cJeff Sharkey         */
1208de74231f245c90e5861ec84a9880b5b4ec247480Jeff Sharkey        public @Nullable Intent createDetailsIntent() {
1209a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            final Intent intent = new Intent(PackageInstaller.ACTION_SESSION_DETAILS);
1210a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            intent.putExtra(PackageInstaller.EXTRA_SESSION_ID, sessionId);
1211a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            intent.setPackage(installerPackageName);
1212a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1213a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            return intent;
1214bb580670350b76fa2fcc5ee873f99b7970759cbfJeff Sharkey        }
1215bb580670350b76fa2fcc5ee873f99b7970759cbfJeff Sharkey
1216de74231f245c90e5861ec84a9880b5b4ec247480Jeff Sharkey        /** {@hide} */
1217de74231f245c90e5861ec84a9880b5b4ec247480Jeff Sharkey        @Deprecated
1218de74231f245c90e5861ec84a9880b5b4ec247480Jeff Sharkey        public @Nullable Intent getDetailsIntent() {
1219de74231f245c90e5861ec84a9880b5b4ec247480Jeff Sharkey            return createDetailsIntent();
1220de74231f245c90e5861ec84a9880b5b4ec247480Jeff Sharkey        }
1221de74231f245c90e5861ec84a9880b5b4ec247480Jeff Sharkey
1222bb580670350b76fa2fcc5ee873f99b7970759cbfJeff Sharkey        @Override
1223a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public int describeContents() {
1224a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            return 0;
1225fbd0e9fa37fc17ccd25e4c1f16195bbd27de3c4cJeff Sharkey        }
1226fbd0e9fa37fc17ccd25e4c1f16195bbd27de3c4cJeff Sharkey
1227fbd0e9fa37fc17ccd25e4c1f16195bbd27de3c4cJeff Sharkey        @Override
1228a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public void writeToParcel(Parcel dest, int flags) {
1229a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            dest.writeInt(sessionId);
1230a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            dest.writeString(installerPackageName);
1231a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            dest.writeString(resolvedBaseCodePath);
1232a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            dest.writeFloat(progress);
1233a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            dest.writeInt(sealed ? 1 : 0);
1234bc7bce38b2e4733a14f6296c75f983bd50f996d1Jeff Sharkey            dest.writeInt(active ? 1 : 0);
1235a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey
1236a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            dest.writeInt(mode);
1237a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            dest.writeLong(sizeBytes);
1238a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            dest.writeString(appPackageName);
1239a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            dest.writeParcelable(appIcon, flags);
1240a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey            dest.writeString(appLabel != null ? appLabel.toString() : null);
1241a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        }
1242a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey
1243a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey        public static final Parcelable.Creator<SessionInfo>
1244a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey                CREATOR = new Parcelable.Creator<SessionInfo>() {
1245a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey                    @Override
1246a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey                    public SessionInfo createFromParcel(Parcel p) {
1247a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey                        return new SessionInfo(p);
1248a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey                    }
124916c8e3f49497b6046972ae650772f65768366be8Jeff Sharkey
1250a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey                    @Override
1251a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey                    public SessionInfo[] newArray(int size) {
1252a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey                        return new SessionInfo[size];
1253a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey                    }
1254a0907436c01fd8c545a6b5c7b28bc3bc9db59270Jeff Sharkey                };
1255bb580670350b76fa2fcc5ee873f99b7970759cbfJeff Sharkey    }
12563a44f3f1b446315ef894e01d2ab9b5388c2bd8c4Jeff Sharkey}
1257