FileDocCategorySizeDatePackage
HotspotControllerImpl.javaAPI DocAndroid 5.1 API6704Thu Mar 12 22:22:42 GMT 2015com.android.systemui.statusbar.policy

HotspotControllerImpl

public class HotspotControllerImpl extends Object implements HotspotController

Fields Summary
private static final String
TAG
private static final boolean
DEBUG
public static final String
EXTRA_ADD_TETHER_TYPE
public static final String
EXTRA_SET_ALARM
public static final String
EXTRA_RUN_PROVISION
public static final String
EXTRA_ENABLE_WIFI_TETHER
public static final int
WIFI_TETHERING
private final ArrayList
mCallbacks
private final Receiver
mReceiver
private final android.content.Context
mContext
private final android.net.wifi.WifiManager
mWifiManager
private final android.net.ConnectivityManager
mConnectivityManager
Constructors Summary
public HotspotControllerImpl(android.content.Context context)


       
        mContext = context;
        mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
        mConnectivityManager = (ConnectivityManager)
                mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
    
Methods Summary
public voidaddCallback(Callback callback)

        if (callback == null || mCallbacks.contains(callback)) return;
        if (DEBUG) Log.d(TAG, "addCallback " + callback);
        mCallbacks.add(callback);
        mReceiver.setListening(!mCallbacks.isEmpty());
    
private voidfireCallback(boolean isEnabled)

        for (Callback callback : mCallbacks) {
            callback.onHotspotChanged(isEnabled);
        }
    
public booleanisHotspotEnabled()

        return mWifiManager.getWifiApState() == WifiManager.WIFI_AP_STATE_ENABLED;
    
public booleanisHotspotSupported()

        final boolean isSecondaryUser = ActivityManager.getCurrentUser() != UserHandle.USER_OWNER;
        return !isSecondaryUser && mConnectivityManager.isTetheringSupported();
    
public booleanisProvisioningNeeded()

        // Keep in sync with other usage of config_mobile_hotspot_provision_app.
        // TetherSettings#isProvisioningNeeded and
        // ConnectivityManager#enforceTetherChangePermission
        String[] provisionApp = mContext.getResources().getStringArray(
                com.android.internal.R.array.config_mobile_hotspot_provision_app);
        if (SystemProperties.getBoolean("net.tethering.noprovisioning", false)
                || provisionApp == null) {
            return false;
        }
        return (provisionApp.length == 2);
    
public voidremoveCallback(Callback callback)

        if (callback == null) return;
        if (DEBUG) Log.d(TAG, "removeCallback " + callback);
        mCallbacks.remove(callback);
        mReceiver.setListening(!mCallbacks.isEmpty());
    
public voidsetHotspotEnabled(boolean enabled)

        final ContentResolver cr = mContext.getContentResolver();
        // Call provisioning app which is called when enabling Tethering from Settings
        if (enabled) {
            if (isProvisioningNeeded()) {
                String tetherEnable = mContext.getResources().getString(
                        com.android.internal.R.string.config_wifi_tether_enable);
                Intent intent = new Intent();
                intent.putExtra(EXTRA_ADD_TETHER_TYPE, WIFI_TETHERING);
                intent.putExtra(EXTRA_SET_ALARM, true);
                intent.putExtra(EXTRA_RUN_PROVISION, true);
                intent.putExtra(EXTRA_ENABLE_WIFI_TETHER, true);
                intent.setComponent(ComponentName.unflattenFromString(tetherEnable));
                mContext.startServiceAsUser(intent, UserHandle.CURRENT);
            } else {
                int wifiState = mWifiManager.getWifiState();
                if ((wifiState == WifiManager.WIFI_STATE_ENABLING) ||
                        (wifiState == WifiManager.WIFI_STATE_ENABLED)) {
                    mWifiManager.setWifiEnabled(false);
                    Settings.Global.putInt(cr, Settings.Global.WIFI_SAVED_STATE, 1);
                }
                mWifiManager.setWifiApEnabled(null, true);
            }
        } else {
            mWifiManager.setWifiApEnabled(null, false);
            if (Settings.Global.getInt(cr, Settings.Global.WIFI_SAVED_STATE, 0) == 1) {
                mWifiManager.setWifiEnabled(true);
                Settings.Global.putInt(cr, Settings.Global.WIFI_SAVED_STATE, 0);
            }
        }