Todd Kennedy | e991022 | 2017-02-21 16:00:11 -0800 | [diff] [blame] | 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 | |
| 17 | package android.content.pm; |
| 18 | |
| 19 | import android.annotation.NonNull; |
| 20 | import android.annotation.Nullable; |
Todd Kennedy | d0084f7 | 2017-07-28 13:56:14 -0700 | [diff] [blame] | 21 | import android.content.ComponentName; |
Todd Kennedy | e991022 | 2017-02-21 16:00:11 -0800 | [diff] [blame] | 22 | import android.content.Intent; |
| 23 | import android.content.IntentFilter; |
Patrick Baumann | 577d402 | 2018-01-31 16:55:10 +0000 | [diff] [blame] | 24 | import android.os.Bundle; |
| 25 | |
| 26 | import java.util.Collections; |
| 27 | import java.util.List; |
Todd Kennedy | e991022 | 2017-02-21 16:00:11 -0800 | [diff] [blame] | 28 | |
| 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 Baumann | 577d402 | 2018-01-31 16:55:10 +0000 | [diff] [blame] | 38 | public final class AuxiliaryResolveInfo { |
Todd Kennedy | d0084f7 | 2017-07-28 13:56:14 -0700 | [diff] [blame] | 39 | /** The activity to launch if there's an installation failure. */ |
| 40 | public final ComponentName installFailureActivity; |
Todd Kennedy | 1fb3404 | 2017-03-01 13:56:58 -0800 | [diff] [blame] | 41 | /** Whether or not instant resolution needs the second phase */ |
Todd Kennedy | e991022 | 2017-02-21 16:00:11 -0800 | [diff] [blame] | 42 | public final boolean needsPhaseTwo; |
Todd Kennedy | 1fb3404 | 2017-03-01 13:56:58 -0800 | [diff] [blame] | 43 | /** Opaque token to track the instant application resolution */ |
Todd Kennedy | e991022 | 2017-02-21 16:00:11 -0800 | [diff] [blame] | 44 | public final String token; |
Todd Kennedy | 7dd99e3 | 2017-05-03 16:12:49 -0700 | [diff] [blame] | 45 | /** An intent to start upon failure to install */ |
| 46 | public final Intent failureIntent; |
Patrick Baumann | 577d402 | 2018-01-31 16:55:10 +0000 | [diff] [blame] | 47 | /** The matching filters for this resolve info. */ |
| 48 | public final List<AuxiliaryFilter> filters; |
Todd Kennedy | e991022 | 2017-02-21 16:00:11 -0800 | [diff] [blame] | 49 | |
| 50 | /** Create a response for installing an instant application. */ |
Patrick Baumann | 577d402 | 2018-01-31 16:55:10 +0000 | [diff] [blame] | 51 | public AuxiliaryResolveInfo(@NonNull String token, |
Todd Kennedy | 7dd99e3 | 2017-05-03 16:12:49 -0700 | [diff] [blame] | 52 | boolean needsPhase2, |
Patrick Baumann | 577d402 | 2018-01-31 16:55:10 +0000 | [diff] [blame] | 53 | @Nullable Intent failureIntent, |
| 54 | @Nullable List<AuxiliaryFilter> filters) { |
Todd Kennedy | e991022 | 2017-02-21 16:00:11 -0800 | [diff] [blame] | 55 | this.token = token; |
| 56 | this.needsPhaseTwo = needsPhase2; |
Todd Kennedy | 7dd99e3 | 2017-05-03 16:12:49 -0700 | [diff] [blame] | 57 | this.failureIntent = failureIntent; |
Patrick Baumann | 577d402 | 2018-01-31 16:55:10 +0000 | [diff] [blame] | 58 | this.filters = filters; |
Todd Kennedy | d0084f7 | 2017-07-28 13:56:14 -0700 | [diff] [blame] | 59 | this.installFailureActivity = null; |
Todd Kennedy | e991022 | 2017-02-21 16:00:11 -0800 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | /** Create a response for installing a split on demand. */ |
Patrick Baumann | 577d402 | 2018-01-31 16:55:10 +0000 | [diff] [blame] | 63 | public AuxiliaryResolveInfo(@Nullable ComponentName failureActivity, |
| 64 | @Nullable Intent failureIntent, |
| 65 | @Nullable List<AuxiliaryFilter> filters) { |
Todd Kennedy | e991022 | 2017-02-21 16:00:11 -0800 | [diff] [blame] | 66 | super(); |
Todd Kennedy | d0084f7 | 2017-07-28 13:56:14 -0700 | [diff] [blame] | 67 | this.installFailureActivity = failureActivity; |
Patrick Baumann | 577d402 | 2018-01-31 16:55:10 +0000 | [diff] [blame] | 68 | this.filters = filters; |
Todd Kennedy | e991022 | 2017-02-21 16:00:11 -0800 | [diff] [blame] | 69 | this.token = null; |
| 70 | this.needsPhaseTwo = false; |
Todd Kennedy | 7dd99e3 | 2017-05-03 16:12:49 -0700 | [diff] [blame] | 71 | this.failureIntent = failureIntent; |
Todd Kennedy | e991022 | 2017-02-21 16:00:11 -0800 | [diff] [blame] | 72 | } |
Patrick Baumann | 577d402 | 2018-01-31 16:55:10 +0000 | [diff] [blame] | 73 | |
| 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 Kennedy | e991022 | 2017-02-21 16:00:11 -0800 | [diff] [blame] | 129 | } |