Skip to content

Commit 597f31d

Browse files
committed
[Refactor] ProxyBinder throws ServiceNotFoundException instead of RuntimeException
Signed-off-by: Muntashir Al-Islam <muntashirakon@riseup.net>
1 parent e2a376d commit 597f31d

2 files changed

Lines changed: 25 additions & 5 deletions

File tree

app/src/main/java/io/github/muntashirakon/AppManager/ipc/ProxyBinder.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class ProxyBinder implements IBinder {
4141
= Collections.synchronizedMap(new ArrayMap<>());
4242

4343
@NonNull
44-
public static IBinder getService(String serviceName) {
44+
public static IBinder getService(String serviceName) throws ServiceNotFoundException {
4545
IBinder binder = sServiceCache.get(serviceName);
4646
if (binder == null) {
4747
binder = getServiceInternal(serviceName);
@@ -59,29 +59,32 @@ public static IBinder getService(String serviceName) {
5959
* @return binder to that service
6060
*/
6161
@NotNull
62-
private static IBinder getServiceInternal(String serviceName) {
62+
private static IBinder getServiceInternal(String serviceName) throws ServiceNotFoundException {
6363
IBinder binder = ServiceManager.getService(serviceName);
6464
if (LocalServices.alive() && binder == null) {
6565
try {
6666
binder = LocalServices.getAmService().getService(serviceName);
6767
} catch (RemoteException e) {
6868
Log.e(TAG, e);
69-
throw new RuntimeException("Service couldn't be loaded: " + serviceName, e);
69+
throw new ServiceNotFoundException("Service couldn't be loaded: " + serviceName, e);
7070
}
7171
}
7272
if (binder == null) {
73-
throw new RuntimeException("Service couldn't be found");
73+
throw new ServiceNotFoundException("Service couldn't be found: " + serviceName);
7474
}
7575
return binder;
7676
}
7777

7878
@NonNull
79-
public static IBinder getUnprivilegedService(String serviceName) {
79+
public static IBinder getUnprivilegedService(String serviceName) throws ServiceNotFoundException {
8080
IBinder binder = sServiceCache.get(serviceName);
8181
if (binder == null) {
8282
binder = ServiceManager.getService(serviceName);
8383
sServiceCache.put(serviceName, binder);
8484
}
85+
if (binder == null) {
86+
throw new ServiceNotFoundException("Service couldn't be found: " + serviceName);
87+
}
8588
return binder;
8689
}
8790

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// SPDX-License-Identifier: GPL-3.0-or-later
2+
3+
package io.github.muntashirakon.AppManager.ipc;
4+
5+
public class ServiceNotFoundException extends RuntimeException {
6+
public ServiceNotFoundException() {
7+
super();
8+
}
9+
10+
public ServiceNotFoundException(String name) {
11+
super(name);
12+
}
13+
14+
public ServiceNotFoundException(String name, Exception cause) {
15+
super(name, cause);
16+
}
17+
}

0 commit comments

Comments
 (0)