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