1 /* 2 * Copyright (C) 2017 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.incallui.videotech.lightbringer; 18 19 import android.content.Context; 20 import android.support.annotation.NonNull; 21 import android.telecom.Call; 22 import com.android.dialer.common.Assert; 23 import com.android.dialer.lightbringer.Lightbringer; 24 import com.android.dialer.lightbringer.LightbringerListener; 25 import com.android.incallui.video.protocol.VideoCallScreen; 26 import com.android.incallui.video.protocol.VideoCallScreenDelegate; 27 import com.android.incallui.videotech.VideoTech; 28 import com.android.incallui.videotech.utils.SessionModificationState; 29 30 public class LightbringerTech implements VideoTech, LightbringerListener { 31 private final Lightbringer lightbringer; 32 private final VideoTechListener listener; 33 private final String callingNumber; 34 private int callState = Call.STATE_NEW; 35 LightbringerTech( @onNull Lightbringer lightbringer, @NonNull VideoTechListener listener, @NonNull String callingNumber)36 public LightbringerTech( 37 @NonNull Lightbringer lightbringer, 38 @NonNull VideoTechListener listener, 39 @NonNull String callingNumber) { 40 this.lightbringer = Assert.isNotNull(lightbringer); 41 this.listener = Assert.isNotNull(listener); 42 this.callingNumber = Assert.isNotNull(callingNumber); 43 44 lightbringer.registerListener(this); 45 } 46 47 @Override isAvailable(Context context)48 public boolean isAvailable(Context context) { 49 return callState == Call.STATE_ACTIVE && lightbringer.isReachable(context, callingNumber); 50 } 51 52 @Override isTransmittingOrReceiving()53 public boolean isTransmittingOrReceiving() { 54 return false; 55 } 56 57 @Override isSelfManagedCamera()58 public boolean isSelfManagedCamera() { 59 return false; 60 } 61 62 @Override shouldUseSurfaceView()63 public boolean shouldUseSurfaceView() { 64 return false; 65 } 66 67 @Override createVideoCallScreenDelegate( Context context, VideoCallScreen videoCallScreen)68 public VideoCallScreenDelegate createVideoCallScreenDelegate( 69 Context context, VideoCallScreen videoCallScreen) { 70 throw Assert.createUnsupportedOperationFailException(); 71 } 72 73 @Override onCallStateChanged(Context context, int newState)74 public void onCallStateChanged(Context context, int newState) { 75 if (newState == Call.STATE_DISCONNECTING) { 76 lightbringer.unregisterListener(this); 77 } 78 79 callState = newState; 80 } 81 82 @Override getSessionModificationState()83 public int getSessionModificationState() { 84 return SessionModificationState.NO_REQUEST; 85 } 86 87 @Override upgradeToVideo()88 public void upgradeToVideo() { 89 // TODO: upgrade to a video call 90 } 91 92 @Override acceptVideoRequest()93 public void acceptVideoRequest() { 94 throw Assert.createUnsupportedOperationFailException(); 95 } 96 97 @Override acceptVideoRequestAsAudio()98 public void acceptVideoRequestAsAudio() { 99 throw Assert.createUnsupportedOperationFailException(); 100 } 101 102 @Override declineVideoRequest()103 public void declineVideoRequest() { 104 throw Assert.createUnsupportedOperationFailException(); 105 } 106 107 @Override isTransmitting()108 public boolean isTransmitting() { 109 return false; 110 } 111 112 @Override stopTransmission()113 public void stopTransmission() { 114 throw Assert.createUnsupportedOperationFailException(); 115 } 116 117 @Override resumeTransmission()118 public void resumeTransmission() { 119 throw Assert.createUnsupportedOperationFailException(); 120 } 121 122 @Override pause()123 public void pause() { 124 throw Assert.createUnsupportedOperationFailException(); 125 } 126 127 @Override unpause()128 public void unpause() { 129 throw Assert.createUnsupportedOperationFailException(); 130 } 131 132 @Override setCamera(String cameraId)133 public void setCamera(String cameraId) { 134 throw Assert.createUnsupportedOperationFailException(); 135 } 136 137 @Override setDeviceOrientation(int rotation)138 public void setDeviceOrientation(int rotation) { 139 throw Assert.createUnsupportedOperationFailException(); 140 } 141 142 @Override onLightbringerStateChanged()143 public void onLightbringerStateChanged() { 144 listener.onVideoTechStateChanged(); 145 } 146 } 147