Ambient Activation p2.1
Using voice-activation ops OP_SANDBOX_TRIGGER_AUDIO for voice acitivation
of the assistant app.
1) This change is currently flag protected by a static boolean
IS_VOICE_ACITVAITON_OP_ENABLED. Will be converted and conform to the
trunk stable flag configuration in a follow-up change.
2) OP_RECORD_AUDIO_HOTWORD is replaced by
OP_RECEIVE_SANDBOX_TRIGGER_AUDIO for noting the discrete event of voice activation of
the assistant app.
Bug: 287264308
Test: presubmit
Change-Id: I09fb4e3bc0493571a9c7f15bc84c106a127c7588
diff --git a/core/java/android/app/AppOpsManager.java b/core/java/android/app/AppOpsManager.java
index 096ad55..56fef1a 100644
--- a/core/java/android/app/AppOpsManager.java
+++ b/core/java/android/app/AppOpsManager.java
@@ -2809,7 +2809,8 @@
"RECORD_AUDIO_SANDBOXED").setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_RECEIVE_SANDBOX_TRIGGER_AUDIO,
OPSTR_RECEIVE_SANDBOX_TRIGGER_AUDIO,
- "RECEIVE_SANDBOX_TRIGGER_AUDIO").build(),
+ "RECEIVE_SANDBOX_TRIGGER_AUDIO")
+ .setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_RECEIVE_SANDBOX_NEGATIVE_DATA_AUDIO,
OPSTR_RECEIVE_SANDBOX_NEGATIVE_DATA_AUDIO,
"RECEIVE_SANDBOX_NEGATIVE_DATA_AUDIO").build()
diff --git a/services/core/java/com/android/server/appop/DiscreteRegistry.java b/services/core/java/com/android/server/appop/DiscreteRegistry.java
index 10243e2..e91b7e8 100644
--- a/services/core/java/com/android/server/appop/DiscreteRegistry.java
+++ b/services/core/java/com/android/server/appop/DiscreteRegistry.java
@@ -35,6 +35,7 @@
import static android.app.AppOpsManager.OP_PHONE_CALL_CAMERA;
import static android.app.AppOpsManager.OP_PHONE_CALL_MICROPHONE;
import static android.app.AppOpsManager.OP_RECEIVE_AMBIENT_TRIGGER_AUDIO;
+import static android.app.AppOpsManager.OP_RECEIVE_SANDBOX_TRIGGER_AUDIO;
import static android.app.AppOpsManager.OP_RECORD_AUDIO;
import static android.app.AppOpsManager.flagsToString;
import static android.app.AppOpsManager.getUidStateName;
@@ -134,7 +135,8 @@
private static final String PROPERTY_DISCRETE_OPS_LIST = "discrete_history_ops_cslist";
private static final String DEFAULT_DISCRETE_OPS = OP_FINE_LOCATION + "," + OP_COARSE_LOCATION
+ "," + OP_CAMERA + "," + OP_RECORD_AUDIO + "," + OP_PHONE_CALL_MICROPHONE + ","
- + OP_PHONE_CALL_CAMERA + "," + OP_RECEIVE_AMBIENT_TRIGGER_AUDIO;
+ + OP_PHONE_CALL_CAMERA + "," + OP_RECEIVE_AMBIENT_TRIGGER_AUDIO + ","
+ + OP_RECEIVE_SANDBOX_TRIGGER_AUDIO;
private static final long DEFAULT_DISCRETE_HISTORY_CUTOFF = Duration.ofDays(7).toMillis();
private static final long MAXIMUM_DISCRETE_HISTORY_CUTOFF = Duration.ofDays(30).toMillis();
private static final long DEFAULT_DISCRETE_HISTORY_QUANTIZATION =
diff --git a/services/core/java/com/android/server/policy/AppOpsPolicy.java b/services/core/java/com/android/server/policy/AppOpsPolicy.java
index 5288e85..ebc7163 100644
--- a/services/core/java/com/android/server/policy/AppOpsPolicy.java
+++ b/services/core/java/com/android/server/policy/AppOpsPolicy.java
@@ -16,6 +16,9 @@
package com.android.server.policy;
+import static android.app.AppOpsManager.OP_RECEIVE_SANDBOX_TRIGGER_AUDIO;
+import static android.app.AppOpsManager.OP_RECORD_AUDIO_HOTWORD;
+
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.AppOpsManager;
@@ -72,6 +75,9 @@
private static final boolean SYSPROP_HOTWORD_DETECTION_SERVICE_REQUIRED =
SystemProperties.getBoolean("ro.hotword.detection_service_required", false);
+ //TODO(b/289087412): import this from the flag value in set up in device config.
+ private static final boolean IS_VOICE_ACTIVATION_OP_ENABLED = false;
+
@NonNull
private final Object mLock = new Object();
@@ -203,6 +209,16 @@
}
/**
+ * @return the op that should be noted for the voice activations of the app by detected hotword.
+ */
+ public static int getVoiceActivationOp() {
+ if (IS_VOICE_ACTIVATION_OP_ENABLED) {
+ return OP_RECEIVE_SANDBOX_TRIGGER_AUDIO;
+ }
+ return OP_RECORD_AUDIO_HOTWORD;
+ }
+
+ /**
* @hide
*/
public static boolean isHotwordDetectionServiceRequired(PackageManager pm) {
@@ -321,7 +337,6 @@
}
}
-
private int resolveDatasourceOp(int code, int uid, @NonNull String packageName,
@Nullable String attributionTag) {
code = resolveRecordAudioOp(code, uid);
diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/DetectorSession.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/DetectorSession.java
index ffc7b8e..42b08e3 100644
--- a/services/voiceinteraction/java/com/android/server/voiceinteraction/DetectorSession.java
+++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/DetectorSession.java
@@ -753,11 +753,11 @@
"Failed to obtain permission RECORD_AUDIO for identity "
+ mVoiceInteractorIdentity);
}
- int hotwordOp = AppOpsManager.strOpToOp(
- AppOpsManager.OPSTR_RECORD_AUDIO_HOTWORD);
- mAppOpsManager.noteOpNoThrow(hotwordOp,
+ mAppOpsManager.noteOpNoThrow(
+ AppOpsPolicy.getVoiceActivationOp(),
mVoiceInteractorIdentity.uid, mVoiceInteractorIdentity.packageName,
- mVoiceInteractorIdentity.attributionTag, HOTWORD_DETECTION_OP_MESSAGE);
+ mVoiceInteractorIdentity.attributionTag,
+ HOTWORD_DETECTION_OP_MESSAGE);
} else {
enforcePermissionForDataDelivery(mContext, mVoiceInteractorIdentity,
RECORD_AUDIO, HOTWORD_DETECTION_OP_MESSAGE);