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

Commit dcb27105 authored by Jean-Michel Trivi's avatar Jean-Michel Trivi Committed by Android (Google) Code Review
Browse files

Merge "AudioDeviceVolumeManager and VolumeInfo API changes" into tm-qpr-dev

parents b272ead9 7ec3e248
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -115,6 +115,7 @@ import android.location.CountryDetector;
import android.location.ICountryDetector;
import android.location.ILocationManager;
import android.location.LocationManager;
import android.media.AudioDeviceVolumeManager;
import android.media.AudioManager;
import android.media.MediaFrameworkInitializer;
import android.media.MediaFrameworkPlatformInitializer;
@@ -339,6 +340,13 @@ public final class SystemServiceRegistry {
                return new AudioManager(ctx);
            }});

        registerService(Context.AUDIO_DEVICE_VOLUME_SERVICE, AudioDeviceVolumeManager.class,
                new CachedServiceFetcher<AudioDeviceVolumeManager>() {
            @Override
            public AudioDeviceVolumeManager createService(ContextImpl ctx) {
                return new AudioDeviceVolumeManager(ctx);
            }});

        registerService(Context.MEDIA_ROUTER_SERVICE, MediaRouter.class,
                new CachedServiceFetcher<MediaRouter>() {
            @Override
+12 −0
Original line number Diff line number Diff line
@@ -3846,6 +3846,7 @@ public abstract class Context {
            WIFI_RTT_RANGING_SERVICE,
            NSD_SERVICE,
            AUDIO_SERVICE,
            AUDIO_DEVICE_VOLUME_SERVICE,
            AUTH_SERVICE,
            FINGERPRINT_SERVICE,
            //@hide: FACE_SERVICE,
@@ -4686,6 +4687,17 @@ public abstract class Context {
     */
    public static final String AUDIO_SERVICE = "audio";

    /**
     * @hide
     * Use with {@link #getSystemService(String)} to retrieve a
     * {@link android.media.AudioDeviceVolumeManager} for handling management of audio device
     * (e.g. speaker, USB headset) volume.
     *
     * @see #getSystemService(String)
     * @see android.media.AudioDeviceVolumeManager
     */
    public static final String AUDIO_DEVICE_VOLUME_SERVICE = "audio_device_volume";

    /**
     * Use with {@link #getSystemService(String)} to retrieve a {@link
     * android.media.MediaTranscodingManager} for transcoding media.
+32 −6
Original line number Diff line number Diff line
@@ -41,8 +41,7 @@ import java.util.concurrent.Executor;
 */
public class AudioDeviceVolumeManager {

    // define when using Log.*
    //private static final String TAG = "AudioDeviceVolumeManager";
    private static final String TAG = "AudioDeviceVolumeManager";

    /** Indicates no special treatment in the handling of the volume adjustment */
    public static final int ADJUST_MODE_NORMAL = 0;
@@ -62,11 +61,15 @@ public class AudioDeviceVolumeManager {
    private static IAudioService sService;

    private final @NonNull String mPackageName;
    private final @Nullable String mAttributionTag;

    public AudioDeviceVolumeManager(Context context) {
    /**
     * @hide
     * Constructor
     * @param context the Context for the device volume operations
     */
    public AudioDeviceVolumeManager(@NonNull Context context) {
        Objects.requireNonNull(context);
        mPackageName = context.getApplicationContext().getOpPackageName();
        mAttributionTag = context.getApplicationContext().getAttributionTag();
    }

    /**
@@ -308,13 +311,36 @@ public class AudioDeviceVolumeManager {
    @RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_ROUTING)
    public void setDeviceVolume(@NonNull VolumeInfo vi, @NonNull AudioDeviceAttributes ada) {
        try {
            getService().setDeviceVolume(vi, ada, mPackageName, mAttributionTag);
            getService().setDeviceVolume(vi, ada, mPackageName);
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
        }
    }

    /**
     * @hide
     * Returns the volume on the given audio device for the given volume information.
     * For instance if using a {@link VolumeInfo} configured for {@link AudioManager#STREAM_ALARM},
     * it will return the alarm volume. When no volume index has ever been set for the given
     * device, the default volume will be returned (the volume setting that would have been
     * applied if playback for that use case had started).
     * @param vi the volume information, only stream-based volumes are supported. Information
     *           other than the stream type is ignored.
     * @param ada the device for which volume is to be retrieved
     */
    @RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_ROUTING)
    public @NonNull VolumeInfo getDeviceVolume(@NonNull VolumeInfo vi,
            @NonNull AudioDeviceAttributes ada) {
        try {
            return getService().getDeviceVolume(vi, ada, mPackageName);
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
        }
        return VolumeInfo.getDefaultVolumeInfo();
    }

    /**
     * @hide
     * Return human-readable name for volume behavior
     * @param behavior one of the volume behaviors defined in AudioManager
     * @return a string for the given behavior
+7 −1
Original line number Diff line number Diff line
@@ -1212,7 +1212,13 @@ public class AudioManager {
        }
    }

    private static boolean isPublicStreamType(int streamType) {
    /**
     * @hide
     * Checks whether a stream type is part of the public SDK
     * @param streamType
     * @return true if the stream type is available in SDK
     */
    public static boolean isPublicStreamType(int streamType) {
        switch (streamType) {
            case STREAM_VOICE_CALL:
            case STREAM_SYSTEM:
+4 −1
Original line number Diff line number Diff line
@@ -99,7 +99,10 @@ interface IAudioService {
            in String callingPackage, in String attributionTag);

    void setDeviceVolume(in VolumeInfo vi, in AudioDeviceAttributes ada,
            in String callingPackage, in String attributionTag);
            in String callingPackage);

    VolumeInfo getDeviceVolume(in VolumeInfo vi, in AudioDeviceAttributes ada,
            in String callingPackage);

    oneway void handleVolumeKey(in KeyEvent event, boolean isOnTv,
            String callingPackage, String caller);
Loading