am 58de1427: Merge "Implement enableNoAutoconnect()" into jb-mr1-dev
* commit '58de1427c313e0debf2a929931e8c4065d4d46c5': Implement enableNoAutoconnect()
This commit is contained in:
@@ -504,7 +504,10 @@ public final class BluetoothAdapter {
|
|||||||
* immediate error
|
* immediate error
|
||||||
*/
|
*/
|
||||||
public boolean enable() {
|
public boolean enable() {
|
||||||
boolean enabled = false;
|
if (isEnabled() == true){
|
||||||
|
if (DBG) Log.d(TAG, "enable(): BT is already enabled..!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
return mManagerService.enable();
|
return mManagerService.enable();
|
||||||
} catch (RemoteException e) {Log.e(TAG, "", e);}
|
} catch (RemoteException e) {Log.e(TAG, "", e);}
|
||||||
@@ -1246,8 +1249,14 @@ public final class BluetoothAdapter {
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public boolean enableNoAutoConnect() {
|
public boolean enableNoAutoConnect() {
|
||||||
// TODO avoid auto-connect in the new stack.
|
if (isEnabled() == true){
|
||||||
return enable();
|
if (DBG) Log.d(TAG, "enableNoAutoConnect(): BT is already enabled..!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return mManagerService.enableNoAutoConnect();
|
||||||
|
} catch (RemoteException e) {Log.e(TAG, "", e);}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
1
core/java/android/bluetooth/IBluetoothManager.aidl
Normal file → Executable file
1
core/java/android/bluetooth/IBluetoothManager.aidl
Normal file → Executable file
@@ -21,6 +21,7 @@ interface IBluetoothManager
|
|||||||
void unregisterStateChangeCallback(in IBluetoothStateChangeCallback callback);
|
void unregisterStateChangeCallback(in IBluetoothStateChangeCallback callback);
|
||||||
boolean isEnabled();
|
boolean isEnabled();
|
||||||
boolean enable();
|
boolean enable();
|
||||||
|
boolean enableNoAutoConnect();
|
||||||
boolean disable(boolean persist);
|
boolean disable(boolean persist);
|
||||||
|
|
||||||
String getAddress();
|
String getAddress();
|
||||||
|
|||||||
60
services/java/com/android/server/BluetoothManagerService.java
Normal file → Executable file
60
services/java/com/android/server/BluetoothManagerService.java
Normal file → Executable file
@@ -22,6 +22,7 @@ import android.os.IBinder;
|
|||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.RemoteCallbackList;
|
import android.os.RemoteCallbackList;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
|
import android.os.Binder;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -66,6 +67,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
private IBluetooth mBluetooth;
|
private IBluetooth mBluetooth;
|
||||||
private boolean mBinding;
|
private boolean mBinding;
|
||||||
private boolean mUnbinding;
|
private boolean mUnbinding;
|
||||||
|
private boolean mQuietEnable = false;
|
||||||
|
|
||||||
private void registerForAirplaneMode(IntentFilter filter) {
|
private void registerForAirplaneMode(IntentFilter filter) {
|
||||||
final ContentResolver resolver = mContext.getContentResolver();
|
final ContentResolver resolver = mContext.getContentResolver();
|
||||||
@@ -105,7 +107,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
} else {
|
} else {
|
||||||
if (isBluetoothPersistedStateOn()) {
|
if (isBluetoothPersistedStateOn()) {
|
||||||
// enable without persisting the setting
|
// enable without persisting the setting
|
||||||
handleEnable(false);
|
handleEnable(false, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -269,7 +271,32 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
Message msg = mHandler.obtainMessage(MESSAGE_GET_NAME_AND_ADDRESS);
|
Message msg = mHandler.obtainMessage(MESSAGE_GET_NAME_AND_ADDRESS);
|
||||||
mHandler.sendMessage(msg);
|
mHandler.sendMessage(msg);
|
||||||
}
|
}
|
||||||
|
public boolean enableNoAutoConnect()
|
||||||
|
{
|
||||||
|
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
|
||||||
|
"Need BLUETOOTH ADMIN permission");
|
||||||
|
if (DBG) {
|
||||||
|
Log.d(TAG,"enableNoAutoConnect(): mBluetooth =" + mBluetooth +
|
||||||
|
" mBinding = " + mBinding);
|
||||||
|
}
|
||||||
|
if (Binder.getCallingUid() != android.os.Process.NFC_UID) {
|
||||||
|
throw new SecurityException("no permission to enable Bluetooth quietly");
|
||||||
|
}
|
||||||
|
synchronized(mConnection) {
|
||||||
|
if (mBinding) {
|
||||||
|
Log.w(TAG,"enableNoAutoConnect(): binding in progress. Returning..");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (mConnection == null) mBinding = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Message msg = mHandler.obtainMessage(MESSAGE_ENABLE);
|
||||||
|
msg.arg1=0; //No persist
|
||||||
|
msg.arg2=1; //Quiet mode
|
||||||
|
mHandler.sendMessage(msg);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
public boolean enable() {
|
public boolean enable() {
|
||||||
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
|
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
|
||||||
"Need BLUETOOTH ADMIN permission");
|
"Need BLUETOOTH ADMIN permission");
|
||||||
@@ -288,6 +315,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
|
|
||||||
Message msg = mHandler.obtainMessage(MESSAGE_ENABLE);
|
Message msg = mHandler.obtainMessage(MESSAGE_ENABLE);
|
||||||
msg.arg1=1; //persist
|
msg.arg1=1; //persist
|
||||||
|
msg.arg2=0; //No Quiet Mode
|
||||||
mHandler.sendMessage(msg);
|
mHandler.sendMessage(msg);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -501,7 +529,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
Log.d(TAG, "MESSAGE_ENABLE: mBluetooth = " + mBluetooth);
|
Log.d(TAG, "MESSAGE_ENABLE: mBluetooth = " + mBluetooth);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleEnable(msg.arg1 == 1);
|
handleEnable(msg.arg1 == 1, msg.arg2 ==1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MESSAGE_DISABLE:
|
case MESSAGE_DISABLE:
|
||||||
@@ -574,14 +602,21 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
|
|
||||||
//Do enable request
|
//Do enable request
|
||||||
try {
|
try {
|
||||||
if(!mBluetooth.enable()) {
|
if (mQuietEnable == false) {
|
||||||
Log.e(TAG,"IBluetooth.enable() returned false");
|
if(!mBluetooth.enable()) {
|
||||||
|
Log.e(TAG,"IBluetooth.enable() returned false");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(!mBluetooth.enableNoAutoConnect()) {
|
||||||
|
Log.e(TAG,"IBluetooth.enableNoAutoConnect() returned false");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.e(TAG,"Unable to call enable()",e);
|
Log.e(TAG,"Unable to call enable()",e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MESSAGE_TIMEOUT_BIND: {
|
case MESSAGE_TIMEOUT_BIND: {
|
||||||
@@ -637,11 +672,13 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private void handleEnable(boolean persist) {
|
private void handleEnable(boolean persist, boolean quietMode) {
|
||||||
if (persist) {
|
if (persist) {
|
||||||
persistBluetoothSetting(true);
|
persistBluetoothSetting(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mQuietEnable = quietMode;
|
||||||
|
|
||||||
synchronized(mConnection) {
|
synchronized(mConnection) {
|
||||||
if (mBluetooth == null) {
|
if (mBluetooth == null) {
|
||||||
//Start bind timeout and bind
|
//Start bind timeout and bind
|
||||||
@@ -664,8 +701,15 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
|
|
||||||
//Enable bluetooth
|
//Enable bluetooth
|
||||||
try {
|
try {
|
||||||
if(!mBluetooth.enable()) {
|
if (!mQuietEnable) {
|
||||||
Log.e(TAG,"IBluetooth.enable() returned false");
|
if(!mBluetooth.enable()) {
|
||||||
|
Log.e(TAG,"IBluetooth.enable() returned false");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(!mBluetooth.enableNoAutoConnect()) {
|
||||||
|
Log.e(TAG,"IBluetooth.enableNoAutoConnect() returned false");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.e(TAG,"Unable to call enable()",e);
|
Log.e(TAG,"Unable to call enable()",e);
|
||||||
|
|||||||
Reference in New Issue
Block a user