use of android.bluetooth.BluetoothPan in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class TetherSettings method onCreate.
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
if (icicle != null) {
mTetherChoice = icicle.getInt(TETHER_CHOICE);
}
addPreferencesFromResource(R.xml.tether_prefs);
mDataSaverBackend = new DataSaverBackend(getContext());
mDataSaverEnabled = mDataSaverBackend.isDataSaverEnabled();
mDataSaverFooter = findPreference(DATA_SAVER_FOOTER);
setIfOnlyAvailableForAdmins(true);
if (isUiRestricted()) {
mUnavailable = true;
setPreferenceScreen(new PreferenceScreen(getPrefContext(), null));
return;
}
final Activity activity = getActivity();
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter != null) {
adapter.getProfileProxy(activity.getApplicationContext(), mProfileServiceListener, BluetoothProfile.PAN);
}
mCreateNetwork = findPreference(WIFI_AP_SSID_AND_SECURITY);
boolean enableWifiApSettingsExt = getResources().getBoolean(R.bool.show_wifi_hotspot_settings);
boolean isWifiApEnabled = getResources().getBoolean(R.bool.hide_wifi_hotspot);
checkDefaultValue(getActivity());
if (enableWifiApSettingsExt) {
mEnableWifiAp = (HotspotPreference) findPreference(ENABLE_WIFI_AP_EXT);
getPreferenceScreen().removePreference(findPreference(ENABLE_WIFI_AP));
getPreferenceScreen().removePreference(mCreateNetwork);
Intent intent = new Intent();
intent.setAction("com.qti.ap.settings");
intent.setPackage("com.qualcomm.qti.extsettings");
mEnableWifiAp.setIntent(intent);
} else {
mEnableWifiAp = (SwitchPreference) findPreference(ENABLE_WIFI_AP);
getPreferenceScreen().removePreference(findPreference(ENABLE_WIFI_AP_EXT));
}
if (isWifiApEnabled) {
getPreferenceScreen().removePreference(mEnableWifiAp);
getPreferenceScreen().removePreference(mCreateNetwork);
}
if (getResources().getBoolean(R.bool.config_regional_hotspot_tether_help_enable)) {
mTetherHelp = (PreferenceScreen) findPreference(TETHERING_HELP);
} else {
getPreferenceScreen().removePreference(findPreference(TETHERING_HELP));
}
mUsbTether = (SwitchPreference) findPreference(USB_TETHER_SETTINGS);
mBluetoothTether = (SwitchPreference) findPreference(ENABLE_BLUETOOTH_TETHERING);
mHotspotInactivityTimeout = (ListPreference) findPreference(HOTSPOT_TIMEOUT);
mDataSaverBackend.addListener(this);
mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
mUsbRegexs = mCm.getTetherableUsbRegexs();
mWifiRegexs = mCm.getTetherableWifiRegexs();
mBluetoothRegexs = mCm.getTetherableBluetoothRegexs();
final boolean usbAvailable = mUsbRegexs.length != 0;
final boolean wifiAvailable = mWifiRegexs.length != 0;
final boolean bluetoothAvailable = mBluetoothRegexs.length != 0;
if (!usbAvailable || Utils.isMonkeyRunning()) {
getPreferenceScreen().removePreference(mUsbTether);
}
if (wifiAvailable && !Utils.isMonkeyRunning()) {
mWifiApEnabler = new WifiApEnabler(activity, mDataSaverBackend, mEnableWifiAp);
initWifiTethering();
} else {
getPreferenceScreen().removePreference(mEnableWifiAp);
getPreferenceScreen().removePreference(mCreateNetwork);
}
if (!bluetoothAvailable) {
getPreferenceScreen().removePreference(mBluetoothTether);
} else {
BluetoothPan pan = mBluetoothPan.get();
if (pan != null && pan.isTetheringOn()) {
mBluetoothTether.setChecked(true);
} else {
mBluetoothTether.setChecked(false);
}
}
mHotspotInactivityTimeout.setOnPreferenceChangeListener(this);
// Set initial state based on Data Saver mode.
onDataSaverChanged(mDataSaverBackend.isDataSaverEnabled());
}
use of android.bluetooth.BluetoothPan in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class TetherSettings method updateBluetoothState.
private void updateBluetoothState(String[] available, String[] tethered, String[] errored) {
boolean bluetoothErrored = false;
for (String s : errored) {
for (String regex : mBluetoothRegexs) {
if (s.matches(regex))
bluetoothErrored = true;
}
}
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter == null) {
return;
}
int btState = adapter.getState();
if (btState == BluetoothAdapter.STATE_TURNING_OFF) {
mBluetoothTether.setEnabled(false);
mBluetoothTether.setSummary(R.string.bluetooth_turning_off);
} else if (btState == BluetoothAdapter.STATE_TURNING_ON) {
mBluetoothTether.setEnabled(false);
mBluetoothTether.setSummary(R.string.bluetooth_turning_on);
} else {
BluetoothPan bluetoothPan = mBluetoothPan.get();
if (btState == BluetoothAdapter.STATE_ON && bluetoothPan != null && bluetoothPan.isTetheringOn()) {
mBluetoothTether.setChecked(true);
mBluetoothTether.setEnabled(!mDataSaverEnabled);
int bluetoothTethered = bluetoothPan.getConnectedDevices().size();
if (bluetoothTethered > 1) {
String summary = getString(R.string.bluetooth_tethering_devices_connected_subtext, bluetoothTethered);
mBluetoothTether.setSummary(summary);
} else if (bluetoothTethered == 1) {
mBluetoothTether.setSummary(R.string.bluetooth_tethering_device_connected_subtext);
} else if (bluetoothErrored) {
mBluetoothTether.setSummary(R.string.bluetooth_tethering_errored_subtext);
} else {
mBluetoothTether.setSummary(R.string.bluetooth_tethering_available_subtext);
}
} else {
mBluetoothTether.setEnabled(!mDataSaverEnabled);
mBluetoothTether.setChecked(false);
mBluetoothTether.setSummary(R.string.bluetooth_tethering_off_subtext);
}
}
}
Aggregations