1 /* 2 * Copyright (C) 2022 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.server.nearby.fastpair.blocklist; 18 19 20 /** 21 * Skeletal implementation of Blocklist 22 * 23 * <p>Controls the frequency to show the available device to users. 24 */ 25 public interface Blocklist { 26 27 /** Checks certain item is blocked within durationSeconds. */ isBlocklisted(int id, int durationSeconds)28 boolean isBlocklisted(int id, int durationSeconds); 29 30 /** Updates the HalfSheet blocklist state for a given id. */ updateState(int id, BlocklistState state)31 boolean updateState(int id, BlocklistState state); 32 33 /** Removes the HalfSheet blocklist. */ removeBlocklist(int id)34 boolean removeBlocklist(int id); 35 36 /** Resets certain device ban state to active. */ resetBlockState(int id)37 void resetBlockState(int id); 38 39 /** 40 * Used for indicate what state is the blocklist item. 41 * 42 * <p>The different states have differing priorities and higher priority states will override 43 * lower one. 44 * More details and state transition diagram, 45 * see: https://docs.google.com/document/d/1wzE5CHXTkzKJY-2AltSrxOVteom2Nebc1sbjw1Tt7BQ/edit?usp=sharing&resourcekey=0-L-wUz3Hw5gZPThm5VPwHOQ 46 */ 47 enum BlocklistState { 48 UNKNOWN(0), 49 ACTIVE(1), 50 DISMISSED(2), 51 PAIRING(3), 52 PAIRED(4), 53 DO_NOT_SHOW_AGAIN(5), 54 DO_NOT_SHOW_AGAIN_LONG(6); 55 56 private final int mValue; 57 BlocklistState(final int value)58 BlocklistState(final int value) { 59 this.mValue = value; 60 } 61 hasHigherPriorityThan(BlocklistState otherState)62 public boolean hasHigherPriorityThan(BlocklistState otherState) { 63 return this.mValue > otherState.mValue; 64 } 65 } 66 } 67