Loading cmds/media/src/com/android/commands/media/Media.java +7 −5 Original line number Diff line number Diff line Loading @@ -46,6 +46,8 @@ import java.io.PrintStream; import java.util.List; public class Media extends BaseCommand { // This doesn't belongs to any package. Setting the package name to empty string. private static final String PACKAGE_NAME = ""; private ISessionManager mSessionService; /** Loading Loading @@ -104,7 +106,7 @@ public class Media extends BaseCommand { private void sendMediaKey(KeyEvent event) { try { mSessionService.dispatchMediaKeyEvent(event, false); mSessionService.dispatchMediaKeyEvent(PACKAGE_NAME, false, event, false); } catch (RemoteException e) { } } Loading Loading @@ -264,13 +266,13 @@ public class Media extends BaseCommand { } else if ("q".equals(line) || "quit".equals(line)) { break; } else if ("play".equals(line)) { mController.play(""); mController.play(PACKAGE_NAME); } else if ("pause".equals(line)) { mController.pause(""); mController.pause(PACKAGE_NAME); } else if ("next".equals(line)) { mController.next(""); mController.next(PACKAGE_NAME); } else if ("previous".equals(line)) { mController.previous(""); mController.previous(PACKAGE_NAME); } else { System.out.println("Invalid command: " + line); } Loading core/java/com/android/internal/policy/PhoneFallbackEventHandler.java +18 −6 Original line number Diff line number Diff line Loading @@ -23,7 +23,7 @@ import android.content.Context; import android.content.Intent; import android.content.res.Configuration; import android.media.AudioManager; import android.media.session.MediaSessionLegacyHelper; import android.media.session.MediaSessionManager; import android.os.UserHandle; import android.provider.Settings; import android.telephony.TelephonyManager; Loading @@ -48,6 +48,7 @@ public class PhoneFallbackEventHandler implements FallbackEventHandler { KeyguardManager mKeyguardManager; SearchManager mSearchManager; TelephonyManager mTelephonyManager; MediaSessionManager mMediaSessionManager; public PhoneFallbackEventHandler(Context context) { mContext = context; Loading Loading @@ -84,8 +85,7 @@ public class PhoneFallbackEventHandler implements FallbackEventHandler { case KeyEvent.KEYCODE_VOLUME_UP: case KeyEvent.KEYCODE_VOLUME_DOWN: case KeyEvent.KEYCODE_VOLUME_MUTE: { MediaSessionLegacyHelper.getHelper(mContext).sendVolumeKeyEvent( event, AudioManager.USE_DEFAULT_STREAM_TYPE, false); handleVolumeKeyEvent(event); return true; } Loading Loading @@ -216,8 +216,7 @@ public class PhoneFallbackEventHandler implements FallbackEventHandler { case KeyEvent.KEYCODE_VOLUME_DOWN: case KeyEvent.KEYCODE_VOLUME_MUTE: { if (!event.isCanceled()) { MediaSessionLegacyHelper.getHelper(mContext).sendVolumeKeyEvent( event, AudioManager.USE_DEFAULT_STREAM_TYPE, false); handleVolumeKeyEvent(event); } return true; } Loading Loading @@ -306,12 +305,25 @@ public class PhoneFallbackEventHandler implements FallbackEventHandler { return mAudioManager; } MediaSessionManager getMediaSessionManager() { if (mMediaSessionManager == null) { mMediaSessionManager = (MediaSessionManager) mContext.getSystemService(Context.MEDIA_SESSION_SERVICE); } return mMediaSessionManager; } void sendCloseSystemWindows() { PhoneWindow.sendCloseSystemWindows(mContext, null); } private void handleVolumeKeyEvent(KeyEvent keyEvent) { getMediaSessionManager().dispatchVolumeKeyEventAsSystemService(keyEvent, AudioManager.USE_DEFAULT_STREAM_TYPE); } private void handleMediaKeyEvent(KeyEvent keyEvent) { MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(keyEvent, false); getMediaSessionManager().dispatchMediaKeyEventAsSystemService(keyEvent); } private boolean isUserSetupComplete() { Loading core/java/com/android/internal/policy/PhoneWindow.java +20 −25 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import static android.view.WindowManager.LayoutParams.*; import android.app.ActivityManager; import android.app.SearchManager; import android.media.session.MediaSessionManager; import android.os.UserHandle; import android.text.TextUtils; Loading Loading @@ -74,7 +75,6 @@ import android.graphics.Color; import android.graphics.drawable.Drawable; import android.media.AudioManager; import android.media.session.MediaController; import android.media.session.MediaSessionLegacyHelper; import android.net.Uri; import android.os.Bundle; import android.os.Handler; Loading Loading @@ -252,6 +252,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { private AudioManager mAudioManager; private KeyguardManager mKeyguardManager; private MediaSessionManager mMediaSessionManager; private int mUiOptions = 0; Loading Loading @@ -1873,22 +1874,10 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { // If we have a session send it the volume command, otherwise // use the suggested stream. if (mMediaController != null) { int direction = 0; switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: direction = AudioManager.ADJUST_RAISE; break; case KeyEvent.KEYCODE_VOLUME_DOWN: direction = AudioManager.ADJUST_LOWER; break; case KeyEvent.KEYCODE_VOLUME_MUTE: direction = AudioManager.ADJUST_TOGGLE_MUTE; break; } mMediaController.adjustVolume(direction, AudioManager.FLAG_SHOW_UI); mMediaController.dispatchVolumeButtonEventAsSystemService(event); } else { MediaSessionLegacyHelper.getHelper(getContext()).sendVolumeKeyEvent( event, mVolumeControlStreamType, false); getMediaSessionManager().dispatchVolumeKeyEventAsSystemService(event, mVolumeControlStreamType); } return true; } Loading @@ -1906,7 +1895,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { case KeyEvent.KEYCODE_MEDIA_RECORD: case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: { if (mMediaController != null) { if (mMediaController.dispatchMediaButtonEvent(event)) { if (mMediaController.dispatchMediaButtonEventAsSystemService(event)) { return true; } } Loading Loading @@ -1948,6 +1937,14 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { return mAudioManager; } private MediaSessionManager getMediaSessionManager() { if (mMediaSessionManager == null) { mMediaSessionManager = (MediaSessionManager) getContext().getSystemService( Context.MEDIA_SESSION_SERVICE); } return mMediaSessionManager; } /** * A key was released and not handled by anything else in the window. * Loading @@ -1969,12 +1966,10 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { // If we have a session send it the volume command, otherwise // use the suggested stream. if (mMediaController != null) { final int flags = AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_VIBRATE | AudioManager.FLAG_FROM_KEY; mMediaController.adjustVolume(0, flags); mMediaController.dispatchVolumeButtonEventAsSystemService(event); } else { MediaSessionLegacyHelper.getHelper(getContext()).sendVolumeKeyEvent( event, mVolumeControlStreamType, false); getMediaSessionManager().dispatchVolumeKeyEventAsSystemService( event, mVolumeControlStreamType); } return true; } Loading @@ -1983,8 +1978,8 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { // doesn't have one of these. In this case, we execute it here and // eat the event instead, because we have mVolumeControlStreamType // and they don't. MediaSessionLegacyHelper.getHelper(getContext()).sendVolumeKeyEvent( event, AudioManager.USE_DEFAULT_STREAM_TYPE, false); getMediaSessionManager().dispatchVolumeKeyEventAsSystemService( event, AudioManager.USE_DEFAULT_STREAM_TYPE); return true; } // These are all the recognized media key codes in Loading @@ -2001,7 +1996,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { case KeyEvent.KEYCODE_MEDIA_RECORD: case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: { if (mMediaController != null) { if (mMediaController.dispatchMediaButtonEvent(event)) { if (mMediaController.dispatchMediaButtonEventAsSystemService(event)) { return true; } } Loading media/java/android/media/session/ISessionController.aidl +2 −2 Original line number Diff line number Diff line Loading @@ -37,7 +37,7 @@ import java.util.List; */ interface ISessionController { void sendCommand(String packageName, String command, in Bundle args, in ResultReceiver cb); boolean sendMediaButton(String packageName, in KeyEvent mediaButton); boolean sendMediaButton(String packageName, boolean asSystemService, in KeyEvent mediaButton); void registerCallbackListener(in ISessionControllerCallback cb); void unregisterCallbackListener(in ISessionControllerCallback cb); boolean isTransportControlEnabled(); Loading @@ -46,7 +46,7 @@ interface ISessionController { PendingIntent getLaunchPendingIntent(); long getFlags(); ParcelableVolumeInfo getVolumeAttributes(); void adjustVolume(String packageName, int direction, int flags); void adjustVolume(String packageName, boolean asSystemService, int direction, int flags); void setVolumeTo(String packageName, int value, int flags); // These commands are for the TransportControls Loading media/java/android/media/session/ISessionManager.aidl +5 −3 Original line number Diff line number Diff line Loading @@ -34,9 +34,11 @@ import android.view.KeyEvent; interface ISessionManager { ISession createSession(String packageName, in ISessionCallback cb, String tag, int userId); List<IBinder> getSessions(in ComponentName compName, int userId); void dispatchMediaKeyEvent(in KeyEvent keyEvent, boolean needWakeLock); void dispatchVolumeKeyEvent(in KeyEvent keyEvent, int stream, boolean musicOnly); void dispatchAdjustVolume(int suggestedStream, int delta, int flags); void dispatchMediaKeyEvent(String packageName, boolean asSystemService, in KeyEvent keyEvent, boolean needWakeLock); void dispatchVolumeKeyEvent(String packageName, boolean asSystemService, in KeyEvent keyEvent, int stream, boolean musicOnly); void dispatchAdjustVolume(String packageName, int suggestedStream, int delta, int flags); void addSessionsListener(in IActiveSessionsListener listener, in ComponentName compName, int userId); void removeSessionsListener(in IActiveSessionsListener listener); Loading Loading
cmds/media/src/com/android/commands/media/Media.java +7 −5 Original line number Diff line number Diff line Loading @@ -46,6 +46,8 @@ import java.io.PrintStream; import java.util.List; public class Media extends BaseCommand { // This doesn't belongs to any package. Setting the package name to empty string. private static final String PACKAGE_NAME = ""; private ISessionManager mSessionService; /** Loading Loading @@ -104,7 +106,7 @@ public class Media extends BaseCommand { private void sendMediaKey(KeyEvent event) { try { mSessionService.dispatchMediaKeyEvent(event, false); mSessionService.dispatchMediaKeyEvent(PACKAGE_NAME, false, event, false); } catch (RemoteException e) { } } Loading Loading @@ -264,13 +266,13 @@ public class Media extends BaseCommand { } else if ("q".equals(line) || "quit".equals(line)) { break; } else if ("play".equals(line)) { mController.play(""); mController.play(PACKAGE_NAME); } else if ("pause".equals(line)) { mController.pause(""); mController.pause(PACKAGE_NAME); } else if ("next".equals(line)) { mController.next(""); mController.next(PACKAGE_NAME); } else if ("previous".equals(line)) { mController.previous(""); mController.previous(PACKAGE_NAME); } else { System.out.println("Invalid command: " + line); } Loading
core/java/com/android/internal/policy/PhoneFallbackEventHandler.java +18 −6 Original line number Diff line number Diff line Loading @@ -23,7 +23,7 @@ import android.content.Context; import android.content.Intent; import android.content.res.Configuration; import android.media.AudioManager; import android.media.session.MediaSessionLegacyHelper; import android.media.session.MediaSessionManager; import android.os.UserHandle; import android.provider.Settings; import android.telephony.TelephonyManager; Loading @@ -48,6 +48,7 @@ public class PhoneFallbackEventHandler implements FallbackEventHandler { KeyguardManager mKeyguardManager; SearchManager mSearchManager; TelephonyManager mTelephonyManager; MediaSessionManager mMediaSessionManager; public PhoneFallbackEventHandler(Context context) { mContext = context; Loading Loading @@ -84,8 +85,7 @@ public class PhoneFallbackEventHandler implements FallbackEventHandler { case KeyEvent.KEYCODE_VOLUME_UP: case KeyEvent.KEYCODE_VOLUME_DOWN: case KeyEvent.KEYCODE_VOLUME_MUTE: { MediaSessionLegacyHelper.getHelper(mContext).sendVolumeKeyEvent( event, AudioManager.USE_DEFAULT_STREAM_TYPE, false); handleVolumeKeyEvent(event); return true; } Loading Loading @@ -216,8 +216,7 @@ public class PhoneFallbackEventHandler implements FallbackEventHandler { case KeyEvent.KEYCODE_VOLUME_DOWN: case KeyEvent.KEYCODE_VOLUME_MUTE: { if (!event.isCanceled()) { MediaSessionLegacyHelper.getHelper(mContext).sendVolumeKeyEvent( event, AudioManager.USE_DEFAULT_STREAM_TYPE, false); handleVolumeKeyEvent(event); } return true; } Loading Loading @@ -306,12 +305,25 @@ public class PhoneFallbackEventHandler implements FallbackEventHandler { return mAudioManager; } MediaSessionManager getMediaSessionManager() { if (mMediaSessionManager == null) { mMediaSessionManager = (MediaSessionManager) mContext.getSystemService(Context.MEDIA_SESSION_SERVICE); } return mMediaSessionManager; } void sendCloseSystemWindows() { PhoneWindow.sendCloseSystemWindows(mContext, null); } private void handleVolumeKeyEvent(KeyEvent keyEvent) { getMediaSessionManager().dispatchVolumeKeyEventAsSystemService(keyEvent, AudioManager.USE_DEFAULT_STREAM_TYPE); } private void handleMediaKeyEvent(KeyEvent keyEvent) { MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(keyEvent, false); getMediaSessionManager().dispatchMediaKeyEventAsSystemService(keyEvent); } private boolean isUserSetupComplete() { Loading
core/java/com/android/internal/policy/PhoneWindow.java +20 −25 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import static android.view.WindowManager.LayoutParams.*; import android.app.ActivityManager; import android.app.SearchManager; import android.media.session.MediaSessionManager; import android.os.UserHandle; import android.text.TextUtils; Loading Loading @@ -74,7 +75,6 @@ import android.graphics.Color; import android.graphics.drawable.Drawable; import android.media.AudioManager; import android.media.session.MediaController; import android.media.session.MediaSessionLegacyHelper; import android.net.Uri; import android.os.Bundle; import android.os.Handler; Loading Loading @@ -252,6 +252,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { private AudioManager mAudioManager; private KeyguardManager mKeyguardManager; private MediaSessionManager mMediaSessionManager; private int mUiOptions = 0; Loading Loading @@ -1873,22 +1874,10 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { // If we have a session send it the volume command, otherwise // use the suggested stream. if (mMediaController != null) { int direction = 0; switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: direction = AudioManager.ADJUST_RAISE; break; case KeyEvent.KEYCODE_VOLUME_DOWN: direction = AudioManager.ADJUST_LOWER; break; case KeyEvent.KEYCODE_VOLUME_MUTE: direction = AudioManager.ADJUST_TOGGLE_MUTE; break; } mMediaController.adjustVolume(direction, AudioManager.FLAG_SHOW_UI); mMediaController.dispatchVolumeButtonEventAsSystemService(event); } else { MediaSessionLegacyHelper.getHelper(getContext()).sendVolumeKeyEvent( event, mVolumeControlStreamType, false); getMediaSessionManager().dispatchVolumeKeyEventAsSystemService(event, mVolumeControlStreamType); } return true; } Loading @@ -1906,7 +1895,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { case KeyEvent.KEYCODE_MEDIA_RECORD: case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: { if (mMediaController != null) { if (mMediaController.dispatchMediaButtonEvent(event)) { if (mMediaController.dispatchMediaButtonEventAsSystemService(event)) { return true; } } Loading Loading @@ -1948,6 +1937,14 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { return mAudioManager; } private MediaSessionManager getMediaSessionManager() { if (mMediaSessionManager == null) { mMediaSessionManager = (MediaSessionManager) getContext().getSystemService( Context.MEDIA_SESSION_SERVICE); } return mMediaSessionManager; } /** * A key was released and not handled by anything else in the window. * Loading @@ -1969,12 +1966,10 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { // If we have a session send it the volume command, otherwise // use the suggested stream. if (mMediaController != null) { final int flags = AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_VIBRATE | AudioManager.FLAG_FROM_KEY; mMediaController.adjustVolume(0, flags); mMediaController.dispatchVolumeButtonEventAsSystemService(event); } else { MediaSessionLegacyHelper.getHelper(getContext()).sendVolumeKeyEvent( event, mVolumeControlStreamType, false); getMediaSessionManager().dispatchVolumeKeyEventAsSystemService( event, mVolumeControlStreamType); } return true; } Loading @@ -1983,8 +1978,8 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { // doesn't have one of these. In this case, we execute it here and // eat the event instead, because we have mVolumeControlStreamType // and they don't. MediaSessionLegacyHelper.getHelper(getContext()).sendVolumeKeyEvent( event, AudioManager.USE_DEFAULT_STREAM_TYPE, false); getMediaSessionManager().dispatchVolumeKeyEventAsSystemService( event, AudioManager.USE_DEFAULT_STREAM_TYPE); return true; } // These are all the recognized media key codes in Loading @@ -2001,7 +1996,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { case KeyEvent.KEYCODE_MEDIA_RECORD: case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: { if (mMediaController != null) { if (mMediaController.dispatchMediaButtonEvent(event)) { if (mMediaController.dispatchMediaButtonEventAsSystemService(event)) { return true; } } Loading
media/java/android/media/session/ISessionController.aidl +2 −2 Original line number Diff line number Diff line Loading @@ -37,7 +37,7 @@ import java.util.List; */ interface ISessionController { void sendCommand(String packageName, String command, in Bundle args, in ResultReceiver cb); boolean sendMediaButton(String packageName, in KeyEvent mediaButton); boolean sendMediaButton(String packageName, boolean asSystemService, in KeyEvent mediaButton); void registerCallbackListener(in ISessionControllerCallback cb); void unregisterCallbackListener(in ISessionControllerCallback cb); boolean isTransportControlEnabled(); Loading @@ -46,7 +46,7 @@ interface ISessionController { PendingIntent getLaunchPendingIntent(); long getFlags(); ParcelableVolumeInfo getVolumeAttributes(); void adjustVolume(String packageName, int direction, int flags); void adjustVolume(String packageName, boolean asSystemService, int direction, int flags); void setVolumeTo(String packageName, int value, int flags); // These commands are for the TransportControls Loading
media/java/android/media/session/ISessionManager.aidl +5 −3 Original line number Diff line number Diff line Loading @@ -34,9 +34,11 @@ import android.view.KeyEvent; interface ISessionManager { ISession createSession(String packageName, in ISessionCallback cb, String tag, int userId); List<IBinder> getSessions(in ComponentName compName, int userId); void dispatchMediaKeyEvent(in KeyEvent keyEvent, boolean needWakeLock); void dispatchVolumeKeyEvent(in KeyEvent keyEvent, int stream, boolean musicOnly); void dispatchAdjustVolume(int suggestedStream, int delta, int flags); void dispatchMediaKeyEvent(String packageName, boolean asSystemService, in KeyEvent keyEvent, boolean needWakeLock); void dispatchVolumeKeyEvent(String packageName, boolean asSystemService, in KeyEvent keyEvent, int stream, boolean musicOnly); void dispatchAdjustVolume(String packageName, int suggestedStream, int delta, int flags); void addSessionsListener(in IActiveSessionsListener listener, in ComponentName compName, int userId); void removeSessionsListener(in IActiveSessionsListener listener); Loading