1 /* 2 * Copyright (C) 2018 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.spam.status; 18 19 import android.support.annotation.IntDef; 20 import com.google.auto.value.AutoValue; 21 import com.google.common.base.Optional; 22 import java.lang.annotation.Retention; 23 import java.lang.annotation.RetentionPolicy; 24 25 /** A value class representing a number's spam status in the user spam list. */ 26 @AutoValue 27 @SuppressWarnings("Guava") 28 public abstract class UserSpamListStatus { 29 30 /** Integers representing the spam status in the user spam list. */ 31 @Retention(RetentionPolicy.SOURCE) 32 @IntDef({Status.NOT_ON_LIST, Status.WHITELISTED, Status.BLACKLISTED}) 33 public @interface Status { 34 int NOT_ON_LIST = 1; 35 int WHITELISTED = 2; 36 int BLACKLISTED = 3; 37 } 38 getStatus()39 public abstract @Status int getStatus(); 40 41 /** 42 * Returns the timestamp (in milliseconds) representing when a number's spam status was put on the 43 * list, or {@code Optional.absent()} if the number is not on the list. 44 */ getTimestampMillis()45 public abstract Optional<Long> getTimestampMillis(); 46 notOnList()47 public static UserSpamListStatus notOnList() { 48 return new AutoValue_UserSpamListStatus(Status.NOT_ON_LIST, Optional.absent()); 49 } 50 whitelisted(long timestampMillis)51 public static UserSpamListStatus whitelisted(long timestampMillis) { 52 return new AutoValue_UserSpamListStatus(Status.WHITELISTED, Optional.of(timestampMillis)); 53 } 54 blacklisted(long timestampMillis)55 public static UserSpamListStatus blacklisted(long timestampMillis) { 56 return new AutoValue_UserSpamListStatus(Status.BLACKLISTED, Optional.of(timestampMillis)); 57 } 58 } 59