From b80126fd61de3bcdaee3b38a6f1f4670838c9513 Mon Sep 17 00:00:00 2001 From: agnostic-apollo Date: Tue, 14 Jun 2022 04:08:03 +0500 Subject: [PATCH] Fixed: Catch exceptions if failed to bypass hidden API restrictions Attempting to bypass restrictions while tests are running will fail due to call to `TermuxApplication.onCreate()` -> `TermuxShellEnvironment.init()` -> `SELinuxUtils.getContext()` --- .../java/com/termux/shared/reflection/ReflectionUtils.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/termux-shared/src/main/java/com/termux/shared/reflection/ReflectionUtils.java b/termux-shared/src/main/java/com/termux/shared/reflection/ReflectionUtils.java index 10886a4164..c57f103b4e 100644 --- a/termux-shared/src/main/java/com/termux/shared/reflection/ReflectionUtils.java +++ b/termux-shared/src/main/java/com/termux/shared/reflection/ReflectionUtils.java @@ -28,7 +28,12 @@ public class ReflectionUtils { public static void bypassHiddenAPIReflectionRestrictions() { if (!HIDDEN_API_REFLECTION_RESTRICTIONS_BYPASSED && Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { Logger.logDebug(LOG_TAG, "Bypassing android hidden api reflection restrictions"); - HiddenApiBypass.addHiddenApiExemptions(""); + try { + HiddenApiBypass.addHiddenApiExemptions(""); + } catch (Throwable t) { + Logger.logStackTraceWithMessage(LOG_TAG, "Failed to bypass hidden API reflection restrictions", t); + } + HIDDEN_API_REFLECTION_RESTRICTIONS_BYPASSED = true; } }