diff options
| author | The Android Open Source Project <initial-contribution@android.com> | 2009-02-19 10:57:31 -0800 | 
|---|---|---|
| committer | The Android Open Source Project <initial-contribution@android.com> | 2009-02-19 10:57:31 -0800 | 
| commit | 3001a035439d8134a7d70d796376d1dfbff3cdcd (patch) | |
| tree | 343ccdba15a594ff6e50c874a145232753315a30 /core/java/android/server | |
| parent | da996f390e17e16f2dfa60e972e7ebc4f868f37e (diff) | |
| download | frameworks_base-3001a035439d8134a7d70d796376d1dfbff3cdcd.zip frameworks_base-3001a035439d8134a7d70d796376d1dfbff3cdcd.tar.gz frameworks_base-3001a035439d8134a7d70d796376d1dfbff3cdcd.tar.bz2 | |
auto import from //branches/cupcake/...@132276
Diffstat (limited to 'core/java/android/server')
| -rw-r--r-- | core/java/android/server/BluetoothDeviceService.java | 50 | ||||
| -rw-r--r-- | core/java/android/server/BluetoothEventLoop.java | 2 | 
2 files changed, 41 insertions, 11 deletions
| diff --git a/core/java/android/server/BluetoothDeviceService.java b/core/java/android/server/BluetoothDeviceService.java index 7c15045..86d5a1e 100644 --- a/core/java/android/server/BluetoothDeviceService.java +++ b/core/java/android/server/BluetoothDeviceService.java @@ -111,9 +111,19 @@ public class BluetoothDeviceService extends IBluetoothDevice.Stub {      private native int isEnabledNative();      /** -     * Disable bluetooth. Returns true on success. +     * Bring down bluetooth and disable BT in settings. Returns true on success.       */ -    public synchronized boolean disable() { +    public boolean disable() { +        return disable(true); +    } + +    /** +     * Bring down bluetooth. Returns true on success. +     * +     * @param saveSetting If true, disable BT in settings +     *  +     */ +    public synchronized boolean disable(boolean saveSetting) {          mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,                                                  "Need BLUETOOTH_ADMIN permission"); @@ -137,7 +147,9 @@ public class BluetoothDeviceService extends IBluetoothDevice.Stub {          mContext.sendBroadcast(intent, BLUETOOTH_PERM);          mIsEnabled = false; -        persistBluetoothOnSetting(false); +        if (saveSetting) { +            persistBluetoothOnSetting(false); +        }          mIsDiscovering = false;          intent = new Intent(BluetoothIntent.DISABLED_ACTION);          mContext.sendBroadcast(intent, BLUETOOTH_PERM); @@ -145,13 +157,27 @@ public class BluetoothDeviceService extends IBluetoothDevice.Stub {      }      /** +     * Bring up bluetooth, asynchronously, and enable BT in settings. +     * This turns on/off the underlying hardware. +     * +     * @return True on success (so far), guaranteeing the callback with be +     * notified when complete. +     */ +    public boolean enable(IBluetoothDeviceCallback callback) { +        return enable(callback, true); +    } + +    /**       * Enable this Bluetooth device, asynchronously.       * This turns on/off the underlying hardware.       * -     * @return True on success (so far), guarenteeing the callback with be +     * @param saveSetting If true, enable BT in settings +     *  +     * @return True on success (so far), guaranteeing the callback with be       * notified when complete.       */ -    public synchronized boolean enable(IBluetoothDeviceCallback callback) { +    public synchronized boolean enable(IBluetoothDeviceCallback callback, +            boolean saveSetting) {          mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,                                                  "Need BLUETOOTH_ADMIN permission"); @@ -165,7 +191,7 @@ public class BluetoothDeviceService extends IBluetoothDevice.Stub {          if (mEnableThread != null && mEnableThread.isAlive()) {              return false;          } -        mEnableThread = new EnableThread(callback); +        mEnableThread = new EnableThread(callback, saveSetting);          mEnableThread.start();          return true;      } @@ -189,8 +215,10 @@ public class BluetoothDeviceService extends IBluetoothDevice.Stub {      private class EnableThread extends Thread {          private final IBluetoothDeviceCallback mEnableCallback; -        public EnableThread(IBluetoothDeviceCallback callback) { +        private final boolean mSaveSetting; +        public EnableThread(IBluetoothDeviceCallback callback, boolean saveSetting) {              mEnableCallback = callback; +            mSaveSetting = saveSetting;          }          public void run() {              boolean res = (enableNative() == 0); @@ -208,7 +236,9 @@ public class BluetoothDeviceService extends IBluetoothDevice.Stub {              if (res) {                  mIsEnabled = true; -                persistBluetoothOnSetting(true); +                if (mSaveSetting) { +                    persistBluetoothOnSetting(true); +                }                  mIsDiscovering = false;                  Intent intent = new Intent(BluetoothIntent.ENABLED_ACTION);                  mBondState.loadBondState(); @@ -952,9 +982,9 @@ public class BluetoothDeviceService extends IBluetoothDevice.Stub {                  // If bluetooth is currently expected to be on, then enable or disable bluetooth                  if (Settings.Secure.getInt(resolver, Settings.Secure.BLUETOOTH_ON, 0) > 0) {                      if (enabled) { -                        enable(null); +                        enable(null, false);                      } else { -                        disable(); +                        disable(false);                      }                  }              } diff --git a/core/java/android/server/BluetoothEventLoop.java b/core/java/android/server/BluetoothEventLoop.java index b5e4090..187ec2c 100644 --- a/core/java/android/server/BluetoothEventLoop.java +++ b/core/java/android/server/BluetoothEventLoop.java @@ -359,10 +359,10 @@ class BluetoothEventLoop {      private void onGetRemoteServiceChannelResult(String address, int channel) {          IBluetoothDeviceCallback callback = mGetRemoteServiceChannelCallbacks.get(address);          if (callback != null) { +            mGetRemoteServiceChannelCallbacks.remove(address);              try {                  callback.onGetRemoteServiceChannelResult(address, channel);              } catch (RemoteException e) {} -            mGetRemoteServiceChannelCallbacks.remove(address);          }      } | 
