• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 static com.android.systemui.screenshot.LogConfig.DEBUG_ACTIONS;
20 import static com.android.systemui.screenshot.LogConfig.logTag;
21 
22 import android.app.Notification;
23 import android.content.ComponentName;
24 import android.content.Intent;
25 import android.graphics.Bitmap;
26 import android.net.Uri;
27 import android.os.UserHandle;
28 import android.util.Log;
29 
30 import java.util.Collections;
31 import java.util.List;
32 import java.util.concurrent.CompletableFuture;
33 
34 /**
35  * This class can be overridden by a vendor-specific sys UI implementation,
36  * in order to provide smart actions in the screenshot notification.
37  */
38 public class ScreenshotNotificationSmartActionsProvider {
39 
40     private static final String TAG = logTag(ScreenshotNotificationSmartActionsProvider.class);
41 
42     /* Key provided in the notification action to get the type of smart action. */
43     public static final String ACTION_TYPE = "action_type";
44     public static final String DEFAULT_ACTION_TYPE = "Smart Action";
45 
46     /* Define phases of screenshot execution. */
47     protected enum ScreenshotOp {
48         OP_UNKNOWN,
49         RETRIEVE_SMART_ACTIONS,
50         REQUEST_SMART_ACTIONS,
51         WAIT_FOR_SMART_ACTIONS
52     }
53 
54     /* Enum to report success or failure for screenshot execution phases. */
55     protected enum ScreenshotOpStatus {
56         OP_STATUS_UNKNOWN,
57         SUCCESS,
58         ERROR,
59         TIMEOUT
60     }
61 
62     /* Enum to define screenshot smart action types. */
63     public enum ScreenshotSmartActionType {
64         REGULAR_SMART_ACTIONS,
65         QUICK_SHARE_ACTION
66     }
67 
68     /**
69      * Default implementation that returns an empty list.
70      * This method is overridden in vendor-specific Sys UI implementation.
71      *
72      * @param screenshotId       a unique id for the screenshot
73      * @param screenshotUri      uri where the screenshot has been stored
74      * @param bitmap             the screenshot, config must be {@link Bitmap.Config#HARDWARE}
75      * @param componentName      name of the foreground component when the screenshot was taken
76      * @param userHandle         user handle of the foreground task owner
77      */
getActions(String screenshotId, Uri screenshotUri, Bitmap bitmap, ComponentName componentName, ScreenshotSmartActionType actionType, UserHandle userHandle)78     public CompletableFuture<List<Notification.Action>> getActions(String screenshotId,
79             Uri screenshotUri, Bitmap bitmap, ComponentName componentName,
80             ScreenshotSmartActionType actionType, UserHandle userHandle) {
81         if (DEBUG_ACTIONS) {
82             Log.d(TAG, "Returning empty smart action list.");
83         }
84         return CompletableFuture.completedFuture(Collections.emptyList());
85     }
86 
87     /**
88      * Notify exceptions and latency encountered during generating smart actions.
89      * This method is overridden in vendor-specific Sys UI implementation.
90      *
91      * @param screenshotId unique id of the screenshot.
92      * @param op           screenshot execution phase defined in {@link ScreenshotOp}
93      * @param status       {@link ScreenshotOpStatus} to report success or failure.
94      * @param durationMs   latency experienced in different phases of screenshots.
95      */
notifyOp(String screenshotId, ScreenshotOp op, ScreenshotOpStatus status, long durationMs)96     public void notifyOp(String screenshotId, ScreenshotOp op, ScreenshotOpStatus status,
97             long durationMs) {
98         if (DEBUG_ACTIONS) {
99             Log.d(TAG, "SmartActions: notifyOp() - return without notify");
100         }
101     }
102 
103     /**
104      * Notify screenshot notification action invoked.
105      * This method is overridden in vendor-specific Sys UI implementation.
106      *
107      * @param screenshotId  Unique id of the screenshot.
108      * @param action        type of notification action invoked.
109      * @param isSmartAction whether action invoked was a smart action.
110      */
notifyAction(String screenshotId, String action, boolean isSmartAction, Intent intent)111     public void notifyAction(String screenshotId, String action, boolean isSmartAction,
112             Intent intent) {
113         if (DEBUG_ACTIONS) {
114             Log.d(TAG, "SmartActions: notifyAction: return without notify");
115         }
116     }
117 }
118