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.MmTelFeature;
21 import android.telephony.ims.stub.ImsRegistrationImplBase;
22 import android.util.Log;
23 
24 import java.util.List;
25 
26 public class TestMmTelFeature extends MmTelFeature {
27 
28     private final TestImsService.RemovedListener mRemovedListener;
29     private final TestImsService.ReadyListener mReadyListener;
30     private final TestImsService.CapabilitiesSetListener mCapSetListener;
31 
32     private static final String TAG = "CtsTestImsService";
33 
34     private MmTelCapabilities mCapabilities =
35             new MmTelCapabilities(MmTelCapabilities.CAPABILITY_TYPE_SMS);
36     private TestImsSmsImpl mSmsImpl;
37 
TestMmTelFeature(TestImsService.ReadyListener readyListener, TestImsService.RemovedListener removedListener, TestImsService.CapabilitiesSetListener setListener)38     TestMmTelFeature(TestImsService.ReadyListener readyListener,
39             TestImsService.RemovedListener removedListener,
40             TestImsService.CapabilitiesSetListener setListener) {
41         mReadyListener = readyListener;
42         mRemovedListener = removedListener;
43         mCapSetListener = setListener;
44         mSmsImpl = new TestImsSmsImpl();
45         // Must set the state to READY in the constructor - onFeatureReady depends on the state
46         // being ready.
47         setFeatureState(STATE_READY);
48     }
49 
getSmsImplementation()50     public TestImsSmsImpl getSmsImplementation() {
51         return mSmsImpl;
52     }
53 
54     @Override
queryCapabilityConfiguration(int capability, int radioTech)55     public boolean queryCapabilityConfiguration(int capability, int radioTech) {
56         if (ImsUtils.VDBG) {
57             Log.d(TAG, "queryCapabilityConfiguration called with capability: " + capability);
58         }
59         return mCapabilities.isCapable(capability);
60     }
61 
62     @Override
changeEnabledCapabilities(CapabilityChangeRequest request, CapabilityCallbackProxy c)63     public void changeEnabledCapabilities(CapabilityChangeRequest request,
64             CapabilityCallbackProxy c) {
65         List<CapabilityChangeRequest.CapabilityPair> pairs = request.getCapabilitiesToEnable();
66         for (CapabilityChangeRequest.CapabilityPair pair : pairs) {
67             if (pair.getRadioTech() == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
68                 mCapabilities.addCapabilities(pair.getCapability());
69             }
70         }
71         pairs = request.getCapabilitiesToDisable();
72         for (CapabilityChangeRequest.CapabilityPair pair : pairs) {
73             if (pair.getRadioTech() == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
74                 mCapabilities.removeCapabilities(pair.getCapability());
75             }
76         }
77         mCapSetListener.onSet();
78     }
79 
80     @Override
onFeatureReady()81     public void onFeatureReady() {
82         if (ImsUtils.VDBG) {
83             Log.d(TAG, "TestMmTelFeature.onFeatureReady called");
84         }
85         mReadyListener.onReady();
86     }
87 
88     @Override
onFeatureRemoved()89     public void onFeatureRemoved() {
90         if (ImsUtils.VDBG) {
91             Log.d(TAG, "TestMmTelFeature.onFeatureRemoved called");
92         }
93         mRemovedListener.onRemoved();
94     }
95 
setCapabilities(MmTelCapabilities capabilities)96     public void setCapabilities(MmTelCapabilities capabilities) {
97         mCapabilities = capabilities;
98     }
99 
getCapabilities()100     public MmTelCapabilities getCapabilities() {
101         return mCapabilities;
102     }
103 }
104