1 /* 2 * Copyright (C) 2020 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.GlobalScreenshot.EXTRA_ACTION_INTENT; 20 import static com.android.systemui.screenshot.GlobalScreenshot.EXTRA_ACTION_TYPE; 21 import static com.android.systemui.screenshot.GlobalScreenshot.EXTRA_ID; 22 23 import android.app.ActivityOptions; 24 import android.app.PendingIntent; 25 import android.content.BroadcastReceiver; 26 import android.content.Context; 27 import android.content.Intent; 28 import android.util.Log; 29 import android.util.Slog; 30 31 import javax.inject.Inject; 32 33 34 /** 35 * Executes the smart action tapped by the user in the notification. 36 */ 37 public class SmartActionsReceiver extends BroadcastReceiver { 38 private static final String TAG = "SmartActionsReceiver"; 39 40 private final ScreenshotSmartActions mScreenshotSmartActions; 41 42 @Inject SmartActionsReceiver(ScreenshotSmartActions screenshotSmartActions)43 SmartActionsReceiver(ScreenshotSmartActions screenshotSmartActions) { 44 mScreenshotSmartActions = screenshotSmartActions; 45 } 46 47 @Override onReceive(Context context, Intent intent)48 public void onReceive(Context context, Intent intent) { 49 PendingIntent pendingIntent = intent.getParcelableExtra(EXTRA_ACTION_INTENT); 50 String actionType = intent.getStringExtra(EXTRA_ACTION_TYPE); 51 Slog.d(TAG, "Executing smart action [" + actionType + "]:" + pendingIntent.getIntent()); 52 ActivityOptions opts = ActivityOptions.makeBasic(); 53 54 try { 55 pendingIntent.send(context, 0, null, null, null, null, opts.toBundle()); 56 } catch (PendingIntent.CanceledException e) { 57 Log.e(TAG, "Pending intent canceled", e); 58 } 59 60 mScreenshotSmartActions.notifyScreenshotAction( 61 context, intent.getStringExtra(EXTRA_ID), actionType, true); 62 } 63 } 64