| 1 | /* |
| 2 | * Copyright (C) 2021 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 android.view.displayhash; |
| 18 | |
| 19 | import android.annotation.IntDef; |
| 20 | import android.annotation.NonNull; |
| 21 | import android.graphics.Rect; |
| 22 | import android.view.View; |
| 23 | |
| 24 | import java.lang.annotation.Retention; |
| 25 | import java.lang.annotation.RetentionPolicy; |
| 26 | import java.util.concurrent.Executor; |
| 27 | |
| 28 | /** |
| 29 | * Use when calling {@link View#generateDisplayHash(String, Rect, Executor, |
| 30 | * DisplayHashResultCallback)}. |
| 31 | * |
| 32 | * The callback will only invoke either {@link #onDisplayHashResult} when the system successfully |
| 33 | * generated the {@link DisplayHash} or {@link #onDisplayHashError(int)} when it failed. |
| 34 | */ |
| 35 | public interface DisplayHashResultCallback { |
| 36 | /** |
| 37 | * @hide |
| 38 | */ |
| 39 | String EXTRA_DISPLAY_HASH = "DISPLAY_HASH"; |
| 40 | |
| 41 | /** |
| 42 | * @hide |
| 43 | */ |
| 44 | String EXTRA_DISPLAY_HASH_ERROR_CODE = "DISPLAY_HASH_ERROR_CODE"; |
| 45 | |
| 46 | /** |
| 47 | * An unknown error occurred. |
| 48 | */ |
| 49 | int DISPLAY_HASH_ERROR_UNKNOWN = -1; |
| 50 | |
| 51 | /** |
| 52 | * The bounds used when requesting the hash hash were invalid or empty. |
| 53 | */ |
| 54 | int DISPLAY_HASH_ERROR_INVALID_BOUNDS = -2; |
| 55 | |
| 56 | /** |
| 57 | * The window for the view that requested the hash is no longer around. This can happen if the |
| 58 | * window is getting torn down. |
| 59 | */ |
| 60 | int DISPLAY_HASH_ERROR_MISSING_WINDOW = -3; |
| 61 | |
| 62 | /** |
| 63 | * The view that requested the hash is not visible on screen. This could either mean |
| 64 | * that the view bounds are offscreen, window bounds are offscreen, view is not visible, or |
| 65 | * window is not visible. |
| 66 | */ |
| 67 | int DISPLAY_HASH_ERROR_NOT_VISIBLE_ON_SCREEN = -4; |
| 68 | |
| 69 | /** |
| 70 | * The hash algorithm sent to generate the hash was invalid. This means the value is not one |
| 71 | * of the supported values in {@link DisplayHashManager#getSupportedHashAlgorithms()} |
| 72 | */ |
| 73 | int DISPLAY_HASH_ERROR_INVALID_HASH_ALGORITHM = -5; |
| 74 | |
| 75 | /** |
| 76 | * The caller requested to generate the hash too frequently. The caller should try again at a |
| 77 | * after some time has passed to ensure the system isn't overloaded. |
| 78 | */ |
| 79 | int DISPLAY_HASH_ERROR_TOO_MANY_REQUESTS = -6; |
| 80 | |
| 81 | /** @hide */ |
| 82 | @IntDef(prefix = {"DISPLAY_HASH_ERROR_"}, value = { |
| 83 | DISPLAY_HASH_ERROR_UNKNOWN, |
| 84 | DISPLAY_HASH_ERROR_INVALID_BOUNDS, |
| 85 | DISPLAY_HASH_ERROR_MISSING_WINDOW, |
| 86 | DISPLAY_HASH_ERROR_NOT_VISIBLE_ON_SCREEN, |
| 87 | DISPLAY_HASH_ERROR_INVALID_HASH_ALGORITHM, |
| 88 | DISPLAY_HASH_ERROR_TOO_MANY_REQUESTS |
| 89 | }) |
| 90 | @Retention(RetentionPolicy.SOURCE) |
| 91 | @interface DisplayHashErrorCode { |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Callback invoked when calling |
| 96 | * {@link android.view.View#generateDisplayHash(String, Rect, Executor, |
| 97 | * DisplayHashResultCallback)} |
| 98 | * |
| 99 | * @param displayHash The DisplayHash generated. If the hash cannot be generated, |
| 100 | * {@link #onDisplayHashError(int)} will be called instead |
| 101 | */ |
| 102 | void onDisplayHashResult(@NonNull DisplayHash displayHash); |
| 103 | |
| 104 | /** |
| 105 | * Callback invoked when |
| 106 | * {@link android.view.View#generateDisplayHash(String, Rect, Executor, |
| 107 | * DisplayHashResultCallback)} results in an error and cannot generate a display hash. |
| 108 | * |
| 109 | * @param errorCode One of the values in {@link DisplayHashErrorCode} |
| 110 | */ |
| 111 | void onDisplayHashError(@DisplayHashErrorCode int errorCode); |
| 112 | } |