{"record":{"id":"cb99a539a7dcb533","repo":"asLody/VirtualApp","slug":"not-supported-in-system-context","errorCode":null,"errorMessage":"Not supported in system context","messagePattern":"Not supported in system context","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"VirtualApp/lib/src/main/java/com/lody/virtual/client/hook/secondary/ServiceConnectionDelegate.java","lineNumber":49,"sourceCode":"    private ServiceConnectionDelegate(IServiceConnection mConn) {\n        this.mConn = mConn;\n    }\n\n    public static IServiceConnection getDelegate(Context context, ServiceConnection connection,int flags) {\n        IServiceConnection sd = null;\n        if (connection == null) {\n            throw new IllegalArgumentException(\"connection is null\");\n        }\n        try {\n            Object activityThread = ActivityThread.currentActivityThread.call();\n            Object loadApk = ContextImpl.mPackageInfo.get(VirtualCore.get().getContext());\n            Handler handler = ActivityThread.getHandler.call(activityThread);\n            sd = LoadedApk.getServiceDispatcher.call(loadApk, connection, context, handler, flags);\n        } catch (Exception e) {\n            Log.e(\"ConnectionDelegate\", \"getServiceDispatcher\", e);\n        }\n        if (sd == null) {\n            throw new RuntimeException(\"Not supported in system context\");\n        }\n        return getDelegate(sd);\n    }\n\n    public static IServiceConnection removeDelegate(Context context, ServiceConnection conn) {\n        IServiceConnection connection = null;\n        try{\n            Object loadApk = ContextImpl.mPackageInfo.get(VirtualCore.get().getContext());\n            connection = LoadedApk.forgetServiceDispatcher.call(loadApk, context, conn);\n        }catch (Exception e){\n            Log.e(\"ConnectionDelegate\", \"forgetServiceDispatcher\", e);\n        }\n        if(connection == null){\n            return null;\n        }\n        return ServiceConnectionDelegate.removeDelegate(connection);\n    }\n","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/asLody/VirtualApp/blob/666fefcb5d3f39cc944001c3457c38ffd6544c87/VirtualApp/lib/src/main/java/com/lody/virtual/client/hook/secondary/ServiceConnectionDelegate.java#L31-L67","documentation":"After the native LoadedApk.getServiceDispatcher call fails (its exception is only logged), sd remains null; the library then throws this RuntimeException because a system/application context is required to create a service-connection dispatcher. In a system context (no LoadedApk/PackageInfo), binder dispatchers for ServiceConnection cannot be created.","triggerScenarios":"Calling getDelegate from a system-level Context (e.g., created with the system server's context or a context without mPackageInfo), causing LoadedApk.getServiceDispatcher to fail and return null.","commonSituations":"Running in a process started as system/root where ContextImpl.mPackageInfo is unavailable; using an application context obtained through unusual reflection paths; ROM-specific changes breaking the mirror of LoadedApk.getServiceDispatcher on newer Android versions.","solutions":["Bind services using a normal app Context (Activity or application context of the VA host), never a system context","Verify ContextImpl.mPackageInfo reflection target exists on the current Android version and update the mirror definitions if it changed","Add a try/catch around bindService in the plugin to degrade gracefully on unsupported ROMs"],"exampleFix":"// before\nIServiceConnection sd = ServiceConnectionDelegate.getDelegate(systemContext, conn, flags);\n// after\nIServiceConnection sd = ServiceConnectionDelegate.getDelegate(appContext, conn, flags); // non-system context","handlingStrategy":"try-catch","validationCode":"boolean isSystemContext = context.getSystemService(ActivityManager.class) != null && context.getPackageName() == null; // avoid system ctx for binding\nif (context is system context) use appContext instead;","typeGuard":null,"tryCatchPattern":"try { sd = ServiceConnectionDelegate.getDelegate(ctx, conn, flags); } catch (RuntimeException e) { Log.e(TAG, \"bind unsupported in this context/ROM\", e); }","preventionTips":["Bind services only with normal app/Activity contexts","Test on target ROMs/Android versions where reflection targets may change","Keep mirror definitions updated per API level"],"tags":["android","service","context","reflection"],"backgroundTag":"unsupported-operation","analyzedSha":"666fefcb5d3f39cc944001c3457c38ffd6544c87","analyzedAt":"2026-09-09T11:09:01.694Z","contentChangedAt":"2026-09-09T11:09:01.694Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}