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.cts;
18 
19 import android.telephony.ims.feature.CapabilityChangeRequest;
20 import android.telephony.ims.feature.RcsFeature;
21 import android.telephony.ims.stub.CapabilityExchangeEventListener;
22 import android.telephony.ims.stub.ImsRegistrationImplBase;
23 import android.telephony.ims.stub.RcsCapabilityExchangeImplBase;
24 import android.util.Log;
25 
26 import java.util.List;
27 import java.util.concurrent.Executor;
28 
29 public class TestRcsFeature extends RcsFeature {
30 
31     private static final String TAG = "CtsTestImsService";
32 
33     private final TestImsService.ReadyListener mReadyListener;
34     private final TestImsService.RemovedListener mRemovedListener;
35     private final TestImsService.RcsCapabilityExchangeEventListener mCapExchangeEventListener;
36 
37     private final RcsImsCapabilities mRcsCapabilitiesLte;
38     private final RcsImsCapabilities mRcsCapabilitiesIWan;
39     private final TestImsService.CapabilitiesSetListener mRcsCapabilityChangedListener;
40 
41     private TestRcsCapabilityExchangeImpl mCapExchangeImpl;
42     private CapabilityExchangeEventListener mCapEventListener;
43     private TestImsService.DeviceCapPublishListener mDeviceCapPublishListener;
44 
TestRcsFeature(TestImsService.ReadyListener readyListener, TestImsService.RemovedListener removedListener, TestImsService.CapabilitiesSetListener setListener, TestImsService.RcsCapabilityExchangeEventListener capExchangeEventListener)45     TestRcsFeature(TestImsService.ReadyListener readyListener,
46             TestImsService.RemovedListener removedListener,
47             TestImsService.CapabilitiesSetListener setListener,
48             TestImsService.RcsCapabilityExchangeEventListener capExchangeEventListener) {
49         super();
50         Log.d(TAG, "TestRcsFeature with default constructor");
51         mReadyListener = readyListener;
52         mRemovedListener = removedListener;
53         mCapExchangeEventListener = capExchangeEventListener;
54 
55         mRcsCapabilityChangedListener = setListener;
56         mRcsCapabilitiesLte = new RcsImsCapabilities(RcsImsCapabilities.CAPABILITY_TYPE_NONE);
57         mRcsCapabilitiesIWan = new RcsImsCapabilities(RcsImsCapabilities.CAPABILITY_TYPE_NONE);
58 
59         setFeatureState(STATE_READY);
60     }
61 
TestRcsFeature(TestImsService.ReadyListener readyListener, TestImsService.RemovedListener removedListener, TestImsService.CapabilitiesSetListener setListener, TestImsService.RcsCapabilityExchangeEventListener capExchangeEventListener, Executor executor)62     TestRcsFeature(TestImsService.ReadyListener readyListener,
63             TestImsService.RemovedListener removedListener,
64             TestImsService.CapabilitiesSetListener setListener,
65             TestImsService.RcsCapabilityExchangeEventListener capExchangeEventListener,
66             Executor executor) {
67         super(executor);
68         Log.d(TAG, "TestRcsFeature with Executor constructor");
69         mReadyListener = readyListener;
70         mRemovedListener = removedListener;
71         mCapExchangeEventListener = capExchangeEventListener;
72 
73         mRcsCapabilityChangedListener = setListener;
74         mRcsCapabilitiesLte = new RcsImsCapabilities(RcsImsCapabilities.CAPABILITY_TYPE_NONE);
75         mRcsCapabilitiesIWan = new RcsImsCapabilities(RcsImsCapabilities.CAPABILITY_TYPE_NONE);
76 
77         setFeatureState(STATE_READY);
78     }
79 
setDeviceCapPublishListener(TestImsService.DeviceCapPublishListener listener)80     public void setDeviceCapPublishListener(TestImsService.DeviceCapPublishListener listener) {
81         mDeviceCapPublishListener = listener;
82     }
83 
84     @Override
onFeatureReady()85     public void onFeatureReady() {
86         if (ImsUtils.VDBG) {
87             Log.d(TAG, "TestRcsFeature.onFeatureReady called");
88         }
89         mReadyListener.onReady();
90     }
91 
92     @Override
onFeatureRemoved()93     public void onFeatureRemoved() {
94         if (ImsUtils.VDBG) {
95             Log.d(TAG, "TestRcsFeature.onFeatureRemoved called");
96         }
97         mRemovedListener.onRemoved();
98     }
99 
createCapabilityExchangeImpl(Executor executor, CapabilityExchangeEventListener listener)100     public RcsCapabilityExchangeImplBase createCapabilityExchangeImpl(Executor executor,
101             CapabilityExchangeEventListener listener) {
102         return createCapabilityExchangeImpl(listener);
103     }
104 
105     @Override
createCapabilityExchangeImpl( CapabilityExchangeEventListener listener)106     public RcsCapabilityExchangeImplBase createCapabilityExchangeImpl(
107             CapabilityExchangeEventListener listener) {
108         if (ImsUtils.VDBG) {
109             Log.d(TAG, "TestRcsFeature.createCapabilityExchangeImpl called");
110         }
111         mCapEventListener = listener;
112         mCapExchangeImpl = new TestRcsCapabilityExchangeImpl(mDeviceCapPublishListener);
113         mCapExchangeEventListener.onSet();
114         return mCapExchangeImpl;
115     }
116 
117     @Override
destroyCapabilityExchangeImpl(RcsCapabilityExchangeImplBase capExchangeImpl)118     public void destroyCapabilityExchangeImpl(RcsCapabilityExchangeImplBase capExchangeImpl) {
119         if (ImsUtils.VDBG) {
120             Log.d(TAG, "TestRcsFeature.destroyCapabilityExchangeImpl called");
121         }
122         mCapEventListener = null;
123         mCapExchangeEventListener.onSet();
124     }
125 
getEventListener()126     public CapabilityExchangeEventListener getEventListener() {
127         return mCapEventListener;
128     }
129 
getRcsCapabilityExchangeImpl()130     public TestRcsCapabilityExchangeImpl getRcsCapabilityExchangeImpl() {
131         return mCapExchangeImpl;
132     }
133 
134     @Override
changeEnabledCapabilities(CapabilityChangeRequest request, CapabilityCallbackProxy c)135     public void changeEnabledCapabilities(CapabilityChangeRequest request,
136             CapabilityCallbackProxy c) {
137 
138         // Enabled RCS capabilities
139         List<CapabilityChangeRequest.CapabilityPair> pairs = request.getCapabilitiesToEnable();
140         for (CapabilityChangeRequest.CapabilityPair pair : pairs) {
141             if (pair.getRadioTech() == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
142                 mRcsCapabilitiesLte.addCapabilities(pair.getCapability());
143             } else if (pair.getRadioTech() == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
144                 mRcsCapabilitiesIWan.addCapabilities(pair.getCapability());
145             }
146         }
147 
148         // Disabled RCS capabilities
149         pairs = request.getCapabilitiesToDisable();
150         for (CapabilityChangeRequest.CapabilityPair pair : pairs) {
151             if (pair.getRadioTech() == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
152                 mRcsCapabilitiesLte.removeCapabilities(pair.getCapability());
153             } else if (pair.getRadioTech() == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
154                 mRcsCapabilitiesIWan.removeCapabilities(pair.getCapability());
155             }
156         }
157         mRcsCapabilityChangedListener.onSet();
158     }
159 
160     @Override
queryCapabilityConfiguration(int capability, int radioTech)161     public boolean queryCapabilityConfiguration(int capability, int radioTech) {
162         if (ImsUtils.VDBG) {
163             Log.d(TAG, "TestRcsFeature.queryCapabilityConfiguration capability: " + capability);
164         }
165         if (radioTech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
166             return mRcsCapabilitiesLte.isCapable(capability);
167         } else if (radioTech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
168             return mRcsCapabilitiesIWan.isCapable(capability);
169         }
170         return false;
171     }
172 }
173