From 88eed6cc2323a5170a2f57b921392087e269551d Mon Sep 17 00:00:00 2001 From: Hanif Shersy Date: Wed, 4 May 2022 18:39:08 +1000 Subject: [PATCH] Add JSDoc comment and a performance note for `isDesktopMode` --- .../java/org/schabi/newpipe/util/DeviceUtils.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/util/DeviceUtils.java b/app/src/main/java/org/schabi/newpipe/util/DeviceUtils.java index c4d3a7bbf..081a205ea 100644 --- a/app/src/main/java/org/schabi/newpipe/util/DeviceUtils.java +++ b/app/src/main/java/org/schabi/newpipe/util/DeviceUtils.java @@ -88,12 +88,19 @@ public final class DeviceUtils { return DeviceUtils.isTV; } + /** + * Checks if the device is in desktop or DeX mode. This function should only + * be invoked once on view load as it is using reflection for the DeX checks. + * @param context the context to use for services and config. + * @return true if the Android device is in desktop mode or using DeX. + */ public static boolean isDesktopMode(final Context context) { if (ContextCompat.getSystemService(context, UiModeManager.class) .getCurrentModeType() == Configuration.UI_MODE_TYPE_DESK) { return true; } - // DeX check for standalone and multi-window mode + // DeX check for standalone and multi-window mode, from: + // https://developer.samsung.com/samsung-dex/modify-optimizing.html try { final Configuration config = context.getResources().getConfiguration(); final Class configClass = config.getClass(); @@ -119,8 +126,8 @@ public final class DeviceUtils { final Class desktopModeStateClass = desktopModeState.getClass(); final Method getEnabledMethod = desktopModeStateClass .getDeclaredMethod("getEnabled"); - final int enabled = (int) getEnabledMethod.invoke(desktopModeState); - if (enabled == desktopModeStateClass + final int enabledStatus = (int) getEnabledMethod.invoke(desktopModeState); + if (enabledStatus == desktopModeStateClass .getDeclaredField("ENABLED").getInt(desktopModeStateClass)) { return true; }