Loading media/java/android/media/AudioManager.java +7 −99 Original line number Diff line number Diff line Loading @@ -2194,48 +2194,8 @@ public class AudioManager { Log.e(TAG, "Cannot call registerMediaButtonIntent() with a null parameter"); return; } IAudioService service = getService(); try { // pi != null, this is currently still needed to support across // reboot launching of the last app. service.registerMediaButtonIntent(pi, eventReceiver, eventReceiver == null ? mToken : null); } catch (RemoteException e) { Log.e(TAG, "Dead object in registerMediaButtonIntent"+e); } MediaSessionLegacyHelper helper = MediaSessionLegacyHelper.getHelper(mContext); helper.addMediaButtonListener(pi, mContext); } /** * @hide * Used internally by telephony package to register an intent receiver for ACTION_MEDIA_BUTTON. * @param eventReceiver the component that will receive the media button key events, * no-op if eventReceiver is null */ public void registerMediaButtonEventReceiverForCalls(ComponentName eventReceiver) { if (eventReceiver == null) { return; } IAudioService service = getService(); try { // eventReceiver != null service.registerMediaButtonEventReceiverForCalls(eventReceiver); } catch (RemoteException e) { Log.e(TAG, "Dead object in registerMediaButtonEventReceiverForCalls", e); } } /** * @hide */ public void unregisterMediaButtonEventReceiverForCalls() { IAudioService service = getService(); try { service.unregisterMediaButtonEventReceiverForCalls(); } catch (RemoteException e) { Log.e(TAG, "Dead object in unregisterMediaButtonEventReceiverForCalls", e); } helper.addMediaButtonListener(pi, eventReceiver, mContext); } /** Loading Loading @@ -2272,12 +2232,6 @@ public class AudioManager { * @hide */ public void unregisterMediaButtonIntent(PendingIntent pi) { IAudioService service = getService(); try { service.unregisterMediaButtonIntent(pi); } catch (RemoteException e) { Log.e(TAG, "Dead object in unregisterMediaButtonIntent"+e); } MediaSessionLegacyHelper helper = MediaSessionLegacyHelper.getHelper(mContext); helper.removeMediaButtonListener(pi); } Loading Loading @@ -2442,46 +2396,6 @@ public class AudioManager { } } /** * @hide * Request the user of a RemoteControlClient to seek to the given playback position. * @param generationId the RemoteControlClient generation counter for which this request is * issued. Requests for an older generation than current one will be ignored. * @param timeMs the time in ms to seek to, must be positive. */ public void setRemoteControlClientPlaybackPosition(int generationId, long timeMs) { if (timeMs < 0) { return; } IAudioService service = getService(); try { service.setRemoteControlClientPlaybackPosition(generationId, timeMs); } catch (RemoteException e) { Log.e(TAG, "Dead object in setRccPlaybackPosition("+ generationId + ", " + timeMs + ")", e); } } /** * @hide * Notify the user of a RemoteControlClient that it should update its metadata with the * new value for the given key. * @param generationId the RemoteControlClient generation counter for which this request is * issued. Requests for an older generation than current one will be ignored. * @param key the metadata key for which a new value exists * @param value the new metadata value */ public void updateRemoteControlClientMetadata(int generationId, int key, Rating value) { IAudioService service = getService(); try { service.updateRemoteControlClientMetadata(generationId, key, value); } catch (RemoteException e) { Log.e(TAG, "Dead object in updateRemoteControlClientMetadata("+ generationId + ", " + key +", " + value + ")", e); } } /** * @hide * Reload audio settings. This method is called by Settings backup Loading Loading @@ -2898,26 +2812,20 @@ public class AudioManager { * @hide */ public int getRemoteStreamVolume() { try { return getService().getRemoteStreamVolume(); } catch (RemoteException e) { Log.w(TAG, "Error getting remote stream volume", e); // TODO STOPSHIP switch callers to use media sessions instead Log.e(TAG, "Need to implement new Remote Volume!"); return 0; } } /** * Only useful for volume controllers. * @hide */ public int getRemoteStreamMaxVolume() { try { return getService().getRemoteStreamMaxVolume(); } catch (RemoteException e) { Log.w(TAG, "Error getting remote stream max volume", e); // TODO STOPSHIP switch callers to use media sessions instead Log.e(TAG, "Need to implement new Remote Volume!"); return 0; } } /** * Only useful for volume controllers. Loading media/java/android/media/AudioService.java +0 −56 Original line number Diff line number Diff line Loading @@ -4412,68 +4412,12 @@ public class AudioService extends IAudioService.Stub { mMediaFocusControl.remoteControlDisplayWantsPlaybackPositionSync(rcd, wantsSync); } public void registerMediaButtonEventReceiverForCalls(ComponentName c) { mMediaFocusControl.registerMediaButtonEventReceiverForCalls(c); } public void unregisterMediaButtonEventReceiverForCalls() { mMediaFocusControl.unregisterMediaButtonEventReceiverForCalls(); } public void registerMediaButtonIntent(PendingIntent pi, ComponentName c, IBinder token) { mMediaFocusControl.registerMediaButtonIntent(pi, c, token); } public void unregisterMediaButtonIntent(PendingIntent pi) { mMediaFocusControl.unregisterMediaButtonIntent(pi); } public int registerRemoteControlClient(PendingIntent mediaIntent, IRemoteControlClient rcClient, String callingPckg) { return mMediaFocusControl.registerRemoteControlClient(mediaIntent, rcClient, callingPckg); } public void unregisterRemoteControlClient(PendingIntent mediaIntent, IRemoteControlClient rcClient) { mMediaFocusControl.unregisterRemoteControlClient(mediaIntent, rcClient); } public void setRemoteControlClientPlaybackPosition(int generationId, long timeMs) { mMediaFocusControl.setRemoteControlClientPlaybackPosition(generationId, timeMs); } public void updateRemoteControlClientMetadata(int generationId, int key, Rating value) { mMediaFocusControl.updateRemoteControlClientMetadata(generationId, key, value); } public void registerRemoteVolumeObserverForRcc(int rccId, IRemoteVolumeObserver rvo) { mMediaFocusControl.registerRemoteVolumeObserverForRcc(rccId, rvo); } @Override public int getRemoteStreamVolume() { return mMediaFocusControl.getRemoteStreamVolume(); } @Override public int getRemoteStreamMaxVolume() { return mMediaFocusControl.getRemoteStreamMaxVolume(); } @Override public void setRemoteStreamVolume(int index) { enforceSelfOrSystemUI("set the remote stream volume"); mMediaFocusControl.setRemoteStreamVolume(index); } public void setPlaybackStateForRcc(int rccId, int state, long timeMs, float speed) { mMediaFocusControl.setPlaybackStateForRcc(rccId, state, timeMs, speed); } public void setPlaybackInfoForRcc(int rccId, int what, int value) { mMediaFocusControl.setPlaybackInfoForRcc(rccId, what, value); } //========================================================================================== // Audio Focus //========================================================================================== Loading media/java/android/media/IAudioService.aidl +0 −41 Original line number Diff line number Diff line Loading @@ -122,12 +122,6 @@ interface IAudioService { int getCurrentAudioFocus(); void registerMediaButtonIntent(in PendingIntent pi, in ComponentName c, IBinder token); oneway void unregisterMediaButtonIntent(in PendingIntent pi); oneway void registerMediaButtonEventReceiverForCalls(in ComponentName c); oneway void unregisterMediaButtonEventReceiverForCalls(); /** * Register an IRemoteControlDisplay. * Success of registration is subject to a check on Loading Loading @@ -180,41 +174,6 @@ interface IAudioService { */ oneway void remoteControlDisplayWantsPlaybackPositionSync(in IRemoteControlDisplay rcd, boolean wantsSync); /** * Request the user of a RemoteControlClient to seek to the given playback position. * @param generationId the RemoteControlClient generation counter for which this request is * issued. Requests for an older generation than current one will be ignored. * @param timeMs the time in ms to seek to, must be positive. */ void setRemoteControlClientPlaybackPosition(int generationId, long timeMs); /** * Notify the user of a RemoteControlClient that it should update its metadata with the * new value for the given key. * @param generationId the RemoteControlClient generation counter for which this request is * issued. Requests for an older generation than current one will be ignored. * @param key the metadata key for which a new value exists * @param value the new metadata value */ void updateRemoteControlClientMetadata(int generationId, int key, in Rating value); /** * Do not use directly, use instead * {@link android.media.AudioManager#registerRemoteControlClient(RemoteControlClient)} */ int registerRemoteControlClient(in PendingIntent mediaIntent, in IRemoteControlClient rcClient, in String callingPackageName); /** * Do not use directly, use instead * {@link android.media.AudioManager#unregisterRemoteControlClient(RemoteControlClient)} */ oneway void unregisterRemoteControlClient(in PendingIntent mediaIntent, in IRemoteControlClient rcClient); oneway void setPlaybackInfoForRcc(int rccId, int what, int value); void setPlaybackStateForRcc(int rccId, int state, long timeMs, float speed); int getRemoteStreamMaxVolume(); int getRemoteStreamVolume(); oneway void registerRemoteVolumeObserverForRcc(int rccId, in IRemoteVolumeObserver rvo); void startBluetoothSco(IBinder cb, int targetSdkVersion); void startBluetoothScoVirtualCall(IBinder cb); Loading media/java/android/media/MediaFocusControl.java +0 −232 Original line number Diff line number Diff line Loading @@ -379,32 +379,11 @@ public class MediaFocusControl implements OnFinished { onReevaluateRemote(); break; case MSG_RCC_NEW_PLAYBACK_INFO: onNewPlaybackInfoForRcc(msg.arg1 /* rccId */, msg.arg2 /* key */, ((Integer)msg.obj).intValue() /* value */); break; case MSG_RCC_NEW_VOLUME_OBS: onRegisterVolumeObserverForRcc(msg.arg1 /* rccId */, (IRemoteVolumeObserver)msg.obj /* rvo */); break; case MSG_RCC_NEW_PLAYBACK_STATE: onNewPlaybackStateForRcc(msg.arg1 /* rccId */, msg.arg2 /* state */, (PlayerRecord.RccPlaybackState)msg.obj /* newState */); break; case MSG_RCC_SEEK_REQUEST: onSetRemoteControlClientPlaybackPosition( msg.arg1 /* generationId */, ((Long)msg.obj).longValue() /* timeMs */); break; case MSG_RCC_UPDATE_METADATA: onUpdateRemoteControlClientMetadata(msg.arg1 /*genId*/, msg.arg2 /*key*/, (Rating) msg.obj /* value */); break; case MSG_RCDISPLAY_INIT_INFO: // msg.obj is guaranteed to be non null onRcDisplayInitInfo((IRemoteControlDisplay)msg.obj /*newRcd*/, Loading Loading @@ -2003,217 +1982,6 @@ public class MediaFocusControl implements OnFinished { } } protected void setRemoteControlClientPlaybackPosition(int generationId, long timeMs) { // ignore position change requests if invalid generation ID synchronized(mPRStack) { synchronized(mCurrentRcLock) { if (mCurrentRcClientGen != generationId) { return; } } } // discard any unprocessed seek request in the message queue, and replace with latest sendMsg(mEventHandler, MSG_RCC_SEEK_REQUEST, SENDMSG_REPLACE, generationId /* arg1 */, 0 /* arg2 ignored*/, new Long(timeMs) /* obj */, 0 /* delay */); } private void onSetRemoteControlClientPlaybackPosition(int generationId, long timeMs) { if(DEBUG_RC) Log.d(TAG, "onSetRemoteControlClientPlaybackPosition(genId=" + generationId + ", timeMs=" + timeMs + ")"); synchronized(mPRStack) { synchronized(mCurrentRcLock) { if ((mCurrentRcClient != null) && (mCurrentRcClientGen == generationId)) { // tell the current client to seek to the requested location try { mCurrentRcClient.seekTo(generationId, timeMs); } catch (RemoteException e) { Log.e(TAG, "Current valid remote client is dead: "+e); mCurrentRcClient = null; } } } } } protected void updateRemoteControlClientMetadata(int genId, int key, Rating value) { sendMsg(mEventHandler, MSG_RCC_UPDATE_METADATA, SENDMSG_QUEUE, genId /* arg1 */, key /* arg2 */, value /* obj */, 0 /* delay */); } private void onUpdateRemoteControlClientMetadata(int genId, int key, Rating value) { if(DEBUG_RC) Log.d(TAG, "onUpdateRemoteControlClientMetadata(genId=" + genId + ", what=" + key + ",rating=" + value + ")"); synchronized(mPRStack) { synchronized(mCurrentRcLock) { if ((mCurrentRcClient != null) && (mCurrentRcClientGen == genId)) { try { switch (key) { case MediaMetadataEditor.RATING_KEY_BY_USER: mCurrentRcClient.updateMetadata(genId, key, value); break; default: Log.e(TAG, "unhandled metadata key " + key + " update for RCC " + genId); break; } } catch (RemoteException e) { Log.e(TAG, "Current valid remote client is dead", e); mCurrentRcClient = null; } } } } } protected void setPlaybackInfoForRcc(int rccId, int what, int value) { sendMsg(mEventHandler, MSG_RCC_NEW_PLAYBACK_INFO, SENDMSG_QUEUE, rccId /* arg1 */, what /* arg2 */, Integer.valueOf(value) /* obj */, 0 /* delay */); } // handler for MSG_RCC_NEW_PLAYBACK_INFO private void onNewPlaybackInfoForRcc(int rccId, int key, int value) { if(DEBUG_RC) Log.d(TAG, "onNewPlaybackInfoForRcc(id=" + rccId + ", what=" + key + ",val=" + value + ")"); synchronized(mPRStack) { // iterating from top of stack as playback information changes are more likely // on entries at the top of the remote control stack try { for (int index = mPRStack.size()-1; index >= 0; index--) { final PlayerRecord prse = mPRStack.elementAt(index); if (prse.getRccId() == rccId) { switch (key) { case RemoteControlClient.PLAYBACKINFO_PLAYBACK_TYPE: prse.mPlaybackType = value; postReevaluateRemote(); break; case RemoteControlClient.PLAYBACKINFO_VOLUME: prse.mPlaybackVolume = value; synchronized (mMainRemote) { if (rccId == mMainRemote.mRccId) { mMainRemote.mVolume = value; mVolumeController.postHasNewRemotePlaybackInfo(); } } break; case RemoteControlClient.PLAYBACKINFO_VOLUME_MAX: prse.mPlaybackVolumeMax = value; synchronized (mMainRemote) { if (rccId == mMainRemote.mRccId) { mMainRemote.mVolumeMax = value; mVolumeController.postHasNewRemotePlaybackInfo(); } } break; case RemoteControlClient.PLAYBACKINFO_VOLUME_HANDLING: prse.mPlaybackVolumeHandling = value; synchronized (mMainRemote) { if (rccId == mMainRemote.mRccId) { mMainRemote.mVolumeHandling = value; mVolumeController.postHasNewRemotePlaybackInfo(); } } break; case RemoteControlClient.PLAYBACKINFO_USES_STREAM: prse.mPlaybackStream = value; break; default: Log.e(TAG, "unhandled key " + key + " for RCC " + rccId); break; } return; } }//for } catch (ArrayIndexOutOfBoundsException e) { // not expected to happen, indicates improper concurrent modification Log.e(TAG, "Wrong index mPRStack on onNewPlaybackInfoForRcc, lock error? ", e); } } } protected void setPlaybackStateForRcc(int rccId, int state, long timeMs, float speed) { sendMsg(mEventHandler, MSG_RCC_NEW_PLAYBACK_STATE, SENDMSG_QUEUE, rccId /* arg1 */, state /* arg2 */, new PlayerRecord.RccPlaybackState(state, timeMs, speed) /* obj */, 0 /* delay */); } private void onNewPlaybackStateForRcc(int rccId, int state, PlayerRecord.RccPlaybackState newState) { if(DEBUG_RC) Log.d(TAG, "onNewPlaybackStateForRcc(id=" + rccId + ", state=" + state + ", time=" + newState.mPositionMs + ", speed=" + newState.mSpeed + ")"); synchronized(mPRStack) { if (mPRStack.empty()) { return; } PlayerRecord oldTopPrse = mPRStack.lastElement(); // top of the stack before any changes PlayerRecord prse = null; int lastPlayingIndex = mPRStack.size(); int inStackIndex = -1; try { // go through the stack from the top to figure out who's playing, and the position // of this RemoteControlClient (note that it may not be in the stack) for (int index = mPRStack.size()-1; index >= 0; index--) { prse = mPRStack.elementAt(index); if (prse.getRccId() == rccId) { inStackIndex = index; prse.mPlaybackState = newState; } if (prse.isPlaybackActive()) { lastPlayingIndex = index; } } if (inStackIndex != -1) { // is in the stack prse = mPRStack.elementAt(inStackIndex); synchronized (mMainRemote) { if (rccId == mMainRemote.mRccId) { mMainRemoteIsActive = isPlaystateActive(state); postReevaluateRemote(); } } if (mPRStack.size() > 1) { // no need to remove and add if stack contains only 1 // remove it from its old location in the stack mPRStack.removeElementAt(inStackIndex); if (prse.isPlaybackActive()) { // and put it at the top mPRStack.push(prse); } else { // and put it after the ones with active playback if (inStackIndex > lastPlayingIndex) { mPRStack.add(lastPlayingIndex, prse); } else { mPRStack.add(lastPlayingIndex - 1, prse); } } } if (oldTopPrse != mPRStack.lastElement()) { // the top of the stack changed: final ComponentName target = mPRStack.lastElement().getMediaButtonReceiver(); if (target != null) { // post message to persist the default media button receiver mEventHandler.sendMessage( mEventHandler.obtainMessage( MSG_PERSIST_MEDIABUTTONRECEIVER, 0, 0, target/*obj*/) ); } // reevaluate the display checkUpdateRemoteControlDisplay_syncPrs(RC_INFO_ALL); } } } catch (ArrayIndexOutOfBoundsException e) { // not expected to happen, indicates improper concurrent modification or bad index Log.e(TAG, "Wrong index (inStack=" + inStackIndex + " lastPlaying=" + lastPlayingIndex + " size=" + mPRStack.size() + "accessing PlayerRecord stack in onNewPlaybackStateForRcc", e); } } } protected void registerRemoteVolumeObserverForRcc(int rccId, IRemoteVolumeObserver rvo) { sendMsg(mEventHandler, MSG_RCC_NEW_VOLUME_OBS, SENDMSG_QUEUE, rccId /* arg1 */, 0, rvo /* obj */, 0 /* delay */); } // handler for MSG_RCC_NEW_VOLUME_OBS private void onRegisterVolumeObserverForRcc(int rccId, IRemoteVolumeObserver rvo) { synchronized(mPRStack) { Loading media/java/android/media/RemoteController.java +8 −35 Original line number Diff line number Diff line Loading @@ -361,19 +361,11 @@ public final class RemoteController if (timeMs < 0) { throw new IllegalArgumentException("illegal negative time value"); } if (USE_SESSIONS) { synchronized (mInfoLock) { if (mCurrentSession != null) { mCurrentSession.getTransportControls().seekTo(timeMs); } } } else { final int genId; synchronized (mGenLock) { genId = mClientGenerationIdCurrent; } mAudioManager.setRemoteControlClientPlaybackPosition(genId, timeMs); } return true; } Loading Loading @@ -534,7 +526,6 @@ public final class RemoteController if (!mMetadataChanged) { return; } if (USE_SESSIONS) { synchronized (mInfoLock) { if (mCurrentSession != null) { if (mEditorMetadata.containsKey( Loading @@ -547,24 +538,6 @@ public final class RemoteController } } } } else { final int genId; synchronized(mGenLock) { genId = mClientGenerationIdCurrent; } synchronized(mInfoLock) { if (mEditorMetadata.containsKey( String.valueOf(MediaMetadataEditor.RATING_KEY_BY_USER))) { Rating rating = (Rating) getObject( MediaMetadataEditor.RATING_KEY_BY_USER, null); mAudioManager.updateRemoteControlClientMetadata(genId, MediaMetadataEditor.RATING_KEY_BY_USER, rating); } else { Log.e(TAG, "no metadata to apply"); } } } // NOT setting mApplied to true as this type of MetadataEditor will be applied // multiple times, whenever the user of a RemoteController needs to change the // metadata (e.g. user changes the rating of a song more than once during playback) Loading Loading
media/java/android/media/AudioManager.java +7 −99 Original line number Diff line number Diff line Loading @@ -2194,48 +2194,8 @@ public class AudioManager { Log.e(TAG, "Cannot call registerMediaButtonIntent() with a null parameter"); return; } IAudioService service = getService(); try { // pi != null, this is currently still needed to support across // reboot launching of the last app. service.registerMediaButtonIntent(pi, eventReceiver, eventReceiver == null ? mToken : null); } catch (RemoteException e) { Log.e(TAG, "Dead object in registerMediaButtonIntent"+e); } MediaSessionLegacyHelper helper = MediaSessionLegacyHelper.getHelper(mContext); helper.addMediaButtonListener(pi, mContext); } /** * @hide * Used internally by telephony package to register an intent receiver for ACTION_MEDIA_BUTTON. * @param eventReceiver the component that will receive the media button key events, * no-op if eventReceiver is null */ public void registerMediaButtonEventReceiverForCalls(ComponentName eventReceiver) { if (eventReceiver == null) { return; } IAudioService service = getService(); try { // eventReceiver != null service.registerMediaButtonEventReceiverForCalls(eventReceiver); } catch (RemoteException e) { Log.e(TAG, "Dead object in registerMediaButtonEventReceiverForCalls", e); } } /** * @hide */ public void unregisterMediaButtonEventReceiverForCalls() { IAudioService service = getService(); try { service.unregisterMediaButtonEventReceiverForCalls(); } catch (RemoteException e) { Log.e(TAG, "Dead object in unregisterMediaButtonEventReceiverForCalls", e); } helper.addMediaButtonListener(pi, eventReceiver, mContext); } /** Loading Loading @@ -2272,12 +2232,6 @@ public class AudioManager { * @hide */ public void unregisterMediaButtonIntent(PendingIntent pi) { IAudioService service = getService(); try { service.unregisterMediaButtonIntent(pi); } catch (RemoteException e) { Log.e(TAG, "Dead object in unregisterMediaButtonIntent"+e); } MediaSessionLegacyHelper helper = MediaSessionLegacyHelper.getHelper(mContext); helper.removeMediaButtonListener(pi); } Loading Loading @@ -2442,46 +2396,6 @@ public class AudioManager { } } /** * @hide * Request the user of a RemoteControlClient to seek to the given playback position. * @param generationId the RemoteControlClient generation counter for which this request is * issued. Requests for an older generation than current one will be ignored. * @param timeMs the time in ms to seek to, must be positive. */ public void setRemoteControlClientPlaybackPosition(int generationId, long timeMs) { if (timeMs < 0) { return; } IAudioService service = getService(); try { service.setRemoteControlClientPlaybackPosition(generationId, timeMs); } catch (RemoteException e) { Log.e(TAG, "Dead object in setRccPlaybackPosition("+ generationId + ", " + timeMs + ")", e); } } /** * @hide * Notify the user of a RemoteControlClient that it should update its metadata with the * new value for the given key. * @param generationId the RemoteControlClient generation counter for which this request is * issued. Requests for an older generation than current one will be ignored. * @param key the metadata key for which a new value exists * @param value the new metadata value */ public void updateRemoteControlClientMetadata(int generationId, int key, Rating value) { IAudioService service = getService(); try { service.updateRemoteControlClientMetadata(generationId, key, value); } catch (RemoteException e) { Log.e(TAG, "Dead object in updateRemoteControlClientMetadata("+ generationId + ", " + key +", " + value + ")", e); } } /** * @hide * Reload audio settings. This method is called by Settings backup Loading Loading @@ -2898,26 +2812,20 @@ public class AudioManager { * @hide */ public int getRemoteStreamVolume() { try { return getService().getRemoteStreamVolume(); } catch (RemoteException e) { Log.w(TAG, "Error getting remote stream volume", e); // TODO STOPSHIP switch callers to use media sessions instead Log.e(TAG, "Need to implement new Remote Volume!"); return 0; } } /** * Only useful for volume controllers. * @hide */ public int getRemoteStreamMaxVolume() { try { return getService().getRemoteStreamMaxVolume(); } catch (RemoteException e) { Log.w(TAG, "Error getting remote stream max volume", e); // TODO STOPSHIP switch callers to use media sessions instead Log.e(TAG, "Need to implement new Remote Volume!"); return 0; } } /** * Only useful for volume controllers. Loading
media/java/android/media/AudioService.java +0 −56 Original line number Diff line number Diff line Loading @@ -4412,68 +4412,12 @@ public class AudioService extends IAudioService.Stub { mMediaFocusControl.remoteControlDisplayWantsPlaybackPositionSync(rcd, wantsSync); } public void registerMediaButtonEventReceiverForCalls(ComponentName c) { mMediaFocusControl.registerMediaButtonEventReceiverForCalls(c); } public void unregisterMediaButtonEventReceiverForCalls() { mMediaFocusControl.unregisterMediaButtonEventReceiverForCalls(); } public void registerMediaButtonIntent(PendingIntent pi, ComponentName c, IBinder token) { mMediaFocusControl.registerMediaButtonIntent(pi, c, token); } public void unregisterMediaButtonIntent(PendingIntent pi) { mMediaFocusControl.unregisterMediaButtonIntent(pi); } public int registerRemoteControlClient(PendingIntent mediaIntent, IRemoteControlClient rcClient, String callingPckg) { return mMediaFocusControl.registerRemoteControlClient(mediaIntent, rcClient, callingPckg); } public void unregisterRemoteControlClient(PendingIntent mediaIntent, IRemoteControlClient rcClient) { mMediaFocusControl.unregisterRemoteControlClient(mediaIntent, rcClient); } public void setRemoteControlClientPlaybackPosition(int generationId, long timeMs) { mMediaFocusControl.setRemoteControlClientPlaybackPosition(generationId, timeMs); } public void updateRemoteControlClientMetadata(int generationId, int key, Rating value) { mMediaFocusControl.updateRemoteControlClientMetadata(generationId, key, value); } public void registerRemoteVolumeObserverForRcc(int rccId, IRemoteVolumeObserver rvo) { mMediaFocusControl.registerRemoteVolumeObserverForRcc(rccId, rvo); } @Override public int getRemoteStreamVolume() { return mMediaFocusControl.getRemoteStreamVolume(); } @Override public int getRemoteStreamMaxVolume() { return mMediaFocusControl.getRemoteStreamMaxVolume(); } @Override public void setRemoteStreamVolume(int index) { enforceSelfOrSystemUI("set the remote stream volume"); mMediaFocusControl.setRemoteStreamVolume(index); } public void setPlaybackStateForRcc(int rccId, int state, long timeMs, float speed) { mMediaFocusControl.setPlaybackStateForRcc(rccId, state, timeMs, speed); } public void setPlaybackInfoForRcc(int rccId, int what, int value) { mMediaFocusControl.setPlaybackInfoForRcc(rccId, what, value); } //========================================================================================== // Audio Focus //========================================================================================== Loading
media/java/android/media/IAudioService.aidl +0 −41 Original line number Diff line number Diff line Loading @@ -122,12 +122,6 @@ interface IAudioService { int getCurrentAudioFocus(); void registerMediaButtonIntent(in PendingIntent pi, in ComponentName c, IBinder token); oneway void unregisterMediaButtonIntent(in PendingIntent pi); oneway void registerMediaButtonEventReceiverForCalls(in ComponentName c); oneway void unregisterMediaButtonEventReceiverForCalls(); /** * Register an IRemoteControlDisplay. * Success of registration is subject to a check on Loading Loading @@ -180,41 +174,6 @@ interface IAudioService { */ oneway void remoteControlDisplayWantsPlaybackPositionSync(in IRemoteControlDisplay rcd, boolean wantsSync); /** * Request the user of a RemoteControlClient to seek to the given playback position. * @param generationId the RemoteControlClient generation counter for which this request is * issued. Requests for an older generation than current one will be ignored. * @param timeMs the time in ms to seek to, must be positive. */ void setRemoteControlClientPlaybackPosition(int generationId, long timeMs); /** * Notify the user of a RemoteControlClient that it should update its metadata with the * new value for the given key. * @param generationId the RemoteControlClient generation counter for which this request is * issued. Requests for an older generation than current one will be ignored. * @param key the metadata key for which a new value exists * @param value the new metadata value */ void updateRemoteControlClientMetadata(int generationId, int key, in Rating value); /** * Do not use directly, use instead * {@link android.media.AudioManager#registerRemoteControlClient(RemoteControlClient)} */ int registerRemoteControlClient(in PendingIntent mediaIntent, in IRemoteControlClient rcClient, in String callingPackageName); /** * Do not use directly, use instead * {@link android.media.AudioManager#unregisterRemoteControlClient(RemoteControlClient)} */ oneway void unregisterRemoteControlClient(in PendingIntent mediaIntent, in IRemoteControlClient rcClient); oneway void setPlaybackInfoForRcc(int rccId, int what, int value); void setPlaybackStateForRcc(int rccId, int state, long timeMs, float speed); int getRemoteStreamMaxVolume(); int getRemoteStreamVolume(); oneway void registerRemoteVolumeObserverForRcc(int rccId, in IRemoteVolumeObserver rvo); void startBluetoothSco(IBinder cb, int targetSdkVersion); void startBluetoothScoVirtualCall(IBinder cb); Loading
media/java/android/media/MediaFocusControl.java +0 −232 Original line number Diff line number Diff line Loading @@ -379,32 +379,11 @@ public class MediaFocusControl implements OnFinished { onReevaluateRemote(); break; case MSG_RCC_NEW_PLAYBACK_INFO: onNewPlaybackInfoForRcc(msg.arg1 /* rccId */, msg.arg2 /* key */, ((Integer)msg.obj).intValue() /* value */); break; case MSG_RCC_NEW_VOLUME_OBS: onRegisterVolumeObserverForRcc(msg.arg1 /* rccId */, (IRemoteVolumeObserver)msg.obj /* rvo */); break; case MSG_RCC_NEW_PLAYBACK_STATE: onNewPlaybackStateForRcc(msg.arg1 /* rccId */, msg.arg2 /* state */, (PlayerRecord.RccPlaybackState)msg.obj /* newState */); break; case MSG_RCC_SEEK_REQUEST: onSetRemoteControlClientPlaybackPosition( msg.arg1 /* generationId */, ((Long)msg.obj).longValue() /* timeMs */); break; case MSG_RCC_UPDATE_METADATA: onUpdateRemoteControlClientMetadata(msg.arg1 /*genId*/, msg.arg2 /*key*/, (Rating) msg.obj /* value */); break; case MSG_RCDISPLAY_INIT_INFO: // msg.obj is guaranteed to be non null onRcDisplayInitInfo((IRemoteControlDisplay)msg.obj /*newRcd*/, Loading Loading @@ -2003,217 +1982,6 @@ public class MediaFocusControl implements OnFinished { } } protected void setRemoteControlClientPlaybackPosition(int generationId, long timeMs) { // ignore position change requests if invalid generation ID synchronized(mPRStack) { synchronized(mCurrentRcLock) { if (mCurrentRcClientGen != generationId) { return; } } } // discard any unprocessed seek request in the message queue, and replace with latest sendMsg(mEventHandler, MSG_RCC_SEEK_REQUEST, SENDMSG_REPLACE, generationId /* arg1 */, 0 /* arg2 ignored*/, new Long(timeMs) /* obj */, 0 /* delay */); } private void onSetRemoteControlClientPlaybackPosition(int generationId, long timeMs) { if(DEBUG_RC) Log.d(TAG, "onSetRemoteControlClientPlaybackPosition(genId=" + generationId + ", timeMs=" + timeMs + ")"); synchronized(mPRStack) { synchronized(mCurrentRcLock) { if ((mCurrentRcClient != null) && (mCurrentRcClientGen == generationId)) { // tell the current client to seek to the requested location try { mCurrentRcClient.seekTo(generationId, timeMs); } catch (RemoteException e) { Log.e(TAG, "Current valid remote client is dead: "+e); mCurrentRcClient = null; } } } } } protected void updateRemoteControlClientMetadata(int genId, int key, Rating value) { sendMsg(mEventHandler, MSG_RCC_UPDATE_METADATA, SENDMSG_QUEUE, genId /* arg1 */, key /* arg2 */, value /* obj */, 0 /* delay */); } private void onUpdateRemoteControlClientMetadata(int genId, int key, Rating value) { if(DEBUG_RC) Log.d(TAG, "onUpdateRemoteControlClientMetadata(genId=" + genId + ", what=" + key + ",rating=" + value + ")"); synchronized(mPRStack) { synchronized(mCurrentRcLock) { if ((mCurrentRcClient != null) && (mCurrentRcClientGen == genId)) { try { switch (key) { case MediaMetadataEditor.RATING_KEY_BY_USER: mCurrentRcClient.updateMetadata(genId, key, value); break; default: Log.e(TAG, "unhandled metadata key " + key + " update for RCC " + genId); break; } } catch (RemoteException e) { Log.e(TAG, "Current valid remote client is dead", e); mCurrentRcClient = null; } } } } } protected void setPlaybackInfoForRcc(int rccId, int what, int value) { sendMsg(mEventHandler, MSG_RCC_NEW_PLAYBACK_INFO, SENDMSG_QUEUE, rccId /* arg1 */, what /* arg2 */, Integer.valueOf(value) /* obj */, 0 /* delay */); } // handler for MSG_RCC_NEW_PLAYBACK_INFO private void onNewPlaybackInfoForRcc(int rccId, int key, int value) { if(DEBUG_RC) Log.d(TAG, "onNewPlaybackInfoForRcc(id=" + rccId + ", what=" + key + ",val=" + value + ")"); synchronized(mPRStack) { // iterating from top of stack as playback information changes are more likely // on entries at the top of the remote control stack try { for (int index = mPRStack.size()-1; index >= 0; index--) { final PlayerRecord prse = mPRStack.elementAt(index); if (prse.getRccId() == rccId) { switch (key) { case RemoteControlClient.PLAYBACKINFO_PLAYBACK_TYPE: prse.mPlaybackType = value; postReevaluateRemote(); break; case RemoteControlClient.PLAYBACKINFO_VOLUME: prse.mPlaybackVolume = value; synchronized (mMainRemote) { if (rccId == mMainRemote.mRccId) { mMainRemote.mVolume = value; mVolumeController.postHasNewRemotePlaybackInfo(); } } break; case RemoteControlClient.PLAYBACKINFO_VOLUME_MAX: prse.mPlaybackVolumeMax = value; synchronized (mMainRemote) { if (rccId == mMainRemote.mRccId) { mMainRemote.mVolumeMax = value; mVolumeController.postHasNewRemotePlaybackInfo(); } } break; case RemoteControlClient.PLAYBACKINFO_VOLUME_HANDLING: prse.mPlaybackVolumeHandling = value; synchronized (mMainRemote) { if (rccId == mMainRemote.mRccId) { mMainRemote.mVolumeHandling = value; mVolumeController.postHasNewRemotePlaybackInfo(); } } break; case RemoteControlClient.PLAYBACKINFO_USES_STREAM: prse.mPlaybackStream = value; break; default: Log.e(TAG, "unhandled key " + key + " for RCC " + rccId); break; } return; } }//for } catch (ArrayIndexOutOfBoundsException e) { // not expected to happen, indicates improper concurrent modification Log.e(TAG, "Wrong index mPRStack on onNewPlaybackInfoForRcc, lock error? ", e); } } } protected void setPlaybackStateForRcc(int rccId, int state, long timeMs, float speed) { sendMsg(mEventHandler, MSG_RCC_NEW_PLAYBACK_STATE, SENDMSG_QUEUE, rccId /* arg1 */, state /* arg2 */, new PlayerRecord.RccPlaybackState(state, timeMs, speed) /* obj */, 0 /* delay */); } private void onNewPlaybackStateForRcc(int rccId, int state, PlayerRecord.RccPlaybackState newState) { if(DEBUG_RC) Log.d(TAG, "onNewPlaybackStateForRcc(id=" + rccId + ", state=" + state + ", time=" + newState.mPositionMs + ", speed=" + newState.mSpeed + ")"); synchronized(mPRStack) { if (mPRStack.empty()) { return; } PlayerRecord oldTopPrse = mPRStack.lastElement(); // top of the stack before any changes PlayerRecord prse = null; int lastPlayingIndex = mPRStack.size(); int inStackIndex = -1; try { // go through the stack from the top to figure out who's playing, and the position // of this RemoteControlClient (note that it may not be in the stack) for (int index = mPRStack.size()-1; index >= 0; index--) { prse = mPRStack.elementAt(index); if (prse.getRccId() == rccId) { inStackIndex = index; prse.mPlaybackState = newState; } if (prse.isPlaybackActive()) { lastPlayingIndex = index; } } if (inStackIndex != -1) { // is in the stack prse = mPRStack.elementAt(inStackIndex); synchronized (mMainRemote) { if (rccId == mMainRemote.mRccId) { mMainRemoteIsActive = isPlaystateActive(state); postReevaluateRemote(); } } if (mPRStack.size() > 1) { // no need to remove and add if stack contains only 1 // remove it from its old location in the stack mPRStack.removeElementAt(inStackIndex); if (prse.isPlaybackActive()) { // and put it at the top mPRStack.push(prse); } else { // and put it after the ones with active playback if (inStackIndex > lastPlayingIndex) { mPRStack.add(lastPlayingIndex, prse); } else { mPRStack.add(lastPlayingIndex - 1, prse); } } } if (oldTopPrse != mPRStack.lastElement()) { // the top of the stack changed: final ComponentName target = mPRStack.lastElement().getMediaButtonReceiver(); if (target != null) { // post message to persist the default media button receiver mEventHandler.sendMessage( mEventHandler.obtainMessage( MSG_PERSIST_MEDIABUTTONRECEIVER, 0, 0, target/*obj*/) ); } // reevaluate the display checkUpdateRemoteControlDisplay_syncPrs(RC_INFO_ALL); } } } catch (ArrayIndexOutOfBoundsException e) { // not expected to happen, indicates improper concurrent modification or bad index Log.e(TAG, "Wrong index (inStack=" + inStackIndex + " lastPlaying=" + lastPlayingIndex + " size=" + mPRStack.size() + "accessing PlayerRecord stack in onNewPlaybackStateForRcc", e); } } } protected void registerRemoteVolumeObserverForRcc(int rccId, IRemoteVolumeObserver rvo) { sendMsg(mEventHandler, MSG_RCC_NEW_VOLUME_OBS, SENDMSG_QUEUE, rccId /* arg1 */, 0, rvo /* obj */, 0 /* delay */); } // handler for MSG_RCC_NEW_VOLUME_OBS private void onRegisterVolumeObserverForRcc(int rccId, IRemoteVolumeObserver rvo) { synchronized(mPRStack) { Loading
media/java/android/media/RemoteController.java +8 −35 Original line number Diff line number Diff line Loading @@ -361,19 +361,11 @@ public final class RemoteController if (timeMs < 0) { throw new IllegalArgumentException("illegal negative time value"); } if (USE_SESSIONS) { synchronized (mInfoLock) { if (mCurrentSession != null) { mCurrentSession.getTransportControls().seekTo(timeMs); } } } else { final int genId; synchronized (mGenLock) { genId = mClientGenerationIdCurrent; } mAudioManager.setRemoteControlClientPlaybackPosition(genId, timeMs); } return true; } Loading Loading @@ -534,7 +526,6 @@ public final class RemoteController if (!mMetadataChanged) { return; } if (USE_SESSIONS) { synchronized (mInfoLock) { if (mCurrentSession != null) { if (mEditorMetadata.containsKey( Loading @@ -547,24 +538,6 @@ public final class RemoteController } } } } else { final int genId; synchronized(mGenLock) { genId = mClientGenerationIdCurrent; } synchronized(mInfoLock) { if (mEditorMetadata.containsKey( String.valueOf(MediaMetadataEditor.RATING_KEY_BY_USER))) { Rating rating = (Rating) getObject( MediaMetadataEditor.RATING_KEY_BY_USER, null); mAudioManager.updateRemoteControlClientMetadata(genId, MediaMetadataEditor.RATING_KEY_BY_USER, rating); } else { Log.e(TAG, "no metadata to apply"); } } } // NOT setting mApplied to true as this type of MetadataEditor will be applied // multiple times, whenever the user of a RemoteController needs to change the // metadata (e.g. user changes the rating of a song more than once during playback) Loading