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