1 /* 2 * Copyright (C) 2015 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 package com.android.settings.wifi; 17 18 import static android.content.Context.NETWORK_SCORE_SERVICE; 19 import static android.content.Context.WIFI_SERVICE; 20 21 import android.content.Context; 22 import android.content.Intent; 23 import android.net.NetworkScoreManager; 24 import android.net.wifi.WifiManager; 25 import android.provider.SearchIndexableResource; 26 27 import com.android.internal.logging.nano.MetricsProto.MetricsEvent; 28 import com.android.settings.R; 29 import com.android.settings.SettingsActivity; 30 import com.android.settings.core.PreferenceController; 31 import com.android.settings.dashboard.DashboardFragment; 32 import com.android.settings.network.NetworkScoreManagerWrapper; 33 import com.android.settings.network.NetworkScorerPickerPreferenceController; 34 import com.android.settings.network.WifiCallingPreferenceController; 35 import com.android.settings.search.BaseSearchIndexProvider; 36 import com.android.settings.search.Indexable; 37 import com.android.settings.wifi.p2p.WifiP2pPreferenceController; 38 39 import java.util.ArrayList; 40 import java.util.Arrays; 41 import java.util.List; 42 43 public class ConfigureWifiSettings extends DashboardFragment { 44 45 private static final String TAG = "ConfigureWifiSettings"; 46 47 private UseOpenWifiPreferenceController mUseOpenWifiPreferenceController; 48 49 @Override 50 public int getMetricsCategory() { 51 return MetricsEvent.CONFIGURE_WIFI; 52 } 53 54 @Override 55 protected String getLogTag() { 56 return TAG; 57 } 58 59 @Override 60 public void onAttach(Context context) { 61 super.onAttach(context); 62 mProgressiveDisclosureMixin.setTileLimit( 63 mUseOpenWifiPreferenceController.isAvailable() ? 3 : 2); 64 ((SettingsActivity) getActivity()).setDisplaySearchMenu(true); 65 } 66 67 @Override 68 protected int getPreferenceScreenResId() { 69 return R.xml.wifi_configure_settings; 70 } 71 72 @Override 73 protected List<PreferenceController> getPreferenceControllers(Context context) { 74 final NetworkScoreManagerWrapper networkScoreManagerWrapper = 75 new NetworkScoreManagerWrapper(context.getSystemService(NetworkScoreManager.class)); 76 mUseOpenWifiPreferenceController = new UseOpenWifiPreferenceController(context, this, 77 networkScoreManagerWrapper, getLifecycle()); 78 final WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE); 79 final List<PreferenceController> controllers = new ArrayList<>(); 80 controllers.add(new WifiWakeupPreferenceController(context, getLifecycle())); 81 controllers.add(new NetworkScorerPickerPreferenceController(context, 82 networkScoreManagerWrapper)); 83 controllers.add(new NotifyOpenNetworksPreferenceController(context, getLifecycle())); 84 controllers.add(mUseOpenWifiPreferenceController); 85 controllers.add(new WifiSleepPolicyPreferenceController(context)); 86 controllers.add(new WifiInfoPreferenceController(context, getLifecycle(), wifiManager)); 87 controllers.add(new CellularFallbackPreferenceController(context)); 88 controllers.add(new WifiP2pPreferenceController(context, getLifecycle(), wifiManager)); 89 controllers.add(new WifiCallingPreferenceController(context)); 90 controllers.add(new WpsPreferenceController( 91 context, getLifecycle(), wifiManager, getFragmentManager())); 92 return controllers; 93 } 94 95 @Override 96 public void onActivityResult(int requestCode, int resultCode, Intent data) { 97 if (mUseOpenWifiPreferenceController == null || 98 !mUseOpenWifiPreferenceController.onActivityResult(requestCode, resultCode)) { 99 super.onActivityResult(requestCode, resultCode, data); 100 } 101 } 102 103 public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 104 new BaseSearchIndexProvider() { 105 @Override 106 public List<SearchIndexableResource> getXmlResourcesToIndex(Context context, 107 boolean enabled) { 108 final SearchIndexableResource sir = new SearchIndexableResource(context); 109 sir.xmlResId = R.xml.wifi_configure_settings; 110 return Arrays.asList(sir); 111 } 112 }; 113 } 114