From 9d79f868f0e23079f6bd0f987fd74b73aec43a8b Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sun, 4 Oct 2026 21:50:57 -0700 Subject: [PATCH] test: update su test to explicitly grant access With interactive su prompting removed, update MagiskAppTest to explicitly grant su access to the ADB shell UID in the policy database rather than relying on SuRequestActivity launch and auto-allow config. Assisted-by: Gemini 3.8 Flash --- .../topjohnwu/magisk/test/MagiskAppTest.kt | 32 +++---------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/app/core/src/main/java/com/topjohnwu/magisk/test/MagiskAppTest.kt b/app/core/src/main/java/com/topjohnwu/magisk/test/MagiskAppTest.kt index a359481af..78def704d 100644 --- a/app/core/src/main/java/com/topjohnwu/magisk/test/MagiskAppTest.kt +++ b/app/core/src/main/java/com/topjohnwu/magisk/test/MagiskAppTest.kt @@ -1,23 +1,17 @@ package com.topjohnwu.magisk.test -import android.content.Intent -import android.content.IntentFilter import android.os.Build import android.os.ParcelFileDescriptor.AutoCloseInputStream import androidx.annotation.Keep import androidx.test.ext.junit.runners.AndroidJUnit4 -import com.topjohnwu.magisk.core.Config import com.topjohnwu.magisk.core.Info import com.topjohnwu.magisk.core.di.ServiceLocator import com.topjohnwu.magisk.core.model.su.SuPolicy import kotlinx.coroutines.runBlocking -import org.junit.Assert.assertEquals -import org.junit.Assert.assertNotNull import org.junit.Assert.assertTrue import org.junit.BeforeClass import org.junit.Test import org.junit.runner.RunWith -import java.util.concurrent.TimeUnit @Keep @RunWith(AndroidJUnit4::class) @@ -35,14 +29,11 @@ class MagiskAppTest : BaseTest { } @Test - fun testSuRequest() { - // Bypass the need to actually show a dialog - Config.suAutoResponse = Config.Value.SU_AUTO_ALLOW - Config.prefs.edit().commit() - - // Inject an undetermined + mute logging policy for ADB shell + fun testSu() { + // Explicitly grant shell su access val policy = SuPolicy( uid = 2000, + policy = SuPolicy.ALLOW, logging = false, notification = false, remain = 0L @@ -51,10 +42,6 @@ class MagiskAppTest : BaseTest { ServiceLocator.policyDB.update(policy) } - val filter = IntentFilter(Intent.ACTION_VIEW) - filter.addCategory(Intent.CATEGORY_DEFAULT) - val monitor = instrumentation.addMonitor(filter, null, false) - // Try to call su from ADB shell val cmd = if (Build.VERSION.SDK_INT < 24) { // API 23 runs executeShellCommand as root @@ -64,23 +51,12 @@ class MagiskAppTest : BaseTest { } val pfd = uiAutomation.executeShellCommand(cmd) - // Make sure SuRequestActivity is launched - val suRequest = monitor.waitForActivityWithTimeout(TimeUnit.SECONDS.toMillis(10)) - assertNotNull("SuRequestActivity is not launched", suRequest) - - // Check that the request went through + // Check that root access is granted AutoCloseInputStream(pfd).reader().use { assertTrue( "Cannot grant root permission from shell", it.readText().contains("uid=0") ) } - - // Check that the database is updated - runBlocking { - val policy = ServiceLocator.policyDB.fetch(2000) - ?: throw AssertionError("PolicyDB is invalid") - assertEquals("Policy for shell is incorrect", SuPolicy.ALLOW, policy.policy) - } } }