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 | |
arangelov | 7981b12 | 2020-01-16 10:58:27 +0000 | [diff] [blame] | 19 | import static android.Manifest.permission.INTERACT_ACROSS_PROFILES; |
Hyunyoung Song | 16b7af4 | 2018-10-05 14:00:42 -0700 | [diff] [blame] | 20 | import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; |
arangelov | 7981b12 | 2020-01-16 10:58:27 +0000 | [diff] [blame] | 21 | import static android.content.PermissionChecker.PID_UNKNOWN; |
Hyunyoung Song | 16b7af4 | 2018-10-05 14:00:42 -0700 | [diff] [blame] | 22 | |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 23 | import static com.android.internal.app.AbstractMultiProfilePagerAdapter.PROFILE_PERSONAL; |
| 24 | import static com.android.internal.app.AbstractMultiProfilePagerAdapter.PROFILE_WORK; |
| 25 | |
Adam Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 26 | import android.annotation.Nullable; |
Philip P. Moltmann | f8173ca | 2016-04-12 15:11:23 -0700 | [diff] [blame] | 27 | import android.annotation.StringRes; |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 28 | import android.annotation.UiThread; |
Adam Powell | e9414d9 | 2014-07-05 17:44:18 -0700 | [diff] [blame] | 29 | import android.app.Activity; |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 30 | import android.app.ActivityManager; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 31 | import android.app.ActivityTaskManager; |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 32 | import android.app.ActivityThread; |
Adam Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 33 | import android.app.VoiceInteractor.PickOptionRequest; |
| 34 | import android.app.VoiceInteractor.PickOptionRequest.Option; |
| 35 | import android.app.VoiceInteractor.Prompt; |
Artur Satayev | ed5a6ae | 2019-12-10 17:47:54 +0000 | [diff] [blame] | 36 | import android.compat.annotation.UnsupportedAppUsage; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import android.content.ComponentName; |
| 38 | import android.content.Context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | import android.content.Intent; |
| 40 | import android.content.IntentFilter; |
arangelov | 7981b12 | 2020-01-16 10:58:27 +0000 | [diff] [blame] | 41 | import android.content.PermissionChecker; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | import android.content.pm.ActivityInfo; |
Sander Alewijnse | 6c9eee8 | 2014-07-17 10:03:31 +0100 | [diff] [blame] | 43 | import android.content.pm.ApplicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | import android.content.pm.PackageManager; |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 45 | import android.content.pm.PackageManager.NameNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | import android.content.pm.ResolveInfo; |
Sander Alewijnse | 6c9eee8 | 2014-07-17 10:03:31 +0100 | [diff] [blame] | 47 | import android.content.pm.UserInfo; |
Jiongxuan Gao | 3365b16 | 2016-11-24 20:20:27 +0900 | [diff] [blame] | 48 | import android.content.res.Configuration; |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 49 | import android.content.res.Resources; |
Matt Pietal | 800136a | 2019-05-08 07:46:39 -0400 | [diff] [blame] | 50 | import android.graphics.Insets; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | import android.net.Uri; |
Sander Alewijnse | 6c9eee8 | 2014-07-17 10:03:31 +0100 | [diff] [blame] | 52 | import android.os.Build; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | import android.os.Bundle; |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 54 | import android.os.IBinder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | import android.os.PatternMatcher; |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 56 | import android.os.RemoteException; |
Jeff Sharkey | 37355a9 | 2016-02-05 16:19:10 -0700 | [diff] [blame] | 57 | import android.os.StrictMode; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 58 | import android.os.UserHandle; |
Sander Alewijnse | 6c9eee8 | 2014-07-17 10:03:31 +0100 | [diff] [blame] | 59 | import android.os.UserManager; |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 60 | import android.provider.MediaStore; |
| 61 | import android.provider.Settings; |
| 62 | import android.text.TextUtils; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | import android.util.Log; |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 64 | import android.util.Slog; |
arangelov | cf26864 | 2020-01-15 15:09:51 +0000 | [diff] [blame] | 65 | import android.view.Gravity; |
Adam Powell | 2d80962 | 2012-03-22 15:24:43 -0700 | [diff] [blame] | 66 | import android.view.LayoutInflater; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | import android.view.View; |
| 68 | import android.view.ViewGroup; |
Matt Pietal | 800136a | 2019-05-08 07:46:39 -0400 | [diff] [blame] | 69 | import android.view.ViewGroup.LayoutParams; |
| 70 | import android.view.WindowInsets; |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 71 | import android.widget.AbsListView; |
Adam Powell | 2d80962 | 2012-03-22 15:24:43 -0700 | [diff] [blame] | 72 | import android.widget.AdapterView; |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 73 | import android.widget.Button; |
arangelov | cf26864 | 2020-01-15 15:09:51 +0000 | [diff] [blame] | 74 | import android.widget.FrameLayout; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | import android.widget.ImageView; |
Adam Powell | 2d80962 | 2012-03-22 15:24:43 -0700 | [diff] [blame] | 76 | import android.widget.ListView; |
Matt Pietal | 800136a | 2019-05-08 07:46:39 -0400 | [diff] [blame] | 77 | import android.widget.Space; |
arangelov | cf26864 | 2020-01-15 15:09:51 +0000 | [diff] [blame] | 78 | import android.widget.TabHost; |
| 79 | import android.widget.TabWidget; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | import android.widget.TextView; |
Sander Alewijnse | 6c9eee8 | 2014-07-17 10:03:31 +0100 | [diff] [blame] | 81 | import android.widget.Toast; |
Hyunyoung Song | 16b7af4 | 2018-10-05 14:00:42 -0700 | [diff] [blame] | 82 | |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 83 | import com.android.internal.R; |
| 84 | import com.android.internal.annotations.VisibleForTesting; |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 85 | import com.android.internal.app.AbstractMultiProfilePagerAdapter.Profile; |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 86 | import com.android.internal.app.chooser.DisplayResolveInfo; |
| 87 | import com.android.internal.app.chooser.TargetInfo; |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 88 | import com.android.internal.content.PackageMonitor; |
Clara Bayarri | fa902aa | 2016-04-13 14:45:08 +0100 | [diff] [blame] | 89 | import com.android.internal.logging.MetricsLogger; |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 90 | import com.android.internal.logging.nano.MetricsProto; |
Adam Powell | 4f6c205 | 2014-07-07 18:49:10 -0700 | [diff] [blame] | 91 | import com.android.internal.widget.ResolverDrawerLayout; |
arangelov | cf26864 | 2020-01-15 15:09:51 +0000 | [diff] [blame] | 92 | import com.android.internal.widget.ViewPager; |
Adam Powell | 2d80962 | 2012-03-22 15:24:43 -0700 | [diff] [blame] | 93 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 94 | import java.util.ArrayList; |
Clara Bayarri | fa902aa | 2016-04-13 14:45:08 +0100 | [diff] [blame] | 95 | import java.util.Arrays; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | import java.util.Iterator; |
| 97 | import java.util.List; |
Adam Powell | c412be6 | 2015-06-24 13:54:10 -0700 | [diff] [blame] | 98 | import java.util.Objects; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | import java.util.Set; |
| 100 | |
| 101 | /** |
| 102 | * This activity is displayed when the system attempts to start an Intent for |
| 103 | * which there is more than one matching activity, allowing the user to decide |
| 104 | * which to go to. It is not normally used directly by application developers. |
| 105 | */ |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 106 | @UiThread |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 107 | public class ResolverActivity extends Activity implements |
| 108 | ResolverListAdapter.ResolverListCommunicator { |
Alison Cichowlas | 4691ed4 | 2018-11-13 15:59:55 -0500 | [diff] [blame] | 109 | |
Andrei Onea | 1588439 | 2019-03-22 17:28:11 +0000 | [diff] [blame] | 110 | @UnsupportedAppUsage |
Artur Satayev | 751e551 | 2019-11-15 19:12:49 +0000 | [diff] [blame] | 111 | public ResolverActivity() { |
| 112 | } |
| 113 | |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 114 | private boolean mSafeForwardingMode; |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 115 | private Button mAlwaysButton; |
| 116 | private Button mOnceButton; |
Matt Pietal | 74c6ed0 | 2019-04-18 13:38:46 -0400 | [diff] [blame] | 117 | protected View mProfileView; |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 118 | private int mLastSelected = AbsListView.INVALID_POSITION; |
Sander Alewijnse | 6c9eee8 | 2014-07-17 10:03:31 +0100 | [diff] [blame] | 119 | private boolean mResolvingHome = false; |
Sander Alewijnse | f654533 | 2014-10-31 12:39:02 +0000 | [diff] [blame] | 120 | private int mProfileSwitchMessageId = -1; |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 121 | private int mLayoutId; |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 122 | @VisibleForTesting |
| 123 | protected final ArrayList<Intent> mIntents = new ArrayList<>(); |
Adam Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 124 | private PickTargetOptionRequest mPickOptionRequest; |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 125 | private String mReferrerPackage; |
Hakan Seyalioglu | 3355012 | 2017-01-06 19:54:43 -0800 | [diff] [blame] | 126 | private CharSequence mTitle; |
| 127 | private int mDefaultTitleResId; |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 128 | |
| 129 | @VisibleForTesting |
| 130 | protected boolean mUseLayoutForBrowsables; |
Adam Powell | 09a6560 | 2014-07-20 16:23:14 -0700 | [diff] [blame] | 131 | |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 132 | // Whether or not this activity supports choosing a default handler for the intent. |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 133 | @VisibleForTesting |
| 134 | protected boolean mSupportsAlwaysUseOption; |
Adam Powell | 63b3169 | 2015-09-28 10:45:00 -0700 | [diff] [blame] | 135 | protected ResolverDrawerLayout mResolverDrawerLayout; |
Andrei Onea | 1588439 | 2019-03-22 17:28:11 +0000 | [diff] [blame] | 136 | @UnsupportedAppUsage |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 137 | protected PackageManager mPm; |
| 138 | protected int mLaunchedFromUid; |
| 139 | |
| 140 | private static final String TAG = "ResolverActivity"; |
| 141 | private static final boolean DEBUG = false; |
Adam Powell | 63b3169 | 2015-09-28 10:45:00 -0700 | [diff] [blame] | 142 | |
Dianne Hackborn | d44713a | 2012-04-30 16:34:46 -0700 | [diff] [blame] | 143 | private boolean mRegistered; |
Jorim Jaggi | f631ef7 | 2017-02-24 13:49:47 +0100 | [diff] [blame] | 144 | |
Matt Pietal | 800136a | 2019-05-08 07:46:39 -0400 | [diff] [blame] | 145 | protected Insets mSystemWindowInsets = null; |
| 146 | private Space mFooterSpacer = null; |
| 147 | |
Jorim Jaggi | f631ef7 | 2017-02-24 13:49:47 +0100 | [diff] [blame] | 148 | /** See {@link #setRetainInOnStop}. */ |
| 149 | private boolean mRetainInOnStop; |
| 150 | |
Matt Pietal | 0d6834a | 2019-06-27 13:27:52 -0400 | [diff] [blame] | 151 | private static final String EXTRA_SHOW_FRAGMENT_ARGS = ":settings:show_fragment_args"; |
| 152 | private static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key"; |
| 153 | private static final String OPEN_LINKS_COMPONENT_KEY = "app_link_state"; |
| 154 | |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 155 | /** |
| 156 | * TODO(arangelov): Remove a couple of weeks after work/personal tabs are finalized. |
| 157 | */ |
arangelov | cf26864 | 2020-01-15 15:09:51 +0000 | [diff] [blame] | 158 | @VisibleForTesting |
| 159 | public static boolean ENABLE_TABBED_VIEW = false; |
| 160 | private static final String TAB_TAG_PERSONAL = "personal"; |
| 161 | private static final String TAB_TAG_WORK = "work"; |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 162 | |
arangelov | 7981b12 | 2020-01-16 10:58:27 +0000 | [diff] [blame] | 163 | private PackageMonitor mPersonalPackageMonitor; |
arangelov | bdb4005 | 2020-01-09 18:01:58 +0000 | [diff] [blame] | 164 | private PackageMonitor mWorkPackageMonitor; |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 165 | |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 166 | @VisibleForTesting |
| 167 | protected AbstractMultiProfilePagerAdapter mMultiProfilePagerAdapter; |
| 168 | |
Paul McLean | 07425c8 | 2019-10-18 12:00:11 -0600 | [diff] [blame] | 169 | // Intent extra for connected audio devices |
| 170 | public static final String EXTRA_IS_AUDIO_CAPTURE_DEVICE = "is_audio_capture_device"; |
| 171 | |
Philip P. Moltmann | f8173ca | 2016-04-12 15:11:23 -0700 | [diff] [blame] | 172 | /** |
| 173 | * Get the string resource to be used as a label for the link to the resolver activity for an |
| 174 | * action. |
| 175 | * |
| 176 | * @param action The action to resolve |
| 177 | * |
| 178 | * @return The string resource to be used as a label |
| 179 | */ |
| 180 | public static @StringRes int getLabelRes(String action) { |
| 181 | return ActionTitle.forAction(action).labelRes; |
| 182 | } |
| 183 | |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 184 | private enum ActionTitle { |
| 185 | VIEW(Intent.ACTION_VIEW, |
| 186 | com.android.internal.R.string.whichViewApplication, |
Philip P. Moltmann | f8173ca | 2016-04-12 15:11:23 -0700 | [diff] [blame] | 187 | com.android.internal.R.string.whichViewApplicationNamed, |
| 188 | com.android.internal.R.string.whichViewApplicationLabel), |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 189 | EDIT(Intent.ACTION_EDIT, |
| 190 | com.android.internal.R.string.whichEditApplication, |
Philip P. Moltmann | f8173ca | 2016-04-12 15:11:23 -0700 | [diff] [blame] | 191 | com.android.internal.R.string.whichEditApplicationNamed, |
| 192 | com.android.internal.R.string.whichEditApplicationLabel), |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 193 | SEND(Intent.ACTION_SEND, |
| 194 | com.android.internal.R.string.whichSendApplication, |
Philip P. Moltmann | f8173ca | 2016-04-12 15:11:23 -0700 | [diff] [blame] | 195 | com.android.internal.R.string.whichSendApplicationNamed, |
| 196 | com.android.internal.R.string.whichSendApplicationLabel), |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 197 | SENDTO(Intent.ACTION_SENDTO, |
Adam Powell | 13ea8f4 | 2016-03-18 09:39:41 -0700 | [diff] [blame] | 198 | com.android.internal.R.string.whichSendToApplication, |
Philip P. Moltmann | f8173ca | 2016-04-12 15:11:23 -0700 | [diff] [blame] | 199 | com.android.internal.R.string.whichSendToApplicationNamed, |
| 200 | com.android.internal.R.string.whichSendToApplicationLabel), |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 201 | SEND_MULTIPLE(Intent.ACTION_SEND_MULTIPLE, |
| 202 | com.android.internal.R.string.whichSendApplication, |
Philip P. Moltmann | f8173ca | 2016-04-12 15:11:23 -0700 | [diff] [blame] | 203 | com.android.internal.R.string.whichSendApplicationNamed, |
| 204 | com.android.internal.R.string.whichSendApplicationLabel), |
| 205 | CAPTURE_IMAGE(MediaStore.ACTION_IMAGE_CAPTURE, |
| 206 | com.android.internal.R.string.whichImageCaptureApplication, |
| 207 | com.android.internal.R.string.whichImageCaptureApplicationNamed, |
| 208 | com.android.internal.R.string.whichImageCaptureApplicationLabel), |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 209 | DEFAULT(null, |
| 210 | com.android.internal.R.string.whichApplication, |
Philip P. Moltmann | f8173ca | 2016-04-12 15:11:23 -0700 | [diff] [blame] | 211 | com.android.internal.R.string.whichApplicationNamed, |
| 212 | com.android.internal.R.string.whichApplicationLabel), |
Adam Powell | a35c77a | 2014-09-25 16:46:36 -0700 | [diff] [blame] | 213 | HOME(Intent.ACTION_MAIN, |
| 214 | com.android.internal.R.string.whichHomeApplication, |
Philip P. Moltmann | f8173ca | 2016-04-12 15:11:23 -0700 | [diff] [blame] | 215 | com.android.internal.R.string.whichHomeApplicationNamed, |
| 216 | com.android.internal.R.string.whichHomeApplicationLabel); |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 217 | |
shafik | 0c7c5d5 | 2019-02-27 12:13:25 +0000 | [diff] [blame] | 218 | // titles for layout that deals with http(s) intents |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 219 | public static final int BROWSABLE_TITLE_RES = |
Matt Pietal | 0d6834a | 2019-06-27 13:27:52 -0400 | [diff] [blame] | 220 | com.android.internal.R.string.whichOpenLinksWith; |
| 221 | public static final int BROWSABLE_HOST_TITLE_RES = |
| 222 | com.android.internal.R.string.whichOpenHostLinksWith; |
| 223 | public static final int BROWSABLE_HOST_APP_TITLE_RES = |
| 224 | com.android.internal.R.string.whichOpenHostLinksWithApp; |
| 225 | public static final int BROWSABLE_APP_TITLE_RES = |
| 226 | com.android.internal.R.string.whichOpenLinksWithApp; |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 227 | |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 228 | public final String action; |
| 229 | public final int titleRes; |
| 230 | public final int namedTitleRes; |
Philip P. Moltmann | f8173ca | 2016-04-12 15:11:23 -0700 | [diff] [blame] | 231 | public final @StringRes int labelRes; |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 232 | |
Philip P. Moltmann | f8173ca | 2016-04-12 15:11:23 -0700 | [diff] [blame] | 233 | ActionTitle(String action, int titleRes, int namedTitleRes, @StringRes int labelRes) { |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 234 | this.action = action; |
| 235 | this.titleRes = titleRes; |
| 236 | this.namedTitleRes = namedTitleRes; |
Philip P. Moltmann | f8173ca | 2016-04-12 15:11:23 -0700 | [diff] [blame] | 237 | this.labelRes = labelRes; |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | public static ActionTitle forAction(String action) { |
| 241 | for (ActionTitle title : values()) { |
Adam Powell | a35c77a | 2014-09-25 16:46:36 -0700 | [diff] [blame] | 242 | if (title != HOME && action != null && action.equals(title.action)) { |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 243 | return title; |
| 244 | } |
| 245 | } |
| 246 | return DEFAULT; |
| 247 | } |
| 248 | } |
| 249 | |
arangelov | 7981b12 | 2020-01-16 10:58:27 +0000 | [diff] [blame] | 250 | protected PackageMonitor createPackageMonitor(ResolverListAdapter listAdapter) { |
Matt Pietal | ab73a88 | 2019-06-05 07:04:55 -0400 | [diff] [blame] | 251 | return new PackageMonitor() { |
| 252 | @Override |
| 253 | public void onSomePackagesChanged() { |
arangelov | 7981b12 | 2020-01-16 10:58:27 +0000 | [diff] [blame] | 254 | listAdapter.handlePackagesChanged(); |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 255 | updateProfileViewButton(); |
Matt Pietal | ab73a88 | 2019-06-05 07:04:55 -0400 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | @Override |
| 259 | public boolean onPackageChanged(String packageName, int uid, String[] components) { |
| 260 | // We care about all package changes, not just the whole package itself which is |
| 261 | // default behavior. |
| 262 | return true; |
| 263 | } |
| 264 | }; |
| 265 | } |
| 266 | |
Dianne Hackborn | 905577f | 2011-09-07 18:31:28 -0700 | [diff] [blame] | 267 | private Intent makeMyIntent() { |
| 268 | Intent intent = new Intent(getIntent()); |
Dianne Hackborn | 6d8dfbd | 2013-09-23 17:38:51 -0700 | [diff] [blame] | 269 | intent.setComponent(null); |
Dianne Hackborn | 905577f | 2011-09-07 18:31:28 -0700 | [diff] [blame] | 270 | // The resolver activity is set to be hidden from recent tasks. |
| 271 | // we don't want this attribute to be propagated to the next activity |
| 272 | // being launched. Note that if the original Intent also had this |
| 273 | // flag set, we are now losing it. That should be a very rare case |
| 274 | // and we can live with this. |
| 275 | intent.setFlags(intent.getFlags()&~Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
| 276 | return intent; |
| 277 | } |
| 278 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 279 | @Override |
| 280 | protected void onCreate(Bundle savedInstanceState) { |
Christopher Tate | b72b363 | 2013-09-30 17:50:32 -0700 | [diff] [blame] | 281 | // Use a specialized prompt when we're handling the 'Home' app startActivity() |
Christopher Tate | b72b363 | 2013-09-30 17:50:32 -0700 | [diff] [blame] | 282 | final Intent intent = makeMyIntent(); |
| 283 | final Set<String> categories = intent.getCategories(); |
| 284 | if (Intent.ACTION_MAIN.equals(intent.getAction()) |
| 285 | && categories != null |
| 286 | && categories.size() == 1 |
| 287 | && categories.contains(Intent.CATEGORY_HOME)) { |
Sander Alewijnse | 6c9eee8 | 2014-07-17 10:03:31 +0100 | [diff] [blame] | 288 | // Note: this field is not set to true in the compatibility version. |
| 289 | mResolvingHome = true; |
Christopher Tate | b72b363 | 2013-09-30 17:50:32 -0700 | [diff] [blame] | 290 | } |
| 291 | |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 292 | setSafeForwardingMode(true); |
| 293 | |
Adam Powell | a35c77a | 2014-09-25 16:46:36 -0700 | [diff] [blame] | 294 | onCreate(savedInstanceState, intent, null, 0, null, null, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 295 | } |
| 296 | |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 297 | /** |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 298 | * Compatibility version for other bundled services that use this overload without |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 299 | * a default title resource |
| 300 | */ |
Andrei Onea | 1588439 | 2019-03-22 17:28:11 +0000 | [diff] [blame] | 301 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 302 | protected void onCreate(Bundle savedInstanceState, Intent intent, |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 303 | CharSequence title, Intent[] initialIntents, |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 304 | List<ResolveInfo> rList, boolean supportsAlwaysUseOption) { |
| 305 | onCreate(savedInstanceState, intent, title, 0, initialIntents, rList, |
| 306 | supportsAlwaysUseOption); |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | protected void onCreate(Bundle savedInstanceState, Intent intent, |
| 310 | CharSequence title, int defaultTitleRes, Intent[] initialIntents, |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 311 | List<ResolveInfo> rList, boolean supportsAlwaysUseOption) { |
Adam Powell | e9414d9 | 2014-07-05 17:44:18 -0700 | [diff] [blame] | 312 | setTheme(R.style.Theme_DeviceDefault_Resolver); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 313 | super.onCreate(savedInstanceState); |
Sander Alewijnse | f654533 | 2014-10-31 12:39:02 +0000 | [diff] [blame] | 314 | |
| 315 | // Determine whether we should show that intent is forwarded |
| 316 | // from managed profile to owner or other way around. |
| 317 | setProfileSwitchMessageId(intent.getContentUserHint()); |
| 318 | |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 319 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 320 | mLaunchedFromUid = ActivityTaskManager.getService().getLaunchedFromUid( |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 321 | getActivityToken()); |
| 322 | } catch (RemoteException e) { |
| 323 | mLaunchedFromUid = -1; |
| 324 | } |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 325 | |
| 326 | if (mLaunchedFromUid < 0 || UserHandle.isIsolated(mLaunchedFromUid)) { |
| 327 | // Gulp! |
| 328 | finish(); |
| 329 | return; |
| 330 | } |
| 331 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 332 | mPm = getPackageManager(); |
Adam Powell | 09a6560 | 2014-07-20 16:23:14 -0700 | [diff] [blame] | 333 | |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 334 | mReferrerPackage = getReferrerPackageName(); |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 335 | |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 336 | // 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] | 337 | mIntents.add(0, new Intent(intent)); |
Hakan Seyalioglu | 3355012 | 2017-01-06 19:54:43 -0800 | [diff] [blame] | 338 | mTitle = title; |
| 339 | mDefaultTitleResId = defaultTitleRes; |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 340 | |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 341 | mUseLayoutForBrowsables = getTargetIntent() == null |
| 342 | ? false |
shafik | 0c7c5d5 | 2019-02-27 12:13:25 +0000 | [diff] [blame] | 343 | : isHttpSchemeAndViewAction(getTargetIntent()); |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 344 | |
Matt Pietal | 0d6834a | 2019-06-27 13:27:52 -0400 | [diff] [blame] | 345 | mSupportsAlwaysUseOption = supportsAlwaysUseOption; |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 346 | |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 347 | // The last argument of createResolverListAdapter is whether to do special handling |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 348 | // of the last used choice to highlight it in the list. We need to always |
| 349 | // turn this off when running under voice interaction, since it results in |
| 350 | // a more complicated UI that the current voice interaction flow is not able |
| 351 | // to handle. |
| 352 | boolean filterLastUsed = mSupportsAlwaysUseOption && !isVoiceInteraction(); |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 353 | mMultiProfilePagerAdapter = createMultiProfilePagerAdapter(initialIntents, rList, filterLastUsed); |
arangelov | bb57233 | 2019-11-13 12:50:08 +0000 | [diff] [blame] | 354 | if (configureContentView()) { |
Adam Powell | 39e94eb | 2015-09-08 17:01:49 -0700 | [diff] [blame] | 355 | return; |
| 356 | } |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 357 | |
arangelov | 7981b12 | 2020-01-16 10:58:27 +0000 | [diff] [blame] | 358 | mPersonalPackageMonitor = createPackageMonitor( |
| 359 | mMultiProfilePagerAdapter.getPersonalListAdapter()); |
| 360 | mPersonalPackageMonitor.register( |
| 361 | this, getMainLooper(), getPersonalProfileUserHandle(), false); |
| 362 | if (hasWorkProfile()) { |
| 363 | mWorkPackageMonitor = createPackageMonitor( |
| 364 | mMultiProfilePagerAdapter.getWorkListAdapter()); |
| 365 | mWorkPackageMonitor.register(this, getMainLooper(), getWorkProfileUserHandle(), false); |
| 366 | } |
| 367 | |
| 368 | mRegistered = true; |
| 369 | |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 370 | final ResolverDrawerLayout rdl = findViewById(R.id.contentPanel); |
Adam Powell | 4f6c205 | 2014-07-07 18:49:10 -0700 | [diff] [blame] | 371 | if (rdl != null) { |
Adam Powell | 5dd072d | 2014-10-30 19:51:41 -0700 | [diff] [blame] | 372 | rdl.setOnDismissedListener(new ResolverDrawerLayout.OnDismissedListener() { |
Adam Powell | 4f6c205 | 2014-07-07 18:49:10 -0700 | [diff] [blame] | 373 | @Override |
Adam Powell | 5dd072d | 2014-10-30 19:51:41 -0700 | [diff] [blame] | 374 | public void onDismissed() { |
Adam Powell | 4f6c205 | 2014-07-07 18:49:10 -0700 | [diff] [blame] | 375 | finish(); |
| 376 | } |
| 377 | }); |
Sergey Troshin | 40e979e | 2019-12-30 17:29:50 +0100 | [diff] [blame] | 378 | |
| 379 | boolean hasTouchScreen = getPackageManager() |
| 380 | .hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN); |
| 381 | |
| 382 | if (isVoiceInteraction() || !hasTouchScreen) { |
Adam Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 383 | rdl.setCollapsed(false); |
| 384 | } |
Matt Pietal | 800136a | 2019-05-08 07:46:39 -0400 | [diff] [blame] | 385 | |
| 386 | rdl.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
| 387 | | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); |
| 388 | rdl.setOnApplyWindowInsetsListener(this::onApplyWindowInsets); |
| 389 | |
Adam Powell | 63b3169 | 2015-09-28 10:45:00 -0700 | [diff] [blame] | 390 | mResolverDrawerLayout = rdl; |
Adam Powell | 4f6c205 | 2014-07-07 18:49:10 -0700 | [diff] [blame] | 391 | } |
| 392 | |
Adam Powell | 88831a2 | 2014-11-20 18:17:00 -0800 | [diff] [blame] | 393 | mProfileView = findViewById(R.id.profile_button); |
| 394 | if (mProfileView != null) { |
Matt Pietal | 74c6ed0 | 2019-04-18 13:38:46 -0400 | [diff] [blame] | 395 | mProfileView.setOnClickListener(this::onProfileClick); |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 396 | updateProfileViewButton(); |
Adam Powell | 88831a2 | 2014-11-20 18:17:00 -0800 | [diff] [blame] | 397 | } |
Adam Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 398 | |
Clara Bayarri | 9550f5d | 2016-05-11 11:20:13 +0100 | [diff] [blame] | 399 | final Set<String> categories = intent.getCategories(); |
arangelov | a3912cf | 2019-12-13 14:34:45 +0000 | [diff] [blame] | 400 | MetricsLogger.action(this, mMultiProfilePagerAdapter.getActiveListAdapter().hasFilteredItem() |
Clara Bayarri | fa902aa | 2016-04-13 14:45:08 +0100 | [diff] [blame] | 401 | ? MetricsProto.MetricsEvent.ACTION_SHOW_APP_DISAMBIG_APP_FEATURED |
| 402 | : MetricsProto.MetricsEvent.ACTION_SHOW_APP_DISAMBIG_NONE_FEATURED, |
| 403 | intent.getAction() + ":" + intent.getType() + ":" |
Clara Bayarri | 9550f5d | 2016-05-11 11:20:13 +0100 | [diff] [blame] | 404 | + (categories != null ? Arrays.toString(categories.toArray()) : "")); |
Adam Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 405 | } |
| 406 | |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 407 | protected AbstractMultiProfilePagerAdapter createMultiProfilePagerAdapter( |
| 408 | Intent[] initialIntents, |
| 409 | List<ResolveInfo> rList, |
| 410 | boolean filterLastUsed) { |
| 411 | AbstractMultiProfilePagerAdapter resolverMultiProfilePagerAdapter = null; |
| 412 | if (hasWorkProfile() && ENABLE_TABBED_VIEW) { |
| 413 | resolverMultiProfilePagerAdapter = |
| 414 | createResolverMultiProfilePagerAdapterForTwoProfiles( |
| 415 | initialIntents, rList, filterLastUsed); |
| 416 | } else { |
| 417 | resolverMultiProfilePagerAdapter = createResolverMultiProfilePagerAdapterForOneProfile( |
| 418 | initialIntents, rList, filterLastUsed); |
| 419 | } |
| 420 | return resolverMultiProfilePagerAdapter; |
| 421 | } |
| 422 | |
| 423 | private ResolverMultiProfilePagerAdapter createResolverMultiProfilePagerAdapterForOneProfile( |
| 424 | Intent[] initialIntents, |
| 425 | List<ResolveInfo> rList, boolean filterLastUsed) { |
| 426 | ResolverListAdapter adapter = createResolverListAdapter( |
| 427 | /* context */ this, |
| 428 | /* payloadIntents */ mIntents, |
| 429 | initialIntents, |
| 430 | rList, |
| 431 | filterLastUsed, |
| 432 | mUseLayoutForBrowsables, |
| 433 | /* userHandle */ UserHandle.of(UserHandle.myUserId())); |
| 434 | return new ResolverMultiProfilePagerAdapter( |
| 435 | /* context */ this, |
arangelov | 7981b12 | 2020-01-16 10:58:27 +0000 | [diff] [blame] | 436 | adapter, |
| 437 | getPersonalProfileUserHandle(), |
| 438 | /* workProfileUserHandle= */ null); |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | private ResolverMultiProfilePagerAdapter createResolverMultiProfilePagerAdapterForTwoProfiles( |
| 442 | Intent[] initialIntents, |
| 443 | List<ResolveInfo> rList, |
| 444 | boolean filterLastUsed) { |
arangelov | cf26864 | 2020-01-15 15:09:51 +0000 | [diff] [blame] | 445 | // We only show the default app for the profile of the current user. The filterLastUsed |
| 446 | // flag determines whether to show a default app and that app is not shown in the |
| 447 | // resolver list. So filterLastUsed should be false for the other profile. |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 448 | ResolverListAdapter personalAdapter = createResolverListAdapter( |
| 449 | /* context */ this, |
| 450 | /* payloadIntents */ mIntents, |
| 451 | initialIntents, |
| 452 | rList, |
arangelov | cf26864 | 2020-01-15 15:09:51 +0000 | [diff] [blame] | 453 | (filterLastUsed && UserHandle.myUserId() |
| 454 | == getPersonalProfileUserHandle().getIdentifier()), |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 455 | mUseLayoutForBrowsables, |
| 456 | /* userHandle */ getPersonalProfileUserHandle()); |
arangelov | 7981b12 | 2020-01-16 10:58:27 +0000 | [diff] [blame] | 457 | UserHandle workProfileUserHandle = getWorkProfileUserHandle(); |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 458 | ResolverListAdapter workAdapter = createResolverListAdapter( |
| 459 | /* context */ this, |
| 460 | /* payloadIntents */ mIntents, |
| 461 | initialIntents, |
| 462 | rList, |
arangelov | cf26864 | 2020-01-15 15:09:51 +0000 | [diff] [blame] | 463 | (filterLastUsed && UserHandle.myUserId() |
arangelov | 7981b12 | 2020-01-16 10:58:27 +0000 | [diff] [blame] | 464 | == workProfileUserHandle.getIdentifier()), |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 465 | mUseLayoutForBrowsables, |
arangelov | 7981b12 | 2020-01-16 10:58:27 +0000 | [diff] [blame] | 466 | /* userHandle */ workProfileUserHandle); |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 467 | return new ResolverMultiProfilePagerAdapter( |
| 468 | /* context */ this, |
| 469 | personalAdapter, |
| 470 | workAdapter, |
arangelov | 7981b12 | 2020-01-16 10:58:27 +0000 | [diff] [blame] | 471 | /* defaultProfile */ getCurrentProfile(), |
| 472 | getPersonalProfileUserHandle(), |
| 473 | getWorkProfileUserHandle()); |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | protected @Profile int getCurrentProfile() { |
| 477 | return (UserHandle.myUserId() == UserHandle.USER_SYSTEM ? PROFILE_PERSONAL : PROFILE_WORK); |
| 478 | } |
| 479 | |
| 480 | protected UserHandle getPersonalProfileUserHandle() { |
| 481 | return UserHandle.of(ActivityManager.getCurrentUser()); |
| 482 | } |
| 483 | protected @Nullable UserHandle getWorkProfileUserHandle() { |
| 484 | UserManager userManager = getSystemService(UserManager.class); |
| 485 | for (final UserInfo userInfo : userManager.getProfiles(ActivityManager.getCurrentUser())) { |
| 486 | if (userInfo.isManagedProfile()) { |
| 487 | return userInfo.getUserHandle(); |
| 488 | } |
| 489 | } |
| 490 | return null; |
| 491 | } |
| 492 | |
| 493 | protected boolean hasWorkProfile() { |
| 494 | return getWorkProfileUserHandle() != null; |
| 495 | } |
| 496 | |
Matt Pietal | 74c6ed0 | 2019-04-18 13:38:46 -0400 | [diff] [blame] | 497 | protected void onProfileClick(View v) { |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 498 | final DisplayResolveInfo dri = |
arangelov | a3912cf | 2019-12-13 14:34:45 +0000 | [diff] [blame] | 499 | mMultiProfilePagerAdapter.getActiveListAdapter().getOtherProfile(); |
Matt Pietal | 74c6ed0 | 2019-04-18 13:38:46 -0400 | [diff] [blame] | 500 | if (dri == null) { |
| 501 | return; |
| 502 | } |
| 503 | |
| 504 | // Do not show the profile switch message anymore. |
| 505 | mProfileSwitchMessageId = -1; |
| 506 | |
| 507 | onTargetSelected(dri, false); |
| 508 | finish(); |
| 509 | } |
| 510 | |
Matt Pietal | 9236adc | 2019-12-12 09:24:23 -0500 | [diff] [blame] | 511 | /** |
| 512 | * Numerous layouts are supported, each with optional ViewGroups. |
| 513 | * Make sure the inset gets added to the correct View, using |
| 514 | * a footer for Lists so it can properly scroll under the navbar. |
| 515 | */ |
| 516 | protected boolean shouldAddFooterView() { |
| 517 | if (useLayoutWithDefault()) return true; |
| 518 | |
| 519 | View buttonBar = findViewById(R.id.button_bar); |
| 520 | if (buttonBar == null || buttonBar.getVisibility() == View.GONE) return true; |
| 521 | |
| 522 | return false; |
| 523 | } |
| 524 | |
| 525 | protected void applyFooterView(int height) { |
| 526 | if (mFooterSpacer == null) { |
| 527 | mFooterSpacer = new Space(getApplicationContext()); |
| 528 | } else { |
| 529 | ((ResolverMultiProfilePagerAdapter) mMultiProfilePagerAdapter) |
arangelov | cf26864 | 2020-01-15 15:09:51 +0000 | [diff] [blame] | 530 | .getActiveAdapterView().removeFooterView(mFooterSpacer); |
Matt Pietal | 9236adc | 2019-12-12 09:24:23 -0500 | [diff] [blame] | 531 | } |
| 532 | mFooterSpacer.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT, |
| 533 | mSystemWindowInsets.bottom)); |
| 534 | ((ResolverMultiProfilePagerAdapter) mMultiProfilePagerAdapter) |
arangelov | cf26864 | 2020-01-15 15:09:51 +0000 | [diff] [blame] | 535 | .getActiveAdapterView().addFooterView(mFooterSpacer); |
Matt Pietal | 9236adc | 2019-12-12 09:24:23 -0500 | [diff] [blame] | 536 | } |
| 537 | |
Matt Pietal | 800136a | 2019-05-08 07:46:39 -0400 | [diff] [blame] | 538 | protected WindowInsets onApplyWindowInsets(View v, WindowInsets insets) { |
| 539 | mSystemWindowInsets = insets.getSystemWindowInsets(); |
| 540 | |
| 541 | mResolverDrawerLayout.setPadding(mSystemWindowInsets.left, mSystemWindowInsets.top, |
| 542 | mSystemWindowInsets.right, 0); |
| 543 | |
Matt Pietal | 9236adc | 2019-12-12 09:24:23 -0500 | [diff] [blame] | 544 | resetButtonBar(); |
| 545 | |
Matt Pietal | d507120 | 2019-10-10 11:21:28 -0400 | [diff] [blame] | 546 | // Need extra padding so the list can fully scroll up |
Matt Pietal | 9236adc | 2019-12-12 09:24:23 -0500 | [diff] [blame] | 547 | if (shouldAddFooterView()) { |
| 548 | applyFooterView(mSystemWindowInsets.bottom); |
Matt Pietal | 800136a | 2019-05-08 07:46:39 -0400 | [diff] [blame] | 549 | } |
Matt Pietal | 800136a | 2019-05-08 07:46:39 -0400 | [diff] [blame] | 550 | |
Matt Pietal | 9236adc | 2019-12-12 09:24:23 -0500 | [diff] [blame] | 551 | View emptyView = findViewById(R.id.empty); |
| 552 | if (emptyView != null) { |
| 553 | emptyView.setPadding(0, 0, 0, mSystemWindowInsets.bottom |
| 554 | + getResources().getDimensionPixelSize( |
| 555 | R.dimen.chooser_edge_margin_normal) * 2); |
| 556 | } |
Matt Pietal | 78fdbd4 | 2019-06-05 07:08:08 -0400 | [diff] [blame] | 557 | |
Matt Pietal | 800136a | 2019-05-08 07:46:39 -0400 | [diff] [blame] | 558 | return insets.consumeSystemWindowInsets(); |
| 559 | } |
| 560 | |
Jiongxuan Gao | 3365b16 | 2016-11-24 20:20:27 +0900 | [diff] [blame] | 561 | @Override |
| 562 | public void onConfigurationChanged(Configuration newConfig) { |
| 563 | super.onConfigurationChanged(newConfig); |
arangelov | a3912cf | 2019-12-13 14:34:45 +0000 | [diff] [blame] | 564 | mMultiProfilePagerAdapter.getActiveListAdapter().handlePackagesChanged(); |
Matt Pietal | 800136a | 2019-05-08 07:46:39 -0400 | [diff] [blame] | 565 | |
| 566 | if (mSystemWindowInsets != null) { |
| 567 | mResolverDrawerLayout.setPadding(mSystemWindowInsets.left, mSystemWindowInsets.top, |
| 568 | mSystemWindowInsets.right, 0); |
| 569 | } |
Jiongxuan Gao | 3365b16 | 2016-11-24 20:20:27 +0900 | [diff] [blame] | 570 | } |
| 571 | |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 572 | @Override // ResolverListCommunicator |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 573 | public void sendVoiceChoicesIfNeeded() { |
Adam Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 574 | if (!isVoiceInteraction()) { |
| 575 | // Clearly not needed. |
| 576 | return; |
| 577 | } |
| 578 | |
arangelov | a3912cf | 2019-12-13 14:34:45 +0000 | [diff] [blame] | 579 | int count = mMultiProfilePagerAdapter.getActiveListAdapter().getCount(); |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 580 | final Option[] options = new Option[count]; |
Adam Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 581 | for (int i = 0, N = options.length; i < N; i++) { |
arangelov | a3912cf | 2019-12-13 14:34:45 +0000 | [diff] [blame] | 582 | TargetInfo target = mMultiProfilePagerAdapter.getActiveListAdapter().getItem(i); |
Matt Pietal | 2cf4c6c | 2019-09-10 09:33:11 -0400 | [diff] [blame] | 583 | if (target == null) { |
| 584 | // If this occurs, a new set of targets is being loaded. Let that complete, |
| 585 | // and have the next call to send voice choices proceed instead. |
| 586 | return; |
| 587 | } |
| 588 | options[i] = optionForChooserTarget(target, i); |
Adam Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | mPickOptionRequest = new PickTargetOptionRequest( |
| 592 | new Prompt(getTitle()), options, null); |
| 593 | getVoiceInteractor().submitRequest(mPickOptionRequest); |
| 594 | } |
| 595 | |
| 596 | Option optionForChooserTarget(TargetInfo target, int index) { |
| 597 | return new Option(target.getDisplayLabel(), index); |
Adam Powell | 88831a2 | 2014-11-20 18:17:00 -0800 | [diff] [blame] | 598 | } |
| 599 | |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 600 | protected final void setAdditionalTargets(Intent[] intents) { |
| 601 | if (intents != null) { |
| 602 | for (Intent intent : intents) { |
| 603 | mIntents.add(intent); |
| 604 | } |
| 605 | } |
| 606 | } |
| 607 | |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 608 | @Override // SelectableTargetInfoCommunicator ResolverListCommunicator |
Adam Powell | 0ccc0e9 | 2015-04-23 17:19:37 -0700 | [diff] [blame] | 609 | public Intent getTargetIntent() { |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 610 | return mIntents.isEmpty() ? null : mIntents.get(0); |
Adam Powell | 0ccc0e9 | 2015-04-23 17:19:37 -0700 | [diff] [blame] | 611 | } |
| 612 | |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 613 | protected String getReferrerPackageName() { |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 614 | final Uri referrer = getReferrer(); |
| 615 | if (referrer != null && "android-app".equals(referrer.getScheme())) { |
| 616 | return referrer.getHost(); |
| 617 | } |
| 618 | return null; |
| 619 | } |
| 620 | |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 621 | public int getLayoutResource() { |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 622 | return R.layout.resolver_list; |
| 623 | } |
| 624 | |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 625 | @Override // ResolverListCommunicator |
| 626 | public void updateProfileViewButton() { |
Matt Pietal | 74c6ed0 | 2019-04-18 13:38:46 -0400 | [diff] [blame] | 627 | if (mProfileView == null) { |
| 628 | return; |
| 629 | } |
| 630 | |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 631 | final DisplayResolveInfo dri = |
arangelov | a3912cf | 2019-12-13 14:34:45 +0000 | [diff] [blame] | 632 | mMultiProfilePagerAdapter.getActiveListAdapter().getOtherProfile(); |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 633 | if (dri != null && !ENABLE_TABBED_VIEW) { |
Adam Powell | 88831a2 | 2014-11-20 18:17:00 -0800 | [diff] [blame] | 634 | mProfileView.setVisibility(View.VISIBLE); |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 635 | View text = mProfileView.findViewById(R.id.profile_button); |
| 636 | if (!(text instanceof TextView)) { |
| 637 | text = mProfileView.findViewById(R.id.text1); |
| 638 | } |
| 639 | ((TextView) text).setText(dri.getDisplayLabel()); |
Adam Powell | 88831a2 | 2014-11-20 18:17:00 -0800 | [diff] [blame] | 640 | } else { |
| 641 | mProfileView.setVisibility(View.GONE); |
| 642 | } |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 643 | } |
| 644 | |
Sander Alewijnse | f654533 | 2014-10-31 12:39:02 +0000 | [diff] [blame] | 645 | private void setProfileSwitchMessageId(int contentUserHint) { |
| 646 | if (contentUserHint != UserHandle.USER_CURRENT && |
| 647 | contentUserHint != UserHandle.myUserId()) { |
| 648 | UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE); |
| 649 | UserInfo originUserInfo = userManager.getUserInfo(contentUserHint); |
| 650 | boolean originIsManaged = originUserInfo != null ? originUserInfo.isManagedProfile() |
| 651 | : false; |
| 652 | boolean targetIsManaged = userManager.isManagedProfile(); |
| 653 | if (originIsManaged && !targetIsManaged) { |
| 654 | mProfileSwitchMessageId = com.android.internal.R.string.forward_intent_to_owner; |
| 655 | } else if (!originIsManaged && targetIsManaged) { |
| 656 | mProfileSwitchMessageId = com.android.internal.R.string.forward_intent_to_work; |
| 657 | } |
| 658 | } |
| 659 | } |
| 660 | |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 661 | /** |
| 662 | * Turn on launch mode that is safe to use when forwarding intents received from |
| 663 | * applications and running in system processes. This mode uses Activity.startActivityAsCaller |
| 664 | * instead of the normal Activity.startActivity for launching the activity selected |
| 665 | * by the user. |
| 666 | * |
| 667 | * <p>This mode is set to true by default if the activity is initialized through |
| 668 | * {@link #onCreate(android.os.Bundle)}. If a subclass calls one of the other onCreate |
| 669 | * methods, it is set to false by default. You must set it before calling one of the |
| 670 | * more detailed onCreate methods, so that it will be set correctly in the case where |
| 671 | * there is only one intent to resolve and it is thus started immediately.</p> |
| 672 | */ |
| 673 | public void setSafeForwardingMode(boolean safeForwarding) { |
| 674 | mSafeForwardingMode = safeForwarding; |
| 675 | } |
| 676 | |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 677 | protected CharSequence getTitleForAction(Intent intent, int defaultTitleRes) { |
| 678 | final ActionTitle title = mResolvingHome |
| 679 | ? ActionTitle.HOME |
| 680 | : ActionTitle.forAction(intent.getAction()); |
| 681 | |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 682 | // While there may already be a filtered item, we can only use it in the title if the list |
| 683 | // 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] | 684 | final boolean named = |
arangelov | a3912cf | 2019-12-13 14:34:45 +0000 | [diff] [blame] | 685 | mMultiProfilePagerAdapter.getActiveListAdapter().getFilteredPosition() >= 0; |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 686 | if (title == ActionTitle.DEFAULT && defaultTitleRes != 0) { |
| 687 | return getString(defaultTitleRes); |
shafik | 0c7c5d5 | 2019-02-27 12:13:25 +0000 | [diff] [blame] | 688 | } else if (isHttpSchemeAndViewAction(intent)) { |
| 689 | // 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] | 690 | // 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] | 691 | String dialogTitle = null; |
| 692 | if (named && !mUseLayoutForBrowsables) { |
| 693 | dialogTitle = getString(ActionTitle.BROWSABLE_APP_TITLE_RES, |
arangelov | a3912cf | 2019-12-13 14:34:45 +0000 | [diff] [blame] | 694 | mMultiProfilePagerAdapter.getActiveListAdapter().getFilteredItem() |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 695 | .getDisplayLabel()); |
Matt Pietal | 0d6834a | 2019-06-27 13:27:52 -0400 | [diff] [blame] | 696 | } else if (named && mUseLayoutForBrowsables) { |
| 697 | dialogTitle = getString(ActionTitle.BROWSABLE_HOST_APP_TITLE_RES, |
| 698 | intent.getData().getHost(), |
arangelov | a3912cf | 2019-12-13 14:34:45 +0000 | [diff] [blame] | 699 | mMultiProfilePagerAdapter.getActiveListAdapter().getFilteredItem() |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 700 | .getDisplayLabel()); |
arangelov | a3912cf | 2019-12-13 14:34:45 +0000 | [diff] [blame] | 701 | } else if (mMultiProfilePagerAdapter.getActiveListAdapter().areAllTargetsBrowsers()) { |
Matt Pietal | d507120 | 2019-10-10 11:21:28 -0400 | [diff] [blame] | 702 | dialogTitle = getString(ActionTitle.BROWSABLE_TITLE_RES); |
Matt Pietal | 0d6834a | 2019-06-27 13:27:52 -0400 | [diff] [blame] | 703 | } else { |
| 704 | dialogTitle = getString(ActionTitle.BROWSABLE_HOST_TITLE_RES, |
| 705 | intent.getData().getHost()); |
| 706 | } |
| 707 | return dialogTitle; |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 708 | } else { |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 709 | return named |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 710 | ? getString(title.namedTitleRes, mMultiProfilePagerAdapter |
arangelov | a3912cf | 2019-12-13 14:34:45 +0000 | [diff] [blame] | 711 | .getActiveListAdapter().getFilteredItem().getDisplayLabel()) |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 712 | : getString(title.titleRes); |
Amith Yamasani | e9ecc8b | 2013-08-22 11:16:27 -0700 | [diff] [blame] | 713 | } |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 714 | } |
| 715 | |
Adam Powell | e9414d9 | 2014-07-05 17:44:18 -0700 | [diff] [blame] | 716 | void dismiss() { |
| 717 | if (!isFinishing()) { |
| 718 | finish(); |
| 719 | } |
| 720 | } |
| 721 | |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 722 | @Override |
| 723 | protected void onRestart() { |
| 724 | super.onRestart(); |
Dianne Hackborn | d44713a | 2012-04-30 16:34:46 -0700 | [diff] [blame] | 725 | if (!mRegistered) { |
arangelov | bdb4005 | 2020-01-09 18:01:58 +0000 | [diff] [blame] | 726 | mPersonalPackageMonitor.register(this, getMainLooper(), |
| 727 | getPersonalProfileUserHandle(), false); |
| 728 | if (hasWorkProfile()) { |
| 729 | if (mWorkPackageMonitor == null) { |
arangelov | 7981b12 | 2020-01-16 10:58:27 +0000 | [diff] [blame] | 730 | mWorkPackageMonitor = createPackageMonitor( |
| 731 | mMultiProfilePagerAdapter.getWorkListAdapter()); |
arangelov | bdb4005 | 2020-01-09 18:01:58 +0000 | [diff] [blame] | 732 | } |
| 733 | mWorkPackageMonitor.register(this, getMainLooper(), |
| 734 | getWorkProfileUserHandle(), false); |
| 735 | } |
Dianne Hackborn | d44713a | 2012-04-30 16:34:46 -0700 | [diff] [blame] | 736 | mRegistered = true; |
| 737 | } |
arangelov | a3912cf | 2019-12-13 14:34:45 +0000 | [diff] [blame] | 738 | mMultiProfilePagerAdapter.getActiveListAdapter().handlePackagesChanged(); |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 739 | updateProfileViewButton(); |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | @Override |
| 743 | protected void onStop() { |
| 744 | super.onStop(); |
Dianne Hackborn | d44713a | 2012-04-30 16:34:46 -0700 | [diff] [blame] | 745 | if (mRegistered) { |
arangelov | bdb4005 | 2020-01-09 18:01:58 +0000 | [diff] [blame] | 746 | mPersonalPackageMonitor.unregister(); |
| 747 | if (mWorkPackageMonitor != null) { |
| 748 | mWorkPackageMonitor.unregister(); |
| 749 | } |
Dianne Hackborn | d44713a | 2012-04-30 16:34:46 -0700 | [diff] [blame] | 750 | mRegistered = false; |
| 751 | } |
Wale Ogunwale | 9014e66 | 2016-03-19 14:55:46 -0700 | [diff] [blame] | 752 | final Intent intent = getIntent(); |
| 753 | if ((intent.getFlags() & FLAG_ACTIVITY_NEW_TASK) != 0 && !isVoiceInteraction() |
Jorim Jaggi | f631ef7 | 2017-02-24 13:49:47 +0100 | [diff] [blame] | 754 | && !mResolvingHome && !mRetainInOnStop) { |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 755 | // This resolver is in the unusual situation where it has been |
| 756 | // launched at the top of a new task. We don't let it be added |
| 757 | // to the recent tasks shown to the user, and we need to make sure |
| 758 | // that each time we are launched we get the correct launching |
| 759 | // uid (not re-using the same resolver from an old launching uid), |
| 760 | // so we will now finish ourself since being no longer visible, |
| 761 | // the user probably can't get back to us. |
| 762 | if (!isChangingConfigurations()) { |
| 763 | finish(); |
| 764 | } |
| 765 | } |
Dianne Hackborn | e8f2c7f | 2012-03-01 17:30:53 -0800 | [diff] [blame] | 766 | } |
| 767 | |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 768 | @Override |
Adam Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 769 | protected void onDestroy() { |
| 770 | super.onDestroy(); |
| 771 | if (!isChangingConfigurations() && mPickOptionRequest != null) { |
| 772 | mPickOptionRequest.cancel(); |
| 773 | } |
arangelov | a3912cf | 2019-12-13 14:34:45 +0000 | [diff] [blame] | 774 | if (mMultiProfilePagerAdapter.getActiveListAdapter() != null) { |
| 775 | mMultiProfilePagerAdapter.getActiveListAdapter().onDestroy(); |
Kang Li | 38a6da64 | 2017-04-05 12:30:55 -0700 | [diff] [blame] | 776 | } |
Adam Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | @Override |
Adam Powell | 9bee466 | 2012-05-08 11:07:23 -0700 | [diff] [blame] | 780 | protected void onRestoreInstanceState(Bundle savedInstanceState) { |
| 781 | super.onRestoreInstanceState(savedInstanceState); |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 782 | resetButtonBar(); |
Adam Powell | 9bee466 | 2012-05-08 11:07:23 -0700 | [diff] [blame] | 783 | } |
| 784 | |
shafik | 0c7c5d5 | 2019-02-27 12:13:25 +0000 | [diff] [blame] | 785 | private boolean isHttpSchemeAndViewAction(Intent intent) { |
| 786 | return (IntentFilter.SCHEME_HTTP.equals(intent.getScheme()) |
| 787 | || IntentFilter.SCHEME_HTTPS.equals(intent.getScheme())) |
| 788 | && Intent.ACTION_VIEW.equals(intent.getAction()); |
| 789 | } |
| 790 | |
Sander Alewijnse | 6c9eee8 | 2014-07-17 10:03:31 +0100 | [diff] [blame] | 791 | private boolean hasManagedProfile() { |
| 792 | UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE); |
| 793 | if (userManager == null) { |
| 794 | return false; |
| 795 | } |
| 796 | |
| 797 | try { |
| 798 | List<UserInfo> profiles = userManager.getProfiles(getUserId()); |
| 799 | for (UserInfo userInfo : profiles) { |
| 800 | if (userInfo != null && userInfo.isManagedProfile()) { |
| 801 | return true; |
| 802 | } |
| 803 | } |
| 804 | } catch (SecurityException e) { |
| 805 | return false; |
| 806 | } |
| 807 | return false; |
| 808 | } |
| 809 | |
| 810 | private boolean supportsManagedProfiles(ResolveInfo resolveInfo) { |
| 811 | try { |
| 812 | ApplicationInfo appInfo = getPackageManager().getApplicationInfo( |
| 813 | resolveInfo.activityInfo.packageName, 0 /* default flags */); |
Adam Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 814 | return appInfo.targetSdkVersion >= Build.VERSION_CODES.LOLLIPOP; |
Sander Alewijnse | 6c9eee8 | 2014-07-17 10:03:31 +0100 | [diff] [blame] | 815 | } catch (NameNotFoundException e) { |
| 816 | return false; |
| 817 | } |
| 818 | } |
| 819 | |
Adam Powell | 278902c | 2014-07-12 18:33:22 -0700 | [diff] [blame] | 820 | private void setAlwaysButtonEnabled(boolean hasValidSelection, int checkedPos, |
| 821 | boolean filtered) { |
Nicolas Prevot | 5044988 | 2014-06-23 12:42:37 +0100 | [diff] [blame] | 822 | boolean enabled = false; |
Paul McLean | 3a30e55 | 2019-12-07 14:47:29 -0700 | [diff] [blame] | 823 | ResolveInfo ri = null; |
Nicolas Prevot | 5044988 | 2014-06-23 12:42:37 +0100 | [diff] [blame] | 824 | if (hasValidSelection) { |
arangelov | a3912cf | 2019-12-13 14:34:45 +0000 | [diff] [blame] | 825 | ri = mMultiProfilePagerAdapter.getActiveListAdapter() |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 826 | .resolveInfoForPosition(checkedPos, filtered); |
Hakan Seyalioglu | 5dbc819 | 2017-02-24 16:16:37 -0800 | [diff] [blame] | 827 | if (ri == null) { |
| 828 | Log.e(TAG, "Invalid position supplied to setAlwaysButtonEnabled"); |
| 829 | return; |
| 830 | } else if (ri.targetUserId != UserHandle.USER_CURRENT) { |
| 831 | Log.e(TAG, "Attempted to set selection to resolve info for another user"); |
| 832 | return; |
| 833 | } else { |
Nicolas Prevot | 5044988 | 2014-06-23 12:42:37 +0100 | [diff] [blame] | 834 | enabled = true; |
| 835 | } |
Matt Pietal | 0d6834a | 2019-06-27 13:27:52 -0400 | [diff] [blame] | 836 | if (mUseLayoutForBrowsables && !ri.handleAllWebDataURI) { |
| 837 | mAlwaysButton.setText(getResources() |
| 838 | .getString(R.string.activity_resolver_set_always)); |
| 839 | } else { |
| 840 | mAlwaysButton.setText(getResources() |
| 841 | .getString(R.string.activity_resolver_use_always)); |
| 842 | } |
Nicolas Prevot | 5044988 | 2014-06-23 12:42:37 +0100 | [diff] [blame] | 843 | } |
Paul McLean | 3a30e55 | 2019-12-07 14:47:29 -0700 | [diff] [blame] | 844 | |
| 845 | ActivityInfo activityInfo = ri.activityInfo; |
| 846 | |
| 847 | boolean hasRecordPermission = |
Paul McLean | c613c77 | 2019-12-13 11:36:16 -0700 | [diff] [blame] | 848 | mPm.checkPermission(android.Manifest.permission.RECORD_AUDIO, |
Paul McLean | 3a30e55 | 2019-12-07 14:47:29 -0700 | [diff] [blame] | 849 | activityInfo.packageName) |
Paul McLean | c613c77 | 2019-12-13 11:36:16 -0700 | [diff] [blame] | 850 | == android.content.pm.PackageManager.PERMISSION_GRANTED; |
Paul McLean | 3a30e55 | 2019-12-07 14:47:29 -0700 | [diff] [blame] | 851 | |
| 852 | if (!hasRecordPermission) { |
| 853 | // OK, we know the record permission, is this a capture device |
| 854 | boolean hasAudioCapture = |
| 855 | getIntent().getBooleanExtra( |
| 856 | ResolverActivity.EXTRA_IS_AUDIO_CAPTURE_DEVICE, false); |
| 857 | enabled = !hasAudioCapture; |
| 858 | } |
Nicolas Prevot | 5044988 | 2014-06-23 12:42:37 +0100 | [diff] [blame] | 859 | mAlwaysButton.setEnabled(enabled); |
| 860 | } |
| 861 | |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 862 | public void onButtonClick(View v) { |
| 863 | final int id = v.getId(); |
arangelov | cf26864 | 2020-01-15 15:09:51 +0000 | [diff] [blame] | 864 | ListView listView = (ListView) mMultiProfilePagerAdapter.getActiveAdapterView(); |
arangelov | a3912cf | 2019-12-13 14:34:45 +0000 | [diff] [blame] | 865 | ResolverListAdapter currentListAdapter = mMultiProfilePagerAdapter.getActiveListAdapter(); |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 866 | int which = currentListAdapter.hasFilteredItem() |
| 867 | ? currentListAdapter.getFilteredPosition() |
| 868 | : listView.getCheckedItemPosition(); |
| 869 | boolean hasIndexBeenFiltered = !currentListAdapter.hasFilteredItem(); |
| 870 | ResolveInfo ri = currentListAdapter.resolveInfoForPosition(which, hasIndexBeenFiltered); |
Matt Pietal | a310c1f | 2019-07-03 09:12:56 -0400 | [diff] [blame] | 871 | if (mUseLayoutForBrowsables |
| 872 | && !ri.handleAllWebDataURI && id == R.id.button_always) { |
Matt Pietal | 0d6834a | 2019-06-27 13:27:52 -0400 | [diff] [blame] | 873 | showSettingsForSelected(ri); |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 874 | } else { |
| 875 | startSelected(which, id == R.id.button_always, hasIndexBeenFiltered); |
| 876 | } |
| 877 | } |
| 878 | |
Matt Pietal | 0d6834a | 2019-06-27 13:27:52 -0400 | [diff] [blame] | 879 | private void showSettingsForSelected(ResolveInfo ri) { |
shafik | 34064c3 | 2019-03-06 15:42:52 +0000 | [diff] [blame] | 880 | Intent intent = new Intent(); |
Matt Pietal | 0d6834a | 2019-06-27 13:27:52 -0400 | [diff] [blame] | 881 | |
| 882 | final String packageName = ri.activityInfo.packageName; |
| 883 | Bundle showFragmentArgs = new Bundle(); |
| 884 | showFragmentArgs.putString(EXTRA_FRAGMENT_ARG_KEY, OPEN_LINKS_COMPONENT_KEY); |
| 885 | showFragmentArgs.putString("package", packageName); |
| 886 | |
shafik | 34064c3 | 2019-03-06 15:42:52 +0000 | [diff] [blame] | 887 | // For regular apps, we open the Open by Default page |
Matt Pietal | 0d6834a | 2019-06-27 13:27:52 -0400 | [diff] [blame] | 888 | intent.setAction(Settings.ACTION_APP_OPEN_BY_DEFAULT_SETTINGS) |
| 889 | .setData(Uri.fromParts("package", packageName, null)) |
| 890 | .addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT) |
| 891 | .putExtra(EXTRA_FRAGMENT_ARG_KEY, OPEN_LINKS_COMPONENT_KEY) |
| 892 | .putExtra(EXTRA_SHOW_FRAGMENT_ARGS, showFragmentArgs); |
| 893 | |
shafik | 34064c3 | 2019-03-06 15:42:52 +0000 | [diff] [blame] | 894 | startActivity(intent); |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 895 | } |
| 896 | |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 897 | public void startSelected(int which, boolean always, boolean hasIndexBeenFiltered) { |
Amith Yamasani | 07cd351 | 2013-09-18 13:16:00 -0700 | [diff] [blame] | 898 | if (isFinishing()) { |
| 899 | return; |
| 900 | } |
arangelov | a3912cf | 2019-12-13 14:34:45 +0000 | [diff] [blame] | 901 | ResolveInfo ri = mMultiProfilePagerAdapter.getActiveListAdapter() |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 902 | .resolveInfoForPosition(which, hasIndexBeenFiltered); |
Sander Alewijnse | 86d35ba | 2015-02-04 15:14:53 +0000 | [diff] [blame] | 903 | if (mResolvingHome && hasManagedProfile() && !supportsManagedProfiles(ri)) { |
| 904 | Toast.makeText(this, String.format(getResources().getString( |
| 905 | com.android.internal.R.string.activity_resolver_work_profiles_support), |
| 906 | ri.activityInfo.loadLabel(getPackageManager()).toString()), |
| 907 | Toast.LENGTH_LONG).show(); |
| 908 | return; |
| 909 | } |
| 910 | |
arangelov | a3912cf | 2019-12-13 14:34:45 +0000 | [diff] [blame] | 911 | TargetInfo target = mMultiProfilePagerAdapter.getActiveListAdapter() |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 912 | .targetInfoForPosition(which, hasIndexBeenFiltered); |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 913 | if (target == null) { |
| 914 | return; |
| 915 | } |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 916 | if (onTargetSelected(target, always)) { |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 917 | if (always && mSupportsAlwaysUseOption) { |
Clara Bayarri | fa902aa | 2016-04-13 14:45:08 +0100 | [diff] [blame] | 918 | MetricsLogger.action( |
| 919 | this, MetricsProto.MetricsEvent.ACTION_APP_DISAMBIG_ALWAYS); |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 920 | } else if (mSupportsAlwaysUseOption) { |
Clara Bayarri | fa902aa | 2016-04-13 14:45:08 +0100 | [diff] [blame] | 921 | MetricsLogger.action( |
| 922 | this, MetricsProto.MetricsEvent.ACTION_APP_DISAMBIG_JUST_ONCE); |
| 923 | } else { |
| 924 | MetricsLogger.action( |
| 925 | this, MetricsProto.MetricsEvent.ACTION_APP_DISAMBIG_TAP); |
| 926 | } |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 927 | MetricsLogger.action(this, |
arangelov | a3912cf | 2019-12-13 14:34:45 +0000 | [diff] [blame] | 928 | mMultiProfilePagerAdapter.getActiveListAdapter().hasFilteredItem() |
Clara Bayarri | fa902aa | 2016-04-13 14:45:08 +0100 | [diff] [blame] | 929 | ? MetricsProto.MetricsEvent.ACTION_HIDE_APP_DISAMBIG_APP_FEATURED |
| 930 | : MetricsProto.MetricsEvent.ACTION_HIDE_APP_DISAMBIG_NONE_FEATURED); |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 931 | finish(); |
| 932 | } |
Mike Lockwood | 02eb874 | 2011-02-27 09:10:37 -0800 | [diff] [blame] | 933 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 934 | |
Adam Powell | e49d939 | 2014-07-17 18:45:19 -0700 | [diff] [blame] | 935 | /** |
| 936 | * Replace me in subclasses! |
| 937 | */ |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 938 | @Override // ResolverListCommunicator |
Nicolas Prevot | 0e2b73f | 2014-10-27 10:06:11 +0000 | [diff] [blame] | 939 | public Intent getReplacementIntent(ActivityInfo aInfo, Intent defIntent) { |
Adam Powell | e49d939 | 2014-07-17 18:45:19 -0700 | [diff] [blame] | 940 | return defIntent; |
| 941 | } |
| 942 | |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 943 | @Override // ResolverListCommunicator |
arangelov | 7981b12 | 2020-01-16 10:58:27 +0000 | [diff] [blame] | 944 | public void onPostListReady(ResolverListAdapter listAdapter, boolean doPostProcessing) { |
| 945 | if (isAutolaunching() || maybeAutolaunchActivity()) { |
| 946 | return; |
arangelov | cf26864 | 2020-01-15 15:09:51 +0000 | [diff] [blame] | 947 | } |
arangelov | 7981b12 | 2020-01-16 10:58:27 +0000 | [diff] [blame] | 948 | if (doPostProcessing) { |
| 949 | if (mMultiProfilePagerAdapter.getCurrentUserHandle().getIdentifier() |
| 950 | == UserHandle.myUserId()) { |
| 951 | setHeader(); |
| 952 | } |
| 953 | resetButtonBar(); |
| 954 | onListRebuilt(listAdapter); |
| 955 | } |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 956 | } |
| 957 | |
arangelov | a3912cf | 2019-12-13 14:34:45 +0000 | [diff] [blame] | 958 | protected void onListRebuilt(ResolverListAdapter listAdapter) { |
arangelov | cf26864 | 2020-01-15 15:09:51 +0000 | [diff] [blame] | 959 | final ItemClickListener listener = new ItemClickListener(); |
| 960 | setupAdapterListView((ListView) mMultiProfilePagerAdapter.getActiveAdapterView(), listener); |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 961 | } |
| 962 | |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 963 | protected boolean onTargetSelected(TargetInfo target, boolean alwaysCheck) { |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 964 | final ResolveInfo ri = target.getResolveInfo(); |
| 965 | final Intent intent = target != null ? target.getResolvedIntent() : null; |
| 966 | |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 967 | if (intent != null && (mSupportsAlwaysUseOption |
arangelov | a3912cf | 2019-12-13 14:34:45 +0000 | [diff] [blame] | 968 | || mMultiProfilePagerAdapter.getActiveListAdapter().hasFilteredItem()) |
| 969 | && mMultiProfilePagerAdapter.getActiveListAdapter().getUnfilteredResolveList() != null) { |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 970 | // Build a reasonable intent filter, based on what matched. |
| 971 | IntentFilter filter = new IntentFilter(); |
Henrik Engström | 3277cf1 | 2014-07-17 12:18:29 +0200 | [diff] [blame] | 972 | Intent filterIntent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 973 | |
Henrik Engström | 3277cf1 | 2014-07-17 12:18:29 +0200 | [diff] [blame] | 974 | if (intent.getSelector() != null) { |
| 975 | filterIntent = intent.getSelector(); |
| 976 | } else { |
| 977 | filterIntent = intent; |
| 978 | } |
| 979 | |
| 980 | String action = filterIntent.getAction(); |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 981 | if (action != null) { |
| 982 | filter.addAction(action); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 983 | } |
Henrik Engström | 3277cf1 | 2014-07-17 12:18:29 +0200 | [diff] [blame] | 984 | Set<String> categories = filterIntent.getCategories(); |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 985 | if (categories != null) { |
| 986 | for (String cat : categories) { |
| 987 | filter.addCategory(cat); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 988 | } |
| 989 | } |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 990 | filter.addCategory(Intent.CATEGORY_DEFAULT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 991 | |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 992 | int cat = ri.match & IntentFilter.MATCH_CATEGORY_MASK; |
Henrik Engström | 3277cf1 | 2014-07-17 12:18:29 +0200 | [diff] [blame] | 993 | Uri data = filterIntent.getData(); |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 994 | if (cat == IntentFilter.MATCH_CATEGORY_TYPE) { |
Henrik Engström | 3277cf1 | 2014-07-17 12:18:29 +0200 | [diff] [blame] | 995 | String mimeType = filterIntent.resolveType(this); |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 996 | if (mimeType != null) { |
| 997 | try { |
| 998 | filter.addDataType(mimeType); |
| 999 | } catch (IntentFilter.MalformedMimeTypeException e) { |
| 1000 | Log.w("ResolverActivity", e); |
| 1001 | filter = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1002 | } |
| 1003 | } |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 1004 | } |
| 1005 | if (data != null && data.getScheme() != null) { |
| 1006 | // We need the data specification if there was no type, |
| 1007 | // OR if the scheme is not one of our magical "file:" |
| 1008 | // or "content:" schemes (see IntentFilter for the reason). |
| 1009 | if (cat != IntentFilter.MATCH_CATEGORY_TYPE |
| 1010 | || (!"file".equals(data.getScheme()) |
| 1011 | && !"content".equals(data.getScheme()))) { |
| 1012 | filter.addDataScheme(data.getScheme()); |
| 1013 | |
| 1014 | // Look through the resolved filter to determine which part |
| 1015 | // of it matched the original Intent. |
| 1016 | Iterator<PatternMatcher> pIt = ri.filter.schemeSpecificPartsIterator(); |
| 1017 | if (pIt != null) { |
| 1018 | String ssp = data.getSchemeSpecificPart(); |
| 1019 | while (ssp != null && pIt.hasNext()) { |
| 1020 | PatternMatcher p = pIt.next(); |
| 1021 | if (p.match(ssp)) { |
| 1022 | filter.addDataSchemeSpecificPart(p.getPath(), p.getType()); |
| 1023 | break; |
| 1024 | } |
Dianne Hackborn | df1c0bf | 2013-06-12 16:21:38 -0700 | [diff] [blame] | 1025 | } |
| 1026 | } |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 1027 | Iterator<IntentFilter.AuthorityEntry> aIt = ri.filter.authoritiesIterator(); |
| 1028 | if (aIt != null) { |
| 1029 | while (aIt.hasNext()) { |
| 1030 | IntentFilter.AuthorityEntry a = aIt.next(); |
| 1031 | if (a.match(data) >= 0) { |
| 1032 | int port = a.getPort(); |
| 1033 | filter.addDataAuthority(a.getHost(), |
| 1034 | port >= 0 ? Integer.toString(port) : null); |
| 1035 | break; |
| 1036 | } |
| 1037 | } |
| 1038 | } |
| 1039 | pIt = ri.filter.pathsIterator(); |
| 1040 | if (pIt != null) { |
| 1041 | String path = data.getPath(); |
| 1042 | while (path != null && pIt.hasNext()) { |
| 1043 | PatternMatcher p = pIt.next(); |
| 1044 | if (p.match(path)) { |
| 1045 | filter.addDataPath(p.getPath(), p.getType()); |
| 1046 | break; |
| 1047 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1048 | } |
| 1049 | } |
| 1050 | } |
| 1051 | } |
| 1052 | |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 1053 | if (filter != null) { |
arangelov | a3912cf | 2019-12-13 14:34:45 +0000 | [diff] [blame] | 1054 | final int N = mMultiProfilePagerAdapter.getActiveListAdapter() |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1055 | .getUnfilteredResolveList().size(); |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 1056 | ComponentName[] set; |
| 1057 | // If we don't add back in the component for forwarding the intent to a managed |
| 1058 | // profile, the preferred activity may not be updated correctly (as the set of |
| 1059 | // components we tell it we knew about will have changed). |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 1060 | final boolean needToAddBackProfileForwardingComponent = |
arangelov | a3912cf | 2019-12-13 14:34:45 +0000 | [diff] [blame] | 1061 | mMultiProfilePagerAdapter.getActiveListAdapter().getOtherProfile() != null; |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 1062 | if (!needToAddBackProfileForwardingComponent) { |
| 1063 | set = new ComponentName[N]; |
| 1064 | } else { |
| 1065 | set = new ComponentName[N + 1]; |
| 1066 | } |
| 1067 | |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 1068 | int bestMatch = 0; |
| 1069 | for (int i=0; i<N; i++) { |
arangelov | a3912cf | 2019-12-13 14:34:45 +0000 | [diff] [blame] | 1070 | ResolveInfo r = mMultiProfilePagerAdapter.getActiveListAdapter() |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1071 | .getUnfilteredResolveList().get(i).getResolveInfoAt(0); |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 1072 | set[i] = new ComponentName(r.activityInfo.packageName, |
| 1073 | r.activityInfo.name); |
| 1074 | if (r.match > bestMatch) bestMatch = r.match; |
| 1075 | } |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 1076 | |
| 1077 | if (needToAddBackProfileForwardingComponent) { |
arangelov | a3912cf | 2019-12-13 14:34:45 +0000 | [diff] [blame] | 1078 | set[N] = mMultiProfilePagerAdapter.getActiveListAdapter() |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1079 | .getOtherProfile().getResolvedComponentName(); |
arangelov | a3912cf | 2019-12-13 14:34:45 +0000 | [diff] [blame] | 1080 | final int otherProfileMatch = mMultiProfilePagerAdapter.getActiveListAdapter() |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1081 | .getOtherProfile().getResolveInfo().match; |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 1082 | if (otherProfileMatch > bestMatch) bestMatch = otherProfileMatch; |
| 1083 | } |
| 1084 | |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 1085 | if (alwaysCheck) { |
Fabrice Di Meglio | 3453e08 | 2015-05-11 17:46:23 -0700 | [diff] [blame] | 1086 | final int userId = getUserId(); |
| 1087 | final PackageManager pm = getPackageManager(); |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1088 | |
| 1089 | // Set the preferred Activity |
| 1090 | pm.addPreferredActivity(filter, bestMatch, set, intent.getComponent()); |
| 1091 | |
Fabrice Di Meglio | 3453e08 | 2015-05-11 17:46:23 -0700 | [diff] [blame] | 1092 | if (ri.handleAllWebDataURI) { |
| 1093 | // Set default Browser if needed |
Jeff Sharkey | e06b4d1 | 2016-01-06 14:51:50 -0700 | [diff] [blame] | 1094 | final String packageName = pm.getDefaultBrowserPackageNameAsUser(userId); |
Fabrice Di Meglio | 3453e08 | 2015-05-11 17:46:23 -0700 | [diff] [blame] | 1095 | if (TextUtils.isEmpty(packageName)) { |
Jeff Sharkey | e06b4d1 | 2016-01-06 14:51:50 -0700 | [diff] [blame] | 1096 | pm.setDefaultBrowserPackageNameAsUser(ri.activityInfo.packageName, userId); |
Fabrice Di Meglio | 3453e08 | 2015-05-11 17:46:23 -0700 | [diff] [blame] | 1097 | } |
| 1098 | } else { |
| 1099 | // Update Domain Verification status |
| 1100 | ComponentName cn = intent.getComponent(); |
| 1101 | String packageName = cn.getPackageName(); |
| 1102 | String dataScheme = (data != null) ? data.getScheme() : null; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1103 | |
Fabrice Di Meglio | 3453e08 | 2015-05-11 17:46:23 -0700 | [diff] [blame] | 1104 | boolean isHttpOrHttps = (dataScheme != null) && |
| 1105 | (dataScheme.equals(IntentFilter.SCHEME_HTTP) || |
| 1106 | dataScheme.equals(IntentFilter.SCHEME_HTTPS)); |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1107 | |
Fabrice Di Meglio | 3453e08 | 2015-05-11 17:46:23 -0700 | [diff] [blame] | 1108 | boolean isViewAction = (action != null) && action.equals(Intent.ACTION_VIEW); |
| 1109 | boolean hasCategoryBrowsable = (categories != null) && |
| 1110 | categories.contains(Intent.CATEGORY_BROWSABLE); |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1111 | |
Fabrice Di Meglio | 3453e08 | 2015-05-11 17:46:23 -0700 | [diff] [blame] | 1112 | if (isHttpOrHttps && isViewAction && hasCategoryBrowsable) { |
Jeff Sharkey | e06b4d1 | 2016-01-06 14:51:50 -0700 | [diff] [blame] | 1113 | pm.updateIntentVerificationStatusAsUser(packageName, |
Fabrice Di Meglio | 3453e08 | 2015-05-11 17:46:23 -0700 | [diff] [blame] | 1114 | PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS, |
| 1115 | userId); |
| 1116 | } |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1117 | } |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 1118 | } else { |
| 1119 | try { |
arangelov | a3912cf | 2019-12-13 14:34:45 +0000 | [diff] [blame] | 1120 | mMultiProfilePagerAdapter.getActiveListAdapter() |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1121 | .mResolverListController.setLastChosen(intent, filter, bestMatch); |
Amith Yamasani | 588dd2a | 2013-09-03 12:30:44 -0700 | [diff] [blame] | 1122 | } catch (RemoteException re) { |
| 1123 | Log.d(TAG, "Error calling setLastChosenActivity\n" + re); |
| 1124 | } |
Amith Yamasani | e9ecc8b | 2013-08-22 11:16:27 -0700 | [diff] [blame] | 1125 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1126 | } |
| 1127 | } |
| 1128 | |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1129 | if (target != null) { |
arangelov | 9e14852 | 2020-01-15 21:11:51 +0000 | [diff] [blame] | 1130 | if (intent != null) { |
| 1131 | intent.fixUris(UserHandle.myUserId()); |
| 1132 | } |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1133 | safelyStartActivity(target); |
Matt Pietal | a4b3007 | 2019-04-04 13:44:36 -0400 | [diff] [blame] | 1134 | |
| 1135 | // Rely on the ActivityManager to pop up a dialog regarding app suspension |
| 1136 | // and return false |
| 1137 | if (target.isSuspended()) { |
| 1138 | return false; |
| 1139 | } |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 1140 | } |
Matt Pietal | a4b3007 | 2019-04-04 13:44:36 -0400 | [diff] [blame] | 1141 | |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1142 | return true; |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 1143 | } |
| 1144 | |
arangelov | cf26864 | 2020-01-15 15:09:51 +0000 | [diff] [blame] | 1145 | @VisibleForTesting |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 1146 | public void safelyStartActivity(TargetInfo cti) { |
Jeff Sharkey | 2b9eb89 | 2016-02-16 09:21:51 -0700 | [diff] [blame] | 1147 | // We're dispatching intents that might be coming from legacy apps, so |
| 1148 | // don't kill ourselves. |
| 1149 | StrictMode.disableDeathOnFileUriExposure(); |
| 1150 | try { |
| 1151 | safelyStartActivityInternal(cti); |
| 1152 | } finally { |
| 1153 | StrictMode.enableDeathOnFileUriExposure(); |
| 1154 | } |
| 1155 | } |
| 1156 | |
| 1157 | private void safelyStartActivityInternal(TargetInfo cti) { |
arangelov | 7981b12 | 2020-01-16 10:58:27 +0000 | [diff] [blame] | 1158 | mPersonalPackageMonitor.unregister(); |
| 1159 | if (mWorkPackageMonitor != null) { |
| 1160 | mWorkPackageMonitor.unregister(); |
| 1161 | } |
| 1162 | mRegistered = false; |
Sander Alewijnse | f654533 | 2014-10-31 12:39:02 +0000 | [diff] [blame] | 1163 | // If needed, show that intent is forwarded |
| 1164 | // from managed profile to owner or other way around. |
| 1165 | if (mProfileSwitchMessageId != -1) { |
| 1166 | Toast.makeText(this, getString(mProfileSwitchMessageId), Toast.LENGTH_LONG).show(); |
| 1167 | } |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1168 | UserHandle currentUserHandle = mMultiProfilePagerAdapter.getCurrentUserHandle(); |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 1169 | if (!mSafeForwardingMode) { |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1170 | if (cti.startAsUser(this, null, currentUserHandle)) { |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1171 | onActivityStarted(cti); |
| 1172 | } |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 1173 | return; |
| 1174 | } |
| 1175 | try { |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1176 | if (cti.startAsCaller(this, null, currentUserHandle.getIdentifier())) { |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1177 | onActivityStarted(cti); |
| 1178 | } |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 1179 | } catch (RuntimeException e) { |
| 1180 | String launchedFromPackage; |
| 1181 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1182 | launchedFromPackage = ActivityTaskManager.getService().getLaunchedFromPackage( |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 1183 | getActivityToken()); |
| 1184 | } catch (RemoteException e2) { |
| 1185 | launchedFromPackage = "??"; |
| 1186 | } |
| 1187 | Slog.wtf(TAG, "Unable to launch as uid " + mLaunchedFromUid |
| 1188 | + " package " + launchedFromPackage + ", while running in " |
| 1189 | + ActivityThread.currentProcessName(), e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1190 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1191 | } |
| 1192 | |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1193 | |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 1194 | public boolean startAsCallerImpl(Intent intent, Bundle options, boolean ignoreTargetSecurity, |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1195 | int userId) { |
| 1196 | // Pass intent to delegate chooser activity with permission token. |
| 1197 | // TODO: This should move to a trampoline Activity in the system when the ChooserActivity |
| 1198 | // moves into systemui |
| 1199 | try { |
| 1200 | // TODO: Once this is a small springboard activity, it can move off the UI process |
| 1201 | // and we can move the request method to ActivityManagerInternal. |
| 1202 | IBinder permissionToken = ActivityTaskManager.getService() |
| 1203 | .requestStartActivityPermissionToken(getActivityToken()); |
| 1204 | final Intent chooserIntent = new Intent(); |
| 1205 | final ComponentName delegateActivity = ComponentName.unflattenFromString( |
| 1206 | Resources.getSystem().getString(R.string.config_chooserActivity)); |
| 1207 | chooserIntent.setClassName(delegateActivity.getPackageName(), |
| 1208 | delegateActivity.getClassName()); |
| 1209 | chooserIntent.putExtra(ActivityTaskManager.EXTRA_PERMISSION_TOKEN, permissionToken); |
| 1210 | |
| 1211 | // TODO: These extras will change as chooser activity moves into systemui |
| 1212 | chooserIntent.putExtra(Intent.EXTRA_INTENT, intent); |
| 1213 | chooserIntent.putExtra(ActivityTaskManager.EXTRA_OPTIONS, options); |
| 1214 | chooserIntent.putExtra(ActivityTaskManager.EXTRA_IGNORE_TARGET_SECURITY, |
| 1215 | ignoreTargetSecurity); |
| 1216 | chooserIntent.putExtra(Intent.EXTRA_USER_ID, userId); |
Alison Cichowlas | 7b6f3b6 | 2018-12-07 09:06:57 -0500 | [diff] [blame] | 1217 | chooserIntent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT |
| 1218 | | Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP); |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1219 | startActivity(chooserIntent); |
| 1220 | } catch (RemoteException e) { |
| 1221 | Log.e(TAG, e.toString()); |
| 1222 | } |
| 1223 | return true; |
| 1224 | } |
| 1225 | |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 1226 | public void onActivityStarted(TargetInfo cti) { |
Adam Powell | 0b3c112 | 2014-10-09 12:50:14 -0700 | [diff] [blame] | 1227 | // Do nothing |
| 1228 | } |
| 1229 | |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 1230 | @Override // ResolverListCommunicator |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 1231 | public boolean shouldGetActivityMetadata() { |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1232 | return false; |
| 1233 | } |
| 1234 | |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 1235 | public boolean shouldAutoLaunchSingleChoice(TargetInfo target) { |
Matt Pietal | a4b3007 | 2019-04-04 13:44:36 -0400 | [diff] [blame] | 1236 | return !target.isSuspended(); |
Adam Powell | 39e94eb | 2015-09-08 17:01:49 -0700 | [diff] [blame] | 1237 | } |
| 1238 | |
Alison Cichowlas | 19ee292 | 2019-12-16 19:43:12 -0500 | [diff] [blame] | 1239 | void showTargetDetails(ResolveInfo ri) { |
Dianne Hackborn | 028ceeb | 2014-08-17 17:45:48 -0700 | [diff] [blame] | 1240 | Intent in = new Intent().setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS) |
Adam Powell | 0fc5b2b | 2012-07-18 18:20:29 -0700 | [diff] [blame] | 1241 | .setData(Uri.fromParts("package", ri.activityInfo.packageName, null)) |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1242 | .addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT); |
Amith Yamasani | 203a2f4 | 2012-10-03 20:16:40 -0700 | [diff] [blame] | 1243 | startActivity(in); |
Adam Powell | c587861 | 2012-05-04 18:42:38 -0700 | [diff] [blame] | 1244 | } |
| 1245 | |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1246 | @VisibleForTesting |
| 1247 | protected ResolverListAdapter createResolverListAdapter(Context context, |
| 1248 | List<Intent> payloadIntents, Intent[] initialIntents, List<ResolveInfo> rList, |
| 1249 | boolean filterLastUsed, boolean useLayoutForBrowsables, UserHandle userHandle) { |
Paul McLean | 07425c8 | 2019-10-18 12:00:11 -0600 | [diff] [blame] | 1250 | Intent startIntent = getIntent(); |
| 1251 | boolean isAudioCaptureDevice = |
| 1252 | startIntent.getBooleanExtra(EXTRA_IS_AUDIO_CAPTURE_DEVICE, false); |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 1253 | return new ResolverListAdapter(context, payloadIntents, initialIntents, rList, |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1254 | filterLastUsed, createListController(userHandle), useLayoutForBrowsables, this, |
Paul McLean | 07425c8 | 2019-10-18 12:00:11 -0600 | [diff] [blame] | 1255 | isAudioCaptureDevice); |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1256 | } |
| 1257 | |
| 1258 | @VisibleForTesting |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1259 | protected ResolverListController createListController(UserHandle userHandle) { |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1260 | return new ResolverListController( |
| 1261 | this, |
| 1262 | mPm, |
| 1263 | getTargetIntent(), |
| 1264 | getReferrerPackageName(), |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1265 | mLaunchedFromUid, |
| 1266 | userHandle); |
Adam Powell | 88831a2 | 2014-11-20 18:17:00 -0800 | [diff] [blame] | 1267 | } |
| 1268 | |
Adam Powell | 39e94eb | 2015-09-08 17:01:49 -0700 | [diff] [blame] | 1269 | /** |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 1270 | * Sets up the content view. |
arangelov | bb57233 | 2019-11-13 12:50:08 +0000 | [diff] [blame] | 1271 | * @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] | 1272 | */ |
arangelov | bb57233 | 2019-11-13 12:50:08 +0000 | [diff] [blame] | 1273 | private boolean configureContentView() { |
arangelov | a3912cf | 2019-12-13 14:34:45 +0000 | [diff] [blame] | 1274 | if (mMultiProfilePagerAdapter.getActiveListAdapter() == null) { |
| 1275 | throw new IllegalStateException("mMultiProfilePagerAdapter.getCurrentListAdapter() " |
| 1276 | + "cannot be null."); |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 1277 | } |
arangelov | 7981b12 | 2020-01-16 10:58:27 +0000 | [diff] [blame] | 1278 | boolean rebuildCompleted = mMultiProfilePagerAdapter.rebuildActiveTab(true); |
| 1279 | |
| 1280 | // We partially rebuild the inactive adapter to determine if we should auto launch |
| 1281 | mMultiProfilePagerAdapter.rebuildInactiveTab(false); |
| 1282 | |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 1283 | if (useLayoutWithDefault()) { |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1284 | mLayoutId = R.layout.resolver_list_with_default; |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1285 | } else { |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1286 | mLayoutId = getLayoutResource(); |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1287 | } |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 1288 | setContentView(mLayoutId); |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1289 | mMultiProfilePagerAdapter.setupViewPager(findViewById(R.id.profile_pager)); |
arangelov | bb57233 | 2019-11-13 12:50:08 +0000 | [diff] [blame] | 1290 | return postRebuildList(rebuildCompleted); |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 1291 | } |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1292 | |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 1293 | /** |
arangelov | bb57233 | 2019-11-13 12:50:08 +0000 | [diff] [blame] | 1294 | * Finishing procedures to be performed after the list has been rebuilt. |
| 1295 | * </p>Subclasses must call postRebuildListInternal at the end of postRebuildList. |
| 1296 | * @param rebuildCompleted |
| 1297 | * @return <code>true</code> if the activity is finishing and creation should halt. |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 1298 | */ |
arangelov | bb57233 | 2019-11-13 12:50:08 +0000 | [diff] [blame] | 1299 | protected boolean postRebuildList(boolean rebuildCompleted) { |
| 1300 | return postRebuildListInternal(rebuildCompleted); |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 1301 | } |
| 1302 | |
| 1303 | /** |
arangelov | bb57233 | 2019-11-13 12:50:08 +0000 | [diff] [blame] | 1304 | * Finishing procedures to be performed after the list has been rebuilt. |
| 1305 | * @param rebuildCompleted |
| 1306 | * @return <code>true</code> if the activity is finishing and creation should halt. |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 1307 | */ |
arangelov | bb57233 | 2019-11-13 12:50:08 +0000 | [diff] [blame] | 1308 | final boolean postRebuildListInternal(boolean rebuildCompleted) { |
arangelov | a3912cf | 2019-12-13 14:34:45 +0000 | [diff] [blame] | 1309 | int count = mMultiProfilePagerAdapter.getActiveListAdapter().getUnfilteredCount(); |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1310 | |
| 1311 | // We only rebuild asynchronously when we have multiple elements to sort. In the case where |
| 1312 | // we're already done, we can check if we should auto-launch immediately. |
arangelov | 7981b12 | 2020-01-16 10:58:27 +0000 | [diff] [blame] | 1313 | if (rebuildCompleted && maybeAutolaunchActivity()) { |
| 1314 | return true; |
Jeff Sharkey | cc2ae6b4 | 2015-09-29 13:04:46 -0700 | [diff] [blame] | 1315 | } |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1316 | |
arangelov | cf26864 | 2020-01-15 15:09:51 +0000 | [diff] [blame] | 1317 | setupViewVisibilities(); |
| 1318 | |
| 1319 | if (hasWorkProfile() && ENABLE_TABBED_VIEW) { |
| 1320 | setupProfileTabs(); |
| 1321 | } |
| 1322 | |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1323 | return false; |
| 1324 | } |
| 1325 | |
arangelov | 7981b12 | 2020-01-16 10:58:27 +0000 | [diff] [blame] | 1326 | private int isPermissionGranted(String permission, int uid) { |
| 1327 | return ActivityManager.checkComponentPermission(permission, uid, |
| 1328 | /* owningUid= */-1, /* exported= */ true); |
| 1329 | } |
| 1330 | |
| 1331 | /** |
| 1332 | * @return {@code true} if a resolved target is autolaunched, otherwise {@code false} |
| 1333 | */ |
| 1334 | private boolean maybeAutolaunchActivity() { |
| 1335 | int numberOfProfiles = mMultiProfilePagerAdapter.getItemCount(); |
| 1336 | if (numberOfProfiles == 1 && maybeAutolaunchIfSingleTarget()) { |
| 1337 | return true; |
| 1338 | } else if (numberOfProfiles == 2 && maybeAutolaunchIfCrossProfileSupported()) { |
| 1339 | // note that autolaunching when we have 2 profiles, 1 resolved target on the active |
| 1340 | // tab and 0 resolved targets on the inactive tab, is already handled before launching |
| 1341 | // ResolverActivity |
| 1342 | return true; |
| 1343 | } |
| 1344 | return false; |
| 1345 | } |
| 1346 | |
| 1347 | private boolean maybeAutolaunchIfSingleTarget() { |
| 1348 | int count = mMultiProfilePagerAdapter.getActiveListAdapter().getUnfilteredCount(); |
| 1349 | if (count != 1) { |
| 1350 | return false; |
| 1351 | } |
| 1352 | |
| 1353 | // Only one target, so we're a candidate to auto-launch! |
| 1354 | final TargetInfo target = mMultiProfilePagerAdapter.getActiveListAdapter() |
| 1355 | .targetInfoForPosition(0, false); |
| 1356 | if (shouldAutoLaunchSingleChoice(target)) { |
| 1357 | safelyStartActivity(target); |
| 1358 | finish(); |
| 1359 | return true; |
| 1360 | } |
| 1361 | return false; |
| 1362 | } |
| 1363 | |
| 1364 | /** |
| 1365 | * When we have a personal and a work profile, we auto launch in the following scenario: |
| 1366 | * - There is 1 resolved target on each profile |
| 1367 | * - That target is the same app on both profiles |
| 1368 | * - The target app has permission to communicate cross profiles |
| 1369 | * - The target app has declared it supports cross-profile communication via manifest metadata |
| 1370 | */ |
| 1371 | private boolean maybeAutolaunchIfCrossProfileSupported() { |
| 1372 | int count = mMultiProfilePagerAdapter.getActiveListAdapter().getUnfilteredCount(); |
| 1373 | if (count != 1) { |
| 1374 | return false; |
| 1375 | } |
| 1376 | ResolverListAdapter inactiveListAdapter = |
| 1377 | mMultiProfilePagerAdapter.getInactiveListAdapter(); |
| 1378 | if (inactiveListAdapter.getUnfilteredCount() != 1) { |
| 1379 | return false; |
| 1380 | } |
| 1381 | TargetInfo activeProfileTarget = mMultiProfilePagerAdapter.getActiveListAdapter() |
| 1382 | .targetInfoForPosition(0, false); |
| 1383 | TargetInfo inactiveProfileTarget = inactiveListAdapter.targetInfoForPosition(0, false); |
| 1384 | if (!Objects.equals(activeProfileTarget.getResolvedComponentName(), |
| 1385 | inactiveProfileTarget.getResolvedComponentName())) { |
| 1386 | return false; |
| 1387 | } |
| 1388 | if (!shouldAutoLaunchSingleChoice(activeProfileTarget)) { |
| 1389 | return false; |
| 1390 | } |
| 1391 | String packageName = activeProfileTarget.getResolvedComponentName().getPackageName(); |
| 1392 | if (!canAppInteractCrossProfiles(packageName)) { |
| 1393 | return false; |
| 1394 | } |
| 1395 | |
| 1396 | safelyStartActivity(activeProfileTarget); |
| 1397 | finish(); |
| 1398 | return true; |
| 1399 | } |
| 1400 | |
| 1401 | /** |
| 1402 | * Returns whether the package has the necessary permissions to interact across profiles on |
| 1403 | * behalf of a given user. |
| 1404 | * |
| 1405 | * <p>This means meeting the following condition: |
| 1406 | * <ul> |
| 1407 | * <li>The app's {@link ApplicationInfo#crossProfile} flag must be true, and at least |
| 1408 | * one of the following conditions must be fulfilled</li> |
| 1409 | * <li>{@code Manifest.permission.INTERACT_ACROSS_USERS_FULL} granted.</li> |
| 1410 | * <li>{@code Manifest.permission.INTERACT_ACROSS_USERS} granted.</li> |
| 1411 | * <li>{@code Manifest.permission.INTERACT_ACROSS_PROFILES} granted, or the corresponding |
| 1412 | * AppOps {@code android:interact_across_profiles} is set to "allow".</li> |
| 1413 | * </ul> |
| 1414 | * |
| 1415 | */ |
| 1416 | private boolean canAppInteractCrossProfiles(String packageName) { |
| 1417 | ApplicationInfo applicationInfo; |
| 1418 | try { |
| 1419 | applicationInfo = getPackageManager().getApplicationInfo(packageName, 0); |
| 1420 | } catch (NameNotFoundException e) { |
| 1421 | Log.e(TAG, "Package " + packageName + " does not exist on current user."); |
| 1422 | return false; |
| 1423 | } |
| 1424 | if (!applicationInfo.crossProfile) { |
| 1425 | return false; |
| 1426 | } |
| 1427 | |
| 1428 | int packageUid = applicationInfo.uid; |
| 1429 | |
| 1430 | if (isPermissionGranted(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, |
| 1431 | packageUid) == PackageManager.PERMISSION_GRANTED) { |
| 1432 | return true; |
| 1433 | } |
| 1434 | if (isPermissionGranted(android.Manifest.permission.INTERACT_ACROSS_USERS, packageUid) |
| 1435 | == PackageManager.PERMISSION_GRANTED) { |
| 1436 | return true; |
| 1437 | } |
| 1438 | if (PermissionChecker.checkPermissionForPreflight(this, INTERACT_ACROSS_PROFILES, |
| 1439 | PID_UNKNOWN, packageUid, packageName) == PackageManager.PERMISSION_GRANTED) { |
| 1440 | return true; |
| 1441 | } |
| 1442 | return false; |
| 1443 | } |
| 1444 | |
| 1445 | private boolean isAutolaunching() { |
| 1446 | return !mRegistered && isFinishing(); |
| 1447 | } |
| 1448 | |
arangelov | cf26864 | 2020-01-15 15:09:51 +0000 | [diff] [blame] | 1449 | private void setupProfileTabs() { |
| 1450 | TabHost tabHost = findViewById(R.id.profile_tabhost); |
| 1451 | tabHost.setup(); |
| 1452 | ViewPager viewPager = findViewById(R.id.profile_pager); |
| 1453 | TabHost.TabSpec tabSpec = tabHost.newTabSpec(TAB_TAG_PERSONAL) |
| 1454 | .setContent(R.id.profile_pager) |
| 1455 | .setIndicator(getString(R.string.resolver_personal_tab)); |
| 1456 | tabHost.addTab(tabSpec); |
| 1457 | |
| 1458 | tabSpec = tabHost.newTabSpec(TAB_TAG_WORK) |
| 1459 | .setContent(R.id.profile_pager) |
| 1460 | .setIndicator(getString(R.string.resolver_work_tab)); |
| 1461 | tabHost.addTab(tabSpec); |
| 1462 | |
| 1463 | TabWidget tabWidget = tabHost.getTabWidget(); |
| 1464 | tabWidget.setVisibility(View.VISIBLE); |
| 1465 | resetTabsHeaderStyle(tabWidget); |
| 1466 | updateActiveTabStyle(tabHost); |
| 1467 | |
| 1468 | tabHost.setOnTabChangedListener(tabId -> { |
| 1469 | resetTabsHeaderStyle(tabWidget); |
| 1470 | updateActiveTabStyle(tabHost); |
| 1471 | if (TAB_TAG_PERSONAL.equals(tabId)) { |
| 1472 | viewPager.setCurrentItem(0); |
| 1473 | } else { |
| 1474 | viewPager.setCurrentItem(1); |
| 1475 | } |
| 1476 | setupViewVisibilities(); |
| 1477 | }); |
| 1478 | |
| 1479 | viewPager.setVisibility(View.VISIBLE); |
| 1480 | tabHost.setCurrentTab(mMultiProfilePagerAdapter.getCurrentPage()); |
| 1481 | mMultiProfilePagerAdapter.setOnProfileSelectedListener(tabHost::setCurrentTab); |
| 1482 | } |
| 1483 | |
| 1484 | private void resetTabsHeaderStyle(TabWidget tabWidget) { |
| 1485 | for (int i = 0; i < tabWidget.getChildCount(); i++) { |
| 1486 | TextView title = tabWidget.getChildAt(i).findViewById(android.R.id.title); |
| 1487 | title.setTextColor(getColor(R.color.resolver_tabs_inactive_color)); |
| 1488 | title.setAllCaps(false); |
| 1489 | } |
| 1490 | } |
| 1491 | |
| 1492 | private void updateActiveTabStyle(TabHost tabHost) { |
| 1493 | TextView title = tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()) |
| 1494 | .findViewById(android.R.id.title); |
| 1495 | title.setTextColor(getColor(R.color.resolver_tabs_active_color)); |
| 1496 | } |
| 1497 | |
| 1498 | private void setupViewVisibilities() { |
| 1499 | int count = mMultiProfilePagerAdapter.getActiveListAdapter().getUnfilteredCount(); |
| 1500 | boolean shouldShowEmptyState = count == 0 |
| 1501 | && mMultiProfilePagerAdapter.getActiveListAdapter().getPlaceholderCount() == 0; |
| 1502 | //TODO(arangelov): Handle empty state |
| 1503 | if (!shouldShowEmptyState) { |
| 1504 | addUseDifferentAppLabelIfNecessary(mMultiProfilePagerAdapter.getActiveListAdapter()); |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1505 | } |
| 1506 | } |
| 1507 | |
Zhen Zhang | bde7b46 | 2019-11-11 11:49:33 -0800 | [diff] [blame] | 1508 | /** |
arangelov | cf26864 | 2020-01-15 15:09:51 +0000 | [diff] [blame] | 1509 | * Add a label to signify that the user can pick a different app. |
Zhen Zhang | bde7b46 | 2019-11-11 11:49:33 -0800 | [diff] [blame] | 1510 | * @param adapter The adapter used to provide data to item views. |
Zhen Zhang | bde7b46 | 2019-11-11 11:49:33 -0800 | [diff] [blame] | 1511 | */ |
arangelov | cf26864 | 2020-01-15 15:09:51 +0000 | [diff] [blame] | 1512 | public void addUseDifferentAppLabelIfNecessary(ResolverListAdapter adapter) { |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1513 | final boolean useHeader = adapter.hasFilteredItem(); |
arangelov | cf26864 | 2020-01-15 15:09:51 +0000 | [diff] [blame] | 1514 | if (useHeader) { |
| 1515 | FrameLayout stub = findViewById(R.id.stub); |
| 1516 | stub.setVisibility(View.VISIBLE); |
| 1517 | TextView textView = (TextView) LayoutInflater.from(this).inflate( |
| 1518 | R.layout.resolver_different_item_header, null, false); |
| 1519 | if (ENABLE_TABBED_VIEW) { |
| 1520 | textView.setGravity(Gravity.CENTER); |
| 1521 | } |
| 1522 | stub.addView(textView); |
| 1523 | } |
| 1524 | } |
| 1525 | |
| 1526 | private void setupAdapterListView(ListView listView, ItemClickListener listener) { |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1527 | listView.setOnItemClickListener(listener); |
| 1528 | listView.setOnItemLongClickListener(listener); |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1529 | |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 1530 | if (mSupportsAlwaysUseOption || mUseLayoutForBrowsables) { |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1531 | listView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE); |
| 1532 | } |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1533 | } |
| 1534 | |
Matt Pietal | 2603840 | 2019-01-08 07:29:34 -0500 | [diff] [blame] | 1535 | /** |
| 1536 | * Configure the area above the app selection list (title, content preview, etc). |
| 1537 | */ |
| 1538 | public void setHeader() { |
arangelov | a3912cf | 2019-12-13 14:34:45 +0000 | [diff] [blame] | 1539 | if (mMultiProfilePagerAdapter.getActiveListAdapter().getCount() == 0 |
| 1540 | && mMultiProfilePagerAdapter.getActiveListAdapter().getPlaceholderCount() == 0) { |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 1541 | final TextView titleView = findViewById(R.id.title); |
Hakan Seyalioglu | 3355012 | 2017-01-06 19:54:43 -0800 | [diff] [blame] | 1542 | if (titleView != null) { |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 1543 | titleView.setVisibility(View.GONE); |
Hakan Seyalioglu | 3355012 | 2017-01-06 19:54:43 -0800 | [diff] [blame] | 1544 | } |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 1545 | } |
| 1546 | |
| 1547 | CharSequence title = mTitle != null |
| 1548 | ? mTitle |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 1549 | : getTitleForAction(getTargetIntent(), mDefaultTitleResId); |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 1550 | |
| 1551 | if (!TextUtils.isEmpty(title)) { |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 1552 | final TextView titleView = findViewById(R.id.title); |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 1553 | if (titleView != null) { |
| 1554 | titleView.setText(title); |
| 1555 | } |
| 1556 | setTitle(title); |
Hakan Seyalioglu | 3355012 | 2017-01-06 19:54:43 -0800 | [diff] [blame] | 1557 | } |
| 1558 | |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 1559 | final ImageView iconView = findViewById(R.id.icon); |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 1560 | if (iconView != null) { |
arangelov | a3912cf | 2019-12-13 14:34:45 +0000 | [diff] [blame] | 1561 | mMultiProfilePagerAdapter.getActiveListAdapter().loadFilteredItemIconTaskAsync(iconView); |
Hakan Seyalioglu | 3355012 | 2017-01-06 19:54:43 -0800 | [diff] [blame] | 1562 | } |
| 1563 | } |
| 1564 | |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1565 | protected void resetButtonBar() { |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 1566 | if (!mSupportsAlwaysUseOption && !mUseLayoutForBrowsables) { |
| 1567 | return; |
| 1568 | } |
| 1569 | final ViewGroup buttonLayout = findViewById(R.id.button_bar); |
| 1570 | if (buttonLayout != null) { |
| 1571 | buttonLayout.setVisibility(View.VISIBLE); |
Matt Pietal | 800136a | 2019-05-08 07:46:39 -0400 | [diff] [blame] | 1572 | |
Matt Pietal | d507120 | 2019-10-10 11:21:28 -0400 | [diff] [blame] | 1573 | if (!useLayoutWithDefault()) { |
| 1574 | int inset = mSystemWindowInsets != null ? mSystemWindowInsets.bottom : 0; |
| 1575 | buttonLayout.setPadding(buttonLayout.getPaddingLeft(), buttonLayout.getPaddingTop(), |
| 1576 | buttonLayout.getPaddingRight(), getResources().getDimensionPixelSize( |
| 1577 | R.dimen.resolver_button_bar_spacing) + inset); |
| 1578 | } |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 1579 | mOnceButton = (Button) buttonLayout.findViewById(R.id.button_once); |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 1580 | mAlwaysButton = (Button) buttonLayout.findViewById(R.id.button_always); |
| 1581 | |
Matt Pietal | 0d6834a | 2019-06-27 13:27:52 -0400 | [diff] [blame] | 1582 | resetAlwaysOrOnceButtonBar(); |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 1583 | } else { |
| 1584 | Log.e(TAG, "Layout unexpectedly does not have a button bar"); |
| 1585 | } |
| 1586 | } |
| 1587 | |
shafik | 69df9632 | 2018-12-18 15:41:19 +0000 | [diff] [blame] | 1588 | private void resetAlwaysOrOnceButtonBar() { |
arangelov | a3912cf | 2019-12-13 14:34:45 +0000 | [diff] [blame] | 1589 | int filteredPosition = mMultiProfilePagerAdapter.getActiveListAdapter() |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1590 | .getFilteredPosition(); |
| 1591 | if (useLayoutWithDefault() && filteredPosition != ListView.INVALID_POSITION) { |
| 1592 | setAlwaysButtonEnabled(true, filteredPosition, false); |
Hakan Seyalioglu | 3355012 | 2017-01-06 19:54:43 -0800 | [diff] [blame] | 1593 | mOnceButton.setEnabled(true); |
Sergey Troshin | 40e979e | 2019-12-30 17:29:50 +0100 | [diff] [blame] | 1594 | // Focus the button if we already have the default option |
| 1595 | mOnceButton.requestFocus(); |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 1596 | return; |
| 1597 | } |
| 1598 | |
| 1599 | // When the items load in, if an item was already selected, enable the buttons |
arangelov | cf26864 | 2020-01-15 15:09:51 +0000 | [diff] [blame] | 1600 | ListView currentAdapterView = (ListView) mMultiProfilePagerAdapter.getActiveAdapterView(); |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1601 | if (currentAdapterView != null |
| 1602 | && currentAdapterView.getCheckedItemPosition() != ListView.INVALID_POSITION) { |
| 1603 | setAlwaysButtonEnabled(true, currentAdapterView.getCheckedItemPosition(), true); |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 1604 | mOnceButton.setEnabled(true); |
Hakan Seyalioglu | 3355012 | 2017-01-06 19:54:43 -0800 | [diff] [blame] | 1605 | } |
| 1606 | } |
| 1607 | |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 1608 | @Override // ResolverListCommunicator |
| 1609 | public boolean useLayoutWithDefault() { |
arangelov | cf26864 | 2020-01-15 15:09:51 +0000 | [diff] [blame] | 1610 | // We only use the default app layout when the profile of the active user has a |
| 1611 | // filtered item. We always show the same default app even in the inactive user profile. |
| 1612 | boolean currentUserAdapterHasFilteredItem; |
| 1613 | if (mMultiProfilePagerAdapter.getCurrentUserHandle().getIdentifier() |
| 1614 | == UserHandle.myUserId()) { |
| 1615 | currentUserAdapterHasFilteredItem = |
| 1616 | mMultiProfilePagerAdapter.getActiveListAdapter().hasFilteredItem(); |
| 1617 | } else { |
| 1618 | currentUserAdapterHasFilteredItem = |
| 1619 | mMultiProfilePagerAdapter.getInactiveListAdapter().hasFilteredItem(); |
| 1620 | } |
| 1621 | return mSupportsAlwaysUseOption && currentUserAdapterHasFilteredItem; |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 1622 | } |
| 1623 | |
Adam Powell | c412be6 | 2015-06-24 13:54:10 -0700 | [diff] [blame] | 1624 | /** |
Jorim Jaggi | f631ef7 | 2017-02-24 13:49:47 +0100 | [diff] [blame] | 1625 | * If {@code retainInOnStop} is set to true, we will not finish ourselves when onStop gets |
| 1626 | * called and we are launched in a new task. |
| 1627 | */ |
| 1628 | protected void setRetainInOnStop(boolean retainInOnStop) { |
| 1629 | mRetainInOnStop = retainInOnStop; |
| 1630 | } |
| 1631 | |
| 1632 | /** |
Adam Powell | c412be6 | 2015-06-24 13:54:10 -0700 | [diff] [blame] | 1633 | * Check a simple match for the component of two ResolveInfos. |
| 1634 | */ |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 1635 | @Override // ResolverListCommunicator |
| 1636 | public boolean resolveInfoMatch(ResolveInfo lhs, ResolveInfo rhs) { |
Adam Powell | c412be6 | 2015-06-24 13:54:10 -0700 | [diff] [blame] | 1637 | return lhs == null ? rhs == null |
| 1638 | : lhs.activityInfo == null ? rhs.activityInfo == null |
| 1639 | : Objects.equals(lhs.activityInfo.name, rhs.activityInfo.name) |
| 1640 | && Objects.equals(lhs.activityInfo.packageName, rhs.activityInfo.packageName); |
| 1641 | } |
| 1642 | |
arangelov | b0802dc | 2019-10-18 18:03:44 +0100 | [diff] [blame] | 1643 | @Override // ResolverListCommunicator |
arangelov | 7981b12 | 2020-01-16 10:58:27 +0000 | [diff] [blame] | 1644 | public void onHandlePackagesChanged(ResolverListAdapter listAdapter) { |
| 1645 | if (listAdapter == mMultiProfilePagerAdapter.getActiveListAdapter()) { |
| 1646 | boolean listRebuilt = mMultiProfilePagerAdapter.rebuildActiveTab(true); |
| 1647 | if (listRebuilt) { |
| 1648 | ResolverListAdapter activeListAdapter = |
| 1649 | mMultiProfilePagerAdapter.getActiveListAdapter(); |
| 1650 | activeListAdapter.notifyDataSetChanged(); |
| 1651 | if (activeListAdapter.getCount() == 0) { |
| 1652 | // We no longer have any items... just finish the activity. |
| 1653 | finish(); |
| 1654 | } |
| 1655 | } |
| 1656 | } else { |
| 1657 | mMultiProfilePagerAdapter.clearInactiveProfileCache(); |
Zhen Zhang | 55d66aa | 2019-10-14 17:11:19 -0700 | [diff] [blame] | 1658 | } |
Zhen Zhang | 55d66aa | 2019-10-14 17:11:19 -0700 | [diff] [blame] | 1659 | } |
Alison Cichowlas | 1c8816c | 2019-04-03 17:43:22 -0400 | [diff] [blame] | 1660 | |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1661 | @VisibleForTesting |
| 1662 | public static final class ResolvedComponentInfo { |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1663 | public final ComponentName name; |
| 1664 | private final List<Intent> mIntents = new ArrayList<>(); |
| 1665 | private final List<ResolveInfo> mResolveInfos = new ArrayList<>(); |
Alison Cichowlas | 1fd4715 | 2019-11-14 19:50:55 -0500 | [diff] [blame] | 1666 | private boolean mPinned; |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1667 | |
| 1668 | public ResolvedComponentInfo(ComponentName name, Intent intent, ResolveInfo info) { |
| 1669 | this.name = name; |
| 1670 | add(intent, info); |
| 1671 | } |
| 1672 | |
| 1673 | public void add(Intent intent, ResolveInfo info) { |
| 1674 | mIntents.add(intent); |
| 1675 | mResolveInfos.add(info); |
| 1676 | } |
| 1677 | |
| 1678 | public int getCount() { |
| 1679 | return mIntents.size(); |
| 1680 | } |
| 1681 | |
| 1682 | public Intent getIntentAt(int index) { |
| 1683 | return index >= 0 ? mIntents.get(index) : null; |
| 1684 | } |
| 1685 | |
| 1686 | public ResolveInfo getResolveInfoAt(int index) { |
| 1687 | return index >= 0 ? mResolveInfos.get(index) : null; |
| 1688 | } |
| 1689 | |
| 1690 | public int findIntent(Intent intent) { |
| 1691 | for (int i = 0, N = mIntents.size(); i < N; i++) { |
| 1692 | if (intent.equals(mIntents.get(i))) { |
| 1693 | return i; |
| 1694 | } |
| 1695 | } |
| 1696 | return -1; |
| 1697 | } |
| 1698 | |
| 1699 | public int findResolveInfo(ResolveInfo info) { |
| 1700 | for (int i = 0, N = mResolveInfos.size(); i < N; i++) { |
| 1701 | if (info.equals(mResolveInfos.get(i))) { |
| 1702 | return i; |
| 1703 | } |
| 1704 | } |
| 1705 | return -1; |
| 1706 | } |
Alison Cichowlas | 1fd4715 | 2019-11-14 19:50:55 -0500 | [diff] [blame] | 1707 | |
| 1708 | public boolean isPinned() { |
| 1709 | return mPinned; |
| 1710 | } |
| 1711 | |
| 1712 | public void setPinned(boolean pinned) { |
| 1713 | mPinned = pinned; |
| 1714 | } |
Adam Powell | 2ed547e | 2015-04-29 18:45:04 -0700 | [diff] [blame] | 1715 | } |
| 1716 | |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1717 | class ItemClickListener implements AdapterView.OnItemClickListener, |
| 1718 | AdapterView.OnItemLongClickListener { |
| 1719 | @Override |
| 1720 | public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
| 1721 | final ListView listView = parent instanceof ListView ? (ListView) parent : null; |
| 1722 | if (listView != null) { |
| 1723 | position -= listView.getHeaderViewsCount(); |
| 1724 | } |
| 1725 | if (position < 0) { |
| 1726 | // Header views don't count. |
| 1727 | return; |
| 1728 | } |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 1729 | // If we're still loading, we can't yet enable the buttons. |
arangelov | a3912cf | 2019-12-13 14:34:45 +0000 | [diff] [blame] | 1730 | if (mMultiProfilePagerAdapter.getActiveListAdapter() |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1731 | .resolveInfoForPosition(position, true) == null) { |
Hakan Seyalioglu | 23f3465 | 2017-02-03 09:38:35 -0800 | [diff] [blame] | 1732 | return; |
| 1733 | } |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1734 | ListView currentAdapterView = |
arangelov | cf26864 | 2020-01-15 15:09:51 +0000 | [diff] [blame] | 1735 | (ListView) mMultiProfilePagerAdapter.getActiveAdapterView(); |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1736 | final int checkedPos = currentAdapterView.getCheckedItemPosition(); |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1737 | final boolean hasValidSelection = checkedPos != ListView.INVALID_POSITION; |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 1738 | if (!useLayoutWithDefault() |
Ruchi Kandoi | 65d76c1 | 2017-08-18 13:05:39 -0700 | [diff] [blame] | 1739 | && (!hasValidSelection || mLastSelected != checkedPos) |
Matt Pietal | 0d6834a | 2019-06-27 13:27:52 -0400 | [diff] [blame] | 1740 | && mAlwaysButton != null) { |
| 1741 | setAlwaysButtonEnabled(hasValidSelection, checkedPos, true); |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1742 | mOnceButton.setEnabled(hasValidSelection); |
| 1743 | if (hasValidSelection) { |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1744 | currentAdapterView.smoothScrollToPosition(checkedPos); |
Sergey Troshin | 40e979e | 2019-12-30 17:29:50 +0100 | [diff] [blame] | 1745 | mOnceButton.requestFocus(); |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1746 | } |
| 1747 | mLastSelected = checkedPos; |
| 1748 | } else { |
| 1749 | startSelected(position, false, true); |
| 1750 | } |
| 1751 | } |
Adam Powell | 2d80962 | 2012-03-22 15:24:43 -0700 | [diff] [blame] | 1752 | |
| 1753 | @Override |
| 1754 | public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { |
Adam Powell | 7d75800 | 2015-05-06 17:49:36 -0700 | [diff] [blame] | 1755 | final ListView listView = parent instanceof ListView ? (ListView) parent : null; |
| 1756 | if (listView != null) { |
| 1757 | position -= listView.getHeaderViewsCount(); |
Adam Powell | 2442841 | 2015-04-01 17:19:56 -0700 | [diff] [blame] | 1758 | } |
Adam Powell | fd1e93d | 2014-09-07 16:52:22 -0700 | [diff] [blame] | 1759 | if (position < 0) { |
| 1760 | // Header views don't count. |
| 1761 | return false; |
| 1762 | } |
arangelov | a3912cf | 2019-12-13 14:34:45 +0000 | [diff] [blame] | 1763 | ResolveInfo ri = mMultiProfilePagerAdapter.getActiveListAdapter() |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1764 | .resolveInfoForPosition(position, true); |
Adam Powell | 2388251 | 2016-01-29 10:21:00 -0800 | [diff] [blame] | 1765 | showTargetDetails(ri); |
Adam Powell | 2d80962 | 2012-03-22 15:24:43 -0700 | [diff] [blame] | 1766 | return true; |
| 1767 | } |
| 1768 | |
| 1769 | } |
Adam Powell | 0256c6f | 2013-05-29 16:42:33 -0700 | [diff] [blame] | 1770 | |
Dianne Hackborn | ec452d9 | 2014-11-11 17:16:56 -0800 | [diff] [blame] | 1771 | static final boolean isSpecificUriMatch(int match) { |
| 1772 | match = match&IntentFilter.MATCH_CATEGORY_MASK; |
| 1773 | return match >= IntentFilter.MATCH_CATEGORY_HOST |
| 1774 | && match <= IntentFilter.MATCH_CATEGORY_PATH; |
| 1775 | } |
| 1776 | |
Adam Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 1777 | static class PickTargetOptionRequest extends PickOptionRequest { |
| 1778 | public PickTargetOptionRequest(@Nullable Prompt prompt, Option[] options, |
| 1779 | @Nullable Bundle extras) { |
| 1780 | super(prompt, options, extras); |
| 1781 | } |
| 1782 | |
| 1783 | @Override |
| 1784 | public void onCancel() { |
| 1785 | super.onCancel(); |
| 1786 | final ResolverActivity ra = (ResolverActivity) getActivity(); |
| 1787 | if (ra != null) { |
| 1788 | ra.mPickOptionRequest = null; |
| 1789 | ra.finish(); |
| 1790 | } |
| 1791 | } |
| 1792 | |
| 1793 | @Override |
| 1794 | public void onPickOptionResult(boolean finished, Option[] selections, Bundle result) { |
| 1795 | super.onPickOptionResult(finished, selections, result); |
| 1796 | if (selections.length != 1) { |
| 1797 | // TODO In a better world we would filter the UI presented here and let the |
| 1798 | // user refine. Maybe later. |
| 1799 | return; |
| 1800 | } |
| 1801 | |
| 1802 | final ResolverActivity ra = (ResolverActivity) getActivity(); |
| 1803 | if (ra != null) { |
arangelov | a3912cf | 2019-12-13 14:34:45 +0000 | [diff] [blame] | 1804 | final TargetInfo ti = ra.mMultiProfilePagerAdapter.getActiveListAdapter() |
arangelov | 38a6fce | 2019-12-02 18:21:22 +0000 | [diff] [blame] | 1805 | .getItem(selections[0].getIndex()); |
Adam Powell | 4c470d6 | 2015-06-19 17:46:17 -0700 | [diff] [blame] | 1806 | if (ra.onTargetSelected(ti, false)) { |
| 1807 | ra.mPickOptionRequest = null; |
| 1808 | ra.finish(); |
| 1809 | } |
| 1810 | } |
| 1811 | } |
| 1812 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1813 | } |