Fixed Bluetooth availability test in Settings
Added similar test for WiFi to be consistent. Added null tests in BluetoothEnabler. Change-Id: Ia6e7b150a1bc060c7ce0b4db12ab3f6c958af104
This commit is contained in:
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.android.settings;
|
package com.android.settings;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -24,7 +23,6 @@ import android.content.pm.ActivityInfo;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.ServiceManager;
|
|
||||||
import android.preference.PreferenceActivity;
|
import android.preference.PreferenceActivity;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -313,9 +311,14 @@ public class Settings extends PreferenceActivity implements ButtonBarHandler {
|
|||||||
} else if (id == R.id.call_settings) {
|
} else if (id == R.id.call_settings) {
|
||||||
if (!Utils.isVoiceCapable(this))
|
if (!Utils.isVoiceCapable(this))
|
||||||
target.remove(header);
|
target.remove(header);
|
||||||
|
} else if (id == R.id.wifi_settings) {
|
||||||
|
// Remove WiFi Settings if WiFi service is not available.
|
||||||
|
if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)) {
|
||||||
|
target.remove(header);
|
||||||
|
}
|
||||||
} else if (id == R.id.bluetooth_settings) {
|
} else if (id == R.id.bluetooth_settings) {
|
||||||
// Remove Bluetooth Settings if Bluetooth service is not available.
|
// Remove Bluetooth Settings if Bluetooth service is not available.
|
||||||
if (ServiceManager.getService(BluetoothAdapter.BLUETOOTH_SERVICE) == null) {
|
if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) {
|
||||||
target.remove(header);
|
target.remove(header);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -66,6 +66,7 @@ public final class BluetoothEnabler implements CompoundButton.OnCheckedChangeLis
|
|||||||
|
|
||||||
public void resume() {
|
public void resume() {
|
||||||
if (mLocalAdapter == null) {
|
if (mLocalAdapter == null) {
|
||||||
|
mSwitch.setEnabled(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,11 +92,12 @@ public final class BluetoothEnabler implements CompoundButton.OnCheckedChangeLis
|
|||||||
mSwitch = switch_;
|
mSwitch = switch_;
|
||||||
mSwitch.setOnCheckedChangeListener(this);
|
mSwitch.setOnCheckedChangeListener(this);
|
||||||
|
|
||||||
final int bluetoothState = mLocalAdapter.getBluetoothState();
|
int bluetoothState = BluetoothAdapter.STATE_OFF;
|
||||||
boolean isEnabled = bluetoothState == BluetoothAdapter.STATE_ON;
|
if (mLocalAdapter != null) bluetoothState = mLocalAdapter.getBluetoothState();
|
||||||
boolean isDisabled = bluetoothState == BluetoothAdapter.STATE_OFF;
|
boolean isOn = bluetoothState == BluetoothAdapter.STATE_ON;
|
||||||
mSwitch.setChecked(isEnabled);
|
boolean isOff = bluetoothState == BluetoothAdapter.STATE_OFF;
|
||||||
mSwitch.setEnabled(isEnabled || isDisabled);
|
mSwitch.setChecked(isOn);
|
||||||
|
mSwitch.setEnabled(isOn || isOff);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
@@ -107,7 +109,9 @@ public final class BluetoothEnabler implements CompoundButton.OnCheckedChangeLis
|
|||||||
buttonView.setChecked(false);
|
buttonView.setChecked(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
mLocalAdapter.setBluetoothEnabled(isChecked);
|
if (mLocalAdapter != null) {
|
||||||
|
mLocalAdapter.setBluetoothEnabled(isChecked);
|
||||||
|
}
|
||||||
mSwitch.setEnabled(false);
|
mSwitch.setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user