3

I am currently using Hexene's LocalVPN implementation of Android's VPNService to monitor network traffic from my Android device. However, I was wondering if it was possible to see which app sent a particular packet.

I have tried searching online, and I have read through the documentation for LocalVPN to no avail :(

EDIT:

Sorry for not making it clear to begin with, I am trying to extend the application for my own development. Not just using the app as an application

Thank you for any help

user3307598
  • 515
  • 1
  • 5
  • 13
  • I'm voting to close this question as off-topic because this is not a programming question – Gabe Sechan Apr 06 '18 at 18:38
  • You could revoke the internet permission of all your applications, except for one. – Stephan Branczyk Apr 06 '18 at 18:41
  • Sorry, I did not make that clear. I am currently writing my own application, by extending the LocalVPN. I was hoping to be able to somehow pull out the ID of another application, by adding to that project – user3307598 Apr 06 '18 at 18:41
  • Duplicates: https://stackoverflow.com/questions/28930342/how-to-get-uid-from-packet-android, https://stackoverflow.com/questions/58497492/acccess-to-proc-net-tcp-in-android-q – tom Jun 07 '23 at 12:09

1 Answers1

0

As of API level 29 (Android 10+), you can use ConnectivityManager.getConnectionOwnerUid(). Once you have the user ID you can call PackageManager.getPackagesForUid() to get the corresponding app ID(s).

For older Android versions, you can parse /proc/net/* to get the user ID. (Note that this method is blocked on Android 10.)

tom
  • 21,844
  • 6
  • 43
  • 36