blob: 202df50dda6f88c852af97dfff7ceb3895dcf4db [file] [log] [blame]
Todd Kennedye9910222017-02-21 16:00:11 -08001/*
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;
Todd Kennedyd0084f72017-07-28 13:56:14 -070021import android.content.ComponentName;
Todd Kennedye9910222017-02-21 16:00:11 -080022import android.content.Intent;
23import android.content.IntentFilter;
Patrick Baumann577d4022018-01-31 16:55:10 +000024import android.os.Bundle;
25
26import java.util.Collections;
27import java.util.List;
Todd Kennedye9910222017-02-21 16:00:11 -080028
29/**
30 * Auxiliary application resolution response.
31 * <p>
32 * Used when resolution occurs, but, the target is not actually on the device.
33 * This happens resolving instant apps that haven't been installed yet or if
34 * the application consists of multiple feature splits and the needed split
35 * hasn't been installed.
36 * @hide
37 */
Patrick Baumann577d4022018-01-31 16:55:10 +000038public final class AuxiliaryResolveInfo {
Todd Kennedyd0084f72017-07-28 13:56:14 -070039 /** The activity to launch if there's an installation failure. */
40 public final ComponentName installFailureActivity;
Todd Kennedy1fb34042017-03-01 13:56:58 -080041 /** Whether or not instant resolution needs the second phase */
Todd Kennedye9910222017-02-21 16:00:11 -080042 public final boolean needsPhaseTwo;
Todd Kennedy1fb34042017-03-01 13:56:58 -080043 /** Opaque token to track the instant application resolution */
Todd Kennedye9910222017-02-21 16:00:11 -080044 public final String token;
Todd Kennedy7dd99e32017-05-03 16:12:49 -070045 /** An intent to start upon failure to install */
46 public final Intent failureIntent;
Patrick Baumann577d4022018-01-31 16:55:10 +000047 /** The matching filters for this resolve info. */
48 public final List<AuxiliaryFilter> filters;
Todd Kennedye9910222017-02-21 16:00:11 -080049
50 /** Create a response for installing an instant application. */
Patrick Baumann577d4022018-01-31 16:55:10 +000051 public AuxiliaryResolveInfo(@NonNull String token,
Todd Kennedy7dd99e32017-05-03 16:12:49 -070052 boolean needsPhase2,
Patrick Baumann577d4022018-01-31 16:55:10 +000053 @Nullable Intent failureIntent,
54 @Nullable List<AuxiliaryFilter> filters) {
Todd Kennedye9910222017-02-21 16:00:11 -080055 this.token = token;
56 this.needsPhaseTwo = needsPhase2;
Todd Kennedy7dd99e32017-05-03 16:12:49 -070057 this.failureIntent = failureIntent;
Patrick Baumann577d4022018-01-31 16:55:10 +000058 this.filters = filters;
Todd Kennedyd0084f72017-07-28 13:56:14 -070059 this.installFailureActivity = null;
Todd Kennedye9910222017-02-21 16:00:11 -080060 }
61
62 /** Create a response for installing a split on demand. */
Patrick Baumann577d4022018-01-31 16:55:10 +000063 public AuxiliaryResolveInfo(@Nullable ComponentName failureActivity,
64 @Nullable Intent failureIntent,
65 @Nullable List<AuxiliaryFilter> filters) {
Todd Kennedye9910222017-02-21 16:00:11 -080066 super();
Todd Kennedyd0084f72017-07-28 13:56:14 -070067 this.installFailureActivity = failureActivity;
Patrick Baumann577d4022018-01-31 16:55:10 +000068 this.filters = filters;
Todd Kennedye9910222017-02-21 16:00:11 -080069 this.token = null;
70 this.needsPhaseTwo = false;
Todd Kennedy7dd99e32017-05-03 16:12:49 -070071 this.failureIntent = failureIntent;
Todd Kennedye9910222017-02-21 16:00:11 -080072 }
Patrick Baumann577d4022018-01-31 16:55:10 +000073
74 /** Create a response for installing a split on demand. */
75 public AuxiliaryResolveInfo(@Nullable ComponentName failureActivity,
76 String packageName, long versionCode, String splitName) {
77 this(failureActivity, null, Collections.singletonList(
78 new AuxiliaryResolveInfo.AuxiliaryFilter(packageName, versionCode, splitName)));
79 }
80
81 /** @hide */
82 public static final class AuxiliaryFilter extends IntentFilter {
83 /** Resolved information returned from the external instant resolver */
84 public final InstantAppResolveInfo resolveInfo;
85 /** The resolved package. Copied from {@link #resolveInfo}. */
86 public final String packageName;
87 /** The version code of the package */
88 public final long versionCode;
89 /** The resolve split. Copied from the matched filter in {@link #resolveInfo}. */
90 public final String splitName;
91 /** The extras to pass on to the installer for this filter. */
92 public final Bundle extras;
93
94 public AuxiliaryFilter(IntentFilter orig, InstantAppResolveInfo resolveInfo,
95 String splitName, Bundle extras) {
96 super(orig);
97 this.resolveInfo = resolveInfo;
98 this.packageName = resolveInfo.getPackageName();
99 this.versionCode = resolveInfo.getLongVersionCode();
100 this.splitName = splitName;
101 this.extras = extras;
102 }
103
104 public AuxiliaryFilter(InstantAppResolveInfo resolveInfo,
105 String splitName, Bundle extras) {
106 this.resolveInfo = resolveInfo;
107 this.packageName = resolveInfo.getPackageName();
108 this.versionCode = resolveInfo.getLongVersionCode();
109 this.splitName = splitName;
110 this.extras = extras;
111 }
112
113 public AuxiliaryFilter(String packageName, long versionCode, String splitName) {
114 this.resolveInfo = null;
115 this.packageName = packageName;
116 this.versionCode = versionCode;
117 this.splitName = splitName;
118 this.extras = null;
119 }
120
121 @Override
122 public String toString() {
123 return "AuxiliaryFilter{"
124 + "packageName='" + packageName + '\''
125 + ", versionCode=" + versionCode
126 + ", splitName='" + splitName + '\'' + '}';
127 }
128 }
Todd Kennedye9910222017-02-21 16:00:11 -0800129}