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.dialer.multimedia; 18 19 import android.location.Location; 20 import android.net.Uri; 21 import android.support.annotation.NonNull; 22 import android.support.annotation.Nullable; 23 import com.android.dialer.common.LogUtil; 24 import com.google.auto.value.AutoValue; 25 26 /** Holds data associated with a call. */ 27 @AutoValue 28 public abstract class MultimediaData { 29 30 public static final MultimediaData EMPTY = builder().build(); 31 32 @NonNull builder()33 public static Builder builder() { 34 return new AutoValue_MultimediaData.Builder().setImportant(false); 35 } 36 37 /** 38 * Returns the text part of this data. 39 * 40 * <p>This field is used for both the call composer session and the post call note. 41 */ 42 @Nullable getText()43 public abstract String getText(); 44 45 /** Returns the location part of this data. */ 46 @Nullable getLocation()47 public abstract Location getLocation(); 48 49 /** Returns {@code true} if this object contains image data. */ hasImageData()50 public boolean hasImageData() { 51 // imageUri and content are always either both null or nonnull 52 return getImageUri() != null && getImageContentType() != null; 53 } 54 55 /** Returns the image uri part of this object's image. */ 56 @Nullable getImageUri()57 public abstract Uri getImageUri(); 58 59 /** Returns the content type part of this object's image, either image/png or image/jpeg. */ 60 @Nullable getImageContentType()61 public abstract String getImageContentType(); 62 63 /** Returns {@code true} if this data is marked as important. */ isImportant()64 public abstract boolean isImportant(); 65 66 /** Returns the string form of this MultimediaData with no PII. */ 67 @Override toString()68 public String toString() { 69 return String.format( 70 "MultimediaData{subject: %s, location: %s, imageUrl: %s, imageContentType: %s, " 71 + "important: %b}", 72 LogUtil.sanitizePii(getText()), 73 LogUtil.sanitizePii(getLocation()), 74 LogUtil.sanitizePii(getImageUri()), 75 getImageContentType(), 76 isImportant()); 77 } 78 79 /** Creates instances of {@link MultimediaData}. */ 80 @AutoValue.Builder 81 public abstract static class Builder { 82 setText(@onNull String subject)83 public abstract Builder setText(@NonNull String subject); 84 setLocation(@onNull Location location)85 public abstract Builder setLocation(@NonNull Location location); 86 setImage(@onNull Uri image, @NonNull String imageContentType)87 public Builder setImage(@NonNull Uri image, @NonNull String imageContentType) { 88 setImageUri(image); 89 setImageContentType(imageContentType); 90 return this; 91 } 92 setImageUri(@onNull Uri image)93 abstract Builder setImageUri(@NonNull Uri image); 94 setImageContentType(@onNull String imageContentType)95 abstract Builder setImageContentType(@NonNull String imageContentType); 96 setImportant(boolean isImportant)97 public abstract Builder setImportant(boolean isImportant); 98 build()99 public abstract MultimediaData build(); 100 } 101 } 102