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; 21 import android.content.ComponentName; 22 import android.content.Intent; 23 import android.content.IntentFilter; 24 import android.os.Bundle; 25 26 import java.util.Collections; 27 import java.util.List; 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 */ 38 public final class AuxiliaryResolveInfo { 39 /** The activity to launch if there's an installation failure. */ 40 public final ComponentName installFailureActivity; 41 /** Whether or not instant resolution needs the second phase */ 42 public final boolean needsPhaseTwo; 43 /** Opaque token to track the instant application resolution */ 44 public final String token; 45 /** An intent to start upon failure to install */ 46 public final Intent failureIntent; 47 /** The matching filters for this resolve info. */ 48 public final List<AuxiliaryFilter> filters; 49 50 /** Create a response for installing an instant application. */ 51 public AuxiliaryResolveInfo(@NonNull String token, 52 boolean needsPhase2, 53 @Nullable Intent failureIntent, 54 @Nullable List<AuxiliaryFilter> filters) { 55 this.token = token; 56 this.needsPhaseTwo = needsPhase2; 57 this.failureIntent = failureIntent; 58 this.filters = filters; 59 this.installFailureActivity = null; 60 } 61 62 /** Create a response for installing a split on demand. */ 63 public AuxiliaryResolveInfo(@Nullable ComponentName failureActivity, 64 @Nullable Intent failureIntent, 65 @Nullable List<AuxiliaryFilter> filters) { 66 super(); 67 this.installFailureActivity = failureActivity; 68 this.filters = filters; 69 this.token = null; 70 this.needsPhaseTwo = false; 71 this.failureIntent = failureIntent; 72 } 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 } 129 }