The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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; |
| 18 | |
Hyunyoung Song | 16b7af4 | 2018-10-05 14:00:42 -0700 | [diff] [blame] | 19 | import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; |
| 20 | |
Adam Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 21 | import android.annotation.Nullable; |
Philip P. Moltmann | f8173ca | 2016-04-12 15:11:23 -0700 | [diff] [blame] | 22 | import android.annotation.StringRes; |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 23 | import android.annotation.UiThread; |
Adam Powell | e9414d9 | 2014-07-05 17:44:18 -0700 | [diff] [blame] | 24 | import android.app.Activity; |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 25 | import android.app.ActivityManager; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 26 | import android.app.ActivityTaskManager; |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 27 | import android.app.ActivityThread; |
Adam Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 28 | import android.app.VoiceInteractor.PickOptionRequest; |
| 29 | import android.app.VoiceInteractor.PickOptionRequest.Option; |
| 30 | import android.app.VoiceInteractor.Prompt; |
shafik | 34064c3 | 2019-03-06 15:42:52 +0000 | [diff] [blame] | 31 | import android.app.role.RoleManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | import android.content.ComponentName; |
| 33 | import android.content.Context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | import android.content.Intent; |
| 35 | import android.content.IntentFilter; |
| 36 | import android.content.pm.ActivityInfo; |
Sander Alewijnse | 6c9eee8 | 2014-07-17 10:03:31 +0100 | [diff] [blame] | 37 | import android.content.pm.ApplicationInfo; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 38 | import android.content.pm.LabeledIntent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | import android.content.pm.PackageManager; |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 40 | import android.content.pm.PackageManager.NameNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | import android.content.pm.ResolveInfo; |
Sander Alewijnse | 6c9eee8 | 2014-07-17 10:03:31 +0100 | [diff] [blame] | 42 | import android.content.pm.UserInfo; |
Jiongxuan Gao | 3365b16 | 2016-11-24 20:20:27 +0900 | [diff] [blame] | 43 | import android.content.res.Configuration; |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 44 | import android.content.res.Resources; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 45 | import android.graphics.drawable.Drawable; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | import android.net.Uri; |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 47 | import android.os.AsyncTask; |
Sander Alewijnse | 6c9eee8 | 2014-07-17 10:03:31 +0100 | [diff] [blame] | 48 | import android.os.Build; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | import android.os.Bundle; |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 50 | import android.os.IBinder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | import android.os.PatternMatcher; |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 52 | import android.os.RemoteException; |
Jeff Sharkey | 37355a9 | 2016-02-05 16:19:10 -0700 | [diff] [blame] | 53 | import android.os.StrictMode; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 54 | import android.os.UserHandle; |
Sander Alewijnse | 6c9eee8 | 2014-07-17 10:03:31 +0100 | [diff] [blame] | 55 | import android.os.UserManager; |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 56 | import android.provider.MediaStore; |
| 57 | import android.provider.Settings; |
| 58 | import android.text.TextUtils; |
Hyunyoung Song | dadb9e1 | 2017-08-24 18:08:35 -0700 | [diff] [blame] | 59 | import android.util.IconDrawableFactory; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | import android.util.Log; |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 61 | import android.util.Slog; |
Adam Powell | 2d80962 | 2012-03-22 15:24:43 -0700 | [diff] [blame] | 62 | import android.view.LayoutInflater; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | import android.view.View; |
| 64 | import android.view.ViewGroup; |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 65 | import android.widget.AbsListView; |
Adam Powell | 2d80962 | 2012-03-22 15:24:43 -0700 | [diff] [blame] | 66 | import android.widget.AdapterView; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | import android.widget.BaseAdapter; |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 68 | import android.widget.Button; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | import android.widget.ImageView; |
Adam Powell | 2d80962 | 2012-03-22 15:24:43 -0700 | [diff] [blame] | 70 | import android.widget.ListView; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | import android.widget.TextView; |
Sander Alewijnse | 6c9eee8 | 2014-07-17 10:03:31 +0100 | [diff] [blame] | 72 | import android.widget.Toast; |
Hyunyoung Song | 16b7af4 | 2018-10-05 14:00:42 -0700 | [diff] [blame] | 73 | |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 74 | import com.android.internal.R; |
| 75 | import com.android.internal.annotations.VisibleForTesting; |
| 76 | import com.android.internal.content.PackageMonitor; |
Clara Bayarri | fa902aa | 2016-04-13 14:45:08 +0100 | [diff] [blame] | 77 | import com.android.internal.logging.MetricsLogger; |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 78 | import com.android.internal.logging.nano.MetricsProto; |
Adam Powell | 4f6c205 | 2014-07-07 18:49:10 -0700 | [diff] [blame] | 79 | import com.android.internal.widget.ResolverDrawerLayout; |
Adam Powell | 2d80962 | 2012-03-22 15:24:43 -0700 | [diff] [blame] | 80 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | import java.util.ArrayList; |
Clara Bayarri | fa902aa | 2016-04-13 14:45:08 +0100 | [diff] [blame] | 82 | import java.util.Arrays; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | import java.util.HashSet; |
| 84 | import java.util.Iterator; |
| 85 | import java.util.List; |
Adam Powell | c412be6 | 2015-06-24 13:54:10 -0700 | [diff] [blame] | 86 | import java.util.Objects; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | import java.util.Set; |
| 88 | |
| 89 | /** |
| 90 | * This activity is displayed when the system attempts to start an Intent for |
| 91 | * which there is more than one matching activity, allowing the user to decide |
| 92 | * which to go to. It is not normally used directly by application developers. |
| 93 | */ |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 94 | @UiThread |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 95 | public class ResolverActivity extends Activity { |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 96 | |
Alison Cichowlas | 4691ed4 | 2018-11-13 15:59:55 -0500 | [diff] [blame] | 97 | // Temporary flag for new chooser delegate behavior. |
Alison Cichowlas | 7b6f3b6 | 2018-12-07 09:06:57 -0500 | [diff] [blame] | 98 | boolean mEnableChooserDelegate = true; |
Alison Cichowlas | 4691ed4 | 2018-11-13 15:59:55 -0500 | [diff] [blame] | 99 | |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 100 | protected ResolveListAdapter mAdapter; |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 101 | private boolean mSafeForwardingMode; |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 102 | private AbsListView mAdapterView; |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 103 | private Button mAlwaysButton; |
| 104 | private Button mOnceButton; |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 105 | private Button mSettingsButton; |
Adam Powell | 88831a2 | 2014-11-20 18:17:00 -0800 | [diff] [blame] | 106 | private View mProfileView; |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 107 | private int mIconDpi; |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 108 | private int mLastSelected = AbsListView.INVALID_POSITION; |
Sander Alewijnse | 6c9eee8 | 2014-07-17 10:03:31 +0100 | [diff] [blame] | 109 | private boolean mResolvingHome = false; |
Sander Alewijnse | f654533 | 2014-10-31 12:39:02 +0000 | [diff] [blame] | 110 | private int mProfileSwitchMessageId = -1; |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 111 | private int mLayoutId; |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 112 | private final ArrayList<Intent> mIntents = new ArrayList<>(); |
Adam Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 113 | private PickTargetOptionRequest mPickOptionRequest; |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 114 | private String mReferrerPackage; |
Hakan Seyalioglu | 3355012 | 2017-01-06 19:54:43 -0800 | [diff] [blame] | 115 | private CharSequence mTitle; |
| 116 | private int mDefaultTitleResId; |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 117 | private boolean mUseLayoutForBrowsables; |
Adam Powell | 09a6560 | 2014-07-20 16:23:14 -0700 | [diff] [blame] | 118 | |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 119 | // Whether or not this activity supports choosing a default handler for the intent. |
| 120 | private boolean mSupportsAlwaysUseOption; |
Adam Powell | 63b3169 | 2015-09-28 10:45:00 -0700 | [diff] [blame] | 121 | protected ResolverDrawerLayout mResolverDrawerLayout; |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 122 | protected PackageManager mPm; |
| 123 | protected int mLaunchedFromUid; |
| 124 | |
| 125 | private static final String TAG = "ResolverActivity"; |
| 126 | private static final boolean DEBUG = false; |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 127 | private Runnable mPostListReadyRunnable; |
Adam Powell | 63b3169 | 2015-09-28 10:45:00 -0700 | [diff] [blame] | 128 | |
Dianne Hackborn | d44713a | 2012-04-30 16:34:46 -0700 | [diff] [blame] | 129 | private boolean mRegistered; |
Jorim Jaggi | f631ef7 | 2017-02-24 13:49:47 +0100 | [diff] [blame] | 130 | |
| 131 | /** See {@link #setRetainInOnStop}. */ |
| 132 | private boolean mRetainInOnStop; |
| 133 | |
Hyunyoung Song | dadb9e1 | 2017-08-24 18:08:35 -0700 | [diff] [blame] | 134 | IconDrawableFactory mIconFactory; |
| 135 | |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 136 | private final PackageMonitor mPackageMonitor = new PackageMonitor() { |
| 137 | @Override public void onSomePackagesChanged() { |
| 138 | mAdapter.handlePackagesChanged(); |
Adam Powell | 88831a2 | 2014-11-20 18:17:00 -0800 | [diff] [blame] | 139 | if (mProfileView != null) { |
| 140 | bindProfileView(); |
| 141 | } |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 142 | } |
Xiaohui Chen | 393c801 | 2017-02-14 14:55:07 -0800 | [diff] [blame] | 143 | |
| 144 | @Override |
| 145 | public boolean onPackageChanged(String packageName, int uid, String[] components) { |
| 146 | // We care about all package changes, not just the whole package itself which is |
| 147 | // default behavior. |
| 148 | return true; |
| 149 | } |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 150 | }; |
| 151 | |
Philip P. Moltmann | f8173ca | 2016-04-12 15:11:23 -0700 | [diff] [blame] | 152 | /** |
| 153 | * Get the string resource to be used as a label for the link to the resolver activity for an |
| 154 | * action. |
| 155 | * |
| 156 | * @param action The action to resolve |
| 157 | * |
| 158 | * @return The string resource to be used as a label |
| 159 | */ |
| 160 | public static @StringRes int getLabelRes(String action) { |
| 161 | return ActionTitle.forAction(action).labelRes; |
| 162 | } |
| 163 | |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 164 | private enum ActionTitle { |
| 165 | VIEW(Intent.ACTION_VIEW, |
| 166 | com.android.internal.R.string.whichViewApplication, |
Philip P. Moltmann | f8173ca | 2016-04-12 15:11:23 -0700 | [diff] [blame] | 167 | com.android.internal.R.string.whichViewApplicationNamed, |
| 168 | com.android.internal.R.string.whichViewApplicationLabel), |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 169 | EDIT(Intent.ACTION_EDIT, |
| 170 | com.android.internal.R.string.whichEditApplication, |
Philip P. Moltmann | f8173ca | 2016-04-12 15:11:23 -0700 | [diff] [blame] | 171 | com.android.internal.R.string.whichEditApplicationNamed, |
| 172 | com.android.internal.R.string.whichEditApplicationLabel), |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 173 | SEND(Intent.ACTION_SEND, |
| 174 | com.android.internal.R.string.whichSendApplication, |
Philip P. Moltmann | f8173ca | 2016-04-12 15:11:23 -0700 | [diff] [blame] | 175 | com.android.internal.R.string.whichSendApplicationNamed, |
| 176 | com.android.internal.R.string.whichSendApplicationLabel), |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 177 | SENDTO(Intent.ACTION_SENDTO, |
Adam Powell | 13ea8f4 | 2016-03-18 09:39:41 -0700 | [diff] [blame] | 178 | com.android.internal.R.string.whichSendToApplication, |
Philip P. Moltmann | f8173ca | 2016-04-12 15:11:23 -0700 | [diff] [blame] | 179 | com.android.internal.R.string.whichSendToApplicationNamed, |
| 180 | com.android.internal.R.string.whichSendToApplicationLabel), |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 181 | SEND_MULTIPLE(Intent.ACTION_SEND_MULTIPLE, |
| 182 | com.android.internal.R.string.whichSendApplication, |
Philip P. Moltmann | f8173ca | 2016-04-12 15:11:23 -0700 | [diff] [blame] | 183 | com.android.internal.R.string.whichSendApplicationNamed, |
| 184 | com.android.internal.R.string.whichSendApplicationLabel), |
| 185 | CAPTURE_IMAGE(MediaStore.ACTION_IMAGE_CAPTURE, |
| 186 | com.android.internal.R.string.whichImageCaptureApplication, |
| 187 | com.android.internal.R.string.whichImageCaptureApplicationNamed, |
| 188 | com.android.internal.R.string.whichImageCaptureApplicationLabel), |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 189 | DEFAULT(null, |
| 190 | com.android.internal.R.string.whichApplication, |
Philip P. Moltmann | f8173ca | 2016-04-12 15:11:23 -0700 | [diff] [blame] | 191 | com.android.internal.R.string.whichApplicationNamed, |
| 192 | com.android.internal.R.string.whichApplicationLabel), |
Adam Powell | a35c77a | 2014-09-25 16:46:36 -0700 | [diff] [blame] | 193 | HOME(Intent.ACTION_MAIN, |
| 194 | com.android.internal.R.string.whichHomeApplication, |
Philip P. Moltmann | f8173ca | 2016-04-12 15:11:23 -0700 | [diff] [blame] | 195 | com.android.internal.R.string.whichHomeApplicationNamed, |
| 196 | com.android.internal.R.string.whichHomeApplicationLabel); |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 197 | |
shafik | 0c7c5d5 | 2019-02-27 12:13:25 +0000 | [diff] [blame] | 198 | // titles for layout that deals with http(s) intents |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 199 | public static final int BROWSABLE_TITLE_RES = |
| 200 | com.android.internal.R.string.whichGiveAccessToApplication; |
| 201 | public static final int BROWSABLE_NAMED_TITLE_RES = |
| 202 | com.android.internal.R.string.whichGiveAccessToApplicationNamed; |
| 203 | |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 204 | public final String action; |
| 205 | public final int titleRes; |
| 206 | public final int namedTitleRes; |
Philip P. Moltmann | f8173ca | 2016-04-12 15:11:23 -0700 | [diff] [blame] | 207 | public final @StringRes int labelRes; |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 208 | |
Philip P. Moltmann | f8173ca | 2016-04-12 15:11:23 -0700 | [diff] [blame] | 209 | ActionTitle(String action, int titleRes, int namedTitleRes, @StringRes int labelRes) { |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 210 | this.action = action; |
| 211 | this.titleRes = titleRes; |
| 212 | this.namedTitleRes = namedTitleRes; |
Philip P. Moltmann | f8173ca | 2016-04-12 15:11:23 -0700 | [diff] [blame] | 213 | this.labelRes = labelRes; |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | public static ActionTitle forAction(String action) { |
| 217 | for (ActionTitle title : values()) { |
Adam Powell | a35c77a | 2014-09-25 16:46:36 -0700 | [diff] [blame] | 218 | if (title != HOME && action != null && action.equals(title.action)) { |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 219 | return title; |
| 220 | } |
| 221 | } |
| 222 | return DEFAULT; |
| 223 | } |
| 224 | } |
| 225 | |
Dianne Hackborn | 905577f | 2011-09-07 18:31:28 -0700 | [diff] [blame] | 226 | private Intent makeMyIntent() { |
| 227 | Intent intent = new Intent(getIntent()); |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 228 | intent.setComponent(null); |
Dianne Hackborn | 905577f | 2011-09-07 18:31:28 -0700 | [diff] [blame] | 229 | // The resolver activity is set to be hidden from recent tasks. |
| 230 | // we don't want this attribute to be propagated to the next activity |
| 231 | // being launched. Note that if the original Intent also had this |
| 232 | // flag set, we are now losing it. That should be a very rare case |
| 233 | // and we can live with this. |
| 234 | intent.setFlags(intent.getFlags()&~Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
| 235 | return intent; |
| 236 | } |
| 237 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 238 | @Override |
| 239 | protected void onCreate(Bundle savedInstanceState) { |
Christopher Tate | b72b363 | 2013-09-30 17:50:32 -0700 | [diff] [blame] | 240 | // Use a specialized prompt when we're handling the 'Home' app startActivity() |
Christopher Tate | b72b363 | 2013-09-30 17:50:32 -0700 | [diff] [blame] | 241 | final Intent intent = makeMyIntent(); |
| 242 | final Set<String> categories = intent.getCategories(); |
| 243 | if (Intent.ACTION_MAIN.equals(intent.getAction()) |
| 244 | && categories != null |
| 245 | && categories.size() == 1 |
| 246 | && categories.contains(Intent.CATEGORY_HOME)) { |
Sander Alewijnse | 6c9eee8 | 2014-07-17 10:03:31 +0100 | [diff] [blame] | 247 | // Note: this field is not set to true in the compatibility version. |
| 248 | mResolvingHome = true; |
Christopher Tate | b72b363 | 2013-09-30 17:50:32 -0700 | [diff] [blame] | 249 | } |
| 250 | |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 251 | setSafeForwardingMode(true); |
| 252 | |
Adam Powell | a35c77a | 2014-09-25 16:46:36 -0700 | [diff] [blame] | 253 | onCreate(savedInstanceState, intent, null, 0, null, null, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 254 | } |
| 255 | |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 256 | /** |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 257 | * Compatibility version for other bundled services that use this overload without |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 258 | * a default title resource |
| 259 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 260 | protected void onCreate(Bundle savedInstanceState, Intent intent, |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 261 | CharSequence title, Intent[] initialIntents, |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 262 | List<ResolveInfo> rList, boolean supportsAlwaysUseOption) { |
| 263 | onCreate(savedInstanceState, intent, title, 0, initialIntents, rList, |
| 264 | supportsAlwaysUseOption); |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | protected void onCreate(Bundle savedInstanceState, Intent intent, |
| 268 | CharSequence title, int defaultTitleRes, Intent[] initialIntents, |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 269 | List<ResolveInfo> rList, boolean supportsAlwaysUseOption) { |
Adam Powell | e9414d9 | 2014-07-05 17:44:18 -0700 | [diff] [blame] | 270 | setTheme(R.style.Theme_DeviceDefault_Resolver); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 271 | super.onCreate(savedInstanceState); |
Sander Alewijnse | f654533 | 2014-10-31 12:39:02 +0000 | [diff] [blame] | 272 | |
| 273 | // Determine whether we should show that intent is forwarded |
| 274 | // from managed profile to owner or other way around. |
| 275 | setProfileSwitchMessageId(intent.getContentUserHint()); |
| 276 | |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 277 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 278 | mLaunchedFromUid = ActivityTaskManager.getService().getLaunchedFromUid( |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 279 | getActivityToken()); |
| 280 | } catch (RemoteException e) { |
| 281 | mLaunchedFromUid = -1; |
| 282 | } |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 283 | |
| 284 | if (mLaunchedFromUid < 0 || UserHandle.isIsolated(mLaunchedFromUid)) { |
| 285 | // Gulp! |
| 286 | finish(); |
| 287 | return; |
| 288 | } |
| 289 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 290 | mPm = getPackageManager(); |
Adam Powell | 09a6560 | 2014-07-20 16:23:14 -0700 | [diff] [blame] | 291 | |
Dianne Hackborn | d0d7503 | 2012-04-19 23:12:09 -0700 | [diff] [blame] | 292 | mPackageMonitor.register(this, getMainLooper(), false); |
Dianne Hackborn | d44713a | 2012-04-30 16:34:46 -0700 | [diff] [blame] | 293 | mRegistered = true; |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 294 | mReferrerPackage = getReferrerPackageName(); |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 295 | |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 296 | final ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE); |
| 297 | mIconDpi = am.getLauncherLargeIconDensity(); |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 298 | |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 299 | // Add our initial intent as the first item, regardless of what else has already been added. |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 300 | mIntents.add(0, new Intent(intent)); |
Hakan Seyalioglu | 3355012 | 2017-01-06 19:54:43 -0800 | [diff] [blame] | 301 | mTitle = title; |
| 302 | mDefaultTitleResId = defaultTitleRes; |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 303 | |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 304 | mUseLayoutForBrowsables = getTargetIntent() == null |
| 305 | ? false |
shafik | 0c7c5d5 | 2019-02-27 12:13:25 +0000 | [diff] [blame] | 306 | : isHttpSchemeAndViewAction(getTargetIntent()); |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 307 | |
| 308 | // We don't want to support Always Use if browsable layout is being used, |
| 309 | // as to mitigate Intent Capturing vulnerability |
| 310 | mSupportsAlwaysUseOption = supportsAlwaysUseOption && !mUseLayoutForBrowsables; |
| 311 | |
Hyunyoung Song | 16b7af4 | 2018-10-05 14:00:42 -0700 | [diff] [blame] | 312 | mIconFactory = IconDrawableFactory.newInstance(this, true); |
Hakan Seyalioglu | 3355012 | 2017-01-06 19:54:43 -0800 | [diff] [blame] | 313 | if (configureContentView(mIntents, initialIntents, rList)) { |
Adam Powell | 39e94eb | 2015-09-08 17:01:49 -0700 | [diff] [blame] | 314 | return; |
| 315 | } |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 316 | |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 317 | final ResolverDrawerLayout rdl = findViewById(R.id.contentPanel); |
Adam Powell | 4f6c205 | 2014-07-07 18:49:10 -0700 | [diff] [blame] | 318 | if (rdl != null) { |
Adam Powell | 5dd072d | 2014-10-30 19:51:41 -0700 | [diff] [blame] | 319 | rdl.setOnDismissedListener(new ResolverDrawerLayout.OnDismissedListener() { |
Adam Powell | 4f6c205 | 2014-07-07 18:49:10 -0700 | [diff] [blame] | 320 | @Override |
Adam Powell | 5dd072d | 2014-10-30 19:51:41 -0700 | [diff] [blame] | 321 | public void onDismissed() { |
Adam Powell | 4f6c205 | 2014-07-07 18:49:10 -0700 | [diff] [blame] | 322 | finish(); |
| 323 | } |
| 324 | }); |
Adam Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 325 | if (isVoiceInteraction()) { |
| 326 | rdl.setCollapsed(false); |
| 327 | } |
Adam Powell | 63b3169 | 2015-09-28 10:45:00 -0700 | [diff] [blame] | 328 | mResolverDrawerLayout = rdl; |
Adam Powell | 4f6c205 | 2014-07-07 18:49:10 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Adam Powell | 88831a2 | 2014-11-20 18:17:00 -0800 | [diff] [blame] | 331 | mProfileView = findViewById(R.id.profile_button); |
| 332 | if (mProfileView != null) { |
| 333 | mProfileView.setOnClickListener(new View.OnClickListener() { |
| 334 | @Override |
| 335 | public void onClick(View v) { |
| 336 | final DisplayResolveInfo dri = mAdapter.getOtherProfile(); |
| 337 | if (dri == null) { |
| 338 | return; |
| 339 | } |
| 340 | |
Sander Alewijnse | 053d3dd | 2015-03-09 15:31:10 +0000 | [diff] [blame] | 341 | // Do not show the profile switch message anymore. |
| 342 | mProfileSwitchMessageId = -1; |
| 343 | |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 344 | onTargetSelected(dri, false); |
Adam Powell | 88831a2 | 2014-11-20 18:17:00 -0800 | [diff] [blame] | 345 | finish(); |
| 346 | } |
| 347 | }); |
| 348 | bindProfileView(); |
| 349 | } |
Adam Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 350 | |
| 351 | if (isVoiceInteraction()) { |
| 352 | onSetupVoiceInteraction(); |
| 353 | } |
Clara Bayarri | 9550f5d | 2016-05-11 11:20:13 +0100 | [diff] [blame] | 354 | final Set<String> categories = intent.getCategories(); |
Clara Bayarri | fa902aa | 2016-04-13 14:45:08 +0100 | [diff] [blame] | 355 | MetricsLogger.action(this, mAdapter.hasFilteredItem() |
| 356 | ? MetricsProto.MetricsEvent.ACTION_SHOW_APP_DISAMBIG_APP_FEATURED |
| 357 | : MetricsProto.MetricsEvent.ACTION_SHOW_APP_DISAMBIG_NONE_FEATURED, |
| 358 | intent.getAction() + ":" + intent.getType() + ":" |
Clara Bayarri | 9550f5d | 2016-05-11 11:20:13 +0100 | [diff] [blame] | 359 | + (categories != null ? Arrays.toString(categories.toArray()) : "")); |
Adam Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Jiongxuan Gao | 3365b16 | 2016-11-24 20:20:27 +0900 | [diff] [blame] | 362 | @Override |
| 363 | public void onConfigurationChanged(Configuration newConfig) { |
| 364 | super.onConfigurationChanged(newConfig); |
| 365 | mAdapter.handlePackagesChanged(); |
| 366 | } |
| 367 | |
Adam Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 368 | /** |
| 369 | * Perform any initialization needed for voice interaction. |
| 370 | */ |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 371 | public void onSetupVoiceInteraction() { |
Adam Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 372 | // Do it right now. Subclasses may delay this and send it later. |
| 373 | sendVoiceChoicesIfNeeded(); |
| 374 | } |
| 375 | |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 376 | public void sendVoiceChoicesIfNeeded() { |
Adam Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 377 | if (!isVoiceInteraction()) { |
| 378 | // Clearly not needed. |
| 379 | return; |
| 380 | } |
| 381 | |
| 382 | |
| 383 | final Option[] options = new Option[mAdapter.getCount()]; |
| 384 | for (int i = 0, N = options.length; i < N; i++) { |
| 385 | options[i] = optionForChooserTarget(mAdapter.getItem(i), i); |
| 386 | } |
| 387 | |
| 388 | mPickOptionRequest = new PickTargetOptionRequest( |
| 389 | new Prompt(getTitle()), options, null); |
| 390 | getVoiceInteractor().submitRequest(mPickOptionRequest); |
| 391 | } |
| 392 | |
| 393 | Option optionForChooserTarget(TargetInfo target, int index) { |
| 394 | return new Option(target.getDisplayLabel(), index); |
Adam Powell | 88831a2 | 2014-11-20 18:17:00 -0800 | [diff] [blame] | 395 | } |
| 396 | |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 397 | protected final void setAdditionalTargets(Intent[] intents) { |
| 398 | if (intents != null) { |
| 399 | for (Intent intent : intents) { |
| 400 | mIntents.add(intent); |
| 401 | } |
| 402 | } |
| 403 | } |
| 404 | |
Adam Powell | 0ccc0e9 | 2015-04-23 17:19:37 -0700 | [diff] [blame] | 405 | public Intent getTargetIntent() { |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 406 | return mIntents.isEmpty() ? null : mIntents.get(0); |
Adam Powell | 0ccc0e9 | 2015-04-23 17:19:37 -0700 | [diff] [blame] | 407 | } |
| 408 | |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 409 | protected String getReferrerPackageName() { |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 410 | final Uri referrer = getReferrer(); |
| 411 | if (referrer != null && "android-app".equals(referrer.getScheme())) { |
| 412 | return referrer.getHost(); |
| 413 | } |
| 414 | return null; |
| 415 | } |
| 416 | |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 417 | public int getLayoutResource() { |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 418 | return R.layout.resolver_list; |
| 419 | } |
| 420 | |
Adam Powell | 88831a2 | 2014-11-20 18:17:00 -0800 | [diff] [blame] | 421 | void bindProfileView() { |
| 422 | final DisplayResolveInfo dri = mAdapter.getOtherProfile(); |
| 423 | if (dri != null) { |
| 424 | mProfileView.setVisibility(View.VISIBLE); |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 425 | View text = mProfileView.findViewById(R.id.profile_button); |
| 426 | if (!(text instanceof TextView)) { |
| 427 | text = mProfileView.findViewById(R.id.text1); |
| 428 | } |
| 429 | ((TextView) text).setText(dri.getDisplayLabel()); |
Adam Powell | 88831a2 | 2014-11-20 18:17:00 -0800 | [diff] [blame] | 430 | } else { |
| 431 | mProfileView.setVisibility(View.GONE); |
| 432 | } |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 433 | } |
| 434 | |
Sander Alewijnse | f654533 | 2014-10-31 12:39:02 +0000 | [diff] [blame] | 435 | private void setProfileSwitchMessageId(int contentUserHint) { |
| 436 | if (contentUserHint != UserHandle.USER_CURRENT && |
| 437 | contentUserHint != UserHandle.myUserId()) { |
| 438 | UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE); |
| 439 | UserInfo originUserInfo = userManager.getUserInfo(contentUserHint); |
| 440 | boolean originIsManaged = originUserInfo != null ? originUserInfo.isManagedProfile() |
| 441 | : false; |
| 442 | boolean targetIsManaged = userManager.isManagedProfile(); |
| 443 | if (originIsManaged && !targetIsManaged) { |
| 444 | mProfileSwitchMessageId = com.android.internal.R.string.forward_intent_to_owner; |
| 445 | } else if (!originIsManaged && targetIsManaged) { |
| 446 | mProfileSwitchMessageId = com.android.internal.R.string.forward_intent_to_work; |
| 447 | } |
| 448 | } |
| 449 | } |
| 450 | |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 451 | /** |
| 452 | * Turn on launch mode that is safe to use when forwarding intents received from |
| 453 | * applications and running in system processes. This mode uses Activity.startActivityAsCaller |
| 454 | * instead of the normal Activity.startActivity for launching the activity selected |
| 455 | * by the user. |
| 456 | * |
| 457 | * <p>This mode is set to true by default if the activity is initialized through |
| 458 | * {@link #onCreate(android.os.Bundle)}. If a subclass calls one of the other onCreate |
| 459 | * methods, it is set to false by default. You must set it before calling one of the |
| 460 | * more detailed onCreate methods, so that it will be set correctly in the case where |
| 461 | * there is only one intent to resolve and it is thus started immediately.</p> |
| 462 | */ |
| 463 | public void setSafeForwardingMode(boolean safeForwarding) { |
| 464 | mSafeForwardingMode = safeForwarding; |
| 465 | } |
| 466 | |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 467 | protected CharSequence getTitleForAction(Intent intent, int defaultTitleRes) { |
| 468 | final ActionTitle title = mResolvingHome |
| 469 | ? ActionTitle.HOME |
| 470 | : ActionTitle.forAction(intent.getAction()); |
| 471 | |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 472 | // While there may already be a filtered item, we can only use it in the title if the list |
| 473 | // is already sorted and all information relevant to it is already in the list. |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 474 | final boolean named = mAdapter.getFilteredPosition() >= 0; |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 475 | if (title == ActionTitle.DEFAULT && defaultTitleRes != 0) { |
| 476 | return getString(defaultTitleRes); |
shafik | 0c7c5d5 | 2019-02-27 12:13:25 +0000 | [diff] [blame] | 477 | } else if (isHttpSchemeAndViewAction(intent)) { |
| 478 | // If the Intent's scheme is http(s) then we need to warn the user that |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 479 | // they're giving access for the activity to open URLs from this specific host |
| 480 | return named |
| 481 | ? getString(ActionTitle.BROWSABLE_NAMED_TITLE_RES, intent.getData().getHost(), |
| 482 | mAdapter.getFilteredItem().getDisplayLabel()) |
| 483 | : getString(ActionTitle.BROWSABLE_TITLE_RES, intent.getData().getHost()); |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 484 | } else { |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 485 | return named |
| 486 | ? getString(title.namedTitleRes, mAdapter.getFilteredItem().getDisplayLabel()) |
| 487 | : getString(title.titleRes); |
Amith Yamasani | e9ecc8b | 2013-08-22 11:16:27 -0700 | [diff] [blame] | 488 | } |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 489 | } |
| 490 | |
Adam Powell | e9414d9 | 2014-07-05 17:44:18 -0700 | [diff] [blame] | 491 | void dismiss() { |
| 492 | if (!isFinishing()) { |
| 493 | finish(); |
| 494 | } |
| 495 | } |
| 496 | |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 497 | Drawable getIcon(Resources res, int resId) { |
| 498 | Drawable result; |
| 499 | try { |
| 500 | result = res.getDrawableForDensity(resId, mIconDpi); |
| 501 | } catch (Resources.NotFoundException e) { |
| 502 | result = null; |
| 503 | } |
| 504 | |
| 505 | return result; |
| 506 | } |
| 507 | |
| 508 | Drawable loadIconForResolveInfo(ResolveInfo ri) { |
| 509 | Drawable dr; |
| 510 | try { |
| 511 | if (ri.resolvePackageName != null && ri.icon != 0) { |
| 512 | dr = getIcon(mPm.getResourcesForApplication(ri.resolvePackageName), ri.icon); |
| 513 | if (dr != null) { |
Hyunyoung Song | dadb9e1 | 2017-08-24 18:08:35 -0700 | [diff] [blame] | 514 | return mIconFactory.getShadowedIcon(dr); |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 515 | } |
| 516 | } |
| 517 | final int iconRes = ri.getIconResource(); |
| 518 | if (iconRes != 0) { |
| 519 | dr = getIcon(mPm.getResourcesForApplication(ri.activityInfo.packageName), iconRes); |
| 520 | if (dr != null) { |
Hyunyoung Song | dadb9e1 | 2017-08-24 18:08:35 -0700 | [diff] [blame] | 521 | return mIconFactory.getShadowedIcon(dr); |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 522 | } |
| 523 | } |
| 524 | } catch (NameNotFoundException e) { |
| 525 | Log.e(TAG, "Couldn't find resources for package", e); |
| 526 | } |
Hyunyoung Song | dadb9e1 | 2017-08-24 18:08:35 -0700 | [diff] [blame] | 527 | return mIconFactory.getBadgedIcon(ri.activityInfo.applicationInfo); |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 528 | } |
| 529 | |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 530 | @Override |
| 531 | protected void onRestart() { |
| 532 | super.onRestart(); |
Dianne Hackborn | d44713a | 2012-04-30 16:34:46 -0700 | [diff] [blame] | 533 | if (!mRegistered) { |
| 534 | mPackageMonitor.register(this, getMainLooper(), false); |
| 535 | mRegistered = true; |
| 536 | } |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 537 | mAdapter.handlePackagesChanged(); |
Adam Powell | 88831a2 | 2014-11-20 18:17:00 -0800 | [diff] [blame] | 538 | if (mProfileView != null) { |
| 539 | bindProfileView(); |
| 540 | } |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | @Override |
| 544 | protected void onStop() { |
| 545 | super.onStop(); |
Dianne Hackborn | d44713a | 2012-04-30 16:34:46 -0700 | [diff] [blame] | 546 | if (mRegistered) { |
| 547 | mPackageMonitor.unregister(); |
| 548 | mRegistered = false; |
| 549 | } |
Wale Ogunwale | 9014e66 | 2016-03-19 14:55:46 -0700 | [diff] [blame] | 550 | final Intent intent = getIntent(); |
| 551 | if ((intent.getFlags() & FLAG_ACTIVITY_NEW_TASK) != 0 && !isVoiceInteraction() |
Jorim Jaggi | f631ef7 | 2017-02-24 13:49:47 +0100 | [diff] [blame] | 552 | && !mResolvingHome && !mRetainInOnStop) { |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 553 | // This resolver is in the unusual situation where it has been |
| 554 | // launched at the top of a new task. We don't let it be added |
| 555 | // to the recent tasks shown to the user, and we need to make sure |
| 556 | // that each time we are launched we get the correct launching |
| 557 | // uid (not re-using the same resolver from an old launching uid), |
| 558 | // so we will now finish ourself since being no longer visible, |
| 559 | // the user probably can't get back to us. |
| 560 | if (!isChangingConfigurations()) { |
| 561 | finish(); |
| 562 | } |
| 563 | } |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 564 | } |
| 565 | |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 566 | @Override |
Adam Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 567 | protected void onDestroy() { |
| 568 | super.onDestroy(); |
| 569 | if (!isChangingConfigurations() && mPickOptionRequest != null) { |
| 570 | mPickOptionRequest.cancel(); |
| 571 | } |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 572 | if (mPostListReadyRunnable != null) { |
| 573 | getMainThreadHandler().removeCallbacks(mPostListReadyRunnable); |
| 574 | mPostListReadyRunnable = null; |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 575 | } |
Kang Li | 38a6da64 | 2017-04-05 12:30:55 -0700 | [diff] [blame] | 576 | if (mAdapter != null && mAdapter.mResolverListController != null) { |
| 577 | mAdapter.mResolverListController.destroy(); |
| 578 | } |
Adam Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | @Override |
Adam Powell | 9bee466 | 2012-05-08 11:07:23 -0700 | [diff] [blame] | 582 | protected void onRestoreInstanceState(Bundle savedInstanceState) { |
| 583 | super.onRestoreInstanceState(savedInstanceState); |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 584 | resetButtonBar(); |
Adam Powell | 9bee466 | 2012-05-08 11:07:23 -0700 | [diff] [blame] | 585 | } |
| 586 | |
shafik | 0c7c5d5 | 2019-02-27 12:13:25 +0000 | [diff] [blame] | 587 | private boolean isHttpSchemeAndViewAction(Intent intent) { |
| 588 | return (IntentFilter.SCHEME_HTTP.equals(intent.getScheme()) |
| 589 | || IntentFilter.SCHEME_HTTPS.equals(intent.getScheme())) |
| 590 | && Intent.ACTION_VIEW.equals(intent.getAction()); |
| 591 | } |
| 592 | |
Sander Alewijnse | 6c9eee8 | 2014-07-17 10:03:31 +0100 | [diff] [blame] | 593 | private boolean hasManagedProfile() { |
| 594 | UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE); |
| 595 | if (userManager == null) { |
| 596 | return false; |
| 597 | } |
| 598 | |
| 599 | try { |
| 600 | List<UserInfo> profiles = userManager.getProfiles(getUserId()); |
| 601 | for (UserInfo userInfo : profiles) { |
| 602 | if (userInfo != null && userInfo.isManagedProfile()) { |
| 603 | return true; |
| 604 | } |
| 605 | } |
| 606 | } catch (SecurityException e) { |
| 607 | return false; |
| 608 | } |
| 609 | return false; |
| 610 | } |
| 611 | |
| 612 | private boolean supportsManagedProfiles(ResolveInfo resolveInfo) { |
| 613 | try { |
| 614 | ApplicationInfo appInfo = getPackageManager().getApplicationInfo( |
| 615 | resolveInfo.activityInfo.packageName, 0 /* default flags */); |
Adam Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 616 | return appInfo.targetSdkVersion >= Build.VERSION_CODES.LOLLIPOP; |
Sander Alewijnse | 6c9eee8 | 2014-07-17 10:03:31 +0100 | [diff] [blame] | 617 | } catch (NameNotFoundException e) { |
| 618 | return false; |
| 619 | } |
| 620 | } |
| 621 | |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 622 | private void setAlwaysButtonEnabled(boolean hasValidSelection, int checkedPos, |
| 623 | boolean filtered) { |
Nicolas Prevot | 5044988 | 2014-06-23 12:42:37 +0100 | [diff] [blame] | 624 | boolean enabled = false; |
| 625 | if (hasValidSelection) { |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 626 | ResolveInfo ri = mAdapter.resolveInfoForPosition(checkedPos, filtered); |
Hakan Seyalioglu | 5dbc819 | 2017-02-24 16:16:37 -0800 | [diff] [blame] | 627 | if (ri == null) { |
| 628 | Log.e(TAG, "Invalid position supplied to setAlwaysButtonEnabled"); |
| 629 | return; |
| 630 | } else if (ri.targetUserId != UserHandle.USER_CURRENT) { |
| 631 | Log.e(TAG, "Attempted to set selection to resolve info for another user"); |
| 632 | return; |
| 633 | } else { |
Nicolas Prevot | 5044988 | 2014-06-23 12:42:37 +0100 | [diff] [blame] | 634 | enabled = true; |
| 635 | } |
| 636 | } |
| 637 | mAlwaysButton.setEnabled(enabled); |
| 638 | } |
| 639 | |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 640 | public void onButtonClick(View v) { |
| 641 | final int id = v.getId(); |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 642 | int which = mAdapter.hasFilteredItem() |
| 643 | ? mAdapter.getFilteredPosition() |
| 644 | : mAdapterView.getCheckedItemPosition(); |
| 645 | boolean hasIndexBeenFiltered = !mAdapter.hasFilteredItem(); |
| 646 | if (id == R.id.button_app_settings) { |
| 647 | showSettingsForSelected(which, hasIndexBeenFiltered); |
| 648 | } else { |
| 649 | startSelected(which, id == R.id.button_always, hasIndexBeenFiltered); |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | private void showSettingsForSelected(int which, boolean hasIndexBeenFiltered) { |
| 654 | ResolveInfo ri = mAdapter.resolveInfoForPosition(which, hasIndexBeenFiltered); |
shafik | 34064c3 | 2019-03-06 15:42:52 +0000 | [diff] [blame] | 655 | Intent intent = new Intent(); |
| 656 | // For browsers, we open the Default Browser page |
| 657 | // For regular apps, we open the Open by Default page |
| 658 | if (ri.handleAllWebDataURI) { |
| 659 | intent.setAction(Intent.ACTION_MANAGE_DEFAULT_APP) |
| 660 | .putExtra(Intent.EXTRA_ROLE_NAME, RoleManager.ROLE_BROWSER); |
| 661 | } else { |
| 662 | intent.setAction(Settings.ACTION_APP_OPEN_BY_DEFAULT_SETTINGS) |
| 663 | .setData(Uri.fromParts("package", ri.activityInfo.packageName, null)) |
| 664 | .addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT); |
| 665 | } |
| 666 | startActivity(intent); |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 667 | } |
| 668 | |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 669 | public void startSelected(int which, boolean always, boolean hasIndexBeenFiltered) { |
Amith Yamasani | 07cd351 | 2013-09-18 13:16:00 -0700 | [diff] [blame] | 670 | if (isFinishing()) { |
| 671 | return; |
| 672 | } |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 673 | ResolveInfo ri = mAdapter.resolveInfoForPosition(which, hasIndexBeenFiltered); |
Sander Alewijnse | 86d35ba | 2015-02-04 15:14:53 +0000 | [diff] [blame] | 674 | if (mResolvingHome && hasManagedProfile() && !supportsManagedProfiles(ri)) { |
| 675 | Toast.makeText(this, String.format(getResources().getString( |
| 676 | com.android.internal.R.string.activity_resolver_work_profiles_support), |
| 677 | ri.activityInfo.loadLabel(getPackageManager()).toString()), |
| 678 | Toast.LENGTH_LONG).show(); |
| 679 | return; |
| 680 | } |
| 681 | |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 682 | TargetInfo target = mAdapter.targetInfoForPosition(which, hasIndexBeenFiltered); |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 683 | if (target == null) { |
| 684 | return; |
| 685 | } |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 686 | if (onTargetSelected(target, always)) { |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 687 | if (always && mSupportsAlwaysUseOption) { |
Clara Bayarri | fa902aa | 2016-04-13 14:45:08 +0100 | [diff] [blame] | 688 | MetricsLogger.action( |
| 689 | this, MetricsProto.MetricsEvent.ACTION_APP_DISAMBIG_ALWAYS); |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 690 | } else if (mSupportsAlwaysUseOption) { |
Clara Bayarri | fa902aa | 2016-04-13 14:45:08 +0100 | [diff] [blame] | 691 | MetricsLogger.action( |
| 692 | this, MetricsProto.MetricsEvent.ACTION_APP_DISAMBIG_JUST_ONCE); |
| 693 | } else { |
| 694 | MetricsLogger.action( |
| 695 | this, MetricsProto.MetricsEvent.ACTION_APP_DISAMBIG_TAP); |
| 696 | } |
| 697 | MetricsLogger.action(this, mAdapter.hasFilteredItem() |
| 698 | ? MetricsProto.MetricsEvent.ACTION_HIDE_APP_DISAMBIG_APP_FEATURED |
| 699 | : MetricsProto.MetricsEvent.ACTION_HIDE_APP_DISAMBIG_NONE_FEATURED); |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 700 | finish(); |
| 701 | } |
Mike Lockwood | 02eb874 | 2011-02-27 09:10:37 -0800 | [diff] [blame] | 702 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 703 | |
Adam Powell | e49d939 | 2014-07-17 18:45:19 -0700 | [diff] [blame] | 704 | /** |
| 705 | * Replace me in subclasses! |
| 706 | */ |
Nicolas Prevot | 0e2b73f | 2014-10-27 10:06:11 +0000 | [diff] [blame] | 707 | public Intent getReplacementIntent(ActivityInfo aInfo, Intent defIntent) { |
Adam Powell | e49d939 | 2014-07-17 18:45:19 -0700 | [diff] [blame] | 708 | return defIntent; |
| 709 | } |
| 710 | |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 711 | protected boolean onTargetSelected(TargetInfo target, boolean alwaysCheck) { |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 712 | final ResolveInfo ri = target.getResolveInfo(); |
| 713 | final Intent intent = target != null ? target.getResolvedIntent() : null; |
| 714 | |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 715 | if (intent != null && (mSupportsAlwaysUseOption || mAdapter.hasFilteredItem()) |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 716 | && mAdapter.mUnfilteredResolveList != null) { |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 717 | // Build a reasonable intent filter, based on what matched. |
| 718 | IntentFilter filter = new IntentFilter(); |
Henrik Engström | 3277cf1 | 2014-07-17 12:18:29 +0200 | [diff] [blame] | 719 | Intent filterIntent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 720 | |
Henrik Engström | 3277cf1 | 2014-07-17 12:18:29 +0200 | [diff] [blame] | 721 | if (intent.getSelector() != null) { |
| 722 | filterIntent = intent.getSelector(); |
| 723 | } else { |
| 724 | filterIntent = intent; |
| 725 | } |
| 726 | |
| 727 | String action = filterIntent.getAction(); |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 728 | if (action != null) { |
| 729 | filter.addAction(action); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 730 | } |
Henrik Engström | 3277cf1 | 2014-07-17 12:18:29 +0200 | [diff] [blame] | 731 | Set<String> categories = filterIntent.getCategories(); |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 732 | if (categories != null) { |
| 733 | for (String cat : categories) { |
| 734 | filter.addCategory(cat); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 735 | } |
| 736 | } |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 737 | filter.addCategory(Intent.CATEGORY_DEFAULT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 738 | |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 739 | int cat = ri.match & IntentFilter.MATCH_CATEGORY_MASK; |
Henrik Engström | 3277cf1 | 2014-07-17 12:18:29 +0200 | [diff] [blame] | 740 | Uri data = filterIntent.getData(); |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 741 | if (cat == IntentFilter.MATCH_CATEGORY_TYPE) { |
Henrik Engström | 3277cf1 | 2014-07-17 12:18:29 +0200 | [diff] [blame] | 742 | String mimeType = filterIntent.resolveType(this); |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 743 | if (mimeType != null) { |
| 744 | try { |
| 745 | filter.addDataType(mimeType); |
| 746 | } catch (IntentFilter.MalformedMimeTypeException e) { |
| 747 | Log.w("ResolverActivity", e); |
| 748 | filter = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 749 | } |
| 750 | } |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 751 | } |
| 752 | if (data != null && data.getScheme() != null) { |
| 753 | // We need the data specification if there was no type, |
| 754 | // OR if the scheme is not one of our magical "file:" |
| 755 | // or "content:" schemes (see IntentFilter for the reason). |
| 756 | if (cat != IntentFilter.MATCH_CATEGORY_TYPE |
| 757 | || (!"file".equals(data.getScheme()) |
| 758 | && !"content".equals(data.getScheme()))) { |
| 759 | filter.addDataScheme(data.getScheme()); |
| 760 | |
| 761 | // Look through the resolved filter to determine which part |
| 762 | // of it matched the original Intent. |
| 763 | Iterator<PatternMatcher> pIt = ri.filter.schemeSpecificPartsIterator(); |
| 764 | if (pIt != null) { |
| 765 | String ssp = data.getSchemeSpecificPart(); |
| 766 | while (ssp != null && pIt.hasNext()) { |
| 767 | PatternMatcher p = pIt.next(); |
| 768 | if (p.match(ssp)) { |
| 769 | filter.addDataSchemeSpecificPart(p.getPath(), p.getType()); |
| 770 | break; |
| 771 | } |
Dianne Hackborn | df1c0bf | 2013-06-12 16:21:38 -0700 | [diff] [blame] | 772 | } |
| 773 | } |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 774 | Iterator<IntentFilter.AuthorityEntry> aIt = ri.filter.authoritiesIterator(); |
| 775 | if (aIt != null) { |
| 776 | while (aIt.hasNext()) { |
| 777 | IntentFilter.AuthorityEntry a = aIt.next(); |
| 778 | if (a.match(data) >= 0) { |
| 779 | int port = a.getPort(); |
| 780 | filter.addDataAuthority(a.getHost(), |
| 781 | port >= 0 ? Integer.toString(port) : null); |
| 782 | break; |
| 783 | } |
| 784 | } |
| 785 | } |
| 786 | pIt = ri.filter.pathsIterator(); |
| 787 | if (pIt != null) { |
| 788 | String path = data.getPath(); |
| 789 | while (path != null && pIt.hasNext()) { |
| 790 | PatternMatcher p = pIt.next(); |
| 791 | if (p.match(path)) { |
| 792 | filter.addDataPath(p.getPath(), p.getType()); |
| 793 | break; |
| 794 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 795 | } |
| 796 | } |
| 797 | } |
| 798 | } |
| 799 | |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 800 | if (filter != null) { |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 801 | final int N = mAdapter.mUnfilteredResolveList.size(); |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 802 | ComponentName[] set; |
| 803 | // If we don't add back in the component for forwarding the intent to a managed |
| 804 | // profile, the preferred activity may not be updated correctly (as the set of |
| 805 | // components we tell it we knew about will have changed). |
| 806 | final boolean needToAddBackProfileForwardingComponent |
| 807 | = mAdapter.mOtherProfile != null; |
| 808 | if (!needToAddBackProfileForwardingComponent) { |
| 809 | set = new ComponentName[N]; |
| 810 | } else { |
| 811 | set = new ComponentName[N + 1]; |
| 812 | } |
| 813 | |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 814 | int bestMatch = 0; |
| 815 | for (int i=0; i<N; i++) { |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 816 | ResolveInfo r = mAdapter.mUnfilteredResolveList.get(i).getResolveInfoAt(0); |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 817 | set[i] = new ComponentName(r.activityInfo.packageName, |
| 818 | r.activityInfo.name); |
| 819 | if (r.match > bestMatch) bestMatch = r.match; |
| 820 | } |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 821 | |
| 822 | if (needToAddBackProfileForwardingComponent) { |
| 823 | set[N] = mAdapter.mOtherProfile.getResolvedComponentName(); |
| 824 | final int otherProfileMatch = mAdapter.mOtherProfile.getResolveInfo().match; |
| 825 | if (otherProfileMatch > bestMatch) bestMatch = otherProfileMatch; |
| 826 | } |
| 827 | |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 828 | if (alwaysCheck) { |
Fabrice Di Meglio | 3453e08 | 2015-05-11 17:46:23 -0700 | [diff] [blame] | 829 | final int userId = getUserId(); |
| 830 | final PackageManager pm = getPackageManager(); |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 831 | |
| 832 | // Set the preferred Activity |
| 833 | pm.addPreferredActivity(filter, bestMatch, set, intent.getComponent()); |
| 834 | |
Fabrice Di Meglio | 3453e08 | 2015-05-11 17:46:23 -0700 | [diff] [blame] | 835 | if (ri.handleAllWebDataURI) { |
| 836 | // Set default Browser if needed |
Jeff Sharkey | e06b4d1 | 2016-01-06 14:51:50 -0700 | [diff] [blame] | 837 | final String packageName = pm.getDefaultBrowserPackageNameAsUser(userId); |
Fabrice Di Meglio | 3453e08 | 2015-05-11 17:46:23 -0700 | [diff] [blame] | 838 | if (TextUtils.isEmpty(packageName)) { |
Jeff Sharkey | e06b4d1 | 2016-01-06 14:51:50 -0700 | [diff] [blame] | 839 | pm.setDefaultBrowserPackageNameAsUser(ri.activityInfo.packageName, userId); |
Fabrice Di Meglio | 3453e08 | 2015-05-11 17:46:23 -0700 | [diff] [blame] | 840 | } |
| 841 | } else { |
| 842 | // Update Domain Verification status |
| 843 | ComponentName cn = intent.getComponent(); |
| 844 | String packageName = cn.getPackageName(); |
| 845 | String dataScheme = (data != null) ? data.getScheme() : null; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 846 | |
Fabrice Di Meglio | 3453e08 | 2015-05-11 17:46:23 -0700 | [diff] [blame] | 847 | boolean isHttpOrHttps = (dataScheme != null) && |
| 848 | (dataScheme.equals(IntentFilter.SCHEME_HTTP) || |
| 849 | dataScheme.equals(IntentFilter.SCHEME_HTTPS)); |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 850 | |
Fabrice Di Meglio | 3453e08 | 2015-05-11 17:46:23 -0700 | [diff] [blame] | 851 | boolean isViewAction = (action != null) && action.equals(Intent.ACTION_VIEW); |
| 852 | boolean hasCategoryBrowsable = (categories != null) && |
| 853 | categories.contains(Intent.CATEGORY_BROWSABLE); |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 854 | |
Fabrice Di Meglio | 3453e08 | 2015-05-11 17:46:23 -0700 | [diff] [blame] | 855 | if (isHttpOrHttps && isViewAction && hasCategoryBrowsable) { |
Jeff Sharkey | e06b4d1 | 2016-01-06 14:51:50 -0700 | [diff] [blame] | 856 | pm.updateIntentVerificationStatusAsUser(packageName, |
Fabrice Di Meglio | 3453e08 | 2015-05-11 17:46:23 -0700 | [diff] [blame] | 857 | PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS, |
| 858 | userId); |
| 859 | } |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 860 | } |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 861 | } else { |
| 862 | try { |
Hakan Seyalioglu | 9149dca | 2017-01-17 12:20:01 -0800 | [diff] [blame] | 863 | mAdapter.mResolverListController.setLastChosen(intent, filter, bestMatch); |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 864 | } catch (RemoteException re) { |
| 865 | Log.d(TAG, "Error calling setLastChosenActivity\n" + re); |
| 866 | } |
Amith Yamasani | e9ecc8b | 2013-08-22 11:16:27 -0700 | [diff] [blame] | 867 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 868 | } |
| 869 | } |
| 870 | |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 871 | if (target != null) { |
| 872 | safelyStartActivity(target); |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 873 | } |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 874 | return true; |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 875 | } |
| 876 | |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 877 | public void safelyStartActivity(TargetInfo cti) { |
Jeff Sharkey | 2b9eb89 | 2016-02-16 09:21:51 -0700 | [diff] [blame] | 878 | // We're dispatching intents that might be coming from legacy apps, so |
| 879 | // don't kill ourselves. |
| 880 | StrictMode.disableDeathOnFileUriExposure(); |
| 881 | try { |
| 882 | safelyStartActivityInternal(cti); |
| 883 | } finally { |
| 884 | StrictMode.enableDeathOnFileUriExposure(); |
| 885 | } |
| 886 | } |
| 887 | |
| 888 | private void safelyStartActivityInternal(TargetInfo cti) { |
Sander Alewijnse | f654533 | 2014-10-31 12:39:02 +0000 | [diff] [blame] | 889 | // If needed, show that intent is forwarded |
| 890 | // from managed profile to owner or other way around. |
| 891 | if (mProfileSwitchMessageId != -1) { |
| 892 | Toast.makeText(this, getString(mProfileSwitchMessageId), Toast.LENGTH_LONG).show(); |
| 893 | } |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 894 | if (!mSafeForwardingMode) { |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 895 | if (cti.start(this, null)) { |
| 896 | onActivityStarted(cti); |
| 897 | } |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 898 | return; |
| 899 | } |
| 900 | try { |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 901 | if (cti.startAsCaller(this, null, UserHandle.USER_NULL)) { |
| 902 | onActivityStarted(cti); |
| 903 | } |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 904 | } catch (RuntimeException e) { |
| 905 | String launchedFromPackage; |
| 906 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 907 | launchedFromPackage = ActivityTaskManager.getService().getLaunchedFromPackage( |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 908 | getActivityToken()); |
| 909 | } catch (RemoteException e2) { |
| 910 | launchedFromPackage = "??"; |
| 911 | } |
| 912 | Slog.wtf(TAG, "Unable to launch as uid " + mLaunchedFromUid |
| 913 | + " package " + launchedFromPackage + ", while running in " |
| 914 | + ActivityThread.currentProcessName(), e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 915 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 916 | } |
| 917 | |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 918 | |
| 919 | boolean startAsCallerImpl(Intent intent, Bundle options, boolean ignoreTargetSecurity, |
| 920 | int userId) { |
| 921 | // Pass intent to delegate chooser activity with permission token. |
| 922 | // TODO: This should move to a trampoline Activity in the system when the ChooserActivity |
| 923 | // moves into systemui |
| 924 | try { |
| 925 | // TODO: Once this is a small springboard activity, it can move off the UI process |
| 926 | // and we can move the request method to ActivityManagerInternal. |
| 927 | IBinder permissionToken = ActivityTaskManager.getService() |
| 928 | .requestStartActivityPermissionToken(getActivityToken()); |
| 929 | final Intent chooserIntent = new Intent(); |
| 930 | final ComponentName delegateActivity = ComponentName.unflattenFromString( |
| 931 | Resources.getSystem().getString(R.string.config_chooserActivity)); |
| 932 | chooserIntent.setClassName(delegateActivity.getPackageName(), |
| 933 | delegateActivity.getClassName()); |
| 934 | chooserIntent.putExtra(ActivityTaskManager.EXTRA_PERMISSION_TOKEN, permissionToken); |
| 935 | |
| 936 | // TODO: These extras will change as chooser activity moves into systemui |
| 937 | chooserIntent.putExtra(Intent.EXTRA_INTENT, intent); |
| 938 | chooserIntent.putExtra(ActivityTaskManager.EXTRA_OPTIONS, options); |
| 939 | chooserIntent.putExtra(ActivityTaskManager.EXTRA_IGNORE_TARGET_SECURITY, |
| 940 | ignoreTargetSecurity); |
| 941 | chooserIntent.putExtra(Intent.EXTRA_USER_ID, userId); |
Alison Cichowlas | 7b6f3b6 | 2018-12-07 09:06:57 -0500 | [diff] [blame] | 942 | chooserIntent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT |
| 943 | | Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP); |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 944 | startActivity(chooserIntent); |
| 945 | } catch (RemoteException e) { |
| 946 | Log.e(TAG, e.toString()); |
| 947 | } |
| 948 | return true; |
| 949 | } |
| 950 | |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 951 | public void onActivityStarted(TargetInfo cti) { |
Adam Powell | 0b3c112 | 2014-10-09 12:50:14 -0700 | [diff] [blame] | 952 | // Do nothing |
| 953 | } |
| 954 | |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 955 | public boolean shouldGetActivityMetadata() { |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 956 | return false; |
| 957 | } |
| 958 | |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 959 | public boolean shouldAutoLaunchSingleChoice(TargetInfo target) { |
Adam Powell | 39e94eb | 2015-09-08 17:01:49 -0700 | [diff] [blame] | 960 | return true; |
| 961 | } |
| 962 | |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 963 | public void showTargetDetails(ResolveInfo ri) { |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 964 | Intent in = new Intent().setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS) |
Adam Powell | 0fc5b2b | 2012-07-18 18:20:29 -0700 | [diff] [blame] | 965 | .setData(Uri.fromParts("package", ri.activityInfo.packageName, null)) |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 966 | .addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT); |
Amith Yamasani | 203a2f4 | 2012-10-03 20:16:40 -0700 | [diff] [blame] | 967 | startActivity(in); |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 968 | } |
| 969 | |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 970 | public ResolveListAdapter createAdapter(Context context, List<Intent> payloadIntents, |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 971 | Intent[] initialIntents, List<ResolveInfo> rList, int launchedFromUid, |
| 972 | boolean filterLastUsed) { |
| 973 | return new ResolveListAdapter(context, payloadIntents, initialIntents, rList, |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 974 | launchedFromUid, filterLastUsed, createListController()); |
| 975 | } |
| 976 | |
| 977 | @VisibleForTesting |
| 978 | protected ResolverListController createListController() { |
| 979 | return new ResolverListController( |
| 980 | this, |
| 981 | mPm, |
| 982 | getTargetIntent(), |
| 983 | getReferrerPackageName(), |
| 984 | mLaunchedFromUid); |
Adam Powell | 88831a2 | 2014-11-20 18:17:00 -0800 | [diff] [blame] | 985 | } |
| 986 | |
Adam Powell | 39e94eb | 2015-09-08 17:01:49 -0700 | [diff] [blame] | 987 | /** |
| 988 | * Returns true if the activity is finishing and creation should halt |
| 989 | */ |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 990 | public boolean configureContentView(List<Intent> payloadIntents, Intent[] initialIntents, |
Hakan Seyalioglu | 3355012 | 2017-01-06 19:54:43 -0800 | [diff] [blame] | 991 | List<ResolveInfo> rList) { |
Dianne Hackborn | 57dd737 | 2015-07-27 18:11:14 -0700 | [diff] [blame] | 992 | // The last argument of createAdapter is whether to do special handling |
| 993 | // of the last used choice to highlight it in the list. We need to always |
| 994 | // turn this off when running under voice interaction, since it results in |
| 995 | // a more complicated UI that the current voice interaction flow is not able |
| 996 | // to handle. |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 997 | mAdapter = createAdapter(this, payloadIntents, initialIntents, rList, |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 998 | mLaunchedFromUid, mSupportsAlwaysUseOption && !isVoiceInteraction()); |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 999 | boolean rebuildCompleted = mAdapter.rebuildList(); |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1000 | |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 1001 | if (useLayoutWithDefault()) { |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1002 | mLayoutId = R.layout.resolver_list_with_default; |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1003 | } else { |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1004 | mLayoutId = getLayoutResource(); |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1005 | } |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 1006 | setContentView(mLayoutId); |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1007 | |
Adam Powell | 5007735 | 2015-05-26 18:01:55 -0700 | [diff] [blame] | 1008 | int count = mAdapter.getUnfilteredCount(); |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1009 | |
| 1010 | // We only rebuild asynchronously when we have multiple elements to sort. In the case where |
| 1011 | // we're already done, we can check if we should auto-launch immediately. |
| 1012 | if (rebuildCompleted) { |
| 1013 | if (count == 1 && mAdapter.getOtherProfile() == null) { |
| 1014 | // Only one target, so we're a candidate to auto-launch! |
| 1015 | final TargetInfo target = mAdapter.targetInfoForPosition(0, false); |
| 1016 | if (shouldAutoLaunchSingleChoice(target)) { |
| 1017 | safelyStartActivity(target); |
| 1018 | mPackageMonitor.unregister(); |
| 1019 | mRegistered = false; |
| 1020 | finish(); |
| 1021 | return true; |
| 1022 | } |
Jeff Sharkey | cc2ae6b4 | 2015-09-29 13:04:46 -0700 | [diff] [blame] | 1023 | } |
| 1024 | } |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1025 | |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 1026 | |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 1027 | mAdapterView = findViewById(R.id.resolver_list); |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 1028 | |
| 1029 | if (count == 0 && mAdapter.mPlaceholderCount == 0) { |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 1030 | final TextView emptyView = findViewById(R.id.empty); |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 1031 | emptyView.setVisibility(View.VISIBLE); |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1032 | mAdapterView.setVisibility(View.GONE); |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 1033 | } else { |
| 1034 | mAdapterView.setVisibility(View.VISIBLE); |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 1035 | onPrepareAdapterView(mAdapterView, mAdapter); |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1036 | } |
Adam Powell | 39e94eb | 2015-09-08 17:01:49 -0700 | [diff] [blame] | 1037 | return false; |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1038 | } |
| 1039 | |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 1040 | public void onPrepareAdapterView(AbsListView adapterView, ResolveListAdapter adapter) { |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1041 | final boolean useHeader = adapter.hasFilteredItem(); |
| 1042 | final ListView listView = adapterView instanceof ListView ? (ListView) adapterView : null; |
| 1043 | |
| 1044 | adapterView.setAdapter(mAdapter); |
| 1045 | |
| 1046 | final ItemClickListener listener = new ItemClickListener(); |
| 1047 | adapterView.setOnItemClickListener(listener); |
| 1048 | adapterView.setOnItemLongClickListener(listener); |
| 1049 | |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 1050 | if (mSupportsAlwaysUseOption || mUseLayoutForBrowsables) { |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1051 | listView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE); |
| 1052 | } |
| 1053 | |
Hakan Seyalioglu | 3355012 | 2017-01-06 19:54:43 -0800 | [diff] [blame] | 1054 | // In case this method is called again (due to activity recreation), avoid adding a new |
| 1055 | // header if one is already present. |
| 1056 | if (useHeader && listView != null && listView.getHeaderViewsCount() == 0) { |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1057 | listView.addHeaderView(LayoutInflater.from(this).inflate( |
| 1058 | R.layout.resolver_different_item_header, listView, false)); |
| 1059 | } |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1060 | } |
| 1061 | |
Matt Pietal | 2603840 | 2019-01-08 07:29:34 -0500 | [diff] [blame] | 1062 | /** |
| 1063 | * Configure the area above the app selection list (title, content preview, etc). |
| 1064 | */ |
| 1065 | public void setHeader() { |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 1066 | if (mAdapter.getCount() == 0 && mAdapter.mPlaceholderCount == 0) { |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 1067 | final TextView titleView = findViewById(R.id.title); |
Hakan Seyalioglu | 3355012 | 2017-01-06 19:54:43 -0800 | [diff] [blame] | 1068 | if (titleView != null) { |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 1069 | titleView.setVisibility(View.GONE); |
Hakan Seyalioglu | 3355012 | 2017-01-06 19:54:43 -0800 | [diff] [blame] | 1070 | } |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | CharSequence title = mTitle != null |
| 1074 | ? mTitle |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 1075 | : getTitleForAction(getTargetIntent(), mDefaultTitleResId); |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 1076 | |
| 1077 | if (!TextUtils.isEmpty(title)) { |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 1078 | final TextView titleView = findViewById(R.id.title); |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 1079 | if (titleView != null) { |
| 1080 | titleView.setText(title); |
| 1081 | } |
| 1082 | setTitle(title); |
Hakan Seyalioglu | 3355012 | 2017-01-06 19:54:43 -0800 | [diff] [blame] | 1083 | } |
| 1084 | |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 1085 | final ImageView iconView = findViewById(R.id.icon); |
Hakan Seyalioglu | 3355012 | 2017-01-06 19:54:43 -0800 | [diff] [blame] | 1086 | final DisplayResolveInfo iconInfo = mAdapter.getFilteredItem(); |
| 1087 | if (iconView != null && iconInfo != null) { |
| 1088 | new LoadIconIntoViewTask(iconInfo, iconView).execute(); |
| 1089 | } |
| 1090 | } |
| 1091 | |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 1092 | private void resetButtonBar() { |
| 1093 | if (!mSupportsAlwaysUseOption && !mUseLayoutForBrowsables) { |
| 1094 | return; |
| 1095 | } |
| 1096 | final ViewGroup buttonLayout = findViewById(R.id.button_bar); |
| 1097 | if (buttonLayout != null) { |
| 1098 | buttonLayout.setVisibility(View.VISIBLE); |
| 1099 | mOnceButton = (Button) buttonLayout.findViewById(R.id.button_once); |
| 1100 | mSettingsButton = (Button) buttonLayout.findViewById(R.id.button_app_settings); |
| 1101 | mAlwaysButton = (Button) buttonLayout.findViewById(R.id.button_always); |
| 1102 | |
| 1103 | if (mUseLayoutForBrowsables) { |
| 1104 | resetSettingsOrOnceButtonBar(); |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 1105 | } else { |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 1106 | resetAlwaysOrOnceButtonBar(); |
Hakan Seyalioglu | 3355012 | 2017-01-06 19:54:43 -0800 | [diff] [blame] | 1107 | } |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 1108 | } else { |
| 1109 | Log.e(TAG, "Layout unexpectedly does not have a button bar"); |
| 1110 | } |
| 1111 | } |
| 1112 | |
| 1113 | private void resetSettingsOrOnceButtonBar() { |
| 1114 | //unsetting always button |
| 1115 | mAlwaysButton.setVisibility(View.GONE); |
| 1116 | |
| 1117 | // When the items load in, if an item was already selected, |
| 1118 | // enable the buttons |
| 1119 | if (mAdapterView != null |
| 1120 | && mAdapterView.getCheckedItemPosition() != ListView.INVALID_POSITION) { |
| 1121 | mSettingsButton.setEnabled(true); |
| 1122 | mOnceButton.setEnabled(true); |
| 1123 | } |
| 1124 | } |
| 1125 | |
| 1126 | private void resetAlwaysOrOnceButtonBar() { |
| 1127 | // This check needs to be made because layout with default |
| 1128 | // doesn't have a settings button |
| 1129 | if (mSettingsButton != null) { |
| 1130 | //unsetting always button |
| 1131 | mSettingsButton.setVisibility(View.GONE); |
| 1132 | mSettingsButton = null; |
Hakan Seyalioglu | 3355012 | 2017-01-06 19:54:43 -0800 | [diff] [blame] | 1133 | } |
| 1134 | |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 1135 | if (useLayoutWithDefault() |
| 1136 | && mAdapter.getFilteredPosition() != ListView.INVALID_POSITION) { |
Hakan Seyalioglu | 3355012 | 2017-01-06 19:54:43 -0800 | [diff] [blame] | 1137 | setAlwaysButtonEnabled(true, mAdapter.getFilteredPosition(), false); |
| 1138 | mOnceButton.setEnabled(true); |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 1139 | return; |
| 1140 | } |
| 1141 | |
| 1142 | // When the items load in, if an item was already selected, enable the buttons |
| 1143 | if (mAdapterView != null |
| 1144 | && mAdapterView.getCheckedItemPosition() != ListView.INVALID_POSITION) { |
| 1145 | setAlwaysButtonEnabled(true, mAdapterView.getCheckedItemPosition(), true); |
| 1146 | mOnceButton.setEnabled(true); |
Hakan Seyalioglu | 3355012 | 2017-01-06 19:54:43 -0800 | [diff] [blame] | 1147 | } |
| 1148 | } |
| 1149 | |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 1150 | private boolean useLayoutWithDefault() { |
| 1151 | return mSupportsAlwaysUseOption && mAdapter.hasFilteredItem(); |
| 1152 | } |
| 1153 | |
Adam Powell | c412be6 | 2015-06-24 13:54:10 -0700 | [diff] [blame] | 1154 | /** |
Jorim Jaggi | f631ef7 | 2017-02-24 13:49:47 +0100 | [diff] [blame] | 1155 | * If {@code retainInOnStop} is set to true, we will not finish ourselves when onStop gets |
| 1156 | * called and we are launched in a new task. |
| 1157 | */ |
| 1158 | protected void setRetainInOnStop(boolean retainInOnStop) { |
| 1159 | mRetainInOnStop = retainInOnStop; |
| 1160 | } |
| 1161 | |
| 1162 | /** |
Adam Powell | c412be6 | 2015-06-24 13:54:10 -0700 | [diff] [blame] | 1163 | * Check a simple match for the component of two ResolveInfos. |
| 1164 | */ |
| 1165 | static boolean resolveInfoMatch(ResolveInfo lhs, ResolveInfo rhs) { |
| 1166 | return lhs == null ? rhs == null |
| 1167 | : lhs.activityInfo == null ? rhs.activityInfo == null |
| 1168 | : Objects.equals(lhs.activityInfo.name, rhs.activityInfo.name) |
| 1169 | && Objects.equals(lhs.activityInfo.packageName, rhs.activityInfo.packageName); |
| 1170 | } |
| 1171 | |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 1172 | public final class DisplayResolveInfo implements TargetInfo { |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1173 | private final ResolveInfo mResolveInfo; |
| 1174 | private final CharSequence mDisplayLabel; |
| 1175 | private Drawable mDisplayIcon; |
Adam Powell | 00f4aad | 2015-09-17 13:38:16 -0700 | [diff] [blame] | 1176 | private Drawable mBadge; |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1177 | private final CharSequence mExtendedInfo; |
| 1178 | private final Intent mResolvedIntent; |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1179 | private final List<Intent> mSourceIntents = new ArrayList<>(); |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 1180 | private boolean mPinned; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1181 | |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 1182 | public DisplayResolveInfo(Intent originalIntent, ResolveInfo pri, CharSequence pLabel, |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 1183 | CharSequence pInfo, Intent pOrigIntent) { |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1184 | mSourceIntents.add(originalIntent); |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1185 | mResolveInfo = pri; |
| 1186 | mDisplayLabel = pLabel; |
| 1187 | mExtendedInfo = pInfo; |
| 1188 | |
| 1189 | final Intent intent = new Intent(pOrigIntent != null ? pOrigIntent : |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1190 | getReplacementIntent(pri.activityInfo, getTargetIntent())); |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1191 | intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT |
| 1192 | | Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP); |
| 1193 | final ActivityInfo ai = mResolveInfo.activityInfo; |
| 1194 | intent.setComponent(new ComponentName(ai.applicationInfo.packageName, ai.name)); |
| 1195 | |
| 1196 | mResolvedIntent = intent; |
| 1197 | } |
| 1198 | |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1199 | private DisplayResolveInfo(DisplayResolveInfo other, Intent fillInIntent, int flags) { |
| 1200 | mSourceIntents.addAll(other.getAllSourceIntents()); |
| 1201 | mResolveInfo = other.mResolveInfo; |
| 1202 | mDisplayLabel = other.mDisplayLabel; |
| 1203 | mDisplayIcon = other.mDisplayIcon; |
| 1204 | mExtendedInfo = other.mExtendedInfo; |
| 1205 | mResolvedIntent = new Intent(other.mResolvedIntent); |
| 1206 | mResolvedIntent.fillIn(fillInIntent, flags); |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 1207 | mPinned = other.mPinned; |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1208 | } |
| 1209 | |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1210 | public ResolveInfo getResolveInfo() { |
| 1211 | return mResolveInfo; |
| 1212 | } |
| 1213 | |
| 1214 | public CharSequence getDisplayLabel() { |
| 1215 | return mDisplayLabel; |
| 1216 | } |
| 1217 | |
| 1218 | public Drawable getDisplayIcon() { |
| 1219 | return mDisplayIcon; |
| 1220 | } |
| 1221 | |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1222 | public Drawable getBadgeIcon() { |
Adam Powell | 00f4aad | 2015-09-17 13:38:16 -0700 | [diff] [blame] | 1223 | // We only expose a badge if we have extended info. |
| 1224 | // The badge is a higher-priority disambiguation signal |
| 1225 | // but we don't need one if we wouldn't show extended info at all. |
| 1226 | if (TextUtils.isEmpty(getExtendedInfo())) { |
| 1227 | return null; |
| 1228 | } |
| 1229 | |
| 1230 | if (mBadge == null && mResolveInfo != null && mResolveInfo.activityInfo != null |
| 1231 | && mResolveInfo.activityInfo.applicationInfo != null) { |
| 1232 | if (mResolveInfo.activityInfo.icon == 0 || mResolveInfo.activityInfo.icon |
| 1233 | == mResolveInfo.activityInfo.applicationInfo.icon) { |
| 1234 | // Badging an icon with exactly the same icon is silly. |
| 1235 | // If the activityInfo icon resid is 0 it will fall back |
| 1236 | // to the application's icon, making it a match. |
| 1237 | return null; |
| 1238 | } |
| 1239 | mBadge = mResolveInfo.activityInfo.applicationInfo.loadIcon(mPm); |
| 1240 | } |
| 1241 | return mBadge; |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1242 | } |
| 1243 | |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1244 | @Override |
Alan Viverette | ce5d92c | 2015-07-31 16:46:56 -0400 | [diff] [blame] | 1245 | public CharSequence getBadgeContentDescription() { |
| 1246 | return null; |
| 1247 | } |
| 1248 | |
| 1249 | @Override |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1250 | public TargetInfo cloneFilledIn(Intent fillInIntent, int flags) { |
| 1251 | return new DisplayResolveInfo(this, fillInIntent, flags); |
| 1252 | } |
| 1253 | |
| 1254 | @Override |
| 1255 | public List<Intent> getAllSourceIntents() { |
| 1256 | return mSourceIntents; |
| 1257 | } |
| 1258 | |
| 1259 | public void addAlternateSourceIntent(Intent alt) { |
| 1260 | mSourceIntents.add(alt); |
| 1261 | } |
| 1262 | |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1263 | public void setDisplayIcon(Drawable icon) { |
| 1264 | mDisplayIcon = icon; |
| 1265 | } |
| 1266 | |
| 1267 | public boolean hasDisplayIcon() { |
| 1268 | return mDisplayIcon != null; |
| 1269 | } |
| 1270 | |
| 1271 | public CharSequence getExtendedInfo() { |
| 1272 | return mExtendedInfo; |
| 1273 | } |
| 1274 | |
| 1275 | public Intent getResolvedIntent() { |
| 1276 | return mResolvedIntent; |
| 1277 | } |
| 1278 | |
| 1279 | @Override |
| 1280 | public ComponentName getResolvedComponentName() { |
| 1281 | return new ComponentName(mResolveInfo.activityInfo.packageName, |
| 1282 | mResolveInfo.activityInfo.name); |
| 1283 | } |
| 1284 | |
| 1285 | @Override |
| 1286 | public boolean start(Activity activity, Bundle options) { |
| 1287 | activity.startActivity(mResolvedIntent, options); |
| 1288 | return true; |
| 1289 | } |
| 1290 | |
| 1291 | @Override |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1292 | public boolean startAsCaller(ResolverActivity activity, Bundle options, int userId) { |
Alison Cichowlas | 4691ed4 | 2018-11-13 15:59:55 -0500 | [diff] [blame] | 1293 | |
| 1294 | if (mEnableChooserDelegate) { |
| 1295 | return activity.startAsCallerImpl(mResolvedIntent, options, false, userId); |
| 1296 | } else { |
| 1297 | activity.startActivityAsCaller(mResolvedIntent, options, null, false, userId); |
| 1298 | return true; |
| 1299 | } |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1300 | } |
| 1301 | |
| 1302 | @Override |
| 1303 | public boolean startAsUser(Activity activity, Bundle options, UserHandle user) { |
| 1304 | activity.startActivityAsUser(mResolvedIntent, options, user); |
| 1305 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1306 | } |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 1307 | |
| 1308 | @Override |
| 1309 | public boolean isPinned() { |
| 1310 | return mPinned; |
| 1311 | } |
| 1312 | |
| 1313 | public void setPinned(boolean pinned) { |
| 1314 | mPinned = pinned; |
| 1315 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1316 | } |
| 1317 | |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1318 | /** |
| 1319 | * A single target as represented in the chooser. |
| 1320 | */ |
| 1321 | public interface TargetInfo { |
| 1322 | /** |
| 1323 | * Get the resolved intent that represents this target. Note that this may not be the |
| 1324 | * intent that will be launched by calling one of the <code>start</code> methods provided; |
| 1325 | * this is the intent that will be credited with the launch. |
| 1326 | * |
| 1327 | * @return the resolved intent for this target |
| 1328 | */ |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 1329 | Intent getResolvedIntent(); |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1330 | |
| 1331 | /** |
| 1332 | * Get the resolved component name that represents this target. Note that this may not |
| 1333 | * be the component that will be directly launched by calling one of the <code>start</code> |
| 1334 | * methods provided; this is the component that will be credited with the launch. |
| 1335 | * |
| 1336 | * @return the resolved ComponentName for this target |
| 1337 | */ |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 1338 | ComponentName getResolvedComponentName(); |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1339 | |
| 1340 | /** |
| 1341 | * Start the activity referenced by this target. |
| 1342 | * |
| 1343 | * @param activity calling Activity performing the launch |
| 1344 | * @param options ActivityOptions bundle |
| 1345 | * @return true if the start completed successfully |
| 1346 | */ |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 1347 | boolean start(Activity activity, Bundle options); |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1348 | |
| 1349 | /** |
| 1350 | * Start the activity referenced by this target as if the ResolverActivity's caller |
| 1351 | * was performing the start operation. |
| 1352 | * |
| 1353 | * @param activity calling Activity (actually) performing the launch |
| 1354 | * @param options ActivityOptions bundle |
| 1355 | * @param userId userId to start as or {@link UserHandle#USER_NULL} for activity's caller |
| 1356 | * @return true if the start completed successfully |
| 1357 | */ |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1358 | boolean startAsCaller(ResolverActivity activity, Bundle options, int userId); |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1359 | |
| 1360 | /** |
| 1361 | * Start the activity referenced by this target as a given user. |
| 1362 | * |
| 1363 | * @param activity calling activity performing the launch |
| 1364 | * @param options ActivityOptions bundle |
| 1365 | * @param user handle for the user to start the activity as |
| 1366 | * @return true if the start completed successfully |
| 1367 | */ |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 1368 | boolean startAsUser(Activity activity, Bundle options, UserHandle user); |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1369 | |
| 1370 | /** |
| 1371 | * Return the ResolveInfo about how and why this target matched the original query |
| 1372 | * for available targets. |
| 1373 | * |
| 1374 | * @return ResolveInfo representing this target's match |
| 1375 | */ |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 1376 | ResolveInfo getResolveInfo(); |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1377 | |
| 1378 | /** |
| 1379 | * Return the human-readable text label for this target. |
| 1380 | * |
| 1381 | * @return user-visible target label |
| 1382 | */ |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 1383 | CharSequence getDisplayLabel(); |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1384 | |
| 1385 | /** |
| 1386 | * Return any extended info for this target. This may be used to disambiguate |
| 1387 | * otherwise identical targets. |
| 1388 | * |
| 1389 | * @return human-readable disambig string or null if none present |
| 1390 | */ |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 1391 | CharSequence getExtendedInfo(); |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1392 | |
| 1393 | /** |
| 1394 | * @return The drawable that should be used to represent this target |
| 1395 | */ |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 1396 | Drawable getDisplayIcon(); |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1397 | |
| 1398 | /** |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1399 | * @return The (small) icon to badge the target with |
| 1400 | */ |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 1401 | Drawable getBadgeIcon(); |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1402 | |
| 1403 | /** |
Alan Viverette | ce5d92c | 2015-07-31 16:46:56 -0400 | [diff] [blame] | 1404 | * @return The content description for the badge icon |
| 1405 | */ |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 1406 | CharSequence getBadgeContentDescription(); |
Alan Viverette | ce5d92c | 2015-07-31 16:46:56 -0400 | [diff] [blame] | 1407 | |
| 1408 | /** |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1409 | * Clone this target with the given fill-in information. |
| 1410 | */ |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 1411 | TargetInfo cloneFilledIn(Intent fillInIntent, int flags); |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1412 | |
| 1413 | /** |
| 1414 | * @return the list of supported source intents deduped against this single target |
| 1415 | */ |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 1416 | List<Intent> getAllSourceIntents(); |
| 1417 | |
| 1418 | /** |
| 1419 | * @return true if this target should be pinned to the front by the request of the user |
| 1420 | */ |
| 1421 | boolean isPinned(); |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1422 | } |
| 1423 | |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 1424 | public class ResolveListAdapter extends BaseAdapter { |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1425 | private final List<Intent> mIntents; |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 1426 | private final Intent[] mInitialIntents; |
| 1427 | private final List<ResolveInfo> mBaseResolveList; |
Hakan Seyalioglu | 3355012 | 2017-01-06 19:54:43 -0800 | [diff] [blame] | 1428 | protected ResolveInfo mLastChosen; |
Adam Powell | 88831a2 | 2014-11-20 18:17:00 -0800 | [diff] [blame] | 1429 | private DisplayResolveInfo mOtherProfile; |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1430 | private boolean mHasExtendedInfo; |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1431 | private ResolverListController mResolverListController; |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 1432 | private int mPlaceholderCount; |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1433 | |
| 1434 | protected final LayoutInflater mInflater; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1435 | |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1436 | List<DisplayResolveInfo> mDisplayList; |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1437 | List<ResolvedComponentInfo> mUnfilteredResolveList; |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 1438 | |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 1439 | private int mLastChosenPosition = -1; |
| 1440 | private boolean mFilterLastUsed; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1441 | |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1442 | public ResolveListAdapter(Context context, List<Intent> payloadIntents, |
| 1443 | Intent[] initialIntents, List<ResolveInfo> rList, int launchedFromUid, |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1444 | boolean filterLastUsed, |
| 1445 | ResolverListController resolverListController) { |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1446 | mIntents = payloadIntents; |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 1447 | mInitialIntents = initialIntents; |
| 1448 | mBaseResolveList = rList; |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 1449 | mLaunchedFromUid = launchedFromUid; |
Adam Powell | e9414d9 | 2014-07-05 17:44:18 -0700 | [diff] [blame] | 1450 | mInflater = LayoutInflater.from(context); |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1451 | mDisplayList = new ArrayList<>(); |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 1452 | mFilterLastUsed = filterLastUsed; |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1453 | mResolverListController = resolverListController; |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 1454 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1455 | |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 1456 | public void handlePackagesChanged() { |
| 1457 | rebuildList(); |
Esteban Talavera | 6de7266 | 2014-12-11 17:54:07 +0000 | [diff] [blame] | 1458 | if (getCount() == 0) { |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 1459 | // We no longer have any items... just finish the activity. |
| 1460 | finish(); |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 1461 | } |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 1462 | } |
| 1463 | |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 1464 | public void setPlaceholderCount(int count) { |
| 1465 | mPlaceholderCount = count; |
| 1466 | } |
| 1467 | |
Sumir Kataria | db688af | 2017-05-10 17:33:47 -0700 | [diff] [blame] | 1468 | public int getPlaceholderCount() { return mPlaceholderCount; } |
| 1469 | |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 1470 | @Nullable |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 1471 | public DisplayResolveInfo getFilteredItem() { |
| 1472 | if (mFilterLastUsed && mLastChosenPosition >= 0) { |
| 1473 | // Not using getItem since it offsets to dodge this position for the list |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1474 | return mDisplayList.get(mLastChosenPosition); |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 1475 | } |
| 1476 | return null; |
| 1477 | } |
| 1478 | |
Adam Powell | 88831a2 | 2014-11-20 18:17:00 -0800 | [diff] [blame] | 1479 | public DisplayResolveInfo getOtherProfile() { |
| 1480 | return mOtherProfile; |
| 1481 | } |
| 1482 | |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 1483 | public int getFilteredPosition() { |
| 1484 | if (mFilterLastUsed && mLastChosenPosition >= 0) { |
| 1485 | return mLastChosenPosition; |
| 1486 | } |
| 1487 | return AbsListView.INVALID_POSITION; |
| 1488 | } |
| 1489 | |
| 1490 | public boolean hasFilteredItem() { |
Hakan Seyalioglu | 3355012 | 2017-01-06 19:54:43 -0800 | [diff] [blame] | 1491 | return mFilterLastUsed && mLastChosen != null; |
Amith Yamasani | e9ecc8b | 2013-08-22 11:16:27 -0700 | [diff] [blame] | 1492 | } |
| 1493 | |
Adam Powell | a182e45 | 2015-07-06 16:57:56 -0700 | [diff] [blame] | 1494 | public float getScore(DisplayResolveInfo target) { |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1495 | return mResolverListController.getScore(target); |
Adam Powell | a182e45 | 2015-07-06 16:57:56 -0700 | [diff] [blame] | 1496 | } |
| 1497 | |
Kang Li | 0cef910d | 2017-01-05 09:14:36 -0800 | [diff] [blame] | 1498 | public void updateModel(ComponentName componentName) { |
| 1499 | mResolverListController.updateModel(componentName); |
| 1500 | } |
| 1501 | |
Kang Li | 9fa2a2c | 2017-01-06 13:33:24 -0800 | [diff] [blame] | 1502 | public void updateChooserCounts(String packageName, int userId, String action) { |
| 1503 | mResolverListController.updateChooserCounts(packageName, userId, action); |
| 1504 | } |
| 1505 | |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1506 | /** |
| 1507 | * Rebuild the list of resolvers. In some cases some parts will need some asynchronous work |
| 1508 | * to complete. |
| 1509 | * |
| 1510 | * @return Whether or not the list building is completed. |
| 1511 | */ |
| 1512 | protected boolean rebuildList() { |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1513 | List<ResolvedComponentInfo> currentResolveList = null; |
Sudheer Shanka | 7e64e10 | 2015-01-23 10:37:45 +0000 | [diff] [blame] | 1514 | // Clear the value of mOtherProfile from previous call. |
| 1515 | mOtherProfile = null; |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 1516 | mLastChosen = null; |
| 1517 | mLastChosenPosition = -1; |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1518 | mDisplayList.clear(); |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 1519 | if (mBaseResolveList != null) { |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1520 | currentResolveList = mUnfilteredResolveList = new ArrayList<>(); |
| 1521 | mResolverListController.addResolveListDedupe(currentResolveList, |
| 1522 | getTargetIntent(), |
| 1523 | mBaseResolveList); |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 1524 | } else { |
Hakan Seyalioglu | 3355012 | 2017-01-06 19:54:43 -0800 | [diff] [blame] | 1525 | currentResolveList = mUnfilteredResolveList = |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1526 | mResolverListController.getResolversForIntent(shouldGetResolvedFilter(), |
| 1527 | shouldGetActivityMetadata(), |
| 1528 | mIntents); |
| 1529 | if (currentResolveList == null) { |
| 1530 | processSortedList(currentResolveList); |
| 1531 | return true; |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1532 | } |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1533 | List<ResolvedComponentInfo> originalList = |
| 1534 | mResolverListController.filterIneligibleActivities(currentResolveList, |
| 1535 | true); |
| 1536 | if (originalList != null) { |
| 1537 | mUnfilteredResolveList = originalList; |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 1538 | } |
Jeff Hamilton | d88e9aa | 2011-01-24 14:53:00 -0600 | [diff] [blame] | 1539 | } |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 1540 | |
| 1541 | // So far we only support a single other profile at a time. |
| 1542 | // The first one we see gets special treatment. |
| 1543 | for (ResolvedComponentInfo info : currentResolveList) { |
| 1544 | if (info.getResolveInfoAt(0).targetUserId != UserHandle.USER_CURRENT) { |
| 1545 | mOtherProfile = new DisplayResolveInfo(info.getIntentAt(0), |
| 1546 | info.getResolveInfoAt(0), |
| 1547 | info.getResolveInfoAt(0).loadLabel(mPm), |
| 1548 | info.getResolveInfoAt(0).loadLabel(mPm), |
| 1549 | getReplacementIntent(info.getResolveInfoAt(0).activityInfo, |
| 1550 | info.getIntentAt(0))); |
| 1551 | currentResolveList.remove(info); |
| 1552 | break; |
| 1553 | } |
| 1554 | } |
| 1555 | |
| 1556 | if (mOtherProfile == null) { |
| 1557 | try { |
| 1558 | mLastChosen = mResolverListController.getLastChosen(); |
| 1559 | } catch (RemoteException re) { |
| 1560 | Log.d(TAG, "Error calling getLastChosenActivity\n" + re); |
| 1561 | } |
| 1562 | } |
| 1563 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1564 | int N; |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 1565 | if ((currentResolveList != null) && ((N = currentResolveList.size()) > 0)) { |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1566 | // We only care about fixing the unfilteredList if the current resolve list and |
| 1567 | // current resolve list are currently the same. |
| 1568 | List<ResolvedComponentInfo> originalList = |
| 1569 | mResolverListController.filterLowPriority(currentResolveList, |
| 1570 | mUnfilteredResolveList == currentResolveList); |
| 1571 | if (originalList != null) { |
| 1572 | mUnfilteredResolveList = originalList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1573 | } |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1574 | |
Hakan Seyalioglu | 873cbfd | 2017-02-21 19:23:43 -0800 | [diff] [blame] | 1575 | if (currentResolveList.size() > 1) { |
Sumir Kataria | db688af | 2017-05-10 17:33:47 -0700 | [diff] [blame] | 1576 | int placeholderCount = currentResolveList.size(); |
| 1577 | if (useLayoutWithDefault()) { |
| 1578 | --placeholderCount; |
| 1579 | } |
| 1580 | setPlaceholderCount(placeholderCount); |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1581 | AsyncTask<List<ResolvedComponentInfo>, |
| 1582 | Void, |
| 1583 | List<ResolvedComponentInfo>> sortingTask = |
| 1584 | new AsyncTask<List<ResolvedComponentInfo>, |
| 1585 | Void, |
| 1586 | List<ResolvedComponentInfo>>() { |
| 1587 | @Override |
| 1588 | protected List<ResolvedComponentInfo> doInBackground( |
| 1589 | List<ResolvedComponentInfo>... params) { |
| 1590 | mResolverListController.sort(params[0]); |
| 1591 | return params[0]; |
| 1592 | } |
| 1593 | |
| 1594 | @Override |
| 1595 | protected void onPostExecute(List<ResolvedComponentInfo> sortedComponents) { |
| 1596 | processSortedList(sortedComponents); |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1597 | if (mProfileView != null) { |
| 1598 | bindProfileView(); |
| 1599 | } |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 1600 | notifyDataSetChanged(); |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1601 | } |
| 1602 | }; |
| 1603 | sortingTask.execute(currentResolveList); |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 1604 | postListReadyRunnable(); |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1605 | return false; |
| 1606 | } else { |
| 1607 | processSortedList(currentResolveList); |
| 1608 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1609 | } |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1610 | } else { |
| 1611 | processSortedList(currentResolveList); |
| 1612 | return true; |
| 1613 | } |
| 1614 | } |
| 1615 | |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1616 | private void processSortedList(List<ResolvedComponentInfo> sortedComponents) { |
| 1617 | int N; |
| 1618 | if (sortedComponents != null && (N = sortedComponents.size()) != 0) { |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 1619 | // First put the initial items at the top. |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 1620 | if (mInitialIntents != null) { |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1621 | for (int i = 0; i < mInitialIntents.length; i++) { |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 1622 | Intent ii = mInitialIntents[i]; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 1623 | if (ii == null) { |
| 1624 | continue; |
| 1625 | } |
| 1626 | ActivityInfo ai = ii.resolveActivityInfo( |
| 1627 | getPackageManager(), 0); |
| 1628 | if (ai == null) { |
Adam Powell | 09a6560 | 2014-07-20 16:23:14 -0700 | [diff] [blame] | 1629 | Log.w(TAG, "No activity found for " + ii); |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 1630 | continue; |
| 1631 | } |
| 1632 | ResolveInfo ri = new ResolveInfo(); |
| 1633 | ri.activityInfo = ai; |
Nicolas Prevot | 1a81592 | 2014-10-10 16:22:38 +0100 | [diff] [blame] | 1634 | UserManager userManager = |
| 1635 | (UserManager) getSystemService(Context.USER_SERVICE); |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 1636 | if (ii instanceof LabeledIntent) { |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1637 | LabeledIntent li = (LabeledIntent) ii; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 1638 | ri.resolvePackageName = li.getSourcePackage(); |
| 1639 | ri.labelRes = li.getLabelResource(); |
| 1640 | ri.nonLocalizedLabel = li.getNonLocalizedLabel(); |
| 1641 | ri.icon = li.getIconResource(); |
Sudheer Shanka | 9ded760 | 2015-05-19 21:17:25 +0100 | [diff] [blame] | 1642 | ri.iconResourceId = ri.icon; |
| 1643 | } |
| 1644 | if (userManager.isManagedProfile()) { |
| 1645 | ri.noResourceId = true; |
| 1646 | ri.icon = 0; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 1647 | } |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1648 | addResolveInfo(new DisplayResolveInfo(ii, ri, |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 1649 | ri.loadLabel(getPackageManager()), null, ii)); |
| 1650 | } |
| 1651 | } |
You Kim | 43a5070e | 2012-11-21 23:23:45 +0900 | [diff] [blame] | 1652 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1653 | // Check for applications with same name and use application name or |
| 1654 | // package name if necessary |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1655 | ResolvedComponentInfo rci0 = sortedComponents.get(0); |
| 1656 | ResolveInfo r0 = rci0.getResolveInfoAt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1657 | int start = 0; |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1658 | CharSequence r0Label = r0.loadLabel(mPm); |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1659 | mHasExtendedInfo = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1660 | for (int i = 1; i < N; i++) { |
| 1661 | if (r0Label == null) { |
| 1662 | r0Label = r0.activityInfo.packageName; |
| 1663 | } |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1664 | ResolvedComponentInfo rci = sortedComponents.get(i); |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1665 | ResolveInfo ri = rci.getResolveInfoAt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1666 | CharSequence riLabel = ri.loadLabel(mPm); |
| 1667 | if (riLabel == null) { |
| 1668 | riLabel = ri.activityInfo.packageName; |
| 1669 | } |
| 1670 | if (riLabel.equals(r0Label)) { |
| 1671 | continue; |
| 1672 | } |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1673 | processGroup(sortedComponents, start, (i - 1), rci0, r0Label); |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1674 | rci0 = rci; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1675 | r0 = ri; |
| 1676 | r0Label = riLabel; |
| 1677 | start = i; |
| 1678 | } |
| 1679 | // Process last group |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1680 | processGroup(sortedComponents, start, (N - 1), rci0, r0Label); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1681 | } |
Hakan Seyalioglu | 3355012 | 2017-01-06 19:54:43 -0800 | [diff] [blame] | 1682 | |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 1683 | postListReadyRunnable(); |
| 1684 | } |
| 1685 | |
| 1686 | /** |
| 1687 | * Some necessary methods for creating the list are initiated in onCreate and will also |
| 1688 | * determine the layout known. We therefore can't update the UI inline and post to the |
| 1689 | * handler thread to update after the current task is finished. |
| 1690 | */ |
| 1691 | private void postListReadyRunnable() { |
| 1692 | if (mPostListReadyRunnable == null) { |
| 1693 | mPostListReadyRunnable = new Runnable() { |
| 1694 | @Override |
| 1695 | public void run() { |
Matt Pietal | 2603840 | 2019-01-08 07:29:34 -0500 | [diff] [blame] | 1696 | setHeader(); |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 1697 | resetButtonBar(); |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 1698 | onListRebuilt(); |
| 1699 | mPostListReadyRunnable = null; |
| 1700 | } |
| 1701 | }; |
| 1702 | getMainThreadHandler().post(mPostListReadyRunnable); |
| 1703 | } |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1704 | } |
| 1705 | |
| 1706 | public void onListRebuilt() { |
Xiaohui Chen | 393c801 | 2017-02-14 14:55:07 -0800 | [diff] [blame] | 1707 | int count = getUnfilteredCount(); |
| 1708 | if (count == 1 && getOtherProfile() == null) { |
| 1709 | // Only one target, so we're a candidate to auto-launch! |
| 1710 | final TargetInfo target = targetInfoForPosition(0, false); |
| 1711 | if (shouldAutoLaunchSingleChoice(target)) { |
| 1712 | safelyStartActivity(target); |
| 1713 | finish(); |
| 1714 | } |
| 1715 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1716 | } |
| 1717 | |
Adam Powell | c6d5e3a | 2015-04-23 12:22:20 -0700 | [diff] [blame] | 1718 | public boolean shouldGetResolvedFilter() { |
| 1719 | return mFilterLastUsed; |
| 1720 | } |
| 1721 | |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1722 | private void processGroup(List<ResolvedComponentInfo> rList, int start, int end, |
| 1723 | ResolvedComponentInfo ro, CharSequence roLabel) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1724 | // Process labels from start to i |
| 1725 | int num = end - start+1; |
| 1726 | if (num == 1) { |
| 1727 | // No duplicate labels. Use label for entry at start |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1728 | addResolveInfoWithAlternates(ro, null, roLabel); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1729 | } else { |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1730 | mHasExtendedInfo = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1731 | boolean usePkg = false; |
Adam Powell | 00f4aad | 2015-09-17 13:38:16 -0700 | [diff] [blame] | 1732 | final ApplicationInfo ai = ro.getResolveInfoAt(0).activityInfo.applicationInfo; |
| 1733 | final CharSequence startApp = ai.loadLabel(mPm); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1734 | if (startApp == null) { |
| 1735 | usePkg = true; |
| 1736 | } |
| 1737 | if (!usePkg) { |
| 1738 | // Use HashSet to track duplicates |
| 1739 | HashSet<CharSequence> duplicates = |
| 1740 | new HashSet<CharSequence>(); |
| 1741 | duplicates.add(startApp); |
| 1742 | for (int j = start+1; j <= end ; j++) { |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1743 | ResolveInfo jRi = rList.get(j).getResolveInfoAt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1744 | CharSequence jApp = jRi.activityInfo.applicationInfo.loadLabel(mPm); |
| 1745 | if ( (jApp == null) || (duplicates.contains(jApp))) { |
| 1746 | usePkg = true; |
| 1747 | break; |
| 1748 | } else { |
| 1749 | duplicates.add(jApp); |
| 1750 | } |
| 1751 | } |
| 1752 | // Clear HashSet for later use |
| 1753 | duplicates.clear(); |
| 1754 | } |
| 1755 | for (int k = start; k <= end; k++) { |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1756 | final ResolvedComponentInfo rci = rList.get(k); |
| 1757 | final ResolveInfo add = rci.getResolveInfoAt(0); |
| 1758 | final CharSequence extraInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1759 | if (usePkg) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1760 | // Use package name for all entries from start to end-1 |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1761 | extraInfo = add.activityInfo.packageName; |
| 1762 | } else { |
| 1763 | // Use application name for all entries from start to end-1 |
| 1764 | extraInfo = add.activityInfo.applicationInfo.loadLabel(mPm); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1765 | } |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1766 | addResolveInfoWithAlternates(rci, extraInfo, roLabel); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1767 | } |
| 1768 | } |
| 1769 | } |
| 1770 | |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1771 | private void addResolveInfoWithAlternates(ResolvedComponentInfo rci, |
| 1772 | CharSequence extraInfo, CharSequence roLabel) { |
| 1773 | final int count = rci.getCount(); |
| 1774 | final Intent intent = rci.getIntentAt(0); |
| 1775 | final ResolveInfo add = rci.getResolveInfoAt(0); |
| 1776 | final Intent replaceIntent = getReplacementIntent(add.activityInfo, intent); |
| 1777 | final DisplayResolveInfo dri = new DisplayResolveInfo(intent, add, roLabel, |
| 1778 | extraInfo, replaceIntent); |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 1779 | dri.setPinned(rci.isPinned()); |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1780 | addResolveInfo(dri); |
| 1781 | if (replaceIntent == intent) { |
| 1782 | // Only add alternates if we didn't get a specific replacement from |
| 1783 | // the caller. If we have one it trumps potential alternates. |
| 1784 | for (int i = 1, N = count; i < N; i++) { |
| 1785 | final Intent altIntent = rci.getIntentAt(i); |
| 1786 | dri.addAlternateSourceIntent(altIntent); |
| 1787 | } |
| 1788 | } |
| 1789 | updateLastChosenPosition(add); |
| 1790 | } |
| 1791 | |
Esteban Talavera | 6de7266 | 2014-12-11 17:54:07 +0000 | [diff] [blame] | 1792 | private void updateLastChosenPosition(ResolveInfo info) { |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 1793 | // If another profile is present, ignore the last chosen entry. |
| 1794 | if (mOtherProfile != null) { |
| 1795 | mLastChosenPosition = -1; |
| 1796 | return; |
| 1797 | } |
Esteban Talavera | 6de7266 | 2014-12-11 17:54:07 +0000 | [diff] [blame] | 1798 | if (mLastChosen != null |
| 1799 | && mLastChosen.activityInfo.packageName.equals(info.activityInfo.packageName) |
| 1800 | && mLastChosen.activityInfo.name.equals(info.activityInfo.name)) { |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1801 | mLastChosenPosition = mDisplayList.size() - 1; |
Esteban Talavera | 6de7266 | 2014-12-11 17:54:07 +0000 | [diff] [blame] | 1802 | } |
| 1803 | } |
| 1804 | |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 1805 | // We assume that at this point we've already filtered out the only intent for a different |
| 1806 | // targetUserId which we're going to use. |
Adam Powell | 88831a2 | 2014-11-20 18:17:00 -0800 | [diff] [blame] | 1807 | private void addResolveInfo(DisplayResolveInfo dri) { |
Kang Li | 6afa4f2 | 2017-06-23 12:54:38 -0700 | [diff] [blame] | 1808 | if (dri != null && dri.mResolveInfo != null |
| 1809 | && dri.mResolveInfo.targetUserId == UserHandle.USER_CURRENT) { |
| 1810 | // Checks if this info is already listed in display. |
| 1811 | for (DisplayResolveInfo existingInfo : mDisplayList) { |
| 1812 | if (resolveInfoMatch(dri.mResolveInfo, existingInfo.mResolveInfo)) { |
| 1813 | return; |
| 1814 | } |
| 1815 | } |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1816 | mDisplayList.add(dri); |
Adam Powell | 88831a2 | 2014-11-20 18:17:00 -0800 | [diff] [blame] | 1817 | } |
| 1818 | } |
| 1819 | |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 1820 | @Nullable |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 1821 | public ResolveInfo resolveInfoForPosition(int position, boolean filtered) { |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 1822 | TargetInfo target = targetInfoForPosition(position, filtered); |
| 1823 | if (target != null) { |
| 1824 | return target.getResolveInfo(); |
| 1825 | } |
| 1826 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1827 | } |
| 1828 | |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 1829 | @Nullable |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1830 | public TargetInfo targetInfoForPosition(int position, boolean filtered) { |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 1831 | if (filtered) { |
| 1832 | return getItem(position); |
| 1833 | } |
| 1834 | if (mDisplayList.size() > position) { |
| 1835 | return mDisplayList.get(position); |
| 1836 | } |
| 1837 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1838 | } |
| 1839 | |
| 1840 | public int getCount() { |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 1841 | int totalSize = mDisplayList == null || mDisplayList.isEmpty() ? mPlaceholderCount : |
| 1842 | mDisplayList.size(); |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 1843 | if (mFilterLastUsed && mLastChosenPosition >= 0) { |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 1844 | totalSize--; |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 1845 | } |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 1846 | return totalSize; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1847 | } |
| 1848 | |
Adam Powell | 5007735 | 2015-05-26 18:01:55 -0700 | [diff] [blame] | 1849 | public int getUnfilteredCount() { |
| 1850 | return mDisplayList.size(); |
| 1851 | } |
| 1852 | |
| 1853 | public int getDisplayInfoCount() { |
| 1854 | return mDisplayList.size(); |
| 1855 | } |
| 1856 | |
| 1857 | public DisplayResolveInfo getDisplayInfoAt(int index) { |
| 1858 | return mDisplayList.get(index); |
| 1859 | } |
| 1860 | |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 1861 | @Nullable |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1862 | public TargetInfo getItem(int position) { |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 1863 | if (mFilterLastUsed && mLastChosenPosition >= 0 && position >= mLastChosenPosition) { |
| 1864 | position++; |
| 1865 | } |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 1866 | if (mDisplayList.size() > position) { |
| 1867 | return mDisplayList.get(position); |
| 1868 | } else { |
| 1869 | return null; |
| 1870 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1871 | } |
| 1872 | |
| 1873 | public long getItemId(int position) { |
| 1874 | return position; |
| 1875 | } |
| 1876 | |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1877 | public boolean hasExtendedInfo() { |
| 1878 | return mHasExtendedInfo; |
| 1879 | } |
| 1880 | |
| 1881 | public boolean hasResolvedTarget(ResolveInfo info) { |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1882 | for (int i = 0, N = mDisplayList.size(); i < N; i++) { |
Adam Powell | c412be6 | 2015-06-24 13:54:10 -0700 | [diff] [blame] | 1883 | if (resolveInfoMatch(info, mDisplayList.get(i).getResolveInfo())) { |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1884 | return true; |
| 1885 | } |
| 1886 | } |
| 1887 | return false; |
| 1888 | } |
| 1889 | |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 1890 | public int getDisplayResolveInfoCount() { |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1891 | return mDisplayList.size(); |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1892 | } |
| 1893 | |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 1894 | public DisplayResolveInfo getDisplayResolveInfo(int index) { |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1895 | // Used to query services. We only query services for primary targets, not alternates. |
| 1896 | return mDisplayList.get(index); |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1897 | } |
| 1898 | |
| 1899 | public final View getView(int position, View convertView, ViewGroup parent) { |
Adam Powell | fd1e93d | 2014-09-07 16:52:22 -0700 | [diff] [blame] | 1900 | View view = convertView; |
| 1901 | if (view == null) { |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1902 | view = createView(parent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1903 | } |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1904 | onBindView(view, getItem(position)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1905 | return view; |
| 1906 | } |
| 1907 | |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1908 | public final View createView(ViewGroup parent) { |
| 1909 | final View view = onCreateView(parent); |
| 1910 | final ViewHolder holder = new ViewHolder(view); |
| 1911 | view.setTag(holder); |
| 1912 | return view; |
| 1913 | } |
| 1914 | |
| 1915 | public View onCreateView(ViewGroup parent) { |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1916 | return mInflater.inflate( |
| 1917 | com.android.internal.R.layout.resolve_list_item, parent, false); |
| 1918 | } |
| 1919 | |
| 1920 | public boolean showsExtendedInfo(TargetInfo info) { |
| 1921 | return !TextUtils.isEmpty(info.getExtendedInfo()); |
| 1922 | } |
| 1923 | |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 1924 | public boolean isComponentPinned(ComponentName name) { |
| 1925 | return false; |
| 1926 | } |
| 1927 | |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1928 | public final void bindView(int position, View view) { |
| 1929 | onBindView(view, getItem(position)); |
| 1930 | } |
| 1931 | |
| 1932 | private void onBindView(View view, TargetInfo info) { |
Adam Powell | 0256c6f | 2013-05-29 16:42:33 -0700 | [diff] [blame] | 1933 | final ViewHolder holder = (ViewHolder) view.getTag(); |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 1934 | if (info == null) { |
| 1935 | holder.icon.setImageDrawable( |
| 1936 | getDrawable(R.drawable.resolver_icon_placeholder)); |
| 1937 | return; |
| 1938 | } |
Adam Powell | 63b3169 | 2015-09-28 10:45:00 -0700 | [diff] [blame] | 1939 | final CharSequence label = info.getDisplayLabel(); |
| 1940 | if (!TextUtils.equals(holder.text.getText(), label)) { |
| 1941 | holder.text.setText(info.getDisplayLabel()); |
| 1942 | } |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1943 | if (showsExtendedInfo(info)) { |
Adam Powell | 0256c6f | 2013-05-29 16:42:33 -0700 | [diff] [blame] | 1944 | holder.text2.setVisibility(View.VISIBLE); |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1945 | holder.text2.setText(info.getExtendedInfo()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1946 | } else { |
Adam Powell | 0256c6f | 2013-05-29 16:42:33 -0700 | [diff] [blame] | 1947 | holder.text2.setVisibility(View.GONE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1948 | } |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1949 | if (info instanceof DisplayResolveInfo |
| 1950 | && !((DisplayResolveInfo) info).hasDisplayIcon()) { |
| 1951 | new LoadAdapterIconTask((DisplayResolveInfo) info).execute(); |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 1952 | } |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1953 | holder.icon.setImageDrawable(info.getDisplayIcon()); |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1954 | if (holder.badge != null) { |
| 1955 | final Drawable badge = info.getBadgeIcon(); |
| 1956 | if (badge != null) { |
| 1957 | holder.badge.setImageDrawable(badge); |
Alan Viverette | ce5d92c | 2015-07-31 16:46:56 -0400 | [diff] [blame] | 1958 | holder.badge.setContentDescription(info.getBadgeContentDescription()); |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1959 | holder.badge.setVisibility(View.VISIBLE); |
| 1960 | } else { |
| 1961 | holder.badge.setVisibility(View.GONE); |
| 1962 | } |
| 1963 | } |
Adam Powell | 0256c6f | 2013-05-29 16:42:33 -0700 | [diff] [blame] | 1964 | } |
| 1965 | } |
| 1966 | |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1967 | @VisibleForTesting |
| 1968 | public static final class ResolvedComponentInfo { |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1969 | public final ComponentName name; |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 1970 | private boolean mPinned; |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1971 | private final List<Intent> mIntents = new ArrayList<>(); |
| 1972 | private final List<ResolveInfo> mResolveInfos = new ArrayList<>(); |
| 1973 | |
| 1974 | public ResolvedComponentInfo(ComponentName name, Intent intent, ResolveInfo info) { |
| 1975 | this.name = name; |
| 1976 | add(intent, info); |
| 1977 | } |
| 1978 | |
| 1979 | public void add(Intent intent, ResolveInfo info) { |
| 1980 | mIntents.add(intent); |
| 1981 | mResolveInfos.add(info); |
| 1982 | } |
| 1983 | |
| 1984 | public int getCount() { |
| 1985 | return mIntents.size(); |
| 1986 | } |
| 1987 | |
| 1988 | public Intent getIntentAt(int index) { |
| 1989 | return index >= 0 ? mIntents.get(index) : null; |
| 1990 | } |
| 1991 | |
| 1992 | public ResolveInfo getResolveInfoAt(int index) { |
| 1993 | return index >= 0 ? mResolveInfos.get(index) : null; |
| 1994 | } |
| 1995 | |
| 1996 | public int findIntent(Intent intent) { |
| 1997 | for (int i = 0, N = mIntents.size(); i < N; i++) { |
| 1998 | if (intent.equals(mIntents.get(i))) { |
| 1999 | return i; |
| 2000 | } |
| 2001 | } |
| 2002 | return -1; |
| 2003 | } |
| 2004 | |
| 2005 | public int findResolveInfo(ResolveInfo info) { |
| 2006 | for (int i = 0, N = mResolveInfos.size(); i < N; i++) { |
| 2007 | if (info.equals(mResolveInfos.get(i))) { |
| 2008 | return i; |
| 2009 | } |
| 2010 | } |
| 2011 | return -1; |
| 2012 | } |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 2013 | |
| 2014 | public boolean isPinned() { |
| 2015 | return mPinned; |
| 2016 | } |
| 2017 | |
| 2018 | public void setPinned(boolean pinned) { |
| 2019 | mPinned = pinned; |
| 2020 | } |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 2021 | } |
| 2022 | |
Adam Powell | 0256c6f | 2013-05-29 16:42:33 -0700 | [diff] [blame] | 2023 | static class ViewHolder { |
| 2024 | public TextView text; |
| 2025 | public TextView text2; |
| 2026 | public ImageView icon; |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 2027 | public ImageView badge; |
Adam Powell | 0256c6f | 2013-05-29 16:42:33 -0700 | [diff] [blame] | 2028 | |
| 2029 | public ViewHolder(View view) { |
| 2030 | text = (TextView) view.findViewById(com.android.internal.R.id.text1); |
| 2031 | text2 = (TextView) view.findViewById(com.android.internal.R.id.text2); |
| 2032 | icon = (ImageView) view.findViewById(R.id.icon); |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 2033 | badge = (ImageView) view.findViewById(R.id.target_badge); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2034 | } |
| 2035 | } |
| 2036 | |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 2037 | class ItemClickListener implements AdapterView.OnItemClickListener, |
| 2038 | AdapterView.OnItemLongClickListener { |
| 2039 | @Override |
| 2040 | public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
| 2041 | final ListView listView = parent instanceof ListView ? (ListView) parent : null; |
| 2042 | if (listView != null) { |
| 2043 | position -= listView.getHeaderViewsCount(); |
| 2044 | } |
| 2045 | if (position < 0) { |
| 2046 | // Header views don't count. |
| 2047 | return; |
| 2048 | } |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 2049 | // If we're still loading, we can't yet enable the buttons. |
| 2050 | if (mAdapter.resolveInfoForPosition(position, true) == null) { |
| 2051 | return; |
| 2052 | } |
| 2053 | |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 2054 | final int checkedPos = mAdapterView.getCheckedItemPosition(); |
| 2055 | final boolean hasValidSelection = checkedPos != ListView.INVALID_POSITION; |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 2056 | if (!useLayoutWithDefault() |
Ruchi Kandoi | 65d76c1 | 2017-08-18 13:05:39 -0700 | [diff] [blame] | 2057 | && (!hasValidSelection || mLastSelected != checkedPos) |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 2058 | && (mAlwaysButton != null || mSettingsButton != null)) { |
| 2059 | if (mSettingsButton != null) { |
| 2060 | // this implies that the layout for browsables is being used |
| 2061 | mSettingsButton.setEnabled(true); |
| 2062 | } else { |
| 2063 | // this implies that mAlwaysButton != null |
| 2064 | setAlwaysButtonEnabled(hasValidSelection, checkedPos, true); |
| 2065 | } |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 2066 | mOnceButton.setEnabled(hasValidSelection); |
| 2067 | if (hasValidSelection) { |
| 2068 | mAdapterView.smoothScrollToPosition(checkedPos); |
| 2069 | } |
| 2070 | mLastSelected = checkedPos; |
| 2071 | } else { |
| 2072 | startSelected(position, false, true); |
| 2073 | } |
| 2074 | } |
Adam Powell | 2d80962 | 2012-03-22 15:24:43 -0700 | [diff] [blame] | 2075 | |
| 2076 | @Override |
| 2077 | public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 2078 | final ListView listView = parent instanceof ListView ? (ListView) parent : null; |
| 2079 | if (listView != null) { |
| 2080 | position -= listView.getHeaderViewsCount(); |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 2081 | } |
Adam Powell | fd1e93d | 2014-09-07 16:52:22 -0700 | [diff] [blame] | 2082 | if (position < 0) { |
| 2083 | // Header views don't count. |
| 2084 | return false; |
| 2085 | } |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 2086 | ResolveInfo ri = mAdapter.resolveInfoForPosition(position, true); |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 2087 | showTargetDetails(ri); |
Adam Powell | 2d80962 | 2012-03-22 15:24:43 -0700 | [diff] [blame] | 2088 | return true; |
| 2089 | } |
| 2090 | |
| 2091 | } |
Adam Powell | 0256c6f | 2013-05-29 16:42:33 -0700 | [diff] [blame] | 2092 | |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 2093 | abstract class LoadIconTask extends AsyncTask<Void, Void, Drawable> { |
| 2094 | protected final DisplayResolveInfo mDisplayResolveInfo; |
| 2095 | private final ResolveInfo mResolveInfo; |
| 2096 | |
| 2097 | public LoadIconTask(DisplayResolveInfo dri) { |
| 2098 | mDisplayResolveInfo = dri; |
| 2099 | mResolveInfo = dri.getResolveInfo(); |
Adam Powell | 0256c6f | 2013-05-29 16:42:33 -0700 | [diff] [blame] | 2100 | } |
| 2101 | |
| 2102 | @Override |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 2103 | protected Drawable doInBackground(Void... params) { |
| 2104 | return loadIconForResolveInfo(mResolveInfo); |
| 2105 | } |
| 2106 | |
| 2107 | @Override |
| 2108 | protected void onPostExecute(Drawable d) { |
| 2109 | mDisplayResolveInfo.setDisplayIcon(d); |
| 2110 | } |
| 2111 | } |
| 2112 | |
| 2113 | class LoadAdapterIconTask extends LoadIconTask { |
| 2114 | public LoadAdapterIconTask(DisplayResolveInfo dri) { |
| 2115 | super(dri); |
| 2116 | } |
| 2117 | |
| 2118 | @Override |
| 2119 | protected void onPostExecute(Drawable d) { |
| 2120 | super.onPostExecute(d); |
| 2121 | if (mProfileView != null && mAdapter.getOtherProfile() == mDisplayResolveInfo) { |
Adam Powell | 88831a2 | 2014-11-20 18:17:00 -0800 | [diff] [blame] | 2122 | bindProfileView(); |
| 2123 | } |
Adam Powell | 0256c6f | 2013-05-29 16:42:33 -0700 | [diff] [blame] | 2124 | mAdapter.notifyDataSetChanged(); |
| 2125 | } |
| 2126 | } |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 2127 | |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 2128 | class LoadIconIntoViewTask extends LoadIconTask { |
| 2129 | private final ImageView mTargetView; |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 2130 | |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 2131 | public LoadIconIntoViewTask(DisplayResolveInfo dri, ImageView target) { |
| 2132 | super(dri); |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 2133 | mTargetView = target; |
| 2134 | } |
| 2135 | |
| 2136 | @Override |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 2137 | protected void onPostExecute(Drawable d) { |
| 2138 | super.onPostExecute(d); |
| 2139 | mTargetView.setImageDrawable(d); |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 2140 | } |
| 2141 | } |
Adam Powell | 09a6560 | 2014-07-20 16:23:14 -0700 | [diff] [blame] | 2142 | |
Dianne Hackborn | ec452d9 | 2014-11-11 17:16:56 -0800 | [diff] [blame] | 2143 | static final boolean isSpecificUriMatch(int match) { |
| 2144 | match = match&IntentFilter.MATCH_CATEGORY_MASK; |
| 2145 | return match >= IntentFilter.MATCH_CATEGORY_HOST |
| 2146 | && match <= IntentFilter.MATCH_CATEGORY_PATH; |
| 2147 | } |
| 2148 | |
Adam Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 2149 | static class PickTargetOptionRequest extends PickOptionRequest { |
| 2150 | public PickTargetOptionRequest(@Nullable Prompt prompt, Option[] options, |
| 2151 | @Nullable Bundle extras) { |
| 2152 | super(prompt, options, extras); |
| 2153 | } |
| 2154 | |
| 2155 | @Override |
| 2156 | public void onCancel() { |
| 2157 | super.onCancel(); |
| 2158 | final ResolverActivity ra = (ResolverActivity) getActivity(); |
| 2159 | if (ra != null) { |
| 2160 | ra.mPickOptionRequest = null; |
| 2161 | ra.finish(); |
| 2162 | } |
| 2163 | } |
| 2164 | |
| 2165 | @Override |
| 2166 | public void onPickOptionResult(boolean finished, Option[] selections, Bundle result) { |
| 2167 | super.onPickOptionResult(finished, selections, result); |
| 2168 | if (selections.length != 1) { |
| 2169 | // TODO In a better world we would filter the UI presented here and let the |
| 2170 | // user refine. Maybe later. |
| 2171 | return; |
| 2172 | } |
| 2173 | |
| 2174 | final ResolverActivity ra = (ResolverActivity) getActivity(); |
| 2175 | if (ra != null) { |
| 2176 | final TargetInfo ti = ra.mAdapter.getItem(selections[0].getIndex()); |
| 2177 | if (ra.onTargetSelected(ti, false)) { |
| 2178 | ra.mPickOptionRequest = null; |
| 2179 | ra.finish(); |
| 2180 | } |
| 2181 | } |
| 2182 | } |
| 2183 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2184 | } |