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