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 | |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 21 | import static com.android.internal.app.AbstractMultiProfilePagerAdapter.PROFILE_PERSONAL; |
| 22 | import static com.android.internal.app.AbstractMultiProfilePagerAdapter.PROFILE_WORK; |
| 23 | |
Adam Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 24 | import android.annotation.Nullable; |
Philip P. Moltmann | f8173ca | 2016-04-12 15:11:23 -0700 | [diff] [blame] | 25 | import android.annotation.StringRes; |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 26 | import android.annotation.UiThread; |
Andrei Onea | 1588439 | 2019-03-22 17:28:11 +0000 | [diff] [blame] | 27 | import android.annotation.UnsupportedAppUsage; |
Adam Powell | e9414d9 | 2014-07-05 17:44:18 -0700 | [diff] [blame] | 28 | import android.app.Activity; |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 29 | import android.app.ActivityManager; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 30 | import android.app.ActivityTaskManager; |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 31 | import android.app.ActivityThread; |
Adam Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 32 | import android.app.VoiceInteractor.PickOptionRequest; |
| 33 | import android.app.VoiceInteractor.PickOptionRequest.Option; |
| 34 | import android.app.VoiceInteractor.Prompt; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | import android.content.ComponentName; |
| 36 | import android.content.Context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import android.content.Intent; |
| 38 | import android.content.IntentFilter; |
Paul McLean | 3a30e55 | 2019-12-07 14:47:29 -0700 | [diff] [blame] | 39 | import android.content.PermissionChecker; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | import android.content.pm.ActivityInfo; |
Sander Alewijnse | 6c9eee8 | 2014-07-17 10:03:31 +0100 | [diff] [blame] | 41 | import android.content.pm.ApplicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | import android.content.pm.PackageManager; |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 43 | import android.content.pm.PackageManager.NameNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | import android.content.pm.ResolveInfo; |
Sander Alewijnse | 6c9eee8 | 2014-07-17 10:03:31 +0100 | [diff] [blame] | 45 | import android.content.pm.UserInfo; |
Jiongxuan Gao | 3365b16 | 2016-11-24 20:20:27 +0900 | [diff] [blame] | 46 | import android.content.res.Configuration; |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 47 | import android.content.res.Resources; |
Matt Pietal | 800136a | 2019-05-08 07:46:39 -0400 | [diff] [blame] | 48 | import android.graphics.Insets; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | import android.net.Uri; |
Sander Alewijnse | 6c9eee8 | 2014-07-17 10:03:31 +0100 | [diff] [blame] | 50 | import android.os.Build; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | import android.os.Bundle; |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 52 | import android.os.IBinder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | import android.os.PatternMatcher; |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 54 | import android.os.RemoteException; |
Jeff Sharkey | 37355a9 | 2016-02-05 16:19:10 -0700 | [diff] [blame] | 55 | import android.os.StrictMode; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 56 | import android.os.UserHandle; |
Sander Alewijnse | 6c9eee8 | 2014-07-17 10:03:31 +0100 | [diff] [blame] | 57 | import android.os.UserManager; |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 58 | import android.provider.MediaStore; |
| 59 | import android.provider.Settings; |
| 60 | import android.text.TextUtils; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | import android.util.Log; |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 62 | import android.util.Slog; |
Adam Powell | 2d80962 | 2012-03-22 15:24:43 -0700 | [diff] [blame] | 63 | import android.view.LayoutInflater; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | import android.view.View; |
| 65 | import android.view.ViewGroup; |
Matt Pietal | 800136a | 2019-05-08 07:46:39 -0400 | [diff] [blame] | 66 | import android.view.ViewGroup.LayoutParams; |
| 67 | import android.view.WindowInsets; |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 68 | import android.widget.AbsListView; |
Adam Powell | 2d80962 | 2012-03-22 15:24:43 -0700 | [diff] [blame] | 69 | import android.widget.AdapterView; |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 70 | import android.widget.Button; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | import android.widget.ImageView; |
Adam Powell | 2d80962 | 2012-03-22 15:24:43 -0700 | [diff] [blame] | 72 | import android.widget.ListView; |
Matt Pietal | 800136a | 2019-05-08 07:46:39 -0400 | [diff] [blame] | 73 | import android.widget.Space; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | import android.widget.TextView; |
Sander Alewijnse | 6c9eee8 | 2014-07-17 10:03:31 +0100 | [diff] [blame] | 75 | import android.widget.Toast; |
Hyunyoung Song | 16b7af4 | 2018-10-05 14:00:42 -0700 | [diff] [blame] | 76 | |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 77 | import com.android.internal.R; |
| 78 | import com.android.internal.annotations.VisibleForTesting; |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 79 | import com.android.internal.app.AbstractMultiProfilePagerAdapter.Profile; |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 80 | import com.android.internal.app.chooser.DisplayResolveInfo; |
| 81 | import com.android.internal.app.chooser.TargetInfo; |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 82 | import com.android.internal.content.PackageMonitor; |
Clara Bayarri | fa902aa | 2016-04-13 14:45:08 +0100 | [diff] [blame] | 83 | import com.android.internal.logging.MetricsLogger; |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 84 | import com.android.internal.logging.nano.MetricsProto; |
Adam Powell | 4f6c205 | 2014-07-07 18:49:10 -0700 | [diff] [blame] | 85 | import com.android.internal.widget.ResolverDrawerLayout; |
Adam Powell | 2d80962 | 2012-03-22 15:24:43 -0700 | [diff] [blame] | 86 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | import java.util.ArrayList; |
Clara Bayarri | fa902aa | 2016-04-13 14:45:08 +0100 | [diff] [blame] | 88 | import java.util.Arrays; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | import java.util.Iterator; |
| 90 | import java.util.List; |
Adam Powell | c412be6 | 2015-06-24 13:54:10 -0700 | [diff] [blame] | 91 | import java.util.Objects; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | import 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 Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 99 | @UiThread |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 100 | public class ResolverActivity extends Activity implements |
| 101 | ResolverListAdapter.ResolverListCommunicator { |
Alison Cichowlas | 4691ed4 | 2018-11-13 15:59:55 -0500 | [diff] [blame] | 102 | |
Andrei Onea | 1588439 | 2019-03-22 17:28:11 +0000 | [diff] [blame] | 103 | @UnsupportedAppUsage |
Artur Satayev | 751e551 | 2019-11-15 19:12:49 +0000 | [diff] [blame] | 104 | public ResolverActivity() { |
| 105 | } |
| 106 | |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 107 | private boolean mSafeForwardingMode; |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 108 | private Button mAlwaysButton; |
| 109 | private Button mOnceButton; |
Matt Pietal | 74c6ed0 | 2019-04-18 13:38:46 -0400 | [diff] [blame] | 110 | protected View mProfileView; |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 111 | private int mLastSelected = AbsListView.INVALID_POSITION; |
Sander Alewijnse | 6c9eee8 | 2014-07-17 10:03:31 +0100 | [diff] [blame] | 112 | private boolean mResolvingHome = false; |
Sander Alewijnse | f654533 | 2014-10-31 12:39:02 +0000 | [diff] [blame] | 113 | private int mProfileSwitchMessageId = -1; |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 114 | private int mLayoutId; |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 115 | @VisibleForTesting |
| 116 | protected final ArrayList<Intent> mIntents = new ArrayList<>(); |
Adam Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 117 | private PickTargetOptionRequest mPickOptionRequest; |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 118 | private String mReferrerPackage; |
Hakan Seyalioglu | 3355012 | 2017-01-06 19:54:43 -0800 | [diff] [blame] | 119 | private CharSequence mTitle; |
| 120 | private int mDefaultTitleResId; |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 121 | |
| 122 | @VisibleForTesting |
| 123 | protected boolean mUseLayoutForBrowsables; |
Adam Powell | 09a6560 | 2014-07-20 16:23:14 -0700 | [diff] [blame] | 124 | |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 125 | // Whether or not this activity supports choosing a default handler for the intent. |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 126 | @VisibleForTesting |
| 127 | protected boolean mSupportsAlwaysUseOption; |
Adam Powell | 63b3169 | 2015-09-28 10:45:00 -0700 | [diff] [blame] | 128 | protected ResolverDrawerLayout mResolverDrawerLayout; |
Andrei Onea | 1588439 | 2019-03-22 17:28:11 +0000 | [diff] [blame] | 129 | @UnsupportedAppUsage |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 130 | protected PackageManager mPm; |
| 131 | protected int mLaunchedFromUid; |
| 132 | |
| 133 | private static final String TAG = "ResolverActivity"; |
| 134 | private static final boolean DEBUG = false; |
Adam Powell | 63b3169 | 2015-09-28 10:45:00 -0700 | [diff] [blame] | 135 | |
Dianne Hackborn | d44713a | 2012-04-30 16:34:46 -0700 | [diff] [blame] | 136 | private boolean mRegistered; |
Jorim Jaggi | f631ef7 | 2017-02-24 13:49:47 +0100 | [diff] [blame] | 137 | |
Matt Pietal | 800136a | 2019-05-08 07:46:39 -0400 | [diff] [blame] | 138 | protected Insets mSystemWindowInsets = null; |
| 139 | private Space mFooterSpacer = null; |
| 140 | |
Jorim Jaggi | f631ef7 | 2017-02-24 13:49:47 +0100 | [diff] [blame] | 141 | /** See {@link #setRetainInOnStop}. */ |
| 142 | private boolean mRetainInOnStop; |
| 143 | |
Matt Pietal | 0d6834a | 2019-06-27 13:27:52 -0400 | [diff] [blame] | 144 | 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 | |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 148 | /** |
| 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 Pietal | ab73a88 | 2019-06-05 07:04:55 -0400 | [diff] [blame] | 153 | private final PackageMonitor mPackageMonitor = createPackageMonitor(); |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 154 | |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 155 | @VisibleForTesting |
| 156 | protected AbstractMultiProfilePagerAdapter mMultiProfilePagerAdapter; |
| 157 | |
Paul McLean | 07425c8 | 2019-10-18 12:00:11 -0600 | [diff] [blame] | 158 | // Intent extra for connected audio devices |
| 159 | public static final String EXTRA_IS_AUDIO_CAPTURE_DEVICE = "is_audio_capture_device"; |
| 160 | |
Philip P. Moltmann | f8173ca | 2016-04-12 15:11:23 -0700 | [diff] [blame] | 161 | /** |
| 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 Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 173 | private enum ActionTitle { |
| 174 | VIEW(Intent.ACTION_VIEW, |
| 175 | com.android.internal.R.string.whichViewApplication, |
Philip P. Moltmann | f8173ca | 2016-04-12 15:11:23 -0700 | [diff] [blame] | 176 | com.android.internal.R.string.whichViewApplicationNamed, |
| 177 | com.android.internal.R.string.whichViewApplicationLabel), |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 178 | EDIT(Intent.ACTION_EDIT, |
| 179 | com.android.internal.R.string.whichEditApplication, |
Philip P. Moltmann | f8173ca | 2016-04-12 15:11:23 -0700 | [diff] [blame] | 180 | com.android.internal.R.string.whichEditApplicationNamed, |
| 181 | com.android.internal.R.string.whichEditApplicationLabel), |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 182 | SEND(Intent.ACTION_SEND, |
| 183 | com.android.internal.R.string.whichSendApplication, |
Philip P. Moltmann | f8173ca | 2016-04-12 15:11:23 -0700 | [diff] [blame] | 184 | com.android.internal.R.string.whichSendApplicationNamed, |
| 185 | com.android.internal.R.string.whichSendApplicationLabel), |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 186 | SENDTO(Intent.ACTION_SENDTO, |
Adam Powell | 13ea8f4 | 2016-03-18 09:39:41 -0700 | [diff] [blame] | 187 | com.android.internal.R.string.whichSendToApplication, |
Philip P. Moltmann | f8173ca | 2016-04-12 15:11:23 -0700 | [diff] [blame] | 188 | com.android.internal.R.string.whichSendToApplicationNamed, |
| 189 | com.android.internal.R.string.whichSendToApplicationLabel), |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 190 | SEND_MULTIPLE(Intent.ACTION_SEND_MULTIPLE, |
| 191 | com.android.internal.R.string.whichSendApplication, |
Philip P. Moltmann | f8173ca | 2016-04-12 15:11:23 -0700 | [diff] [blame] | 192 | 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 Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 198 | DEFAULT(null, |
| 199 | com.android.internal.R.string.whichApplication, |
Philip P. Moltmann | f8173ca | 2016-04-12 15:11:23 -0700 | [diff] [blame] | 200 | com.android.internal.R.string.whichApplicationNamed, |
| 201 | com.android.internal.R.string.whichApplicationLabel), |
Adam Powell | a35c77a | 2014-09-25 16:46:36 -0700 | [diff] [blame] | 202 | HOME(Intent.ACTION_MAIN, |
| 203 | com.android.internal.R.string.whichHomeApplication, |
Philip P. Moltmann | f8173ca | 2016-04-12 15:11:23 -0700 | [diff] [blame] | 204 | com.android.internal.R.string.whichHomeApplicationNamed, |
| 205 | com.android.internal.R.string.whichHomeApplicationLabel); |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 206 | |
shafik | 0c7c5d5 | 2019-02-27 12:13:25 +0000 | [diff] [blame] | 207 | // titles for layout that deals with http(s) intents |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 208 | public static final int BROWSABLE_TITLE_RES = |
Matt Pietal | 0d6834a | 2019-06-27 13:27:52 -0400 | [diff] [blame] | 209 | 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; |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 216 | |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 217 | public final String action; |
| 218 | public final int titleRes; |
| 219 | public final int namedTitleRes; |
Philip P. Moltmann | f8173ca | 2016-04-12 15:11:23 -0700 | [diff] [blame] | 220 | public final @StringRes int labelRes; |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 221 | |
Philip P. Moltmann | f8173ca | 2016-04-12 15:11:23 -0700 | [diff] [blame] | 222 | ActionTitle(String action, int titleRes, int namedTitleRes, @StringRes int labelRes) { |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 223 | this.action = action; |
| 224 | this.titleRes = titleRes; |
| 225 | this.namedTitleRes = namedTitleRes; |
Philip P. Moltmann | f8173ca | 2016-04-12 15:11:23 -0700 | [diff] [blame] | 226 | this.labelRes = labelRes; |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | public static ActionTitle forAction(String action) { |
| 230 | for (ActionTitle title : values()) { |
Adam Powell | a35c77a | 2014-09-25 16:46:36 -0700 | [diff] [blame] | 231 | if (title != HOME && action != null && action.equals(title.action)) { |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 232 | return title; |
| 233 | } |
| 234 | } |
| 235 | return DEFAULT; |
| 236 | } |
| 237 | } |
| 238 | |
Matt Pietal | ab73a88 | 2019-06-05 07:04:55 -0400 | [diff] [blame] | 239 | protected PackageMonitor createPackageMonitor() { |
| 240 | return new PackageMonitor() { |
| 241 | @Override |
| 242 | public void onSomePackagesChanged() { |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 243 | mMultiProfilePagerAdapter.getCurrentListAdapter().handlePackagesChanged(); |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 244 | updateProfileViewButton(); |
Matt Pietal | ab73a88 | 2019-06-05 07:04:55 -0400 | [diff] [blame] | 245 | } |
| 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 Hackborn | 905577f | 2011-09-07 18:31:28 -0700 | [diff] [blame] | 256 | private Intent makeMyIntent() { |
| 257 | Intent intent = new Intent(getIntent()); |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 258 | intent.setComponent(null); |
Dianne Hackborn | 905577f | 2011-09-07 18:31:28 -0700 | [diff] [blame] | 259 | // 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 268 | @Override |
| 269 | protected void onCreate(Bundle savedInstanceState) { |
Christopher Tate | b72b363 | 2013-09-30 17:50:32 -0700 | [diff] [blame] | 270 | // Use a specialized prompt when we're handling the 'Home' app startActivity() |
Christopher Tate | b72b363 | 2013-09-30 17:50:32 -0700 | [diff] [blame] | 271 | 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 Alewijnse | 6c9eee8 | 2014-07-17 10:03:31 +0100 | [diff] [blame] | 277 | // Note: this field is not set to true in the compatibility version. |
| 278 | mResolvingHome = true; |
Christopher Tate | b72b363 | 2013-09-30 17:50:32 -0700 | [diff] [blame] | 279 | } |
| 280 | |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 281 | setSafeForwardingMode(true); |
| 282 | |
Adam Powell | a35c77a | 2014-09-25 16:46:36 -0700 | [diff] [blame] | 283 | onCreate(savedInstanceState, intent, null, 0, null, null, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 284 | } |
| 285 | |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 286 | /** |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 287 | * Compatibility version for other bundled services that use this overload without |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 288 | * a default title resource |
| 289 | */ |
Andrei Onea | 1588439 | 2019-03-22 17:28:11 +0000 | [diff] [blame] | 290 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 291 | protected void onCreate(Bundle savedInstanceState, Intent intent, |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 292 | CharSequence title, Intent[] initialIntents, |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 293 | List<ResolveInfo> rList, boolean supportsAlwaysUseOption) { |
| 294 | onCreate(savedInstanceState, intent, title, 0, initialIntents, rList, |
| 295 | supportsAlwaysUseOption); |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | protected void onCreate(Bundle savedInstanceState, Intent intent, |
| 299 | CharSequence title, int defaultTitleRes, Intent[] initialIntents, |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 300 | List<ResolveInfo> rList, boolean supportsAlwaysUseOption) { |
Adam Powell | e9414d9 | 2014-07-05 17:44:18 -0700 | [diff] [blame] | 301 | setTheme(R.style.Theme_DeviceDefault_Resolver); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 302 | super.onCreate(savedInstanceState); |
Sander Alewijnse | f654533 | 2014-10-31 12:39:02 +0000 | [diff] [blame] | 303 | |
| 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 Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 308 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 309 | mLaunchedFromUid = ActivityTaskManager.getService().getLaunchedFromUid( |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 310 | getActivityToken()); |
| 311 | } catch (RemoteException e) { |
| 312 | mLaunchedFromUid = -1; |
| 313 | } |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 314 | |
| 315 | if (mLaunchedFromUid < 0 || UserHandle.isIsolated(mLaunchedFromUid)) { |
| 316 | // Gulp! |
| 317 | finish(); |
| 318 | return; |
| 319 | } |
| 320 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 321 | mPm = getPackageManager(); |
Adam Powell | 09a6560 | 2014-07-20 16:23:14 -0700 | [diff] [blame] | 322 | |
Dianne Hackborn | d0d7503 | 2012-04-19 23:12:09 -0700 | [diff] [blame] | 323 | mPackageMonitor.register(this, getMainLooper(), false); |
Dianne Hackborn | d44713a | 2012-04-30 16:34:46 -0700 | [diff] [blame] | 324 | mRegistered = true; |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 325 | mReferrerPackage = getReferrerPackageName(); |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 326 | |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 327 | // 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] | 328 | mIntents.add(0, new Intent(intent)); |
Hakan Seyalioglu | 3355012 | 2017-01-06 19:54:43 -0800 | [diff] [blame] | 329 | mTitle = title; |
| 330 | mDefaultTitleResId = defaultTitleRes; |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 331 | |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 332 | mUseLayoutForBrowsables = getTargetIntent() == null |
| 333 | ? false |
shafik | 0c7c5d5 | 2019-02-27 12:13:25 +0000 | [diff] [blame] | 334 | : isHttpSchemeAndViewAction(getTargetIntent()); |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 335 | |
Matt Pietal | 0d6834a | 2019-06-27 13:27:52 -0400 | [diff] [blame] | 336 | mSupportsAlwaysUseOption = supportsAlwaysUseOption; |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 337 | |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 338 | // The last argument of createResolverListAdapter is whether to do special handling |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 339 | // 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(); |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 344 | mMultiProfilePagerAdapter = createMultiProfilePagerAdapter(initialIntents, rList, filterLastUsed); |
arangelov | bb57233 | 2019-11-13 12:50:08 +0000 | [diff] [blame] | 345 | if (configureContentView()) { |
Adam Powell | 39e94eb | 2015-09-08 17:01:49 -0700 | [diff] [blame] | 346 | return; |
| 347 | } |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 348 | |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 349 | final ResolverDrawerLayout rdl = findViewById(R.id.contentPanel); |
Adam Powell | 4f6c205 | 2014-07-07 18:49:10 -0700 | [diff] [blame] | 350 | if (rdl != null) { |
Adam Powell | 5dd072d | 2014-10-30 19:51:41 -0700 | [diff] [blame] | 351 | rdl.setOnDismissedListener(new ResolverDrawerLayout.OnDismissedListener() { |
Adam Powell | 4f6c205 | 2014-07-07 18:49:10 -0700 | [diff] [blame] | 352 | @Override |
Adam Powell | 5dd072d | 2014-10-30 19:51:41 -0700 | [diff] [blame] | 353 | public void onDismissed() { |
Adam Powell | 4f6c205 | 2014-07-07 18:49:10 -0700 | [diff] [blame] | 354 | finish(); |
| 355 | } |
| 356 | }); |
Adam Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 357 | if (isVoiceInteraction()) { |
| 358 | rdl.setCollapsed(false); |
| 359 | } |
Matt Pietal | 800136a | 2019-05-08 07:46:39 -0400 | [diff] [blame] | 360 | |
| 361 | rdl.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
| 362 | | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); |
| 363 | rdl.setOnApplyWindowInsetsListener(this::onApplyWindowInsets); |
| 364 | |
Adam Powell | 63b3169 | 2015-09-28 10:45:00 -0700 | [diff] [blame] | 365 | mResolverDrawerLayout = rdl; |
Adam Powell | 4f6c205 | 2014-07-07 18:49:10 -0700 | [diff] [blame] | 366 | } |
| 367 | |
Adam Powell | 88831a2 | 2014-11-20 18:17:00 -0800 | [diff] [blame] | 368 | mProfileView = findViewById(R.id.profile_button); |
| 369 | if (mProfileView != null) { |
Matt Pietal | 74c6ed0 | 2019-04-18 13:38:46 -0400 | [diff] [blame] | 370 | mProfileView.setOnClickListener(this::onProfileClick); |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 371 | updateProfileViewButton(); |
Adam Powell | 88831a2 | 2014-11-20 18:17:00 -0800 | [diff] [blame] | 372 | } |
Adam Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 373 | |
Clara Bayarri | 9550f5d | 2016-05-11 11:20:13 +0100 | [diff] [blame] | 374 | final Set<String> categories = intent.getCategories(); |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 375 | MetricsLogger.action(this, mMultiProfilePagerAdapter.getCurrentListAdapter().hasFilteredItem() |
Clara Bayarri | fa902aa | 2016-04-13 14:45:08 +0100 | [diff] [blame] | 376 | ? MetricsProto.MetricsEvent.ACTION_SHOW_APP_DISAMBIG_APP_FEATURED |
| 377 | : MetricsProto.MetricsEvent.ACTION_SHOW_APP_DISAMBIG_NONE_FEATURED, |
| 378 | intent.getAction() + ":" + intent.getType() + ":" |
Clara Bayarri | 9550f5d | 2016-05-11 11:20:13 +0100 | [diff] [blame] | 379 | + (categories != null ? Arrays.toString(categories.toArray()) : "")); |
Adam Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 380 | } |
| 381 | |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 382 | 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 Pietal | 74c6ed0 | 2019-04-18 13:38:46 -0400 | [diff] [blame] | 462 | protected void onProfileClick(View v) { |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 463 | final DisplayResolveInfo dri = |
| 464 | mMultiProfilePagerAdapter.getCurrentListAdapter().getOtherProfile(); |
Matt Pietal | 74c6ed0 | 2019-04-18 13:38:46 -0400 | [diff] [blame] | 465 | 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 Pietal | 800136a | 2019-05-08 07:46:39 -0400 | [diff] [blame] | 476 | 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 Pietal | d507120 | 2019-10-10 11:21:28 -0400 | [diff] [blame] | 482 | // Need extra padding so the list can fully scroll up |
| 483 | if (useLayoutWithDefault()) { |
| 484 | if (mFooterSpacer == null) { |
| 485 | mFooterSpacer = new Space(getApplicationContext()); |
| 486 | } else { |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 487 | ((ResolverMultiProfilePagerAdapter) mMultiProfilePagerAdapter) |
| 488 | .getCurrentAdapterView().removeFooterView(mFooterSpacer); |
Matt Pietal | d507120 | 2019-10-10 11:21:28 -0400 | [diff] [blame] | 489 | } |
| 490 | mFooterSpacer.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT, |
| 491 | mSystemWindowInsets.bottom)); |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 492 | ((ResolverMultiProfilePagerAdapter) mMultiProfilePagerAdapter) |
| 493 | .getCurrentAdapterView().addFooterView(mFooterSpacer); |
Matt Pietal | 800136a | 2019-05-08 07:46:39 -0400 | [diff] [blame] | 494 | } else { |
Matt Pietal | d507120 | 2019-10-10 11:21:28 -0400 | [diff] [blame] | 495 | 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 Pietal | 800136a | 2019-05-08 07:46:39 -0400 | [diff] [blame] | 501 | } |
Matt Pietal | 800136a | 2019-05-08 07:46:39 -0400 | [diff] [blame] | 502 | |
Matt Pietal | 78fdbd4 | 2019-06-05 07:08:08 -0400 | [diff] [blame] | 503 | resetButtonBar(); |
| 504 | |
Matt Pietal | 800136a | 2019-05-08 07:46:39 -0400 | [diff] [blame] | 505 | return insets.consumeSystemWindowInsets(); |
| 506 | } |
| 507 | |
Jiongxuan Gao | 3365b16 | 2016-11-24 20:20:27 +0900 | [diff] [blame] | 508 | @Override |
| 509 | public void onConfigurationChanged(Configuration newConfig) { |
| 510 | super.onConfigurationChanged(newConfig); |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 511 | mMultiProfilePagerAdapter.getCurrentListAdapter().handlePackagesChanged(); |
Matt Pietal | 800136a | 2019-05-08 07:46:39 -0400 | [diff] [blame] | 512 | |
| 513 | if (mSystemWindowInsets != null) { |
| 514 | mResolverDrawerLayout.setPadding(mSystemWindowInsets.left, mSystemWindowInsets.top, |
| 515 | mSystemWindowInsets.right, 0); |
| 516 | } |
Jiongxuan Gao | 3365b16 | 2016-11-24 20:20:27 +0900 | [diff] [blame] | 517 | } |
| 518 | |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 519 | @Override // ResolverListCommunicator |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 520 | public void sendVoiceChoicesIfNeeded() { |
Adam Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 521 | if (!isVoiceInteraction()) { |
| 522 | // Clearly not needed. |
| 523 | return; |
| 524 | } |
| 525 | |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 526 | int count = mMultiProfilePagerAdapter.getCurrentListAdapter().getCount(); |
| 527 | final Option[] options = new Option[count]; |
Adam Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 528 | for (int i = 0, N = options.length; i < N; i++) { |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 529 | TargetInfo target = mMultiProfilePagerAdapter.getCurrentListAdapter().getItem(i); |
Matt Pietal | 2cf4c6c | 2019-09-10 09:33:11 -0400 | [diff] [blame] | 530 | 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 Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 536 | } |
| 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 Powell | 88831a2 | 2014-11-20 18:17:00 -0800 | [diff] [blame] | 545 | } |
| 546 | |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 547 | protected final void setAdditionalTargets(Intent[] intents) { |
| 548 | if (intents != null) { |
| 549 | for (Intent intent : intents) { |
| 550 | mIntents.add(intent); |
| 551 | } |
| 552 | } |
| 553 | } |
| 554 | |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 555 | @Override // SelectableTargetInfoCommunicator ResolverListCommunicator |
Adam Powell | 0ccc0e9 | 2015-04-23 17:19:37 -0700 | [diff] [blame] | 556 | public Intent getTargetIntent() { |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 557 | return mIntents.isEmpty() ? null : mIntents.get(0); |
Adam Powell | 0ccc0e9 | 2015-04-23 17:19:37 -0700 | [diff] [blame] | 558 | } |
| 559 | |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 560 | protected String getReferrerPackageName() { |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 561 | final Uri referrer = getReferrer(); |
| 562 | if (referrer != null && "android-app".equals(referrer.getScheme())) { |
| 563 | return referrer.getHost(); |
| 564 | } |
| 565 | return null; |
| 566 | } |
| 567 | |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 568 | public int getLayoutResource() { |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 569 | return R.layout.resolver_list; |
| 570 | } |
| 571 | |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 572 | @Override // ResolverListCommunicator |
| 573 | public void updateProfileViewButton() { |
Matt Pietal | 74c6ed0 | 2019-04-18 13:38:46 -0400 | [diff] [blame] | 574 | if (mProfileView == null) { |
| 575 | return; |
| 576 | } |
| 577 | |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 578 | final DisplayResolveInfo dri = |
| 579 | mMultiProfilePagerAdapter.getCurrentListAdapter().getOtherProfile(); |
| 580 | if (dri != null && !ENABLE_TABBED_VIEW) { |
Adam Powell | 88831a2 | 2014-11-20 18:17:00 -0800 | [diff] [blame] | 581 | mProfileView.setVisibility(View.VISIBLE); |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 582 | 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 Powell | 88831a2 | 2014-11-20 18:17:00 -0800 | [diff] [blame] | 587 | } else { |
| 588 | mProfileView.setVisibility(View.GONE); |
| 589 | } |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 590 | } |
| 591 | |
Sander Alewijnse | f654533 | 2014-10-31 12:39:02 +0000 | [diff] [blame] | 592 | 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 Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 608 | /** |
| 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 | |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 624 | protected CharSequence getTitleForAction(Intent intent, int defaultTitleRes) { |
| 625 | final ActionTitle title = mResolvingHome |
| 626 | ? ActionTitle.HOME |
| 627 | : ActionTitle.forAction(intent.getAction()); |
| 628 | |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 629 | // 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. |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 631 | final boolean named = |
| 632 | mMultiProfilePagerAdapter.getCurrentListAdapter().getFilteredPosition() >= 0; |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 633 | if (title == ActionTitle.DEFAULT && defaultTitleRes != 0) { |
| 634 | return getString(defaultTitleRes); |
shafik | 0c7c5d5 | 2019-02-27 12:13:25 +0000 | [diff] [blame] | 635 | } else if (isHttpSchemeAndViewAction(intent)) { |
| 636 | // 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] | 637 | // they're giving access for the activity to open URLs from this specific host |
Matt Pietal | 0d6834a | 2019-06-27 13:27:52 -0400 | [diff] [blame] | 638 | String dialogTitle = null; |
| 639 | if (named && !mUseLayoutForBrowsables) { |
| 640 | dialogTitle = getString(ActionTitle.BROWSABLE_APP_TITLE_RES, |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 641 | mMultiProfilePagerAdapter.getCurrentListAdapter().getFilteredItem() |
| 642 | .getDisplayLabel()); |
Matt Pietal | 0d6834a | 2019-06-27 13:27:52 -0400 | [diff] [blame] | 643 | } else if (named && mUseLayoutForBrowsables) { |
| 644 | dialogTitle = getString(ActionTitle.BROWSABLE_HOST_APP_TITLE_RES, |
| 645 | intent.getData().getHost(), |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 646 | mMultiProfilePagerAdapter.getCurrentListAdapter().getFilteredItem() |
| 647 | .getDisplayLabel()); |
| 648 | } else if (mMultiProfilePagerAdapter.getCurrentListAdapter().areAllTargetsBrowsers()) { |
Matt Pietal | d507120 | 2019-10-10 11:21:28 -0400 | [diff] [blame] | 649 | dialogTitle = getString(ActionTitle.BROWSABLE_TITLE_RES); |
Matt Pietal | 0d6834a | 2019-06-27 13:27:52 -0400 | [diff] [blame] | 650 | } else { |
| 651 | dialogTitle = getString(ActionTitle.BROWSABLE_HOST_TITLE_RES, |
| 652 | intent.getData().getHost()); |
| 653 | } |
| 654 | return dialogTitle; |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 655 | } else { |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 656 | return named |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 657 | ? getString(title.namedTitleRes, mMultiProfilePagerAdapter |
| 658 | .getCurrentListAdapter().getFilteredItem().getDisplayLabel()) |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 659 | : getString(title.titleRes); |
Amith Yamasani | e9ecc8b | 2013-08-22 11:16:27 -0700 | [diff] [blame] | 660 | } |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 661 | } |
| 662 | |
Adam Powell | e9414d9 | 2014-07-05 17:44:18 -0700 | [diff] [blame] | 663 | void dismiss() { |
| 664 | if (!isFinishing()) { |
| 665 | finish(); |
| 666 | } |
| 667 | } |
| 668 | |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 669 | @Override |
| 670 | protected void onRestart() { |
| 671 | super.onRestart(); |
Dianne Hackborn | d44713a | 2012-04-30 16:34:46 -0700 | [diff] [blame] | 672 | if (!mRegistered) { |
| 673 | mPackageMonitor.register(this, getMainLooper(), false); |
| 674 | mRegistered = true; |
| 675 | } |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 676 | mMultiProfilePagerAdapter.getCurrentListAdapter().handlePackagesChanged(); |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 677 | updateProfileViewButton(); |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | @Override |
| 681 | protected void onStop() { |
| 682 | super.onStop(); |
Dianne Hackborn | d44713a | 2012-04-30 16:34:46 -0700 | [diff] [blame] | 683 | if (mRegistered) { |
| 684 | mPackageMonitor.unregister(); |
| 685 | mRegistered = false; |
| 686 | } |
Wale Ogunwale | 9014e66 | 2016-03-19 14:55:46 -0700 | [diff] [blame] | 687 | final Intent intent = getIntent(); |
| 688 | if ((intent.getFlags() & FLAG_ACTIVITY_NEW_TASK) != 0 && !isVoiceInteraction() |
Jorim Jaggi | f631ef7 | 2017-02-24 13:49:47 +0100 | [diff] [blame] | 689 | && !mResolvingHome && !mRetainInOnStop) { |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 690 | // 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 Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 701 | } |
| 702 | |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 703 | @Override |
Adam Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 704 | protected void onDestroy() { |
| 705 | super.onDestroy(); |
| 706 | if (!isChangingConfigurations() && mPickOptionRequest != null) { |
| 707 | mPickOptionRequest.cancel(); |
| 708 | } |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 709 | if (mMultiProfilePagerAdapter.getCurrentListAdapter() != null) { |
| 710 | mMultiProfilePagerAdapter.getCurrentListAdapter().onDestroy(); |
Kang Li | 38a6da64 | 2017-04-05 12:30:55 -0700 | [diff] [blame] | 711 | } |
Adam Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | @Override |
Adam Powell | 9bee466 | 2012-05-08 11:07:23 -0700 | [diff] [blame] | 715 | protected void onRestoreInstanceState(Bundle savedInstanceState) { |
| 716 | super.onRestoreInstanceState(savedInstanceState); |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 717 | resetButtonBar(); |
Adam Powell | 9bee466 | 2012-05-08 11:07:23 -0700 | [diff] [blame] | 718 | } |
| 719 | |
shafik | 0c7c5d5 | 2019-02-27 12:13:25 +0000 | [diff] [blame] | 720 | 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 Alewijnse | 6c9eee8 | 2014-07-17 10:03:31 +0100 | [diff] [blame] | 726 | 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 Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 749 | return appInfo.targetSdkVersion >= Build.VERSION_CODES.LOLLIPOP; |
Sander Alewijnse | 6c9eee8 | 2014-07-17 10:03:31 +0100 | [diff] [blame] | 750 | } catch (NameNotFoundException e) { |
| 751 | return false; |
| 752 | } |
| 753 | } |
| 754 | |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 755 | private void setAlwaysButtonEnabled(boolean hasValidSelection, int checkedPos, |
| 756 | boolean filtered) { |
Nicolas Prevot | 5044988 | 2014-06-23 12:42:37 +0100 | [diff] [blame] | 757 | boolean enabled = false; |
Paul McLean | 3a30e55 | 2019-12-07 14:47:29 -0700 | [diff] [blame] | 758 | ResolveInfo ri = null; |
Nicolas Prevot | 5044988 | 2014-06-23 12:42:37 +0100 | [diff] [blame] | 759 | if (hasValidSelection) { |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 760 | ri = mMultiProfilePagerAdapter.getCurrentListAdapter() |
| 761 | .resolveInfoForPosition(checkedPos, filtered); |
Hakan Seyalioglu | 5dbc819 | 2017-02-24 16:16:37 -0800 | [diff] [blame] | 762 | 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 Prevot | 5044988 | 2014-06-23 12:42:37 +0100 | [diff] [blame] | 769 | enabled = true; |
| 770 | } |
Matt Pietal | 0d6834a | 2019-06-27 13:27:52 -0400 | [diff] [blame] | 771 | 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 Prevot | 5044988 | 2014-06-23 12:42:37 +0100 | [diff] [blame] | 778 | } |
Paul McLean | 3a30e55 | 2019-12-07 14:47:29 -0700 | [diff] [blame] | 779 | |
| 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 Prevot | 5044988 | 2014-06-23 12:42:37 +0100 | [diff] [blame] | 797 | mAlwaysButton.setEnabled(enabled); |
| 798 | } |
| 799 | |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 800 | public void onButtonClick(View v) { |
| 801 | final int id = v.getId(); |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 802 | 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 Pietal | a310c1f | 2019-07-03 09:12:56 -0400 | [diff] [blame] | 809 | if (mUseLayoutForBrowsables |
| 810 | && !ri.handleAllWebDataURI && id == R.id.button_always) { |
Matt Pietal | 0d6834a | 2019-06-27 13:27:52 -0400 | [diff] [blame] | 811 | showSettingsForSelected(ri); |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 812 | } else { |
| 813 | startSelected(which, id == R.id.button_always, hasIndexBeenFiltered); |
| 814 | } |
| 815 | } |
| 816 | |
Matt Pietal | 0d6834a | 2019-06-27 13:27:52 -0400 | [diff] [blame] | 817 | private void showSettingsForSelected(ResolveInfo ri) { |
shafik | 34064c3 | 2019-03-06 15:42:52 +0000 | [diff] [blame] | 818 | Intent intent = new Intent(); |
Matt Pietal | 0d6834a | 2019-06-27 13:27:52 -0400 | [diff] [blame] | 819 | |
| 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 | |
shafik | 34064c3 | 2019-03-06 15:42:52 +0000 | [diff] [blame] | 825 | // For regular apps, we open the Open by Default page |
Matt Pietal | 0d6834a | 2019-06-27 13:27:52 -0400 | [diff] [blame] | 826 | 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 | |
shafik | 34064c3 | 2019-03-06 15:42:52 +0000 | [diff] [blame] | 832 | startActivity(intent); |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 833 | } |
| 834 | |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 835 | public void startSelected(int which, boolean always, boolean hasIndexBeenFiltered) { |
Amith Yamasani | 07cd351 | 2013-09-18 13:16:00 -0700 | [diff] [blame] | 836 | if (isFinishing()) { |
| 837 | return; |
| 838 | } |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 839 | ResolveInfo ri = mMultiProfilePagerAdapter.getCurrentListAdapter() |
| 840 | .resolveInfoForPosition(which, hasIndexBeenFiltered); |
Sander Alewijnse | 86d35ba | 2015-02-04 15:14:53 +0000 | [diff] [blame] | 841 | 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 | |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 849 | TargetInfo target = mMultiProfilePagerAdapter.getCurrentListAdapter() |
| 850 | .targetInfoForPosition(which, hasIndexBeenFiltered); |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 851 | if (target == null) { |
| 852 | return; |
| 853 | } |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 854 | if (onTargetSelected(target, always)) { |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 855 | if (always && mSupportsAlwaysUseOption) { |
Clara Bayarri | fa902aa | 2016-04-13 14:45:08 +0100 | [diff] [blame] | 856 | MetricsLogger.action( |
| 857 | this, MetricsProto.MetricsEvent.ACTION_APP_DISAMBIG_ALWAYS); |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 858 | } else if (mSupportsAlwaysUseOption) { |
Clara Bayarri | fa902aa | 2016-04-13 14:45:08 +0100 | [diff] [blame] | 859 | 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 | } |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 865 | MetricsLogger.action(this, |
| 866 | mMultiProfilePagerAdapter.getCurrentListAdapter().hasFilteredItem() |
Clara Bayarri | fa902aa | 2016-04-13 14:45:08 +0100 | [diff] [blame] | 867 | ? MetricsProto.MetricsEvent.ACTION_HIDE_APP_DISAMBIG_APP_FEATURED |
| 868 | : MetricsProto.MetricsEvent.ACTION_HIDE_APP_DISAMBIG_NONE_FEATURED); |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 869 | finish(); |
| 870 | } |
Mike Lockwood | 02eb874 | 2011-02-27 09:10:37 -0800 | [diff] [blame] | 871 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 872 | |
Adam Powell | e49d939 | 2014-07-17 18:45:19 -0700 | [diff] [blame] | 873 | /** |
| 874 | * Replace me in subclasses! |
| 875 | */ |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 876 | @Override // ResolverListCommunicator |
Nicolas Prevot | 0e2b73f | 2014-10-27 10:06:11 +0000 | [diff] [blame] | 877 | public Intent getReplacementIntent(ActivityInfo aInfo, Intent defIntent) { |
Adam Powell | e49d939 | 2014-07-17 18:45:19 -0700 | [diff] [blame] | 878 | return defIntent; |
| 879 | } |
| 880 | |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 881 | @Override // ResolverListCommunicator |
| 882 | public void onPostListReady() { |
| 883 | setHeader(); |
| 884 | resetButtonBar(); |
| 885 | onListRebuilt(); |
| 886 | } |
| 887 | |
| 888 | protected void onListRebuilt() { |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 889 | int count = mMultiProfilePagerAdapter.getCurrentListAdapter().getUnfilteredCount(); |
| 890 | if (count == 1 && mMultiProfilePagerAdapter.getCurrentListAdapter().getOtherProfile() == null) { |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 891 | // Only one target, so we're a candidate to auto-launch! |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 892 | final TargetInfo target = |
| 893 | mMultiProfilePagerAdapter.getCurrentListAdapter().targetInfoForPosition(0, false); |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 894 | if (shouldAutoLaunchSingleChoice(target)) { |
| 895 | safelyStartActivity(target); |
| 896 | finish(); |
| 897 | } |
| 898 | } |
| 899 | } |
| 900 | |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 901 | protected boolean onTargetSelected(TargetInfo target, boolean alwaysCheck) { |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 902 | final ResolveInfo ri = target.getResolveInfo(); |
| 903 | final Intent intent = target != null ? target.getResolvedIntent() : null; |
| 904 | |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 905 | if (intent != null && (mSupportsAlwaysUseOption |
| 906 | || mMultiProfilePagerAdapter.getCurrentListAdapter().hasFilteredItem()) |
| 907 | && mMultiProfilePagerAdapter.getCurrentListAdapter().getUnfilteredResolveList() != null) { |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 908 | // Build a reasonable intent filter, based on what matched. |
| 909 | IntentFilter filter = new IntentFilter(); |
Henrik Engström | 3277cf1 | 2014-07-17 12:18:29 +0200 | [diff] [blame] | 910 | Intent filterIntent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 911 | |
Henrik Engström | 3277cf1 | 2014-07-17 12:18:29 +0200 | [diff] [blame] | 912 | if (intent.getSelector() != null) { |
| 913 | filterIntent = intent.getSelector(); |
| 914 | } else { |
| 915 | filterIntent = intent; |
| 916 | } |
| 917 | |
| 918 | String action = filterIntent.getAction(); |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 919 | if (action != null) { |
| 920 | filter.addAction(action); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 921 | } |
Henrik Engström | 3277cf1 | 2014-07-17 12:18:29 +0200 | [diff] [blame] | 922 | Set<String> categories = filterIntent.getCategories(); |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 923 | if (categories != null) { |
| 924 | for (String cat : categories) { |
| 925 | filter.addCategory(cat); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 926 | } |
| 927 | } |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 928 | filter.addCategory(Intent.CATEGORY_DEFAULT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 929 | |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 930 | int cat = ri.match & IntentFilter.MATCH_CATEGORY_MASK; |
Henrik Engström | 3277cf1 | 2014-07-17 12:18:29 +0200 | [diff] [blame] | 931 | Uri data = filterIntent.getData(); |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 932 | if (cat == IntentFilter.MATCH_CATEGORY_TYPE) { |
Henrik Engström | 3277cf1 | 2014-07-17 12:18:29 +0200 | [diff] [blame] | 933 | String mimeType = filterIntent.resolveType(this); |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 934 | 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 940 | } |
| 941 | } |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 942 | } |
| 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 Hackborn | df1c0bf | 2013-06-12 16:21:38 -0700 | [diff] [blame] | 963 | } |
| 964 | } |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 965 | 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 986 | } |
| 987 | } |
| 988 | } |
| 989 | } |
| 990 | |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 991 | if (filter != null) { |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 992 | final int N = mMultiProfilePagerAdapter.getCurrentListAdapter() |
| 993 | .getUnfilteredResolveList().size(); |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 994 | 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). |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 998 | final boolean needToAddBackProfileForwardingComponent = |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 999 | mMultiProfilePagerAdapter.getCurrentListAdapter().getOtherProfile() != null; |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 1000 | if (!needToAddBackProfileForwardingComponent) { |
| 1001 | set = new ComponentName[N]; |
| 1002 | } else { |
| 1003 | set = new ComponentName[N + 1]; |
| 1004 | } |
| 1005 | |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 1006 | int bestMatch = 0; |
| 1007 | for (int i=0; i<N; i++) { |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1008 | ResolveInfo r = mMultiProfilePagerAdapter.getCurrentListAdapter() |
| 1009 | .getUnfilteredResolveList().get(i).getResolveInfoAt(0); |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 1010 | set[i] = new ComponentName(r.activityInfo.packageName, |
| 1011 | r.activityInfo.name); |
| 1012 | if (r.match > bestMatch) bestMatch = r.match; |
| 1013 | } |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 1014 | |
| 1015 | if (needToAddBackProfileForwardingComponent) { |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1016 | set[N] = mMultiProfilePagerAdapter.getCurrentListAdapter() |
| 1017 | .getOtherProfile().getResolvedComponentName(); |
| 1018 | final int otherProfileMatch = mMultiProfilePagerAdapter.getCurrentListAdapter() |
| 1019 | .getOtherProfile().getResolveInfo().match; |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 1020 | if (otherProfileMatch > bestMatch) bestMatch = otherProfileMatch; |
| 1021 | } |
| 1022 | |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 1023 | if (alwaysCheck) { |
Fabrice Di Meglio | 3453e08 | 2015-05-11 17:46:23 -0700 | [diff] [blame] | 1024 | final int userId = getUserId(); |
| 1025 | final PackageManager pm = getPackageManager(); |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1026 | |
| 1027 | // Set the preferred Activity |
| 1028 | pm.addPreferredActivity(filter, bestMatch, set, intent.getComponent()); |
| 1029 | |
Fabrice Di Meglio | 3453e08 | 2015-05-11 17:46:23 -0700 | [diff] [blame] | 1030 | if (ri.handleAllWebDataURI) { |
| 1031 | // Set default Browser if needed |
Jeff Sharkey | e06b4d1 | 2016-01-06 14:51:50 -0700 | [diff] [blame] | 1032 | final String packageName = pm.getDefaultBrowserPackageNameAsUser(userId); |
Fabrice Di Meglio | 3453e08 | 2015-05-11 17:46:23 -0700 | [diff] [blame] | 1033 | if (TextUtils.isEmpty(packageName)) { |
Jeff Sharkey | e06b4d1 | 2016-01-06 14:51:50 -0700 | [diff] [blame] | 1034 | pm.setDefaultBrowserPackageNameAsUser(ri.activityInfo.packageName, userId); |
Fabrice Di Meglio | 3453e08 | 2015-05-11 17:46:23 -0700 | [diff] [blame] | 1035 | } |
| 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 Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1041 | |
Fabrice Di Meglio | 3453e08 | 2015-05-11 17:46:23 -0700 | [diff] [blame] | 1042 | boolean isHttpOrHttps = (dataScheme != null) && |
| 1043 | (dataScheme.equals(IntentFilter.SCHEME_HTTP) || |
| 1044 | dataScheme.equals(IntentFilter.SCHEME_HTTPS)); |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1045 | |
Fabrice Di Meglio | 3453e08 | 2015-05-11 17:46:23 -0700 | [diff] [blame] | 1046 | boolean isViewAction = (action != null) && action.equals(Intent.ACTION_VIEW); |
| 1047 | boolean hasCategoryBrowsable = (categories != null) && |
| 1048 | categories.contains(Intent.CATEGORY_BROWSABLE); |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1049 | |
Fabrice Di Meglio | 3453e08 | 2015-05-11 17:46:23 -0700 | [diff] [blame] | 1050 | if (isHttpOrHttps && isViewAction && hasCategoryBrowsable) { |
Jeff Sharkey | e06b4d1 | 2016-01-06 14:51:50 -0700 | [diff] [blame] | 1051 | pm.updateIntentVerificationStatusAsUser(packageName, |
Fabrice Di Meglio | 3453e08 | 2015-05-11 17:46:23 -0700 | [diff] [blame] | 1052 | PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS, |
| 1053 | userId); |
| 1054 | } |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1055 | } |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 1056 | } else { |
| 1057 | try { |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1058 | mMultiProfilePagerAdapter.getCurrentListAdapter() |
| 1059 | .mResolverListController.setLastChosen(intent, filter, bestMatch); |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 1060 | } catch (RemoteException re) { |
| 1061 | Log.d(TAG, "Error calling setLastChosenActivity\n" + re); |
| 1062 | } |
Amith Yamasani | e9ecc8b | 2013-08-22 11:16:27 -0700 | [diff] [blame] | 1063 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1064 | } |
| 1065 | } |
| 1066 | |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1067 | if (target != null) { |
| 1068 | safelyStartActivity(target); |
Matt Pietal | a4b3007 | 2019-04-04 13:44:36 -0400 | [diff] [blame] | 1069 | |
| 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 Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 1075 | } |
Matt Pietal | a4b3007 | 2019-04-04 13:44:36 -0400 | [diff] [blame] | 1076 | |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1077 | return true; |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 1078 | } |
| 1079 | |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 1080 | public void safelyStartActivity(TargetInfo cti) { |
Jeff Sharkey | 2b9eb89 | 2016-02-16 09:21:51 -0700 | [diff] [blame] | 1081 | // 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 Alewijnse | f654533 | 2014-10-31 12:39:02 +0000 | [diff] [blame] | 1092 | // 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 | } |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1097 | UserHandle currentUserHandle = mMultiProfilePagerAdapter.getCurrentUserHandle(); |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 1098 | if (!mSafeForwardingMode) { |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1099 | if (cti.startAsUser(this, null, currentUserHandle)) { |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1100 | onActivityStarted(cti); |
| 1101 | } |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 1102 | return; |
| 1103 | } |
| 1104 | try { |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1105 | if (cti.startAsCaller(this, null, currentUserHandle.getIdentifier())) { |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1106 | onActivityStarted(cti); |
| 1107 | } |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 1108 | } catch (RuntimeException e) { |
| 1109 | String launchedFromPackage; |
| 1110 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1111 | launchedFromPackage = ActivityTaskManager.getService().getLaunchedFromPackage( |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 1112 | 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1119 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1120 | } |
| 1121 | |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1122 | |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 1123 | public boolean startAsCallerImpl(Intent intent, Bundle options, boolean ignoreTargetSecurity, |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1124 | 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 Cichowlas | 7b6f3b6 | 2018-12-07 09:06:57 -0500 | [diff] [blame] | 1146 | chooserIntent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT |
| 1147 | | Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP); |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1148 | startActivity(chooserIntent); |
| 1149 | } catch (RemoteException e) { |
| 1150 | Log.e(TAG, e.toString()); |
| 1151 | } |
| 1152 | return true; |
| 1153 | } |
| 1154 | |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 1155 | public void onActivityStarted(TargetInfo cti) { |
Adam Powell | 0b3c112 | 2014-10-09 12:50:14 -0700 | [diff] [blame] | 1156 | // Do nothing |
| 1157 | } |
| 1158 | |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 1159 | @Override // ResolverListCommunicator |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 1160 | public boolean shouldGetActivityMetadata() { |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1161 | return false; |
| 1162 | } |
| 1163 | |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 1164 | public boolean shouldAutoLaunchSingleChoice(TargetInfo target) { |
Matt Pietal | a4b3007 | 2019-04-04 13:44:36 -0400 | [diff] [blame] | 1165 | return !target.isSuspended(); |
Adam Powell | 39e94eb | 2015-09-08 17:01:49 -0700 | [diff] [blame] | 1166 | } |
| 1167 | |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 1168 | public void showTargetDetails(ResolveInfo ri) { |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 1169 | Intent in = new Intent().setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS) |
Adam Powell | 0fc5b2b | 2012-07-18 18:20:29 -0700 | [diff] [blame] | 1170 | .setData(Uri.fromParts("package", ri.activityInfo.packageName, null)) |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1171 | .addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT); |
Amith Yamasani | 203a2f4 | 2012-10-03 20:16:40 -0700 | [diff] [blame] | 1172 | startActivity(in); |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 1173 | } |
| 1174 | |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1175 | @VisibleForTesting |
| 1176 | protected ResolverListAdapter createResolverListAdapter(Context context, |
| 1177 | List<Intent> payloadIntents, Intent[] initialIntents, List<ResolveInfo> rList, |
| 1178 | boolean filterLastUsed, boolean useLayoutForBrowsables, UserHandle userHandle) { |
Paul McLean | 07425c8 | 2019-10-18 12:00:11 -0600 | [diff] [blame] | 1179 | Intent startIntent = getIntent(); |
| 1180 | boolean isAudioCaptureDevice = |
| 1181 | startIntent.getBooleanExtra(EXTRA_IS_AUDIO_CAPTURE_DEVICE, false); |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 1182 | return new ResolverListAdapter(context, payloadIntents, initialIntents, rList, |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1183 | filterLastUsed, createListController(userHandle), useLayoutForBrowsables, this, |
Paul McLean | 07425c8 | 2019-10-18 12:00:11 -0600 | [diff] [blame] | 1184 | isAudioCaptureDevice); |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1185 | } |
| 1186 | |
| 1187 | @VisibleForTesting |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1188 | protected ResolverListController createListController(UserHandle userHandle) { |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1189 | return new ResolverListController( |
| 1190 | this, |
| 1191 | mPm, |
| 1192 | getTargetIntent(), |
| 1193 | getReferrerPackageName(), |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1194 | mLaunchedFromUid, |
| 1195 | userHandle); |
Adam Powell | 88831a2 | 2014-11-20 18:17:00 -0800 | [diff] [blame] | 1196 | } |
| 1197 | |
Adam Powell | 39e94eb | 2015-09-08 17:01:49 -0700 | [diff] [blame] | 1198 | /** |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 1199 | * Sets up the content view. |
arangelov | bb57233 | 2019-11-13 12:50:08 +0000 | [diff] [blame] | 1200 | * @return <code>true</code> if the activity is finishing and creation should halt. |
Adam Powell | 39e94eb | 2015-09-08 17:01:49 -0700 | [diff] [blame] | 1201 | */ |
arangelov | bb57233 | 2019-11-13 12:50:08 +0000 | [diff] [blame] | 1202 | private boolean configureContentView() { |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1203 | if (mMultiProfilePagerAdapter.getCurrentListAdapter() == null) { |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 1204 | throw new IllegalStateException("mAdapter cannot be null."); |
| 1205 | } |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1206 | boolean rebuildCompleted = mMultiProfilePagerAdapter.getCurrentListAdapter().rebuildList(); |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 1207 | if (useLayoutWithDefault()) { |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1208 | mLayoutId = R.layout.resolver_list_with_default; |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1209 | } else { |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1210 | mLayoutId = getLayoutResource(); |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1211 | } |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 1212 | setContentView(mLayoutId); |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1213 | mMultiProfilePagerAdapter.setupViewPager(findViewById(R.id.profile_pager)); |
arangelov | bb57233 | 2019-11-13 12:50:08 +0000 | [diff] [blame] | 1214 | return postRebuildList(rebuildCompleted); |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 1215 | } |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1216 | |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 1217 | /** |
arangelov | bb57233 | 2019-11-13 12:50:08 +0000 | [diff] [blame] | 1218 | * 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. |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 1222 | */ |
arangelov | bb57233 | 2019-11-13 12:50:08 +0000 | [diff] [blame] | 1223 | protected boolean postRebuildList(boolean rebuildCompleted) { |
| 1224 | return postRebuildListInternal(rebuildCompleted); |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 1225 | } |
| 1226 | |
| 1227 | /** |
arangelov | bb57233 | 2019-11-13 12:50:08 +0000 | [diff] [blame] | 1228 | * 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. |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 1231 | */ |
arangelov | bb57233 | 2019-11-13 12:50:08 +0000 | [diff] [blame] | 1232 | final boolean postRebuildListInternal(boolean rebuildCompleted) { |
| 1233 | |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1234 | int count = mMultiProfilePagerAdapter.getCurrentListAdapter().getUnfilteredCount(); |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1235 | |
| 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) { |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1239 | if (count == 1 |
| 1240 | && mMultiProfilePagerAdapter.getCurrentListAdapter().getOtherProfile() == null) { |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1241 | // Only one target, so we're a candidate to auto-launch! |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1242 | final TargetInfo target = mMultiProfilePagerAdapter.getCurrentListAdapter() |
| 1243 | .targetInfoForPosition(0, false); |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1244 | if (shouldAutoLaunchSingleChoice(target)) { |
| 1245 | safelyStartActivity(target); |
| 1246 | mPackageMonitor.unregister(); |
| 1247 | mRegistered = false; |
| 1248 | finish(); |
| 1249 | return true; |
| 1250 | } |
Jeff Sharkey | cc2ae6b4 | 2015-09-29 13:04:46 -0700 | [diff] [blame] | 1251 | } |
| 1252 | } |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1253 | |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1254 | setupViewVisibilities(count); |
| 1255 | return false; |
| 1256 | } |
| 1257 | |
| 1258 | private void setupViewVisibilities(int count) { |
| 1259 | if (count == 0 |
| 1260 | && mMultiProfilePagerAdapter.getCurrentListAdapter().getPlaceholderCount() == 0) { |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 1261 | final TextView emptyView = findViewById(R.id.empty); |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 1262 | emptyView.setVisibility(View.VISIBLE); |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1263 | findViewById(R.id.profile_pager).setVisibility(View.GONE); |
| 1264 | } else { |
| 1265 | onPrepareAdapterView(mMultiProfilePagerAdapter.getCurrentListAdapter()); |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1266 | } |
| 1267 | } |
| 1268 | |
Zhen Zhang | bde7b46 | 2019-11-11 11:49:33 -0800 | [diff] [blame] | 1269 | /** |
| 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 Zhang | bde7b46 | 2019-11-11 11:49:33 -0800 | [diff] [blame] | 1272 | */ |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1273 | public void onPrepareAdapterView(ResolverListAdapter adapter) { |
| 1274 | mMultiProfilePagerAdapter.getCurrentAdapterView().setVisibility(View.VISIBLE); |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1275 | final boolean useHeader = adapter.hasFilteredItem(); |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1276 | final ListView listView = (ListView) mMultiProfilePagerAdapter.getCurrentAdapterView(); |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1277 | final ItemClickListener listener = new ItemClickListener(); |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1278 | listView.setOnItemClickListener(listener); |
| 1279 | listView.setOnItemLongClickListener(listener); |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1280 | |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 1281 | if (mSupportsAlwaysUseOption || mUseLayoutForBrowsables) { |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1282 | listView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE); |
| 1283 | } |
| 1284 | |
Hakan Seyalioglu | 3355012 | 2017-01-06 19:54:43 -0800 | [diff] [blame] | 1285 | // 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 Pietal | d507120 | 2019-10-10 11:21:28 -0400 | [diff] [blame] | 1288 | listView.setHeaderDividersEnabled(true); |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1289 | listView.addHeaderView(LayoutInflater.from(this).inflate( |
| 1290 | R.layout.resolver_different_item_header, listView, false)); |
| 1291 | } |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1292 | } |
| 1293 | |
Matt Pietal | 2603840 | 2019-01-08 07:29:34 -0500 | [diff] [blame] | 1294 | /** |
| 1295 | * Configure the area above the app selection list (title, content preview, etc). |
| 1296 | */ |
| 1297 | public void setHeader() { |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1298 | if (mMultiProfilePagerAdapter.getCurrentListAdapter().getCount() == 0 |
| 1299 | && mMultiProfilePagerAdapter.getCurrentListAdapter().getPlaceholderCount() == 0) { |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 1300 | final TextView titleView = findViewById(R.id.title); |
Hakan Seyalioglu | 3355012 | 2017-01-06 19:54:43 -0800 | [diff] [blame] | 1301 | if (titleView != null) { |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 1302 | titleView.setVisibility(View.GONE); |
Hakan Seyalioglu | 3355012 | 2017-01-06 19:54:43 -0800 | [diff] [blame] | 1303 | } |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 1304 | } |
| 1305 | |
| 1306 | CharSequence title = mTitle != null |
| 1307 | ? mTitle |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 1308 | : getTitleForAction(getTargetIntent(), mDefaultTitleResId); |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 1309 | |
| 1310 | if (!TextUtils.isEmpty(title)) { |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 1311 | final TextView titleView = findViewById(R.id.title); |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 1312 | if (titleView != null) { |
| 1313 | titleView.setText(title); |
| 1314 | } |
| 1315 | setTitle(title); |
Hakan Seyalioglu | 3355012 | 2017-01-06 19:54:43 -0800 | [diff] [blame] | 1316 | } |
| 1317 | |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 1318 | final ImageView iconView = findViewById(R.id.icon); |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 1319 | if (iconView != null) { |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1320 | mMultiProfilePagerAdapter.getCurrentListAdapter().loadFilteredItemIconTaskAsync(iconView); |
Hakan Seyalioglu | 3355012 | 2017-01-06 19:54:43 -0800 | [diff] [blame] | 1321 | } |
| 1322 | } |
| 1323 | |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1324 | protected void resetButtonBar() { |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 1325 | 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 Pietal | 800136a | 2019-05-08 07:46:39 -0400 | [diff] [blame] | 1331 | |
Matt Pietal | d507120 | 2019-10-10 11:21:28 -0400 | [diff] [blame] | 1332 | 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 | } |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 1338 | mOnceButton = (Button) buttonLayout.findViewById(R.id.button_once); |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 1339 | mAlwaysButton = (Button) buttonLayout.findViewById(R.id.button_always); |
| 1340 | |
Matt Pietal | 0d6834a | 2019-06-27 13:27:52 -0400 | [diff] [blame] | 1341 | resetAlwaysOrOnceButtonBar(); |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 1342 | } else { |
| 1343 | Log.e(TAG, "Layout unexpectedly does not have a button bar"); |
| 1344 | } |
| 1345 | } |
| 1346 | |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 1347 | private void resetAlwaysOrOnceButtonBar() { |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1348 | int filteredPosition = mMultiProfilePagerAdapter.getCurrentListAdapter() |
| 1349 | .getFilteredPosition(); |
| 1350 | if (useLayoutWithDefault() && filteredPosition != ListView.INVALID_POSITION) { |
| 1351 | setAlwaysButtonEnabled(true, filteredPosition, false); |
Hakan Seyalioglu | 3355012 | 2017-01-06 19:54:43 -0800 | [diff] [blame] | 1352 | mOnceButton.setEnabled(true); |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 1353 | return; |
| 1354 | } |
| 1355 | |
| 1356 | // When the items load in, if an item was already selected, enable the buttons |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1357 | ListView currentAdapterView = (ListView) mMultiProfilePagerAdapter.getCurrentAdapterView(); |
| 1358 | if (currentAdapterView != null |
| 1359 | && currentAdapterView.getCheckedItemPosition() != ListView.INVALID_POSITION) { |
| 1360 | setAlwaysButtonEnabled(true, currentAdapterView.getCheckedItemPosition(), true); |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 1361 | mOnceButton.setEnabled(true); |
Hakan Seyalioglu | 3355012 | 2017-01-06 19:54:43 -0800 | [diff] [blame] | 1362 | } |
| 1363 | } |
| 1364 | |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 1365 | @Override // ResolverListCommunicator |
| 1366 | public boolean useLayoutWithDefault() { |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1367 | return mSupportsAlwaysUseOption |
| 1368 | && mMultiProfilePagerAdapter.getCurrentListAdapter().hasFilteredItem(); |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 1369 | } |
| 1370 | |
Adam Powell | c412be6 | 2015-06-24 13:54:10 -0700 | [diff] [blame] | 1371 | /** |
Jorim Jaggi | f631ef7 | 2017-02-24 13:49:47 +0100 | [diff] [blame] | 1372 | * 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 Powell | c412be6 | 2015-06-24 13:54:10 -0700 | [diff] [blame] | 1380 | * Check a simple match for the component of two ResolveInfos. |
| 1381 | */ |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 1382 | @Override // ResolverListCommunicator |
| 1383 | public boolean resolveInfoMatch(ResolveInfo lhs, ResolveInfo rhs) { |
Adam Powell | c412be6 | 2015-06-24 13:54:10 -0700 | [diff] [blame] | 1384 | 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 | |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 1390 | @Override // ResolverListCommunicator |
| 1391 | public void onHandlePackagesChanged() { |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1392 | if (mMultiProfilePagerAdapter.getCurrentListAdapter().getCount() == 0) { |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 1393 | // We no longer have any items... just finish the activity. |
| 1394 | finish(); |
Zhen Zhang | 55d66aa | 2019-10-14 17:11:19 -0700 | [diff] [blame] | 1395 | } |
Zhen Zhang | 55d66aa | 2019-10-14 17:11:19 -0700 | [diff] [blame] | 1396 | } |
Alison Cichowlas | 1c8816c | 2019-04-03 17:43:22 -0400 | [diff] [blame] | 1397 | |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1398 | @VisibleForTesting |
| 1399 | public static final class ResolvedComponentInfo { |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1400 | public final ComponentName name; |
| 1401 | private final List<Intent> mIntents = new ArrayList<>(); |
| 1402 | private final List<ResolveInfo> mResolveInfos = new ArrayList<>(); |
Alison Cichowlas | 1fd4715 | 2019-11-14 19:50:55 -0500 | [diff] [blame] | 1403 | private boolean mPinned; |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1404 | |
| 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 Cichowlas | 1fd4715 | 2019-11-14 19:50:55 -0500 | [diff] [blame] | 1444 | |
| 1445 | public boolean isPinned() { |
| 1446 | return mPinned; |
| 1447 | } |
| 1448 | |
| 1449 | public void setPinned(boolean pinned) { |
| 1450 | mPinned = pinned; |
| 1451 | } |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1452 | } |
| 1453 | |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1454 | 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 Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 1466 | // If we're still loading, we can't yet enable the buttons. |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1467 | if (mMultiProfilePagerAdapter.getCurrentListAdapter() |
| 1468 | .resolveInfoForPosition(position, true) == null) { |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 1469 | return; |
| 1470 | } |
| 1471 | |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1472 | ListView currentAdapterView = |
| 1473 | (ListView) mMultiProfilePagerAdapter.getCurrentAdapterView(); |
| 1474 | final int checkedPos = currentAdapterView.getCheckedItemPosition(); |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1475 | final boolean hasValidSelection = checkedPos != ListView.INVALID_POSITION; |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 1476 | if (!useLayoutWithDefault() |
Ruchi Kandoi | 65d76c1 | 2017-08-18 13:05:39 -0700 | [diff] [blame] | 1477 | && (!hasValidSelection || mLastSelected != checkedPos) |
Matt Pietal | 0d6834a | 2019-06-27 13:27:52 -0400 | [diff] [blame] | 1478 | && mAlwaysButton != null) { |
| 1479 | setAlwaysButtonEnabled(hasValidSelection, checkedPos, true); |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1480 | mOnceButton.setEnabled(hasValidSelection); |
| 1481 | if (hasValidSelection) { |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1482 | currentAdapterView.smoothScrollToPosition(checkedPos); |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1483 | } |
| 1484 | mLastSelected = checkedPos; |
| 1485 | } else { |
| 1486 | startSelected(position, false, true); |
| 1487 | } |
| 1488 | } |
Adam Powell | 2d80962 | 2012-03-22 15:24:43 -0700 | [diff] [blame] | 1489 | |
| 1490 | @Override |
| 1491 | public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1492 | final ListView listView = parent instanceof ListView ? (ListView) parent : null; |
| 1493 | if (listView != null) { |
| 1494 | position -= listView.getHeaderViewsCount(); |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1495 | } |
Adam Powell | fd1e93d | 2014-09-07 16:52:22 -0700 | [diff] [blame] | 1496 | if (position < 0) { |
| 1497 | // Header views don't count. |
| 1498 | return false; |
| 1499 | } |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1500 | ResolveInfo ri = mMultiProfilePagerAdapter.getCurrentListAdapter() |
| 1501 | .resolveInfoForPosition(position, true); |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 1502 | showTargetDetails(ri); |
Adam Powell | 2d80962 | 2012-03-22 15:24:43 -0700 | [diff] [blame] | 1503 | return true; |
| 1504 | } |
| 1505 | |
| 1506 | } |
Adam Powell | 0256c6f | 2013-05-29 16:42:33 -0700 | [diff] [blame] | 1507 | |
Dianne Hackborn | ec452d9 | 2014-11-11 17:16:56 -0800 | [diff] [blame] | 1508 | 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 Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 1514 | 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) { |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1541 | final TargetInfo ti = ra.mMultiProfilePagerAdapter.getCurrentListAdapter() |
| 1542 | .getItem(selections[0].getIndex()); |
Adam Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 1543 | if (ra.onTargetSelected(ti, false)) { |
| 1544 | ra.mPickOptionRequest = null; |
| 1545 | ra.finish(); |
| 1546 | } |
| 1547 | } |
| 1548 | } |
| 1549 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1550 | } |