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

Commit 21fb09f9 authored by jianzhou's avatar jianzhou Committed by Jean-Michel Trivi
Browse files

frameworks/base: Fix AudioService JNI leaks

Root cause: AudioService keeps creating new instance of
ForceControlStreamClient and linkToDeath with the same
callback which leads to global reference table overflow
Fix: don't create new instance if call back doesn't change;
release old instance before create new one.

Test: Monkey or directed (see bug)
Bug: 74056493

Change-Id: I90641ae08c9abd522e2e75c6db934235c8b803e6
parent 0aa191cc
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -1915,7 +1915,16 @@ public class AudioService extends IAudioService.Stub
                }
                mUserSelectedVolumeControlStream = false;
            } else {
                if (null == mForceControlStreamClient) {
                    mForceControlStreamClient = new ForceControlStreamClient(cb);
                } else {
                    if (mForceControlStreamClient.getBinder() == cb) {
                        Log.d(TAG, "forceVolumeControlStream cb:" + cb + " is already linked.");
                    } else {
                        mForceControlStreamClient.release();
                        mForceControlStreamClient = new ForceControlStreamClient(cb);
                    }
                }
            }
        }
    }
@@ -1955,6 +1964,10 @@ public class AudioService extends IAudioService.Stub
                mCb = null;
            }
        }

        public IBinder getBinder() {
            return mCb;
        }
    }

    private void sendBroadcastToAll(Intent intent) {