summaryrefslogtreecommitdiffhomepage
path: root/tunnel/src/main/java
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-10-26 22:44:35 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2020-10-26 22:44:35 +0100
commit755148242c11619f92809fcaadf6144c3ad7ca52 (patch)
tree184873bbd271c0b0ee68f4be53475f65ac0926e8 /tunnel/src/main/java
parent15fea6f02ff0c40bd88355b55c6530f89837c447 (diff)
tunnel: do not constantly raise toasts when process is opportunistically killed
Modern Android likes to kill processes to free ram and resources. When kernel-mode WireGuard is in use, this is quite alright with us, since the app doesn't actually need to consume any resources at all in order for the tunnel to run. So, we want to allow and encourage this resource frugality. However, when the quick settings tile is being used or when the app is referenced otherwise, the app will occasionally be restarted, to, for example, repaint the quick settings tile. This is also fine, as the process winds up being short-lived again. But, since process initialization means asking for a new root shell in order to check on kernel-mode WireGuard, this means that Magisk raises a systemwide toast. On some phones, this happens each and every time that the notification shade is pulled down. It's not only annoying but it sometimes obscures other notifications that users want to see, prompting their pulling down of the notification shade in the first place. In order to get rid of this nuisance, just disable these notifications and extraneous logs, so that we don't clutter the system every time that the process is opportunistically killed and restarted. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'tunnel/src/main/java')
-rw-r--r--tunnel/src/main/java/com/wireguard/android/util/RootShell.java7
1 files changed, 5 insertions, 2 deletions
diff --git a/tunnel/src/main/java/com/wireguard/android/util/RootShell.java b/tunnel/src/main/java/com/wireguard/android/util/RootShell.java
index 6fe89a83..90071573 100644
--- a/tunnel/src/main/java/com/wireguard/android/util/RootShell.java
+++ b/tunnel/src/main/java/com/wireguard/android/util/RootShell.java
@@ -43,8 +43,11 @@ public class RootShell {
public RootShell(final Context context) {
localBinaryDir = new File(context.getCodeCacheDir(), "bin");
localTemporaryDir = new File(context.getCacheDir(), "tmp");
- preamble = String.format("export CALLING_PACKAGE=%s PATH=\"%s:$PATH\" TMPDIR='%s'; id -u\n",
- context.getPackageName(), localBinaryDir, localTemporaryDir);
+ final String packageName = context.getPackageName();
+ if (packageName.contains("'"))
+ throw new RuntimeException("Impossibly invalid package name contains a single quote");
+ preamble = String.format("export CALLING_PACKAGE=%s PATH=\"%s:$PATH\" TMPDIR='%s'; magisk --sqlite \"UPDATE policies SET notification=0, logging=0 WHERE package_name='%s'\" >/dev/null 2>&1; id -u\n",
+ packageName, localBinaryDir, localTemporaryDir, packageName);
}
private static boolean isExecutableInPath(final String name) {