2

Instead of using 3rd party app freezers, I've been using "pm disable-user" / "pm uninstall" for years to disable/uninstall bloatware. However, some apps, if uninstalled (or even disabled sometimes), bootloop the device or just break basic functionality.

So, I wish to block internet access to that bloatware which indirectly prevents me from removing it.

Is there an adb command to implement internet blocking on a per app basis, like "pm uninstall" is for uninstalling?

(Yes, there are plenty firewall apps, but why rely on a 3rd-party app for something you can do yourself?)

3
  • If you have root, a hardened iptables solution could be viable. For blocking per app net access, the uid of the apps are needed. App like Afwall+ could handle the job pretty good. It's open source and you cloud asses the codes on Github any time
    – atheros
    Sep 22, 2020 at 21:30
  • 1
    honeymoly is correct. Per app blocking works only on UID basis. With root you can use iptables manually from commandline. Without root you need to use VPN, which requires an app. But even with root, keeping in view the complexity of firewall rules and the changes that occur on network events, it's not feasible to use iptables manually without using a third party app like AFWall+. Also blocking apps isn't always fruitful. Apps might be using shared UID. Or they may use other apps' APIs (e.g. of Play Services) to get/send data from/to internet. Sep 23, 2020 at 1:16
  • I'm using unrooted stock Samsung S9, so pretty much... nah... right? Sep 24, 2020 at 8:59

1 Answer 1

0

I've found something, which seems to work for Chrome web-browser, and requires a rooted device.

Sadly it seems to work on old Android version (tested on Android 9), but for some reason doesn't work properly on Android 13.

@echo off
set package_name="com.android.chrome"

c:
cd\
cd C:\Users\User\AppData\Local\Android\Sdk\platform-tools

for /f "delims=" %%A in ('adb shell dumpsys package %package_name% ^| findstr "userId="') do (
  for /f "tokens=2 delims== " %%B in ("%%A") do (
    echo Extracted UID: %%B
    adb shell "su -c 'iptables -A OUTPUT -m owner --uid-owner %%B -j DROP'"
  )
)

And to allow connection again:

@echo off
set package_name="com.android.chrome"

c:
cd\
cd C:\Users\User\AppData\Local\Android\Sdk\platform-tools

for /f "delims=" %%A in ('adb shell dumpsys package %package_name% ^| findstr "userId="') do (
  for /f "tokens=2 delims== " %%B in ("%%A") do (
    echo Extracted UID: %%B
    adb shell "su -c 'iptables -D OUTPUT -m owner --uid-owner %%B -j DROP'"
  )
)

If anyone can improve it and tell me how to fix it, please let me know

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .