From 377a1c368d1b7dbb0fd788c34d970ac23b037df1 Mon Sep 17 00:00:00 2001 From: JW Wang Date: Thu, 15 Dec 2022 14:07:23 +0800 Subject: [PATCH] API coverage for Builder#requireNotInCall * Simplify the detection of voice call * Use a system property to simulate in-call Bug: 262614529 Bug: 235306967 Test: atest CtsStagedInstallHostTestCases Change-Id: Id835e633fd0668e550817638e39668614f15123d --- .../com/android/server/pm/AppStateHelper.java | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/services/core/java/com/android/server/pm/AppStateHelper.java b/services/core/java/com/android/server/pm/AppStateHelper.java index e6e8212ac16a2..bb0c41ea5591e 100644 --- a/services/core/java/com/android/server/pm/AppStateHelper.java +++ b/services/core/java/com/android/server/pm/AppStateHelper.java @@ -16,9 +16,6 @@ package com.android.server.pm; -import static android.media.AudioAttributes.USAGE_VOICE_COMMUNICATION; -import static android.media.AudioAttributes.USAGE_VOICE_COMMUNICATION_SIGNALLING; - import android.app.ActivityManager; import android.app.ActivityManager.RunningAppProcessInfo; import android.app.ActivityManagerInternal; @@ -26,6 +23,7 @@ import android.content.Context; import android.media.AudioManager; import android.media.IAudioService; import android.os.ServiceManager; +import android.os.SystemProperties; import android.telecom.TelecomManager; import android.text.TextUtils; import android.util.ArraySet; @@ -84,19 +82,12 @@ public class AppStateHelper { private boolean hasVoiceCall() { var am = mContext.getSystemService(AudioManager.class); try { - for (var apc : am.getActivePlaybackConfigurations()) { - if (!apc.isActive()) { - continue; - } - var usage = apc.getAudioAttributes().getUsage(); - if (usage == USAGE_VOICE_COMMUNICATION - || usage == USAGE_VOICE_COMMUNICATION_SIGNALLING) { - return true; - } - } + int audioMode = am.getMode(); + return audioMode == AudioManager.MODE_IN_CALL + || audioMode == AudioManager.MODE_IN_COMMUNICATION; } catch (Exception ignore) { + return false; } - return false; } /** @@ -186,6 +177,11 @@ public class AppStateHelper { * True if there is an ongoing phone call. */ public boolean isInCall() { + // Simulate in-call during test + if (SystemProperties.getBoolean( + "debug.pm.gentle_update_test.is_in_call", false)) { + return true; + } // TelecomManager doesn't handle the case where some apps don't implement ConnectionService. // We check apps using voice communication to detect if the device is in call. var tm = mContext.getSystemService(TelecomManager.class);