1 /* 2 * Copyright (C) 2019 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 com.android.internal.app.chooser; 18 19 20 import android.app.Activity; 21 import android.content.ComponentName; 22 import android.content.Context; 23 import android.content.Intent; 24 import android.content.pm.ResolveInfo; 25 import android.graphics.drawable.Drawable; 26 import android.os.Bundle; 27 import android.os.UserHandle; 28 29 import com.android.internal.app.ResolverActivity; 30 31 import java.util.List; 32 33 /** 34 * A single target as represented in the chooser. 35 */ 36 public interface TargetInfo { 37 /** 38 * Get the resolved intent that represents this target. Note that this may not be the 39 * intent that will be launched by calling one of the <code>start</code> methods provided; 40 * this is the intent that will be credited with the launch. 41 * 42 * @return the resolved intent for this target 43 */ getResolvedIntent()44 Intent getResolvedIntent(); 45 46 /** 47 * Get the resolved component name that represents this target. Note that this may not 48 * be the component that will be directly launched by calling one of the <code>start</code> 49 * methods provided; this is the component that will be credited with the launch. 50 * 51 * @return the resolved ComponentName for this target 52 */ getResolvedComponentName()53 ComponentName getResolvedComponentName(); 54 55 /** 56 * Start the activity referenced by this target. 57 * 58 * @param activity calling Activity performing the launch 59 * @param options ActivityOptions bundle 60 * @return true if the start completed successfully 61 */ start(Activity activity, Bundle options)62 boolean start(Activity activity, Bundle options); 63 64 /** 65 * Start the activity referenced by this target as if the ResolverActivity's caller 66 * was performing the start operation. 67 * 68 * @param activity calling Activity (actually) performing the launch 69 * @param options ActivityOptions bundle 70 * @param userId userId to start as or {@link UserHandle#USER_NULL} for activity's caller 71 * @return true if the start completed successfully 72 */ startAsCaller(ResolverActivity activity, Bundle options, int userId)73 boolean startAsCaller(ResolverActivity activity, Bundle options, int userId); 74 75 /** 76 * Start the activity referenced by this target as a given user. 77 * 78 * @param activity calling activity performing the launch 79 * @param options ActivityOptions bundle 80 * @param user handle for the user to start the activity as 81 * @return true if the start completed successfully 82 */ startAsUser(Activity activity, Bundle options, UserHandle user)83 boolean startAsUser(Activity activity, Bundle options, UserHandle user); 84 85 /** 86 * Return the ResolveInfo about how and why this target matched the original query 87 * for available targets. 88 * 89 * @return ResolveInfo representing this target's match 90 */ getResolveInfo()91 ResolveInfo getResolveInfo(); 92 93 /** 94 * Return the human-readable text label for this target. 95 * 96 * @return user-visible target label 97 */ getDisplayLabel()98 CharSequence getDisplayLabel(); 99 100 /** 101 * Return any extended info for this target. This may be used to disambiguate 102 * otherwise identical targets. 103 * 104 * @return human-readable disambig string or null if none present 105 */ getExtendedInfo()106 CharSequence getExtendedInfo(); 107 108 /** 109 * @return The drawable that should be used to represent this target including badge 110 * @param context 111 */ getDisplayIcon(Context context)112 Drawable getDisplayIcon(Context context); 113 114 /** 115 * Clone this target with the given fill-in information. 116 */ cloneFilledIn(Intent fillInIntent, int flags)117 TargetInfo cloneFilledIn(Intent fillInIntent, int flags); 118 119 /** 120 * @return the list of supported source intents deduped against this single target 121 */ getAllSourceIntents()122 List<Intent> getAllSourceIntents(); 123 124 /** 125 * @return true if this target cannot be selected by the user 126 */ isSuspended()127 boolean isSuspended(); 128 129 /** 130 * @return true if this target should be pinned to the front by the request of the user 131 */ isPinned()132 boolean isPinned(); 133 134 /** 135 * Fix the URIs in {@code intent} if cross-profile sharing is required. This should be called 136 * before launching the intent as another user. 137 */ prepareIntentForCrossProfileLaunch(Intent intent, int targetUserId)138 static void prepareIntentForCrossProfileLaunch(Intent intent, int targetUserId) { 139 final int currentUserId = UserHandle.myUserId(); 140 if (targetUserId != currentUserId) { 141 intent.fixUris(currentUserId); 142 } 143 } 144 } 145