1 /*
2  * Copyright (c) 2020 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.aidl;
18 
19 import android.annotation.NonNull;
20 import android.os.RemoteException;
21 import android.telephony.ims.ImsException;
22 import android.telephony.ims.SipDetails;
23 import android.telephony.ims.stub.RcsCapabilityExchangeImplBase.PublishResponseCallback;
24 
25 /**
26  * Implementation of the callback PublishResponseCallback by wrapping the internal AIDL from
27  * telephony.
28  * @hide
29  */
30 public class RcsPublishResponseAidlWrapper implements PublishResponseCallback {
31 
32     private final IPublishResponseCallback mResponseBinder;
33 
RcsPublishResponseAidlWrapper(IPublishResponseCallback responseBinder)34     public RcsPublishResponseAidlWrapper(IPublishResponseCallback responseBinder) {
35         mResponseBinder = responseBinder;
36     }
37 
38     @Override
onCommandError(int code)39     public void onCommandError(int code) throws ImsException {
40         try {
41             mResponseBinder.onCommandError(code);
42         } catch (RemoteException e) {
43             throw new ImsException(e.getMessage(), ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
44         }
45     }
46 
47     @Override
48     @Deprecated
onNetworkResponse(int code, String reasonPhrase)49     public void onNetworkResponse(int code, String reasonPhrase) throws ImsException {
50         SipDetails details = new SipDetails.Builder(SipDetails.METHOD_PUBLISH)
51                 .setSipResponseCode(code, reasonPhrase)
52                 .build();
53         try {
54             mResponseBinder.onNetworkResponse(details);
55         } catch (RemoteException e) {
56             throw new ImsException(e.getMessage(), ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
57         }
58     }
59 
60     @Override
61     @Deprecated
onNetworkResponse(int code, String reasonPhrase, int reasonHeaderCause, String reasonHeaderText)62     public void onNetworkResponse(int code, String reasonPhrase, int reasonHeaderCause,
63             String reasonHeaderText) throws ImsException {
64         SipDetails details = new SipDetails.Builder(SipDetails.METHOD_PUBLISH)
65                 .setSipResponseCode(code, reasonPhrase)
66                 .setSipResponseReasonHeader(reasonHeaderCause, reasonHeaderText)
67                 .build();
68         try {
69             mResponseBinder.onNetworkResponse(details);
70         } catch (RemoteException e) {
71             throw new ImsException(e.getMessage(), ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
72         }
73     }
74 
75     @Override
onNetworkResponse(@onNull SipDetails details)76     public void onNetworkResponse(@NonNull SipDetails details)
77             throws ImsException {
78         try {
79             mResponseBinder.onNetworkResponse(details);
80         } catch (RemoteException e) {
81             throw new ImsException(e.getMessage(), ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
82         }
83     }
84 }
85