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

Commit f2aae189 authored by Eric Laurent's avatar Eric Laurent
Browse files

AudioService: force audio mode owner update

The audio mode owner can change even if the audio mode does not change

Bug: 417921969
Test: AudioManagerTest
Flag: EXEMPT bug fix
Change-Id: I0e16ff5def60ca3322849486706be9e22a5d0ba7
parent a87ff22f
Loading
Loading
Loading
Loading
+15 −8
Original line number Diff line number Diff line
@@ -5161,20 +5161,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;
@@ -5185,16 +5187,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);
        }
    }
@@ -6666,7 +6671,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 */);
                }
            }
        }
@@ -6855,6 +6860,8 @@ public class AudioService extends IAudioService.Stub
                }
            }
            int previousModeOwnerUid = getModeOwnerUid();
            if (mode == AudioSystem.MODE_NORMAL) {
                if (currentModeHandler != null) {
                    if (!currentModeHandler.isPrivileged()
@@ -6911,9 +6918,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 */);
        }
    }
@@ -10916,7 +10923,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;