Squash SystemUI: screenshot: Add delete action chip intent

[ghostrider-reborn] updated to android 12, 13

Co-authored-by: Adithya R <gh0strider.2k18.reborn@gmail.com>
Change-Id: Ia55ac91c2db2f44062674a699f8df63c96e1de5c

SystemUI: Add back DeleteScreenshotReceiver

And add new delete action view in ActionIntentCreator after

https://github.com/omnirom/android_frameworks_base/commit/08b1e5b55cac6a58e720bea67c77b6c064f0229c#diff-94382179b1c43f734b96336e03eb65ca48ae3aa98f12da6bdda1709de6c1a81fR239

thx to LOS for this addition
https://github.com/LineageOS/android_frameworks_base/commit/e0aaa4f379d000806fb53f352254464781a50ab0#diff-b2975104e4e1fa1d09aae3e75f4de7373693bff263ebdacf6d503b670c37506cR19

Change-Id: I72214a29a44982f178875ee320b140a695e80bbe

SystemUI: hide all text from screenshot action buttons

there is no way to show 4 buttons with text
and without text it looks pretty cool so just hardcode it

Change-Id: I3f91c895256432b6560e9cc409492ebd667916ff

Former-commit-id: 63f09ea984aaa842b9dfb27ee31b4d722e578841
diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml
index edb4710..2217b5b 100644
--- a/packages/SystemUI/AndroidManifest.xml
+++ b/packages/SystemUI/AndroidManifest.xml
@@ -571,6 +571,10 @@
             </intent-filter>
         </activity-alias>
 
+        <!-- Callback for deleting screenshot notification -->
+        <receiver android:name=".screenshot.DeleteScreenshotReceiver"
+            android:exported="false" />
+
         <!-- Callback for invoking a smart action from the screenshot notification. -->
         <receiver android:name=".screenshot.SmartActionsReceiver"
                   android:exported="false"/>
diff --git a/packages/SystemUI/res/values/custom_strings.xml b/packages/SystemUI/res/values/custom_strings.xml
index 3b25063..1124ee3 100644
--- a/packages/SystemUI/res/values/custom_strings.xml
+++ b/packages/SystemUI/res/values/custom_strings.xml
@@ -58,4 +58,14 @@
     <!-- Label for area where tiles can be added to the qs panel -->
     <string name="drag_or_tap_to_add_tiles">Hold &amp; drag or tap to add tiles</string>
 
+    <!-- Label for UI element which allows deleting the screenshot [CHAR LIMIT=30] -->
+    <string name="screenshot_delete_label">Delete</string>
+    <!-- Content description indicating that tapping the element will allow deleting the screenshot [CHAR LIMIT=NONE] -->
+    <string name="screenshot_delete_description">Delete screenshot</string>
+
+    <string name="screenshot_scroll_label_empty"></string>
+    <string name="screenshot_delete_label_empty"></string>
+    <string name="screenshot_edit_label_empty"></string>
+    <string name="screenshot_share_label_empty"></string>
+    
 </resources>
diff --git a/packages/SystemUI/src/com/android/systemui/dagger/DefaultBroadcastReceiverBinder.java b/packages/SystemUI/src/com/android/systemui/dagger/DefaultBroadcastReceiverBinder.java
index 5a0eb72..93f6a1b 100644
--- a/packages/SystemUI/src/com/android/systemui/dagger/DefaultBroadcastReceiverBinder.java
+++ b/packages/SystemUI/src/com/android/systemui/dagger/DefaultBroadcastReceiverBinder.java
@@ -24,6 +24,7 @@
 import com.android.systemui.media.dialog.MediaOutputDialogReceiver;
 import com.android.systemui.people.widget.PeopleSpaceWidgetPinnedReceiver;
 import com.android.systemui.people.widget.PeopleSpaceWidgetProvider;
+import com.android.systemui.screenshot.DeleteScreenshotReceiver;
 import com.android.systemui.screenshot.SmartActionsReceiver;
 
 import dagger.Binds;
@@ -41,6 +42,15 @@
      */
     @Binds
     @IntoMap
+    @ClassKey(DeleteScreenshotReceiver.class)
+    public abstract BroadcastReceiver bindDeleteScreenshotReceiver(
+            DeleteScreenshotReceiver broadcastReceiver);
+
+    /**
+     *
+     */
+    @Binds
+    @IntoMap
     @ClassKey(SmartActionsReceiver.class)
     public abstract BroadcastReceiver bindSmartActionsReceiver(
             SmartActionsReceiver broadcastReceiver);
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ActionIntentCreator.kt b/packages/SystemUI/src/com/android/systemui/screenshot/ActionIntentCreator.kt
index 15638d3..a409fc6 100644
--- a/packages/SystemUI/src/com/android/systemui/screenshot/ActionIntentCreator.kt
+++ b/packages/SystemUI/src/com/android/systemui/screenshot/ActionIntentCreator.kt
@@ -16,6 +16,7 @@
 
 package com.android.systemui.screenshot
 
+import android.app.PendingIntent
 import android.content.ClipData
 import android.content.ClipDescription
 import android.content.ComponentName
@@ -91,6 +92,16 @@
             .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
     }
 
+    fun createDelete(rawUri: Uri, context: Context): PendingIntent {
+        return PendingIntent.getBroadcast(context, rawUri.toString().hashCode(),
+                Intent(context, DeleteScreenshotReceiver::class.java)
+                        .putExtra(SmartActionsReceiver.SCREENSHOT_URI_ID, rawUri.toString())
+                        .addFlags(Intent.FLAG_RECEIVER_FOREGROUND),
+                        (PendingIntent.FLAG_CANCEL_CURRENT
+                        or PendingIntent.FLAG_ONE_SHOT
+                        or PendingIntent.FLAG_IMMUTABLE))
+    }
+
     /** @return an Intent to start the LongScreenshotActivity */
     fun createLongScreenshotIntent(owner: UserHandle, context: Context): Intent {
         return Intent(context, LongScreenshotActivity::class.java)
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/DeleteScreenshotReceiver.java b/packages/SystemUI/src/com/android/systemui/screenshot/DeleteScreenshotReceiver.java
new file mode 100644
index 0000000..e556e4e
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/screenshot/DeleteScreenshotReceiver.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.screenshot;
+
+import static com.android.systemui.screenshot.SmartActionsReceiver.ACTION_TYPE_DELETE;
+import static com.android.systemui.screenshot.SmartActionsReceiver.EXTRA_ID;
+import static com.android.systemui.screenshot.SmartActionsReceiver.EXTRA_SMART_ACTIONS_ENABLED;
+import static com.android.systemui.screenshot.SmartActionsReceiver.SCREENSHOT_URI_ID;
+
+import android.content.BroadcastReceiver;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
+
+import com.android.systemui.dagger.qualifiers.Background;
+
+import java.util.concurrent.Executor;
+
+import javax.inject.Inject;
+
+/**
+ * Removes the file at a provided URI.
+ */
+public class DeleteScreenshotReceiver extends BroadcastReceiver {
+
+    private final ScreenshotSmartActions mScreenshotSmartActions;
+    private final Executor mBackgroundExecutor;
+
+    @Inject
+    public DeleteScreenshotReceiver(ScreenshotSmartActions screenshotSmartActions,
+            @Background Executor backgroundExecutor) {
+        mScreenshotSmartActions = screenshotSmartActions;
+        mBackgroundExecutor = backgroundExecutor;
+    }
+
+    @Override
+    public void onReceive(Context context, Intent intent) {
+        if (!intent.hasExtra(SCREENSHOT_URI_ID)) {
+            return;
+        }
+
+        // And delete the image from the media store
+        final Uri uri = Uri.parse(intent.getStringExtra(SCREENSHOT_URI_ID));
+        mBackgroundExecutor.execute(() -> {
+            ContentResolver resolver = context.getContentResolver();
+            resolver.delete(uri, null, null);
+        });
+        if (intent.getBooleanExtra(EXTRA_SMART_ACTIONS_ENABLED, false)) {
+            mScreenshotSmartActions.notifyScreenshotAction(
+                    intent.getStringExtra(EXTRA_ID), ACTION_TYPE_DELETE, false, null);
+        }
+    }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotActionsProvider.kt b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotActionsProvider.kt
index c216f1d..3b088ca 100644
--- a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotActionsProvider.kt
+++ b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotActionsProvider.kt
@@ -23,8 +23,10 @@
 import com.android.internal.logging.UiEventLogger
 import com.android.systemui.log.DebugLogger.debugLog
 import com.android.systemui.res.R
+import com.android.systemui.screenshot.ActionIntentCreator.createDelete
 import com.android.systemui.screenshot.ActionIntentCreator.createEdit
 import com.android.systemui.screenshot.ActionIntentCreator.createShareWithSubject
+import com.android.systemui.screenshot.ScreenshotEvent.SCREENSHOT_DELETE_TAPPED
 import com.android.systemui.screenshot.ScreenshotEvent.SCREENSHOT_EDIT_TAPPED
 import com.android.systemui.screenshot.ScreenshotEvent.SCREENSHOT_PREVIEW_TAPPED
 import com.android.systemui.screenshot.ScreenshotEvent.SCREENSHOT_SHARE_TAPPED
@@ -95,7 +97,7 @@
         actionsCallback.provideActionButton(
             ActionButtonAppearance(
                 AppCompatResources.getDrawable(context, R.drawable.ic_screenshot_share),
-                context.resources.getString(R.string.screenshot_share_label),
+                context.resources.getString(R.string.screenshot_share_label_empty),
                 context.resources.getString(R.string.screenshot_share_description),
             ),
             showDuringEntrance = true,
@@ -114,7 +116,7 @@
         actionsCallback.provideActionButton(
             ActionButtonAppearance(
                 AppCompatResources.getDrawable(context, R.drawable.ic_screenshot_edit),
-                context.resources.getString(R.string.screenshot_edit_label),
+                context.resources.getString(R.string.screenshot_edit_label_empty),
                 context.resources.getString(R.string.screenshot_edit_description),
             ),
             showDuringEntrance = true,
@@ -129,6 +131,23 @@
                 )
             }
         }
+
+        actionsCallback.provideActionButton(
+            ActionButtonAppearance(
+                AppCompatResources.getDrawable(context, R.drawable.ic_screenshot_delete),
+                context.resources.getString(R.string.screenshot_delete_label_empty),
+                context.resources.getString(R.string.screenshot_delete_description),
+            ),
+            showDuringEntrance = true,
+        ) {
+            debugLog(LogConfig.DEBUG_ACTIONS) { "Delete tapped" }
+            uiEventLogger.log(SCREENSHOT_DELETE_TAPPED, 0, request.packageNameString)
+            onDeferrableActionTapped { result ->
+                actionExecutor.sendPendingIntent(
+                    createDelete(result.uri, context)
+                )
+            }
+        }
     }
 
     override fun onScrollChipReady(onClick: Runnable) {
@@ -137,7 +156,7 @@
             actionsCallback.provideActionButton(
                 ActionButtonAppearance(
                     AppCompatResources.getDrawable(context, R.drawable.ic_screenshot_scroll),
-                    context.resources.getString(R.string.screenshot_scroll_label),
+                    context.resources.getString(R.string.screenshot_scroll_label_empty),
                     context.resources.getString(R.string.screenshot_scroll_label),
                 ),
                 showDuringEntrance = true,
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotEvent.java b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotEvent.java
index 7a62bae..ce1acd6 100644
--- a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotEvent.java
+++ b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotEvent.java
@@ -54,6 +54,8 @@
     SCREENSHOT_EDIT_TAPPED(308),
     @UiEvent(doc = "screenshot share button tapped")
     SCREENSHOT_SHARE_TAPPED(309),
+    @UiEvent(doc = "screenshot delete button tapped")
+    SCREENSHOT_DELETE_TAPPED(369),
     @UiEvent(doc = "screenshot smart action chip tapped")
     SCREENSHOT_SMART_ACTION_TAPPED(374),
     @UiEvent(doc = "screenshot scroll tapped")
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/SmartActionsReceiver.java b/packages/SystemUI/src/com/android/systemui/screenshot/SmartActionsReceiver.java
index f902693..0153022 100644
--- a/packages/SystemUI/src/com/android/systemui/screenshot/SmartActionsReceiver.java
+++ b/packages/SystemUI/src/com/android/systemui/screenshot/SmartActionsReceiver.java
@@ -34,6 +34,7 @@
     private static final String TAG = "SmartActionsReceiver";
     // These strings are used for communicating the action invoked to
     // ScreenshotNotificationSmartActionsProvider.
+    public static final String ACTION_TYPE_DELETE = "Delete";
     public static final String EXTRA_ACTION_TYPE = "android:screenshot_action_type";
     public static final String EXTRA_ID = "android:screenshot_id";
     public static final String EXTRA_SMART_ACTIONS_ENABLED = "android:smart_actions_enabled";
@@ -41,6 +42,7 @@
     public static final String EXTRA_ACTION_INTENT_FILLIN =
             "android:screenshot_action_intent_fillin";
 
+    static final String SCREENSHOT_URI_ID = "android:screenshot_uri_id";
 
     private final ScreenshotSmartActions mScreenshotSmartActions;