Additional changes to AudioCapabilities.java and Util.java

This commit is contained in:
Cedric T 2023-05-10 18:09:09 +08:00 committed by Tianyi Feng
parent b1ac7685bd
commit 924723d6b3
2 changed files with 5 additions and 43 deletions

View file

@ -516,26 +516,6 @@ public final class Util {
return concatenation; return concatenation;
} }
/**
* Creates a new Integer array containing the concatenation of two non-null Integer arrays.
*
* @param first The first array.
* @param second The second array.
* @return The concatenated result.
*/
@UnstableApi
@SuppressWarnings("nullness:assignment")
public static int[] nullSafeIntegerArrayConcatenation(int[] first, int[] second) {
int[] concatenation = Arrays.copyOf(first, first.length + second.length);
System.arraycopy(
/* src= */ second,
+ /* srcPos= */ 0,
/* dest= */ concatenation,
/* destPos= */ first.length,
/* length= */ second.length);
return concatenation;
}
/** /**
* Remove duplicates from an Integer array. * Remove duplicates from an Integer array.
* *
@ -576,23 +556,6 @@ public final class Util {
list.toArray(array); list.toArray(array);
} }
/**
* Creates a new Integer array from a List of Integers.
*
* @param list The list of integers to convert.
* @return Created array of integers.
*/
@UnstableApi
@SuppressWarnings("nullness:assignment")
public static int[] nullSafeIntegerListToArray(List<Integer> list) {
int[] intList = new int[list.size()];
for (int i = 0; i < list.size(); i++) {
intList[i] = list.get(i);
}
return intList;
}
/** /**
* Creates a {@link Handler} on the current {@link Looper} thread. * Creates a {@link Handler} on the current {@link Looper} thread.
* *

View file

@ -112,9 +112,8 @@ public final class AudioCapabilities {
// it on TV and automotive devices, which generally shouldn't support audio offload for surround // it on TV and automotive devices, which generally shouldn't support audio offload for surround
// encodings. // encodings.
if (Util.SDK_INT >= 29 && (Util.isTv(context) || Util.isAutomotive(context))) { if (Util.SDK_INT >= 29 && (Util.isTv(context) || Util.isAutomotive(context))) {
supportedEncodings = Util.nullSafeIntegerArrayConcatenation(supportedEncodings, supportedEncodings = Ints.concat(supportedEncodings,
Api29.getDirectPlaybackSupportedEncodings( Api29.getDirectPlaybackSupportedEncodings(Api29.getAllSurroundEncodingsMaybeSupported()));
Util.nullSafeIntegerListToArray(Api29.getAllSurroundEncodingsMaybeSupported())));
} }
if (intent == null || intent.getIntExtra(AudioManager.EXTRA_AUDIO_PLUG_STATE, 0) == 0) { if (intent == null || intent.getIntExtra(AudioManager.EXTRA_AUDIO_PLUG_STATE, 0) == 0) {
@ -127,7 +126,7 @@ public final class AudioCapabilities {
} }
} }
supportedEncodings = Util.nullSafeIntegerArrayConcatenation(supportedEncodings, supportedEncodings = Ints.concat(supportedEncodings,
intent.getIntArrayExtra(AudioManager.EXTRA_ENCODINGS)); intent.getIntArrayExtra(AudioManager.EXTRA_ENCODINGS));
supportedEncodings = Util.nullSafeIntegerArrayDistinct(supportedEncodings); supportedEncodings = Util.nullSafeIntegerArrayDistinct(supportedEncodings);
return new AudioCapabilities( return new AudioCapabilities(
@ -409,7 +408,7 @@ public final class AudioCapabilities {
/** /**
* Returns an array list of surround encodings that maybe supported. * Returns an array list of surround encodings that maybe supported.
*/ */
private static ImmutableList<Integer> getAllSurroundEncodingsMaybeSupported() { private static int[] getAllSurroundEncodingsMaybeSupported() {
ImmutableList.Builder<Integer> encodings = new ImmutableList.Builder<>(); ImmutableList.Builder<Integer> encodings = new ImmutableList.Builder<>();
for (int encoding : ALL_SURROUND_ENCODINGS_AND_MAX_CHANNELS.keySet()) { for (int encoding : ALL_SURROUND_ENCODINGS_AND_MAX_CHANNELS.keySet()) {
// AudioFormat.ENCODING_DTS_UHD_P2 is supported from API 34. // AudioFormat.ENCODING_DTS_UHD_P2 is supported from API 34.
@ -418,7 +417,7 @@ public final class AudioCapabilities {
} }
encodings.add(encoding); encodings.add(encoding);
} }
return encodings.build(); return Ints.toArray(encodings.build());
} }
} }
} }