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.ScreenshotController.ACTION_TYPE_EDIT; 20 import static com.android.systemui.screenshot.ScreenshotController.ACTION_TYPE_SHARE; 21 import static com.android.systemui.screenshot.ScreenshotController.EXTRA_ACTION_INTENT; 22 import static com.android.systemui.screenshot.ScreenshotController.EXTRA_DISALLOW_ENTER_PIP; 23 import static com.android.systemui.screenshot.ScreenshotController.EXTRA_ID; 24 import static com.android.systemui.screenshot.ScreenshotController.EXTRA_SMART_ACTIONS_ENABLED; 25 import static com.android.systemui.statusbar.phone.CentralSurfaces.SYSTEM_DIALOG_REASON_SCREENSHOT; 26 27 import android.app.ActivityOptions; 28 import android.app.PendingIntent; 29 import android.content.BroadcastReceiver; 30 import android.content.Context; 31 import android.content.Intent; 32 import android.util.Log; 33 import android.view.RemoteAnimationAdapter; 34 import android.view.WindowManagerGlobal; 35 36 import com.android.systemui.settings.DisplayTracker; 37 import com.android.systemui.shared.system.ActivityManagerWrapper; 38 import com.android.systemui.statusbar.phone.CentralSurfaces; 39 40 import java.util.Optional; 41 42 import javax.inject.Inject; 43 44 /** 45 * Receiver to proxy the share or edit intent, used to clean up the notification and send 46 * appropriate signals to the system (ie. to dismiss the keyguard if necessary). 47 */ 48 public class ActionProxyReceiver extends BroadcastReceiver { 49 private static final String TAG = "ActionProxyReceiver"; 50 51 private final CentralSurfaces mCentralSurfaces; 52 private final ActivityManagerWrapper mActivityManagerWrapper; 53 private final ScreenshotSmartActions mScreenshotSmartActions; 54 private final DisplayTracker mDisplayTracker; 55 56 @Inject ActionProxyReceiver(Optional<CentralSurfaces> centralSurfacesOptional, ActivityManagerWrapper activityManagerWrapper, ScreenshotSmartActions screenshotSmartActions, DisplayTracker displayTracker)57 public ActionProxyReceiver(Optional<CentralSurfaces> centralSurfacesOptional, 58 ActivityManagerWrapper activityManagerWrapper, 59 ScreenshotSmartActions screenshotSmartActions, 60 DisplayTracker displayTracker) { 61 mCentralSurfaces = centralSurfacesOptional.orElse(null); 62 mActivityManagerWrapper = activityManagerWrapper; 63 mScreenshotSmartActions = screenshotSmartActions; 64 mDisplayTracker = displayTracker; 65 } 66 67 @Override onReceive(Context context, final Intent intent)68 public void onReceive(Context context, final Intent intent) { 69 Runnable startActivityRunnable = () -> { 70 mActivityManagerWrapper.closeSystemWindows(SYSTEM_DIALOG_REASON_SCREENSHOT); 71 72 PendingIntent actionIntent = intent.getParcelableExtra(EXTRA_ACTION_INTENT); 73 ActivityOptions opts = ActivityOptions.makeBasic(); 74 opts.setDisallowEnterPictureInPictureWhileLaunching( 75 intent.getBooleanExtra(EXTRA_DISALLOW_ENTER_PIP, false)); 76 try { 77 actionIntent.send(context, 0, null, null, null, null, opts.toBundle()); 78 if (intent.getBooleanExtra(ScreenshotController.EXTRA_OVERRIDE_TRANSITION, false)) { 79 RemoteAnimationAdapter runner = new RemoteAnimationAdapter( 80 ScreenshotController.SCREENSHOT_REMOTE_RUNNER, 0, 0); 81 try { 82 WindowManagerGlobal.getWindowManagerService() 83 .overridePendingAppTransitionRemote(runner, 84 mDisplayTracker.getDefaultDisplayId()); 85 } catch (Exception e) { 86 Log.e(TAG, "Error overriding screenshot app transition", e); 87 } 88 } 89 } catch (PendingIntent.CanceledException e) { 90 Log.e(TAG, "Pending intent canceled", e); 91 } 92 93 }; 94 95 if (mCentralSurfaces != null) { 96 mCentralSurfaces.executeRunnableDismissingKeyguard(startActivityRunnable, null, 97 true /* dismissShade */, true /* afterKeyguardGone */, 98 true /* deferred */); 99 } else { 100 startActivityRunnable.run(); 101 } 102 103 if (intent.getBooleanExtra(EXTRA_SMART_ACTIONS_ENABLED, false)) { 104 String actionType = Intent.ACTION_EDIT.equals(intent.getAction()) 105 ? ACTION_TYPE_EDIT 106 : ACTION_TYPE_SHARE; 107 mScreenshotSmartActions.notifyScreenshotAction( 108 intent.getStringExtra(EXTRA_ID), actionType, false, null); 109 } 110 } 111 } 112