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

Commit 15e30053 authored by Jean-Michel Trivi's avatar Jean-Michel Trivi
Browse files

AudioManager: fix implementation of isMusicActive()

Implementation of isMusicActive() should go through AudioService
as AudioSystem.isStreamActive() can only be called from system
service.

Bug: 175084989
Bug: 162423060
Test: atest AudioManagerTest
Change-Id: I15b3f7cd082a7497f857e6bf261f933224da853e
parent 1599b648
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -2881,7 +2881,12 @@ public class AudioManager {
     * @return true if any music tracks are active.
     */
    public boolean isMusicActive() {
        return AudioSystem.isStreamActive(STREAM_MUSIC, 0);
        final IAudioService service = getService();
        try {
            return service.isMusicActive();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
+2 −0
Original line number Diff line number Diff line
@@ -334,4 +334,6 @@ interface IAudioService {
    oneway void setStreamVolumeForUid(int streamType, int direction, int flags,
            in String packageName, int uid, int pid, in UserHandle userHandle,
            int targetSdkVersion);

    boolean isMusicActive();
}
+6 −0
Original line number Diff line number Diff line
@@ -2108,6 +2108,12 @@ public class AudioService extends IAudioService.Stub
        return getDevicesForAttributesInt(attributes);
    }

    /** @see AudioManager#isMusicActive() */
    public boolean isMusicActive() {
        // no permission required
        return AudioSystem.isStreamActive(AudioSystem.STREAM_MUSIC, 0);
    }

    protected @NonNull ArrayList<AudioDeviceAttributes> getDevicesForAttributesInt(
            @NonNull AudioAttributes attributes) {
        Objects.requireNonNull(attributes);