blob: 9cf5e9f47e7f28a65adda17d7e168b629ae601b5 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17package com.android.internal.app;
18
Hyunyoung Song16b7af42018-10-05 14:00:42 -070019import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
20
arangelov38a6fce2019-12-02 18:21:22 +000021import static com.android.internal.app.AbstractMultiProfilePagerAdapter.PROFILE_PERSONAL;
22import static com.android.internal.app.AbstractMultiProfilePagerAdapter.PROFILE_WORK;
23
Adam Powell4c470d62015-06-19 17:46:17 -070024import android.annotation.Nullable;
Philip P. Moltmannf8173ca2016-04-12 15:11:23 -070025import android.annotation.StringRes;
Hakan Seyalioglue1276bf2016-12-07 16:38:57 -080026import android.annotation.UiThread;
Andrei Onea15884392019-03-22 17:28:11 +000027import android.annotation.UnsupportedAppUsage;
Adam Powelle9414d92014-07-05 17:44:18 -070028import android.app.Activity;
arangelov38a6fce2019-12-02 18:21:22 +000029import android.app.ActivityManager;
Wale Ogunwale04d9cb52018-04-30 13:55:07 -070030import android.app.ActivityTaskManager;
Dianne Hackborn028ceeb2014-08-17 17:45:48 -070031import android.app.ActivityThread;
Adam Powell4c470d62015-06-19 17:46:17 -070032import android.app.VoiceInteractor.PickOptionRequest;
33import android.app.VoiceInteractor.PickOptionRequest.Option;
34import android.app.VoiceInteractor.Prompt;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035import android.content.ComponentName;
36import android.content.Context;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import android.content.Intent;
38import android.content.IntentFilter;
Paul McLean3a30e552019-12-07 14:47:29 -070039import android.content.PermissionChecker;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040import android.content.pm.ActivityInfo;
Sander Alewijnse6c9eee82014-07-17 10:03:31 +010041import android.content.pm.ApplicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042import android.content.pm.PackageManager;
Adam Powellc5878612012-05-04 18:42:38 -070043import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044import android.content.pm.ResolveInfo;
Sander Alewijnse6c9eee82014-07-17 10:03:31 +010045import android.content.pm.UserInfo;
Jiongxuan Gao3365b162016-11-24 20:20:27 +090046import android.content.res.Configuration;
Adam Powellc5878612012-05-04 18:42:38 -070047import android.content.res.Resources;
Matt Pietal800136a2019-05-08 07:46:39 -040048import android.graphics.Insets;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049import android.net.Uri;
Sander Alewijnse6c9eee82014-07-17 10:03:31 +010050import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051import android.os.Bundle;
Alison Cichowlas3e340502018-08-07 17:15:01 -040052import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053import android.os.PatternMatcher;
Hakan Seyalioglu13405c52017-01-31 19:01:31 -080054import android.os.RemoteException;
Jeff Sharkey37355a92016-02-05 16:19:10 -070055import android.os.StrictMode;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070056import android.os.UserHandle;
Sander Alewijnse6c9eee82014-07-17 10:03:31 +010057import android.os.UserManager;
Hakan Seyalioglu13405c52017-01-31 19:01:31 -080058import android.provider.MediaStore;
59import android.provider.Settings;
60import android.text.TextUtils;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061import android.util.Log;
Hakan Seyalioglu13405c52017-01-31 19:01:31 -080062import android.util.Slog;
Adam Powell2d809622012-03-22 15:24:43 -070063import android.view.LayoutInflater;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064import android.view.View;
65import android.view.ViewGroup;
Matt Pietal800136a2019-05-08 07:46:39 -040066import android.view.ViewGroup.LayoutParams;
67import android.view.WindowInsets;
Hakan Seyalioglu13405c52017-01-31 19:01:31 -080068import android.widget.AbsListView;
Adam Powell2d809622012-03-22 15:24:43 -070069import android.widget.AdapterView;
Adam Powellc5878612012-05-04 18:42:38 -070070import android.widget.Button;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071import android.widget.ImageView;
Adam Powell2d809622012-03-22 15:24:43 -070072import android.widget.ListView;
Matt Pietal800136a2019-05-08 07:46:39 -040073import android.widget.Space;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074import android.widget.TextView;
Sander Alewijnse6c9eee82014-07-17 10:03:31 +010075import android.widget.Toast;
Hyunyoung Song16b7af42018-10-05 14:00:42 -070076
Hakan Seyalioglu13405c52017-01-31 19:01:31 -080077import com.android.internal.R;
78import com.android.internal.annotations.VisibleForTesting;
arangelov38a6fce2019-12-02 18:21:22 +000079import com.android.internal.app.AbstractMultiProfilePagerAdapter.Profile;
arangelovb0802dc2019-10-18 18:03:44 +010080import com.android.internal.app.chooser.DisplayResolveInfo;
81import com.android.internal.app.chooser.TargetInfo;
Hakan Seyalioglu13405c52017-01-31 19:01:31 -080082import com.android.internal.content.PackageMonitor;
Clara Bayarrifa902aa2016-04-13 14:45:08 +010083import com.android.internal.logging.MetricsLogger;
Tamas Berghammer383db5eb2016-06-22 15:21:38 +010084import com.android.internal.logging.nano.MetricsProto;
Adam Powell4f6c2052014-07-07 18:49:10 -070085import com.android.internal.widget.ResolverDrawerLayout;
Adam Powell2d809622012-03-22 15:24:43 -070086
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087import java.util.ArrayList;
Clara Bayarrifa902aa2016-04-13 14:45:08 +010088import java.util.Arrays;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089import java.util.Iterator;
90import java.util.List;
Adam Powellc412be62015-06-24 13:54:10 -070091import java.util.Objects;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092import java.util.Set;
93
94/**
95 * This activity is displayed when the system attempts to start an Intent for
96 * which there is more than one matching activity, allowing the user to decide
97 * which to go to. It is not normally used directly by application developers.
98 */
Hakan Seyalioglue1276bf2016-12-07 16:38:57 -080099@UiThread
arangelovb0802dc2019-10-18 18:03:44 +0100100public class ResolverActivity extends Activity implements
101 ResolverListAdapter.ResolverListCommunicator {
Alison Cichowlas4691ed42018-11-13 15:59:55 -0500102
Andrei Onea15884392019-03-22 17:28:11 +0000103 @UnsupportedAppUsage
Artur Satayev751e5512019-11-15 19:12:49 +0000104 public ResolverActivity() {
105 }
106
Dianne Hackborn028ceeb2014-08-17 17:45:48 -0700107 private boolean mSafeForwardingMode;
Adam Powellc5878612012-05-04 18:42:38 -0700108 private Button mAlwaysButton;
109 private Button mOnceButton;
Matt Pietal74c6ed02019-04-18 13:38:46 -0400110 protected View mProfileView;
Adam Powell24428412015-04-01 17:19:56 -0700111 private int mLastSelected = AbsListView.INVALID_POSITION;
Sander Alewijnse6c9eee82014-07-17 10:03:31 +0100112 private boolean mResolvingHome = false;
Sander Alewijnsef6545332014-10-31 12:39:02 +0000113 private int mProfileSwitchMessageId = -1;
Hakan Seyalioglue1276bf2016-12-07 16:38:57 -0800114 private int mLayoutId;
arangelovb0802dc2019-10-18 18:03:44 +0100115 @VisibleForTesting
116 protected final ArrayList<Intent> mIntents = new ArrayList<>();
Adam Powell4c470d62015-06-19 17:46:17 -0700117 private PickTargetOptionRequest mPickOptionRequest;
Hakan Seyalioglue1276bf2016-12-07 16:38:57 -0800118 private String mReferrerPackage;
Hakan Seyalioglu33550122017-01-06 19:54:43 -0800119 private CharSequence mTitle;
120 private int mDefaultTitleResId;
arangelovb0802dc2019-10-18 18:03:44 +0100121
122 @VisibleForTesting
123 protected boolean mUseLayoutForBrowsables;
Adam Powell09a65602014-07-20 16:23:14 -0700124
Hakan Seyalioglu13405c52017-01-31 19:01:31 -0800125 // Whether or not this activity supports choosing a default handler for the intent.
arangelovb0802dc2019-10-18 18:03:44 +0100126 @VisibleForTesting
127 protected boolean mSupportsAlwaysUseOption;
Adam Powell63b31692015-09-28 10:45:00 -0700128 protected ResolverDrawerLayout mResolverDrawerLayout;
Andrei Onea15884392019-03-22 17:28:11 +0000129 @UnsupportedAppUsage
Hakan Seyalioglue1276bf2016-12-07 16:38:57 -0800130 protected PackageManager mPm;
131 protected int mLaunchedFromUid;
132
133 private static final String TAG = "ResolverActivity";
134 private static final boolean DEBUG = false;
Adam Powell63b31692015-09-28 10:45:00 -0700135
Dianne Hackbornd44713a2012-04-30 16:34:46 -0700136 private boolean mRegistered;
Jorim Jaggif631ef72017-02-24 13:49:47 +0100137
Matt Pietal800136a2019-05-08 07:46:39 -0400138 protected Insets mSystemWindowInsets = null;
139 private Space mFooterSpacer = null;
140
Jorim Jaggif631ef72017-02-24 13:49:47 +0100141 /** See {@link #setRetainInOnStop}. */
142 private boolean mRetainInOnStop;
143
Matt Pietal0d6834a2019-06-27 13:27:52 -0400144 private static final String EXTRA_SHOW_FRAGMENT_ARGS = ":settings:show_fragment_args";
145 private static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
146 private static final String OPEN_LINKS_COMPONENT_KEY = "app_link_state";
147
arangelov38a6fce2019-12-02 18:21:22 +0000148 /**
149 * TODO(arangelov): Remove a couple of weeks after work/personal tabs are finalized.
150 */
151 static final boolean ENABLE_TABBED_VIEW = false;
152
Matt Pietalab73a882019-06-05 07:04:55 -0400153 private final PackageMonitor mPackageMonitor = createPackageMonitor();
Dianne Hackborne8f2c7f2012-03-01 17:30:53 -0800154
arangelov38a6fce2019-12-02 18:21:22 +0000155 @VisibleForTesting
156 protected AbstractMultiProfilePagerAdapter mMultiProfilePagerAdapter;
157
Paul McLean07425c82019-10-18 12:00:11 -0600158 // Intent extra for connected audio devices
159 public static final String EXTRA_IS_AUDIO_CAPTURE_DEVICE = "is_audio_capture_device";
160
Philip P. Moltmannf8173ca2016-04-12 15:11:23 -0700161 /**
162 * Get the string resource to be used as a label for the link to the resolver activity for an
163 * action.
164 *
165 * @param action The action to resolve
166 *
167 * @return The string resource to be used as a label
168 */
169 public static @StringRes int getLabelRes(String action) {
170 return ActionTitle.forAction(action).labelRes;
171 }
172
Adam Powell278902c2014-07-12 18:33:22 -0700173 private enum ActionTitle {
174 VIEW(Intent.ACTION_VIEW,
175 com.android.internal.R.string.whichViewApplication,
Philip P. Moltmannf8173ca2016-04-12 15:11:23 -0700176 com.android.internal.R.string.whichViewApplicationNamed,
177 com.android.internal.R.string.whichViewApplicationLabel),
Adam Powell278902c2014-07-12 18:33:22 -0700178 EDIT(Intent.ACTION_EDIT,
179 com.android.internal.R.string.whichEditApplication,
Philip P. Moltmannf8173ca2016-04-12 15:11:23 -0700180 com.android.internal.R.string.whichEditApplicationNamed,
181 com.android.internal.R.string.whichEditApplicationLabel),
Adam Powell278902c2014-07-12 18:33:22 -0700182 SEND(Intent.ACTION_SEND,
183 com.android.internal.R.string.whichSendApplication,
Philip P. Moltmannf8173ca2016-04-12 15:11:23 -0700184 com.android.internal.R.string.whichSendApplicationNamed,
185 com.android.internal.R.string.whichSendApplicationLabel),
Adam Powell278902c2014-07-12 18:33:22 -0700186 SENDTO(Intent.ACTION_SENDTO,
Adam Powell13ea8f42016-03-18 09:39:41 -0700187 com.android.internal.R.string.whichSendToApplication,
Philip P. Moltmannf8173ca2016-04-12 15:11:23 -0700188 com.android.internal.R.string.whichSendToApplicationNamed,
189 com.android.internal.R.string.whichSendToApplicationLabel),
Adam Powell278902c2014-07-12 18:33:22 -0700190 SEND_MULTIPLE(Intent.ACTION_SEND_MULTIPLE,
191 com.android.internal.R.string.whichSendApplication,
Philip P. Moltmannf8173ca2016-04-12 15:11:23 -0700192 com.android.internal.R.string.whichSendApplicationNamed,
193 com.android.internal.R.string.whichSendApplicationLabel),
194 CAPTURE_IMAGE(MediaStore.ACTION_IMAGE_CAPTURE,
195 com.android.internal.R.string.whichImageCaptureApplication,
196 com.android.internal.R.string.whichImageCaptureApplicationNamed,
197 com.android.internal.R.string.whichImageCaptureApplicationLabel),
Adam Powell278902c2014-07-12 18:33:22 -0700198 DEFAULT(null,
199 com.android.internal.R.string.whichApplication,
Philip P. Moltmannf8173ca2016-04-12 15:11:23 -0700200 com.android.internal.R.string.whichApplicationNamed,
201 com.android.internal.R.string.whichApplicationLabel),
Adam Powella35c77a2014-09-25 16:46:36 -0700202 HOME(Intent.ACTION_MAIN,
203 com.android.internal.R.string.whichHomeApplication,
Philip P. Moltmannf8173ca2016-04-12 15:11:23 -0700204 com.android.internal.R.string.whichHomeApplicationNamed,
205 com.android.internal.R.string.whichHomeApplicationLabel);
Adam Powell278902c2014-07-12 18:33:22 -0700206
shafik0c7c5d52019-02-27 12:13:25 +0000207 // titles for layout that deals with http(s) intents
shafik69df96322018-12-18 15:41:19 +0000208 public static final int BROWSABLE_TITLE_RES =
Matt Pietal0d6834a2019-06-27 13:27:52 -0400209 com.android.internal.R.string.whichOpenLinksWith;
210 public static final int BROWSABLE_HOST_TITLE_RES =
211 com.android.internal.R.string.whichOpenHostLinksWith;
212 public static final int BROWSABLE_HOST_APP_TITLE_RES =
213 com.android.internal.R.string.whichOpenHostLinksWithApp;
214 public static final int BROWSABLE_APP_TITLE_RES =
215 com.android.internal.R.string.whichOpenLinksWithApp;
shafik69df96322018-12-18 15:41:19 +0000216
Adam Powell278902c2014-07-12 18:33:22 -0700217 public final String action;
218 public final int titleRes;
219 public final int namedTitleRes;
Philip P. Moltmannf8173ca2016-04-12 15:11:23 -0700220 public final @StringRes int labelRes;
Adam Powell278902c2014-07-12 18:33:22 -0700221
Philip P. Moltmannf8173ca2016-04-12 15:11:23 -0700222 ActionTitle(String action, int titleRes, int namedTitleRes, @StringRes int labelRes) {
Adam Powell278902c2014-07-12 18:33:22 -0700223 this.action = action;
224 this.titleRes = titleRes;
225 this.namedTitleRes = namedTitleRes;
Philip P. Moltmannf8173ca2016-04-12 15:11:23 -0700226 this.labelRes = labelRes;
Adam Powell278902c2014-07-12 18:33:22 -0700227 }
228
229 public static ActionTitle forAction(String action) {
230 for (ActionTitle title : values()) {
Adam Powella35c77a2014-09-25 16:46:36 -0700231 if (title != HOME && action != null && action.equals(title.action)) {
Adam Powell278902c2014-07-12 18:33:22 -0700232 return title;
233 }
234 }
235 return DEFAULT;
236 }
237 }
238
Matt Pietalab73a882019-06-05 07:04:55 -0400239 protected PackageMonitor createPackageMonitor() {
240 return new PackageMonitor() {
241 @Override
242 public void onSomePackagesChanged() {
arangelov38a6fce2019-12-02 18:21:22 +0000243 mMultiProfilePagerAdapter.getCurrentListAdapter().handlePackagesChanged();
arangelovb0802dc2019-10-18 18:03:44 +0100244 updateProfileViewButton();
Matt Pietalab73a882019-06-05 07:04:55 -0400245 }
246
247 @Override
248 public boolean onPackageChanged(String packageName, int uid, String[] components) {
249 // We care about all package changes, not just the whole package itself which is
250 // default behavior.
251 return true;
252 }
253 };
254 }
255
Dianne Hackborn905577f2011-09-07 18:31:28 -0700256 private Intent makeMyIntent() {
257 Intent intent = new Intent(getIntent());
Dianne Hackborn6d8dfbd2013-09-23 17:38:51 -0700258 intent.setComponent(null);
Dianne Hackborn905577f2011-09-07 18:31:28 -0700259 // The resolver activity is set to be hidden from recent tasks.
260 // we don't want this attribute to be propagated to the next activity
261 // being launched. Note that if the original Intent also had this
262 // flag set, we are now losing it. That should be a very rare case
263 // and we can live with this.
264 intent.setFlags(intent.getFlags()&~Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
265 return intent;
266 }
267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800268 @Override
269 protected void onCreate(Bundle savedInstanceState) {
Christopher Tateb72b3632013-09-30 17:50:32 -0700270 // Use a specialized prompt when we're handling the 'Home' app startActivity()
Christopher Tateb72b3632013-09-30 17:50:32 -0700271 final Intent intent = makeMyIntent();
272 final Set<String> categories = intent.getCategories();
273 if (Intent.ACTION_MAIN.equals(intent.getAction())
274 && categories != null
275 && categories.size() == 1
276 && categories.contains(Intent.CATEGORY_HOME)) {
Sander Alewijnse6c9eee82014-07-17 10:03:31 +0100277 // Note: this field is not set to true in the compatibility version.
278 mResolvingHome = true;
Christopher Tateb72b3632013-09-30 17:50:32 -0700279 }
280
Dianne Hackborn028ceeb2014-08-17 17:45:48 -0700281 setSafeForwardingMode(true);
282
Adam Powella35c77a2014-09-25 16:46:36 -0700283 onCreate(savedInstanceState, intent, null, 0, null, null, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800284 }
285
Adam Powell278902c2014-07-12 18:33:22 -0700286 /**
Adam Powell24428412015-04-01 17:19:56 -0700287 * Compatibility version for other bundled services that use this overload without
Adam Powell278902c2014-07-12 18:33:22 -0700288 * a default title resource
289 */
Andrei Onea15884392019-03-22 17:28:11 +0000290 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800291 protected void onCreate(Bundle savedInstanceState, Intent intent,
Adam Powell278902c2014-07-12 18:33:22 -0700292 CharSequence title, Intent[] initialIntents,
Hakan Seyalioglu13405c52017-01-31 19:01:31 -0800293 List<ResolveInfo> rList, boolean supportsAlwaysUseOption) {
294 onCreate(savedInstanceState, intent, title, 0, initialIntents, rList,
295 supportsAlwaysUseOption);
Adam Powell278902c2014-07-12 18:33:22 -0700296 }
297
298 protected void onCreate(Bundle savedInstanceState, Intent intent,
299 CharSequence title, int defaultTitleRes, Intent[] initialIntents,
Hakan Seyalioglu13405c52017-01-31 19:01:31 -0800300 List<ResolveInfo> rList, boolean supportsAlwaysUseOption) {
Adam Powelle9414d92014-07-05 17:44:18 -0700301 setTheme(R.style.Theme_DeviceDefault_Resolver);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800302 super.onCreate(savedInstanceState);
Sander Alewijnsef6545332014-10-31 12:39:02 +0000303
304 // Determine whether we should show that intent is forwarded
305 // from managed profile to owner or other way around.
306 setProfileSwitchMessageId(intent.getContentUserHint());
307
Dianne Hackborn5320eb82012-05-18 12:05:04 -0700308 try {
Wale Ogunwale04d9cb52018-04-30 13:55:07 -0700309 mLaunchedFromUid = ActivityTaskManager.getService().getLaunchedFromUid(
Dianne Hackborn5320eb82012-05-18 12:05:04 -0700310 getActivityToken());
311 } catch (RemoteException e) {
312 mLaunchedFromUid = -1;
313 }
Adam Powell7d758002015-05-06 17:49:36 -0700314
315 if (mLaunchedFromUid < 0 || UserHandle.isIsolated(mLaunchedFromUid)) {
316 // Gulp!
317 finish();
318 return;
319 }
320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800321 mPm = getPackageManager();
Adam Powell09a65602014-07-20 16:23:14 -0700322
Dianne Hackbornd0d75032012-04-19 23:12:09 -0700323 mPackageMonitor.register(this, getMainLooper(), false);
Dianne Hackbornd44713a2012-04-30 16:34:46 -0700324 mRegistered = true;
Hakan Seyalioglue1276bf2016-12-07 16:38:57 -0800325 mReferrerPackage = getReferrerPackageName();
Dianne Hackborne8f2c7f2012-03-01 17:30:53 -0800326
Adam Powell7d758002015-05-06 17:49:36 -0700327 // Add our initial intent as the first item, regardless of what else has already been added.
Adam Powell2ed547e2015-04-29 18:45:04 -0700328 mIntents.add(0, new Intent(intent));
Hakan Seyalioglu33550122017-01-06 19:54:43 -0800329 mTitle = title;
330 mDefaultTitleResId = defaultTitleRes;
Adam Powell278902c2014-07-12 18:33:22 -0700331
shafik69df96322018-12-18 15:41:19 +0000332 mUseLayoutForBrowsables = getTargetIntent() == null
333 ? false
shafik0c7c5d52019-02-27 12:13:25 +0000334 : isHttpSchemeAndViewAction(getTargetIntent());
shafik69df96322018-12-18 15:41:19 +0000335
Matt Pietal0d6834a2019-06-27 13:27:52 -0400336 mSupportsAlwaysUseOption = supportsAlwaysUseOption;
shafik69df96322018-12-18 15:41:19 +0000337
arangelov38a6fce2019-12-02 18:21:22 +0000338 // The last argument of createResolverListAdapter is whether to do special handling
arangelovb0802dc2019-10-18 18:03:44 +0100339 // of the last used choice to highlight it in the list. We need to always
340 // turn this off when running under voice interaction, since it results in
341 // a more complicated UI that the current voice interaction flow is not able
342 // to handle.
343 boolean filterLastUsed = mSupportsAlwaysUseOption && !isVoiceInteraction();
arangelov38a6fce2019-12-02 18:21:22 +0000344 mMultiProfilePagerAdapter = createMultiProfilePagerAdapter(initialIntents, rList, filterLastUsed);
arangelovbb572332019-11-13 12:50:08 +0000345 if (configureContentView()) {
Adam Powell39e94eb2015-09-08 17:01:49 -0700346 return;
347 }
Adam Powell278902c2014-07-12 18:33:22 -0700348
Alan Viverette51efddb2017-04-05 10:00:01 -0400349 final ResolverDrawerLayout rdl = findViewById(R.id.contentPanel);
Adam Powell4f6c2052014-07-07 18:49:10 -0700350 if (rdl != null) {
Adam Powell5dd072d2014-10-30 19:51:41 -0700351 rdl.setOnDismissedListener(new ResolverDrawerLayout.OnDismissedListener() {
Adam Powell4f6c2052014-07-07 18:49:10 -0700352 @Override
Adam Powell5dd072d2014-10-30 19:51:41 -0700353 public void onDismissed() {
Adam Powell4f6c2052014-07-07 18:49:10 -0700354 finish();
355 }
356 });
Adam Powell4c470d62015-06-19 17:46:17 -0700357 if (isVoiceInteraction()) {
358 rdl.setCollapsed(false);
359 }
Matt Pietal800136a2019-05-08 07:46:39 -0400360
361 rdl.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
362 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
363 rdl.setOnApplyWindowInsetsListener(this::onApplyWindowInsets);
364
Adam Powell63b31692015-09-28 10:45:00 -0700365 mResolverDrawerLayout = rdl;
Adam Powell4f6c2052014-07-07 18:49:10 -0700366 }
367
Adam Powell88831a22014-11-20 18:17:00 -0800368 mProfileView = findViewById(R.id.profile_button);
369 if (mProfileView != null) {
Matt Pietal74c6ed02019-04-18 13:38:46 -0400370 mProfileView.setOnClickListener(this::onProfileClick);
arangelovb0802dc2019-10-18 18:03:44 +0100371 updateProfileViewButton();
Adam Powell88831a22014-11-20 18:17:00 -0800372 }
Adam Powell4c470d62015-06-19 17:46:17 -0700373
Clara Bayarri9550f5d2016-05-11 11:20:13 +0100374 final Set<String> categories = intent.getCategories();
arangelov38a6fce2019-12-02 18:21:22 +0000375 MetricsLogger.action(this, mMultiProfilePagerAdapter.getCurrentListAdapter().hasFilteredItem()
Clara Bayarrifa902aa2016-04-13 14:45:08 +0100376 ? MetricsProto.MetricsEvent.ACTION_SHOW_APP_DISAMBIG_APP_FEATURED
377 : MetricsProto.MetricsEvent.ACTION_SHOW_APP_DISAMBIG_NONE_FEATURED,
378 intent.getAction() + ":" + intent.getType() + ":"
Clara Bayarri9550f5d2016-05-11 11:20:13 +0100379 + (categories != null ? Arrays.toString(categories.toArray()) : ""));
Adam Powell4c470d62015-06-19 17:46:17 -0700380 }
381
arangelov38a6fce2019-12-02 18:21:22 +0000382 protected AbstractMultiProfilePagerAdapter createMultiProfilePagerAdapter(
383 Intent[] initialIntents,
384 List<ResolveInfo> rList,
385 boolean filterLastUsed) {
386 AbstractMultiProfilePagerAdapter resolverMultiProfilePagerAdapter = null;
387 if (hasWorkProfile() && ENABLE_TABBED_VIEW) {
388 resolverMultiProfilePagerAdapter =
389 createResolverMultiProfilePagerAdapterForTwoProfiles(
390 initialIntents, rList, filterLastUsed);
391 } else {
392 resolverMultiProfilePagerAdapter = createResolverMultiProfilePagerAdapterForOneProfile(
393 initialIntents, rList, filterLastUsed);
394 }
395 return resolverMultiProfilePagerAdapter;
396 }
397
398 private ResolverMultiProfilePagerAdapter createResolverMultiProfilePagerAdapterForOneProfile(
399 Intent[] initialIntents,
400 List<ResolveInfo> rList, boolean filterLastUsed) {
401 ResolverListAdapter adapter = createResolverListAdapter(
402 /* context */ this,
403 /* payloadIntents */ mIntents,
404 initialIntents,
405 rList,
406 filterLastUsed,
407 mUseLayoutForBrowsables,
408 /* userHandle */ UserHandle.of(UserHandle.myUserId()));
409 return new ResolverMultiProfilePagerAdapter(
410 /* context */ this,
411 adapter);
412 }
413
414 private ResolverMultiProfilePagerAdapter createResolverMultiProfilePagerAdapterForTwoProfiles(
415 Intent[] initialIntents,
416 List<ResolveInfo> rList,
417 boolean filterLastUsed) {
418 ResolverListAdapter personalAdapter = createResolverListAdapter(
419 /* context */ this,
420 /* payloadIntents */ mIntents,
421 initialIntents,
422 rList,
423 filterLastUsed,
424 mUseLayoutForBrowsables,
425 /* userHandle */ getPersonalProfileUserHandle());
426 ResolverListAdapter workAdapter = createResolverListAdapter(
427 /* context */ this,
428 /* payloadIntents */ mIntents,
429 initialIntents,
430 rList,
431 filterLastUsed,
432 mUseLayoutForBrowsables,
433 /* userHandle */ getWorkProfileUserHandle());
434 return new ResolverMultiProfilePagerAdapter(
435 /* context */ this,
436 personalAdapter,
437 workAdapter,
438 /* defaultProfile */ getCurrentProfile());
439 }
440
441 protected @Profile int getCurrentProfile() {
442 return (UserHandle.myUserId() == UserHandle.USER_SYSTEM ? PROFILE_PERSONAL : PROFILE_WORK);
443 }
444
445 protected UserHandle getPersonalProfileUserHandle() {
446 return UserHandle.of(ActivityManager.getCurrentUser());
447 }
448 protected @Nullable UserHandle getWorkProfileUserHandle() {
449 UserManager userManager = getSystemService(UserManager.class);
450 for (final UserInfo userInfo : userManager.getProfiles(ActivityManager.getCurrentUser())) {
451 if (userInfo.isManagedProfile()) {
452 return userInfo.getUserHandle();
453 }
454 }
455 return null;
456 }
457
458 protected boolean hasWorkProfile() {
459 return getWorkProfileUserHandle() != null;
460 }
461
Matt Pietal74c6ed02019-04-18 13:38:46 -0400462 protected void onProfileClick(View v) {
arangelov38a6fce2019-12-02 18:21:22 +0000463 final DisplayResolveInfo dri =
464 mMultiProfilePagerAdapter.getCurrentListAdapter().getOtherProfile();
Matt Pietal74c6ed02019-04-18 13:38:46 -0400465 if (dri == null) {
466 return;
467 }
468
469 // Do not show the profile switch message anymore.
470 mProfileSwitchMessageId = -1;
471
472 onTargetSelected(dri, false);
473 finish();
474 }
475
Matt Pietal800136a2019-05-08 07:46:39 -0400476 protected WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
477 mSystemWindowInsets = insets.getSystemWindowInsets();
478
479 mResolverDrawerLayout.setPadding(mSystemWindowInsets.left, mSystemWindowInsets.top,
480 mSystemWindowInsets.right, 0);
481
Matt Pietald5071202019-10-10 11:21:28 -0400482 // Need extra padding so the list can fully scroll up
483 if (useLayoutWithDefault()) {
484 if (mFooterSpacer == null) {
485 mFooterSpacer = new Space(getApplicationContext());
486 } else {
arangelov38a6fce2019-12-02 18:21:22 +0000487 ((ResolverMultiProfilePagerAdapter) mMultiProfilePagerAdapter)
488 .getCurrentAdapterView().removeFooterView(mFooterSpacer);
Matt Pietald5071202019-10-10 11:21:28 -0400489 }
490 mFooterSpacer.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT,
491 mSystemWindowInsets.bottom));
arangelov38a6fce2019-12-02 18:21:22 +0000492 ((ResolverMultiProfilePagerAdapter) mMultiProfilePagerAdapter)
493 .getCurrentAdapterView().addFooterView(mFooterSpacer);
Matt Pietal800136a2019-05-08 07:46:39 -0400494 } else {
Matt Pietald5071202019-10-10 11:21:28 -0400495 View emptyView = findViewById(R.id.empty);
496 if (emptyView != null) {
497 emptyView.setPadding(0, 0, 0, mSystemWindowInsets.bottom
498 + getResources().getDimensionPixelSize(
499 R.dimen.chooser_edge_margin_normal) * 2);
500 }
Matt Pietal800136a2019-05-08 07:46:39 -0400501 }
Matt Pietal800136a2019-05-08 07:46:39 -0400502
Matt Pietal78fdbd42019-06-05 07:08:08 -0400503 resetButtonBar();
504
Matt Pietal800136a2019-05-08 07:46:39 -0400505 return insets.consumeSystemWindowInsets();
506 }
507
Jiongxuan Gao3365b162016-11-24 20:20:27 +0900508 @Override
509 public void onConfigurationChanged(Configuration newConfig) {
510 super.onConfigurationChanged(newConfig);
arangelov38a6fce2019-12-02 18:21:22 +0000511 mMultiProfilePagerAdapter.getCurrentListAdapter().handlePackagesChanged();
Matt Pietal800136a2019-05-08 07:46:39 -0400512
513 if (mSystemWindowInsets != null) {
514 mResolverDrawerLayout.setPadding(mSystemWindowInsets.left, mSystemWindowInsets.top,
515 mSystemWindowInsets.right, 0);
516 }
Jiongxuan Gao3365b162016-11-24 20:20:27 +0900517 }
518
arangelovb0802dc2019-10-18 18:03:44 +0100519 @Override // ResolverListCommunicator
Adam Powell23882512016-01-29 10:21:00 -0800520 public void sendVoiceChoicesIfNeeded() {
Adam Powell4c470d62015-06-19 17:46:17 -0700521 if (!isVoiceInteraction()) {
522 // Clearly not needed.
523 return;
524 }
525
arangelov38a6fce2019-12-02 18:21:22 +0000526 int count = mMultiProfilePagerAdapter.getCurrentListAdapter().getCount();
527 final Option[] options = new Option[count];
Adam Powell4c470d62015-06-19 17:46:17 -0700528 for (int i = 0, N = options.length; i < N; i++) {
arangelov38a6fce2019-12-02 18:21:22 +0000529 TargetInfo target = mMultiProfilePagerAdapter.getCurrentListAdapter().getItem(i);
Matt Pietal2cf4c6c2019-09-10 09:33:11 -0400530 if (target == null) {
531 // If this occurs, a new set of targets is being loaded. Let that complete,
532 // and have the next call to send voice choices proceed instead.
533 return;
534 }
535 options[i] = optionForChooserTarget(target, i);
Adam Powell4c470d62015-06-19 17:46:17 -0700536 }
537
538 mPickOptionRequest = new PickTargetOptionRequest(
539 new Prompt(getTitle()), options, null);
540 getVoiceInteractor().submitRequest(mPickOptionRequest);
541 }
542
543 Option optionForChooserTarget(TargetInfo target, int index) {
544 return new Option(target.getDisplayLabel(), index);
Adam Powell88831a22014-11-20 18:17:00 -0800545 }
546
Adam Powell2ed547e2015-04-29 18:45:04 -0700547 protected final void setAdditionalTargets(Intent[] intents) {
548 if (intents != null) {
549 for (Intent intent : intents) {
550 mIntents.add(intent);
551 }
552 }
553 }
554
arangelovb0802dc2019-10-18 18:03:44 +0100555 @Override // SelectableTargetInfoCommunicator ResolverListCommunicator
Adam Powell0ccc0e92015-04-23 17:19:37 -0700556 public Intent getTargetIntent() {
Adam Powell2ed547e2015-04-29 18:45:04 -0700557 return mIntents.isEmpty() ? null : mIntents.get(0);
Adam Powell0ccc0e92015-04-23 17:19:37 -0700558 }
559
Hakan Seyalioglue1276bf2016-12-07 16:38:57 -0800560 protected String getReferrerPackageName() {
Adam Powell24428412015-04-01 17:19:56 -0700561 final Uri referrer = getReferrer();
562 if (referrer != null && "android-app".equals(referrer.getScheme())) {
563 return referrer.getHost();
564 }
565 return null;
566 }
567
Adam Powell23882512016-01-29 10:21:00 -0800568 public int getLayoutResource() {
Adam Powell24428412015-04-01 17:19:56 -0700569 return R.layout.resolver_list;
570 }
571
arangelovb0802dc2019-10-18 18:03:44 +0100572 @Override // ResolverListCommunicator
573 public void updateProfileViewButton() {
Matt Pietal74c6ed02019-04-18 13:38:46 -0400574 if (mProfileView == null) {
575 return;
576 }
577
arangelov38a6fce2019-12-02 18:21:22 +0000578 final DisplayResolveInfo dri =
579 mMultiProfilePagerAdapter.getCurrentListAdapter().getOtherProfile();
580 if (dri != null && !ENABLE_TABBED_VIEW) {
Adam Powell88831a22014-11-20 18:17:00 -0800581 mProfileView.setVisibility(View.VISIBLE);
Hakan Seyalioglu13405c52017-01-31 19:01:31 -0800582 View text = mProfileView.findViewById(R.id.profile_button);
583 if (!(text instanceof TextView)) {
584 text = mProfileView.findViewById(R.id.text1);
585 }
586 ((TextView) text).setText(dri.getDisplayLabel());
Adam Powell88831a22014-11-20 18:17:00 -0800587 } else {
588 mProfileView.setVisibility(View.GONE);
589 }
Adam Powell278902c2014-07-12 18:33:22 -0700590 }
591
Sander Alewijnsef6545332014-10-31 12:39:02 +0000592 private void setProfileSwitchMessageId(int contentUserHint) {
593 if (contentUserHint != UserHandle.USER_CURRENT &&
594 contentUserHint != UserHandle.myUserId()) {
595 UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
596 UserInfo originUserInfo = userManager.getUserInfo(contentUserHint);
597 boolean originIsManaged = originUserInfo != null ? originUserInfo.isManagedProfile()
598 : false;
599 boolean targetIsManaged = userManager.isManagedProfile();
600 if (originIsManaged && !targetIsManaged) {
601 mProfileSwitchMessageId = com.android.internal.R.string.forward_intent_to_owner;
602 } else if (!originIsManaged && targetIsManaged) {
603 mProfileSwitchMessageId = com.android.internal.R.string.forward_intent_to_work;
604 }
605 }
606 }
607
Dianne Hackborn028ceeb2014-08-17 17:45:48 -0700608 /**
609 * Turn on launch mode that is safe to use when forwarding intents received from
610 * applications and running in system processes. This mode uses Activity.startActivityAsCaller
611 * instead of the normal Activity.startActivity for launching the activity selected
612 * by the user.
613 *
614 * <p>This mode is set to true by default if the activity is initialized through
615 * {@link #onCreate(android.os.Bundle)}. If a subclass calls one of the other onCreate
616 * methods, it is set to false by default. You must set it before calling one of the
617 * more detailed onCreate methods, so that it will be set correctly in the case where
618 * there is only one intent to resolve and it is thus started immediately.</p>
619 */
620 public void setSafeForwardingMode(boolean safeForwarding) {
621 mSafeForwardingMode = safeForwarding;
622 }
623
shafik69df96322018-12-18 15:41:19 +0000624 protected CharSequence getTitleForAction(Intent intent, int defaultTitleRes) {
625 final ActionTitle title = mResolvingHome
626 ? ActionTitle.HOME
627 : ActionTitle.forAction(intent.getAction());
628
Hakan Seyalioglu23f34652017-02-03 09:38:35 -0800629 // While there may already be a filtered item, we can only use it in the title if the list
630 // is already sorted and all information relevant to it is already in the list.
arangelov38a6fce2019-12-02 18:21:22 +0000631 final boolean named =
632 mMultiProfilePagerAdapter.getCurrentListAdapter().getFilteredPosition() >= 0;
Adam Powell278902c2014-07-12 18:33:22 -0700633 if (title == ActionTitle.DEFAULT && defaultTitleRes != 0) {
634 return getString(defaultTitleRes);
shafik0c7c5d52019-02-27 12:13:25 +0000635 } else if (isHttpSchemeAndViewAction(intent)) {
636 // If the Intent's scheme is http(s) then we need to warn the user that
shafik69df96322018-12-18 15:41:19 +0000637 // they're giving access for the activity to open URLs from this specific host
Matt Pietal0d6834a2019-06-27 13:27:52 -0400638 String dialogTitle = null;
639 if (named && !mUseLayoutForBrowsables) {
640 dialogTitle = getString(ActionTitle.BROWSABLE_APP_TITLE_RES,
arangelov38a6fce2019-12-02 18:21:22 +0000641 mMultiProfilePagerAdapter.getCurrentListAdapter().getFilteredItem()
642 .getDisplayLabel());
Matt Pietal0d6834a2019-06-27 13:27:52 -0400643 } else if (named && mUseLayoutForBrowsables) {
644 dialogTitle = getString(ActionTitle.BROWSABLE_HOST_APP_TITLE_RES,
645 intent.getData().getHost(),
arangelov38a6fce2019-12-02 18:21:22 +0000646 mMultiProfilePagerAdapter.getCurrentListAdapter().getFilteredItem()
647 .getDisplayLabel());
648 } else if (mMultiProfilePagerAdapter.getCurrentListAdapter().areAllTargetsBrowsers()) {
Matt Pietald5071202019-10-10 11:21:28 -0400649 dialogTitle = getString(ActionTitle.BROWSABLE_TITLE_RES);
Matt Pietal0d6834a2019-06-27 13:27:52 -0400650 } else {
651 dialogTitle = getString(ActionTitle.BROWSABLE_HOST_TITLE_RES,
652 intent.getData().getHost());
653 }
654 return dialogTitle;
Adam Powell278902c2014-07-12 18:33:22 -0700655 } else {
Adam Powell24428412015-04-01 17:19:56 -0700656 return named
arangelov38a6fce2019-12-02 18:21:22 +0000657 ? getString(title.namedTitleRes, mMultiProfilePagerAdapter
658 .getCurrentListAdapter().getFilteredItem().getDisplayLabel())
Adam Powell24428412015-04-01 17:19:56 -0700659 : getString(title.titleRes);
Amith Yamasanie9ecc8b2013-08-22 11:16:27 -0700660 }
Adam Powellc5878612012-05-04 18:42:38 -0700661 }
662
Adam Powelle9414d92014-07-05 17:44:18 -0700663 void dismiss() {
664 if (!isFinishing()) {
665 finish();
666 }
667 }
668
Dianne Hackborne8f2c7f2012-03-01 17:30:53 -0800669 @Override
670 protected void onRestart() {
671 super.onRestart();
Dianne Hackbornd44713a2012-04-30 16:34:46 -0700672 if (!mRegistered) {
673 mPackageMonitor.register(this, getMainLooper(), false);
674 mRegistered = true;
675 }
arangelov38a6fce2019-12-02 18:21:22 +0000676 mMultiProfilePagerAdapter.getCurrentListAdapter().handlePackagesChanged();
arangelovb0802dc2019-10-18 18:03:44 +0100677 updateProfileViewButton();
Dianne Hackborne8f2c7f2012-03-01 17:30:53 -0800678 }
679
680 @Override
681 protected void onStop() {
682 super.onStop();
Dianne Hackbornd44713a2012-04-30 16:34:46 -0700683 if (mRegistered) {
684 mPackageMonitor.unregister();
685 mRegistered = false;
686 }
Wale Ogunwale9014e662016-03-19 14:55:46 -0700687 final Intent intent = getIntent();
688 if ((intent.getFlags() & FLAG_ACTIVITY_NEW_TASK) != 0 && !isVoiceInteraction()
Jorim Jaggif631ef72017-02-24 13:49:47 +0100689 && !mResolvingHome && !mRetainInOnStop) {
Dianne Hackborn5320eb82012-05-18 12:05:04 -0700690 // This resolver is in the unusual situation where it has been
691 // launched at the top of a new task. We don't let it be added
692 // to the recent tasks shown to the user, and we need to make sure
693 // that each time we are launched we get the correct launching
694 // uid (not re-using the same resolver from an old launching uid),
695 // so we will now finish ourself since being no longer visible,
696 // the user probably can't get back to us.
697 if (!isChangingConfigurations()) {
698 finish();
699 }
700 }
Dianne Hackborne8f2c7f2012-03-01 17:30:53 -0800701 }
702
Adam Powellc5878612012-05-04 18:42:38 -0700703 @Override
Adam Powell4c470d62015-06-19 17:46:17 -0700704 protected void onDestroy() {
705 super.onDestroy();
706 if (!isChangingConfigurations() && mPickOptionRequest != null) {
707 mPickOptionRequest.cancel();
708 }
arangelov38a6fce2019-12-02 18:21:22 +0000709 if (mMultiProfilePagerAdapter.getCurrentListAdapter() != null) {
710 mMultiProfilePagerAdapter.getCurrentListAdapter().onDestroy();
Kang Li38a6da642017-04-05 12:30:55 -0700711 }
Adam Powell4c470d62015-06-19 17:46:17 -0700712 }
713
714 @Override
Adam Powell9bee4662012-05-08 11:07:23 -0700715 protected void onRestoreInstanceState(Bundle savedInstanceState) {
716 super.onRestoreInstanceState(savedInstanceState);
shafik69df96322018-12-18 15:41:19 +0000717 resetButtonBar();
Adam Powell9bee4662012-05-08 11:07:23 -0700718 }
719
shafik0c7c5d52019-02-27 12:13:25 +0000720 private boolean isHttpSchemeAndViewAction(Intent intent) {
721 return (IntentFilter.SCHEME_HTTP.equals(intent.getScheme())
722 || IntentFilter.SCHEME_HTTPS.equals(intent.getScheme()))
723 && Intent.ACTION_VIEW.equals(intent.getAction());
724 }
725
Sander Alewijnse6c9eee82014-07-17 10:03:31 +0100726 private boolean hasManagedProfile() {
727 UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
728 if (userManager == null) {
729 return false;
730 }
731
732 try {
733 List<UserInfo> profiles = userManager.getProfiles(getUserId());
734 for (UserInfo userInfo : profiles) {
735 if (userInfo != null && userInfo.isManagedProfile()) {
736 return true;
737 }
738 }
739 } catch (SecurityException e) {
740 return false;
741 }
742 return false;
743 }
744
745 private boolean supportsManagedProfiles(ResolveInfo resolveInfo) {
746 try {
747 ApplicationInfo appInfo = getPackageManager().getApplicationInfo(
748 resolveInfo.activityInfo.packageName, 0 /* default flags */);
Adam Powell4c470d62015-06-19 17:46:17 -0700749 return appInfo.targetSdkVersion >= Build.VERSION_CODES.LOLLIPOP;
Sander Alewijnse6c9eee82014-07-17 10:03:31 +0100750 } catch (NameNotFoundException e) {
751 return false;
752 }
753 }
754
Adam Powell278902c2014-07-12 18:33:22 -0700755 private void setAlwaysButtonEnabled(boolean hasValidSelection, int checkedPos,
756 boolean filtered) {
Nicolas Prevot50449882014-06-23 12:42:37 +0100757 boolean enabled = false;
Paul McLean3a30e552019-12-07 14:47:29 -0700758 ResolveInfo ri = null;
Nicolas Prevot50449882014-06-23 12:42:37 +0100759 if (hasValidSelection) {
arangelov38a6fce2019-12-02 18:21:22 +0000760 ri = mMultiProfilePagerAdapter.getCurrentListAdapter()
761 .resolveInfoForPosition(checkedPos, filtered);
Hakan Seyalioglu5dbc8192017-02-24 16:16:37 -0800762 if (ri == null) {
763 Log.e(TAG, "Invalid position supplied to setAlwaysButtonEnabled");
764 return;
765 } else if (ri.targetUserId != UserHandle.USER_CURRENT) {
766 Log.e(TAG, "Attempted to set selection to resolve info for another user");
767 return;
768 } else {
Nicolas Prevot50449882014-06-23 12:42:37 +0100769 enabled = true;
770 }
Matt Pietal0d6834a2019-06-27 13:27:52 -0400771 if (mUseLayoutForBrowsables && !ri.handleAllWebDataURI) {
772 mAlwaysButton.setText(getResources()
773 .getString(R.string.activity_resolver_set_always));
774 } else {
775 mAlwaysButton.setText(getResources()
776 .getString(R.string.activity_resolver_use_always));
777 }
Nicolas Prevot50449882014-06-23 12:42:37 +0100778 }
Paul McLean3a30e552019-12-07 14:47:29 -0700779
780 ActivityInfo activityInfo = ri.activityInfo;
781
782 boolean hasRecordPermission =
783 PermissionChecker.checkPermissionForPreflight(
784 getApplicationContext(),
785 android.Manifest.permission.RECORD_AUDIO, -1,
786 activityInfo.applicationInfo.uid,
787 activityInfo.packageName)
788 == android.content.pm.PackageManager.PERMISSION_GRANTED;
789
790 if (!hasRecordPermission) {
791 // OK, we know the record permission, is this a capture device
792 boolean hasAudioCapture =
793 getIntent().getBooleanExtra(
794 ResolverActivity.EXTRA_IS_AUDIO_CAPTURE_DEVICE, false);
795 enabled = !hasAudioCapture;
796 }
Nicolas Prevot50449882014-06-23 12:42:37 +0100797 mAlwaysButton.setEnabled(enabled);
798 }
799
Adam Powellc5878612012-05-04 18:42:38 -0700800 public void onButtonClick(View v) {
801 final int id = v.getId();
arangelov38a6fce2019-12-02 18:21:22 +0000802 ListView listView = (ListView) mMultiProfilePagerAdapter.getCurrentAdapterView();
803 ResolverListAdapter currentListAdapter = mMultiProfilePagerAdapter.getCurrentListAdapter();
804 int which = currentListAdapter.hasFilteredItem()
805 ? currentListAdapter.getFilteredPosition()
806 : listView.getCheckedItemPosition();
807 boolean hasIndexBeenFiltered = !currentListAdapter.hasFilteredItem();
808 ResolveInfo ri = currentListAdapter.resolveInfoForPosition(which, hasIndexBeenFiltered);
Matt Pietala310c1f2019-07-03 09:12:56 -0400809 if (mUseLayoutForBrowsables
810 && !ri.handleAllWebDataURI && id == R.id.button_always) {
Matt Pietal0d6834a2019-06-27 13:27:52 -0400811 showSettingsForSelected(ri);
shafik69df96322018-12-18 15:41:19 +0000812 } else {
813 startSelected(which, id == R.id.button_always, hasIndexBeenFiltered);
814 }
815 }
816
Matt Pietal0d6834a2019-06-27 13:27:52 -0400817 private void showSettingsForSelected(ResolveInfo ri) {
shafik34064c32019-03-06 15:42:52 +0000818 Intent intent = new Intent();
Matt Pietal0d6834a2019-06-27 13:27:52 -0400819
820 final String packageName = ri.activityInfo.packageName;
821 Bundle showFragmentArgs = new Bundle();
822 showFragmentArgs.putString(EXTRA_FRAGMENT_ARG_KEY, OPEN_LINKS_COMPONENT_KEY);
823 showFragmentArgs.putString("package", packageName);
824
shafik34064c32019-03-06 15:42:52 +0000825 // For regular apps, we open the Open by Default page
Matt Pietal0d6834a2019-06-27 13:27:52 -0400826 intent.setAction(Settings.ACTION_APP_OPEN_BY_DEFAULT_SETTINGS)
827 .setData(Uri.fromParts("package", packageName, null))
828 .addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT)
829 .putExtra(EXTRA_FRAGMENT_ARG_KEY, OPEN_LINKS_COMPONENT_KEY)
830 .putExtra(EXTRA_SHOW_FRAGMENT_ARGS, showFragmentArgs);
831
shafik34064c32019-03-06 15:42:52 +0000832 startActivity(intent);
Adam Powellc5878612012-05-04 18:42:38 -0700833 }
834
Hakan Seyalioglu13405c52017-01-31 19:01:31 -0800835 public void startSelected(int which, boolean always, boolean hasIndexBeenFiltered) {
Amith Yamasani07cd3512013-09-18 13:16:00 -0700836 if (isFinishing()) {
837 return;
838 }
arangelov38a6fce2019-12-02 18:21:22 +0000839 ResolveInfo ri = mMultiProfilePagerAdapter.getCurrentListAdapter()
840 .resolveInfoForPosition(which, hasIndexBeenFiltered);
Sander Alewijnse86d35ba2015-02-04 15:14:53 +0000841 if (mResolvingHome && hasManagedProfile() && !supportsManagedProfiles(ri)) {
842 Toast.makeText(this, String.format(getResources().getString(
843 com.android.internal.R.string.activity_resolver_work_profiles_support),
844 ri.activityInfo.loadLabel(getPackageManager()).toString()),
845 Toast.LENGTH_LONG).show();
846 return;
847 }
848
arangelov38a6fce2019-12-02 18:21:22 +0000849 TargetInfo target = mMultiProfilePagerAdapter.getCurrentListAdapter()
850 .targetInfoForPosition(which, hasIndexBeenFiltered);
Hakan Seyalioglu23f34652017-02-03 09:38:35 -0800851 if (target == null) {
852 return;
853 }
Adam Powell2ed547e2015-04-29 18:45:04 -0700854 if (onTargetSelected(target, always)) {
Hakan Seyalioglu13405c52017-01-31 19:01:31 -0800855 if (always && mSupportsAlwaysUseOption) {
Clara Bayarrifa902aa2016-04-13 14:45:08 +0100856 MetricsLogger.action(
857 this, MetricsProto.MetricsEvent.ACTION_APP_DISAMBIG_ALWAYS);
Hakan Seyalioglu13405c52017-01-31 19:01:31 -0800858 } else if (mSupportsAlwaysUseOption) {
Clara Bayarrifa902aa2016-04-13 14:45:08 +0100859 MetricsLogger.action(
860 this, MetricsProto.MetricsEvent.ACTION_APP_DISAMBIG_JUST_ONCE);
861 } else {
862 MetricsLogger.action(
863 this, MetricsProto.MetricsEvent.ACTION_APP_DISAMBIG_TAP);
864 }
arangelov38a6fce2019-12-02 18:21:22 +0000865 MetricsLogger.action(this,
866 mMultiProfilePagerAdapter.getCurrentListAdapter().hasFilteredItem()
Clara Bayarrifa902aa2016-04-13 14:45:08 +0100867 ? MetricsProto.MetricsEvent.ACTION_HIDE_APP_DISAMBIG_APP_FEATURED
868 : MetricsProto.MetricsEvent.ACTION_HIDE_APP_DISAMBIG_NONE_FEATURED);
Adam Powell2ed547e2015-04-29 18:45:04 -0700869 finish();
870 }
Mike Lockwood02eb8742011-02-27 09:10:37 -0800871 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800872
Adam Powelle49d9392014-07-17 18:45:19 -0700873 /**
874 * Replace me in subclasses!
875 */
arangelovb0802dc2019-10-18 18:03:44 +0100876 @Override // ResolverListCommunicator
Nicolas Prevot0e2b73f2014-10-27 10:06:11 +0000877 public Intent getReplacementIntent(ActivityInfo aInfo, Intent defIntent) {
Adam Powelle49d9392014-07-17 18:45:19 -0700878 return defIntent;
879 }
880
arangelovb0802dc2019-10-18 18:03:44 +0100881 @Override // ResolverListCommunicator
882 public void onPostListReady() {
883 setHeader();
884 resetButtonBar();
885 onListRebuilt();
886 }
887
888 protected void onListRebuilt() {
arangelov38a6fce2019-12-02 18:21:22 +0000889 int count = mMultiProfilePagerAdapter.getCurrentListAdapter().getUnfilteredCount();
890 if (count == 1 && mMultiProfilePagerAdapter.getCurrentListAdapter().getOtherProfile() == null) {
arangelovb0802dc2019-10-18 18:03:44 +0100891 // Only one target, so we're a candidate to auto-launch!
arangelov38a6fce2019-12-02 18:21:22 +0000892 final TargetInfo target =
893 mMultiProfilePagerAdapter.getCurrentListAdapter().targetInfoForPosition(0, false);
arangelovb0802dc2019-10-18 18:03:44 +0100894 if (shouldAutoLaunchSingleChoice(target)) {
895 safelyStartActivity(target);
896 finish();
897 }
898 }
899 }
900
Adam Powell2ed547e2015-04-29 18:45:04 -0700901 protected boolean onTargetSelected(TargetInfo target, boolean alwaysCheck) {
Adam Powell24428412015-04-01 17:19:56 -0700902 final ResolveInfo ri = target.getResolveInfo();
903 final Intent intent = target != null ? target.getResolvedIntent() : null;
904
arangelov38a6fce2019-12-02 18:21:22 +0000905 if (intent != null && (mSupportsAlwaysUseOption
906 || mMultiProfilePagerAdapter.getCurrentListAdapter().hasFilteredItem())
907 && mMultiProfilePagerAdapter.getCurrentListAdapter().getUnfilteredResolveList() != null) {
Amith Yamasani588dd2a2013-09-03 12:30:44 -0700908 // Build a reasonable intent filter, based on what matched.
909 IntentFilter filter = new IntentFilter();
Henrik Engström3277cf12014-07-17 12:18:29 +0200910 Intent filterIntent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800911
Henrik Engström3277cf12014-07-17 12:18:29 +0200912 if (intent.getSelector() != null) {
913 filterIntent = intent.getSelector();
914 } else {
915 filterIntent = intent;
916 }
917
918 String action = filterIntent.getAction();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -0800919 if (action != null) {
920 filter.addAction(action);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800921 }
Henrik Engström3277cf12014-07-17 12:18:29 +0200922 Set<String> categories = filterIntent.getCategories();
Amith Yamasani588dd2a2013-09-03 12:30:44 -0700923 if (categories != null) {
924 for (String cat : categories) {
925 filter.addCategory(cat);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800926 }
927 }
Amith Yamasani588dd2a2013-09-03 12:30:44 -0700928 filter.addCategory(Intent.CATEGORY_DEFAULT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800929
Adam Powell24428412015-04-01 17:19:56 -0700930 int cat = ri.match & IntentFilter.MATCH_CATEGORY_MASK;
Henrik Engström3277cf12014-07-17 12:18:29 +0200931 Uri data = filterIntent.getData();
Amith Yamasani588dd2a2013-09-03 12:30:44 -0700932 if (cat == IntentFilter.MATCH_CATEGORY_TYPE) {
Henrik Engström3277cf12014-07-17 12:18:29 +0200933 String mimeType = filterIntent.resolveType(this);
Amith Yamasani588dd2a2013-09-03 12:30:44 -0700934 if (mimeType != null) {
935 try {
936 filter.addDataType(mimeType);
937 } catch (IntentFilter.MalformedMimeTypeException e) {
938 Log.w("ResolverActivity", e);
939 filter = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800940 }
941 }
Amith Yamasani588dd2a2013-09-03 12:30:44 -0700942 }
943 if (data != null && data.getScheme() != null) {
944 // We need the data specification if there was no type,
945 // OR if the scheme is not one of our magical "file:"
946 // or "content:" schemes (see IntentFilter for the reason).
947 if (cat != IntentFilter.MATCH_CATEGORY_TYPE
948 || (!"file".equals(data.getScheme())
949 && !"content".equals(data.getScheme()))) {
950 filter.addDataScheme(data.getScheme());
951
952 // Look through the resolved filter to determine which part
953 // of it matched the original Intent.
954 Iterator<PatternMatcher> pIt = ri.filter.schemeSpecificPartsIterator();
955 if (pIt != null) {
956 String ssp = data.getSchemeSpecificPart();
957 while (ssp != null && pIt.hasNext()) {
958 PatternMatcher p = pIt.next();
959 if (p.match(ssp)) {
960 filter.addDataSchemeSpecificPart(p.getPath(), p.getType());
961 break;
962 }
Dianne Hackborndf1c0bf2013-06-12 16:21:38 -0700963 }
964 }
Amith Yamasani588dd2a2013-09-03 12:30:44 -0700965 Iterator<IntentFilter.AuthorityEntry> aIt = ri.filter.authoritiesIterator();
966 if (aIt != null) {
967 while (aIt.hasNext()) {
968 IntentFilter.AuthorityEntry a = aIt.next();
969 if (a.match(data) >= 0) {
970 int port = a.getPort();
971 filter.addDataAuthority(a.getHost(),
972 port >= 0 ? Integer.toString(port) : null);
973 break;
974 }
975 }
976 }
977 pIt = ri.filter.pathsIterator();
978 if (pIt != null) {
979 String path = data.getPath();
980 while (path != null && pIt.hasNext()) {
981 PatternMatcher p = pIt.next();
982 if (p.match(path)) {
983 filter.addDataPath(p.getPath(), p.getType());
984 break;
985 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800986 }
987 }
988 }
989 }
990
Amith Yamasani588dd2a2013-09-03 12:30:44 -0700991 if (filter != null) {
arangelov38a6fce2019-12-02 18:21:22 +0000992 final int N = mMultiProfilePagerAdapter.getCurrentListAdapter()
993 .getUnfilteredResolveList().size();
Hakan Seyalioglu13405c52017-01-31 19:01:31 -0800994 ComponentName[] set;
995 // If we don't add back in the component for forwarding the intent to a managed
996 // profile, the preferred activity may not be updated correctly (as the set of
997 // components we tell it we knew about will have changed).
arangelovb0802dc2019-10-18 18:03:44 +0100998 final boolean needToAddBackProfileForwardingComponent =
arangelov38a6fce2019-12-02 18:21:22 +0000999 mMultiProfilePagerAdapter.getCurrentListAdapter().getOtherProfile() != null;
Hakan Seyalioglu13405c52017-01-31 19:01:31 -08001000 if (!needToAddBackProfileForwardingComponent) {
1001 set = new ComponentName[N];
1002 } else {
1003 set = new ComponentName[N + 1];
1004 }
1005
Amith Yamasani588dd2a2013-09-03 12:30:44 -07001006 int bestMatch = 0;
1007 for (int i=0; i<N; i++) {
arangelov38a6fce2019-12-02 18:21:22 +00001008 ResolveInfo r = mMultiProfilePagerAdapter.getCurrentListAdapter()
1009 .getUnfilteredResolveList().get(i).getResolveInfoAt(0);
Amith Yamasani588dd2a2013-09-03 12:30:44 -07001010 set[i] = new ComponentName(r.activityInfo.packageName,
1011 r.activityInfo.name);
1012 if (r.match > bestMatch) bestMatch = r.match;
1013 }
Hakan Seyalioglu13405c52017-01-31 19:01:31 -08001014
1015 if (needToAddBackProfileForwardingComponent) {
arangelov38a6fce2019-12-02 18:21:22 +00001016 set[N] = mMultiProfilePagerAdapter.getCurrentListAdapter()
1017 .getOtherProfile().getResolvedComponentName();
1018 final int otherProfileMatch = mMultiProfilePagerAdapter.getCurrentListAdapter()
1019 .getOtherProfile().getResolveInfo().match;
Hakan Seyalioglu13405c52017-01-31 19:01:31 -08001020 if (otherProfileMatch > bestMatch) bestMatch = otherProfileMatch;
1021 }
1022
Amith Yamasani588dd2a2013-09-03 12:30:44 -07001023 if (alwaysCheck) {
Fabrice Di Meglio3453e082015-05-11 17:46:23 -07001024 final int userId = getUserId();
1025 final PackageManager pm = getPackageManager();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001026
1027 // Set the preferred Activity
1028 pm.addPreferredActivity(filter, bestMatch, set, intent.getComponent());
1029
Fabrice Di Meglio3453e082015-05-11 17:46:23 -07001030 if (ri.handleAllWebDataURI) {
1031 // Set default Browser if needed
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001032 final String packageName = pm.getDefaultBrowserPackageNameAsUser(userId);
Fabrice Di Meglio3453e082015-05-11 17:46:23 -07001033 if (TextUtils.isEmpty(packageName)) {
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001034 pm.setDefaultBrowserPackageNameAsUser(ri.activityInfo.packageName, userId);
Fabrice Di Meglio3453e082015-05-11 17:46:23 -07001035 }
1036 } else {
1037 // Update Domain Verification status
1038 ComponentName cn = intent.getComponent();
1039 String packageName = cn.getPackageName();
1040 String dataScheme = (data != null) ? data.getScheme() : null;
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001041
Fabrice Di Meglio3453e082015-05-11 17:46:23 -07001042 boolean isHttpOrHttps = (dataScheme != null) &&
1043 (dataScheme.equals(IntentFilter.SCHEME_HTTP) ||
1044 dataScheme.equals(IntentFilter.SCHEME_HTTPS));
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001045
Fabrice Di Meglio3453e082015-05-11 17:46:23 -07001046 boolean isViewAction = (action != null) && action.equals(Intent.ACTION_VIEW);
1047 boolean hasCategoryBrowsable = (categories != null) &&
1048 categories.contains(Intent.CATEGORY_BROWSABLE);
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001049
Fabrice Di Meglio3453e082015-05-11 17:46:23 -07001050 if (isHttpOrHttps && isViewAction && hasCategoryBrowsable) {
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001051 pm.updateIntentVerificationStatusAsUser(packageName,
Fabrice Di Meglio3453e082015-05-11 17:46:23 -07001052 PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS,
1053 userId);
1054 }
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001055 }
Amith Yamasani588dd2a2013-09-03 12:30:44 -07001056 } else {
1057 try {
arangelov38a6fce2019-12-02 18:21:22 +00001058 mMultiProfilePagerAdapter.getCurrentListAdapter()
1059 .mResolverListController.setLastChosen(intent, filter, bestMatch);
Amith Yamasani588dd2a2013-09-03 12:30:44 -07001060 } catch (RemoteException re) {
1061 Log.d(TAG, "Error calling setLastChosenActivity\n" + re);
1062 }
Amith Yamasanie9ecc8b2013-08-22 11:16:27 -07001063 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001064 }
1065 }
1066
Adam Powell24428412015-04-01 17:19:56 -07001067 if (target != null) {
1068 safelyStartActivity(target);
Matt Pietala4b30072019-04-04 13:44:36 -04001069
1070 // Rely on the ActivityManager to pop up a dialog regarding app suspension
1071 // and return false
1072 if (target.isSuspended()) {
1073 return false;
1074 }
Dianne Hackborn028ceeb2014-08-17 17:45:48 -07001075 }
Matt Pietala4b30072019-04-04 13:44:36 -04001076
Adam Powell2ed547e2015-04-29 18:45:04 -07001077 return true;
Dianne Hackborn028ceeb2014-08-17 17:45:48 -07001078 }
1079
Adam Powell23882512016-01-29 10:21:00 -08001080 public void safelyStartActivity(TargetInfo cti) {
Jeff Sharkey2b9eb892016-02-16 09:21:51 -07001081 // We're dispatching intents that might be coming from legacy apps, so
1082 // don't kill ourselves.
1083 StrictMode.disableDeathOnFileUriExposure();
1084 try {
1085 safelyStartActivityInternal(cti);
1086 } finally {
1087 StrictMode.enableDeathOnFileUriExposure();
1088 }
1089 }
1090
1091 private void safelyStartActivityInternal(TargetInfo cti) {
Sander Alewijnsef6545332014-10-31 12:39:02 +00001092 // If needed, show that intent is forwarded
1093 // from managed profile to owner or other way around.
1094 if (mProfileSwitchMessageId != -1) {
1095 Toast.makeText(this, getString(mProfileSwitchMessageId), Toast.LENGTH_LONG).show();
1096 }
arangelov38a6fce2019-12-02 18:21:22 +00001097 UserHandle currentUserHandle = mMultiProfilePagerAdapter.getCurrentUserHandle();
Dianne Hackborn028ceeb2014-08-17 17:45:48 -07001098 if (!mSafeForwardingMode) {
arangelov38a6fce2019-12-02 18:21:22 +00001099 if (cti.startAsUser(this, null, currentUserHandle)) {
Adam Powell24428412015-04-01 17:19:56 -07001100 onActivityStarted(cti);
1101 }
Dianne Hackborn028ceeb2014-08-17 17:45:48 -07001102 return;
1103 }
1104 try {
arangelov38a6fce2019-12-02 18:21:22 +00001105 if (cti.startAsCaller(this, null, currentUserHandle.getIdentifier())) {
Adam Powell24428412015-04-01 17:19:56 -07001106 onActivityStarted(cti);
1107 }
Dianne Hackborn028ceeb2014-08-17 17:45:48 -07001108 } catch (RuntimeException e) {
1109 String launchedFromPackage;
1110 try {
Wale Ogunwale04d9cb52018-04-30 13:55:07 -07001111 launchedFromPackage = ActivityTaskManager.getService().getLaunchedFromPackage(
Dianne Hackborn028ceeb2014-08-17 17:45:48 -07001112 getActivityToken());
1113 } catch (RemoteException e2) {
1114 launchedFromPackage = "??";
1115 }
1116 Slog.wtf(TAG, "Unable to launch as uid " + mLaunchedFromUid
1117 + " package " + launchedFromPackage + ", while running in "
1118 + ActivityThread.currentProcessName(), e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001119 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001120 }
1121
Alison Cichowlas3e340502018-08-07 17:15:01 -04001122
arangelovb0802dc2019-10-18 18:03:44 +01001123 public boolean startAsCallerImpl(Intent intent, Bundle options, boolean ignoreTargetSecurity,
Alison Cichowlas3e340502018-08-07 17:15:01 -04001124 int userId) {
1125 // Pass intent to delegate chooser activity with permission token.
1126 // TODO: This should move to a trampoline Activity in the system when the ChooserActivity
1127 // moves into systemui
1128 try {
1129 // TODO: Once this is a small springboard activity, it can move off the UI process
1130 // and we can move the request method to ActivityManagerInternal.
1131 IBinder permissionToken = ActivityTaskManager.getService()
1132 .requestStartActivityPermissionToken(getActivityToken());
1133 final Intent chooserIntent = new Intent();
1134 final ComponentName delegateActivity = ComponentName.unflattenFromString(
1135 Resources.getSystem().getString(R.string.config_chooserActivity));
1136 chooserIntent.setClassName(delegateActivity.getPackageName(),
1137 delegateActivity.getClassName());
1138 chooserIntent.putExtra(ActivityTaskManager.EXTRA_PERMISSION_TOKEN, permissionToken);
1139
1140 // TODO: These extras will change as chooser activity moves into systemui
1141 chooserIntent.putExtra(Intent.EXTRA_INTENT, intent);
1142 chooserIntent.putExtra(ActivityTaskManager.EXTRA_OPTIONS, options);
1143 chooserIntent.putExtra(ActivityTaskManager.EXTRA_IGNORE_TARGET_SECURITY,
1144 ignoreTargetSecurity);
1145 chooserIntent.putExtra(Intent.EXTRA_USER_ID, userId);
Alison Cichowlas7b6f3b62018-12-07 09:06:57 -05001146 chooserIntent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT
1147 | Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP);
Alison Cichowlas3e340502018-08-07 17:15:01 -04001148 startActivity(chooserIntent);
1149 } catch (RemoteException e) {
1150 Log.e(TAG, e.toString());
1151 }
1152 return true;
1153 }
1154
Adam Powell23882512016-01-29 10:21:00 -08001155 public void onActivityStarted(TargetInfo cti) {
Adam Powell0b3c1122014-10-09 12:50:14 -07001156 // Do nothing
1157 }
1158
arangelovb0802dc2019-10-18 18:03:44 +01001159 @Override // ResolverListCommunicator
Adam Powell23882512016-01-29 10:21:00 -08001160 public boolean shouldGetActivityMetadata() {
Adam Powell24428412015-04-01 17:19:56 -07001161 return false;
1162 }
1163
Adam Powell23882512016-01-29 10:21:00 -08001164 public boolean shouldAutoLaunchSingleChoice(TargetInfo target) {
Matt Pietala4b30072019-04-04 13:44:36 -04001165 return !target.isSuspended();
Adam Powell39e94eb2015-09-08 17:01:49 -07001166 }
1167
Adam Powell23882512016-01-29 10:21:00 -08001168 public void showTargetDetails(ResolveInfo ri) {
Dianne Hackborn028ceeb2014-08-17 17:45:48 -07001169 Intent in = new Intent().setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
Adam Powell0fc5b2b2012-07-18 18:20:29 -07001170 .setData(Uri.fromParts("package", ri.activityInfo.packageName, null))
Adam Powell24428412015-04-01 17:19:56 -07001171 .addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
Amith Yamasani203a2f42012-10-03 20:16:40 -07001172 startActivity(in);
Adam Powellc5878612012-05-04 18:42:38 -07001173 }
1174
arangelov38a6fce2019-12-02 18:21:22 +00001175 @VisibleForTesting
1176 protected ResolverListAdapter createResolverListAdapter(Context context,
1177 List<Intent> payloadIntents, Intent[] initialIntents, List<ResolveInfo> rList,
1178 boolean filterLastUsed, boolean useLayoutForBrowsables, UserHandle userHandle) {
Paul McLean07425c82019-10-18 12:00:11 -06001179 Intent startIntent = getIntent();
1180 boolean isAudioCaptureDevice =
1181 startIntent.getBooleanExtra(EXTRA_IS_AUDIO_CAPTURE_DEVICE, false);
arangelovb0802dc2019-10-18 18:03:44 +01001182 return new ResolverListAdapter(context, payloadIntents, initialIntents, rList,
arangelov38a6fce2019-12-02 18:21:22 +00001183 filterLastUsed, createListController(userHandle), useLayoutForBrowsables, this,
Paul McLean07425c82019-10-18 12:00:11 -06001184 isAudioCaptureDevice);
Hakan Seyalioglue1276bf2016-12-07 16:38:57 -08001185 }
1186
1187 @VisibleForTesting
arangelov38a6fce2019-12-02 18:21:22 +00001188 protected ResolverListController createListController(UserHandle userHandle) {
Hakan Seyalioglue1276bf2016-12-07 16:38:57 -08001189 return new ResolverListController(
1190 this,
1191 mPm,
1192 getTargetIntent(),
1193 getReferrerPackageName(),
arangelov38a6fce2019-12-02 18:21:22 +00001194 mLaunchedFromUid,
1195 userHandle);
Adam Powell88831a22014-11-20 18:17:00 -08001196 }
1197
Adam Powell39e94eb2015-09-08 17:01:49 -07001198 /**
arangelovb0802dc2019-10-18 18:03:44 +01001199 * Sets up the content view.
arangelovbb572332019-11-13 12:50:08 +00001200 * @return <code>true</code> if the activity is finishing and creation should halt.
Adam Powell39e94eb2015-09-08 17:01:49 -07001201 */
arangelovbb572332019-11-13 12:50:08 +00001202 private boolean configureContentView() {
arangelov38a6fce2019-12-02 18:21:22 +00001203 if (mMultiProfilePagerAdapter.getCurrentListAdapter() == null) {
arangelovb0802dc2019-10-18 18:03:44 +01001204 throw new IllegalStateException("mAdapter cannot be null.");
1205 }
arangelov38a6fce2019-12-02 18:21:22 +00001206 boolean rebuildCompleted = mMultiProfilePagerAdapter.getCurrentListAdapter().rebuildList();
Hakan Seyalioglu13405c52017-01-31 19:01:31 -08001207 if (useLayoutWithDefault()) {
Hakan Seyalioglue1276bf2016-12-07 16:38:57 -08001208 mLayoutId = R.layout.resolver_list_with_default;
Adam Powell7d758002015-05-06 17:49:36 -07001209 } else {
Hakan Seyalioglue1276bf2016-12-07 16:38:57 -08001210 mLayoutId = getLayoutResource();
Adam Powell7d758002015-05-06 17:49:36 -07001211 }
Hakan Seyalioglu13405c52017-01-31 19:01:31 -08001212 setContentView(mLayoutId);
arangelov38a6fce2019-12-02 18:21:22 +00001213 mMultiProfilePagerAdapter.setupViewPager(findViewById(R.id.profile_pager));
arangelovbb572332019-11-13 12:50:08 +00001214 return postRebuildList(rebuildCompleted);
arangelovb0802dc2019-10-18 18:03:44 +01001215 }
Adam Powell7d758002015-05-06 17:49:36 -07001216
arangelovb0802dc2019-10-18 18:03:44 +01001217 /**
arangelovbb572332019-11-13 12:50:08 +00001218 * Finishing procedures to be performed after the list has been rebuilt.
1219 * </p>Subclasses must call postRebuildListInternal at the end of postRebuildList.
1220 * @param rebuildCompleted
1221 * @return <code>true</code> if the activity is finishing and creation should halt.
arangelovb0802dc2019-10-18 18:03:44 +01001222 */
arangelovbb572332019-11-13 12:50:08 +00001223 protected boolean postRebuildList(boolean rebuildCompleted) {
1224 return postRebuildListInternal(rebuildCompleted);
arangelovb0802dc2019-10-18 18:03:44 +01001225 }
1226
1227 /**
arangelovbb572332019-11-13 12:50:08 +00001228 * Finishing procedures to be performed after the list has been rebuilt.
1229 * @param rebuildCompleted
1230 * @return <code>true</code> if the activity is finishing and creation should halt.
arangelovb0802dc2019-10-18 18:03:44 +01001231 */
arangelovbb572332019-11-13 12:50:08 +00001232 final boolean postRebuildListInternal(boolean rebuildCompleted) {
1233
arangelov38a6fce2019-12-02 18:21:22 +00001234 int count = mMultiProfilePagerAdapter.getCurrentListAdapter().getUnfilteredCount();
Hakan Seyalioglue1276bf2016-12-07 16:38:57 -08001235
1236 // We only rebuild asynchronously when we have multiple elements to sort. In the case where
1237 // we're already done, we can check if we should auto-launch immediately.
1238 if (rebuildCompleted) {
arangelov38a6fce2019-12-02 18:21:22 +00001239 if (count == 1
1240 && mMultiProfilePagerAdapter.getCurrentListAdapter().getOtherProfile() == null) {
Hakan Seyalioglue1276bf2016-12-07 16:38:57 -08001241 // Only one target, so we're a candidate to auto-launch!
arangelov38a6fce2019-12-02 18:21:22 +00001242 final TargetInfo target = mMultiProfilePagerAdapter.getCurrentListAdapter()
1243 .targetInfoForPosition(0, false);
Hakan Seyalioglue1276bf2016-12-07 16:38:57 -08001244 if (shouldAutoLaunchSingleChoice(target)) {
1245 safelyStartActivity(target);
1246 mPackageMonitor.unregister();
1247 mRegistered = false;
1248 finish();
1249 return true;
1250 }
Jeff Sharkeycc2ae6b42015-09-29 13:04:46 -07001251 }
1252 }
Hakan Seyalioglue1276bf2016-12-07 16:38:57 -08001253
arangelov38a6fce2019-12-02 18:21:22 +00001254 setupViewVisibilities(count);
1255 return false;
1256 }
1257
1258 private void setupViewVisibilities(int count) {
1259 if (count == 0
1260 && mMultiProfilePagerAdapter.getCurrentListAdapter().getPlaceholderCount() == 0) {
Alan Viverette51efddb2017-04-05 10:00:01 -04001261 final TextView emptyView = findViewById(R.id.empty);
Hakan Seyalioglu13405c52017-01-31 19:01:31 -08001262 emptyView.setVisibility(View.VISIBLE);
arangelov38a6fce2019-12-02 18:21:22 +00001263 findViewById(R.id.profile_pager).setVisibility(View.GONE);
1264 } else {
1265 onPrepareAdapterView(mMultiProfilePagerAdapter.getCurrentListAdapter());
Adam Powell7d758002015-05-06 17:49:36 -07001266 }
1267 }
1268
Zhen Zhangbde7b462019-11-11 11:49:33 -08001269 /**
1270 * Prepare the scrollable view which consumes data in the list adapter.
1271 * @param adapter The adapter used to provide data to item views.
Zhen Zhangbde7b462019-11-11 11:49:33 -08001272 */
arangelov38a6fce2019-12-02 18:21:22 +00001273 public void onPrepareAdapterView(ResolverListAdapter adapter) {
1274 mMultiProfilePagerAdapter.getCurrentAdapterView().setVisibility(View.VISIBLE);
Adam Powell7d758002015-05-06 17:49:36 -07001275 final boolean useHeader = adapter.hasFilteredItem();
arangelov38a6fce2019-12-02 18:21:22 +00001276 final ListView listView = (ListView) mMultiProfilePagerAdapter.getCurrentAdapterView();
Adam Powell7d758002015-05-06 17:49:36 -07001277 final ItemClickListener listener = new ItemClickListener();
arangelov38a6fce2019-12-02 18:21:22 +00001278 listView.setOnItemClickListener(listener);
1279 listView.setOnItemLongClickListener(listener);
Adam Powell7d758002015-05-06 17:49:36 -07001280
shafik69df96322018-12-18 15:41:19 +00001281 if (mSupportsAlwaysUseOption || mUseLayoutForBrowsables) {
Adam Powell7d758002015-05-06 17:49:36 -07001282 listView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
1283 }
1284
Hakan Seyalioglu33550122017-01-06 19:54:43 -08001285 // In case this method is called again (due to activity recreation), avoid adding a new
1286 // header if one is already present.
1287 if (useHeader && listView != null && listView.getHeaderViewsCount() == 0) {
Matt Pietald5071202019-10-10 11:21:28 -04001288 listView.setHeaderDividersEnabled(true);
Adam Powell7d758002015-05-06 17:49:36 -07001289 listView.addHeaderView(LayoutInflater.from(this).inflate(
1290 R.layout.resolver_different_item_header, listView, false));
1291 }
Adam Powell24428412015-04-01 17:19:56 -07001292 }
1293
Matt Pietal26038402019-01-08 07:29:34 -05001294 /**
1295 * Configure the area above the app selection list (title, content preview, etc).
1296 */
1297 public void setHeader() {
arangelov38a6fce2019-12-02 18:21:22 +00001298 if (mMultiProfilePagerAdapter.getCurrentListAdapter().getCount() == 0
1299 && mMultiProfilePagerAdapter.getCurrentListAdapter().getPlaceholderCount() == 0) {
Alan Viverette51efddb2017-04-05 10:00:01 -04001300 final TextView titleView = findViewById(R.id.title);
Hakan Seyalioglu33550122017-01-06 19:54:43 -08001301 if (titleView != null) {
Hakan Seyalioglu23f34652017-02-03 09:38:35 -08001302 titleView.setVisibility(View.GONE);
Hakan Seyalioglu33550122017-01-06 19:54:43 -08001303 }
Hakan Seyalioglu23f34652017-02-03 09:38:35 -08001304 }
1305
1306 CharSequence title = mTitle != null
1307 ? mTitle
shafik69df96322018-12-18 15:41:19 +00001308 : getTitleForAction(getTargetIntent(), mDefaultTitleResId);
Hakan Seyalioglu23f34652017-02-03 09:38:35 -08001309
1310 if (!TextUtils.isEmpty(title)) {
Alan Viverette51efddb2017-04-05 10:00:01 -04001311 final TextView titleView = findViewById(R.id.title);
Hakan Seyalioglu23f34652017-02-03 09:38:35 -08001312 if (titleView != null) {
1313 titleView.setText(title);
1314 }
1315 setTitle(title);
Hakan Seyalioglu33550122017-01-06 19:54:43 -08001316 }
1317
Alan Viverette51efddb2017-04-05 10:00:01 -04001318 final ImageView iconView = findViewById(R.id.icon);
arangelovb0802dc2019-10-18 18:03:44 +01001319 if (iconView != null) {
arangelov38a6fce2019-12-02 18:21:22 +00001320 mMultiProfilePagerAdapter.getCurrentListAdapter().loadFilteredItemIconTaskAsync(iconView);
Hakan Seyalioglu33550122017-01-06 19:54:43 -08001321 }
1322 }
1323
arangelov38a6fce2019-12-02 18:21:22 +00001324 protected void resetButtonBar() {
shafik69df96322018-12-18 15:41:19 +00001325 if (!mSupportsAlwaysUseOption && !mUseLayoutForBrowsables) {
1326 return;
1327 }
1328 final ViewGroup buttonLayout = findViewById(R.id.button_bar);
1329 if (buttonLayout != null) {
1330 buttonLayout.setVisibility(View.VISIBLE);
Matt Pietal800136a2019-05-08 07:46:39 -04001331
Matt Pietald5071202019-10-10 11:21:28 -04001332 if (!useLayoutWithDefault()) {
1333 int inset = mSystemWindowInsets != null ? mSystemWindowInsets.bottom : 0;
1334 buttonLayout.setPadding(buttonLayout.getPaddingLeft(), buttonLayout.getPaddingTop(),
1335 buttonLayout.getPaddingRight(), getResources().getDimensionPixelSize(
1336 R.dimen.resolver_button_bar_spacing) + inset);
1337 }
shafik69df96322018-12-18 15:41:19 +00001338 mOnceButton = (Button) buttonLayout.findViewById(R.id.button_once);
shafik69df96322018-12-18 15:41:19 +00001339 mAlwaysButton = (Button) buttonLayout.findViewById(R.id.button_always);
1340
Matt Pietal0d6834a2019-06-27 13:27:52 -04001341 resetAlwaysOrOnceButtonBar();
shafik69df96322018-12-18 15:41:19 +00001342 } else {
1343 Log.e(TAG, "Layout unexpectedly does not have a button bar");
1344 }
1345 }
1346
shafik69df96322018-12-18 15:41:19 +00001347 private void resetAlwaysOrOnceButtonBar() {
arangelov38a6fce2019-12-02 18:21:22 +00001348 int filteredPosition = mMultiProfilePagerAdapter.getCurrentListAdapter()
1349 .getFilteredPosition();
1350 if (useLayoutWithDefault() && filteredPosition != ListView.INVALID_POSITION) {
1351 setAlwaysButtonEnabled(true, filteredPosition, false);
Hakan Seyalioglu33550122017-01-06 19:54:43 -08001352 mOnceButton.setEnabled(true);
Hakan Seyalioglu23f34652017-02-03 09:38:35 -08001353 return;
1354 }
1355
1356 // When the items load in, if an item was already selected, enable the buttons
arangelov38a6fce2019-12-02 18:21:22 +00001357 ListView currentAdapterView = (ListView) mMultiProfilePagerAdapter.getCurrentAdapterView();
1358 if (currentAdapterView != null
1359 && currentAdapterView.getCheckedItemPosition() != ListView.INVALID_POSITION) {
1360 setAlwaysButtonEnabled(true, currentAdapterView.getCheckedItemPosition(), true);
Hakan Seyalioglu23f34652017-02-03 09:38:35 -08001361 mOnceButton.setEnabled(true);
Hakan Seyalioglu33550122017-01-06 19:54:43 -08001362 }
1363 }
1364
arangelovb0802dc2019-10-18 18:03:44 +01001365 @Override // ResolverListCommunicator
1366 public boolean useLayoutWithDefault() {
arangelov38a6fce2019-12-02 18:21:22 +00001367 return mSupportsAlwaysUseOption
1368 && mMultiProfilePagerAdapter.getCurrentListAdapter().hasFilteredItem();
Hakan Seyalioglu13405c52017-01-31 19:01:31 -08001369 }
1370
Adam Powellc412be62015-06-24 13:54:10 -07001371 /**
Jorim Jaggif631ef72017-02-24 13:49:47 +01001372 * If {@code retainInOnStop} is set to true, we will not finish ourselves when onStop gets
1373 * called and we are launched in a new task.
1374 */
1375 protected void setRetainInOnStop(boolean retainInOnStop) {
1376 mRetainInOnStop = retainInOnStop;
1377 }
1378
1379 /**
Adam Powellc412be62015-06-24 13:54:10 -07001380 * Check a simple match for the component of two ResolveInfos.
1381 */
arangelovb0802dc2019-10-18 18:03:44 +01001382 @Override // ResolverListCommunicator
1383 public boolean resolveInfoMatch(ResolveInfo lhs, ResolveInfo rhs) {
Adam Powellc412be62015-06-24 13:54:10 -07001384 return lhs == null ? rhs == null
1385 : lhs.activityInfo == null ? rhs.activityInfo == null
1386 : Objects.equals(lhs.activityInfo.name, rhs.activityInfo.name)
1387 && Objects.equals(lhs.activityInfo.packageName, rhs.activityInfo.packageName);
1388 }
1389
arangelovb0802dc2019-10-18 18:03:44 +01001390 @Override // ResolverListCommunicator
1391 public void onHandlePackagesChanged() {
arangelov38a6fce2019-12-02 18:21:22 +00001392 if (mMultiProfilePagerAdapter.getCurrentListAdapter().getCount() == 0) {
arangelovb0802dc2019-10-18 18:03:44 +01001393 // We no longer have any items... just finish the activity.
1394 finish();
Zhen Zhang55d66aa2019-10-14 17:11:19 -07001395 }
Zhen Zhang55d66aa2019-10-14 17:11:19 -07001396 }
Alison Cichowlas1c8816c2019-04-03 17:43:22 -04001397
Hakan Seyalioglue1276bf2016-12-07 16:38:57 -08001398 @VisibleForTesting
1399 public static final class ResolvedComponentInfo {
Adam Powell2ed547e2015-04-29 18:45:04 -07001400 public final ComponentName name;
1401 private final List<Intent> mIntents = new ArrayList<>();
1402 private final List<ResolveInfo> mResolveInfos = new ArrayList<>();
Alison Cichowlas1fd47152019-11-14 19:50:55 -05001403 private boolean mPinned;
Adam Powell2ed547e2015-04-29 18:45:04 -07001404
1405 public ResolvedComponentInfo(ComponentName name, Intent intent, ResolveInfo info) {
1406 this.name = name;
1407 add(intent, info);
1408 }
1409
1410 public void add(Intent intent, ResolveInfo info) {
1411 mIntents.add(intent);
1412 mResolveInfos.add(info);
1413 }
1414
1415 public int getCount() {
1416 return mIntents.size();
1417 }
1418
1419 public Intent getIntentAt(int index) {
1420 return index >= 0 ? mIntents.get(index) : null;
1421 }
1422
1423 public ResolveInfo getResolveInfoAt(int index) {
1424 return index >= 0 ? mResolveInfos.get(index) : null;
1425 }
1426
1427 public int findIntent(Intent intent) {
1428 for (int i = 0, N = mIntents.size(); i < N; i++) {
1429 if (intent.equals(mIntents.get(i))) {
1430 return i;
1431 }
1432 }
1433 return -1;
1434 }
1435
1436 public int findResolveInfo(ResolveInfo info) {
1437 for (int i = 0, N = mResolveInfos.size(); i < N; i++) {
1438 if (info.equals(mResolveInfos.get(i))) {
1439 return i;
1440 }
1441 }
1442 return -1;
1443 }
Alison Cichowlas1fd47152019-11-14 19:50:55 -05001444
1445 public boolean isPinned() {
1446 return mPinned;
1447 }
1448
1449 public void setPinned(boolean pinned) {
1450 mPinned = pinned;
1451 }
Adam Powell2ed547e2015-04-29 18:45:04 -07001452 }
1453
Adam Powell7d758002015-05-06 17:49:36 -07001454 class ItemClickListener implements AdapterView.OnItemClickListener,
1455 AdapterView.OnItemLongClickListener {
1456 @Override
1457 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
1458 final ListView listView = parent instanceof ListView ? (ListView) parent : null;
1459 if (listView != null) {
1460 position -= listView.getHeaderViewsCount();
1461 }
1462 if (position < 0) {
1463 // Header views don't count.
1464 return;
1465 }
Hakan Seyalioglu23f34652017-02-03 09:38:35 -08001466 // If we're still loading, we can't yet enable the buttons.
arangelov38a6fce2019-12-02 18:21:22 +00001467 if (mMultiProfilePagerAdapter.getCurrentListAdapter()
1468 .resolveInfoForPosition(position, true) == null) {
Hakan Seyalioglu23f34652017-02-03 09:38:35 -08001469 return;
1470 }
1471
arangelov38a6fce2019-12-02 18:21:22 +00001472 ListView currentAdapterView =
1473 (ListView) mMultiProfilePagerAdapter.getCurrentAdapterView();
1474 final int checkedPos = currentAdapterView.getCheckedItemPosition();
Adam Powell7d758002015-05-06 17:49:36 -07001475 final boolean hasValidSelection = checkedPos != ListView.INVALID_POSITION;
Hakan Seyalioglu13405c52017-01-31 19:01:31 -08001476 if (!useLayoutWithDefault()
Ruchi Kandoi65d76c12017-08-18 13:05:39 -07001477 && (!hasValidSelection || mLastSelected != checkedPos)
Matt Pietal0d6834a2019-06-27 13:27:52 -04001478 && mAlwaysButton != null) {
1479 setAlwaysButtonEnabled(hasValidSelection, checkedPos, true);
Adam Powell7d758002015-05-06 17:49:36 -07001480 mOnceButton.setEnabled(hasValidSelection);
1481 if (hasValidSelection) {
arangelov38a6fce2019-12-02 18:21:22 +00001482 currentAdapterView.smoothScrollToPosition(checkedPos);
Adam Powell7d758002015-05-06 17:49:36 -07001483 }
1484 mLastSelected = checkedPos;
1485 } else {
1486 startSelected(position, false, true);
1487 }
1488 }
Adam Powell2d809622012-03-22 15:24:43 -07001489
1490 @Override
1491 public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
Adam Powell7d758002015-05-06 17:49:36 -07001492 final ListView listView = parent instanceof ListView ? (ListView) parent : null;
1493 if (listView != null) {
1494 position -= listView.getHeaderViewsCount();
Adam Powell24428412015-04-01 17:19:56 -07001495 }
Adam Powellfd1e93d2014-09-07 16:52:22 -07001496 if (position < 0) {
1497 // Header views don't count.
1498 return false;
1499 }
arangelov38a6fce2019-12-02 18:21:22 +00001500 ResolveInfo ri = mMultiProfilePagerAdapter.getCurrentListAdapter()
1501 .resolveInfoForPosition(position, true);
Adam Powell23882512016-01-29 10:21:00 -08001502 showTargetDetails(ri);
Adam Powell2d809622012-03-22 15:24:43 -07001503 return true;
1504 }
1505
1506 }
Adam Powell0256c6f2013-05-29 16:42:33 -07001507
Dianne Hackbornec452d92014-11-11 17:16:56 -08001508 static final boolean isSpecificUriMatch(int match) {
1509 match = match&IntentFilter.MATCH_CATEGORY_MASK;
1510 return match >= IntentFilter.MATCH_CATEGORY_HOST
1511 && match <= IntentFilter.MATCH_CATEGORY_PATH;
1512 }
1513
Adam Powell4c470d62015-06-19 17:46:17 -07001514 static class PickTargetOptionRequest extends PickOptionRequest {
1515 public PickTargetOptionRequest(@Nullable Prompt prompt, Option[] options,
1516 @Nullable Bundle extras) {
1517 super(prompt, options, extras);
1518 }
1519
1520 @Override
1521 public void onCancel() {
1522 super.onCancel();
1523 final ResolverActivity ra = (ResolverActivity) getActivity();
1524 if (ra != null) {
1525 ra.mPickOptionRequest = null;
1526 ra.finish();
1527 }
1528 }
1529
1530 @Override
1531 public void onPickOptionResult(boolean finished, Option[] selections, Bundle result) {
1532 super.onPickOptionResult(finished, selections, result);
1533 if (selections.length != 1) {
1534 // TODO In a better world we would filter the UI presented here and let the
1535 // user refine. Maybe later.
1536 return;
1537 }
1538
1539 final ResolverActivity ra = (ResolverActivity) getActivity();
1540 if (ra != null) {
arangelov38a6fce2019-12-02 18:21:22 +00001541 final TargetInfo ti = ra.mMultiProfilePagerAdapter.getCurrentListAdapter()
1542 .getItem(selections[0].getIndex());
Adam Powell4c470d62015-06-19 17:46:17 -07001543 if (ra.onTargetSelected(ti, false)) {
1544 ra.mPickOptionRequest = null;
1545 ra.finish();
1546 }
1547 }
1548 }
1549 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001550}