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 public abstract class WifiTetherBasePreferenceController extends AbstractPreferenceController 30 implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener { 31 32 public interface OnTetherConfigUpdateListener { onTetherConfigUpdated()33 void onTetherConfigUpdated(); 34 } 35 36 protected final WifiManager mWifiManager; 37 protected final String[] mWifiRegexs; 38 protected final ConnectivityManager mCm; 39 protected final OnTetherConfigUpdateListener mListener; 40 41 protected Preference mPreference; 42 WifiTetherBasePreferenceController(Context context, OnTetherConfigUpdateListener listener)43 public WifiTetherBasePreferenceController(Context context, 44 OnTetherConfigUpdateListener listener) { 45 super(context); 46 mListener = listener; 47 mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); 48 mCm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); 49 mWifiRegexs = mCm.getTetherableWifiRegexs(); 50 } 51 52 @Override isAvailable()53 public boolean isAvailable() { 54 return mWifiManager != null && mWifiRegexs != null && mWifiRegexs.length > 0; 55 } 56 57 @Override displayPreference(PreferenceScreen screen)58 public void displayPreference(PreferenceScreen screen) { 59 super.displayPreference(screen); 60 mPreference = screen.findPreference(getPreferenceKey()); 61 updateDisplay(); 62 } 63 updateDisplay()64 public abstract void updateDisplay(); 65 } 66