Merge "Honor Ble scanning settings from Settings UI." into mnc-dev

This commit is contained in:
Wei Wang
2015-05-01 05:10:17 +00:00
committed by Android (Google) Code Review
3 changed files with 22 additions and 22 deletions

View File

@@ -34,6 +34,7 @@ import android.os.RemoteException;
import android.os.ServiceManager; import android.os.ServiceManager;
import android.app.ActivityThread; import android.app.ActivityThread;
import android.os.SystemProperties; import android.os.SystemProperties;
import android.provider.Settings;
import android.os.Binder; import android.os.Binder;
import android.util.Log; import android.util.Log;
import android.util.Pair; import android.util.Pair;
@@ -631,24 +632,6 @@ public final class BluetoothAdapter {
} }
} }
/**
* Returns true if LE only mode is enabled, that is apps
* have authorization to turn only BT ON and the calling
* app has privilage to do so
*/
private boolean isLEAlwaysOnEnabled() {
boolean ret = false;
if (SystemProperties.getBoolean("ro.bluetooth.blealwayson", true) == true) {
Log.v(TAG, "LE always on mode is enabled");
// TODO: System API authorization check
ret = true;
} else {
Log.v(TAG, "LE always on mode is disabled");
ret = false;
}
return ret;
}
/** /**
* Turns off Bluetooth LE which was earlier turned on by calling EnableBLE(). * Turns off Bluetooth LE which was earlier turned on by calling EnableBLE().
* *
@@ -676,7 +659,7 @@ public final class BluetoothAdapter {
* @hide * @hide
*/ */
public boolean disableBLE() { public boolean disableBLE() {
if (isLEAlwaysOnEnabled() != true) return false; if (!isBleScanAlwaysAvailable()) return false;
int state = getLeState(); int state = getLeState();
if (state == BluetoothAdapter.STATE_ON) { if (state == BluetoothAdapter.STATE_ON) {
@@ -738,7 +721,7 @@ public final class BluetoothAdapter {
* @hide * @hide
*/ */
public boolean enableBLE() { public boolean enableBLE() {
if (isLEAlwaysOnEnabled() != true) return false; if (!isBleScanAlwaysAvailable()) return false;
if (isLeEnabled() == true) { if (isLeEnabled() == true) {
if (DBG) Log.d(TAG, "enableBLE(): BT is already enabled..!"); if (DBG) Log.d(TAG, "enableBLE(): BT is already enabled..!");
@@ -1243,9 +1226,13 @@ public final class BluetoothAdapter {
*/ */
@SystemApi @SystemApi
public boolean isBleScanAlwaysAvailable() { public boolean isBleScanAlwaysAvailable() {
// TODO: implement after Settings UI change. try {
return mManagerService.isBleScanAlwaysAvailable();
} catch (RemoteException e) {
Log.e(TAG, "remote expection when calling isBleScanAlwaysAvailable", e);
return false; return false;
} }
}
/** /**
* Returns whether peripheral mode is supported. * Returns whether peripheral mode is supported.

View File

@@ -44,6 +44,8 @@ interface IBluetoothManager
String getAddress(); String getAddress();
String getName(); String getName();
boolean isBleScanAlwaysAvailable();
int updateBleAppCount(IBinder b, boolean enable); int updateBleAppCount(IBinder b, boolean enable);
boolean isBleAppPresent(); boolean isBleAppPresent();
} }

View File

@@ -48,6 +48,7 @@ import android.os.SystemClock;
import android.os.UserHandle; import android.os.UserHandle;
import android.os.UserManager; import android.os.UserManager;
import android.provider.Settings; import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import android.util.Log; import android.util.Log;
import java.io.FileDescriptor; import java.io.FileDescriptor;
@@ -443,6 +444,16 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
/** Internal death rec list */ /** Internal death rec list */
Map<IBinder, ClientDeathRecipient> mBleApps = new HashMap<IBinder, ClientDeathRecipient>(); Map<IBinder, ClientDeathRecipient> mBleApps = new HashMap<IBinder, ClientDeathRecipient>();
@Override
public boolean isBleScanAlwaysAvailable() {
try {
return (Settings.Global.getInt(mContentResolver,
Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE)) != 0;
} catch (SettingNotFoundException e) {
}
return false;
}
public int updateBleAppCount(IBinder token, boolean enable) { public int updateBleAppCount(IBinder token, boolean enable) {
if (enable) { if (enable) {
ClientDeathRecipient r = mBleApps.get(token); ClientDeathRecipient r = mBleApps.get(token);