Fix failing MediaController2Test#test(Set|Adjust)VolumeWithLocalVolume
The minimum alarm volume can be 0 on devices lower than Android P.
However, in the tests the minimum volume was all set to 1 regardless
of the API level.
This CL fixes this issue by setting the correct minimum volume of the
alarm stream.
Bug: 127589497
Test: Ran MediaController2Test / version-compat-tests (in API 19 and Q)
Change-Id: Iab66b821264884aa2d6b5d5efc6c7fe3111a048c
diff --git a/media/version-compat-tests/current/client/src/androidTest/java/android/support/mediacompat/client/ClientBroadcastReceiver.java b/media/version-compat-tests/current/client/src/androidTest/java/android/support/mediacompat/client/ClientBroadcastReceiver.java
index 0f4d8e8..280ceb9 100644
--- a/media/version-compat-tests/current/client/src/androidTest/java/android/support/mediacompat/client/ClientBroadcastReceiver.java
+++ b/media/version-compat-tests/current/client/src/androidTest/java/android/support/mediacompat/client/ClientBroadcastReceiver.java
@@ -71,11 +71,13 @@
import android.support.v4.media.session.MediaControllerCompat.TransportControls;
import android.support.v4.media.session.MediaSessionCompat;
import android.support.v4.media.session.PlaybackStateCompat;
+import android.util.Log;
import android.view.KeyEvent;
import androidx.media.test.lib.CustomParcelable;
public class ClientBroadcastReceiver extends BroadcastReceiver {
+ private static final String TAG = "ClientBroadcastReceiver";
@Override
public void onReceive(Context context, Intent intent) {
@@ -89,6 +91,7 @@
return;
}
int method = extras.getInt(KEY_METHOD_ID, 0);
+ Log.d(TAG, "action=" + intent.getAction() + ", method=" + method);
if (ACTION_CALL_MEDIA_CONTROLLER_METHOD.equals(intent.getAction()) && extras != null) {
Bundle arguments;
diff --git a/media/version-compat-tests/current/service/src/androidTest/java/android/support/mediacompat/service/MediaSessionCompatCallbackTest.java b/media/version-compat-tests/current/service/src/androidTest/java/android/support/mediacompat/service/MediaSessionCompatCallbackTest.java
index 56a99c2..ecbcaae 100644
--- a/media/version-compat-tests/current/service/src/androidTest/java/android/support/mediacompat/service/MediaSessionCompatCallbackTest.java
+++ b/media/version-compat-tests/current/service/src/androidTest/java/android/support/mediacompat/service/MediaSessionCompatCallbackTest.java
@@ -868,7 +868,9 @@
// 'Do Not Disturb' or 'Volume limit'.
final int stream = AudioManager.STREAM_ALARM;
final int maxVolume = mAudioManager.getStreamMaxVolume(stream);
- final int minVolume = 1;
+ final int minVolume =
+ Build.VERSION.SDK_INT >= 28 ? mAudioManager.getStreamMinVolume(stream) : 0;
+ Log.d(TAG, "maxVolume=" + maxVolume + ", minVolume=" + minVolume);
if (maxVolume <= minVolume) {
return;
}
@@ -878,6 +880,7 @@
final int originalVolume = mAudioManager.getStreamVolume(stream);
final int targetVolume = originalVolume == minVolume
? originalVolume + 1 : originalVolume - 1;
+ Log.d(TAG, "originalVolume=" + originalVolume + ", targetVolume=" + targetVolume);
callMediaControllerMethod(SET_VOLUME_TO, targetVolume, getApplicationContext(),
mSession.getSessionToken());
@@ -904,7 +907,9 @@
// 'Do Not Disturb' or 'Volume limit'.
final int stream = AudioManager.STREAM_ALARM;
final int maxVolume = mAudioManager.getStreamMaxVolume(stream);
- final int minVolume = 1;
+ final int minVolume =
+ Build.VERSION.SDK_INT >= 28 ? mAudioManager.getStreamMinVolume(stream) : 0;
+ Log.d(TAG, "maxVolume=" + maxVolume + ", minVolume=" + minVolume);
if (maxVolume <= minVolume) {
return;
}
@@ -915,6 +920,7 @@
final int direction = originalVolume == minVolume
? AudioManager.ADJUST_RAISE : AudioManager.ADJUST_LOWER;
final int targetVolume = originalVolume + direction;
+ Log.d(TAG, "originalVolume=" + originalVolume + ", targetVolume=" + targetVolume);
callMediaControllerMethod(ADJUST_VOLUME, direction, getApplicationContext(),
mSession.getSessionToken());
diff --git a/media/version-compat-tests/previous/client/src/androidTest/java/android/support/mediacompat/client/ClientBroadcastReceiver.java b/media/version-compat-tests/previous/client/src/androidTest/java/android/support/mediacompat/client/ClientBroadcastReceiver.java
index 1baba08..5119908 100644
--- a/media/version-compat-tests/previous/client/src/androidTest/java/android/support/mediacompat/client/ClientBroadcastReceiver.java
+++ b/media/version-compat-tests/previous/client/src/androidTest/java/android/support/mediacompat/client/ClientBroadcastReceiver.java
@@ -70,11 +70,13 @@
import android.support.v4.media.session.MediaControllerCompat.TransportControls;
import android.support.v4.media.session.MediaSessionCompat;
import android.support.v4.media.session.PlaybackStateCompat;
+import android.util.Log;
import android.view.KeyEvent;
import androidx.media.test.lib.CustomParcelable;
public class ClientBroadcastReceiver extends BroadcastReceiver {
+ private static final String TAG = "ClientBroadcastReceiver";
@Override
public void onReceive(Context context, Intent intent) {
@@ -88,6 +90,7 @@
return;
}
int method = extras.getInt(KEY_METHOD_ID, 0);
+ Log.d(TAG, "action=" + intent.getAction() + ", method=" + method);
if (ACTION_CALL_MEDIA_CONTROLLER_METHOD.equals(intent.getAction()) && extras != null) {
Bundle arguments;
diff --git a/media2/src/androidTest/java/androidx/media2/MediaControllerTest.java b/media2/src/androidTest/java/androidx/media2/MediaControllerTest.java
index 533eec9..e4a8734 100644
--- a/media2/src/androidTest/java/androidx/media2/MediaControllerTest.java
+++ b/media2/src/androidTest/java/androidx/media2/MediaControllerTest.java
@@ -36,6 +36,7 @@
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Process;
+import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -916,7 +917,9 @@
// 'Do Not Disturb' or 'Volume limit'.
final int stream = AudioManager.STREAM_ALARM;
final int maxVolume = mAudioManager.getStreamMaxVolume(stream);
- final int minVolume = 1;
+ final int minVolume =
+ Build.VERSION.SDK_INT >= 28 ? mAudioManager.getStreamMinVolume(stream) : 0;
+ Log.d(TAG, "maxVolume=" + maxVolume + ", minVolume=" + minVolume);
if (maxVolume <= minVolume) {
return;
}
@@ -931,6 +934,7 @@
final int originalVolume = mAudioManager.getStreamVolume(stream);
final int targetVolume = originalVolume == minVolume
? originalVolume + 1 : originalVolume - 1;
+ Log.d(TAG, "originalVolume=" + originalVolume + ", targetVolume=" + targetVolume);
mController.setVolumeTo(targetVolume, AudioManager.FLAG_SHOW_UI);
new PollingCheck(TIMEOUT_MS) {
@@ -956,7 +960,9 @@
// 'Do Not Disturb' or 'Volume limit'.
final int stream = AudioManager.STREAM_ALARM;
final int maxVolume = mAudioManager.getStreamMaxVolume(stream);
- final int minVolume = 1;
+ final int minVolume =
+ Build.VERSION.SDK_INT >= 28 ? mAudioManager.getStreamMinVolume(stream) : 0;
+ Log.d(TAG, "maxVolume=" + maxVolume + ", minVolume=" + minVolume);
if (maxVolume <= minVolume) {
return;
}
@@ -972,6 +978,7 @@
final int direction = originalVolume == minVolume
? AudioManager.ADJUST_RAISE : AudioManager.ADJUST_LOWER;
final int targetVolume = originalVolume + direction;
+ Log.d(TAG, "originalVolume=" + originalVolume + ", targetVolume=" + targetVolume);
mController.adjustVolume(direction, AudioManager.FLAG_SHOW_UI);
new PollingCheck(TIMEOUT_MS) {
diff --git a/media2/version-compat-tests/current/client/src/androidTest/java/androidx/media2/test/client/tests/MediaControllerTest.java b/media2/version-compat-tests/current/client/src/androidTest/java/androidx/media2/test/client/tests/MediaControllerTest.java
index 618c257..8f167c6 100644
--- a/media2/version-compat-tests/current/client/src/androidTest/java/androidx/media2/test/client/tests/MediaControllerTest.java
+++ b/media2/version-compat-tests/current/client/src/androidTest/java/androidx/media2/test/client/tests/MediaControllerTest.java
@@ -34,6 +34,7 @@
import android.media.AudioManager;
import android.os.Build;
import android.os.Bundle;
+import android.util.Log;
import androidx.media.AudioAttributesCompat;
import androidx.media2.MediaController;
@@ -64,6 +65,7 @@
@LargeTest
public class MediaControllerTest extends MediaSessionTestBase {
+ static final String TAG = "MediaControllerTest";
final List<RemoteMediaSession> mRemoteSessionList = new ArrayList<>();
AudioManager mAudioManager;
@@ -139,7 +141,9 @@
// 'Do Not Disturb' or 'Volume limit'.
final int stream = AudioManager.STREAM_ALARM;
final int maxVolume = mAudioManager.getStreamMaxVolume(stream);
- final int minVolume = 1;
+ final int minVolume =
+ Build.VERSION.SDK_INT >= 28 ? mAudioManager.getStreamMinVolume(stream) : 0;
+ Log.d(TAG, "maxVolume=" + maxVolume + ", minVolume=" + minVolume);
if (maxVolume <= minVolume) {
return;
}
@@ -154,6 +158,7 @@
final int originalVolume = mAudioManager.getStreamVolume(stream);
final int targetVolume = originalVolume == minVolume
? originalVolume + 1 : originalVolume - 1;
+ Log.d(TAG, "originalVolume=" + originalVolume + ", targetVolume=" + targetVolume);
controller.setVolumeTo(targetVolume, AudioManager.FLAG_SHOW_UI);
new PollingCheck(TIMEOUT_MS) {
@@ -181,7 +186,9 @@
// 'Do Not Disturb' or 'Volume limit'.
final int stream = AudioManager.STREAM_ALARM;
final int maxVolume = mAudioManager.getStreamMaxVolume(stream);
- final int minVolume = 1;
+ final int minVolume =
+ Build.VERSION.SDK_INT >= 28 ? mAudioManager.getStreamMinVolume(stream) : 0;
+ Log.d(TAG, "maxVolume=" + maxVolume + ", minVolume=" + minVolume);
if (maxVolume <= minVolume) {
return;
}
@@ -197,6 +204,7 @@
final int direction = originalVolume == minVolume
? AudioManager.ADJUST_RAISE : AudioManager.ADJUST_LOWER;
final int targetVolume = originalVolume + direction;
+ Log.d(TAG, "originalVolume=" + originalVolume + ", targetVolume=" + targetVolume);
controller.adjustVolume(direction, AudioManager.FLAG_SHOW_UI);
new PollingCheck(TIMEOUT_MS) {
diff --git a/media2/version-compat-tests/current/service/src/androidTest/java/androidx/media2/test/service/tests/MediaSessionCallbackTestWithMediaControllerCompat.java b/media2/version-compat-tests/current/service/src/androidTest/java/androidx/media2/test/service/tests/MediaSessionCallbackTestWithMediaControllerCompat.java
index 912c37d..700440e 100644
--- a/media2/version-compat-tests/current/service/src/androidTest/java/androidx/media2/test/service/tests/MediaSessionCallbackTestWithMediaControllerCompat.java
+++ b/media2/version-compat-tests/current/service/src/androidTest/java/androidx/media2/test/service/tests/MediaSessionCallbackTestWithMediaControllerCompat.java
@@ -39,6 +39,7 @@
import android.support.v4.media.RatingCompat;
import android.support.v4.media.session.MediaControllerCompat;
import android.support.v4.media.session.MediaSessionCompat.QueueItem;
+import android.util.Log;
import androidx.annotation.NonNull;
import androidx.media.AudioAttributesCompat;
@@ -406,7 +407,9 @@
// 'Do Not Disturb' or 'Volume limit'.
final int stream = AudioManager.STREAM_ALARM;
final int maxVolume = mAudioManager.getStreamMaxVolume(stream);
- final int minVolume = 1;
+ final int minVolume =
+ Build.VERSION.SDK_INT >= 28 ? mAudioManager.getStreamMinVolume(stream) : 0;
+ Log.d(TAG, "maxVolume=" + maxVolume + ", minVolume=" + minVolume);
if (maxVolume <= minVolume) {
return;
}
@@ -421,6 +424,7 @@
final int originalVolume = mAudioManager.getStreamVolume(stream);
final int targetVolume = originalVolume == minVolume
? originalVolume + 1 : originalVolume - 1;
+ Log.d(TAG, "originalVolume=" + originalVolume + ", targetVolume=" + targetVolume);
mController.setVolumeTo(targetVolume, AudioManager.FLAG_SHOW_UI);
new PollingCheck(TIMEOUT_MS) {
@@ -446,7 +450,9 @@
// 'Do Not Disturb' or 'Volume limit'.
final int stream = AudioManager.STREAM_ALARM;
final int maxVolume = mAudioManager.getStreamMaxVolume(stream);
- final int minVolume = 1;
+ final int minVolume =
+ Build.VERSION.SDK_INT >= 28 ? mAudioManager.getStreamMinVolume(stream) : 0;
+ Log.d(TAG, "maxVolume=" + maxVolume + ", minVolume=" + minVolume);
if (maxVolume <= minVolume) {
return;
}
@@ -462,6 +468,7 @@
final int direction = originalVolume == minVolume
? AudioManager.ADJUST_RAISE : AudioManager.ADJUST_LOWER;
final int targetVolume = originalVolume + direction;
+ Log.d(TAG, "originalVolume=" + originalVolume + ", targetVolume=" + targetVolume);
mController.adjustVolume(direction, AudioManager.FLAG_SHOW_UI);
new PollingCheck(TIMEOUT_MS) {
diff --git a/media2/version-compat-tests/current/service/src/androidTest/java/androidx/media2/test/service/tests/MediaSessionCompatCallbackTestWithMediaController.java b/media2/version-compat-tests/current/service/src/androidTest/java/androidx/media2/test/service/tests/MediaSessionCompatCallbackTestWithMediaController.java
index 59349bf..f2014c2 100644
--- a/media2/version-compat-tests/current/service/src/androidTest/java/androidx/media2/test/service/tests/MediaSessionCompatCallbackTestWithMediaController.java
+++ b/media2/version-compat-tests/current/service/src/androidTest/java/androidx/media2/test/service/tests/MediaSessionCompatCallbackTestWithMediaController.java
@@ -36,6 +36,7 @@
import android.support.v4.media.session.MediaSessionCompat;
import android.support.v4.media.session.MediaSessionCompat.QueueItem;
import android.support.v4.media.session.PlaybackStateCompat;
+import android.util.Log;
import androidx.media.VolumeProviderCompat;
import androidx.media2.MediaController;
@@ -372,7 +373,9 @@
// 'Do Not Disturb' or 'Volume limit'.
final int stream = AudioManager.STREAM_ALARM;
final int maxVolume = mAudioManager.getStreamMaxVolume(stream);
- final int minVolume = 1;
+ final int minVolume =
+ Build.VERSION.SDK_INT >= 28 ? mAudioManager.getStreamMinVolume(stream) : 0;
+ Log.d(TAG, "maxVolume=" + maxVolume + ", minVolume=" + minVolume);
if (maxVolume <= minVolume) {
return;
}
@@ -382,6 +385,7 @@
final int originalVolume = mAudioManager.getStreamVolume(stream);
final int targetVolume = originalVolume == minVolume
? originalVolume + 1 : originalVolume - 1;
+ Log.d(TAG, "originalVolume=" + originalVolume + ", targetVolume=" + targetVolume);
controller.setVolumeTo(targetVolume, AudioManager.FLAG_SHOW_UI);
new PollingCheck(TIMEOUT_MS) {
@@ -407,7 +411,9 @@
// 'Do Not Disturb' or 'Volume limit'.
final int stream = AudioManager.STREAM_ALARM;
final int maxVolume = mAudioManager.getStreamMaxVolume(stream);
- final int minVolume = 1;
+ final int minVolume =
+ Build.VERSION.SDK_INT >= 28 ? mAudioManager.getStreamMinVolume(stream) : 0;
+ Log.d(TAG, "maxVolume=" + maxVolume + ", minVolume=" + minVolume);
if (maxVolume <= minVolume) {
return;
}
@@ -419,6 +425,7 @@
final int direction = originalVolume == minVolume
? AudioManager.ADJUST_RAISE : AudioManager.ADJUST_LOWER;
final int targetVolume = originalVolume + direction;
+ Log.d(TAG, "originalVolume=" + originalVolume + ", targetVolume=" + targetVolume);
controller.adjustVolume(direction, AudioManager.FLAG_SHOW_UI);
new PollingCheck(TIMEOUT_MS) {