{"record":{"id":"2edfe04de36c65a7","repo":"MuntashirAkon/AppManager","slug":"root-service-did-not-start-as-root","errorCode":null,"errorMessage":"Root service did not start as root.","messagePattern":"Root service did not start as root\\.","errorType":"exception","errorClass":"android.os.RemoteException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/settings/Ops.java","lineNumber":340,"sourceCode":"            LocalServices.stopServices();\n        }\n        try {\n            switch (mode) {\n                case MODE_ROOT:\n                    if (!sDirectRoot) {\n                        throw new Exception(\"Root is unavailable.\");\n                    }\n                    // Disable remote server first\n                    ExUtils.exceptionAsIgnored(() -> {\n                        if (LocalServer.checkServerHealth(context)) {\n                            LocalServer.getInstance().closeBgServer();\n                        }\n                    });\n                    sIsSystem = sIsAdb = false;\n                    sIsRoot = true;\n                    LocalServices.bindServicesIfNotAlready();\n                    if (!LocalServices.alive() || Users.getSelfOrRemoteUid() != ROOT_UID) {\n                        throw new RemoteException(\"Root service did not start as root.\");\n                    }\n                    return initPermissionsWithSuccess();\n                case MODE_ADB_WIFI:\n                    sDirectRoot = false;\n                    sIsRoot = sIsSystem = false;\n                    sIsAdb = true;\n                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {\n                        if (!AdbUtils.isWifiConnected(context)) {\n                            throw new Exception(\"Wifi not enabled.\");\n                        }\n                        if (AdbUtils.enableWirelessDebugging(context)) {\n                            // Wireless debugging enabled, try auto-connect\n                            return STATUS_AUTO_CONNECT_WIRELESS_DEBUGGING;\n                        } else {\n                            // Wireless debugging is turned off or there's no permission\n                            return STATUS_WIRELESS_DEBUGGING_CHOOSER_REQUIRED;\n                        }\n                    } // else fallback to ADB over TCP","sourceCodeStart":322,"sourceCodeEnd":358,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/settings/Ops.java#L322-L358","documentation":"During initLocked in root mode, Ops binds the local root service and then verifies it is actually running as root (LocalServices.alive() and effective UID == ROOT_UID). If the service is not alive or is not running as root, a RemoteException is thrown because privileged operations cannot proceed.","triggerScenarios":"Selecting root mode and calling Ops.init(...) when the root service fails to bind or the su session drops privileges, e.g. su denies the request or dies immediately after spawn.","commonSituations":"Device not actually rooted, Magisk superuser prompt denied or timed out, a root manager that breaks Unix socket inheritance, or SELinux preventing the service from keeping root UID.","solutions":["Confirm root actually works: run 'su -c id' via a terminal and verify uid=0","Re-grant root permission to AppManager in Magisk/SuperSU settings","Retry init — transient su daemon issues can fail the first bind","Check SELinux status (setenforce) and Magisk logs for denials; consider enforcing-mode exceptions"],"exampleFix":"// before\nif (!LocalServices.alive() || Users.getSelfOrRemoteUid() != ROOT_UID) {\n    throw new RemoteException(\"Root service did not start as root.\");\n}\n// after\nif (!LocalServices.alive()) {\n    throw new RemoteException(\"Root service failed to bind; su may be denied.\");\n}\nif (Users.getSelfOrRemoteUid() != ROOT_UID) {\n    throw new RemoteException(\"Root service is running as non-root uid=\" + Users.getSelfOrRemoteUid());\n}","handlingStrategy":"try-catch","validationCode":"if (!ShellUtils.rootAccess()) { // e.g. test 'su -c id' returns uid=0\n    // switch to MODE_ADB instead of MODE_ROOT\n}","typeGuard":null,"tryCatchPattern":"try {\n    Ops.init(...);\n} catch (RemoteException e) {\n    Log.e(TAG, \"Root service not running as root; falling back to ADB mode\", e);\n    Ops.setMode(Ops.MODE_ADB);\n    Ops.init(...);\n}","preventionTips":["Verify su access (test command returning uid 0) before selecting root mode","Ensure the app is granted superuser in Magisk/KernelSU manager","Check SELinux policy for denials against the service","Handle the case where the user denies the superuser prompt"],"tags":["android","root","remote-service"],"backgroundTag":"authentication-required","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}