Home | History | Annotate | Download | only in protocol
      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 
     17 package com.android.incallui.incall.protocol;
     18 
     19 import android.graphics.drawable.Drawable;
     20 import android.support.annotation.Nullable;
     21 import com.android.dialer.common.LogUtil;
     22 import com.android.dialer.multimedia.MultimediaData;
     23 import com.google.auto.value.AutoValue;
     24 import java.util.Locale;
     25 
     26 /** Information about the primary call. */
     27 @AutoValue
     28 public abstract class PrimaryInfo {
     29   @Nullable
     30   public abstract String number();
     31 
     32   @Nullable
     33   public abstract String name();
     34 
     35   public abstract boolean nameIsNumber();
     36   // This is from contacts and shows the type of number. For example, "Mobile".
     37   @Nullable
     38   public abstract String label();
     39 
     40   @Nullable
     41   public abstract String location();
     42 
     43   @Nullable
     44   public abstract Drawable photo();
     45 
     46   @ContactPhotoType
     47   public abstract int photoType();
     48 
     49   public abstract boolean isSipCall();
     50 
     51   public abstract boolean isContactPhotoShown();
     52 
     53   public abstract boolean isWorkCall();
     54 
     55   public abstract boolean isSpam();
     56 
     57   public abstract boolean isLocalContact();
     58 
     59   public abstract boolean answeringDisconnectsOngoingCall();
     60 
     61   public abstract boolean shouldShowLocation();
     62   // Used for consistent LetterTile coloring.
     63   @Nullable
     64   public abstract String contactInfoLookupKey();
     65 
     66   @Nullable
     67   public abstract MultimediaData multimediaData();
     68 
     69   public abstract boolean showInCallButtonGrid();
     70 
     71   public abstract int numberPresentation();
     72 
     73   public static Builder builder() {
     74     return new AutoValue_PrimaryInfo.Builder();
     75   }
     76   /** Builder class for primary call info. */
     77   @AutoValue.Builder
     78   public abstract static class Builder {
     79     public abstract Builder setNumber(String number);
     80 
     81     public abstract Builder setName(String name);
     82 
     83     public abstract Builder setNameIsNumber(boolean nameIsNumber);
     84 
     85     public abstract Builder setLabel(String label);
     86 
     87     public abstract Builder setLocation(String location);
     88 
     89     public abstract Builder setPhoto(Drawable photo);
     90 
     91     public abstract Builder setPhotoType(@ContactPhotoType int photoType);
     92 
     93     public abstract Builder setIsSipCall(boolean isSipCall);
     94 
     95     public abstract Builder setIsContactPhotoShown(boolean isContactPhotoShown);
     96 
     97     public abstract Builder setIsWorkCall(boolean isWorkCall);
     98 
     99     public abstract Builder setIsSpam(boolean isSpam);
    100 
    101     public abstract Builder setIsLocalContact(boolean isLocalContact);
    102 
    103     public abstract Builder setAnsweringDisconnectsOngoingCall(
    104         boolean answeringDisconnectsOngoingCall);
    105 
    106     public abstract Builder setShouldShowLocation(boolean shouldShowLocation);
    107 
    108     public abstract Builder setContactInfoLookupKey(String contactInfoLookupKey);
    109 
    110     public abstract Builder setMultimediaData(MultimediaData multimediaData);
    111 
    112     public abstract Builder setShowInCallButtonGrid(boolean showInCallButtonGrid);
    113 
    114     public abstract Builder setNumberPresentation(int numberPresentation);
    115 
    116     public abstract PrimaryInfo build();
    117   }
    118 
    119   public static PrimaryInfo empty() {
    120     return PrimaryInfo.builder()
    121         .setNameIsNumber(false)
    122         .setPhotoType(ContactPhotoType.DEFAULT_PLACEHOLDER)
    123         .setIsSipCall(false)
    124         .setIsContactPhotoShown(false)
    125         .setIsWorkCall(false)
    126         .setIsSpam(false)
    127         .setIsLocalContact(false)
    128         .setAnsweringDisconnectsOngoingCall(false)
    129         .setShouldShowLocation(false)
    130         .setShowInCallButtonGrid(true)
    131         .setNumberPresentation(-1)
    132         .build();
    133   }
    134 
    135   @Override
    136   public String toString() {
    137     return String.format(
    138         Locale.US,
    139         "PrimaryInfo, number: %s, name: %s, location: %s, label: %s, "
    140             + "photo: %s, photoType: %d, isPhotoVisible: %b, MultimediaData: %s",
    141         LogUtil.sanitizePhoneNumber(number()),
    142         LogUtil.sanitizePii(name()),
    143         LogUtil.sanitizePii(location()),
    144         label(),
    145         photo(),
    146         photoType(),
    147         isContactPhotoShown(),
    148         multimediaData());
    149   }
    150 }
    151