Fix Bug 2835657

If the bluetooth voicedialer was used while the
lock screen was up, it would sometimes get stuck
trying to keep the confirmation utterance.  This
is fixed by holding a wakelock as long as the
BluetoothVoiceDialerActivity is present.

Change-Id: I8f07c5a7a6720d2bd36dfdc105ce95979699de6b
diff --git a/src/com/android/voicedialer/BluetoothVoiceDialerActivity.java b/src/com/android/voicedialer/BluetoothVoiceDialerActivity.java
index 420ea8f..bbcb9ba 100644
--- a/src/com/android/voicedialer/BluetoothVoiceDialerActivity.java
+++ b/src/com/android/voicedialer/BluetoothVoiceDialerActivity.java
@@ -41,6 +41,9 @@
 import java.io.InputStream;
 import java.util.HashMap;
 
+import android.os.PowerManager;
+import android.os.PowerManager.WakeLock;
+
 /**
  * TODO: get rid of the anonymous classes
  *
@@ -168,6 +171,8 @@
     private AlertDialog mAlertDialog;
     private Runnable mFallbackRunnable;
 
+    private WakeLock mWakeLock;
+
     @Override
     protected void onCreate(Bundle icicle) {
         if (Config.LOGD) Log.d(TAG, "onCreate");
@@ -182,6 +187,8 @@
         if (Config.LOGD) Log.d(TAG, "onStart " + getIntent());
         super.onStart();
 
+        acquireWakeLock(this);
+
         mState = INITIALIZING;
         mChosenAction = null;
         mAudioManager.requestAudioFocus(
@@ -907,11 +914,28 @@
 
         super.onStop();
 
+        releaseWakeLock();
+
         // It makes no sense to have this activity maintain state when in
         // background.  When it stops, it should just be destroyed.
         finish();
     }
 
+    private void acquireWakeLock(Context context) {
+        if (mWakeLock == null) {
+            PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
+            mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "BluetoothVoiceDialer");
+            mWakeLock.acquire();
+        }
+    }
+
+    private void releaseWakeLock() {
+        if (mWakeLock != null) {
+            mWakeLock.release();
+            mWakeLock = null;
+        }
+    }
+
     private Runnable mMicFlasher = new Runnable() {
         int visible = View.VISIBLE;
 
@@ -928,4 +952,4 @@
         if (Config.LOGD) Log.d(TAG, "onDestroy");
         super.onDestroy();
     }
-}
\ No newline at end of file
+}