• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.telephony.ims;
18 
19 import android.content.Context;
20 import android.os.RemoteException;
21 import android.os.ServiceManager;
22 import android.telephony.ims.aidl.IRcs;
23 
24 /**
25  * A wrapper class around RPC calls that {@link RcsMessageStore} APIs to minimize boilerplate code.
26  *
27  * @hide - not meant for public use
28  */
29 class RcsControllerCall {
30     private final Context mContext;
31 
RcsControllerCall(Context context)32     RcsControllerCall(Context context) {
33         mContext = context;
34     }
35 
call(RcsServiceCall<R> serviceCall)36     <R> R call(RcsServiceCall<R> serviceCall) throws RcsMessageStoreException {
37         IRcs iRcs = IRcs.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_RCS_SERVICE));
38         if (iRcs == null) {
39             throw new RcsMessageStoreException("Could not connect to RCS storage service");
40         }
41 
42         try {
43             return serviceCall.methodOnIRcs(iRcs, mContext.getOpPackageName());
44         } catch (RemoteException exception) {
45             throw new RcsMessageStoreException(exception.getMessage());
46         }
47     }
48 
callWithNoReturn(RcsServiceCallWithNoReturn serviceCall)49     void callWithNoReturn(RcsServiceCallWithNoReturn serviceCall)
50             throws RcsMessageStoreException {
51         call((iRcs, callingPackage) -> {
52             serviceCall.methodOnIRcs(iRcs, callingPackage);
53             return null;
54         });
55     }
56 
57     interface RcsServiceCall<R> {
methodOnIRcs(IRcs iRcs, String callingPackage)58         R methodOnIRcs(IRcs iRcs, String callingPackage) throws RemoteException;
59     }
60 
61     interface RcsServiceCallWithNoReturn {
methodOnIRcs(IRcs iRcs, String callingPackage)62         void methodOnIRcs(IRcs iRcs, String callingPackage) throws RemoteException;
63     }
64 }
65