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

Commit 5026936e authored by Jaewan Kim's avatar Jaewan Kim
Browse files

Allow privileged app to set volume key long-press listener

If the volume long-press listener is set, the listener will receive
the volume key long-presses instead of chaging the volume.

Privileged app needs permission
android.permission.SET_VOLUME_KEY_LONG_PRESS_LISTENER to set the listener.

Bug: 30125811
Change-Id: I5e8fafbb950e5e11522da0f14004648d0877bf3e
parent 70c5c30a
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -423,10 +423,11 @@ LOCAL_SRC_FILES += \
	media/java/android/media/projection/IMediaProjectionManager.aidl \
	media/java/android/media/projection/IMediaProjectionWatcherCallback.aidl \
	media/java/android/media/session/IActiveSessionsListener.aidl \
	media/java/android/media/session/ISessionController.aidl \
	media/java/android/media/session/ISessionControllerCallback.aidl \
	media/java/android/media/session/IOnVolumeKeyLongPressListener.aidl \
	media/java/android/media/session/ISession.aidl \
	media/java/android/media/session/ISessionCallback.aidl \
	media/java/android/media/session/ISessionController.aidl \
	media/java/android/media/session/ISessionControllerCallback.aidl \
	media/java/android/media/session/ISessionManager.aidl \
	media/java/android/media/tv/ITvInputClient.aidl \
	media/java/android/media/tv/ITvInputHardware.aidl \
+6 −0
Original line number Diff line number Diff line
@@ -222,6 +222,7 @@ package android {
    field public static final java.lang.String SET_SCREEN_COMPATIBILITY = "android.permission.SET_SCREEN_COMPATIBILITY";
    field public static final java.lang.String SET_TIME = "android.permission.SET_TIME";
    field public static final java.lang.String SET_TIME_ZONE = "android.permission.SET_TIME_ZONE";
    field public static final java.lang.String SET_VOLUME_KEY_LONG_PRESS_LISTENER = "android.permission.SET_VOLUME_KEY_LONG_PRESS_LISTENER";
    field public static final java.lang.String SET_WALLPAPER = "android.permission.SET_WALLPAPER";
    field public static final java.lang.String SET_WALLPAPER_COMPONENT = "android.permission.SET_WALLPAPER_COMPONENT";
    field public static final java.lang.String SET_WALLPAPER_HINTS = "android.permission.SET_WALLPAPER_HINTS";
@@ -24819,12 +24820,17 @@ package android.media.session {
    method public void addOnActiveSessionsChangedListener(android.media.session.MediaSessionManager.OnActiveSessionsChangedListener, android.content.ComponentName, android.os.Handler);
    method public java.util.List<android.media.session.MediaController> getActiveSessions(android.content.ComponentName);
    method public void removeOnActiveSessionsChangedListener(android.media.session.MediaSessionManager.OnActiveSessionsChangedListener);
    method public void setOnVolumeKeyLongPressListener(android.media.session.MediaSessionManager.OnVolumeKeyLongPressListener, android.os.Handler);
  }
  public static abstract interface MediaSessionManager.OnActiveSessionsChangedListener {
    method public abstract void onActiveSessionsChanged(java.util.List<android.media.session.MediaController>);
  }
  public static abstract interface MediaSessionManager.OnVolumeKeyLongPressListener {
    method public abstract void onVolumeKeyLongPress(android.view.KeyEvent);
  }
  public final class PlaybackState implements android.os.Parcelable {
    method public int describeContents();
    method public long getActions();
+4 −2
Original line number Diff line number Diff line
@@ -84,7 +84,8 @@ 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, false);
                MediaSessionLegacyHelper.getHelper(mContext).sendVolumeKeyEvent(
                        event, AudioManager.USE_DEFAULT_STREAM_TYPE, false);
                return true;
            }

@@ -215,7 +216,8 @@ public class PhoneFallbackEventHandler implements FallbackEventHandler {
            case KeyEvent.KEYCODE_VOLUME_DOWN:
            case KeyEvent.KEYCODE_VOLUME_MUTE: {
                if (!event.isCanceled()) {
                    MediaSessionLegacyHelper.getHelper(mContext).sendVolumeKeyEvent(event, false);
                    MediaSessionLegacyHelper.getHelper(mContext).sendVolumeKeyEvent(
                            event, AudioManager.USE_DEFAULT_STREAM_TYPE, false);
                }
                return true;
            }
+20 −21
Original line number Diff line number Diff line
@@ -1856,6 +1856,9 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
            case KeyEvent.KEYCODE_VOLUME_UP:
            case KeyEvent.KEYCODE_VOLUME_DOWN:
            case KeyEvent.KEYCODE_VOLUME_MUTE: {
                // 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:
@@ -1868,15 +1871,10 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
                            direction = AudioManager.ADJUST_TOGGLE_MUTE;
                            break;
                    }
                // If we have a session send it the volume command, otherwise
                // use the suggested stream.
                if (mMediaController != null) {
                    mMediaController.adjustVolume(direction, AudioManager.FLAG_SHOW_UI);
                } else {
                    MediaSessionLegacyHelper.getHelper(getContext()).sendAdjustVolumeBy(
                            mVolumeControlStreamType, direction,
                            AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_VIBRATE
                                    | AudioManager.FLAG_FROM_KEY);
                    MediaSessionLegacyHelper.getHelper(getContext()).sendVolumeKeyEvent(
                            event, mVolumeControlStreamType, false);
                }
                return true;
            }
@@ -1954,15 +1952,15 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
        switch (keyCode) {
            case KeyEvent.KEYCODE_VOLUME_UP:
            case KeyEvent.KEYCODE_VOLUME_DOWN: {
                final int flags = AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_VIBRATE
                        | AudioManager.FLAG_FROM_KEY;
                // 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);
                } else {
                    MediaSessionLegacyHelper.getHelper(getContext()).sendAdjustVolumeBy(
                            mVolumeControlStreamType, 0, flags);
                    MediaSessionLegacyHelper.getHelper(getContext()).sendVolumeKeyEvent(
                            event, mVolumeControlStreamType, false);
                }
                return true;
            }
@@ -1971,7 +1969,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.
                getAudioManager().handleKeyUp(event, mVolumeControlStreamType);
                MediaSessionLegacyHelper.getHelper(getContext()).sendVolumeKeyEvent(
                        event, AudioManager.USE_DEFAULT_STREAM_TYPE, false);
                return true;
            }
            // These are all the recognized media key codes in
+7 −0
Original line number Diff line number Diff line
@@ -2625,6 +2625,13 @@
    <permission android:name="android.permission.MEDIA_CONTENT_CONTROL"
        android:protectionLevel="signature|privileged" />

    <!-- @SystemApi @hide Allows an application to set the volume key long-press listener.
         <p>When it's set, the application will receive the volume key long-press event
         instead of changing volume.</p>
         <p>Not for use by third-party applications</p> -->
    <permission android:name="android.permission.SET_VOLUME_KEY_LONG_PRESS_LISTENER"
        android:protectionLevel="signature|privileged|development" />

    <!-- @SystemApi Required to be able to disable the device (very dangerous!).
         <p>Not for use by third-party applications.
         @hide
Loading