Add public API for isWear check in media3-common.
PiperOrigin-RevId: 541925117
This commit is contained in:
parent
b9cc70d9e2
commit
63ca2595be
@ -2687,6 +2687,18 @@ public final class Util {
|
||||
&& context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the app is running on a Wear OS device.
|
||||
*
|
||||
* @param context Any context.
|
||||
* @return Whether the app is running on a Wear OS device.
|
||||
*/
|
||||
@UnstableApi
|
||||
public static boolean isWear(Context context) {
|
||||
return SDK_INT >= 20
|
||||
&& context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the size of the current mode of the default display, in pixels.
|
||||
*
|
||||
|
@ -40,7 +40,6 @@ import static java.lang.Math.min;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.SurfaceTexture;
|
||||
import android.media.AudioDeviceCallback;
|
||||
@ -3324,7 +3323,7 @@ import java.util.concurrent.TimeoutException;
|
||||
|
||||
public static boolean isSuitableAudioOutputPresentInAudioDeviceInfoList(
|
||||
Context context, AudioDeviceInfo[] audioDeviceInfos) {
|
||||
if (!isRunningOnWear(context)) {
|
||||
if (!Util.isWear(context)) {
|
||||
return true;
|
||||
}
|
||||
for (AudioDeviceInfo device : audioDeviceInfos) {
|
||||
@ -3353,11 +3352,6 @@ import java.util.concurrent.TimeoutException;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isRunningOnWear(Context context) {
|
||||
PackageManager packageManager = context.getPackageManager();
|
||||
return packageManager.hasSystemFeature(PackageManager.FEATURE_WATCH);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -27,6 +27,7 @@ import androidx.annotation.Nullable;
|
||||
import androidx.media3.common.Player;
|
||||
import androidx.media3.common.Player.Events;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.common.util.Util;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -96,7 +97,7 @@ public final class WearUnsuitableOutputPlaybackSuppressionResolverListener
|
||||
|
||||
@Override
|
||||
public void onEvents(Player player, Events events) {
|
||||
if (!isRunningOnWear(applicationContext)) {
|
||||
if (!Util.isWear(applicationContext)) {
|
||||
return;
|
||||
}
|
||||
if (events.contains(Player.EVENT_PLAY_WHEN_READY_CHANGED)
|
||||
@ -160,9 +161,4 @@ public final class WearUnsuitableOutputPlaybackSuppressionResolverListener
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean isRunningOnWear(Context context) {
|
||||
PackageManager packageManager = context.getPackageManager();
|
||||
return packageManager.hasSystemFeature(PackageManager.FEATURE_WATCH);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user