From 366f305dfb314160fa27c6fd02bee5fdf45f6e48 Mon Sep 17 00:00:00 2001 From: RikkaW Date: Wed, 27 Mar 2019 22:44:41 +0800 Subject: [PATCH] catch exceptions from registerProcessObserver and registerUidObserver --- build.gradle | 2 +- .../java/moe/shizuku/server/BinderSender.java | 20 +++++++++++++------ .../moe/shizuku/server/ShizukuService.java | 6 +----- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/build.gradle b/build.gradle index b236fdc50..5399c5f6e 100644 --- a/build.gradle +++ b/build.gradle @@ -33,7 +33,7 @@ task clean(type: Delete) { def gitCommitId = 'git rev-parse --short HEAD'.execute([], project.rootDir).text.trim() def gitCommitCount = Integer.parseInt('git rev-list --count HEAD'.execute([], project.rootDir).text.trim()) -def baseVersionName = '3.2.0' +def baseVersionName = '3.2.1' ext { androidXLibraryVersion = '1.0.0' diff --git a/server/src/main/java/moe/shizuku/server/BinderSender.java b/server/src/main/java/moe/shizuku/server/BinderSender.java index 65699ae95..bdc66c81e 100644 --- a/server/src/main/java/moe/shizuku/server/BinderSender.java +++ b/server/src/main/java/moe/shizuku/server/BinderSender.java @@ -110,16 +110,24 @@ private static void onActive(int uid, int pid) throws RemoteException { } } - public static void register(ShizukuService shizukuService) throws RemoteException { + public static void register(ShizukuService shizukuService) { sShizukuService = shizukuService; - Api.registerProcessObserver(new ProcessObserver()); + try { + Api.registerProcessObserver(new ProcessObserver()); + } catch (Throwable tr) { + LOGGER.e(tr, "registerProcessObserver"); + } if (Build.VERSION.SDK_INT >= 26) { - Api.registerUidObserver(new UidObserver(), - ActivityManager.UID_OBSERVER_ACTIVE, - ActivityManager.PROCESS_STATE_UNKNOWN, - null); + try { + Api.registerUidObserver(new UidObserver(), + ActivityManager.UID_OBSERVER_ACTIVE, + ActivityManager.PROCESS_STATE_UNKNOWN, + null); + } catch (Throwable tr) { + LOGGER.e(tr, "registerUidObserver"); + } } } } diff --git a/server/src/main/java/moe/shizuku/server/ShizukuService.java b/server/src/main/java/moe/shizuku/server/ShizukuService.java index 51f2c596b..f64b93ef2 100644 --- a/server/src/main/java/moe/shizuku/server/ShizukuService.java +++ b/server/src/main/java/moe/shizuku/server/ShizukuService.java @@ -48,11 +48,7 @@ public class ShizukuService extends IShizukuService.Stub { mToken = token.toString(); } - try { - BinderSender.register(this); - } catch (RemoteException e) { - LOGGER.e(e, "registerProcessObserver"); - } + BinderSender.register(this); } static Map getPidToken() {