diff options
author | Linux Build Service Account <lnxbuild@localhost> | 2014-12-13 09:15:59 -0800 |
---|---|---|
committer | Gerrit - the friendly Code Review server <code-review@localhost> | 2014-12-13 09:15:59 -0800 |
commit | 27046f3c6fdd6cee14e4e41af837fba2b0eaeafd (patch) | |
tree | b7df4cb92880db5656f8f1ac48dcc1867aa6490e | |
parent | 2a735e3137d1bc354b349050101241d30af1efb9 (diff) | |
parent | c059805fd638c5a3a72cf158cd35d64c588db2ee (diff) | |
download | android_packages_apps_BluetoothExt-27046f3c6fdd6cee14e4e41af837fba2b0eaeafd.tar.gz android_packages_apps_BluetoothExt-27046f3c6fdd6cee14e4e41af837fba2b0eaeafd.tar.bz2 android_packages_apps_BluetoothExt-27046f3c6fdd6cee14e4e41af837fba2b0eaeafd.zip |
Merge "Bluetooh-Wipower: Fix for delayed advertisments."
-rw-r--r-- | src/org/codeaurora/bluetooth/a4wp/A4wpService.java | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/src/org/codeaurora/bluetooth/a4wp/A4wpService.java b/src/org/codeaurora/bluetooth/a4wp/A4wpService.java index e766fdc..b62f740 100644 --- a/src/org/codeaurora/bluetooth/a4wp/A4wpService.java +++ b/src/org/codeaurora/bluetooth/a4wp/A4wpService.java @@ -59,6 +59,10 @@ import android.wipower.WipowerManager.PowerLevel; import android.wipower.WipowerDynamicParam; import com.quicinc.wbc.WbcManager; import com.quicinc.wbc.WbcTypes; +import android.os.Handler; +import android.os.HandlerThread; +import android.os.Looper; +import android.os.Message; import android.bluetooth.le.AdvertiseCallback; import android.bluetooth.le.AdvertiseSettings; @@ -80,6 +84,11 @@ public class A4wpService extends Service private BluetoothDevice mDevice = null; private PowerManager.WakeLock mWakeLock = null; + // Advertising variables + private final static int START_ADVERTISING = 1; + private final static int STOP_ADVERTISING = 0; + private WipowerAdvHandler mHandler; + private static final UUID A4WP_SERVICE_UUID = UUID.fromString("6455fffe-a146-11e2-9e96-0800200c9a67"); //PRU writes private static final UUID A4WP_PRU_CTRL_UUID = UUID.fromString("6455e670-a146-11e2-9e96-0800200c9a67"); @@ -144,6 +153,25 @@ public class A4wpService extends Service private AdvertiseCallback mAdvertiseCallback = new myAdvertiseCallback(1); ParcelUuid uuid1 = ParcelUuid.fromString("6455fffe-a146-11e2-9e96-0800200c9a67"); + // Handler to maintain advertisement messages + private final class WipowerAdvHandler extends Handler { + private WipowerAdvHandler(Looper looper) { + super(looper); + } + + @Override + public void handleMessage(Message msg) { + switch (msg.what) { + case START_ADVERTISING: + StartAdvertising(); + break; + case STOP_ADVERTISING: + stopAdvertising(); + break; + } + } + } + private WbcManager.WbcEventListener mWbcCallback = new WbcManager.WbcEventListener() { @Override @@ -571,7 +599,9 @@ public class A4wpService extends Service Log.v(LOGTAG, "onPowerApply" + state); if (state == PowerApplyEvent.ON) { Log.v(LOGTAG, "StartAdvertising"); - StartAdvertising(); + Message msg = mHandler.obtainMessage(START_ADVERTISING); + mHandler.sendMessage(msg); + } else { Log.v(LOGTAG, "Cancel connection as part of -" + state); if (mBluetoothGattServer != null) { @@ -892,6 +922,11 @@ public class A4wpService extends Service Log.v(LOGTAG, "onCreate: charge complete " + mChargeComplete); mWbcManager.register(mWbcCallback); } + // Starting a thread to handle the advertising + HandlerThread thread = new HandlerThread("WipowerAdvHandler"); + thread.start(); + Looper looper = thread.getLooper(); + mHandler = new WipowerAdvHandler(looper); } @Override @@ -905,6 +940,11 @@ public class A4wpService extends Service //release wake lock during BT-OFF. acquire_wake_lock(false); } + // Clear thread on destroy + Looper looper = mHandler.getLooper(); + if (looper != null) { + looper.quit(); + } } @Override |