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

Commit a3431c7b authored by ot_chenqi.c's avatar ot_chenqi.c Committed by Shunkai Yao
Browse files

Fix unbind service error for MusicFxHelper

Unbinding an unbound service will cause an exception,
for example: service not registered: com.android.server.audio.MusicFxHelper.

Bug: 332454067
Test: run MTBF test and no crash
Test: MusicFx panel enable/disable
Test: atest com.android.server.audio.MusicFxHelperTest

Change-Id: Ic519221b2bb7d28e5378a995519f8b3269d03c70
parent f245247d
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -70,6 +70,8 @@ public class MusicFxHelper {
    // The binder token identifying the UidObserver registration.
    private IBinder mUidObserverToken = null;

    private boolean mIsBound;

    // Package name and list of open audio sessions for this package
    private static class PackageSessions {
        String mPackageName;
@@ -110,6 +112,7 @@ public class MusicFxHelper {
                if (procState > ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) {
                    Intent bindIntent = new Intent().setClassName(mMusicFxPackageName,
                            "com.android.musicfx.KeepAliveService");
                    mIsBound = true;
                    mContext.bindServiceAsUser(
                            bindIntent, mMusicFxBindConnection, Context.BIND_AUTO_CREATE,
                            UserHandle.of(getCurrentUserId()));
@@ -158,12 +161,15 @@ public class MusicFxHelper {
                    Log.e(TAG, "RemoteException with unregisterUidObserver: " + e);
                }
                mUidObserverToken = null;
                if (mIsBound) {
                    mContext.unbindService(mMusicFxBindConnection);
                    mIsBound = false;
                    Log.i(TAG, "last session closed, unregister UID observer, and unbind "
                            + mMusicFxPackageName);
                }
            }
        }
    }

    // Hashmap of UID and list of open sessions for this UID.
    @GuardedBy("mClientUidMapLock")