Skip to content

UID always 0: getConnectionOwnerUid() result discarded at JNI bridge #2100

@salty-flower

Description

@salty-flower

Summary

metadata.Uid is always 0 for all connections on Android Q+. UID rules (UID,90010466,proxy) never match — traffic falls through to MATCH. PROCESS-NAME rules work correctly.

Root Cause

The Java layer calls ConnectivityManager.getConnectionOwnerUid() and gets the correct UID. It uses this UID to resolve the package name via PackageManager.getPackagesForUid(uid). However, the JNI bridge (resolve_process) only returns the package name string — the UID integer is discarded at the JNI boundary.

Java:  getConnectionOwnerUid() → uid ✓ → getPackagesForUid(uid) → "com.example" ✓
JNI:   resolve_process() → returns char* (package name only)
Go:    metadata.Process = "com.example" ✓
       metadata.Uid = 0  ← never assigned

Code path

  1. android/service/.../VpnService.ktresolverProcess() calls getConnectionOwnerUid(), gets real UID, resolves package name
  2. android/core/src/main/cpp/core.cpp — JNI bridge receives UID but only passes package name string back
  3. core/bride.go / core/bride.h — CGO bridge signature is char*, no room for UID
  4. core/lib.go — assigns returned string to metadata.Process, metadata.Uid stays 0
  5. core/platform/procfs.go/proc/net/tcp fallback gated by version < 29, skipped on Android Q+

Proposed Fix

Modify the JNI bridge to return both package name and UID:

  1. bride.h — change return type or add out-parameter for UID
  2. core.cpp — pass UID from Java getConnectionOwnerUid() back through JNI
  3. bride.go — CGO bridge returns struct {name string, uid uint32}
  4. lib.go — assign UID to metadata.Uid

Reproduction

  1. Configure mihomo with UID,<uid>,<proxy> rules
  2. Check /connections API: all entries show "uid": 0
  3. UID rules never match, traffic falls to MATCH
  4. PROCESS-NAME rules work correctly (confirms process resolution is functional)

Environment

  • FlClash latest
  • Android 15 (API 35)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions