diff options
author | Android Dialer <noreply@google.com> | 2018-02-26 13:29:09 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-02-26 14:24:23 -0800 |
commit | 31fe99856b34854bd36a17d02b774095dcfe51a6 (patch) | |
tree | 54e027c351b2b7e4c9f226ad178c16d4dd183cdf /java/com/android/incallui/incall/protocol/PrimaryCallState.java | |
parent | b2c8e1c635c5c1803ef712e29f46a0ebf172cf27 (diff) |
Updating PrimaryCallState value class to use AutoValue with builder pattern.
Bug: 34502119
Test: BottomRowTest,CallCardPresenterTest,PrimaryCallStateTest,TopRowTest
PiperOrigin-RevId: 187071451
Change-Id: Ib1b4baee397f61eade84bf1a887596dddc37230a
Diffstat (limited to 'java/com/android/incallui/incall/protocol/PrimaryCallState.java')
-rw-r--r-- | java/com/android/incallui/incall/protocol/PrimaryCallState.java | 261 |
1 files changed, 148 insertions, 113 deletions
diff --git a/java/com/android/incallui/incall/protocol/PrimaryCallState.java b/java/com/android/incallui/incall/protocol/PrimaryCallState.java index 7a3abedcd..1d536e9b9 100644 --- a/java/com/android/incallui/incall/protocol/PrimaryCallState.java +++ b/java/com/android/incallui/incall/protocol/PrimaryCallState.java @@ -26,12 +26,14 @@ import com.android.dialer.common.Assert; import com.android.incallui.call.DialerCall; import com.android.incallui.call.DialerCall.State; import com.android.incallui.videotech.utils.SessionModificationState; +import com.google.auto.value.AutoValue; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.Locale; /** State of the primary call. */ -public class PrimaryCallState { +@AutoValue +public abstract class PrimaryCallState { /** * Button state that will be invisible if not supported, visible but invalid if disabled, or @@ -45,126 +47,159 @@ public class PrimaryCallState { int ENABLED = 2; } - public final int state; - public final boolean isVideoCall; - @SessionModificationState public final int sessionModificationState; - public final DisconnectCause disconnectCause; - public final String connectionLabel; - public final Drawable connectionIcon; - public final String gatewayNumber; - public final String callSubject; - public final String callbackNumber; - public final boolean isWifi; - public final boolean isConference; - public final boolean isWorkCall; - public final boolean isHdAttempting; - public final boolean isHdAudioCall; - public final boolean isForwardedNumber; - public final boolean shouldShowContactPhoto; - public final long connectTimeMillis; - public final boolean isVoiceMailNumber; - public final boolean isRemotelyHeld; - public final boolean isBusinessNumber; - public final boolean supportsCallOnHold; - public final @ButtonState int swapToSecondaryButtonState; - public final boolean isAssistedDialed; - @Nullable public final String customLabel; - @Nullable public final TransformationInfo assistedDialingExtras; - - // TODO: Convert to autovalue. a bug - public static PrimaryCallState createEmptyPrimaryCallState() { - return createEmptyPrimaryCallStateWithState(DialerCall.State.IDLE, null); - } + public abstract int state(); + + public abstract boolean isVideoCall(); + + @SessionModificationState + public abstract int sessionModificationState(); + + public abstract DisconnectCause disconnectCause(); + + @Nullable + public abstract String connectionLabel(); + + @Nullable + public abstract Drawable connectionIcon(); + + @Nullable + public abstract String gatewayNumber(); + + @Nullable + public abstract String callSubject(); + + @Nullable + public abstract String callbackNumber(); + + public abstract boolean isWifi(); + + public abstract boolean isConference(); + + public abstract boolean isWorkCall(); + + public abstract boolean isHdAttempting(); + + public abstract boolean isHdAudioCall(); - public static PrimaryCallState createEmptyPrimaryCallStateWithState( - int state, String customLabel) { - return new PrimaryCallState( - state, - false, /* isVideoCall */ - SessionModificationState.NO_REQUEST, - new DisconnectCause(DisconnectCause.UNKNOWN), - null, /* connectionLabel */ - null, /* connectionIcon */ - null, /* gatewayNumber */ - null, /* callSubject */ - null, /* callbackNumber */ - false /* isWifi */, - false /* isConference */, - false /* isWorkCall */, - false /* isHdAttempting */, - false /* isHdAudioCall */, - false /* isForwardedNumber */, - false /* shouldShowContactPhoto */, - 0, - false /* isVoiceMailNumber */, - false /* isRemotelyHeld */, - false /* isBusinessNumber */, - true /* supportsCallOnHold */, - ButtonState.NOT_SUPPORT /* swapToSecondaryButtonState */, - false /* isAssistedDialed */, - customLabel, - null /* assistedDialingExtras */); + public abstract boolean isForwardedNumber(); + + public abstract boolean shouldShowContactPhoto(); + + public abstract long connectTimeMillis(); + + public abstract boolean isVoiceMailNumber(); + + public abstract boolean isRemotelyHeld(); + + public abstract boolean isBusinessNumber(); + + public abstract boolean supportsCallOnHold(); + + public abstract @ButtonState int swapToSecondaryButtonState(); + + public abstract boolean isAssistedDialed(); + + @Nullable + public abstract String customLabel(); + + @Nullable + public abstract TransformationInfo assistedDialingExtras(); + + public static Builder builder() { + return new AutoValue_PrimaryCallState.Builder() + .setState(DialerCall.State.IDLE) + .setIsVideoCall(false) + .setSessionModificationState(SessionModificationState.NO_REQUEST) + .setDisconnectCause(new DisconnectCause(DisconnectCause.UNKNOWN)) + .setIsWifi(false) + .setIsConference(false) + .setIsWorkCall(false) + .setIsHdAttempting(false) + .setIsHdAudioCall(false) + .setIsForwardedNumber(false) + .setShouldShowContactPhoto(false) + .setConnectTimeMillis(0) + .setIsVoiceMailNumber(false) + .setIsRemotelyHeld(false) + .setIsBusinessNumber(false) + .setSupportsCallOnHold(true) + .setSwapToSecondaryButtonState(ButtonState.NOT_SUPPORT) + .setIsAssistedDialed(false); } - public PrimaryCallState( - int state, - boolean isVideoCall, - @SessionModificationState int sessionModificationState, - DisconnectCause disconnectCause, - String connectionLabel, - Drawable connectionIcon, - String gatewayNumber, - String callSubject, - String callbackNumber, - boolean isWifi, - boolean isConference, - boolean isWorkCall, - boolean isHdAttempting, - boolean isHdAudioCall, - boolean isForwardedNumber, - boolean shouldShowContactPhoto, - long connectTimeMillis, - boolean isVoiceMailNumber, - boolean isRemotelyHeld, - boolean isBusinessNumber, - boolean supportsCallOnHold, - @ButtonState int swapToSecondaryButtonState, - boolean isAssistedDialed, - @Nullable String customLabel, - @Nullable TransformationInfo assistedDialingExtras) { - this.state = state; - this.isVideoCall = isVideoCall; - this.sessionModificationState = sessionModificationState; - this.disconnectCause = disconnectCause; - this.connectionLabel = connectionLabel; - this.connectionIcon = connectionIcon; - this.gatewayNumber = gatewayNumber; - this.callSubject = callSubject; - this.callbackNumber = callbackNumber; - this.isWifi = isWifi; - this.isConference = isConference; - this.isWorkCall = isWorkCall; - this.isHdAttempting = isHdAttempting; - this.isHdAudioCall = isHdAudioCall; - this.isForwardedNumber = isForwardedNumber; - this.shouldShowContactPhoto = shouldShowContactPhoto; - this.connectTimeMillis = connectTimeMillis; - this.isVoiceMailNumber = isVoiceMailNumber; - this.isRemotelyHeld = isRemotelyHeld; - this.isBusinessNumber = isBusinessNumber; - this.supportsCallOnHold = supportsCallOnHold; - this.swapToSecondaryButtonState = swapToSecondaryButtonState; - this.isAssistedDialed = isAssistedDialed; - if (!TextUtils.isEmpty(customLabel)) { - Assert.checkArgument(state == State.CALL_PENDING); + /** Builder class for primary call state info. */ + @AutoValue.Builder + public abstract static class Builder { + public abstract Builder setState(int state); + + public abstract Builder setIsVideoCall(boolean isVideoCall); + + public abstract Builder setSessionModificationState( + @SessionModificationState int sessionModificationState); + + public abstract Builder setDisconnectCause(DisconnectCause disconnectCause); + + public abstract Builder setConnectionLabel(String connectionLabel); + + public abstract Builder setConnectionIcon(Drawable connectionIcon); + + public abstract Builder setGatewayNumber(String gatewayNumber); + + public abstract Builder setCallSubject(String callSubject); + + public abstract Builder setCallbackNumber(String callbackNumber); + + public abstract Builder setIsWifi(boolean isWifi); + + public abstract Builder setIsConference(boolean isConference); + + public abstract Builder setIsWorkCall(boolean isWorkCall); + + public abstract Builder setIsHdAttempting(boolean isHdAttempting); + + public abstract Builder setIsHdAudioCall(boolean isHdAudioCall); + + public abstract Builder setIsForwardedNumber(boolean isForwardedNumber); + + public abstract Builder setShouldShowContactPhoto(boolean shouldShowContactPhoto); + + public abstract Builder setConnectTimeMillis(long connectTimeMillis); + + public abstract Builder setIsVoiceMailNumber(boolean isVoiceMailNumber); + + public abstract Builder setIsRemotelyHeld(boolean isRemotelyHeld); + + public abstract Builder setIsBusinessNumber(boolean isBusinessNumber); + + public abstract Builder setSupportsCallOnHold(boolean supportsCallOnHold); + + public abstract Builder setSwapToSecondaryButtonState( + @ButtonState int swapToSecondaryButtonState); + + public abstract Builder setIsAssistedDialed(boolean isAssistedDialed); + + public abstract Builder setCustomLabel(String customLabel); + + public abstract Builder setAssistedDialingExtras(TransformationInfo assistedDialingExtras); + + abstract PrimaryCallState autoBuild(); + + public PrimaryCallState build() { + PrimaryCallState primaryCallState = autoBuild(); + if (!TextUtils.isEmpty(primaryCallState.customLabel())) { + Assert.checkArgument(primaryCallState.state() == State.CALL_PENDING); + } + return primaryCallState; } - this.customLabel = customLabel; - this.assistedDialingExtras = assistedDialingExtras; + } + + public static PrimaryCallState empty() { + return PrimaryCallState.builder().build(); } @Override public String toString() { return String.format( - Locale.US, "PrimaryCallState, state: %d, connectionLabel: %s", state, connectionLabel); + Locale.US, "PrimaryCallState, state: %d, connectionLabel: %s", state(), connectionLabel()); } } |