{"record":{"id":"b7d5357b8de85864","repo":"MuntashirAkon/AppManager","slug":"unknown-mode-of-operation-newmode","errorCode":null,"errorMessage":"Unknown mode of operation: ${newMode}","messagePattern":"Unknown mode of operation: (.+?)","errorType":"validation","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/settings/Ops.java","lineNumber":266,"sourceCode":"            AppPref.set(AppPref.PrefKey.PREF_MODE_OF_OPS_STR, mode);\n        }\n        if (!isValidMode(mode)) {\n            // Reset mode\n            mode = MODE_AUTO;\n            AppPref.set(AppPref.PrefKey.PREF_MODE_OF_OPS_STR, mode);\n        }\n        if ((MODE_ADB_OVER_TCP.equals(mode) || MODE_ADB_WIFI.equals(mode))\n                && !SelfPermissions.checkSelfPermission(Manifest.permission.INTERNET)) {\n            // ADB enabled but the INTERNET permission is not granted, replace current with auto.\n            return MODE_AUTO;\n        }\n        return mode;\n    }\n\n    @NoOps\n    public static void setMode(@Mode @NonNull String newMode) {\n        if (!isValidMode(newMode)) {\n            throw new IllegalArgumentException(\"Unknown mode of operation: \" + newMode);\n        }\n        AppPref.set(AppPref.PrefKey.PREF_MODE_OF_OPS_STR, newMode);\n        if (!MODE_ADB_WIFI.equals(newMode)) {\n            Context context = ContextUtils.getContext();\n            context.stopService(new Intent(context, WifiWaitService.class));\n            context.stopService(new Intent(context, AdbPairingService.class));\n        }\n    }\n\n    private static boolean isValidMode(@NonNull String mode) {\n        switch (mode) {\n            case MODE_AUTO:\n            case MODE_ROOT:\n            case MODE_ADB_OVER_TCP:\n            case MODE_ADB_WIFI:\n            case MODE_NO_ROOT:\n                return true;\n            default:","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/settings/Ops.java#L248-L284","documentation":"Ops.setMode validates the new mode string against the known modes (root, ADB, system, etc.) via isValidMode before persisting it. An unrecognized mode string throws IllegalArgumentException naming the invalid mode.","triggerScenarios":"Calling Ops.setMode(newMode) with a string that is not one of the MODE_* constants, e.g. \"Root\", \"adb_wifi\" casing mismatch, or a value read from old/migrated preferences.","commonSituations":"Persisted mode strings from an older app version that no longer match constants, hand-edited preference files, or localization mistakes passing a translated mode label instead of the constant.","solutions":["Pass only the Ops.MODE_* constants (MODE_ROOT, MODE_ADB, MODE_ADB_WIFI, MODE_SYSTEM, MODE_NO_ROOT) to setMode","Pre-check with Ops.isValidMode(newMode) and fall back to a default mode if false","If migrating old preferences, map legacy mode strings to current constants before applying","Check for case or whitespace differences — trim and normalize, then compare against constants"],"exampleFix":"// before\nOps.setMode(prefs.getString(\"mode\", \"\"));\n// after\nString mode = prefs.getString(\"mode\", Ops.MODE_NO_ROOT);\nOps.setMode(Ops.isValidMode(mode) ? mode : Ops.MODE_NO_ROOT);","handlingStrategy":"type-guard","validationCode":"if (!Ops.isValidMode(candidateMode)) {\n    candidateMode = Ops.MODE_NO_ROOT; // safe default\n}","typeGuard":null,"tryCatchPattern":"try {\n    Ops.setMode(newMode);\n} catch (IllegalArgumentException e) {\n    Log.w(TAG, \"Unknown mode, falling back\", e);\n    Ops.setMode(Ops.MODE_NO_ROOT);\n}","preventionTips":["Only pass Ops.MODE_* constants, never raw strings from UI","Normalize (trim/case) any mode value loaded from persisted prefs","Map legacy mode strings during migration","Guard with isValidMode before persisting"],"tags":["android","validation","enum"],"backgroundTag":"invalid-enum-value","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}