Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate Util.SDK_INT in favor of Build.VERSION.SDK_INT #2285

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Unreleased changes

* Common Library:
* Deprecate `Util.SDK_INT`. Use `Build.VERSION.SDK_INT` instead.
* ExoPlayer:
* Add `ExoPlayer.setScrubbingModeEnabled(boolean)` method. This optimizes
the player for many frequent seeks (for example, from a user dragging a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package androidx.media3.demo.composition;

import static android.content.pm.ActivityInfo.COLOR_MODE_HDR;
import static androidx.media3.common.util.Util.SDK_INT;
import static android.os.Build.VERSION.SDK_INT;
import static androidx.media3.transformer.Composition.HDR_MODE_EXPERIMENTAL_FORCE_INTERPRET_HDR_AS_SDR;
import static androidx.media3.transformer.Composition.HDR_MODE_KEEP_HDR;
import static androidx.media3.transformer.Composition.HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_MEDIACODEC;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package androidx.media3.demo.effect

import android.Manifest
import android.net.Uri
import android.os.Build.VERSION.SDK_INT
import android.os.Bundle
import android.text.Spannable
import android.text.SpannableString
Expand Down Expand Up @@ -81,7 +82,6 @@ import androidx.lifecycle.lifecycleScope
import androidx.media3.common.Effect
import androidx.media3.common.MediaItem
import androidx.media3.common.util.UnstableApi
import androidx.media3.common.util.Util.SDK_INT
import androidx.media3.effect.Contrast
import androidx.media3.effect.OverlayEffect
import androidx.media3.effect.StaticOverlaySettings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package androidx.media3.demo.gl;

import static android.os.Build.VERSION.SDK_INT;
import static androidx.media3.common.util.Assertions.checkNotNull;

import android.app.Activity;
Expand Down Expand Up @@ -94,7 +95,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
@Override
public void onStart() {
super.onStart();
if (Util.SDK_INT > 23) {
if (SDK_INT > 23) {
initializePlayer();
if (playerView != null) {
playerView.onResume();
Expand All @@ -105,7 +106,7 @@ public void onStart() {
@Override
public void onResume() {
super.onResume();
if (Util.SDK_INT <= 23 || player == null) {
if (SDK_INT <= 23 || player == null) {
initializePlayer();
if (playerView != null) {
playerView.onResume();
Expand All @@ -116,7 +117,7 @@ public void onResume() {
@Override
public void onPause() {
super.onPause();
if (Util.SDK_INT <= 23) {
if (SDK_INT <= 23) {
if (playerView != null) {
playerView.onPause();
}
Expand All @@ -127,7 +128,7 @@ public void onPause() {
@Override
public void onStop() {
super.onStop();
if (Util.SDK_INT > 23) {
if (SDK_INT > 23) {
if (playerView != null) {
playerView.onPause();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
import static android.Manifest.permission.READ_MEDIA_VIDEO;
import static android.os.Build.VERSION.SDK_INT;
import static androidx.media3.common.util.Assertions.checkState;
import static androidx.media3.common.util.Util.SDK_INT;
import static androidx.media3.transformer.Composition.HDR_MODE_EXPERIMENTAL_FORCE_INTERPRET_HDR_AS_SDR;
import static androidx.media3.transformer.Composition.HDR_MODE_KEEP_HDR;
import static androidx.media3.transformer.Composition.HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_MEDIACODEC;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package androidx.media3.demo.transformer;

import static android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION;
import static android.os.Build.VERSION.SDK_INT;
import static androidx.media3.common.util.Assertions.checkNotNull;
import static androidx.media3.common.util.Assertions.checkState;
import static androidx.media3.exoplayer.DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS;
Expand Down Expand Up @@ -985,14 +986,14 @@ public int onStartCommand(Intent intent, int flags, int startId) {
.setOngoing(true)
.setSmallIcon(R.drawable.exo_icon_play)
.build();
if (Util.SDK_INT >= 26) {
if (SDK_INT >= 26) {
NotificationChannel channel =
new NotificationChannel(
CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);
NotificationManager manager = getSystemService(NotificationManager.class);
manager.createNotificationChannel(channel);
}
if (Util.SDK_INT >= 29) {
if (SDK_INT >= 29) {
startForeground(NOTIFICATION_ID, notification, FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION);
} else {
startForeground(NOTIFICATION_ID, notification);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/
package androidx.media3.cast;

import static android.os.Build.VERSION.SDK_INT;
import static androidx.media3.common.util.Assertions.checkArgument;
import static androidx.media3.common.util.Assertions.checkNotNull;
import static androidx.media3.common.util.Util.SDK_INT;
import static androidx.media3.common.util.Util.castNonNull;
import static java.lang.Math.min;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package androidx.media3.common;

import static android.os.Build.VERSION.SDK_INT;

import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
Expand Down Expand Up @@ -45,10 +47,10 @@ private AudioAttributesV21(AudioAttributes audioAttributes) {
.setContentType(audioAttributes.contentType)
.setFlags(audioAttributes.flags)
.setUsage(audioAttributes.usage);
if (Util.SDK_INT >= 29) {
if (SDK_INT >= 29) {
Api29.setAllowedCapturePolicy(builder, audioAttributes.allowedCapturePolicy);
}
if (Util.SDK_INT >= 32) {
if (SDK_INT >= 32) {
Api32.setSpatializationBehavior(builder, audioAttributes.spatializationBehavior);
}
this.audioAttributes = builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package androidx.media3.common;

import static android.os.Build.VERSION.SDK_INT;
import static androidx.media3.common.util.Assertions.checkNotNull;

import android.os.Binder;
Expand All @@ -25,7 +26,6 @@
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.common.util.Util;
import com.google.common.collect.ImmutableList;
import java.util.List;

Expand Down Expand Up @@ -56,7 +56,7 @@ public final class BundleListRetriever extends Binder {

// Soft limit of an IPC buffer size
private static final int SUGGESTED_MAX_IPC_SIZE =
Util.SDK_INT >= 30 ? IBinder.getSuggestedMaxIpcSizeBytes() : 64 * 1024;
SDK_INT >= 30 ? IBinder.getSuggestedMaxIpcSizeBytes() : 64 * 1024;

private static final int REPLY_END_OF_LIST = 0;
private static final int REPLY_CONTINUE = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
*/
package androidx.media3.common;

import static android.os.Build.VERSION.SDK_INT;
import static androidx.media3.common.util.Assertions.checkIndex;
import static androidx.media3.common.util.Assertions.checkState;

import android.util.SparseBooleanArray;
import androidx.annotation.Nullable;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.common.util.Util;
import com.google.errorprone.annotations.CanIgnoreReturnValue;

/**
Expand Down Expand Up @@ -222,7 +222,7 @@ public boolean equals(@Nullable Object o) {
return false;
}
FlagSet that = (FlagSet) o;
if (Util.SDK_INT < 24) {
if (SDK_INT < 24) {
// SparseBooleanArray.equals() is not implemented on API levels below 24.
if (size() != that.size()) {
return false;
Expand All @@ -240,7 +240,7 @@ public boolean equals(@Nullable Object o) {

@Override
public int hashCode() {
if (Util.SDK_INT < 24) {
if (SDK_INT < 24) {
// SparseBooleanArray.hashCode() is not implemented on API levels below 24.
int hashCode = size();
for (int i = 0; i < size(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package androidx.media3.common.audio;

import static android.os.Build.VERSION.SDK_INT;
import static androidx.media3.common.util.Assertions.checkArgument;
import static androidx.media3.common.util.Assertions.checkNotNull;

Expand Down Expand Up @@ -55,15 +56,15 @@ public final class AudioFocusRequestCompat {
this.audioAttributes = audioFocusRequestCompat;
this.pauseOnDuck = pauseOnDuck;

if (Util.SDK_INT < 26) {
if (SDK_INT < 26) {
this.onAudioFocusChangeListener =
new OnAudioFocusChangeListenerHandlerCompat(
onAudioFocusChangeListener, focusChangeHandler);
} else {
this.onAudioFocusChangeListener = onAudioFocusChangeListener;
}

if (Util.SDK_INT >= 26) {
if (SDK_INT >= 26) {
this.frameworkAudioFocusRequest =
new AudioFocusRequest.Builder(focusGain)
.setAudioAttributes(audioAttributes.getAudioAttributesV21().audioAttributes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package androidx.media3.common.audio;

import static android.os.Build.VERSION.SDK_INT;
import static androidx.media3.common.util.Assertions.checkNotNull;
import static java.lang.annotation.ElementType.TYPE_USE;

Expand All @@ -29,7 +30,6 @@
import androidx.media3.common.util.ConditionVariable;
import androidx.media3.common.util.Log;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.common.util.Util;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand Down Expand Up @@ -154,7 +154,7 @@ public static synchronized AudioManager getAudioManager(Context context) {
@SuppressWarnings("deprecation")
public static int requestAudioFocus(
AudioManager audioManager, AudioFocusRequestCompat focusRequest) {
if (Util.SDK_INT >= 26) {
if (SDK_INT >= 26) {
return audioManager.requestAudioFocus(focusRequest.getAudioFocusRequest());
} else {
return audioManager.requestAudioFocus(
Expand All @@ -176,7 +176,7 @@ public static int requestAudioFocus(
@SuppressWarnings("deprecation")
public static int abandonAudioFocusRequest(
AudioManager audioManager, AudioFocusRequestCompat focusRequest) {
if (Util.SDK_INT >= 26) {
if (SDK_INT >= 26) {
return audioManager.abandonAudioFocusRequest(focusRequest.getAudioFocusRequest());
} else {
return audioManager.abandonAudioFocus(focusRequest.getOnAudioFocusChangeListener());
Expand Down Expand Up @@ -204,7 +204,7 @@ public static int getStreamMaxVolume(AudioManager audioManager, @C.StreamType in
*/
@IntRange(from = 0)
public static int getStreamMinVolume(AudioManager audioManager, @C.StreamType int streamType) {
return Util.SDK_INT >= 28 ? audioManager.getStreamMinVolume(streamType) : 0;
return SDK_INT >= 28 ? audioManager.getStreamMinVolume(streamType) : 0;
}

/**
Expand Down Expand Up @@ -233,7 +233,7 @@ public static int getStreamVolume(AudioManager audioManager, @C.StreamType int s
* @return Whether the stream is muted.
*/
public static boolean isStreamMute(AudioManager audioManager, @C.StreamType int streamType) {
if (Util.SDK_INT >= 23) {
if (SDK_INT >= 23) {
return audioManager.isStreamMute(streamType);
} else {
return getStreamVolume(audioManager, streamType) == 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import static android.opengl.EGL14.EGL_CONTEXT_CLIENT_VERSION;
import static android.opengl.GLU.gluErrorString;
import static android.os.Build.VERSION.SDK_INT;
import static androidx.media3.common.util.Assertions.checkArgument;
import static androidx.media3.common.util.Assertions.checkState;

Expand Down Expand Up @@ -169,18 +170,17 @@ public static float[] createVertexBuffer(List<float[]> vertexList) {
* <p>If {@code true}, the device supports a protected output path for DRM content when using GL.
*/
public static boolean isProtectedContentExtensionSupported(Context context) {
if (Util.SDK_INT < 24) {
if (SDK_INT < 24) {
return false;
}
if (Util.SDK_INT < 26
&& ("samsung".equals(Build.MANUFACTURER) || "XT1650".equals(Build.MODEL))) {
if (SDK_INT < 26 && ("samsung".equals(Build.MANUFACTURER) || "XT1650".equals(Build.MODEL))) {
// Samsung devices running Nougat are known to be broken. See
// https://github.com/google/ExoPlayer/issues/3373 and [Internal: b/37197802].
// Moto Z XT1650 is also affected. See
// https://github.com/google/ExoPlayer/issues/3215.
return false;
}
if (Util.SDK_INT < 26
if (SDK_INT < 26
&& !context
.getPackageManager()
.hasSystemFeature(PackageManager.FEATURE_VR_MODE_HIGH_PERFORMANCE)) {
Expand Down Expand Up @@ -242,7 +242,7 @@ public static boolean isColorTransferSupported(@C.ColorTransfer int colorTransfe
public static boolean isBt2020PqExtensionSupported() {
// On API<33, the system cannot display PQ content correctly regardless of whether BT2020 PQ
// GL extension is supported. Context: http://b/252537203#comment5.
return Util.SDK_INT >= 33 && isExtensionSupported(EXTENSION_COLORSPACE_BT2020_PQ);
return SDK_INT >= 33 && isExtensionSupported(EXTENSION_COLORSPACE_BT2020_PQ);
}

/** Returns whether {@link #EXTENSION_COLORSPACE_BT2020_HLG} is supported. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package androidx.media3.common.util;

import static androidx.media3.common.util.Util.SDK_INT;
import static android.os.Build.VERSION.SDK_INT;

import android.annotation.SuppressLint;
import android.media.AudioFormat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package androidx.media3.common.util;

import static android.os.Build.VERSION.SDK_INT;
import static androidx.media3.common.util.Assertions.checkNotNull;

import android.annotation.SuppressLint;
Expand Down Expand Up @@ -159,7 +160,7 @@ private void removeClearedReferences() {

private void handleConnectivityActionBroadcast(Context context) {
@C.NetworkType int networkType = getNetworkTypeFromConnectivityManager(context);
if (Util.SDK_INT >= 31 && networkType == C.NETWORK_TYPE_4G) {
if (SDK_INT >= 31 && networkType == C.NETWORK_TYPE_4G) {
// Delay update of the network type to check whether this is actually 5G-NSA.
Api31.disambiguate4gAnd5gNsa(context, /* instance= */ NetworkTypeObserver.this);
} else {
Expand Down Expand Up @@ -239,7 +240,7 @@ private void updateNetworkType(@C.NetworkType int networkType) {
case TelephonyManager.NETWORK_TYPE_LTE:
return C.NETWORK_TYPE_4G;
case TelephonyManager.NETWORK_TYPE_NR:
return Util.SDK_INT >= 29 ? C.NETWORK_TYPE_5G_SA : C.NETWORK_TYPE_UNKNOWN;
return SDK_INT >= 29 ? C.NETWORK_TYPE_5G_SA : C.NETWORK_TYPE_UNKNOWN;
case TelephonyManager.NETWORK_TYPE_IWLAN:
return C.NETWORK_TYPE_WIFI;
case TelephonyManager.NETWORK_TYPE_GSM:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package androidx.media3.common.util;

import static android.os.Build.VERSION.SDK_INT;
import static androidx.media3.common.util.Assertions.checkNotNull;
import static java.lang.annotation.ElementType.TYPE_USE;

Expand Down Expand Up @@ -113,7 +114,7 @@ public static void createNotificationChannel(
@StringRes int nameResourceId,
@StringRes int descriptionResourceId,
@Importance int importance) {
if (Util.SDK_INT >= 26) {
if (SDK_INT >= 26) {
NotificationManager notificationManager =
checkNotNull(
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE));
Expand Down
Loading