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

Commit 484a8497 authored by Vlad Popa's avatar Vlad Popa Committed by Android (Google) Code Review
Browse files

Merge "Add test method for disabling the long press timeout" into main

parents fa49fd5c db087b24
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -2003,6 +2003,7 @@ package android.media {
    method public void setRampingRingerEnabled(boolean);
    method @RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_SETTINGS_PRIVILEGED) public void setRs2Value(float);
    method @RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_ROUTING) public void setTestDeviceConnectionState(@NonNull android.media.AudioDeviceAttributes, boolean);
    method @RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_SETTINGS_PRIVILEGED) public void setVolumeControllerLongPressTimeoutEnabled(boolean);
    method @FlaggedApi("android.media.audio.focus_exclusive_with_recording") @RequiresPermission(android.Manifest.permission.QUERY_AUDIO_STATE) public boolean shouldNotificationSoundPlay(@NonNull android.media.AudioAttributes);
  }

+21 −0
Original line number Diff line number Diff line
@@ -6983,6 +6983,27 @@ public class AudioManager {
        }
    }

    /**
     * Test method for enabling/disabling the volume controller long press timeout for checking
     * whether two consecutive volume adjustments should be treated as a volume long press.
     *
     * <p>Used only for testing
     *
     * @param enable true for enabling, otherwise will be disabled (test mode)
     *
     * @hide
     **/
    @TestApi
    @SuppressLint("UnflaggedApi") // @TestApi without associated feature.
    @RequiresPermission(Manifest.permission.MODIFY_AUDIO_SETTINGS_PRIVILEGED)
    public void setVolumeControllerLongPressTimeoutEnabled(boolean enable) {
        try {
            getService().setVolumeControllerLongPressTimeoutEnabled(enable);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Only useful for volume controllers.
     * @hide
+3 −0
Original line number Diff line number Diff line
@@ -303,6 +303,9 @@ interface IAudioService {

    void notifyVolumeControllerVisible(in IVolumeController controller, boolean visible);

    @EnforcePermission("MODIFY_AUDIO_SETTINGS_PRIVILEGED")
    oneway void setVolumeControllerLongPressTimeoutEnabled(boolean enable);

    boolean isStreamAffectedByRingerMode(int streamType);

    boolean isStreamAffectedByMute(int streamType);
+15 −2
Original line number Diff line number Diff line
@@ -285,7 +285,6 @@ import java.util.Objects;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
@@ -411,6 +410,9 @@ public class AudioService extends IAudioService.Stub
    /** The controller for the volume UI. */
    private final VolumeController mVolumeController = new VolumeController();
    /** Used only for testing to enable/disable the long press timeout volume actions. */
    private final AtomicBoolean mVolumeControllerLongPressEnabled = new AtomicBoolean(true);
    // sendMsg() flags
    /** If the msg is already queued, replace it with this one. */
    private static final int SENDMSG_REPLACE = 0;
@@ -12554,6 +12556,15 @@ public class AudioService extends IAudioService.Stub
        if (DEBUG_VOL) Log.d(TAG, "Volume controller visible: " + visible);
    }
    /** @see AudioManager#setVolumeControllerLongPressTimeoutEnabled(boolean) */
    @Override
    @android.annotation.EnforcePermission(MODIFY_AUDIO_SETTINGS_PRIVILEGED)
    public void setVolumeControllerLongPressTimeoutEnabled(boolean enable) {
        super.setVolumeControllerLongPressTimeoutEnabled_enforcePermission();
        mVolumeControllerLongPressEnabled.set(enable);
        Log.i(TAG, "Volume controller long press timeout enabled: " + enable);
    }
    @Override
    public void setVolumePolicy(VolumePolicy policy) {
        enforceVolumeController("set volume policy");
@@ -12632,7 +12643,9 @@ public class AudioService extends IAudioService.Stub
                if ((flags & AudioManager.FLAG_SHOW_UI) != 0 && !mVisible) {
                    // UI is not visible yet, adjustment is ignored
                    if (mNextLongPress < now) {
                        mNextLongPress = now + mLongPressTimeout;
                        mNextLongPress =
                                now + (mVolumeControllerLongPressEnabled.get() ? mLongPressTimeout
                                        : 0);
                    }
                    suppress = true;
                } else if (mNextLongPress > 0) {  // in a long-press