MuntashirAkon/AppManager · error · java.lang.IllegalArgumentException
Unknown mode of operation: ${newMode}
Error message
Unknown mode of operation: ${newMode} What it means
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.
Source
Thrown at app/src/main/java/io/github/muntashirakon/AppManager/settings/Ops.java:266
AppPref.set(AppPref.PrefKey.PREF_MODE_OF_OPS_STR, mode);
}
if (!isValidMode(mode)) {
// Reset mode
mode = MODE_AUTO;
AppPref.set(AppPref.PrefKey.PREF_MODE_OF_OPS_STR, mode);
}
if ((MODE_ADB_OVER_TCP.equals(mode) || MODE_ADB_WIFI.equals(mode))
&& !SelfPermissions.checkSelfPermission(Manifest.permission.INTERNET)) {
// ADB enabled but the INTERNET permission is not granted, replace current with auto.
return MODE_AUTO;
}
return mode;
}
@NoOps
public static void setMode(@Mode @NonNull String newMode) {
if (!isValidMode(newMode)) {
throw new IllegalArgumentException("Unknown mode of operation: " + newMode);
}
AppPref.set(AppPref.PrefKey.PREF_MODE_OF_OPS_STR, newMode);
if (!MODE_ADB_WIFI.equals(newMode)) {
Context context = ContextUtils.getContext();
context.stopService(new Intent(context, WifiWaitService.class));
context.stopService(new Intent(context, AdbPairingService.class));
}
}
private static boolean isValidMode(@NonNull String mode) {
switch (mode) {
case MODE_AUTO:
case MODE_ROOT:
case MODE_ADB_OVER_TCP:
case MODE_ADB_WIFI:
case MODE_NO_ROOT:
return true;
default:View on GitHub (pinned to 0152f468fc)
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
Example fix
// before
Ops.setMode(prefs.getString("mode", ""));
// after
String mode = prefs.getString("mode", Ops.MODE_NO_ROOT);
Ops.setMode(Ops.isValidMode(mode) ? mode : Ops.MODE_NO_ROOT); Defensive patterns
Strategy: type-guard
Validate before calling
if (!Ops.isValidMode(candidateMode)) {
candidateMode = Ops.MODE_NO_ROOT; // safe default
} Try / catch
try {
Ops.setMode(newMode);
} catch (IllegalArgumentException e) {
Log.w(TAG, "Unknown mode, falling back", e);
Ops.setMode(Ops.MODE_NO_ROOT);
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Unknown density {densityName}
- Package name is missing.
- No splits selected.
- Invalid export type: {exportType}
- "manifest" has duplicate "application" tags.
AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12).
Data as JSON: /api/errors/b7d5357b8de85864.
Report an issue: GitHub.