1 /* 2 * Copyright (C) 2016 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.network; 17 18 import android.app.settings.SettingsEnums; 19 import android.content.Context; 20 import android.content.Intent; 21 22 import androidx.lifecycle.LifecycleOwner; 23 24 import com.android.settings.R; 25 import com.android.settings.SettingsDumpService; 26 import com.android.settings.core.OnActivityResultListener; 27 import com.android.settings.dashboard.DashboardFragment; 28 import com.android.settings.flags.Flags; 29 import com.android.settings.search.BaseSearchIndexProvider; 30 import com.android.settingslib.core.AbstractPreferenceController; 31 import com.android.settingslib.core.lifecycle.Lifecycle; 32 import com.android.settingslib.search.SearchIndexable; 33 34 import java.util.ArrayList; 35 import java.util.List; 36 37 @SearchIndexable 38 public class NetworkDashboardFragment extends DashboardFragment implements 39 OnActivityResultListener { 40 41 private static final String TAG = "NetworkDashboardFrag"; 42 43 @Override getMetricsCategory()44 public int getMetricsCategory() { 45 return SettingsEnums.SETTINGS_NETWORK_CATEGORY; 46 } 47 48 @Override getLogTag()49 protected String getLogTag() { 50 return TAG; 51 } 52 53 @Override getPreferenceScreenResId()54 protected int getPreferenceScreenResId() { 55 return R.xml.network_provider_internet; 56 } 57 58 @Override onAttach(Context context)59 public void onAttach(Context context) { 60 super.onAttach(context); 61 62 use(AirplaneModePreferenceController.class).setFragment(this); 63 use(NetworkProviderCallsSmsController.class).init(this); 64 } 65 66 @Override getHelpResource()67 public int getHelpResource() { 68 return R.string.help_url_network_dashboard; 69 } 70 71 @Override createPreferenceControllers(Context context)72 protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { 73 return buildPreferenceControllers(context, getSettingsLifecycle(), 74 this /* LifecycleOwner */); 75 } 76 buildPreferenceControllers(Context context, Lifecycle lifecycle, LifecycleOwner lifecycleOwner)77 private static List<AbstractPreferenceController> buildPreferenceControllers(Context context, 78 Lifecycle lifecycle, LifecycleOwner lifecycleOwner) { 79 final VpnPreferenceController vpnPreferenceController = 80 new VpnPreferenceController(context); 81 final PrivateDnsPreferenceController privateDnsPreferenceController = 82 new PrivateDnsPreferenceController(context); 83 84 if (lifecycle != null) { 85 lifecycle.addObserver(vpnPreferenceController); 86 lifecycle.addObserver(privateDnsPreferenceController); 87 } 88 89 final List<AbstractPreferenceController> controllers = new ArrayList<>(); 90 91 controllers.add(new MobileNetworkSummaryController(context, lifecycle, lifecycleOwner)); 92 controllers.add(vpnPreferenceController); 93 94 if (Flags.internetPreferenceControllerV2()) { 95 controllers.add( 96 new InternetPreferenceControllerV2(context, InternetPreferenceController.KEY)); 97 } else { 98 controllers.add(new InternetPreferenceController(context, lifecycle, lifecycleOwner)); 99 } 100 101 controllers.add(privateDnsPreferenceController); 102 103 // Start SettingsDumpService after the MobileNetworkRepository is created. 104 Intent intent = new Intent(context, SettingsDumpService.class); 105 intent.putExtra(SettingsDumpService.EXTRA_KEY_SHOW_NETWORK_DUMP, true); 106 context.startService(intent); 107 return controllers; 108 } 109 onActivityResult(int requestCode, int resultCode, Intent data)110 public void onActivityResult(int requestCode, int resultCode, Intent data) { 111 super.onActivityResult(requestCode, resultCode, data); 112 113 switch (requestCode) { 114 case AirplaneModePreferenceController.REQUEST_CODE_EXIT_ECM: 115 use(AirplaneModePreferenceController.class) 116 .onActivityResult(requestCode, resultCode, data); 117 break; 118 } 119 } 120 121 public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 122 new BaseSearchIndexProvider(R.xml.network_provider_internet) { 123 @Override 124 public List<AbstractPreferenceController> createPreferenceControllers(Context 125 context) { 126 return buildPreferenceControllers(context, null /* lifecycle */, 127 null /* LifecycleOwner */); 128 } 129 }; 130 } 131