@@ -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
0 commit comments