Merge "Make TetherSettings use the new tether api."
This commit is contained in:
@@ -455,7 +455,7 @@
|
|||||||
<activity android:name="TetherProvisioningActivity"
|
<activity android:name="TetherProvisioningActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:permission="android.permission.TETHER_PRIVILEGED"
|
android:permission="android.permission.TETHER_PRIVILEGED"
|
||||||
android:theme="@android:style/Theme.Translucent.NoTitleBar">
|
android:theme="@style/Theme.ProvisioningActivity">
|
||||||
<intent-filter android:priority="1">
|
<intent-filter android:priority="1">
|
||||||
<action android:name="android.settings.TETHER_PROVISIONING_UI" />
|
<action android:name="android.settings.TETHER_PROVISIONING_UI" />
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
@@ -173,6 +173,16 @@
|
|||||||
<item name="switchBarTheme">@style/ThemeOverlay.SwitchBar.SubSettings</item>
|
<item name="switchBarTheme">@style/ThemeOverlay.SwitchBar.SubSettings</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<style name="Theme.ProvisioningActivity" parent="@android:style/Theme.Translucent.NoTitleBar">
|
||||||
|
<item name="android:windowAnimationStyle">@null</item>
|
||||||
|
<item name="android:windowIsTranslucent">true</item>
|
||||||
|
<item name="android:windowBackground">@android:color/transparent</item>
|
||||||
|
<item name="android:windowContentOverlay">@null</item>
|
||||||
|
<item name="android:windowNoTitle">true</item>
|
||||||
|
<item name="android:windowIsFloating">true</item>
|
||||||
|
<item name="android:backgroundDimEnabled">false</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
<style name="Theme.ActionBar" parent="@android:style/Widget.Material.ActionBar.Solid">
|
<style name="Theme.ActionBar" parent="@android:style/Widget.Material.ActionBar.Solid">
|
||||||
<item name="android:contentInsetStart">@dimen/actionbar_contentInsetStart</item>
|
<item name="android:contentInsetStart">@dimen/actionbar_contentInsetStart</item>
|
||||||
</style>
|
</style>
|
||||||
|
@@ -18,6 +18,7 @@ package com.android.settings;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.ResultReceiver;
|
import android.os.ResultReceiver;
|
||||||
@@ -44,9 +45,6 @@ public class TetherProvisioningActivity extends Activity {
|
|||||||
mResultReceiver = (ResultReceiver)getIntent().getParcelableExtra(
|
mResultReceiver = (ResultReceiver)getIntent().getParcelableExtra(
|
||||||
ConnectivityManager.EXTRA_PROVISION_CALLBACK);
|
ConnectivityManager.EXTRA_PROVISION_CALLBACK);
|
||||||
|
|
||||||
// TODO: Move isProvisioningNeededButUnavailable into ConnectivityManager and check
|
|
||||||
// it here to short-circuit and fail.
|
|
||||||
|
|
||||||
int tetherType = getIntent().getIntExtra(ConnectivityManager.EXTRA_ADD_TETHER_TYPE,
|
int tetherType = getIntent().getIntExtra(ConnectivityManager.EXTRA_ADD_TETHER_TYPE,
|
||||||
ConnectivityManager.TETHERING_INVALID);
|
ConnectivityManager.TETHERING_INVALID);
|
||||||
String[] provisionApp = getResources().getStringArray(
|
String[] provisionApp = getResources().getStringArray(
|
||||||
@@ -58,6 +56,15 @@ public class TetherProvisioningActivity extends Activity {
|
|||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "Starting provisioning app: " + provisionApp[0] + "." + provisionApp[1]);
|
Log.d(TAG, "Starting provisioning app: " + provisionApp[0] + "." + provisionApp[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (getPackageManager().queryIntentActivities(intent,
|
||||||
|
PackageManager.MATCH_DEFAULT_ONLY).isEmpty()) {
|
||||||
|
Log.e(TAG, "Provisioning app is configured, but not available.");
|
||||||
|
mResultReceiver.send(ConnectivityManager.TETHER_ERROR_PROVISION_FAILED, null);
|
||||||
|
finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
startActivityForResultAsUser(intent, PROVISION_REQUEST, UserHandle.CURRENT);
|
startActivityForResultAsUser(intent, PROVISION_REQUEST, UserHandle.CURRENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -29,6 +29,7 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.ResultReceiver;
|
import android.os.ResultReceiver;
|
||||||
@@ -121,13 +122,7 @@ public class TetherService extends Service {
|
|||||||
int index = mCurrentTethers.indexOf(type);
|
int index = mCurrentTethers.indexOf(type);
|
||||||
if (DEBUG) Log.d(TAG, "Removing tether " + type + ", index " + index);
|
if (DEBUG) Log.d(TAG, "Removing tether " + type + ", index " + index);
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
mCurrentTethers.remove(index);
|
removeTypeAtIndex(index);
|
||||||
// If we are currently in the middle of a check, we may need to adjust the
|
|
||||||
// index accordingly.
|
|
||||||
if (DEBUG) Log.d(TAG, "mCurrentTypeIndex: " + mCurrentTypeIndex);
|
|
||||||
if (index <= mCurrentTypeIndex && mCurrentTypeIndex > 0) {
|
|
||||||
mCurrentTypeIndex--;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
cancelAlarmIfNecessary();
|
cancelAlarmIfNecessary();
|
||||||
} else {
|
} else {
|
||||||
@@ -170,6 +165,16 @@ public class TetherService extends Service {
|
|||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void removeTypeAtIndex(int index) {
|
||||||
|
mCurrentTethers.remove(index);
|
||||||
|
// If we are currently in the middle of a check, we may need to adjust the
|
||||||
|
// index accordingly.
|
||||||
|
if (DEBUG) Log.d(TAG, "mCurrentTypeIndex: " + mCurrentTypeIndex);
|
||||||
|
if (index <= mCurrentTypeIndex && mCurrentTypeIndex > 0) {
|
||||||
|
mCurrentTypeIndex--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private ArrayList<Integer> stringToTethers(String tethersStr) {
|
private ArrayList<Integer> stringToTethers(String tethersStr) {
|
||||||
ArrayList<Integer> ret = new ArrayList<Integer>();
|
ArrayList<Integer> ret = new ArrayList<Integer>();
|
||||||
if (TextUtils.isEmpty(tethersStr)) return ret;
|
if (TextUtils.isEmpty(tethersStr)) return ret;
|
||||||
@@ -227,8 +232,20 @@ public class TetherService extends Service {
|
|||||||
if (DEBUG) Log.d(TAG, "Sending provisioning broadcast: " + provisionAction + " type: "
|
if (DEBUG) Log.d(TAG, "Sending provisioning broadcast: " + provisionAction + " type: "
|
||||||
+ mCurrentTethers.get(index));
|
+ mCurrentTethers.get(index));
|
||||||
Intent intent = new Intent(provisionAction);
|
Intent intent = new Intent(provisionAction);
|
||||||
intent.putExtra(TETHER_CHOICE, mCurrentTethers.get(index));
|
int type = mCurrentTethers.get(index);
|
||||||
|
intent.putExtra(TETHER_CHOICE, type);
|
||||||
intent.setFlags(Intent.FLAG_RECEIVER_FOREGROUND);
|
intent.setFlags(Intent.FLAG_RECEIVER_FOREGROUND);
|
||||||
|
|
||||||
|
// Ensure that the provisioning app will actually handle the intent.
|
||||||
|
final PackageManager packageManager = getPackageManager();
|
||||||
|
if (packageManager.queryBroadcastReceivers(
|
||||||
|
intent, PackageManager.MATCH_DEFAULT_ONLY).isEmpty()) {
|
||||||
|
Log.e(TAG, "Provisioning app is configured, but not available.");
|
||||||
|
fireCallbacksForType(type, ConnectivityManager.TETHER_ERROR_PROVISION_FAILED);
|
||||||
|
removeTypeAtIndex(index);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
sendBroadcast(intent);
|
sendBroadcast(intent);
|
||||||
mInProvisionCheck = true;
|
mInProvisionCheck = true;
|
||||||
}
|
}
|
||||||
|
@@ -16,6 +16,10 @@
|
|||||||
|
|
||||||
package com.android.settings;
|
package com.android.settings;
|
||||||
|
|
||||||
|
import static android.net.ConnectivityManager.TETHERING_BLUETOOTH;
|
||||||
|
import static android.net.ConnectivityManager.TETHERING_USB;
|
||||||
|
import static android.net.ConnectivityManager.TETHERING_WIFI;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
@@ -33,6 +37,7 @@ import android.net.wifi.WifiConfiguration;
|
|||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
import android.os.Handler;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.support.v14.preference.SwitchPreference;
|
import android.support.v14.preference.SwitchPreference;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
@@ -44,20 +49,15 @@ import com.android.settings.wifi.WifiApDialog;
|
|||||||
import com.android.settings.wifi.WifiApEnabler;
|
import com.android.settings.wifi.WifiApEnabler;
|
||||||
import com.android.settingslib.TetherUtil;
|
import com.android.settingslib.TetherUtil;
|
||||||
|
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import static android.net.ConnectivityManager.TETHERING_BLUETOOTH;
|
|
||||||
import static android.net.ConnectivityManager.TETHERING_INVALID;
|
|
||||||
import static android.net.ConnectivityManager.TETHERING_USB;
|
|
||||||
import static android.net.ConnectivityManager.TETHERING_WIFI;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Displays preferences for Tethering.
|
* Displays preferences for Tethering.
|
||||||
*/
|
*/
|
||||||
public class TetherSettings extends SettingsPreferenceFragment
|
public class TetherSettings extends SettingsPreferenceFragment
|
||||||
implements DialogInterface.OnClickListener, Preference.OnPreferenceChangeListener {
|
implements DialogInterface.OnClickListener, Preference.OnPreferenceChangeListener {
|
||||||
private static final String TAG = "TetherSettings";
|
|
||||||
|
|
||||||
private static final String USB_TETHER_SETTINGS = "usb_tether_settings";
|
private static final String USB_TETHER_SETTINGS = "usb_tether_settings";
|
||||||
private static final String ENABLE_WIFI_AP = "enable_wifi_ap";
|
private static final String ENABLE_WIFI_AP = "enable_wifi_ap";
|
||||||
@@ -82,6 +82,9 @@ public class TetherSettings extends SettingsPreferenceFragment
|
|||||||
private String[] mBluetoothRegexs;
|
private String[] mBluetoothRegexs;
|
||||||
private AtomicReference<BluetoothPan> mBluetoothPan = new AtomicReference<BluetoothPan>();
|
private AtomicReference<BluetoothPan> mBluetoothPan = new AtomicReference<BluetoothPan>();
|
||||||
|
|
||||||
|
private Handler mHandler = new Handler();
|
||||||
|
private OnStartTetheringCallback mStartTetheringCallback;
|
||||||
|
|
||||||
private static final String WIFI_AP_SSID_AND_SECURITY = "wifi_ap_ssid_and_security";
|
private static final String WIFI_AP_SSID_AND_SECURITY = "wifi_ap_ssid_and_security";
|
||||||
private static final int CONFIG_SUBTEXT = R.string.wifi_tether_configure_subtext;
|
private static final int CONFIG_SUBTEXT = R.string.wifi_tether_configure_subtext;
|
||||||
|
|
||||||
@@ -92,15 +95,13 @@ public class TetherSettings extends SettingsPreferenceFragment
|
|||||||
private WifiManager mWifiManager;
|
private WifiManager mWifiManager;
|
||||||
private WifiConfiguration mWifiConfig = null;
|
private WifiConfiguration mWifiConfig = null;
|
||||||
private UserManager mUm;
|
private UserManager mUm;
|
||||||
|
private ConnectivityManager mCm;
|
||||||
|
|
||||||
private boolean mUsbConnected;
|
private boolean mUsbConnected;
|
||||||
private boolean mMassStorageActive;
|
private boolean mMassStorageActive;
|
||||||
|
|
||||||
private boolean mBluetoothEnableForTether;
|
private boolean mBluetoothEnableForTether;
|
||||||
|
|
||||||
/* One of INVALID, WIFI_TETHERING, USB_TETHERING or BLUETOOTH_TETHERING */
|
|
||||||
private int mTetherChoice = TETHERING_INVALID;
|
|
||||||
|
|
||||||
/* Stores the package name and the class name of the provisioning app */
|
/* Stores the package name and the class name of the provisioning app */
|
||||||
private String[] mProvisionApp;
|
private String[] mProvisionApp;
|
||||||
private static final int PROVISION_REQUEST = 0;
|
private static final int PROVISION_REQUEST = 0;
|
||||||
@@ -116,9 +117,6 @@ public class TetherSettings extends SettingsPreferenceFragment
|
|||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
super.onCreate(icicle);
|
super.onCreate(icicle);
|
||||||
|
|
||||||
if(icicle != null) {
|
|
||||||
mTetherChoice = icicle.getInt(TETHER_CHOICE);
|
|
||||||
}
|
|
||||||
addPreferencesFromResource(R.xml.tether_prefs);
|
addPreferencesFromResource(R.xml.tether_prefs);
|
||||||
|
|
||||||
mUm = (UserManager) getSystemService(Context.USER_SERVICE);
|
mUm = (UserManager) getSystemService(Context.USER_SERVICE);
|
||||||
@@ -143,12 +141,11 @@ public class TetherSettings extends SettingsPreferenceFragment
|
|||||||
mUsbTether = (SwitchPreference) findPreference(USB_TETHER_SETTINGS);
|
mUsbTether = (SwitchPreference) findPreference(USB_TETHER_SETTINGS);
|
||||||
mBluetoothTether = (SwitchPreference) findPreference(ENABLE_BLUETOOTH_TETHERING);
|
mBluetoothTether = (SwitchPreference) findPreference(ENABLE_BLUETOOTH_TETHERING);
|
||||||
|
|
||||||
ConnectivityManager cm =
|
mCm = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
||||||
|
|
||||||
mUsbRegexs = cm.getTetherableUsbRegexs();
|
mUsbRegexs = mCm.getTetherableUsbRegexs();
|
||||||
mWifiRegexs = cm.getTetherableWifiRegexs();
|
mWifiRegexs = mCm.getTetherableWifiRegexs();
|
||||||
mBluetoothRegexs = cm.getTetherableBluetoothRegexs();
|
mBluetoothRegexs = mCm.getTetherableBluetoothRegexs();
|
||||||
|
|
||||||
final boolean usbAvailable = mUsbRegexs.length != 0;
|
final boolean usbAvailable = mUsbRegexs.length != 0;
|
||||||
final boolean wifiAvailable = mWifiRegexs.length != 0;
|
final boolean wifiAvailable = mWifiRegexs.length != 0;
|
||||||
@@ -176,15 +173,6 @@ public class TetherSettings extends SettingsPreferenceFragment
|
|||||||
mBluetoothTether.setChecked(false);
|
mBluetoothTether.setChecked(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mProvisionApp = getResources().getStringArray(
|
|
||||||
com.android.internal.R.array.config_mobile_hotspot_provision_app);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSaveInstanceState(Bundle savedInstanceState) {
|
|
||||||
savedInstanceState.putInt(TETHER_CHOICE, mTetherChoice);
|
|
||||||
super.onSaveInstanceState(savedInstanceState);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initWifiTethering() {
|
private void initWifiTethering() {
|
||||||
@@ -208,16 +196,6 @@ public class TetherSettings extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private BluetoothProfile.ServiceListener mProfileServiceListener =
|
|
||||||
new BluetoothProfile.ServiceListener() {
|
|
||||||
public void onServiceConnected(int profile, BluetoothProfile proxy) {
|
|
||||||
mBluetoothPan.set((BluetoothPan) proxy);
|
|
||||||
}
|
|
||||||
public void onServiceDisconnected(int profile) {
|
|
||||||
mBluetoothPan.set(null);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(int id) {
|
public Dialog onCreateDialog(int id) {
|
||||||
if (id == DIALOG_AP_SETTINGS) {
|
if (id == DIALOG_AP_SETTINGS) {
|
||||||
@@ -258,11 +236,8 @@ public class TetherSettings extends SettingsPreferenceFragment
|
|||||||
switch (intent
|
switch (intent
|
||||||
.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR)) {
|
.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR)) {
|
||||||
case BluetoothAdapter.STATE_ON:
|
case BluetoothAdapter.STATE_ON:
|
||||||
BluetoothPan bluetoothPan = mBluetoothPan.get();
|
startTethering(TETHERING_BLUETOOTH);
|
||||||
if (bluetoothPan != null) {
|
|
||||||
bluetoothPan.setBluetoothTethering(true);
|
|
||||||
mBluetoothEnableForTether = false;
|
mBluetoothEnableForTether = false;
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BluetoothAdapter.STATE_OFF:
|
case BluetoothAdapter.STATE_OFF:
|
||||||
@@ -294,6 +269,8 @@ public class TetherSettings extends SettingsPreferenceFragment
|
|||||||
|
|
||||||
final Activity activity = getActivity();
|
final Activity activity = getActivity();
|
||||||
|
|
||||||
|
mStartTetheringCallback = new OnStartTetheringCallback(this);
|
||||||
|
|
||||||
mMassStorageActive = Environment.MEDIA_SHARED.equals(Environment.getExternalStorageState());
|
mMassStorageActive = Environment.MEDIA_SHARED.equals(Environment.getExternalStorageState());
|
||||||
mTetherChangeReceiver = new TetherChangeReceiver();
|
mTetherChangeReceiver = new TetherChangeReceiver();
|
||||||
IntentFilter filter = new IntentFilter(ConnectivityManager.ACTION_TETHER_STATE_CHANGED);
|
IntentFilter filter = new IntentFilter(ConnectivityManager.ACTION_TETHER_STATE_CHANGED);
|
||||||
@@ -331,6 +308,7 @@ public class TetherSettings extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
getActivity().unregisterReceiver(mTetherChangeReceiver);
|
getActivity().unregisterReceiver(mTetherChangeReceiver);
|
||||||
mTetherChangeReceiver = null;
|
mTetherChangeReceiver = null;
|
||||||
|
mStartTetheringCallback = null;
|
||||||
if (mWifiApEnabler != null) {
|
if (mWifiApEnabler != null) {
|
||||||
mEnableWifiAp.setOnPreferenceChangeListener(null);
|
mEnableWifiAp.setOnPreferenceChangeListener(null);
|
||||||
mWifiApEnabler.pause();
|
mWifiApEnabler.pause();
|
||||||
@@ -338,12 +316,9 @@ public class TetherSettings extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateState() {
|
private void updateState() {
|
||||||
ConnectivityManager cm =
|
String[] available = mCm.getTetherableIfaces();
|
||||||
(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
|
String[] tethered = mCm.getTetheredIfaces();
|
||||||
|
String[] errored = mCm.getTetheringErroredIfaces();
|
||||||
String[] available = cm.getTetherableIfaces();
|
|
||||||
String[] tethered = cm.getTetheredIfaces();
|
|
||||||
String[] errored = cm.getTetheringErroredIfaces();
|
|
||||||
updateState(available, tethered, errored);
|
updateState(available, tethered, errored);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -356,15 +331,13 @@ public class TetherSettings extends SettingsPreferenceFragment
|
|||||||
|
|
||||||
private void updateUsbState(String[] available, String[] tethered,
|
private void updateUsbState(String[] available, String[] tethered,
|
||||||
String[] errored) {
|
String[] errored) {
|
||||||
ConnectivityManager cm =
|
|
||||||
(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
||||||
boolean usbAvailable = mUsbConnected && !mMassStorageActive;
|
boolean usbAvailable = mUsbConnected && !mMassStorageActive;
|
||||||
int usbError = ConnectivityManager.TETHER_ERROR_NO_ERROR;
|
int usbError = ConnectivityManager.TETHER_ERROR_NO_ERROR;
|
||||||
for (String s : available) {
|
for (String s : available) {
|
||||||
for (String regex : mUsbRegexs) {
|
for (String regex : mUsbRegexs) {
|
||||||
if (s.matches(regex)) {
|
if (s.matches(regex)) {
|
||||||
if (usbError == ConnectivityManager.TETHER_ERROR_NO_ERROR) {
|
if (usbError == ConnectivityManager.TETHER_ERROR_NO_ERROR) {
|
||||||
usbError = cm.getLastTetherError(s);
|
usbError = mCm.getLastTetherError(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -456,16 +429,14 @@ public class TetherSettings extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object value) {
|
public boolean onPreferenceChange(Preference preference, Object value) {
|
||||||
boolean enable = (Boolean) value;
|
boolean enable = (Boolean) value;
|
||||||
|
|
||||||
if (enable) {
|
if (enable) {
|
||||||
startProvisioningIfNecessary(TETHERING_WIFI);
|
startTethering(TETHERING_WIFI);
|
||||||
} else {
|
} else {
|
||||||
if (TetherUtil.isProvisioningNeeded(getActivity())) {
|
mCm.stopTethering(TETHERING_WIFI);
|
||||||
TetherService.cancelRecheckAlarmIfNecessary(getActivity(), TETHERING_WIFI);
|
|
||||||
}
|
|
||||||
mWifiApEnabler.setSoftapEnabled(false);
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -486,120 +457,38 @@ public class TetherSettings extends SettingsPreferenceFragment
|
|||||||
PackageManager.MATCH_DEFAULT_ONLY).size() > 0);
|
PackageManager.MATCH_DEFAULT_ONLY).size() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startProvisioningIfNecessary(int choice) {
|
private void startTethering(int choice) {
|
||||||
mTetherChoice = choice;
|
if (choice == TETHERING_BLUETOOTH) {
|
||||||
if (TetherUtil.isProvisioningNeeded(getActivity())) {
|
// Turn on Bluetooth first.
|
||||||
Intent intent = new Intent(Intent.ACTION_MAIN);
|
|
||||||
intent.setClassName(mProvisionApp[0], mProvisionApp[1]);
|
|
||||||
intent.putExtra(TETHER_CHOICE, mTetherChoice);
|
|
||||||
startActivityForResult(intent, PROVISION_REQUEST);
|
|
||||||
} else {
|
|
||||||
startTethering();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
|
||||||
super.onActivityResult(requestCode, resultCode, intent);
|
|
||||||
if (requestCode == PROVISION_REQUEST) {
|
|
||||||
if (resultCode == Activity.RESULT_OK) {
|
|
||||||
TetherService.scheduleRecheckAlarm(getActivity(), mTetherChoice);
|
|
||||||
startTethering();
|
|
||||||
} else {
|
|
||||||
//BT and USB need switch turned off on failure
|
|
||||||
//Wifi tethering is never turned on until afterwards
|
|
||||||
switch (mTetherChoice) {
|
|
||||||
case TETHERING_BLUETOOTH:
|
|
||||||
mBluetoothTether.setChecked(false);
|
|
||||||
break;
|
|
||||||
case TETHERING_USB:
|
|
||||||
mUsbTether.setChecked(false);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
mTetherChoice = TETHERING_INVALID;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void startTethering() {
|
|
||||||
switch (mTetherChoice) {
|
|
||||||
case TETHERING_WIFI:
|
|
||||||
mWifiApEnabler.setSoftapEnabled(true);
|
|
||||||
break;
|
|
||||||
case TETHERING_BLUETOOTH:
|
|
||||||
// turn on Bluetooth first
|
|
||||||
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
||||||
if (adapter.getState() == BluetoothAdapter.STATE_OFF) {
|
if (adapter.getState() == BluetoothAdapter.STATE_OFF) {
|
||||||
mBluetoothEnableForTether = true;
|
mBluetoothEnableForTether = true;
|
||||||
adapter.enable();
|
adapter.enable();
|
||||||
mBluetoothTether.setSummary(R.string.bluetooth_turning_on);
|
mBluetoothTether.setSummary(R.string.bluetooth_turning_on);
|
||||||
mBluetoothTether.setEnabled(false);
|
mBluetoothTether.setEnabled(false);
|
||||||
} else {
|
return;
|
||||||
BluetoothPan bluetoothPan = mBluetoothPan.get();
|
|
||||||
if (bluetoothPan != null) bluetoothPan.setBluetoothTethering(true);
|
|
||||||
mBluetoothTether.setSummary(R.string.bluetooth_tethering_available_subtext);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case TETHERING_USB:
|
|
||||||
setUsbTethering(true);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
//should not happen
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUsbTethering(boolean enabled) {
|
mCm.startTethering(choice, true, mStartTetheringCallback, mHandler);
|
||||||
ConnectivityManager cm =
|
|
||||||
(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
||||||
mUsbTether.setChecked(false);
|
|
||||||
if (cm.setUsbTethering(enabled) != ConnectivityManager.TETHER_ERROR_NO_ERROR) {
|
|
||||||
mUsbTether.setSummary(R.string.usb_tethering_errored_subtext);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mUsbTether.setSummary("");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceTreeClick(Preference preference) {
|
public boolean onPreferenceTreeClick(Preference preference) {
|
||||||
ConnectivityManager cm =
|
|
||||||
(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
||||||
|
|
||||||
if (preference == mUsbTether) {
|
if (preference == mUsbTether) {
|
||||||
boolean newState = mUsbTether.isChecked();
|
if (mUsbTether.isChecked()) {
|
||||||
|
startTethering(TETHERING_USB);
|
||||||
if (newState) {
|
|
||||||
startProvisioningIfNecessary(TETHERING_USB);
|
|
||||||
} else {
|
} else {
|
||||||
if (TetherUtil.isProvisioningNeeded(getActivity())) {
|
mCm.stopTethering(TETHERING_USB);
|
||||||
TetherService.cancelRecheckAlarmIfNecessary(getActivity(), TETHERING_USB);
|
|
||||||
}
|
|
||||||
setUsbTethering(newState);
|
|
||||||
}
|
}
|
||||||
} else if (preference == mBluetoothTether) {
|
} else if (preference == mBluetoothTether) {
|
||||||
boolean bluetoothTetherState = mBluetoothTether.isChecked();
|
if (mBluetoothTether.isChecked()) {
|
||||||
|
startTethering(TETHERING_BLUETOOTH);
|
||||||
if (bluetoothTetherState) {
|
|
||||||
startProvisioningIfNecessary(TETHERING_BLUETOOTH);
|
|
||||||
} else {
|
} else {
|
||||||
if (TetherUtil.isProvisioningNeeded(getActivity())) {
|
mCm.stopTethering(TETHERING_BLUETOOTH);
|
||||||
TetherService.cancelRecheckAlarmIfNecessary(getActivity(), TETHERING_BLUETOOTH);
|
// No ACTION_TETHER_STATE_CHANGED is fired or bluetooth unless a device is
|
||||||
}
|
// connected. Need to update state manually.
|
||||||
boolean errored = false;
|
updateState();
|
||||||
|
|
||||||
String [] tethered = cm.getTetheredIfaces();
|
|
||||||
String bluetoothIface = findIface(tethered, mBluetoothRegexs);
|
|
||||||
if (bluetoothIface != null &&
|
|
||||||
cm.untether(bluetoothIface) != ConnectivityManager.TETHER_ERROR_NO_ERROR) {
|
|
||||||
errored = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
BluetoothPan bluetoothPan = mBluetoothPan.get();
|
|
||||||
if (bluetoothPan != null) bluetoothPan.setBluetoothTethering(false);
|
|
||||||
if (errored) {
|
|
||||||
mBluetoothTether.setSummary(R.string.bluetooth_tethering_errored_subtext);
|
|
||||||
} else {
|
|
||||||
mBluetoothTether.setSummary(R.string.bluetooth_tethering_off_subtext);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (preference == mCreateNetwork) {
|
} else if (preference == mCreateNetwork) {
|
||||||
showDialog(DIALOG_AP_SETTINGS);
|
showDialog(DIALOG_AP_SETTINGS);
|
||||||
@@ -608,17 +497,6 @@ public class TetherSettings extends SettingsPreferenceFragment
|
|||||||
return super.onPreferenceTreeClick(preference);
|
return super.onPreferenceTreeClick(preference);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String findIface(String[] ifaces, String[] regexes) {
|
|
||||||
for (String iface : ifaces) {
|
|
||||||
for (String regex : regexes) {
|
|
||||||
if (iface.matches(regex)) {
|
|
||||||
return iface;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onClick(DialogInterface dialogInterface, int button) {
|
public void onClick(DialogInterface dialogInterface, int button) {
|
||||||
if (button == DialogInterface.BUTTON_POSITIVE) {
|
if (button == DialogInterface.BUTTON_POSITIVE) {
|
||||||
mWifiConfig = mDialog.getConfig();
|
mWifiConfig = mDialog.getConfig();
|
||||||
@@ -646,4 +524,40 @@ public class TetherSettings extends SettingsPreferenceFragment
|
|||||||
public int getHelpResource() {
|
public int getHelpResource() {
|
||||||
return R.string.help_url_tether;
|
return R.string.help_url_tether;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private BluetoothProfile.ServiceListener mProfileServiceListener =
|
||||||
|
new BluetoothProfile.ServiceListener() {
|
||||||
|
public void onServiceConnected(int profile, BluetoothProfile proxy) {
|
||||||
|
mBluetoothPan.set((BluetoothPan) proxy);
|
||||||
|
}
|
||||||
|
public void onServiceDisconnected(int profile) {
|
||||||
|
mBluetoothPan.set(null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private static final class OnStartTetheringCallback extends
|
||||||
|
ConnectivityManager.OnStartTetheringCallback {
|
||||||
|
final WeakReference<TetherSettings> mTetherSettings;
|
||||||
|
|
||||||
|
OnStartTetheringCallback(TetherSettings settings) {
|
||||||
|
mTetherSettings = new WeakReference<TetherSettings>(settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTetheringStarted() {
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTetheringFailed() {
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void update() {
|
||||||
|
TetherSettings settings = mTetherSettings.get();
|
||||||
|
if (settings != null) {
|
||||||
|
settings.updateState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user