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 |
Methods Summary |
---|
public void | addCallback(Callback callback)
if (callback == null || mCallbacks.contains(callback)) return;
if (DEBUG) Log.d(TAG, "addCallback " + callback);
mCallbacks.add(callback);
mReceiver.setListening(!mCallbacks.isEmpty());
|
private void | fireCallback(boolean isEnabled)
for (Callback callback : mCallbacks) {
callback.onHotspotChanged(isEnabled);
}
|
public boolean | isHotspotEnabled()
return mWifiManager.getWifiApState() == WifiManager.WIFI_AP_STATE_ENABLED;
|
public boolean | isHotspotSupported()
final boolean isSecondaryUser = ActivityManager.getCurrentUser() != UserHandle.USER_OWNER;
return !isSecondaryUser && mConnectivityManager.isTetheringSupported();
|
public boolean | isProvisioningNeeded()
// 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 void | removeCallback(Callback callback)
if (callback == null) return;
if (DEBUG) Log.d(TAG, "removeCallback " + callback);
mCallbacks.remove(callback);
mReceiver.setListening(!mCallbacks.isEmpty());
|
public void | setHotspotEnabled(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);
}
}
|