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