• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package android.telephony.ims;
18 
19 import android.os.Bundle;
20 import android.os.Message;
21 import android.os.RemoteException;
22 import android.telephony.ims.feature.CapabilityChangeRequest;
23 import android.telephony.ims.feature.ImsFeature;
24 import android.telephony.ims.feature.MmTelFeature;
25 import android.telephony.ims.stub.ImsCallSessionImplBase;
26 import android.telephony.ims.stub.ImsEcbmImplBase;
27 import android.telephony.ims.stub.ImsMultiEndpointImplBase;
28 import android.telephony.ims.stub.ImsRegistrationImplBase;
29 import android.telephony.ims.stub.ImsUtImplBase;
30 
31 import java.util.Set;
32 import java.util.concurrent.CountDownLatch;
33 
34 public class TestMmTelFeature extends MmTelFeature {
35 
36     public boolean queryConfigurationResult = false;
37     public int setCapabilitiesResult = ImsFeature.CAPABILITY_SUCCESS;
38     public CapabilityChangeRequest lastRequest;
39     public boolean isUtInterfaceCalled = false;
40     public CountDownLatch configuredRtpHeaderExtensions = new CountDownLatch(1);
41     Set<RtpHeaderExtensionType> receivedExtensions = null;
42 
TestMmTelFeature()43     public TestMmTelFeature() {
44         super(Runnable::run);
45     }
46 
47     private final TestImsCallSession mCallSession = new TestImsCallSession();
48     private class TestImsCallSession extends ImsCallSessionImplBase {
49 
50         @Override
sendDtmf(char c, Message result)51         public void sendDtmf(char c, Message result) {
52             // Just call result to signify complete for test.
53             if (result.replyTo != null) {
54                 try {
55                     result.replyTo.send(result);
56                 } catch (RemoteException e) {
57                     // eat error, test will fail.
58                 }
59             }
60         }
61     }
62 
incomingCall(ImsCallSessionImplBase c)63     public void incomingCall(ImsCallSessionImplBase c) {
64         notifyIncomingCall(c, new Bundle());
65     }
66 
incomingCall( ImsCallSessionImplBase c, String callId, Bundle extra)67     public ImsCallSessionListener incomingCall(
68             ImsCallSessionImplBase c, String callId, Bundle extra) {
69         return notifyIncomingCall(c, callId, extra);
70     }
71 
72     @Override
createCallProfile(int callSessionType, int callType)73     public ImsCallProfile createCallProfile(int callSessionType, int callType) {
74         return super.createCallProfile(callSessionType, callType);
75     }
76 
77     @Override
changeOfferedRtpHeaderExtensionTypes(Set<RtpHeaderExtensionType> types)78     public void changeOfferedRtpHeaderExtensionTypes(Set<RtpHeaderExtensionType> types) {
79         receivedExtensions = types;
80         configuredRtpHeaderExtensions.countDown();
81     }
82 
83     @Override
createCallSession(ImsCallProfile profile)84     public ImsCallSessionImplBase createCallSession(ImsCallProfile profile) {
85         return mCallSession;
86     }
87 
88     @Override
getUt()89     public ImsUtImplBase getUt() {
90         isUtInterfaceCalled = true;
91         return super.getUt();
92     }
93 
94     @Override
getEcbm()95     public ImsEcbmImplBase getEcbm() {
96         return super.getEcbm();
97     }
98 
99     @Override
getMultiEndpoint()100     public ImsMultiEndpointImplBase getMultiEndpoint() {
101         return super.getMultiEndpoint();
102     }
103 
104     @Override
setUiTtyMode(int mode, Message onCompleteMessage)105     public void setUiTtyMode(int mode, Message onCompleteMessage) {
106         try {
107             // just send complete message.
108             onCompleteMessage.replyTo.send(onCompleteMessage);
109         } catch (RemoteException e) {
110             // do nothing, test will fail.
111         }
112     }
113 
114     @Override
queryCapabilityConfiguration(@mTelCapabilities.MmTelCapability int capability, @ImsRegistrationImplBase.ImsRegistrationTech int radioTech)115     public boolean queryCapabilityConfiguration(@MmTelCapabilities.MmTelCapability int capability,
116             @ImsRegistrationImplBase.ImsRegistrationTech int radioTech) {
117         // Base implementation - Override to provide functionality
118         return queryConfigurationResult;
119     }
120 
121     @Override
changeEnabledCapabilities(CapabilityChangeRequest request, CapabilityCallbackProxy c)122     public void changeEnabledCapabilities(CapabilityChangeRequest request,
123             CapabilityCallbackProxy c) {
124         lastRequest = request;
125         if (setCapabilitiesResult != ImsFeature.CAPABILITY_SUCCESS) {
126             // Take the first value to enable and return it as an error.
127             CapabilityChangeRequest.CapabilityPair capPair = request.getCapabilitiesToEnable()
128                     .get(0);
129             c.onChangeCapabilityConfigurationError(capPair.getCapability(), capPair.getRadioTech(),
130                     ImsFeature.CAPABILITY_ERROR_GENERIC);
131         }
132     }
133 
sendSetFeatureState(int state)134     public void sendSetFeatureState(int state) {
135         setFeatureState(state);
136     }
137 
138     @Override
onFeatureRemoved()139     public void onFeatureRemoved() {
140     }
141 
142     @Override
onFeatureReady()143     public void onFeatureReady() {
144     }
145 }
146