diff options
author | Jaikumar Ganesh <jaikumar@google.com> | 2012-03-06 17:15:16 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-07-16 21:14:15 -0700 |
commit | e21a4ac09d2473becaea43a73d19e9e836e7732a (patch) | |
tree | 83818e511bf4a9592d4711458c8c8c305037904e | |
parent | 75780aa43103c1810ce422f30fb0cbebde4a0716 (diff) | |
download | frameworks_base-e21a4ac09d2473becaea43a73d19e9e836e7732a.zip frameworks_base-e21a4ac09d2473becaea43a73d19e9e836e7732a.tar.gz frameworks_base-e21a4ac09d2473becaea43a73d19e9e836e7732a.tar.bz2 |
Add a new version of the disable API.
This allows for the setting to be persisted or not.
Also turn on Bluetooth in System Server if needed.
It won't work currently because the service wouldn't have
started.
Change-Id: I15fa2bff93aa32134c1b565fcbe90ba68614b6a1
4 files changed, 27 insertions, 5 deletions
diff --git a/core/java/android/bluetooth/BluetoothAdapter.java b/core/java/android/bluetooth/BluetoothAdapter.java index 755884c..8d4c3af 100644 --- a/core/java/android/bluetooth/BluetoothAdapter.java +++ b/core/java/android/bluetooth/BluetoothAdapter.java @@ -518,7 +518,24 @@ public final class BluetoothAdapter { */ public boolean disable() { try { - return mService.disable(); + return mService.disable(true); + } catch (RemoteException e) {Log.e(TAG, "", e);} + return false; + } + + /** + * Turn off the local Bluetooth adapter and don't persist the setting. + * + * <p>Requires the {@link android.Manifest.permission#BLUETOOTH_ADMIN} + * permission + * + * @return true to indicate adapter shutdown has begun, or false on + * immediate error + * @hide + */ + public boolean disable(boolean persist) { + try { + return mService.disable(persist); } catch (RemoteException e) {Log.e(TAG, "", e);} return false; } diff --git a/core/java/android/bluetooth/IBluetooth.aidl b/core/java/android/bluetooth/IBluetooth.aidl index 21f2ae3..c59c62c 100644 --- a/core/java/android/bluetooth/IBluetooth.aidl +++ b/core/java/android/bluetooth/IBluetooth.aidl @@ -34,7 +34,7 @@ interface IBluetooth boolean isEnabled(); int getState(); boolean enable(); - boolean disable(); + boolean disable(boolean persist); String getAddress(); ParcelUuid[] getUuids(); diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java index f49c4e6..2393957 100644 --- a/services/java/com/android/server/SystemServer.java +++ b/services/java/com/android/server/SystemServer.java @@ -241,11 +241,17 @@ class ServerThread extends Thread { } else if (factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL) { Slog.i(TAG, "No Bluetooth Service (factory test)"); } else { - //TODO(BT): Start BT services and turn on if needed. int airplaneModeOn = Settings.System.getInt(mContentResolver, Settings.System.AIRPLANE_MODE_ON, 0); int bluetoothOn = Settings.Secure.getInt(mContentResolver, Settings.Secure.BLUETOOTH_ON, 0); + BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); + // TODO(BT): This will not work as the Bluetooth process is not + // up. Depending on the process architecture, BluetoothAdapter + // will have to bind to the service. + if (adapter != null && airplaneModeOn == 0 && bluetoothOn != 0) { + adapter.enable(); + } } } catch (RuntimeException e) { diff --git a/services/java/com/android/server/power/ShutdownThread.java b/services/java/com/android/server/power/ShutdownThread.java index 82f72f7..d5b266a 100644 --- a/services/java/com/android/server/power/ShutdownThread.java +++ b/services/java/com/android/server/power/ShutdownThread.java @@ -340,8 +340,7 @@ public final class ShutdownThread extends Thread { bluetooth.getState() == BluetoothAdapter.STATE_OFF; if (!bluetoothOff) { Log.w(TAG, "Disabling Bluetooth..."); - //TODO(BT) - bluetooth.disable(); // disable but don't persist new state + bluetooth.disable(false); // disable but don't persist new state } } catch (RemoteException ex) { Log.e(TAG, "RemoteException during bluetooth shutdown", ex); |