summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSandeep Siddhartha <sansid@google.com>2014-06-10 12:32:53 -0700
committerSandeep Siddhartha <sansid@google.com>2014-06-11 15:34:39 -0700
commit22968950b814e66a6aa119ea92ae648884cbe0d9 (patch)
treecc21b57d32cbc30c3b008893ce10be519168bcb9
parente912ac012e7146e9b0e8589bd9d88790e55372e3 (diff)
Activity for enrollment
- Make the enrollment attrs public - Add a dummy activity for enrollment - Manually tested that the meta-data is correctly read by the VoiceInteractionService when the enrollment application is under /system/priv-app Change-Id: I36676ed8ffc919109031c26bac047d0c51a77e13
-rw-r--r--api/current.txt3
-rw-r--r--core/java/android/service/voice/KeyphraseEnrollmentInfo.java26
-rw-r--r--core/java/android/service/voice/KeyphraseInfo.java5
-rw-r--r--core/java/android/service/voice/VoiceInteractionService.java10
-rw-r--r--core/res/res/values/public.xml3
-rw-r--r--tests/VoiceEnrollment/Android.mk12
-rw-r--r--tests/VoiceEnrollment/AndroidManifest.xml16
-rw-r--r--tests/VoiceEnrollment/res/xml/enrollment_application.xml23
-rw-r--r--tests/VoiceEnrollment/src/com/android/test/voiceenrollment/TestEnrollmentActivity.java23
-rw-r--r--tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionService.java5
10 files changed, 118 insertions, 8 deletions
diff --git a/api/current.txt b/api/current.txt
index a091f1a45912..6fcd249caeee 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -1002,6 +1002,9 @@ package android {
field public static final int scrollbars = 16842974; // 0x10100de
field public static final int scrollingCache = 16843006; // 0x10100fe
field public static final deprecated int searchButtonText = 16843269; // 0x1010205
+ field public static final int searchKeyphrase = 16843874; // 0x1010462
+ field public static final int searchKeyphraseId = 16843873; // 0x1010461
+ field public static final int searchKeyphraseSupportedLocales = 16843875; // 0x1010463
field public static final int searchMode = 16843221; // 0x10101d5
field public static final int searchSettingsDescription = 16843402; // 0x101028a
field public static final int searchSuggestAuthority = 16843222; // 0x10101d6
diff --git a/core/java/android/service/voice/KeyphraseEnrollmentInfo.java b/core/java/android/service/voice/KeyphraseEnrollmentInfo.java
index 3af8054eadf6..ebe41ce43ef6 100644
--- a/core/java/android/service/voice/KeyphraseEnrollmentInfo.java
+++ b/core/java/android/service/voice/KeyphraseEnrollmentInfo.java
@@ -25,7 +25,7 @@ import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.util.AttributeSet;
-import android.util.Log;
+import android.util.Slog;
import android.util.Xml;
import org.xmlpull.v1.XmlPullParser;
@@ -93,18 +93,20 @@ public class KeyphraseEnrollmentInfo {
if ((ai.flags & ApplicationInfo.FLAG_PRIVILEGED) == 0) {
// The application isn't privileged (/system/priv-app).
// The enrollment application needs to be a privileged system app.
+ Slog.w(TAG, ai.packageName + "is not a privileged system app");
continue;
}
if (!Manifest.permission.MANAGE_VOICE_KEYPHRASES.equals(ai.permission)) {
// The application trying to manage keyphrases doesn't
// require the MANAGE_VOICE_KEYPHRASES permission.
+ Slog.w(TAG, ai.packageName + " does not require MANAGE_VOICE_KEYPHRASES");
continue;
}
mEnrollmentPackage = ai.packageName;
found = true;
break;
} catch (PackageManager.NameNotFoundException e) {
- Log.w(TAG, "error parsing voice enrollment meta-data", e);
+ Slog.w(TAG, "error parsing voice enrollment meta-data", e);
}
}
@@ -163,15 +165,15 @@ public class KeyphraseEnrollmentInfo {
}
} catch (XmlPullParserException e) {
mParseError = "Error parsing keyphrase enrollment meta-data: " + e;
- Log.w(TAG, "error parsing keyphrase enrollment meta-data", e);
+ Slog.w(TAG, "error parsing keyphrase enrollment meta-data", e);
return;
} catch (IOException e) {
mParseError = "Error parsing keyphrase enrollment meta-data: " + e;
- Log.w(TAG, "error parsing keyphrase enrollment meta-data", e);
+ Slog.w(TAG, "error parsing keyphrase enrollment meta-data", e);
return;
} catch (PackageManager.NameNotFoundException e) {
mParseError = "Error parsing keyphrase enrollment meta-data: " + e;
- Log.w(TAG, "error parsing keyphrase enrollment meta-data", e);
+ Slog.w(TAG, "error parsing keyphrase enrollment meta-data", e);
return;
} finally {
if (parser != null) parser.close();
@@ -183,6 +185,14 @@ public class KeyphraseEnrollmentInfo {
}
/**
+ * @return An array of available keyphrases that can be enrolled on the system.
+ * It may be null if no keyphrases can be enrolled.
+ */
+ public KeyphraseInfo[] getKeyphrases() {
+ return mKeyphrases;
+ }
+
+ /**
* Returns an intent to launch an activity that manages the given keyphrase
* for the locale.
*
@@ -194,7 +204,7 @@ public class KeyphraseEnrollmentInfo {
*/
public Intent getManageKeyphraseIntent(boolean enroll, String keyphrase, String locale) {
if (mEnrollmentPackage == null || mEnrollmentPackage.isEmpty()) {
- Log.w(TAG, "No enrollment application exists");
+ Slog.w(TAG, "No enrollment application exists");
return null;
}
@@ -218,7 +228,7 @@ public class KeyphraseEnrollmentInfo {
*/
public boolean isKeyphraseEnrollmentSupported(String keyphrase, String locale) {
if (mKeyphrases == null || mKeyphrases.length == 0) {
- Log.w(TAG, "Enrollment application doesn't support keyphrases");
+ Slog.w(TAG, "Enrollment application doesn't support keyphrases");
return false;
}
for (KeyphraseInfo keyphraseInfo : mKeyphrases) {
@@ -230,7 +240,7 @@ public class KeyphraseEnrollmentInfo {
return true;
}
}
- Log.w(TAG, "Enrollment application doesn't support the given keyphrase");
+ Slog.w(TAG, "Enrollment application doesn't support the given keyphrase");
return false;
}
}
diff --git a/core/java/android/service/voice/KeyphraseInfo.java b/core/java/android/service/voice/KeyphraseInfo.java
index 303aac453887..d266e1a24471 100644
--- a/core/java/android/service/voice/KeyphraseInfo.java
+++ b/core/java/android/service/voice/KeyphraseInfo.java
@@ -19,4 +19,9 @@ public class KeyphraseInfo {
this.supportedLocales.add(locale);
}
}
+
+ @Override
+ public String toString() {
+ return "id=" + id + ", keyphrase=" + keyphrase + ", supported-locales=" + supportedLocales;
+ }
}
diff --git a/core/java/android/service/voice/VoiceInteractionService.java b/core/java/android/service/voice/VoiceInteractionService.java
index 175a9682bd86..7c5d270f33d7 100644
--- a/core/java/android/service/voice/VoiceInteractionService.java
+++ b/core/java/android/service/voice/VoiceInteractionService.java
@@ -25,6 +25,7 @@ import android.os.IBinder;
import android.os.RemoteException;
import android.os.ServiceManager;
+import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.app.IVoiceInteractionManagerService;
/**
@@ -108,4 +109,13 @@ public class VoiceInteractionService extends Service {
return mDspInfo != null
&& mKeyphraseEnrollmentInfo.isKeyphraseEnrollmentSupported(keyphrase, locale);
}
+
+ /**
+ * @return Details of keyphrases available for enrollment.
+ * @hide
+ */
+ @VisibleForTesting
+ protected final KeyphraseEnrollmentInfo getKeyphraseEnrollmentInfo() {
+ return mKeyphraseEnrollmentInfo;
+ }
}
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index 16bba5b3fdb3..64d18c03d435 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -2186,6 +2186,9 @@
<public type="attr" name="translateY" />
<public type="attr" name="selectableItemBackgroundBorderless" />
<public type="attr" name="elegantTextHeight" />
+ <public type="attr" name="searchKeyphraseId" />
+ <public type="attr" name="searchKeyphrase" />
+ <public type="attr" name="searchKeyphraseSupportedLocales" />
<public-padding type="dimen" name="l_resource_pad" end="0x01050010" />
diff --git a/tests/VoiceEnrollment/Android.mk b/tests/VoiceEnrollment/Android.mk
new file mode 100644
index 000000000000..2ab3d029092f
--- /dev/null
+++ b/tests/VoiceEnrollment/Android.mk
@@ -0,0 +1,12 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(call all-subdir-java-files)
+
+LOCAL_PACKAGE_NAME := VoiceEnrollment
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_PRIVILEGED_MODULE := true
+
+include $(BUILD_PACKAGE)
diff --git a/tests/VoiceEnrollment/AndroidManifest.xml b/tests/VoiceEnrollment/AndroidManifest.xml
new file mode 100644
index 000000000000..6321222f6b1b
--- /dev/null
+++ b/tests/VoiceEnrollment/AndroidManifest.xml
@@ -0,0 +1,16 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.test.voiceenrollment">
+
+ <application
+ android:permission="android.permission.MANAGE_VOICE_KEYPHRASES">
+ <activity android:name="TestEnrollmentActivity" android:label="Voice Enrollment Application"
+ android:theme="@android:style/Theme.Material.Light.Voice">
+ <intent-filter>
+ <action android:name="com.android.intent.action.MANAGE_VOICE_KEYPHRASES" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ </activity>
+ <meta-data android:name="android.voice_enrollment"
+ android:resource="@xml/enrollment_application"/>
+ </application>
+</manifest>
diff --git a/tests/VoiceEnrollment/res/xml/enrollment_application.xml b/tests/VoiceEnrollment/res/xml/enrollment_application.xml
new file mode 100644
index 000000000000..710a0ac0f54a
--- /dev/null
+++ b/tests/VoiceEnrollment/res/xml/enrollment_application.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/**
+ * Copyright (c) 2014, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+-->
+
+<voice-enrollment-application xmlns:android="http://schemas.android.com/apk/res/android"
+ android:searchKeyphraseId="101"
+ android:searchKeyphrase="Hello There"
+ android:searchKeyphraseSupportedLocales="en-US,en-GB,fr-FR,de-DE" />
diff --git a/tests/VoiceEnrollment/src/com/android/test/voiceenrollment/TestEnrollmentActivity.java b/tests/VoiceEnrollment/src/com/android/test/voiceenrollment/TestEnrollmentActivity.java
new file mode 100644
index 000000000000..7fbd965b6989
--- /dev/null
+++ b/tests/VoiceEnrollment/src/com/android/test/voiceenrollment/TestEnrollmentActivity.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.test.voiceenrollment;
+
+import android.app.Activity;
+
+public class TestEnrollmentActivity extends Activity {
+ // TODO(sansid): Add a test enrollment flow here.
+}
diff --git a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionService.java b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionService.java
index d40b05f15cb0..00c2c641af92 100644
--- a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionService.java
+++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionService.java
@@ -21,6 +21,8 @@ import android.os.Bundle;
import android.service.voice.VoiceInteractionService;
import android.util.Log;
+import java.util.Arrays;
+
public class MainInteractionService extends VoiceInteractionService {
static final String TAG = "MainInteractionService";
@@ -28,6 +30,9 @@ public class MainInteractionService extends VoiceInteractionService {
public void onCreate() {
super.onCreate();
Log.i(TAG, "Creating " + this);
+ Log.i(TAG, "Keyphrase enrollment error? " + getKeyphraseEnrollmentInfo().getParseError());
+ Log.i(TAG, "Keyphrase enrollment meta-data: "
+ + Arrays.toString(getKeyphraseEnrollmentInfo().getKeyphrases()));
}
@Override