am 01b32368
: Add provisioning checks for BT and USB
* commit '01b32368fffd944a0265f22db764b689179be94c': Add provisioning checks for BT and USB
This commit is contained in:
@@ -72,7 +72,6 @@ public class TetherSettings extends SettingsPreferenceFragment
|
|||||||
|
|
||||||
private WifiApEnabler mWifiApEnabler;
|
private WifiApEnabler mWifiApEnabler;
|
||||||
private CheckBoxPreference mEnableWifiAp;
|
private CheckBoxPreference mEnableWifiAp;
|
||||||
private static final int MHS_REQUEST = 0;
|
|
||||||
|
|
||||||
private CheckBoxPreference mBluetoothTether;
|
private CheckBoxPreference mBluetoothTether;
|
||||||
|
|
||||||
@@ -102,6 +101,18 @@ public class TetherSettings extends SettingsPreferenceFragment
|
|||||||
|
|
||||||
private boolean mBluetoothEnableForTether;
|
private boolean mBluetoothEnableForTether;
|
||||||
|
|
||||||
|
private static final int INVALID = -1;
|
||||||
|
private static final int WIFI_TETHERING = 0;
|
||||||
|
private static final int USB_TETHERING = 1;
|
||||||
|
private static final int BLUETOOTH_TETHERING = 2;
|
||||||
|
|
||||||
|
/* One of INVALID, WIFI_TETHERING, USB_TETHERING or BLUETOOTH_TETHERING */
|
||||||
|
private int mTetherChoice = INVALID;
|
||||||
|
|
||||||
|
/* Stores the package name and the class name of the provisioning app */
|
||||||
|
private String[] mProvisionApp;
|
||||||
|
private static final int PROVISION_REQUEST = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
super.onCreate(icicle);
|
super.onCreate(icicle);
|
||||||
@@ -154,6 +165,9 @@ public class TetherSettings extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mProvisionApp = getResources().getStringArray(
|
||||||
|
com.android.internal.R.array.config_mobile_hotspot_provision_app);
|
||||||
|
|
||||||
mView = new WebView(activity);
|
mView = new WebView(activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -454,50 +468,55 @@ public class TetherSettings extends SettingsPreferenceFragment
|
|||||||
boolean enable = (Boolean) value;
|
boolean enable = (Boolean) value;
|
||||||
|
|
||||||
if (enable) {
|
if (enable) {
|
||||||
//Check if provisioning is needed
|
startProvisioningIfNecessary(WIFI_TETHERING);
|
||||||
String[] appDetails = getResources().getStringArray(
|
|
||||||
com.android.internal.R.array.config_mobile_hotspot_provision_app);
|
|
||||||
|
|
||||||
if (appDetails.length != 2) {
|
|
||||||
mWifiApEnabler.setSoftapEnabled(true);
|
|
||||||
} else {
|
|
||||||
Intent intent = new Intent(Intent.ACTION_MAIN);
|
|
||||||
intent.setClassName(appDetails[0], appDetails[1]);
|
|
||||||
startActivityForResult(intent, MHS_REQUEST);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
mWifiApEnabler.setSoftapEnabled(false);
|
mWifiApEnabler.setSoftapEnabled(false);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean isProvisioningNeeded() {
|
||||||
|
return mProvisionApp.length == 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startProvisioningIfNecessary(int choice) {
|
||||||
|
mTetherChoice = choice;
|
||||||
|
if (isProvisioningNeeded()) {
|
||||||
|
Intent intent = new Intent(Intent.ACTION_MAIN);
|
||||||
|
intent.setClassName(mProvisionApp[0], mProvisionApp[1]);
|
||||||
|
startActivityForResult(intent, PROVISION_REQUEST);
|
||||||
|
} else {
|
||||||
|
startTethering();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
||||||
super.onActivityResult(requestCode, resultCode, intent);
|
super.onActivityResult(requestCode, resultCode, intent);
|
||||||
if (requestCode == MHS_REQUEST) {
|
if (requestCode == PROVISION_REQUEST) {
|
||||||
if (resultCode == Activity.RESULT_OK) {
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
mWifiApEnabler.setSoftapEnabled(true);
|
startTethering();
|
||||||
|
} else {
|
||||||
|
//BT and USB need checkbox turned off on failure
|
||||||
|
//Wifi tethering is never turned on until afterwards
|
||||||
|
switch (mTetherChoice) {
|
||||||
|
case BLUETOOTH_TETHERING:
|
||||||
|
mBluetoothTether.setChecked(false);
|
||||||
|
break;
|
||||||
|
case USB_TETHERING:
|
||||||
|
mUsbTether.setChecked(false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
mTetherChoice = INVALID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void startTethering() {
|
||||||
public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {
|
switch (mTetherChoice) {
|
||||||
ConnectivityManager cm =
|
case WIFI_TETHERING:
|
||||||
(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
|
mWifiApEnabler.setSoftapEnabled(true);
|
||||||
|
break;
|
||||||
if (preference == mUsbTether) {
|
case BLUETOOTH_TETHERING:
|
||||||
boolean newState = mUsbTether.isChecked();
|
|
||||||
|
|
||||||
if (cm.setUsbTethering(newState) != ConnectivityManager.TETHER_ERROR_NO_ERROR) {
|
|
||||||
mUsbTether.setChecked(false);
|
|
||||||
mUsbTether.setSummary(R.string.usb_tethering_errored_subtext);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
mUsbTether.setSummary("");
|
|
||||||
} else if (preference == mBluetoothTether) {
|
|
||||||
boolean bluetoothTetherState = mBluetoothTether.isChecked();
|
|
||||||
|
|
||||||
if (bluetoothTetherState) {
|
|
||||||
// turn on Bluetooth first
|
// turn on Bluetooth first
|
||||||
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
||||||
if (adapter.getState() == BluetoothAdapter.STATE_OFF) {
|
if (adapter.getState() == BluetoothAdapter.STATE_OFF) {
|
||||||
@@ -509,6 +528,45 @@ public class TetherSettings extends SettingsPreferenceFragment
|
|||||||
mBluetoothPan.setBluetoothTethering(true);
|
mBluetoothPan.setBluetoothTethering(true);
|
||||||
mBluetoothTether.setSummary(R.string.bluetooth_tethering_available_subtext);
|
mBluetoothTether.setSummary(R.string.bluetooth_tethering_available_subtext);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
case USB_TETHERING:
|
||||||
|
setUsbTethering(true);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
//should not happen
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setUsbTethering(boolean enabled) {
|
||||||
|
ConnectivityManager cm =
|
||||||
|
(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
if (cm.setUsbTethering(enabled) != ConnectivityManager.TETHER_ERROR_NO_ERROR) {
|
||||||
|
mUsbTether.setChecked(false);
|
||||||
|
mUsbTether.setSummary(R.string.usb_tethering_errored_subtext);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mUsbTether.setSummary("");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {
|
||||||
|
ConnectivityManager cm =
|
||||||
|
(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
|
||||||
|
if (preference == mUsbTether) {
|
||||||
|
boolean newState = mUsbTether.isChecked();
|
||||||
|
|
||||||
|
if (newState) {
|
||||||
|
startProvisioningIfNecessary(USB_TETHERING);
|
||||||
|
} else {
|
||||||
|
setUsbTethering(newState);
|
||||||
|
}
|
||||||
|
} else if (preference == mBluetoothTether) {
|
||||||
|
boolean bluetoothTetherState = mBluetoothTether.isChecked();
|
||||||
|
|
||||||
|
if (bluetoothTetherState) {
|
||||||
|
startProvisioningIfNecessary(BLUETOOTH_TETHERING);
|
||||||
} else {
|
} else {
|
||||||
boolean errored = false;
|
boolean errored = false;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user