1/*
2 * Copyright (C) 2018 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
17package com.android.internal.telephony.ims;
18
19import static android.telephony.ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN;
20import static android.telephony.ServiceState.RIL_RADIO_TECHNOLOGY_LTE;
21
22import android.net.Uri;
23import android.os.RemoteException;
24import android.telephony.ims.ImsReasonInfo;
25import android.telephony.ims.stub.ImsRegistrationImplBase;
26import android.util.ArrayMap;
27
28import com.android.ims.internal.IImsRegistrationListener;
29
30import java.util.Map;
31
32public class ImsRegistrationCompatAdapter extends ImsRegistrationImplBase {
33
34    // Maps "RAT" based radio technologies to ImsRegistrationImplBase definitions.
35    private static final Map<Integer, Integer> RADIO_TECH_MAPPER = new ArrayMap<>(2);
36    static {
37        RADIO_TECH_MAPPER.put(RIL_RADIO_TECHNOLOGY_LTE, REGISTRATION_TECH_LTE);
38        RADIO_TECH_MAPPER.put(RIL_RADIO_TECHNOLOGY_IWLAN, REGISTRATION_TECH_IWLAN);
39    }
40
41    // Trampolines "old" listener events to the new interface.
42    private final IImsRegistrationListener mListener = new IImsRegistrationListener.Stub() {
43        @Override
44        public void registrationConnected() throws RemoteException {
45            onRegistered(REGISTRATION_TECH_NONE);
46        }
47
48        @Override
49        public void registrationProgressing() throws RemoteException {
50            onRegistering(REGISTRATION_TECH_NONE);
51        }
52
53        @Override
54        public void registrationConnectedWithRadioTech(int imsRadioTech) throws RemoteException {
55            onRegistered(RADIO_TECH_MAPPER.getOrDefault(imsRadioTech, REGISTRATION_TECH_NONE));
56        }
57
58        @Override
59        public void registrationProgressingWithRadioTech(int imsRadioTech) throws RemoteException {
60            onRegistering(RADIO_TECH_MAPPER.getOrDefault(imsRadioTech, REGISTRATION_TECH_NONE));
61        }
62
63        @Override
64        public void registrationDisconnected(ImsReasonInfo imsReasonInfo) throws RemoteException {
65            onDeregistered(imsReasonInfo);
66        }
67
68        @Override
69        public void registrationResumed() throws RemoteException {
70            // Don't care
71        }
72
73        @Override
74        public void registrationSuspended() throws RemoteException {
75            // Don't care
76        }
77
78        @Override
79        public void registrationServiceCapabilityChanged(int serviceClass, int event)
80                throws RemoteException {
81            // Don't care
82        }
83
84        @Override
85        public void registrationFeatureCapabilityChanged(int serviceClass, int[] enabledFeatures,
86                int[] disabledFeatures) throws RemoteException {
87            // Implemented in the MMTel Adapter
88        }
89
90        @Override
91        public void voiceMessageCountUpdate(int count) throws RemoteException {
92            // Implemented in the MMTel Adapter
93        }
94
95        @Override
96        public void registrationAssociatedUriChanged(Uri[] uris) throws RemoteException {
97            onSubscriberAssociatedUriChanged(uris);
98        }
99
100        @Override
101        public void registrationChangeFailed(int targetAccessTech, ImsReasonInfo imsReasonInfo)
102                throws RemoteException {
103            onTechnologyChangeFailed(RADIO_TECH_MAPPER.getOrDefault(targetAccessTech,
104                    REGISTRATION_TECH_NONE), imsReasonInfo);
105        }
106    };
107
108    /**
109     * Need access to the listener in order to register for events in MMTelFeature adapter
110     */
111    public IImsRegistrationListener getRegistrationListener() {
112        return mListener;
113    }
114}
115