Skip to content

Commit 7551482

Browse files
committed
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 <[email protected]>
1 parent 15fea6f commit 7551482

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

tunnel/src/main/java/com/wireguard/android/util/RootShell.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@ public class RootShell {
4343
public RootShell(final Context context) {
4444
localBinaryDir = new File(context.getCodeCacheDir(), "bin");
4545
localTemporaryDir = new File(context.getCacheDir(), "tmp");
46-
preamble = String.format("export CALLING_PACKAGE=%s PATH=\"%s:$PATH\" TMPDIR='%s'; id -u\n",
47-
context.getPackageName(), localBinaryDir, localTemporaryDir);
46+
final String packageName = context.getPackageName();
47+
if (packageName.contains("'"))
48+
throw new RuntimeException("Impossibly invalid package name contains a single quote");
49+
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",
50+
packageName, localBinaryDir, localTemporaryDir, packageName);
4851
}
4952

5053
private static boolean isExecutableInPath(final String name) {

0 commit comments

Comments
 (0)