1/* 2 * Copyright (C) 2016 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 17package com.android.incallui.incall.protocol; 18 19import android.graphics.drawable.Drawable; 20import android.support.annotation.IntDef; 21import android.support.annotation.Nullable; 22import android.telecom.DisconnectCause; 23import android.text.TextUtils; 24import com.android.dialer.assisteddialing.TransformationInfo; 25import com.android.dialer.common.Assert; 26import com.android.incallui.call.DialerCall; 27import com.android.incallui.call.DialerCall.State; 28import com.android.incallui.videotech.utils.SessionModificationState; 29import com.google.auto.value.AutoValue; 30import java.lang.annotation.Retention; 31import java.lang.annotation.RetentionPolicy; 32import java.util.Locale; 33 34/** State of the primary call. */ 35@AutoValue 36public abstract class PrimaryCallState { 37 38 /** 39 * Button state that will be invisible if not supported, visible but invalid if disabled, or 40 * visible if enabled. 41 */ 42 @Retention(RetentionPolicy.SOURCE) 43 @IntDef({ButtonState.NOT_SUPPORT, ButtonState.DISABLED, ButtonState.ENABLED}) 44 public @interface ButtonState { 45 int NOT_SUPPORT = 0; 46 int DISABLED = 1; 47 int ENABLED = 2; 48 } 49 50 public abstract int state(); 51 52 public abstract boolean isVideoCall(); 53 54 @SessionModificationState 55 public abstract int sessionModificationState(); 56 57 public abstract DisconnectCause disconnectCause(); 58 59 @Nullable 60 public abstract String connectionLabel(); 61 62 @Nullable 63 public abstract Drawable connectionIcon(); 64 65 @Nullable 66 public abstract String gatewayNumber(); 67 68 @Nullable 69 public abstract String callSubject(); 70 71 @Nullable 72 public abstract String callbackNumber(); 73 74 public abstract boolean isWifi(); 75 76 public abstract boolean isConference(); 77 78 public abstract boolean isWorkCall(); 79 80 public abstract boolean isHdAttempting(); 81 82 public abstract boolean isHdAudioCall(); 83 84 public abstract boolean isForwardedNumber(); 85 86 public abstract boolean shouldShowContactPhoto(); 87 88 public abstract long connectTimeMillis(); 89 90 public abstract boolean isVoiceMailNumber(); 91 92 public abstract boolean isRemotelyHeld(); 93 94 public abstract boolean isBusinessNumber(); 95 96 public abstract boolean supportsCallOnHold(); 97 98 public abstract @ButtonState int swapToSecondaryButtonState(); 99 100 public abstract boolean isAssistedDialed(); 101 102 @Nullable 103 public abstract String customLabel(); 104 105 @Nullable 106 public abstract TransformationInfo assistedDialingExtras(); 107 108 public static Builder builder() { 109 return new AutoValue_PrimaryCallState.Builder() 110 .setState(DialerCall.State.IDLE) 111 .setIsVideoCall(false) 112 .setSessionModificationState(SessionModificationState.NO_REQUEST) 113 .setDisconnectCause(new DisconnectCause(DisconnectCause.UNKNOWN)) 114 .setIsWifi(false) 115 .setIsConference(false) 116 .setIsWorkCall(false) 117 .setIsHdAttempting(false) 118 .setIsHdAudioCall(false) 119 .setIsForwardedNumber(false) 120 .setShouldShowContactPhoto(false) 121 .setConnectTimeMillis(0) 122 .setIsVoiceMailNumber(false) 123 .setIsRemotelyHeld(false) 124 .setIsBusinessNumber(false) 125 .setSupportsCallOnHold(true) 126 .setSwapToSecondaryButtonState(ButtonState.NOT_SUPPORT) 127 .setIsAssistedDialed(false); 128 } 129 130 /** Builder class for primary call state info. */ 131 @AutoValue.Builder 132 public abstract static class Builder { 133 public abstract Builder setState(int state); 134 135 public abstract Builder setIsVideoCall(boolean isVideoCall); 136 137 public abstract Builder setSessionModificationState( 138 @SessionModificationState int sessionModificationState); 139 140 public abstract Builder setDisconnectCause(DisconnectCause disconnectCause); 141 142 public abstract Builder setConnectionLabel(String connectionLabel); 143 144 public abstract Builder setConnectionIcon(Drawable connectionIcon); 145 146 public abstract Builder setGatewayNumber(String gatewayNumber); 147 148 public abstract Builder setCallSubject(String callSubject); 149 150 public abstract Builder setCallbackNumber(String callbackNumber); 151 152 public abstract Builder setIsWifi(boolean isWifi); 153 154 public abstract Builder setIsConference(boolean isConference); 155 156 public abstract Builder setIsWorkCall(boolean isWorkCall); 157 158 public abstract Builder setIsHdAttempting(boolean isHdAttempting); 159 160 public abstract Builder setIsHdAudioCall(boolean isHdAudioCall); 161 162 public abstract Builder setIsForwardedNumber(boolean isForwardedNumber); 163 164 public abstract Builder setShouldShowContactPhoto(boolean shouldShowContactPhoto); 165 166 public abstract Builder setConnectTimeMillis(long connectTimeMillis); 167 168 public abstract Builder setIsVoiceMailNumber(boolean isVoiceMailNumber); 169 170 public abstract Builder setIsRemotelyHeld(boolean isRemotelyHeld); 171 172 public abstract Builder setIsBusinessNumber(boolean isBusinessNumber); 173 174 public abstract Builder setSupportsCallOnHold(boolean supportsCallOnHold); 175 176 public abstract Builder setSwapToSecondaryButtonState( 177 @ButtonState int swapToSecondaryButtonState); 178 179 public abstract Builder setIsAssistedDialed(boolean isAssistedDialed); 180 181 public abstract Builder setCustomLabel(String customLabel); 182 183 public abstract Builder setAssistedDialingExtras(TransformationInfo assistedDialingExtras); 184 185 abstract PrimaryCallState autoBuild(); 186 187 public PrimaryCallState build() { 188 PrimaryCallState primaryCallState = autoBuild(); 189 if (!TextUtils.isEmpty(primaryCallState.customLabel())) { 190 Assert.checkArgument(primaryCallState.state() == State.CALL_PENDING); 191 } 192 return primaryCallState; 193 } 194 } 195 196 public static PrimaryCallState empty() { 197 return PrimaryCallState.builder().build(); 198 } 199 200 @Override 201 public String toString() { 202 return String.format( 203 Locale.US, "PrimaryCallState, state: %d, connectionLabel: %s", state(), connectionLabel()); 204 } 205} 206