diff options
| author | Jim Tan <jimtan@google.com> | 2017-02-23 11:27:12 -0800 |
|---|---|---|
| committer | Jim Tan <jimtan@google.com> | 2017-02-27 20:49:14 +0000 |
| commit | ca0b3497c93456c547da1b472d9e221ab8a13cbe (patch) | |
| tree | 25afdd17b80fa6b0ae23d5ab334f1a9acec3c95c | |
| parent | e3b655fbaec4c8d80d51f1a5f0e275a065c88f34 (diff) | |
| download | platform_packages_apps_Test_connectivity-o-preview.tar.gz platform_packages_apps_Test_connectivity-o-preview.tar.bz2 platform_packages_apps_Test_connectivity-o-preview.zip | |
Add code to enable Bluetooth if not enabledandroid-o-preview-1android-n-mr2-preview-2o-preview
Add code to enable Bluetooth if not enabled.
Add some checks for null points and change some bad variable names.
Change the default volume for MediaPlayer to 0.30 since 0.50 is too loud.
Test: None
Bug: 35708388
Change-Id: I424332d3f2faa8673c1a511cb48374061e3f3375
| -rw-r--r-- | PMC/src/com/android/pmc/A2dpReceiver.java | 5 | ||||
| -rw-r--r-- | PMC/src/com/android/pmc/BleScanReceiver.java | 12 | ||||
| -rw-r--r-- | PMC/src/com/android/pmc/GattClientListener.java | 32 | ||||
| -rw-r--r-- | PMC/src/com/android/pmc/GattServer.java | 20 |
4 files changed, 49 insertions, 20 deletions
diff --git a/PMC/src/com/android/pmc/A2dpReceiver.java b/PMC/src/com/android/pmc/A2dpReceiver.java index 0de2cc5..7c10157 100644 --- a/PMC/src/com/android/pmc/A2dpReceiver.java +++ b/PMC/src/com/android/pmc/A2dpReceiver.java @@ -52,7 +52,7 @@ public class A2dpReceiver extends BroadcastReceiver { public static final int START_PLAY = 1; public static final int PAUSE_PLAY = 2; public static final int STOP_PLAY = 3; - public static final float NORMAL_VOLUME = 0.5f; + public static final float NORMAL_VOLUME = 0.3f; public static final float ZERO_VOLUME = 0.0f; private final Context mContext; @@ -330,6 +330,9 @@ public class A2dpReceiver extends BroadcastReceiver { Log.v(TAG, "Before Start Play"); mPlayer.start(); mPlayer.setLooping(true); + if (!mPlayer.isPlaying()) { + Log.e(TAG, "Media Player is not playing"); + } startAlarm(mPlayTime, intent); } else if (action == PAUSE_PLAY) { Log.v(TAG, "Before Pause play"); diff --git a/PMC/src/com/android/pmc/BleScanReceiver.java b/PMC/src/com/android/pmc/BleScanReceiver.java index a682e58..bd090a2 100644 --- a/PMC/src/com/android/pmc/BleScanReceiver.java +++ b/PMC/src/com/android/pmc/BleScanReceiver.java @@ -81,15 +81,21 @@ public class BleScanReceiver extends BroadcastReceiver { */ public BleScanListener() { BluetoothAdapter bleAdaptor = BluetoothAdapter.getDefaultAdapter(); + if (bleAdaptor == null) { - Log.e(TAG, "BleAdaptor is Null"); + Log.e(TAG, "BluetoothAdapter is Null"); return; } else { if (!bleAdaptor.isEnabled()) { - Log.e(TAG, "BleAdaptor is NOT enabled"); - return; + Log.d(TAG, "BluetoothAdapter is NOT enabled, enable now"); + bleAdaptor.enable(); + if (!bleAdaptor.isEnabled()) { + Log.e(TAG, "Can't enable Bluetooth"); + return; + } } } + mBleScanner = bleAdaptor.getBluetoothLeScanner(); mScanFilterList = new ArrayList<ScanFilter>(); } diff --git a/PMC/src/com/android/pmc/GattClientListener.java b/PMC/src/com/android/pmc/GattClientListener.java index 4434e84..428149c 100644 --- a/PMC/src/com/android/pmc/GattClientListener.java +++ b/PMC/src/com/android/pmc/GattClientListener.java @@ -59,7 +59,7 @@ public class GattClientListener extends BroadcastReceiver { private BluetoothGatt mBluetoothGatt; private GattCallback mGattCallback; - private MyBleScanner mBleScanner; + private MyBleScanner mMyBleScanner; private String mMacAddress; private BluetoothDevice mDevice; private int mWriteTime; @@ -75,17 +75,22 @@ public class GattClientListener extends BroadcastReceiver { mContext = context; mAlarmManager = alarmManager; mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); + if (mBluetoothAdapter == null) { - Log.e(TAG, "BleAdaptor is Null"); + Log.e(TAG, "BluetoothAdapter is Null"); return; } else { if (!mBluetoothAdapter.isEnabled()) { - Log.d(TAG, "BleAdaptor is NOT enabled, enable now"); + Log.d(TAG, "BluetoothAdapter is NOT enabled, enable now"); mBluetoothAdapter.enable(); + if (!mBluetoothAdapter.isEnabled()) { + Log.e(TAG, "Can't enable Bluetooth"); + return; + } } } - mBleScanner = new MyBleScanner(mBluetoothAdapter); + mMyBleScanner = new MyBleScanner(mBluetoothAdapter); mGattCallback = new GattCallback(); mBluetoothGatt = null; mMacAddress = null; @@ -107,7 +112,7 @@ public class GattClientListener extends BroadcastReceiver { if (intent == null) { // Start Scan here when this func is called for the first time - mBleScanner.startScan(); + mMyBleScanner.startScan(); mWriteTime = writeTime; mIdleTime = idleTime; mCycles = numCycles; @@ -145,7 +150,7 @@ public class GattClientListener extends BroadcastReceiver { return; } - if (mMacAddress == null) mMacAddress = mBleScanner.getAdvMacAddress(); + if (mMacAddress == null) mMacAddress = mMyBleScanner.getAdvMacAddress(); if (mMacAddress == null || mMacAddress.isEmpty()) { Log.e(TAG, "Remote device Mac Address is not set"); return; @@ -323,21 +328,30 @@ public class GattClientListener extends BroadcastReceiver { */ public void startScan() { // Start Scan here when this func is called for the first time - mBLEScanner.startScan(mScanFilterList, mScanSettings, mScanCallback); + if (mBLEScanner != null) { + mBLEScanner.startScan(mScanFilterList, mScanSettings, mScanCallback); + } else { + Log.e(TAG, "BLEScanner is null"); + } + } /** * Wrapper function to stop BLE Scanning */ public void stopScan() { - mBLEScanner.stopScan(mScanCallback); + if (mBLEScanner != null) { + mBLEScanner.stopScan(mScanCallback); + } else { + Log.e(TAG, "BLEScanner is null"); + } } /** * function to get Mac Address for BLE Advertiser device */ public String getAdvMacAddress() { - // wait to get Mac Address for Ble Advertiser + // Return Mac address for Advertiser device return mAdvMacAddress; } diff --git a/PMC/src/com/android/pmc/GattServer.java b/PMC/src/com/android/pmc/GattServer.java index 6af9fde..9e88364 100644 --- a/PMC/src/com/android/pmc/GattServer.java +++ b/PMC/src/com/android/pmc/GattServer.java @@ -61,16 +61,22 @@ public class GattServer { public GattServer(Context context) { mContext = context; // Check if Bluetooth is enabled - BluetoothAdapter betoothAdapter = BluetoothAdapter.getDefaultAdapter(); - if (betoothAdapter == null) { - Log.e(TAG, "BleAdaptor is Null"); + BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); + + if (bluetoothAdapter == null) { + Log.e(TAG, "BluetoothAdapter is Null"); return; } else { - if (!betoothAdapter.isEnabled()) { - Log.d(TAG, "BleAdaptor is NOT enabled, enable now"); - betoothAdapter.enable(); + if (!bluetoothAdapter.isEnabled()) { + Log.d(TAG, "BluetoothAdapter is NOT enabled, enable now"); + bluetoothAdapter.enable(); + if (!bluetoothAdapter.isEnabled()) { + Log.e(TAG, "Can't enable Bluetooth"); + return; + } } } + // Prepare data for GATT service mBluetoothManager = (BluetoothManager) context.getSystemService( Service.BLUETOOTH_SERVICE); @@ -95,7 +101,7 @@ public class GattServer { mGattService.addCharacteristic(characteristic); // Create BLE Advertiser object - mBleAdvertiser = new MyBleAdvertiser(betoothAdapter); + mBleAdvertiser = new MyBleAdvertiser(bluetoothAdapter); Log.d(TAG, "Construstor finished"); } |
