Satakshi | d2010f2 | 2019-10-29 10:57:43 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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.systemui.screenshot; |
| 18 | |
| 19 | import android.app.Notification; |
| 20 | import android.content.ComponentName; |
Satakshi | d2010f2 | 2019-10-29 10:57:43 -0700 | [diff] [blame] | 21 | import android.graphics.Bitmap; |
Katsiaryna Naliuka | 2f8ae17 | 2020-04-22 14:14:27 +0200 | [diff] [blame^] | 22 | import android.net.Uri; |
Satakshi | d2010f2 | 2019-10-29 10:57:43 -0700 | [diff] [blame] | 23 | import android.util.Log; |
| 24 | |
| 25 | import java.util.Collections; |
| 26 | import java.util.List; |
| 27 | import java.util.concurrent.CompletableFuture; |
Satakshi | d2010f2 | 2019-10-29 10:57:43 -0700 | [diff] [blame] | 28 | |
| 29 | /** |
| 30 | * This class can be overridden by a vendor-specific sys UI implementation, |
| 31 | * in order to provide smart actions in the screenshot notification. |
| 32 | */ |
| 33 | public class ScreenshotNotificationSmartActionsProvider { |
Satakshi | aaf6953 | 2019-11-07 17:54:24 -0800 | [diff] [blame] | 34 | /* Key provided in the notification action to get the type of smart action. */ |
| 35 | public static final String ACTION_TYPE = "action_type"; |
| 36 | public static final String DEFAULT_ACTION_TYPE = "Smart Action"; |
| 37 | |
| 38 | /* Define phases of screenshot execution. */ |
| 39 | protected enum ScreenshotOp { |
| 40 | OP_UNKNOWN, |
| 41 | RETRIEVE_SMART_ACTIONS, |
| 42 | REQUEST_SMART_ACTIONS, |
| 43 | WAIT_FOR_SMART_ACTIONS |
| 44 | } |
| 45 | |
| 46 | /* Enum to report success or failure for screenshot execution phases. */ |
| 47 | protected enum ScreenshotOpStatus { |
| 48 | OP_STATUS_UNKNOWN, |
| 49 | SUCCESS, |
| 50 | ERROR, |
| 51 | TIMEOUT |
| 52 | } |
| 53 | |
Satakshi | d2010f2 | 2019-10-29 10:57:43 -0700 | [diff] [blame] | 54 | private static final String TAG = "ScreenshotActions"; |
| 55 | |
| 56 | /** |
| 57 | * Default implementation that returns an empty list. |
| 58 | * This method is overridden in vendor-specific Sys UI implementation. |
| 59 | * |
Katsiaryna Naliuka | 858daa4 | 2020-03-20 14:58:35 +0100 | [diff] [blame] | 60 | * @param screenshotId A generated random unique id for the screenshot. |
| 61 | * @param screenshotFileName name of the file where the screenshot will be written. |
| 62 | * @param bitmap The bitmap of the screenshot. The bitmap config must be {@link |
| 63 | * HARDWARE}. |
| 64 | * @param componentName Contains package and activity class names where the screenshot was |
| 65 | * taken. This is used as an additional signal to generate and rank |
| 66 | * more relevant actions. |
| 67 | * @param isManagedProfile The screenshot was taken for a work profile app. |
Satakshi | d2010f2 | 2019-10-29 10:57:43 -0700 | [diff] [blame] | 68 | */ |
Satakshi | aaf6953 | 2019-11-07 17:54:24 -0800 | [diff] [blame] | 69 | public CompletableFuture<List<Notification.Action>> getActions( |
| 70 | String screenshotId, |
Katsiaryna Naliuka | 2f8ae17 | 2020-04-22 14:14:27 +0200 | [diff] [blame^] | 71 | Uri screenshotUri, |
Satakshi | aaf6953 | 2019-11-07 17:54:24 -0800 | [diff] [blame] | 72 | Bitmap bitmap, |
| 73 | ComponentName componentName, |
Satakshi | d2010f2 | 2019-10-29 10:57:43 -0700 | [diff] [blame] | 74 | boolean isManagedProfile) { |
| 75 | Log.d(TAG, "Returning empty smart action list."); |
| 76 | return CompletableFuture.completedFuture(Collections.emptyList()); |
| 77 | } |
Satakshi | aaf6953 | 2019-11-07 17:54:24 -0800 | [diff] [blame] | 78 | |
| 79 | /** |
| 80 | * Notify exceptions and latency encountered during generating smart actions. |
| 81 | * This method is overridden in vendor-specific Sys UI implementation. |
| 82 | * |
Katsiaryna Naliuka | 858daa4 | 2020-03-20 14:58:35 +0100 | [diff] [blame] | 83 | * @param screenshotId unique id of the screenshot. |
Satakshi | aaf6953 | 2019-11-07 17:54:24 -0800 | [diff] [blame] | 84 | * @param op screenshot execution phase defined in {@link ScreenshotOp} |
| 85 | * @param status {@link ScreenshotOpStatus} to report success or failure. |
| 86 | * @param durationMs latency experienced in different phases of screenshots. |
| 87 | */ |
| 88 | public void notifyOp(String screenshotId, ScreenshotOp op, ScreenshotOpStatus status, |
| 89 | long durationMs) { |
| 90 | Log.d(TAG, "Return without notify."); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Notify screenshot notification action invoked. |
| 95 | * This method is overridden in vendor-specific Sys UI implementation. |
| 96 | * |
| 97 | * @param screenshotId Unique id of the screenshot. |
| 98 | * @param action type of notification action invoked. |
| 99 | * @param isSmartAction whether action invoked was a smart action. |
| 100 | */ |
| 101 | public void notifyAction(String screenshotId, String action, boolean isSmartAction) { |
| 102 | Log.d(TAG, "Return without notify."); |
| 103 | } |
Satakshi | d2010f2 | 2019-10-29 10:57:43 -0700 | [diff] [blame] | 104 | } |