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_DELETE; 20 import static com.android.systemui.screenshot.ScreenshotController.EXTRA_ID; 21 import static com.android.systemui.screenshot.ScreenshotController.EXTRA_SMART_ACTIONS_ENABLED; 22 import static com.android.systemui.screenshot.ScreenshotController.SCREENSHOT_URI_ID; 23 24 import android.content.BroadcastReceiver; 25 import android.content.ContentResolver; 26 import android.content.Context; 27 import android.content.Intent; 28 import android.net.Uri; 29 30 import com.android.systemui.dagger.qualifiers.Background; 31 32 import java.util.concurrent.Executor; 33 34 import javax.inject.Inject; 35 36 /** 37 * Removes the file at a provided URI. 38 */ 39 public class DeleteScreenshotReceiver extends BroadcastReceiver { 40 41 private final ScreenshotSmartActions mScreenshotSmartActions; 42 private final Executor mBackgroundExecutor; 43 44 @Inject DeleteScreenshotReceiver(ScreenshotSmartActions screenshotSmartActions, @Background Executor backgroundExecutor)45 public DeleteScreenshotReceiver(ScreenshotSmartActions screenshotSmartActions, 46 @Background Executor backgroundExecutor) { 47 mScreenshotSmartActions = screenshotSmartActions; 48 mBackgroundExecutor = backgroundExecutor; 49 } 50 51 @Override onReceive(Context context, Intent intent)52 public void onReceive(Context context, Intent intent) { 53 if (!intent.hasExtra(SCREENSHOT_URI_ID)) { 54 return; 55 } 56 57 // And delete the image from the media store 58 final Uri uri = Uri.parse(intent.getStringExtra(SCREENSHOT_URI_ID)); 59 mBackgroundExecutor.execute(() -> { 60 ContentResolver resolver = context.getContentResolver(); 61 resolver.delete(uri, null, null); 62 }); 63 if (intent.getBooleanExtra(EXTRA_SMART_ACTIONS_ENABLED, false)) { 64 mScreenshotSmartActions.notifyScreenshotAction( 65 intent.getStringExtra(EXTRA_ID), ACTION_TYPE_DELETE, false, null); 66 } 67 } 68 } 69