1 /* 2 * Copyright (C) 2017 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.settings.wifi.tether; 18 19 import android.content.Context; 20 import android.net.ConnectivityManager; 21 import android.net.wifi.WifiManager; 22 23 import androidx.preference.Preference; 24 import androidx.preference.PreferenceScreen; 25 26 import com.android.settings.core.PreferenceControllerMixin; 27 import com.android.settingslib.core.AbstractPreferenceController; 28 29 // TODO(b/151133650): Replace AbstractPreferenceController with BasePreferenceController. 30 public abstract class WifiTetherBasePreferenceController extends AbstractPreferenceController 31 implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener { 32 33 public interface OnTetherConfigUpdateListener { onTetherConfigUpdated(AbstractPreferenceController context)34 void onTetherConfigUpdated(AbstractPreferenceController context); 35 } 36 37 protected final WifiManager mWifiManager; 38 protected final String[] mWifiRegexs; 39 protected final ConnectivityManager mCm; 40 protected final OnTetherConfigUpdateListener mListener; 41 42 protected Preference mPreference; 43 WifiTetherBasePreferenceController(Context context, OnTetherConfigUpdateListener listener)44 public WifiTetherBasePreferenceController(Context context, 45 OnTetherConfigUpdateListener listener) { 46 super(context); 47 mListener = listener; 48 mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); 49 mCm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); 50 mWifiRegexs = mCm.getTetherableWifiRegexs(); 51 } 52 53 @Override isAvailable()54 public boolean isAvailable() { 55 return mWifiManager != null && mWifiRegexs != null && mWifiRegexs.length > 0; 56 } 57 58 @Override displayPreference(PreferenceScreen screen)59 public void displayPreference(PreferenceScreen screen) { 60 super.displayPreference(screen); 61 mPreference = screen.findPreference(getPreferenceKey()); 62 updateDisplay(); 63 } 64 updateDisplay()65 public abstract void updateDisplay(); 66 } 67