/** * Returns a user agent string based on the given application name and the library version. * * @param context A valid context of the calling application. * @param applicationName String that will be prefix'ed to the generated user agent. * @return A user agent string generated using the applicationName and the library version. */ public static String getUserAgent(Context context, String applicationName) { String versionName; try { String packageName = context.getPackageName(); PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0); versionName = info.versionName; } catch (NameNotFoundException e) { versionName = "?"; } return applicationName + "/" + versionName + " (Linux;Android " + Build.VERSION.RELEASE + ") " + ExoPlayerLibraryInfo.VERSION_SLASHY; }
@Test public void whenGettingPlayerInformation_thenReturnsPlayerInformation() { PlayerInformation playerInformation = player.getPlayerInformation(); assertThat(playerInformation.getPlayerType()).isEqualTo(PlayerType.EXO_PLAYER); assertThat(playerInformation.getVersion()).isEqualTo(ExoPlayerLibraryInfo.VERSION); }
/** * Returns a user agent string based on the given application name and the library version. * * @param context A valid context of the calling application. * @param applicationName String that will be prefix'ed to the generated user agent. * @return A user agent string generated using the applicationName and the library version. */ public static String getUserAgent(Context context, String applicationName) { String versionName; try { String packageName = context.getPackageName(); PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0); versionName = info.versionName; } catch (NameNotFoundException e) { versionName = "?"; } return applicationName + "/" + versionName + " (Linux;Android " + Build.VERSION.RELEASE + ") " + "ExoPlayerLib/" + ExoPlayerLibraryInfo.VERSION; }
/** * Writes a trace message to indicate that a given section of code has ended. * * @see android.os.Trace#endSection() */ public static void endSection() { if (ExoPlayerLibraryInfo.TRACE_ENABLED && Util.SDK_INT >= 18) { endSectionV18(); } }
@Override public String getVersion() { return ExoPlayerLibraryInfo.VERSION; }
/** * Throws {@link NullPointerException} if {@code reference} is null. * * @param <T> The type of the reference. * @param reference The reference. * @return The non-null reference that was validated. * @throws NullPointerException If {@code reference} is null. */ public static <T> T checkNotNull(T reference) { if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && reference == null) { throw new NullPointerException(); } return reference; }
/** * Throws {@link NullPointerException} if {@code reference} is null. * * @param <T> The type of the reference. * @param reference The reference. * @param errorMessage The exception message to use if the check fails. The message is converted * to a string using {@link String#valueOf(Object)}. * @return The non-null reference that was validated. * @throws NullPointerException If {@code reference} is null. */ public static <T> T checkNotNull(T reference, Object errorMessage) { if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && reference == null) { throw new NullPointerException(String.valueOf(errorMessage)); } return reference; }
/** * Throws {@link IllegalArgumentException} if {@code string} is null or zero length. * * @param string The string to check. * @return The non-null, non-empty string that was validated. * @throws IllegalArgumentException If {@code string} is null or 0-length. */ public static String checkNotEmpty(String string) { if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && TextUtils.isEmpty(string)) { throw new IllegalArgumentException(); } return string; }
/** * Throws {@link IllegalArgumentException} if {@code string} is null or zero length. * * @param string The string to check. * @param errorMessage The exception message to use if the check fails. The message is converted * to a string using {@link String#valueOf(Object)}. * @return The non-null, non-empty string that was validated. * @throws IllegalArgumentException If {@code string} is null or 0-length. */ public static String checkNotEmpty(String string, Object errorMessage) { if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && TextUtils.isEmpty(string)) { throw new IllegalArgumentException(String.valueOf(errorMessage)); } return string; }
@Test public void whenReadingVersion_thenReturnsExoPlayerLibraryVersion() { String version = playerInformation.getVersion(); assertThat(version).isEqualTo(ExoPlayerLibraryInfo.VERSION); }
/** * Writes a trace message to indicate that a given section of code has begun. * * @see android.os.Trace#beginSection(String) * @param sectionName The name of the code section to appear in the trace. This may be at most 127 * Unicode code units long. */ public static void beginSection(String sectionName) { if (ExoPlayerLibraryInfo.TRACE_ENABLED && Util.SDK_INT >= 18) { beginSectionV18(sectionName); } }
/** * Throws {@link IllegalArgumentException} if {@code expression} evaluates to false. * * @param expression The expression to evaluate. * @throws IllegalArgumentException If {@code expression} is false. */ public static void checkArgument(boolean expression) { if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && !expression) { throw new IllegalArgumentException(); } }
/** * Throws {@link IllegalArgumentException} if {@code expression} evaluates to false. * * @param expression The expression to evaluate. * @param errorMessage The exception message if an exception is thrown. The message is converted * to a {@link String} using {@link String#valueOf(Object)}. * @throws IllegalArgumentException If {@code expression} is false. */ public static void checkArgument(boolean expression, Object errorMessage) { if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && !expression) { throw new IllegalArgumentException(String.valueOf(errorMessage)); } }
/** * Throws {@link IllegalStateException} if {@code expression} evaluates to false. * * @param expression The expression to evaluate. * @throws IllegalStateException If {@code expression} is false. */ public static void checkState(boolean expression) { if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && !expression) { throw new IllegalStateException(); } }
/** * Throws {@link IllegalStateException} if {@code expression} evaluates to false. * * @param expression The expression to evaluate. * @param errorMessage The exception message if an exception is thrown. The message is converted * to a {@link String} using {@link String#valueOf(Object)}. * @throws IllegalStateException If {@code expression} is false. */ public static void checkState(boolean expression, Object errorMessage) { if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && !expression) { throw new IllegalStateException(String.valueOf(errorMessage)); } }
/** * Throws {@link IllegalStateException} if the calling thread is not the application's main * thread. * * @throws IllegalStateException If the calling thread is not the application's main thread. */ public static void checkMainThread() { if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && Looper.myLooper() != Looper.getMainLooper()) { throw new IllegalStateException("Not in applications main thread"); } }