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

Commit 76920fbb authored by Eric Laurent's avatar Eric Laurent Committed by Android (Google) Code Review
Browse files

Merge "AudioService: force audio mode owner update" into main

parents d3f7ea06 f2aae189
Loading
Loading
Loading
Loading
+15 −8
Original line number Diff line number Diff line
@@ -5177,20 +5177,22 @@ public class AudioService extends IAudioService.Stub
            if (updateAudioMode) {
                postUpdateAudioMode(existingMsgPolicy, AudioSystem.MODE_CURRENT,
                        android.os.Process.myPid(), mContext.getPackageName(),
                        false /*signal*/, delay);
                        false /*signal*/, delay, false /* force */);
            }
        }
    }
    static class UpdateAudioModeInfo {
        UpdateAudioModeInfo(int mode, int pid, String packageName) {
        UpdateAudioModeInfo(int mode, int pid, String packageName, boolean force) {
            mMode = mode;
            mPid = pid;
            mPackageName = packageName;
            mForce = force;
        }
        private final int mMode;
        private final int mPid;
        private final String mPackageName;
        private final boolean mForce;
        int getMode() {
            return mMode;
@@ -5201,16 +5203,19 @@ public class AudioService extends IAudioService.Stub
        String getPackageName() {
            return mPackageName;
        }
        boolean getForce() {
            return mForce;
        }
    }
    void postUpdateAudioMode(int msgPolicy, int mode, int pid, String packageName,
            boolean signal, int delay) {
            boolean signal, int delay, boolean force) {
        synchronized (mAudioModeResetLock) {
            if (signal) {
                mAudioModeResetCount++;
            }
            sendMsg(mAudioHandler, signal ? MSG_UPDATE_AUDIO_MODE_SIGNAL : MSG_UPDATE_AUDIO_MODE,
                    msgPolicy, 0, 0, new UpdateAudioModeInfo(mode, pid, packageName), delay);
                    msgPolicy, 0, 0, new UpdateAudioModeInfo(mode, pid, packageName, force), delay);
        }
    }
@@ -6682,7 +6687,7 @@ public class AudioService extends IAudioService.Stub
                    mSetModeDeathHandlers.remove(index);
                    postUpdateAudioMode(SENDMSG_QUEUE, AudioSystem.MODE_CURRENT,
                            android.os.Process.myPid(), mContext.getPackageName(),
                            false /*signal*/, 0);
                            false /*signal*/, 0, false /* force */);
                }
            }
        }
@@ -6871,6 +6876,8 @@ public class AudioService extends IAudioService.Stub
                }
            }
            int previousModeOwnerUid = getModeOwnerUid();
            if (mode == AudioSystem.MODE_NORMAL) {
                if (currentModeHandler != null) {
                    if (!currentModeHandler.isPrivileged()
@@ -6927,9 +6934,9 @@ public class AudioService extends IAudioService.Stub
                    }
                }
            }
            postUpdateAudioMode(SENDMSG_REPLACE, mode, pid, callingPackage,
                    hasModifyPhoneStatePermission && mode == AudioSystem.MODE_NORMAL, 0);
                    hasModifyPhoneStatePermission && mode == AudioSystem.MODE_NORMAL, 0,
                    previousModeOwnerUid != getModeOwnerUid() /* force */);
        }
    }
@@ -10932,7 +10939,7 @@ public class AudioService extends IAudioService.Stub
                    synchronized (mDeviceBroker.mSetModeLock) {
                        UpdateAudioModeInfo info = (UpdateAudioModeInfo) msg.obj;
                        onUpdateAudioMode(info.getMode(), info.getPid(), info.getPackageName(),
                                false /*force*/, msg.what == MSG_UPDATE_AUDIO_MODE_SIGNAL);
                                info.getForce(), msg.what == MSG_UPDATE_AUDIO_MODE_SIGNAL);
                    }
                    break;