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