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

Commit 1c3408fc authored by Eric Laurent's avatar Eric Laurent
Browse files

audio: add call redirection audio modes

Add two audio modes corresponding to a call redirection
scenario:
- AudioManager.MODE_CALL_REDIRECT: PSTN call redirection
- AudioManager.MODE_COMMUNICATION_REDIRECT: VoIP call redirection

When in call redirect mode, call audio uplink and downlink are not
routed to regular audio sinks (e.g. earpiece) or sources (e.g. built in
mic) but disconnected. A privileged app can use system APIs to inject
and extract call audio and redirect the call to another device.

All other media use cases operate as if no call was active.

Bug: 189472651
Test: make
Change-Id: I3b1a616a72b1f7c97e0e5bf7c9f76c40a28876f1
parent 420679de
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -20732,7 +20732,9 @@ package android.media {
    field public static final int GET_DEVICES_ALL = 3; // 0x3
    field public static final int GET_DEVICES_ALL = 3; // 0x3
    field public static final int GET_DEVICES_INPUTS = 1; // 0x1
    field public static final int GET_DEVICES_INPUTS = 1; // 0x1
    field public static final int GET_DEVICES_OUTPUTS = 2; // 0x2
    field public static final int GET_DEVICES_OUTPUTS = 2; // 0x2
    field public static final int MODE_CALL_REDIRECT = 5; // 0x5
    field public static final int MODE_CALL_SCREENING = 4; // 0x4
    field public static final int MODE_CALL_SCREENING = 4; // 0x4
    field public static final int MODE_COMMUNICATION_REDIRECT = 6; // 0x6
    field public static final int MODE_CURRENT = -1; // 0xffffffff
    field public static final int MODE_CURRENT = -1; // 0xffffffff
    field public static final int MODE_INVALID = -2; // 0xfffffffe
    field public static final int MODE_INVALID = -2; // 0xfffffffe
    field public static final int MODE_IN_CALL = 2; // 0x2
    field public static final int MODE_IN_CALL = 2; // 0x2
+4 −0
Original line number Original line Diff line number Diff line
@@ -45,4 +45,8 @@ enum AudioMode {
    IN_COMMUNICATION = 3,
    IN_COMMUNICATION = 3,
    /** Call screening in progress. */
    /** Call screening in progress. */
    CALL_SCREEN = 4,
    CALL_SCREEN = 4,
    /** PSTN Call redirection  in progress. */
    SYS_RESERVED_CALL_REDIRECT = 5,
    /** VoIP Call redirection  in progress. */
    SYS_RESERVED_COMMUNICATION_REDIRECT = 6,
}
}
+2 −0
Original line number Original line Diff line number Diff line
@@ -42,4 +42,6 @@ enum AudioMode {
  IN_CALL = 2,
  IN_CALL = 2,
  IN_COMMUNICATION = 3,
  IN_COMMUNICATION = 3,
  CALL_SCREEN = 4,
  CALL_SCREEN = 4,
  SYS_RESERVED_CALL_REDIRECT = 5,
  SYS_RESERVED_COMMUNICATION_REDIRECT = 6,
}
}
+31 −1
Original line number Original line Diff line number Diff line
@@ -30,8 +30,11 @@ import android.annotation.SystemService;
import android.annotation.TestApi;
import android.annotation.TestApi;
import android.app.NotificationManager;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.PendingIntent;
import android.app.compat.CompatChanges;
import android.bluetooth.BluetoothCodecConfig;
import android.bluetooth.BluetoothCodecConfig;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothDevice;
import android.compat.annotation.ChangeId;
import android.compat.annotation.EnabledSince;
import android.compat.annotation.UnsupportedAppUsage;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.ComponentName;
import android.content.ComponentName;
import android.content.Context;
import android.content.Context;
@@ -2839,6 +2842,14 @@ public class AudioManager {
        }
        }
    }
    }


    /**
     * This change id controls use of audio modes for call audio redirection.
     * @hide
     */
    @ChangeId
    @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
    public static final long CALL_REDIRECTION_AUDIO_MODES = 189472651L; // buganizer id

    /**
    /**
     * Returns the current audio mode.
     * Returns the current audio mode.
     *
     *
@@ -2858,6 +2869,12 @@ public class AudioManager {
            }
            }
            if (mode == MODE_CALL_SCREENING && sdk <= Build.VERSION_CODES.Q) {
            if (mode == MODE_CALL_SCREENING && sdk <= Build.VERSION_CODES.Q) {
                mode = MODE_IN_CALL;
                mode = MODE_IN_CALL;
            } else if (mode == MODE_CALL_REDIRECT
                    && !CompatChanges.isChangeEnabled(CALL_REDIRECTION_AUDIO_MODES)) {
                mode = MODE_IN_CALL;
            } else if (mode == MODE_COMMUNICATION_REDIRECT
                    && !CompatChanges.isChangeEnabled(CALL_REDIRECTION_AUDIO_MODES)) {
                mode = MODE_IN_COMMUNICATION;
            }
            }
            return mode;
            return mode;
        } catch (RemoteException e) {
        } catch (RemoteException e) {
@@ -3075,13 +3092,26 @@ public class AudioManager {
     */
     */
    public static final int MODE_CALL_SCREENING     = AudioSystem.MODE_CALL_SCREENING;
    public static final int MODE_CALL_SCREENING     = AudioSystem.MODE_CALL_SCREENING;


    /**
     * A telephony call is established and its audio is being redirected to another device.
     */
    public static final int MODE_CALL_REDIRECT   = AudioSystem.MODE_CALL_REDIRECT;

    /**
     * n audio/video chat or VoIP call is established and its audio is being redirected to another
     * device.
     */
    public static final int MODE_COMMUNICATION_REDIRECT = AudioSystem.MODE_COMMUNICATION_REDIRECT;

    /** @hide */
    /** @hide */
    @IntDef(flag = false, prefix = "MODE_", value = {
    @IntDef(flag = false, prefix = "MODE_", value = {
            MODE_NORMAL,
            MODE_NORMAL,
            MODE_RINGTONE,
            MODE_RINGTONE,
            MODE_IN_CALL,
            MODE_IN_CALL,
            MODE_IN_COMMUNICATION,
            MODE_IN_COMMUNICATION,
            MODE_CALL_SCREENING }
            MODE_CALL_SCREENING,
            MODE_CALL_REDIRECT,
            MODE_COMMUNICATION_REDIRECT}
    )
    )
    @Retention(RetentionPolicy.SOURCE)
    @Retention(RetentionPolicy.SOURCE)
    public @interface AudioMode {}
    public @interface AudioMode {}
+7 −1
Original line number Original line Diff line number Diff line
@@ -199,7 +199,11 @@ public class AudioSystem
    /** @hide */
    /** @hide */
    public static final int MODE_CALL_SCREENING     = 4;
    public static final int MODE_CALL_SCREENING     = 4;
    /** @hide */
    /** @hide */
    public static final int NUM_MODES               = 5;
    public static final int MODE_CALL_REDIRECT     = 5;
    /** @hide */
    public static final int MODE_COMMUNICATION_REDIRECT  = 6;
    /** @hide */
    public static final int NUM_MODES               = 7;


    /** @hide */
    /** @hide */
    public static String modeToString(int mode) {
    public static String modeToString(int mode) {
@@ -211,6 +215,8 @@ public class AudioSystem
            case MODE_NORMAL: return "MODE_NORMAL";
            case MODE_NORMAL: return "MODE_NORMAL";
            case MODE_RINGTONE: return "MODE_RINGTONE";
            case MODE_RINGTONE: return "MODE_RINGTONE";
            case MODE_CALL_SCREENING: return "MODE_CALL_SCREENING";
            case MODE_CALL_SCREENING: return "MODE_CALL_SCREENING";
            case MODE_CALL_REDIRECT: return "MODE_CALL_REDIRECT";
            case MODE_COMMUNICATION_REDIRECT: return "MODE_COMMUNICATION_REDIRECT";
            default: return "unknown mode (" + mode + ")";
            default: return "unknown mode (" + mode + ")";
        }
        }
    }
    }
Loading