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

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

Notify newly registered audio focus listener of current focus owner

When an AudioPolicy with an AudioPolicyFocusListener gets registered,
  notify it automatically of the current focus owner, i.e. the
  top of the stack, if there is one.

Bug 19194917

Change-Id: I66fa141ce9550349d107288fc36ddab50898dc45
parent b9b8aef9
Loading
Loading
Loading
Loading
+29 −2
Original line number Diff line number Diff line
@@ -653,6 +653,7 @@ public class MediaFocusControl implements OnFinished {
                return;
            } else {
                mFocusFollowers.add(ff);
                notifyExtPolicyCurrentFocusAsync(ff);
            }
        }
    }
@@ -671,6 +672,32 @@ public class MediaFocusControl implements OnFinished {
        }
    }

    /**
     * @param pcb non null
     */
    void notifyExtPolicyCurrentFocusAsync(IAudioPolicyCallback pcb) {
        final IAudioPolicyCallback pcb2 = pcb;
        final Thread thread = new Thread() {
            @Override
            public void run() {
                synchronized(mAudioFocusLock) {
                    if (mFocusStack.isEmpty()) {
                        return;
                    }
                    try {
                        pcb2.notifyAudioFocusGrant(mFocusStack.peek().toAudioFocusInfo(),
                                // top of focus stack always has focus
                                AudioManager.AUDIOFOCUS_REQUEST_GRANTED);
                    } catch (RemoteException e) {
                        Log.e(TAG, "Can't call notifyAudioFocusGrant() on IAudioPolicyCallback "
                                + pcb2.asBinder(), e);
                    }
                }
            }
        };
        thread.start();
    }

    /**
     * Called synchronized on mAudioFocusLock
     */
@@ -680,7 +707,7 @@ public class MediaFocusControl implements OnFinished {
                // oneway
                pcb.notifyAudioFocusGrant(afi, requestResult);
            } catch (RemoteException e) {
                Log.e(TAG, "Can't call newAudioFocusLoser() on IAudioPolicyCallback "
                Log.e(TAG, "Can't call notifyAudioFocusGrant() on IAudioPolicyCallback "
                        + pcb.asBinder(), e);
            }
        }
@@ -695,7 +722,7 @@ public class MediaFocusControl implements OnFinished {
                // oneway
                pcb.notifyAudioFocusLoss(afi, wasDispatched);
            } catch (RemoteException e) {
                Log.e(TAG, "Can't call newAudioFocusLoser() on IAudioPolicyCallback "
                Log.e(TAG, "Can't call notifyAudioFocusLoss() on IAudioPolicyCallback "
                        + pcb.asBinder(), e);
            }
        }