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

Commit c544bee8 authored by Bishoy Gendy's avatar Bishoy Gendy
Browse files

Change Runnables to lamda in MediaSessionRecord

Bug: 295518668
Test: Non funtional change
Change-Id: If356945c397ac108fccc147d2b0680ae6410aefd
parent 66c68099
Loading
Loading
Loading
Loading
+96 −78
Original line number Diff line number Diff line
@@ -431,28 +431,9 @@ public class MediaSessionRecord extends MediaSessionRecordImpl implements IBinde
            int stream = getVolumeStream(mAudioAttrs);
            final int volumeValue = value;
            mHandler.post(
                    new Runnable() {
                        @Override
                        public void run() {
                            try {
                                mAudioManager.setStreamVolumeForUid(
                                        stream,
                                        volumeValue,
                                        flags,
                                        opPackageName,
                                        uid,
                                        pid,
                                        mContext.getApplicationInfo().targetSdkVersion);
                            } catch (IllegalArgumentException | SecurityException e) {
                                Slog.e(
                                        TAG,
                                        "Cannot set volume: stream=" + stream
                                                + ", value=" + volumeValue
                                                + ", flags=" + flags,
                                        e);
                            }
                        }
                    });
                    () ->
                            setStreamVolumeForUid(
                                    opPackageName, pid, uid, flags, stream, volumeValue));
        } else {
            if (mVolumeControlType != VOLUME_CONTROL_ABSOLUTE) {
                if (DEBUG) {
@@ -482,6 +463,27 @@ public class MediaSessionRecord extends MediaSessionRecordImpl implements IBinde
        }
    }

    private void setStreamVolumeForUid(
            String opPackageName, int pid, int uid, int flags, int stream, int volumeValue) {
        try {
            mAudioManager.setStreamVolumeForUid(
                    stream,
                    volumeValue,
                    flags,
                    opPackageName,
                    uid,
                    pid,
                    mContext.getApplicationInfo().targetSdkVersion);
        } catch (IllegalArgumentException | SecurityException e) {
            Slog.e(
                    TAG,
                    "Cannot set volume: stream=" + stream
                            + ", value=" + volumeValue
                            + ", flags=" + flags,
                    e);
        }
    }

    /**
     * Check if this session has been set to active by the app.
     * <p>
@@ -749,9 +751,27 @@ public class MediaSessionRecord extends MediaSessionRecordImpl implements IBinde
            pid = callingPid;
        }
        mHandler.post(
                new Runnable() {
                    @Override
                    public void run() {
                () ->
                        adjustSuggestedStreamVolumeForUid(
                                stream,
                                direction,
                                flags,
                                useSuggested,
                                previousFlagPlaySound,
                                opPackageName,
                                uid,
                                pid));
    }

    private void adjustSuggestedStreamVolumeForUid(
            int stream,
            int direction,
            int flags,
            boolean useSuggested,
            int previousFlagPlaySound,
            String opPackageName,
            int uid,
            int pid) {
        try {
            if (useSuggested) {
                if (AudioSystem.isStreamActive(stream, 0)) {
@@ -787,15 +807,15 @@ public class MediaSessionRecord extends MediaSessionRecordImpl implements IBinde
            Slog.e(
                    TAG,
                    "Cannot adjust volume: direction=" + direction
                                            + ", stream=" + stream + ", flags=" + flags
                                            + ", opPackageName=" + opPackageName + ", uid=" + uid
                            + ", stream=" + stream
                            + ", flags=" + flags
                            + ", opPackageName=" + opPackageName
                            + ", uid=" + uid
                            + ", useSuggested=" + useSuggested
                            + ", previousFlagPlaySound=" + previousFlagPlaySound,
                    e);
        }
    }
                });
    }

    private void logCallbackException(
            String msg, ISessionControllerCallbackHolder holder, Exception e) {
@@ -1089,15 +1109,13 @@ public class MediaSessionRecord extends MediaSessionRecordImpl implements IBinde
                volumeType, VOLUME_CONTROL_ABSOLUTE, max, current, attributes, null);
    }

    private final Runnable mClearOptimisticVolumeRunnable = new Runnable() {
        @Override
        public void run() {
    private final Runnable mClearOptimisticVolumeRunnable =
            () -> {
                boolean needUpdate = (mOptimisticVolume != mCurrentVolume);
                mOptimisticVolume = -1;
                if (needUpdate) {
                    pushVolumeUpdate();
                }
        }
            };

    @RequiresPermission(Manifest.permission.INTERACT_ACROSS_USERS)