OSDN Git Service

send broadcast intents to voice search for logging purposes
authorLeon Scroggins <scroggo@google.com>
Tue, 9 Feb 2010 20:31:26 +0000 (15:31 -0500)
committerLeon Scroggins <scroggo@google.com>
Tue, 9 Feb 2010 21:29:17 +0000 (16:29 -0500)
Fix for http://b/issue?id=2390720

src/com/android/browser/BrowserActivity.java
src/com/android/browser/Tab.java
src/com/android/browser/TitleBar.java

index ebb5246..864d688 100644 (file)
@@ -111,6 +111,7 @@ import android.accounts.OperationCanceledException;
 import android.accounts.AccountManagerCallback;
 
 import com.android.common.Patterns;
+import com.android.common.speech.LoggingEvents;
 
 import com.google.android.gsf.GoogleLoginServiceConstants;
 
@@ -487,6 +488,20 @@ public class BrowserActivity extends Activity
                     // search, so do nothing.
                     return;
                 }
+                if (Intent.ACTION_SEARCH.equals(action)
+                        && current.voiceSearchSourceIsGoogle()) {
+                    Intent logIntent = new Intent(
+                            LoggingEvents.ACTION_LOG_EVENT);
+                    logIntent.putExtra(LoggingEvents.EXTRA_EVENT,
+                            LoggingEvents.VoiceSearch.QUERY_UPDATED);
+                    logIntent.putExtra(
+                            LoggingEvents.VoiceSearch.EXTRA_QUERY_UPDATED_VALUE,
+                            intent.getDataString());
+                    sendBroadcast(logIntent);
+                    // Note, onPageStarted will revert the voice title bar
+                    // When http://b/issue?id=2379215 is fixed, we should update
+                    // the title bar here.
+                }
             }
             // If this was a search request (e.g. search query directly typed into the address bar),
             // pass it on to the default web search provider.
index 3c8f5ba..afd9b09 100644 (file)
@@ -65,6 +65,8 @@ import android.widget.ImageButton;
 import android.widget.LinearLayout;
 import android.widget.TextView;
 
+import com.android.common.speech.LoggingEvents;
+
 /**
  * Class for maintaining Tabs with a main WebView and a subwindow.
  */
@@ -158,6 +160,13 @@ class Tab {
         return mVoiceSearchData != null;
     }
     /**
+     * Return true if the voice search Intent came with a String identifying
+     * that Google provided the Intent.
+     */
+    public boolean voiceSearchSourceIsGoogle() {
+        return mVoiceSearchData != null && mVoiceSearchData.mSourceIsGoogle;
+    }
+    /**
      * Get the title to display for the current voice search page.  If the Tab
      * is not in voice search mode, return null.
      */
@@ -205,6 +214,8 @@ class Tab {
             }
             mVoiceSearchData = new VoiceSearchData(results, urls, htmls,
                     baseUrls);
+            mVoiceSearchData.mSourceIsGoogle = intent.getBooleanExtra(
+                    VoiceSearchData.SOURCE_IS_GOOGLE, false);
         } else {
             String extraData = intent.getStringExtra(
                     SearchManager.EXTRA_DATA_KEY);
@@ -214,6 +225,16 @@ class Tab {
                     throw new AssertionError("index must be less than "
                             + " size of mVoiceSearchResults");
                 }
+                if (mVoiceSearchData.mSourceIsGoogle) {
+                    Intent logIntent = new Intent(
+                            LoggingEvents.ACTION_LOG_EVENT);
+                    logIntent.putExtra(LoggingEvents.EXTRA_EVENT,
+                            LoggingEvents.VoiceSearch.N_BEST_CHOOSE);
+                    logIntent.putExtra(
+                            LoggingEvents.VoiceSearch.EXTRA_N_BEST_CHOOSE_INDEX,
+                            index);
+                    mActivity.sendBroadcast(logIntent);
+                }
             }
         }
         mVoiceSearchData.mLastVoiceSearchTitle
@@ -292,6 +313,16 @@ class Tab {
          * when switching tabs.
          */
         public String mLastVoiceSearchTitle;
+        /**
+         * Whether the Intent which turned on voice search mode contained the
+         * String signifying that Google was the source.
+         */
+        public boolean mSourceIsGoogle;
+        /**
+         * String used to identify Google as the source of voice search.
+         */
+        public static String SOURCE_IS_GOOGLE
+                = "android.speech.extras.SOURCE_IS_GOOGLE";
     }
 
     // Container class for the next error dialog that needs to be displayed
@@ -373,6 +404,11 @@ class Tab {
             mLoadStartTime = SystemClock.uptimeMillis();
             if (mVoiceSearchData != null
                     && !url.equals(mVoiceSearchData.mLastVoiceSearchUrl)) {
+                if (mVoiceSearchData.mSourceIsGoogle) {
+                    Intent i = new Intent(LoggingEvents.ACTION_LOG_EVENT);
+                    i.putExtra(LoggingEvents.EXTRA_FLUSH, true);
+                    mActivity.sendBroadcast(i);
+                }
                 mVoiceSearchData = null;
                 if (mInForeground) {
                     mActivity.revertVoiceTitleBar();
index 14ac2ae..844d5a1 100644 (file)
@@ -48,6 +48,8 @@ import android.widget.LinearLayout;
 import android.widget.ProgressBar;
 import android.widget.TextView;
 
+import com.android.common.speech.LoggingEvents;
+
 /**
  * This class represents a title bar for a particular "tab" or "window" in the
  * browser.
@@ -189,6 +191,14 @@ public class TitleBar extends LinearLayout {
             case MotionEvent.ACTION_UP:
                 if (mRtButton.isPressed()) {
                     if (mInVoiceMode) {
+                        if (mBrowserActivity.getTabControl().getCurrentTab()
+                                .voiceSearchSourceIsGoogle()) {
+                            Intent i = new Intent(
+                                    LoggingEvents.ACTION_LOG_EVENT);
+                            i.putExtra(LoggingEvents.EXTRA_EVENT,
+                                    LoggingEvents.VoiceSearch.RETRY);
+                            mBrowserActivity.sendBroadcast(i);
+                        }
                         mBrowserActivity.startActivity(mVoiceSearchIntent);
                     } else if (mInLoad) {
                         mBrowserActivity.stopLoading();
@@ -199,6 +209,14 @@ public class TitleBar extends LinearLayout {
                 } else if (mTitleBg.isPressed()) {
                     mHandler.removeMessages(LONG_PRESS);
                     if (mInVoiceMode) {
+                        if (mBrowserActivity.getTabControl().getCurrentTab()
+                                .voiceSearchSourceIsGoogle()) {
+                            Intent i = new Intent(
+                                    LoggingEvents.ACTION_LOG_EVENT);
+                            i.putExtra(LoggingEvents.EXTRA_EVENT,
+                                    LoggingEvents.VoiceSearch.N_BEST_REVEAL);
+                            mBrowserActivity.sendBroadcast(i);
+                        }
                         mBrowserActivity.showVoiceSearchResults(
                                 mTitle.getText().toString().trim());
                     } else {