blob: 7d6cf77a8e3041006f43c7effc8d4aec9e3d3aeb [file] [log] [blame]
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.settings;
18
Fan Zhang60f01072016-10-13 16:53:41 -070019import android.app.ActionBar;
Matthew Fritze7ac78f22016-10-03 13:26:07 -070020import android.app.ActivityManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080021import android.app.Fragment;
22import android.app.FragmentManager;
23import android.app.FragmentTransaction;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080024import android.content.BroadcastReceiver;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070025import android.content.ComponentName;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080026import android.content.Context;
27import android.content.Intent;
28import android.content.IntentFilter;
29import android.content.SharedPreferences;
30import android.content.pm.ActivityInfo;
31import android.content.pm.PackageManager;
32import android.content.pm.PackageManager.NameNotFoundException;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080033import android.content.res.Configuration;
jackqdyulei6c355f52017-03-01 17:37:23 -080034import android.graphics.Bitmap;
jackqdyulei6c355f52017-03-01 17:37:23 -080035import android.graphics.Canvas;
36import android.graphics.drawable.Drawable;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080037import android.nfc.NfcAdapter;
Jason Monkfd2c7222015-12-02 15:38:38 -050038import android.os.AsyncTask;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080039import android.os.Bundle;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080040import android.os.UserHandle;
41import android.os.UserManager;
Fan Zhanga3e8f5c2016-12-01 09:52:10 -080042import android.support.annotation.VisibleForTesting;
Jason Monk39b46742015-09-10 15:52:51 -040043import android.support.v14.preference.PreferenceFragment;
44import android.support.v7.preference.Preference;
45import android.support.v7.preference.PreferenceManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080046import android.text.TextUtils;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070047import android.transition.TransitionManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080048import android.util.Log;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070049import android.view.Menu;
50import android.view.MenuInflater;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080051import android.view.MenuItem;
52import android.view.View;
53import android.view.View.OnClickListener;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070054import android.view.ViewGroup;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080055import android.widget.Button;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070056import android.widget.SearchView;
Fan Zhang28691572016-03-23 15:31:08 -070057
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080058import com.android.internal.util.ArrayUtils;
Jason Monk4da79e02015-09-10 10:54:36 -040059import com.android.settings.Settings.WifiSettingsActivity;
Anton Philippovadfec552017-01-25 20:37:36 +000060import com.android.settings.backup.BackupSettingsActivity;
Fan Zhanga3e8f5c2016-12-01 09:52:10 -080061import com.android.settings.core.gateway.SettingsGateway;
Fan Zhangc6ca3142017-02-14 15:02:35 -080062import com.android.settings.core.instrumentation.MetricsFeatureProvider;
Fan Zhang5f79ae92016-08-18 16:04:19 -070063import com.android.settings.core.instrumentation.SharedPreferencesLogger;
Fan Zhanga96a2d82016-09-27 17:51:11 -070064import com.android.settings.dashboard.DashboardFeatureProvider;
65import com.android.settings.dashboard.DashboardSummary;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070066import com.android.settings.dashboard.SearchResultsSummary;
Fan Zhanga96a2d82016-09-27 17:51:11 -070067import com.android.settings.overlay.FeatureFactory;
Jason Monk2ebc8a02015-02-13 15:23:19 -050068import com.android.settings.search.DynamicIndexableContentMonitor;
Matthew Fritze0ed37c32016-10-24 10:12:49 -070069import com.android.settings.search2.SearchFeatureProvider;
Fabrice Di Meglio41937762014-05-13 19:51:59 -070070import com.android.settings.widget.SwitchBar;
Jason Monk4da79e02015-09-10 10:54:36 -040071import com.android.settingslib.drawer.DashboardCategory;
Jason Monk4da79e02015-09-10 10:54:36 -040072import com.android.settingslib.drawer.SettingsDrawerActivity;
Jason Monk7ea14c52016-01-22 14:28:02 -050073import com.android.settingslib.drawer.Tile;
Jason Monk2ebc8a02015-02-13 15:23:19 -050074
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080075import java.util.ArrayList;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080076import java.util.List;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -070077import java.util.Set;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080078
Jason Monk4da79e02015-09-10 10:54:36 -040079public class SettingsActivity extends SettingsDrawerActivity
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080080 implements PreferenceManager.OnPreferenceTreeClickListener,
81 PreferenceFragment.OnPreferenceStartFragmentCallback,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +010082 ButtonBarHandler, FragmentManager.OnBackStackChangedListener,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070083 SearchView.OnQueryTextListener, SearchView.OnCloseListener,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +010084 MenuItem.OnActionExpandListener {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080085
86 private static final String LOG_TAG = "Settings";
87
Philip P. Moltmannd9779db2016-02-24 12:11:05 -080088 private static final int LOADER_ID_INDEXABLE_CONTENT_MONITOR = 1;
89
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080090 // Constants for state save/restore
Fabrice Di Meglio769630c2014-04-24 14:48:48 -070091 private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070092 private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded";
93 private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query";
Fabrice Di Megliob731dd02014-04-03 18:40:38 -070094 private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -070095 private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080096
97 /**
98 * When starting this activity, the invoking Intent can contain this extra
99 * string to specify which fragment should be initially displayed.
100 * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
101 * will call isValidFragment() to confirm that the fragment class name is valid for this
102 * activity.
103 */
104 public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
105
106 /**
Fan Zhangc6ca3142017-02-14 15:02:35 -0800107 * The metrics category constant for logging source when a setting fragment is opened.
108 */
109 public static final String EXTRA_SOURCE_METRICS_CATEGORY = ":settings:source_metrics";
110
111 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800112 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
113 * this extra can also be specified to supply a Bundle of arguments to pass
114 * to that fragment when it is instantiated during the initial creation
115 * of the activity.
116 */
117 public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
118
119 /**
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700120 * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS}
121 */
122 public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
123
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800124 public static final String BACK_STACK_PREFS = ":settings:prefs";
125
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800126 // extras that allow any preference activity to be launched as part of a wizard
127
128 // show Back and Next buttons? takes boolean parameter
129 // Back will then return RESULT_CANCELED and Next RESULT_OK
130 protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
131
132 // add a Skip button?
133 private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
134
135 // specify custom text for the Back or Next buttons, or cause a button to not appear
136 // at all by setting it to null
137 protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
138 protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
139
140 /**
141 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700142 * those extra can also be specify to supply the title or title res id to be shown for
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800143 * that fragment.
144 */
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700145 public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100146 /**
147 * The package name used to resolve the title resource id.
148 */
149 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME =
150 ":settings:show_fragment_title_res_package_name";
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700151 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
152 ":settings:show_fragment_title_resid";
153 public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
154 ":settings:show_fragment_as_shortcut";
155
156 public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
157 ":settings:show_fragment_as_subsetting";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800158
Fan Zhang78ab9f92017-02-27 16:10:05 -0800159 @Deprecated
Udam Saini92779ce2016-03-28 14:29:48 -0700160 public static final String EXTRA_HIDE_DRAWER = ":settings:hide_drawer";
161
Jason Monk30695812015-11-17 09:01:08 -0500162 public static final String META_DATA_KEY_FRAGMENT_CLASS =
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800163 "com.android.settings.FRAGMENT_CLASS";
164
165 private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
166
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700167 private static final String EMPTY_QUERY = "";
168
Jason Monkd4f03ec2016-01-07 16:25:34 -0500169 private static final int REQUEST_SUGGESTION = 42;
170
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800171 private String mFragmentClass;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800172
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800173 private CharSequence mInitialTitle;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700174 private int mInitialTitleResId;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800175
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700176 private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
177 "android.settings.APPLICATION_DETAILS_SETTINGS"
178 };
179
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800180 private SharedPreferences mDevelopmentPreferences;
181 private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
182
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800183 private boolean mBatteryPresent = true;
184 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800185 @Override
186 public void onReceive(Context context, Intent intent) {
187 String action = intent.getAction();
188 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
189 boolean batteryPresent = Utils.isBatteryPresent(intent);
190
191 if (mBatteryPresent != batteryPresent) {
192 mBatteryPresent = batteryPresent;
Jason Monk4da79e02015-09-10 10:54:36 -0400193 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800194 }
195 }
196 }
197 };
198
Clara Bayarri6934a042015-10-14 11:07:35 +0100199 private final BroadcastReceiver mUserAddRemoveReceiver = new BroadcastReceiver() {
200 @Override
201 public void onReceive(Context context, Intent intent) {
Matthew Fritze34c27602017-01-18 18:24:56 -0800202 if (mSearchFeatureProvider != null && !mSearchFeatureProvider.isEnabled(context)) {
203 String action = intent.getAction();
204 if (action.equals(Intent.ACTION_USER_ADDED)
205 || action.equals(Intent.ACTION_USER_REMOVED)) {
206 mSearchFeatureProvider.updateIndex(getApplicationContext());
207 }
Clara Bayarri6934a042015-10-14 11:07:35 +0100208 }
209 }
210 };
211
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800212 private DynamicIndexableContentMonitor mDynamicIndexableContentMonitor;
Svetoslav853e4712014-04-14 10:10:25 -0700213
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700214 private ActionBar mActionBar;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700215 private SwitchBar mSwitchBar;
216
217 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700218
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700219 private boolean mDisplayHomeAsUpEnabled;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700220 private boolean mDisplaySearch;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700221
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700222 private boolean mIsShowingDashboard;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700223 private boolean mIsShortcut;
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700224
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700225 private ViewGroup mContent;
226
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700227 private SearchView mSearchView;
228 private MenuItem mSearchMenuItem;
229 private boolean mSearchMenuItemExpanded = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700230 private SearchResultsSummary mSearchResultsFragment;
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700231 private SearchFeatureProvider mSearchFeatureProvider;
Fan Zhangc6ca3142017-02-14 15:02:35 -0800232 private MetricsFeatureProvider mMetricsFeatureProvider;
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700233
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700234 // Categories
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800235 private ArrayList<DashboardCategory> mCategories = new ArrayList<>();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800236
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700237 private boolean mNeedToRevertToInitialFragment = false;
238
Fan Zhanga96a2d82016-09-27 17:51:11 -0700239 private DashboardFeatureProvider mDashboardFeatureProvider;
Jim Miller0698a212014-10-16 19:49:07 -0700240 private Intent mResultIntentData;
Jason Monkd4f03ec2016-01-07 16:25:34 -0500241 private ComponentName mCurrentSuggestion;
Jim Miller0698a212014-10-16 19:49:07 -0700242
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800243 @VisibleForTesting
244 String mSearchQuery;
245
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700246 public SwitchBar getSwitchBar() {
247 return mSwitchBar;
248 }
249
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800250 @Override
251 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
Fan Zhangc6ca3142017-02-14 15:02:35 -0800252 startPreferencePanel(caller, pref.getFragment(), pref.getExtras(), -1, pref.getTitle(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800253 null, 0);
254 return true;
255 }
256
257 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400258 public boolean onPreferenceTreeClick(Preference preference) {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800259 return false;
260 }
261
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800262 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800263 public void onConfigurationChanged(Configuration newConfig) {
264 super.onConfigurationChanged(newConfig);
Matthew Fritze34c27602017-01-18 18:24:56 -0800265 if (!mSearchFeatureProvider.isEnabled(this)) {
266 mSearchFeatureProvider.updateIndex(getApplicationContext());
267 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800268 }
269
270 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700271 protected void onStart() {
272 super.onStart();
273
274 if (mNeedToRevertToInitialFragment) {
275 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800276 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800277 }
278
279 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700280 public boolean onCreateOptionsMenu(Menu menu) {
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700281 if (!mDisplaySearch) {
282 return false;
283 }
284
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700285 MenuInflater inflater = getMenuInflater();
Matthew Fritze9955db62016-12-20 09:37:21 -0800286 if (mSearchFeatureProvider.isEnabled(this)) {
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700287 mSearchFeatureProvider.setUpSearchMenu(menu, this);
288 return true;
289 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700290 inflater.inflate(R.menu.options_menu, menu);
291
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700292
293 // Cache the search query (can be overridden by the OnQueryTextListener)
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700294 final String query = mSearchQuery;
295
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700296 mSearchMenuItem = menu.findItem(R.id.search);
297 mSearchView = (SearchView) mSearchMenuItem.getActionView();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700298
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -0700299 if (mSearchMenuItem == null || mSearchView == null) {
300 return false;
301 }
302
Fabrice Di Meglio8c3b0ce2014-05-12 18:54:32 -0700303 if (mSearchResultsFragment != null) {
304 mSearchResultsFragment.setSearchView(mSearchView);
305 }
306
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700307 mSearchMenuItem.setOnActionExpandListener(this);
Fan Zhangb9239182016-08-22 13:59:59 -0700308 mSearchView.setMaxWidth(Integer.MAX_VALUE);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700309 mSearchView.setOnQueryTextListener(this);
310 mSearchView.setOnCloseListener(this);
311
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700312 if (mSearchMenuItemExpanded) {
313 mSearchMenuItem.expandActionView();
314 }
315 mSearchView.setQuery(query, true /* submit */);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700316 return true;
317 }
318
Jason Monk31c7c322016-01-20 14:41:52 -0500319 @Override
320 public SharedPreferences getSharedPreferences(String name, int mode) {
321 if (name.equals(getPackageName() + "_preferences")) {
Jason Monke4ebcd12016-02-21 09:37:41 -0500322 return new SharedPreferencesLogger(this, getMetricsTag());
Jason Monk31c7c322016-01-20 14:41:52 -0500323 }
324 return super.getSharedPreferences(name, mode);
325 }
326
Jason Monke4ebcd12016-02-21 09:37:41 -0500327 private String getMetricsTag() {
328 String tag = getClass().getName();
329 if (getIntent() != null && getIntent().hasExtra(EXTRA_SHOW_FRAGMENT)) {
330 tag = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT);
331 }
332 if (tag.startsWith("com.android.settings.")) {
333 tag = tag.replace("com.android.settings.", "");
334 }
335 return tag;
336 }
337
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700338 private static boolean isShortCutIntent(final Intent intent) {
339 Set<String> categories = intent.getCategories();
340 return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
341 }
342
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700343 private static boolean isLikeShortCutIntent(final Intent intent) {
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700344 String action = intent.getAction();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700345 if (action == null) {
346 return false;
347 }
348 for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
349 if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
350 }
351 return false;
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700352 }
353
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700354 @Override
355 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700356 super.onCreate(savedState);
Jason Monkfd2c7222015-12-02 15:38:38 -0500357 long startTime = System.currentTimeMillis();
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700358
359 final FeatureFactory factory = FeatureFactory.getFactory(this);
360
361 mDashboardFeatureProvider = factory.getDashboardFeatureProvider(this);
Matthew Fritze9955db62016-12-20 09:37:21 -0800362 mSearchFeatureProvider = factory.getSearchFeatureProvider();
Fan Zhangc6ca3142017-02-14 15:02:35 -0800363 mMetricsFeatureProvider = factory.getMetricsFeatureProvider();
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700364
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700365 // Should happen before any call to getIntent()
366 getMetaData();
367
368 final Intent intent = getIntent();
369 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
370 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800371 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800372
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800373 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
374 Context.MODE_PRIVATE);
375
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700376 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700377 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700378
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700379 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700380 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
381
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700382 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700383 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700384
Doris Ling1694d4b2017-03-03 14:21:37 -0800385 mIsShowingDashboard = className.equals(Settings.class.getName());
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700386
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700387 // This is a "Sub Settings" when:
388 // - this is a real SubSettings
389 // - or :settings:show_fragment_as_subsetting is passed to the Intent
Jorim Jaggi4dfcb822015-04-29 17:21:32 -0700390 final boolean isSubSettings = this instanceof SubSettings ||
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700391 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
392
Fan Zhang92f1e942017-01-21 10:07:26 -0800393 // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content
394 // insets
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700395 if (isSubSettings) {
Fan Zhang92f1e942017-01-21 10:07:26 -0800396 setTheme(R.style.Theme_SubSettings);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700397 }
398
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700399 setContentView(mIsShowingDashboard ?
400 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800401
Anna Galusza6b1e9db2016-03-30 17:25:36 -0700402 mContent = (ViewGroup) findViewById(R.id.main_content);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700403
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800404 getFragmentManager().addOnBackStackChangedListener(this);
405
Matthew Fritze34c27602017-01-18 18:24:56 -0800406 if (mIsShowingDashboard && !mSearchFeatureProvider.isEnabled(this)) {
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800407 // Run the Index update only if we have some space
408 if (!Utils.isLowStorage(this)) {
Fan Zhanga8759242017-01-06 09:18:59 -0800409 mSearchFeatureProvider.updateIndex(getApplicationContext());
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800410 } else {
411 Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!");
412 }
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700413 }
414
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700415 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700416 // We are restarting from a previous saved state; used that to initialize, instead
417 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700418 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
419 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700420 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800421
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700422 ArrayList<DashboardCategory> categories =
423 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
424 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700425 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700426 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700427 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800428 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700429
430 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700431 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Salvador Martinez2368e542016-07-25 18:16:47 -0700432
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800433 } else {
Doris Lingcb69baf2017-02-23 17:50:03 -0800434 launchSettingFragment(initialFragmentName, isSubSettings, intent);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800435 }
436
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700437 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700438 if (mActionBar != null) {
439 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
440 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
441 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700442 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
Jason Monke4ebcd12016-02-21 09:37:41 -0500443 if (mSwitchBar != null) {
444 mSwitchBar.setMetricsTag(getMetricsTag());
445 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700446
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800447 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800448 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
449
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700450 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800451 if (buttonBar != null) {
452 buttonBar.setVisibility(View.VISIBLE);
453
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700454 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800455 backButton.setOnClickListener(new OnClickListener() {
456 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700457 setResult(RESULT_CANCELED, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800458 finish();
459 }
460 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700461 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800462 skipButton.setOnClickListener(new OnClickListener() {
463 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700464 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800465 finish();
466 }
467 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700468 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800469 mNextButton.setOnClickListener(new OnClickListener() {
470 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700471 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800472 finish();
473 }
474 });
475
476 // set our various button parameters
477 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
478 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
479 if (TextUtils.isEmpty(buttonText)) {
480 mNextButton.setVisibility(View.GONE);
481 }
482 else {
483 mNextButton.setText(buttonText);
484 }
485 }
486 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
487 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
488 if (TextUtils.isEmpty(buttonText)) {
489 backButton.setVisibility(View.GONE);
490 }
491 else {
492 backButton.setText(buttonText);
493 }
494 }
495 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
496 skipButton.setVisibility(View.VISIBLE);
497 }
498 }
499 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700500
Fan Zhangefba6b42017-02-07 17:40:59 -0800501 if (DEBUG_TIMING) {
502 Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime) + " ms");
503 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700504 }
505
Doris Lingcb69baf2017-02-23 17:50:03 -0800506 @VisibleForTesting
507 void launchSettingFragment(String initialFragmentName, boolean isSubSettings, Intent intent) {
508 if (!mIsShowingDashboard && initialFragmentName != null) {
509 mDisplaySearch = false;
510 // UP will be shown only if it is a sub settings
511 if (mIsShortcut) {
512 mDisplayHomeAsUpEnabled = isSubSettings;
513 } else if (isSubSettings) {
514 mDisplayHomeAsUpEnabled = true;
515 } else {
516 mDisplayHomeAsUpEnabled = false;
517 }
518 setTitleFromIntent(intent);
519
520 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
521 switchToFragment(initialFragmentName, initialArguments, true, false,
522 mInitialTitleResId, mInitialTitle, false);
523 } else {
524 // No UP affordance if we are displaying the main Dashboard
525 mDisplayHomeAsUpEnabled = false;
526 // Show Search affordance
527 mDisplaySearch = true;
528 mInitialTitleResId = R.string.dashboard_title;
529
530 switchToFragment(DashboardSummary.class.getName(), null /* args */, false, false,
531 mInitialTitleResId, mInitialTitle, false);
532 }
533 }
534
Fan Zhangece8ff62016-06-30 13:20:12 -0700535 public void setDisplaySearchMenu(boolean displaySearch) {
536 if (displaySearch != mDisplaySearch) {
537 mDisplaySearch = displaySearch;
538 invalidateOptionsMenu();
539 }
540 }
541
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700542 private void setTitleFromIntent(Intent intent) {
543 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
544 if (initialTitleResId > 0) {
545 mInitialTitle = null;
546 mInitialTitleResId = initialTitleResId;
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100547
548 final String initialTitleResPackageName = intent.getStringExtra(
549 EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
550 if (initialTitleResPackageName != null) {
551 try {
552 Context authContext = createPackageContextAsUser(initialTitleResPackageName,
553 0 /* flags */, new UserHandle(UserHandle.myUserId()));
554 mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
555 setTitle(mInitialTitle);
556 mInitialTitleResId = -1;
557 return;
558 } catch (NameNotFoundException e) {
559 Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
560 }
561 } else {
562 setTitle(mInitialTitleResId);
563 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700564 } else {
565 mInitialTitleResId = -1;
566 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
567 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
568 setTitle(mInitialTitle);
569 }
570 }
571
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800572 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800573 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700574 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800575 }
576
Fan Zhang28691572016-03-23 15:31:08 -0700577 private void setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800578 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700579
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800580 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700581 if (mInitialTitleResId > 0) {
582 setTitle(mInitialTitleResId);
583 } else {
584 setTitle(mInitialTitle);
585 }
Fan Zhang28691572016-03-23 15:31:08 -0700586 return;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800587 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700588
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800589 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
590 setTitleFromBackStackEntry(bse);
591 }
592
593 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
594 final CharSequence title;
595 final int titleRes = bse.getBreadCrumbTitleRes();
596 if (titleRes > 0) {
597 title = getText(titleRes);
598 } else {
599 title = bse.getBreadCrumbTitle();
600 }
601 if (title != null) {
602 setTitle(title);
603 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800604 }
605
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800606 @Override
607 protected void onSaveInstanceState(Bundle outState) {
608 super.onSaveInstanceState(outState);
609
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700610 if (mCategories.size() > 0) {
611 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800612 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700613
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700614 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700615 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700616
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700617 if (mDisplaySearch) {
618 // The option menus are created if the ActionBar is visible and they are also created
619 // asynchronously. If you launch Settings with an Intent action like
620 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
621 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
622 // menu item and search view are null.
623 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
624 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700625
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700626 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
627 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
628 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800629 }
630
631 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400632 protected void onResume() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800633 super.onResume();
634
635 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
636 @Override
637 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Jason Monk4da79e02015-09-10 10:54:36 -0400638 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800639 }
640 };
641 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
642 mDevelopmentPreferencesListener);
643
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800644 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Matthew Fritze34c27602017-01-18 18:24:56 -0800645 if (!mSearchFeatureProvider.isEnabled(this)) {
646 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_ADDED));
647 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_REMOVED));
648 }
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800649 if (mDynamicIndexableContentMonitor == null) {
650 mDynamicIndexableContentMonitor = new DynamicIndexableContentMonitor();
651 }
Philip P. Moltmannd9779db2016-02-24 12:11:05 -0800652 mDynamicIndexableContentMonitor.register(this, LOADER_ID_INDEXABLE_CONTENT_MONITOR);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700653
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700654 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700655 onQueryTextSubmit(mSearchQuery);
656 }
Jason Monk4da79e02015-09-10 10:54:36 -0400657 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800658 }
659
660 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400661 protected void onPause() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800662 super.onPause();
Fan Zhanga6986e72017-03-08 09:24:45 -0800663 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
664 mDevelopmentPreferencesListener);
665 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800666 unregisterReceiver(mBatteryInfoReceiver);
Matthew Fritze34c27602017-01-18 18:24:56 -0800667 if (!mSearchFeatureProvider.isEnabled(this)) {
668 unregisterReceiver(mUserAddRemoveReceiver);
669 }
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800670 if (mDynamicIndexableContentMonitor != null) {
Tadashi G. Takaokaa034fa52016-11-21 14:20:19 +0900671 mDynamicIndexableContentMonitor.unregister(this, LOADER_ID_INDEXABLE_CONTENT_MONITOR);
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800672 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800673 }
674
675 @Override
jackqdyulei6c355f52017-03-01 17:37:23 -0800676 public void setTaskDescription(ActivityManager.TaskDescription taskDescription) {
677 final Bitmap icon = getBitmapFromXmlResource(R.drawable.ic_launcher_settings);
678 taskDescription.setIcon(icon);
679 super.setTaskDescription(taskDescription);
680 }
681
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800682 protected boolean isValidFragment(String fragmentName) {
683 // Almost all fragments are wrapped in this,
684 // except for a few that have their own activities.
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800685 for (int i = 0; i < SettingsGateway.ENTRY_FRAGMENTS.length; i++) {
686 if (SettingsGateway.ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800687 }
688 return false;
689 }
690
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800691 @Override
692 public Intent getIntent() {
693 Intent superIntent = super.getIntent();
694 String startingFragment = getStartingFragmentClass(superIntent);
695 // This is called from super.onCreate, isMultiPane() is not yet reliable
696 // Do not use onIsHidingHeaders either, which relies itself on this method
697 if (startingFragment != null) {
698 Intent modIntent = new Intent(superIntent);
699 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
700 Bundle args = superIntent.getExtras();
701 if (args != null) {
702 args = new Bundle(args);
703 } else {
704 args = new Bundle();
705 }
706 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100707 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800708 return modIntent;
709 }
710 return superIntent;
711 }
712
713 /**
714 * Checks if the component name in the intent is different from the Settings class and
715 * returns the class name to load as a fragment.
716 */
717 private String getStartingFragmentClass(Intent intent) {
718 if (mFragmentClass != null) return mFragmentClass;
719
720 String intentClass = intent.getComponent().getClassName();
721 if (intentClass.equals(getClass().getName())) return null;
722
723 if ("com.android.settings.ManageApplications".equals(intentClass)
724 || "com.android.settings.RunningServices".equals(intentClass)
725 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
726 // Old names of manage apps.
727 intentClass = com.android.settings.applications.ManageApplications.class.getName();
728 }
729
730 return intentClass;
731 }
732
733 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000734 * Start a new fragment containing a preference panel. If the preferences
735 * are being displayed in multi-pane mode, the given fragment class will
736 * be instantiated and placed in the appropriate pane. If running in
737 * single-pane mode, a new activity will be launched in which to show the
738 * fragment.
739 *
740 * @param fragmentClass Full name of the class implementing the fragment.
741 * @param args Any desired arguments to supply to the fragment.
742 * @param titleRes Optional resource identifier of the title of this
743 * fragment.
744 * @param titleText Optional text of the title of this fragment.
745 * @param resultTo Optional fragment that result data should be sent to.
746 * If non-null, resultTo.onActivityResult() will be called when this
747 * preference panel is done. The launched panel must use
748 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
749 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700750 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000751 */
Fan Zhangc6ca3142017-02-14 15:02:35 -0800752 public void startPreferencePanel(Fragment caller, String fragmentClass, Bundle args,
753 int titleRes, CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700754 String title = null;
755 if (titleRes < 0) {
756 if (titleText != null) {
757 title = titleText.toString();
758 } else {
759 // There not much we can do in that case
760 title = "";
761 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700762 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700763 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fan Zhangc6ca3142017-02-14 15:02:35 -0800764 titleRes, title, mIsShortcut, mMetricsFeatureProvider.getMetricsCategory(caller));
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000765 }
766
767 /**
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100768 * Start a new fragment in a new activity containing a preference panel for a given user. If the
769 * preferences are being displayed in multi-pane mode, the given fragment class will be
770 * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
771 * activity will be launched in which to show the fragment.
772 *
773 * @param fragmentClass Full name of the class implementing the fragment.
774 * @param args Any desired arguments to supply to the fragment.
775 * @param titleRes Optional resource identifier of the title of this fragment.
776 * @param titleText Optional text of the title of this fragment.
777 * @param userHandle The user for which the panel has to be started.
778 */
Fan Zhangc6ca3142017-02-14 15:02:35 -0800779 public void startPreferencePanelAsUser(Fragment caller, String fragmentClass,
780 Bundle args, int titleRes, CharSequence titleText, UserHandle userHandle) {
Lifu Tangd0332852015-04-02 12:05:46 -0700781 // This is a workaround.
782 //
783 // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
784 // starting the fragment could cause a native stack corruption. See b/17523189. However,
785 // adding that flag and start the preference panel with the same UserHandler will make it
786 // impossible to use back button to return to the previous screen. See b/20042570.
787 //
788 // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
789 // another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
790 // when we're calling it as the same user.
791 if (userHandle.getIdentifier() == UserHandle.myUserId()) {
Fan Zhangc6ca3142017-02-14 15:02:35 -0800792 startPreferencePanel(caller, fragmentClass, args, titleRes, titleText, null, 0);
Lifu Tangd0332852015-04-02 12:05:46 -0700793 } else {
794 String title = null;
795 if (titleRes < 0) {
796 if (titleText != null) {
797 title = titleText.toString();
798 } else {
799 // There not much we can do in that case
800 title = "";
801 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100802 }
Fan Zhangc6ca3142017-02-14 15:02:35 -0800803 Utils.startWithFragmentAsUser(this, fragmentClass, args, titleRes, title,
804 mIsShortcut, mMetricsFeatureProvider.getMetricsCategory(caller), userHandle);
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100805 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100806 }
807
808 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800809 * Called by a preference panel fragment to finish itself.
810 *
811 * @param caller The fragment that is asking to be finished.
812 * @param resultCode Optional result code to send back to the original
813 * launching fragment.
814 * @param resultData Optional result data to send back to the original
815 * launching fragment.
816 */
817 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
818 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700819 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800820 }
821
822 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000823 * Start a new fragment.
824 *
825 * @param fragment The fragment to start
826 * @param push If true, the current fragment will be pushed onto the back stack. If false,
827 * the current fragment will be replaced.
828 */
829 public void startPreferenceFragment(Fragment fragment, boolean push) {
830 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Anna Galusza6b1e9db2016-03-30 17:25:36 -0700831 transaction.replace(R.id.main_content, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000832 if (push) {
833 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
834 transaction.addToBackStack(BACK_STACK_PREFS);
835 } else {
836 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
837 }
838 transaction.commitAllowingStateLoss();
839 }
840
841 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700842 * Switch to a specific Fragment with taking care of validation, Title and BackStack
843 */
844 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700845 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700846 if (validate && !isValidFragment(fragmentName)) {
847 throw new IllegalArgumentException("Invalid fragment for this activity: "
848 + fragmentName);
849 }
850 Fragment f = Fragment.instantiate(this, fragmentName, args);
851 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Anna Galusza6b1e9db2016-03-30 17:25:36 -0700852 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700853 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700854 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700855 }
856 if (addToBackStack) {
857 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
858 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700859 if (titleResId > 0) {
860 transaction.setBreadCrumbTitle(titleResId);
861 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700862 transaction.setBreadCrumbTitle(title);
863 }
864 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700865 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700866 return f;
867 }
868
Jason Monk4da79e02015-09-10 10:54:36 -0400869 private void updateTilesList() {
Jason Monkfd2c7222015-12-02 15:38:38 -0500870 // Generally the items that are will be changing from these updates will
871 // not be in the top list of tiles, so run it in the background and the
872 // SettingsDrawerActivity will pick up on the updates automatically.
873 AsyncTask.execute(new Runnable() {
874 @Override
875 public void run() {
876 doUpdateTilesList();
877 }
878 });
879 }
880
881 private void doUpdateTilesList() {
Jason Monk4da79e02015-09-10 10:54:36 -0400882 PackageManager pm = getPackageManager();
Xiaohui Chen44879a32015-07-22 13:53:22 -0700883 final UserManager um = UserManager.get(this);
884 final boolean isAdmin = um.isAdminUser();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700885
Jason Monk4da79e02015-09-10 10:54:36 -0400886 String packageName = getPackageName();
887 setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800888 pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700889
Jason Monk4da79e02015-09-10 10:54:36 -0400890 setTileEnabled(new ComponentName(packageName,
Fan Zhanga6986e72017-03-08 09:24:45 -0800891 Settings.BluetoothSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800892 pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700893
Jason Monk4da79e02015-09-10 10:54:36 -0400894 setTileEnabled(new ComponentName(packageName,
Fan Zhanga6986e72017-03-08 09:24:45 -0800895 Settings.DataUsageSummaryActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800896 Utils.isBandwidthControlEnabled(), isAdmin);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700897
Jason Monk4da79e02015-09-10 10:54:36 -0400898 setTileEnabled(new ComponentName(packageName,
Fan Zhanga6986e72017-03-08 09:24:45 -0800899 Settings.SimSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800900 Utils.showSimCardTile(this), isAdmin);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700901
Jason Monk4da79e02015-09-10 10:54:36 -0400902 setTileEnabled(new ComponentName(packageName,
Fan Zhanga6986e72017-03-08 09:24:45 -0800903 Settings.PowerUsageSummaryActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800904 mBatteryPresent, isAdmin);
Jason Monk4da79e02015-09-10 10:54:36 -0400905
906 setTileEnabled(new ComponentName(packageName,
Fan Zhanga6986e72017-03-08 09:24:45 -0800907 Settings.UserSettingsActivity.class.getName()),
Jason Monk4da79e02015-09-10 10:54:36 -0400908 UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
Fan Zhanga6986e72017-03-08 09:24:45 -0800909 && !Utils.isMonkeyRunning(), isAdmin);
Jason Monk4da79e02015-09-10 10:54:36 -0400910
Fyodor Kupolovca060e32016-06-24 13:01:11 -0700911 setTileEnabled(new ComponentName(packageName,
Fan Zhanga6986e72017-03-08 09:24:45 -0800912 Settings.NetworkDashboardActivity.class.getName()),
Doris Ling26208222017-03-03 11:28:05 -0800913 !UserManager.isDeviceInDemoMode(this), isAdmin);
914
915 setTileEnabled(new ComponentName(packageName,
Fan Zhanga6986e72017-03-08 09:24:45 -0800916 Settings.ConnectedDeviceDashboardActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800917 !UserManager.isDeviceInDemoMode(this), isAdmin);
Fyodor Kupolovca060e32016-06-24 13:01:11 -0700918
919 setTileEnabled(new ComponentName(packageName,
920 Settings.DateTimeSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800921 !UserManager.isDeviceInDemoMode(this), isAdmin);
Jason Monk4da79e02015-09-10 10:54:36 -0400922 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
923 setTileEnabled(new ComponentName(packageName,
924 Settings.PaymentSettingsActivity.class.getName()),
925 pm.hasSystemFeature(PackageManager.FEATURE_NFC)
926 && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
Fan Zhang224caad2017-01-06 11:42:48 -0800927 && adapter != null && adapter.isEnabled(), isAdmin);
Jason Monk4da79e02015-09-10 10:54:36 -0400928
929 setTileEnabled(new ComponentName(packageName,
Fan Zhanga6986e72017-03-08 09:24:45 -0800930 Settings.PrintSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800931 pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin);
Jason Monk4da79e02015-09-10 10:54:36 -0400932
933 final boolean showDev = mDevelopmentPreferences.getBoolean(
Fan Zhanga6986e72017-03-08 09:24:45 -0800934 DevelopmentSettings.PREF_SHOW, android.os.Build.TYPE.equals("eng"))
Dan Sandler12c4ba42016-03-28 11:13:40 -0400935 && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES);
Jason Monk4da79e02015-09-10 10:54:36 -0400936 setTileEnabled(new ComponentName(packageName,
937 Settings.DevelopmentSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800938 showDev, isAdmin);
Dan Sandler12c4ba42016-03-28 11:13:40 -0400939
Fan Zhanga6986e72017-03-08 09:24:45 -0800940 // Enable/disable backup settings depending on whether the user is admin.
941 setTileEnabled(new ComponentName(packageName,
942 BackupSettingsActivity.class.getName()), true,
943 isAdmin || Utils.isCarrierDemoUser(this));
944
945 setTileEnabled(new ComponentName(packageName,
946 Settings.EnterprisePrivacySettingsActivity.class.getName()),
947 FeatureFactory.getFactory(this).getEnterprisePrivacyFeatureProvider(this)
948 .hasDeviceOwner(), isAdmin);
949
Jason Monk4da79e02015-09-10 10:54:36 -0400950 if (UserHandle.MU_ENABLED && !isAdmin) {
Fan Zhanga6986e72017-03-08 09:24:45 -0800951
Jason Monk4da79e02015-09-10 10:54:36 -0400952 // When on restricted users, disable all extra categories (but only the settings ones).
Fan Zhang78ab9f92017-02-27 16:10:05 -0800953 final List<DashboardCategory> categories = mDashboardFeatureProvider.getAllCategories();
Fan Zhanga6986e72017-03-08 09:24:45 -0800954 synchronized (categories) {
955 for (DashboardCategory category : categories) {
956 for (Tile tile : category.tiles) {
957 ComponentName component = tile.intent.getComponent();
958 final String name = component.getClassName();
959 final boolean isEnabledForRestricted = ArrayUtils.contains(
960 SettingsGateway.SETTINGS_FOR_RESTRICTED, name);
961 if (packageName.equals(component.getPackageName())
962 && !isEnabledForRestricted) {
963 setTileEnabled(component, false, isAdmin);
964 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700965 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700966 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700967 }
968 }
Doris Ling26bf0032016-06-15 18:16:09 -0700969
Fan Zhang224caad2017-01-06 11:42:48 -0800970 // Final step, refresh categories.
971 updateCategories();
Jason Monk2ebc8a02015-02-13 15:23:19 -0500972 }
973
Fan Zhang224caad2017-01-06 11:42:48 -0800974 private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin) {
Jason Monk5862c1e2016-06-07 14:02:33 -0400975 if (UserHandle.MU_ENABLED && !isAdmin && getPackageName().equals(component.getPackageName())
Fan Zhang9ec45362017-01-10 11:55:45 -0800976 && !ArrayUtils.contains(SettingsGateway.SETTINGS_FOR_RESTRICTED,
977 component.getClassName())) {
Jason Monk4da79e02015-09-10 10:54:36 -0400978 enabled = false;
979 }
Jason Monk5862c1e2016-06-07 14:02:33 -0400980 setTileEnabled(component, enabled);
Jason Monk2ebc8a02015-02-13 15:23:19 -0500981 }
982
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800983 private void getMetaData() {
984 try {
985 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
986 PackageManager.GET_META_DATA);
987 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800988 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
989 } catch (NameNotFoundException nnfe) {
990 // No recovery
991 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
992 }
993 }
994
995 // give subclasses access to the Next button
996 public boolean hasNextButton() {
997 return mNextButton != null;
998 }
999
1000 public Button getNextButton() {
1001 return mNextButton;
1002 }
1003
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001004 @Override
1005 public boolean shouldUpRecreateTask(Intent targetIntent) {
1006 return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1007 }
1008
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001009 @Deprecated
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001010 @Override
1011 public boolean onQueryTextSubmit(String query) {
Matthew Fritze9955db62016-12-20 09:37:21 -08001012 if (mSearchFeatureProvider.isEnabled(this)) {
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001013 return false;
1014 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001015 mSearchQuery = query;
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001016 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001017 return mSearchResultsFragment.onQueryTextSubmit(query);
1018 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001019
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001020 @Deprecated
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001021 @Override
1022 public boolean onQueryTextChange(String newText) {
Fan Zhanga3e8f5c2016-12-01 09:52:10 -08001023 mSearchQuery = newText;
Matthew Fritze9955db62016-12-20 09:37:21 -08001024 if (mSearchFeatureProvider.isEnabled(this) || mSearchResultsFragment == null) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -07001025 return false;
1026 }
1027 return mSearchResultsFragment.onQueryTextChange(newText);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001028 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001029
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001030 @Override
1031 public boolean onClose() {
1032 return false;
1033 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001034
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001035 @Override
1036 public boolean onMenuItemActionExpand(MenuItem item) {
1037 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001038 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001039 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001040 return true;
1041 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001042
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001043 @Override
1044 public boolean onMenuItemActionCollapse(MenuItem item) {
1045 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001046 if (mSearchMenuItemExpanded) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001047 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001048 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001049 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001050 return true;
1051 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001052
Jason Monk4da79e02015-09-10 10:54:36 -04001053 @Override
Jason Monkaf001092015-11-04 13:16:18 -05001054 public void onProfileTileOpen() {
1055 if (!mIsShowingDashboard) {
1056 finish();
1057 }
1058 }
1059
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001060 @Deprecated
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001061 private void switchToSearchResultsFragmentIfNeeded() {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001062 if (mSearchResultsFragment != null) {
1063 return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001064 }
Anna Galusza6b1e9db2016-03-30 17:25:36 -07001065 Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001066 if (current != null && current instanceof SearchResultsSummary) {
1067 mSearchResultsFragment = (SearchResultsSummary) current;
1068 } else {
Fan Zhang28691572016-03-23 15:31:08 -07001069 setContentHeaderView(null);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001070 mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001071 SearchResultsSummary.class.getName(), null, false, true,
1072 R.string.search_results_title, null, true);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001073 }
Fabrice Di Megliod297a582014-04-22 17:23:23 -07001074 mSearchResultsFragment.setSearchView(mSearchView);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001075 mSearchMenuItemExpanded = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001076 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001077
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001078 @Deprecated
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001079 public void needToRevertToInitialFragment() {
1080 mNeedToRevertToInitialFragment = true;
1081 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001082
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001083 @Deprecated
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001084 private void revertToInitialFragment() {
1085 mNeedToRevertToInitialFragment = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001086 mSearchResultsFragment = null;
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001087 mSearchMenuItemExpanded = false;
1088 getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1089 FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -07001090 if (mSearchMenuItem != null) {
1091 mSearchMenuItem.collapseActionView();
1092 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001093 }
Jim Miller0698a212014-10-16 19:49:07 -07001094
1095 public Intent getResultIntentData() {
1096 return mResultIntentData;
1097 }
1098
Jason Monkd4f03ec2016-01-07 16:25:34 -05001099 public void startSuggestion(Intent intent) {
Matthew Fritze7ac78f22016-10-03 13:26:07 -07001100 if (intent == null || ActivityManager.isUserAMonkey()) {
Matthew Fritze703dc602016-09-30 12:36:27 -07001101 return;
1102 }
Matthew Fritzef265dbc2016-10-04 13:39:27 -07001103 mCurrentSuggestion = intent.getComponent();
Jason Monkd4f03ec2016-01-07 16:25:34 -05001104 startActivityForResult(intent, REQUEST_SUGGESTION);
1105 }
1106
1107 @Override
1108 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
1109 if (requestCode == REQUEST_SUGGESTION && mCurrentSuggestion != null
1110 && resultCode != RESULT_CANCELED) {
1111 getPackageManager().setComponentEnabledSetting(mCurrentSuggestion,
1112 PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
1113 }
1114 super.onActivityResult(requestCode, resultCode, data);
1115 }
jackqdyulei6c355f52017-03-01 17:37:23 -08001116
1117 @VisibleForTesting
1118 Bitmap getBitmapFromXmlResource(int drawableRes) {
1119 Drawable drawable = getResources().getDrawable(drawableRes, getTheme());
1120 Canvas canvas = new Canvas();
1121 Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
1122 drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
1123 canvas.setBitmap(bitmap);
1124 drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
1125 drawable.draw(canvas);
1126
1127 return bitmap;
1128 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001129}