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

Commit ed2d10da authored by Jean-Michel Trivi's avatar Jean-Michel Trivi
Browse files

Updates to remote control client (un)registration

Iterate over the remote control stack from top to bottom
 when (un)registering a remote control client (RCC).
When unregistering an RCC, stop traversing the stack when
 match found. If match was at top of the stack, update
 the remote control display (RCD).

Change-Id: If64acf102bdf328085d707f9e0f7e86cf4d4001a
parent bc83425c
Loading
Loading
Loading
Loading
+69 −53
Original line number Diff line number Diff line
@@ -5324,9 +5324,9 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
        synchronized(mAudioFocusLock) {
            synchronized(mRCStack) {
                // store the new display information
                Iterator<RemoteControlStackEntry> stackIterator = mRCStack.iterator();
                while(stackIterator.hasNext()) {
                    RemoteControlStackEntry rcse = stackIterator.next();
                try {
                    for (int index = mRCStack.size()-1; index >= 0; index--) {
                        final RemoteControlStackEntry rcse = mRCStack.elementAt(index);
                        if(rcse.mMediaIntent.equals(mediaIntent)) {
                            // already had a remote control client?
                            if (rcse.mRcClientDeathHandler != null) {
@@ -5350,8 +5350,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
                                try {
                                    rcse.mRcClient.plugRemoteControlDisplay(mRcDisplay);
                                } catch (RemoteException e) {
                                Log.e(TAG, "Error connecting remote control display to client: "+e);
                                e.printStackTrace();
                                    Log.e(TAG, "Error connecting RCD to RCC in RCC registration",e);
                                }
                            }
                            // 2/ monitor the new client's death
@@ -5368,14 +5367,19 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
                            rcse.mRcClientDeathHandler = rcdh;
                            break;
                        }
                    }//for
                } catch (ArrayIndexOutOfBoundsException e) {
                    // not expected to happen, indicates improper concurrent modification
                    Log.e(TAG, "Wrong index accessing RC stack, lock error? ", e);
                }

                // if the eventReceiver is at the top of the stack
                // then check for potential refresh of the remote controls
                if (isCurrentRcController(mediaIntent)) {
                    checkUpdateRemoteControlDisplay_syncAfRcs(RC_INFO_ALL);
                }
            }
        }
            }//synchronized(mRCStack)
        }//synchronized(mAudioFocusLock)
        return rccId;
    }

@@ -5387,9 +5391,10 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
            IRemoteControlClient rcClient) {
        synchronized(mAudioFocusLock) {
            synchronized(mRCStack) {
                Iterator<RemoteControlStackEntry> stackIterator = mRCStack.iterator();
                while(stackIterator.hasNext()) {
                    RemoteControlStackEntry rcse = stackIterator.next();
                boolean topRccChange = false;
                try {
                    for (int index = mRCStack.size()-1; index >= 0; index--) {
                        final RemoteControlStackEntry rcse = mRCStack.elementAt(index);
                        if ((rcse.mMediaIntent.equals(mediaIntent))
                                && rcClient.equals(rcse.mRcClient)) {
                            // we found the IRemoteControlClient to unregister
@@ -5398,7 +5403,18 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
                            // reset the client-related fields
                            rcse.mRcClient = null;
                            rcse.mCallingPackageName = null;
                            topRccChange = (index == mRCStack.size()-1);
                            // there can only be one matching RCC in the RC stack, we're done
                            break;
                        }
                    }
                } catch (ArrayIndexOutOfBoundsException e) {
                    // not expected to happen, indicates improper concurrent modification
                    Log.e(TAG, "Wrong index accessing RC stack, lock error? ", e);
                }
                if (topRccChange) {
                    // no more RCC for the RCD, check for potential refresh of the remote controls
                    checkUpdateRemoteControlDisplay_syncAfRcs(RC_INFO_ALL);
                }
            }
        }