asLody/VirtualApp · error · RuntimeException

Not supported in system context

Error message

Not supported in system context

What it means

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.

Solutions

  1. Bind services using a normal app Context (Activity or application context of the VA host), never a system context
  2. Verify ContextImpl.mPackageInfo reflection target exists on the current Android version and update the mirror definitions if it changed
  3. Add a try/catch around bindService in the plugin to degrade gracefully on unsupported ROMs

Example fix

// before
IServiceConnection sd = ServiceConnectionDelegate.getDelegate(systemContext, conn, flags);
// after
IServiceConnection sd = ServiceConnectionDelegate.getDelegate(appContext, conn, flags); // non-system context
Defensive patterns

Strategy: try-catch

Validate before calling

boolean isSystemContext = context.getSystemService(ActivityManager.class) != null && context.getPackageName() == null; // avoid system ctx for binding
if (context is system context) use appContext instead;

Try / catch

try { sd = ServiceConnectionDelegate.getDelegate(ctx, conn, flags); } catch (RuntimeException e) { Log.e(TAG, "bind unsupported in this context/ROM", e); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of asLody/VirtualApp@666fefcb5d (2026-09-09). Data as JSON: /api/errors/cb99a539a7dcb533. Report an issue: GitHub.

Appendix: source

Thrown at VirtualApp/lib/src/main/java/com/lody/virtual/client/hook/secondary/ServiceConnectionDelegate.java:49

    private ServiceConnectionDelegate(IServiceConnection mConn) {
        this.mConn = mConn;
    }

    public static IServiceConnection getDelegate(Context context, ServiceConnection connection,int flags) {
        IServiceConnection sd = null;
        if (connection == null) {
            throw new IllegalArgumentException("connection is null");
        }
        try {
            Object activityThread = ActivityThread.currentActivityThread.call();
            Object loadApk = ContextImpl.mPackageInfo.get(VirtualCore.get().getContext());
            Handler handler = ActivityThread.getHandler.call(activityThread);
            sd = LoadedApk.getServiceDispatcher.call(loadApk, connection, context, handler, flags);
        } catch (Exception e) {
            Log.e("ConnectionDelegate", "getServiceDispatcher", e);
        }
        if (sd == null) {
            throw new RuntimeException("Not supported in system context");
        }
        return getDelegate(sd);
    }

    public static IServiceConnection removeDelegate(Context context, ServiceConnection conn) {
        IServiceConnection connection = null;
        try{
            Object loadApk = ContextImpl.mPackageInfo.get(VirtualCore.get().getContext());
            connection = LoadedApk.forgetServiceDispatcher.call(loadApk, context, conn);
        }catch (Exception e){
            Log.e("ConnectionDelegate", "forgetServiceDispatcher", e);
        }
        if(connection == null){
            return null;
        }
        return ServiceConnectionDelegate.removeDelegate(connection);
    }

View on GitHub (pinned to 666fefcb5d)