1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16
17package com.android.common.userhappiness;
18
19import android.content.Intent;
20import android.content.Context;
21import com.android.common.speech.LoggingEvents;
22
23/**
24 * Metrics for User Happiness are recorded here. Each app can define when to
25 * call these User Happiness metrics.
26 */
27public class UserHappinessSignals {
28    // So that we don't send logging events to VoiceSearch when there is nothing to
29    // log, IME will setHasVoiceLoggingInfo if there has been any voice activity,
30    // such as recognition results returned.
31    private static boolean mHasVoiceLoggingInfo = false;
32
33   /**
34    *  Record whether or not there has been Voice-Input activity which
35    *  needs to be logged. This is called with a value of true by the IME,
36    *  when logging events (such as VoiceInputDelivered) occur, and is should
37    *  be set to false after the logging broadcast is sent.
38    */
39    public static void setHasVoiceLoggingInfo(boolean hasVoiceLogging) {
40        mHasVoiceLoggingInfo = hasVoiceLogging;
41    }
42
43    /**
44     *  Log when a user "accepted" IME text. Each application can define what
45     *  it means to "accept" text. In the case of Gmail, pressing the "Send"
46     *  button indicates text acceptance. We broadcast this information to
47     *  VoiceSearch LoggingEvents and use it to aggregate VoiceIME Happiness Metrics
48     */
49    public static void userAcceptedImeText(Context context) {
50        // Create a Voice IME Logging intent only if there are logging actions
51        if (mHasVoiceLoggingInfo) {
52            Intent i = new Intent(LoggingEvents.ACTION_LOG_EVENT);
53            i.putExtra(LoggingEvents.EXTRA_APP_NAME, LoggingEvents.VoiceIme.APP_NAME);
54            i.putExtra(LoggingEvents.EXTRA_EVENT, LoggingEvents.VoiceIme.IME_TEXT_ACCEPTED);
55            i.putExtra(LoggingEvents.EXTRA_CALLING_APP_NAME, context.getPackageName());
56            i.putExtra(LoggingEvents.EXTRA_TIMESTAMP, System.currentTimeMillis());
57            context.sendBroadcast(i);
58            setHasVoiceLoggingInfo(false);
59        }
60    }
61
62}
63