Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 377a1c36 authored by JW Wang's avatar JW Wang
Browse files

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
parent a6d73457
Loading
Loading
Loading
Loading
+10 −14
Original line number Diff line number Diff line
@@ -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,20 +82,13 @@ 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;
        }
    }

    /**
     * True if the app is recording audio.
@@ -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);