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