@@ -88,12 +88,19 @@ public static boolean isTv(final Context context) {
8888 return DeviceUtils .isTV ;
8989 }
9090
91+ /**
92+ * Checks if the device is in desktop or DeX mode. This function should only
93+ * be invoked once on view load as it is using reflection for the DeX checks.
94+ * @param context the context to use for services and config.
95+ * @return true if the Android device is in desktop mode or using DeX.
96+ */
9197 public static boolean isDesktopMode (final Context context ) {
9298 if (ContextCompat .getSystemService (context , UiModeManager .class )
9399 .getCurrentModeType () == Configuration .UI_MODE_TYPE_DESK ) {
94100 return true ;
95101 }
96- // DeX check for standalone and multi-window mode
102+ // DeX check for standalone and multi-window mode, from:
103+ // https://developer.samsung.com/samsung-dex/modify-optimizing.html
97104 try {
98105 final Configuration config = context .getResources ().getConfiguration ();
99106 final Class <?> configClass = config .getClass ();
@@ -119,8 +126,8 @@ public static boolean isDesktopMode(final Context context) {
119126 final Class <?> desktopModeStateClass = desktopModeState .getClass ();
120127 final Method getEnabledMethod = desktopModeStateClass
121128 .getDeclaredMethod ("getEnabled" );
122- final int enabled = (int ) getEnabledMethod .invoke (desktopModeState );
123- if (enabled == desktopModeStateClass
129+ final int enabledStatus = (int ) getEnabledMethod .invoke (desktopModeState );
130+ if (enabledStatus == desktopModeStateClass
124131 .getDeclaredField ("ENABLED" ).getInt (desktopModeStateClass )) {
125132 return true ;
126133 }
0 commit comments