Home | History | Annotate | Download | only in impl
      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 com.android.dialer.simulator.impl;
     18 
     19 import android.support.annotation.NonNull;
     20 import android.telecom.Connection.RttModifyStatus;
     21 import android.telecom.DisconnectCause;
     22 import com.android.dialer.common.Assert;
     23 import com.android.dialer.common.LogUtil;
     24 import com.android.dialer.common.concurrent.ThreadUtil;
     25 import com.android.dialer.simulator.Simulator.Event;
     26 
     27 /** Listen to call backs from Connections not made by simulator. */
     28 final class NonSimulatorConnectionListener implements SimulatorConnection.Listener {
     29 
     30   @Override
     31   public void onEvent(@NonNull SimulatorConnection connection, @NonNull Event event) {
     32     switch (event.type) {
     33       case Event.STATE_CHANGE:
     34         LogUtil.i(
     35             "SimulatorVoiceCall.onEvent",
     36             String.format("state changed from %s to %s ", event.data1, event.data2));
     37         break;
     38       case Event.REJECT:
     39         connection.setDisconnected(new DisconnectCause(DisconnectCause.REJECTED));
     40         break;
     41       case Event.HOLD:
     42         connection.setOnHold();
     43         break;
     44       case Event.ANSWER:
     45       case Event.UNHOLD:
     46         connection.setActive();
     47         break;
     48       case Event.DISCONNECT:
     49         connection.setDisconnected(new DisconnectCause(DisconnectCause.LOCAL));
     50         break;
     51       case Event.SESSION_MODIFY_REQUEST:
     52         ThreadUtil.postDelayedOnUiThread(() -> connection.handleSessionModifyRequest(event), 2000);
     53         break;
     54       case Event.START_RTT:
     55         boolean accept = true;
     56         if (accept) {
     57           connection.sendRttInitiationSuccess();
     58         } else {
     59           connection.sendRttInitiationFailure(RttModifyStatus.SESSION_MODIFY_REQUEST_FAIL);
     60         }
     61         break;
     62       case Event.NONE:
     63       default:
     64         LogUtil.i("SimulatorVoiceCall.onEvent", "unexpected event: " + event.type);
     65         throw Assert.createIllegalStateFailException();
     66     }
     67   }
     68 }
     69