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.WIFI_SERVICE; 19 20 import android.app.settings.SettingsEnums; 21 import android.content.Context; 22 import android.content.Intent; 23 import android.net.wifi.WifiManager; 24 import android.os.Bundle; 25 import android.util.FeatureFlagUtils; 26 27 import com.android.settings.R; 28 import com.android.settings.dashboard.DashboardFragment; 29 import com.android.settings.search.BaseSearchIndexProvider; 30 import com.android.settings.wifi.p2p.WifiP2pPreferenceController; 31 import com.android.settingslib.core.AbstractPreferenceController; 32 import com.android.settingslib.search.SearchIndexable; 33 34 import java.util.ArrayList; 35 import java.util.List; 36 37 @SearchIndexable 38 public class ConfigureWifiSettings extends DashboardFragment { 39 40 private static final String TAG = "ConfigureWifiSettings"; 41 42 public static final int WIFI_WAKEUP_REQUEST_CODE = 600; 43 44 private WifiWakeupPreferenceController mWifiWakeupPreferenceController; 45 46 @Override onCreate(Bundle icicle)47 public void onCreate(Bundle icicle) { 48 super.onCreate(icicle); 49 if (FeatureFlagUtils.isEnabled(getContext(), FeatureFlagUtils.SETTINGS_PROVIDER_MODEL)) { 50 getActivity().setTitle(R.string.network_and_internet_preferences_title); 51 } 52 } 53 54 @Override getMetricsCategory()55 public int getMetricsCategory() { 56 return SettingsEnums.CONFIGURE_WIFI; 57 } 58 59 @Override getLogTag()60 protected String getLogTag() { 61 return TAG; 62 } 63 64 @Override getPreferenceScreenResId()65 protected int getPreferenceScreenResId() { 66 return R.xml.wifi_configure_settings; 67 } 68 69 @Override createPreferenceControllers(Context context)70 protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { 71 final WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE); 72 final List<AbstractPreferenceController> controllers = new ArrayList<>(); 73 controllers.add(new WifiP2pPreferenceController(context, getSettingsLifecycle(), 74 wifiManager)); 75 return controllers; 76 } 77 78 @Override onAttach(Context context)79 public void onAttach(Context context) { 80 super.onAttach(context); 81 82 83 mWifiWakeupPreferenceController = use(WifiWakeupPreferenceController.class); 84 mWifiWakeupPreferenceController.setFragment(this); 85 } 86 87 @Override onActivityResult(int requestCode, int resultCode, Intent data)88 public void onActivityResult(int requestCode, int resultCode, Intent data) { 89 if (requestCode == WIFI_WAKEUP_REQUEST_CODE) { 90 mWifiWakeupPreferenceController.onActivityResult(requestCode, resultCode); 91 return; 92 } 93 super.onActivityResult(requestCode, resultCode, data); 94 } 95 96 public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 97 new BaseSearchIndexProvider(R.xml.wifi_configure_settings) { 98 protected boolean isPageSearchEnabled(Context context) { 99 return context.getResources() 100 .getBoolean(R.bool.config_show_wifi_settings); 101 } 102 }; 103 } 104