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

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

Clean up role of component name in media button event receiver

A public API was added to AudioManager to register a media button
 event receiver whithout having to supply a ComponentName.
This CL updates the comments that specified that the now optional
 ComponentName parameter can be null, and never persist the button
 event receiver is there is no ComponentName to persist.
Also unregistering the media button receiver makes no use of
 the ComponentName anymore.

Change-Id: Idcfed1e2a85feb6fa178ca7797427f238705957c
parent 6f268369
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -2127,7 +2127,7 @@ public class AudioManager {
        mediaButtonIntent.setComponent(eventReceiver);
        PendingIntent pi = PendingIntent.getBroadcast(mContext,
                0/*requestCode, ignored*/, mediaButtonIntent, 0/*flags*/);
        unregisterMediaButtonIntent(pi, eventReceiver);
        unregisterMediaButtonIntent(pi);
    }

    /**
@@ -2139,16 +2139,16 @@ public class AudioManager {
        if (eventReceiver == null) {
            return;
        }
        unregisterMediaButtonIntent(eventReceiver, null);
        unregisterMediaButtonIntent(eventReceiver);
    }

    /**
     * @hide
     */
    public void unregisterMediaButtonIntent(PendingIntent pi, ComponentName eventReceiver) {
    public void unregisterMediaButtonIntent(PendingIntent pi) {
        IAudioService service = getService();
        try {
            service.unregisterMediaButtonIntent(pi, eventReceiver);
            service.unregisterMediaButtonIntent(pi);
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in unregisterMediaButtonIntent"+e);
        }
+12 −6
Original line number Diff line number Diff line
@@ -5100,7 +5100,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
            mRemoteVolumeObs = null;
        }

        /** precondition: mediaIntent != null, eventReceiver != null */
        /** precondition: mediaIntent != null */
        public RemoteControlStackEntry(PendingIntent mediaIntent, ComponentName eventReceiver) {
            mMediaIntent = mediaIntent;
            mReceiverComponent = eventReceiver;
@@ -5273,6 +5273,10 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
                Settings.System.MEDIA_BUTTON_RECEIVER, UserHandle.USER_CURRENT);
        if ((null != receiverName) && !receiverName.isEmpty()) {
            ComponentName eventReceiver = ComponentName.unflattenFromString(receiverName);
            if (eventReceiver == null) {
                // an invalid name was persisted
                return;
            }
            // construct a PendingIntent targeted to the restored component name
            // for the media button and register it
            Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
@@ -5288,7 +5292,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
     * Helper function:
     * Set the new remote control receiver at the top of the RC focus stack.
     * Called synchronized on mAudioFocusLock, then mRCStack
     * precondition: mediaIntent != null, target != null
     * precondition: mediaIntent != null
     */
    private void pushMediaButtonReceiver_syncAfRcs(PendingIntent mediaIntent, ComponentName target) {
        // already at top of stack?
@@ -5317,9 +5321,11 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
        mRCStack.push(rcse); // rcse is never null

        // post message to persist the default media button receiver
        if (target != null) {
            mAudioHandler.sendMessage( mAudioHandler.obtainMessage(
                    MSG_PERSIST_MEDIABUTTONRECEIVER, 0, 0, target/*obj*/) );
        }
    }

    /**
     * Helper function:
@@ -5618,7 +5624,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished {

    /**
     * see AudioManager.registerMediaButtonIntent(PendingIntent pi, ComponentName c)
     * precondition: mediaIntent != null, target != null
     * precondition: mediaIntent != null
     */
    public void registerMediaButtonIntent(PendingIntent mediaIntent, ComponentName eventReceiver) {
        Log.i(TAG, "  Remote Control   registerMediaButtonIntent() for " + mediaIntent);
@@ -5636,7 +5642,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
     * see AudioManager.unregisterMediaButtonIntent(PendingIntent mediaIntent)
     * precondition: mediaIntent != null, eventReceiver != null
     */
    public void unregisterMediaButtonIntent(PendingIntent mediaIntent, ComponentName eventReceiver)
    public void unregisterMediaButtonIntent(PendingIntent mediaIntent)
    {
        Log.i(TAG, "  Remote Control   unregisterMediaButtonIntent() for " + mediaIntent);

+1 −1
Original line number Diff line number Diff line
@@ -121,7 +121,7 @@ interface IAudioService {
    void dispatchMediaKeyEventUnderWakelock(in KeyEvent keyEvent);

           void registerMediaButtonIntent(in PendingIntent pi, in ComponentName c);
    oneway void unregisterMediaButtonIntent(in PendingIntent pi,  in ComponentName c);
    oneway void unregisterMediaButtonIntent(in PendingIntent pi);

    oneway void registerMediaButtonEventReceiverForCalls(in ComponentName c);
    oneway void unregisterMediaButtonEventReceiverForCalls();