schwabe / ics-openvpn

OpenVPN for Android
3.36k stars 1.2k forks source link

Can't start connect VPN when set System Application #1583

Closed tonhathuy closed 1 year ago

tonhathuy commented 1 year ago

General information

  1. Android Version 7.1.2
  2. Custom ROM
  3. Device: my custom
  4. Version of the app self-built 0.7.41
  5. Architecture x86_64

Description of the issue

I'm looking to integrate your library into my app. I tested some functions like vpnStatus, OpenVPNService and found them working properly. But since my app needs to access deep under android so I changed app to System Application. And it seems the vpn is no longer working.

Create System Application with add android:sharedUserId="android.uid.system" in Manifest.

When I checked the log again I found an error that seems to be caused by android, specifically normally this log line: "Switched from " + mPackage + " to " + newPackage (ex: Switched from [Legacy VPN]] to de.blinkt.openvpn) ) will show after clicking “OK” in popup request VPN connection (permission to monitor traffic ). But in System app , Switched from [Legacy VPN] to [Legacy VPN]. alway show before I click on OK button.

But it's weird that the vpn can work when switching from another vpn that is not Legacy VPN. Eg: Switched from [Legacy VPN] to de.blinkt.openvpn Switched from de.blinkt.openvpn to com.myapp

Log (if applicable)

02-22 08:35:36.893  1710  1721 I ActivityManager: START u0 {act=android.intent.action.MAIN cmp=de.blinkt.openvpn/.LaunchVPN (has extras)} from uid 1000 on display 0
02-22 08:35:37.058  1710  1803 I Vpn     : Switched from [Legacy VPN] to [Legacy VPN]
02-22 08:35:37.059  1710  1803 D Vpn     : setting state=IDLE, reason=prepare
02-22 08:35:37.061  1710  1721 I ActivityManager: START u0 {cmp=com.android.vpndialogs/.ConfirmDialog} from uid 1000 on display 0
02-22 08:35:37.103 20718 20718 W art     : Unexpected CPU variant for X86 using defaults: x86_64
02-22 08:35:37.105  1710  1803 I ActivityManager: Start proc 20718:com.android.vpndialogs/u0a23 for activity com.android.vpndialogs/.ConfirmDialog
02-22 08:35:37.124 20718 20718 W System  : ClassLoader referenced unknown path: /system/priv-app/VpnDialogs/lib/x86_64
02-22 08:35:37.288  1710  1875 W AppOps  : Bad call: specified package de.blinkt.openvpn under uid 10023 but it is really 1000
02-22 08:35:37.288  1710  1875 W AppOps  : java.lang.RuntimeException: here
02-22 08:35:37.288  1710  1875 W AppOps  :  at com.android.server.AppOpsService.getOpsRawLocked(AppOpsService.java:1257)
02-22 08:35:37.288  1710  1875 W AppOps  :  at com.android.server.AppOpsService.noteOperationUnchecked(AppOpsService.java:1020)
02-22 08:35:37.288  1710  1875 W AppOps  :  at com.android.server.AppOpsService.noteOperation(AppOpsService.java:1014)
02-22 08:35:37.288  1710  1875 W AppOps  :  at android.app.AppOpsManager.noteOpNoThrow(AppOpsManager.java:1771)
02-22 08:35:37.288  1710  1875 W AppOps  :  at com.android.server.connectivity.Vpn.isVpnUserPreConsented(Vpn.java:560)
02-22 08:35:37.288  1710  1875 W AppOps  :  at com.android.server.connectivity.Vpn.prepare(Vpn.java:446)
02-22 08:35:37.288  1710  1875 W AppOps  :  at com.android.server.ConnectivityService.prepareVpn(ConnectivityService.java:3500)
02-22 08:35:37.288  1710  1875 W AppOps  :  at android.net.IConnectivityManager$Stub.onTransact(IConnectivityManager.java:536)
02-22 08:35:37.288  1710  1875 W AppOps  :  at android.os.Binder.execTransact(Binder.java:565)
02-22 08:35:37.289  1710  1875 I Vpn     : Switched from [Legacy VPN] to [Legacy VPN]
02-22 08:35:37.289  1710  1875 D Vpn     : setting state=IDLE, reason=prepare
02-22 08:35:38.590  1710  1876 I ActivityManager: START u0 {flg=0x20000 cmp=de.blinkt.openvpn/.activities.LogWindow} from uid 1000 on display 0
02-22 08:35:38.615  2450  2450 W ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.startService:1357 de.blinkt.openvpn.core.VPNLaunchHelper.startOpenVpn:110 de.blinkt.openvpn.LaunchVPN.onActivityResult:254 android.app.Activity.dispatchActivityResult:6945 android.app.ActivityThread.deliverResults:4086 
02-22 08:35:38.618  2342  2342 W ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:892 android.content.ContextWrapper.sendBroadcast:426 de.blinkt.openvpn.core.OpenVPNService.doSendBroadcast:1248 de.blinkt.openvpn.core.OpenVPNService.updateState:1212 de.blinkt.openvpn.core.VpnStatus.addStateListener:272 
02-22 08:35:38.619  1710  1722 E ActivityManager: Sending non-protected broadcast de.blinkt.openvpn.VPN_STATUS from system 2342:de.blinkt.openvpn:openvpn/1000 pkg de.blinkt.openvpn
02-22 08:35:38.619  1710  1722 E ActivityManager: java.lang.Throwable
02-22 08:35:38.619  1710  1722 E ActivityManager:   at com.android.server.am.ActivityManagerService.checkBroadcastFromSystem(ActivityManagerService.java:17927)
02-22 08:35:38.619  1710  1722 E ActivityManager:   at com.android.server.am.ActivityManagerService.broadcastIntentLocked(ActivityManagerService.java:18499)
02-22 08:35:38.619  1710  1722 E ActivityManager:   at com.android.server.am.ActivityManagerService.broadcastIntent(ActivityManagerService.java:18590)
02-22 08:35:38.619  1710  1722 E ActivityManager:   at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:499)
02-22 08:35:38.619  1710  1722 E ActivityManager:   at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2806)
02-22 08:35:38.619  1710  1722 E ActivityManager:   at android.os.Binder.execTransact(Binder.java:565)
schwabe commented 1 year ago

I am closing this since I don't think this is something that I am interested in working on or see any real benefit. Maybe just keep openvpn for android as separate app and just control/start the the VPN with AIDL interface or intents.