1/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.content.pm;
18
19import android.annotation.NonNull;
20import android.annotation.Nullable;
21import android.content.ComponentName;
22import android.content.Intent;
23import android.content.IntentFilter;
24
25/**
26 * Auxiliary application resolution response.
27 * <p>
28 * Used when resolution occurs, but, the target is not actually on the device.
29 * This happens resolving instant apps that haven't been installed yet or if
30 * the application consists of multiple feature splits and the needed split
31 * hasn't been installed.
32 * @hide
33 */
34public final class AuxiliaryResolveInfo extends IntentFilter {
35    /** Resolved information returned from the external instant resolver */
36    public final InstantAppResolveInfo resolveInfo;
37    /** The resolved package. Copied from {@link #resolveInfo}. */
38    public final String packageName;
39    /** The activity to launch if there's an installation failure. */
40    public final ComponentName installFailureActivity;
41    /** The resolve split. Copied from the matched filter in {@link #resolveInfo}. */
42    public final String splitName;
43    /** Whether or not instant resolution needs the second phase */
44    public final boolean needsPhaseTwo;
45    /** Opaque token to track the instant application resolution */
46    public final String token;
47    /** The version code of the package */
48    public final int versionCode;
49    /** An intent to start upon failure to install */
50    public final Intent failureIntent;
51
52    /** Create a response for installing an instant application. */
53    public AuxiliaryResolveInfo(@NonNull InstantAppResolveInfo resolveInfo,
54            @NonNull IntentFilter orig,
55            @Nullable String splitName,
56            @NonNull String token,
57            boolean needsPhase2,
58            @Nullable Intent failureIntent) {
59        super(orig);
60        this.resolveInfo = resolveInfo;
61        this.packageName = resolveInfo.getPackageName();
62        this.splitName = splitName;
63        this.token = token;
64        this.needsPhaseTwo = needsPhase2;
65        this.versionCode = resolveInfo.getVersionCode();
66        this.failureIntent = failureIntent;
67        this.installFailureActivity = null;
68    }
69
70    /** Create a response for installing a split on demand. */
71    public AuxiliaryResolveInfo(@NonNull String packageName,
72            @Nullable String splitName,
73            @Nullable ComponentName failureActivity,
74            int versionCode,
75            @Nullable Intent failureIntent) {
76        super();
77        this.packageName = packageName;
78        this.installFailureActivity = failureActivity;
79        this.splitName = splitName;
80        this.versionCode = versionCode;
81        this.resolveInfo = null;
82        this.token = null;
83        this.needsPhaseTwo = false;
84        this.failureIntent = failureIntent;
85    }
86}