Revert "Record an issue from the Record Issue QS tile."

This reverts commit ad3f9ac5aaa607dbe9f583b4bbef78442f9d2011.

Reason for revert: https://b.corp.google.com/issues/305049544#comment21

Change-Id: I6e15175f3e134333dc899164ec897a5a403ece90
diff --git a/packages/SystemUI/Android.bp b/packages/SystemUI/Android.bp
index 34b4beea..04cb88d 100644
--- a/packages/SystemUI/Android.bp
+++ b/packages/SystemUI/Android.bp
@@ -155,7 +155,6 @@
         "jsr330",
         "lottie",
         "LowLightDreamLib",
-        "TraceurCommon",
         "motion_tool_lib",
         "notification_flags_lib",
         "PlatformComposeCore",
@@ -302,7 +301,6 @@
         "androidx.compose.material_material-icons-extended",
         "androidx.activity_activity-compose",
         "androidx.compose.animation_animation-graphics",
-        "TraceurCommon",
     ],
 }
 
diff --git a/packages/SystemUI/res/xml/fileprovider.xml b/packages/SystemUI/res/xml/fileprovider.xml
index 71cc05d..b67378e 100644
--- a/packages/SystemUI/res/xml/fileprovider.xml
+++ b/packages/SystemUI/res/xml/fileprovider.xml
@@ -19,5 +19,4 @@
     <cache-path name="leak" path="leak/"/>
     <external-path name="screenrecord" path="."/>
     <cache-path name="multi_user" path="multi_user/" />
-    <root-path name="traces" path="/data/local/traces"/>
-</paths>
+</paths>
\ No newline at end of file
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/RecordIssueTile.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/RecordIssueTile.kt
index bd66843..20f3c4d 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/RecordIssueTile.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/RecordIssueTile.kt
@@ -103,27 +103,14 @@
     public override fun handleClick(view: View?) {
         if (isRecording) {
             isRecording = false
-            stopIssueRecordingService()
+            stopScreenRecord()
         } else {
             mUiHandler.post { showPrompt(view) }
         }
         refreshState()
     }
 
-    private fun startIssueRecordingService(screenRecord: Boolean, winscopeTracing: Boolean) =
-        PendingIntent.getForegroundService(
-                userContextProvider.userContext,
-                RecordingService.REQUEST_CODE,
-                IssueRecordingService.getStartIntent(
-                    userContextProvider.userContext,
-                    screenRecord,
-                    winscopeTracing
-                ),
-                PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
-            )
-            .send(BroadcastOptions.makeBasic().apply { isInteractive = true }.toBundle())
-
-    private fun stopIssueRecordingService() =
+    private fun stopScreenRecord() =
         PendingIntent.getService(
                 userContextProvider.userContext,
                 RecordingService.REQUEST_CODE,
@@ -137,7 +124,6 @@
             delegateFactory
                 .create {
                     isRecording = true
-                    startIssueRecordingService(it.screenRecord, it.winscopeTracing)
                     refreshState()
                 }
                 .createDialog()
diff --git a/packages/SystemUI/src/com/android/systemui/recordissue/IssueRecordingConfig.kt b/packages/SystemUI/src/com/android/systemui/recordissue/IssueRecordingConfig.kt
deleted file mode 100644
index bb3b654..0000000
--- a/packages/SystemUI/src/com/android/systemui/recordissue/IssueRecordingConfig.kt
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * Copyright (C) 2024 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.recordissue
-
-data class IssueRecordingConfig(val screenRecord: Boolean, val winscopeTracing: Boolean)
diff --git a/packages/SystemUI/src/com/android/systemui/recordissue/IssueRecordingService.kt b/packages/SystemUI/src/com/android/systemui/recordissue/IssueRecordingService.kt
index 55d7f8e..f487258 100644
--- a/packages/SystemUI/src/com/android/systemui/recordissue/IssueRecordingService.kt
+++ b/packages/SystemUI/src/com/android/systemui/recordissue/IssueRecordingService.kt
@@ -20,9 +20,7 @@
 import android.content.Context
 import android.content.Intent
 import android.content.res.Resources
-import android.net.Uri
 import android.os.Handler
-import android.os.UserHandle
 import com.android.internal.logging.UiEventLogger
 import com.android.systemui.dagger.qualifiers.LongRunning
 import com.android.systemui.dagger.qualifiers.Main
@@ -32,8 +30,6 @@
 import com.android.systemui.screenrecord.RecordingServiceStrings
 import com.android.systemui.settings.UserContextProvider
 import com.android.systemui.statusbar.phone.KeyguardDismissUtil
-import com.android.traceur.FileSender
-import com.android.traceur.TraceUtils
 import java.util.concurrent.Executor
 import javax.inject.Inject
 
@@ -64,89 +60,9 @@
 
     override fun provideRecordingServiceStrings(): RecordingServiceStrings = IrsStrings(resources)
 
-    override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
-        when (intent?.action) {
-            ACTION_START -> {
-                TraceUtils.traceStart(
-                    contentResolver,
-                    DEFAULT_TRACE_TAGS,
-                    DEFAULT_BUFFER_SIZE,
-                    DEFAULT_IS_INCLUDING_WINSCOPE,
-                    DEFAULT_IS_INCLUDING_APP_TRACE,
-                    DEFAULT_IS_LONG_TRACE,
-                    DEFAULT_ATTACH_TO_BUGREPORT,
-                    DEFAULT_MAX_TRACE_SIZE,
-                    DEFAULT_MAX_TRACE_DURATION_IN_MINUTES
-                )
-                if (!intent.getBooleanExtra(EXTRA_SCREEN_RECORD, false)) {
-                    // If we don't want to record the screen, the ACTION_SHOW_START_NOTIF action
-                    // will circumvent the RecordingService's screen recording start code.
-                    return super.onStartCommand(Intent(ACTION_SHOW_START_NOTIF), flags, startId)
-                }
-            }
-            ACTION_STOP,
-            ACTION_STOP_NOTIF -> {
-                TraceUtils.traceStop(contentResolver)
-            }
-            ACTION_SHARE -> {
-                shareRecording(intent)
-
-                // Unlike all other actions, action_share has different behavior for the screen
-                // recording qs tile than it does for the record issue qs tile. Return sticky to
-                // avoid running any of the base class' code for this action.
-                return START_STICKY
-            }
-            else -> {}
-        }
-        return super.onStartCommand(intent, flags, startId)
-    }
-
-    private fun shareRecording(intent: Intent) {
-        val files = TraceUtils.traceDump(contentResolver, TRACE_FILE_NAME).get()
-        val traceUris: MutableList<Uri> = FileSender.getUriForFiles(this, files, AUTHORITY)
-
-        if (
-            intent.hasExtra(EXTRA_PATH) && intent.getStringExtra(EXTRA_PATH)?.isNotEmpty() == true
-        ) {
-            traceUris.add(Uri.parse(intent.getStringExtra(EXTRA_PATH)))
-        }
-
-        val sendIntent =
-            FileSender.buildSendIntent(this, traceUris).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
-
-        if (mNotificationId != NOTIF_BASE_ID) {
-            val currentUserId = mUserContextTracker.userContext.userId
-            mNotificationManager.cancelAsUser(null, mNotificationId, UserHandle(currentUserId))
-        }
-
-        // TODO: Debug why the notification shade isn't closing upon starting the BetterBug activity
-        mKeyguardDismissUtil.executeWhenUnlocked(
-            {
-                startActivity(sendIntent)
-                false
-            },
-            false,
-            false
-        )
-    }
-
     companion object {
         private const val TAG = "IssueRecordingService"
         private const val CHANNEL_ID = "issue_record"
-        private const val EXTRA_SCREEN_RECORD = "extra_screenRecord"
-        private const val EXTRA_WINSCOPE_TRACING = "extra_winscopeTracing"
-
-        private val DEFAULT_TRACE_TAGS = listOf<String>()
-        private const val DEFAULT_BUFFER_SIZE = 16384
-        private const val DEFAULT_IS_INCLUDING_WINSCOPE = true
-        private const val DEFAULT_IS_LONG_TRACE = false
-        private const val DEFAULT_IS_INCLUDING_APP_TRACE = true
-        private const val DEFAULT_ATTACH_TO_BUGREPORT = true
-        private const val DEFAULT_MAX_TRACE_SIZE = 10240
-        private const val DEFAULT_MAX_TRACE_DURATION_IN_MINUTES = 30
-
-        private val TRACE_FILE_NAME = TraceUtils.getOutputFilename(TraceUtils.RecordingType.TRACE)
-        private const val AUTHORITY = "com.android.systemui.fileprovider"
 
         /**
          * Get an intent to stop the issue recording service.
@@ -155,7 +71,7 @@
          * @return
          */
         fun getStopIntent(context: Context): Intent =
-            Intent(context, IssueRecordingService::class.java)
+            Intent(context, RecordingService::class.java)
                 .setAction(ACTION_STOP)
                 .putExtra(Intent.EXTRA_USER_HANDLE, context.userId)
 
@@ -164,15 +80,8 @@
          *
          * @param context Context from the requesting activity
          */
-        fun getStartIntent(
-            context: Context,
-            screenRecord: Boolean,
-            winscopeTracing: Boolean
-        ): Intent =
-            Intent(context, IssueRecordingService::class.java)
-                .setAction(ACTION_START)
-                .putExtra(EXTRA_SCREEN_RECORD, screenRecord)
-                .putExtra(EXTRA_WINSCOPE_TRACING, winscopeTracing)
+        fun getStartIntent(context: Context): Intent =
+            Intent(context, RecordingService::class.java).setAction(ACTION_START)
     }
 }
 
diff --git a/packages/SystemUI/src/com/android/systemui/recordissue/RecordIssueDialogDelegate.kt b/packages/SystemUI/src/com/android/systemui/recordissue/RecordIssueDialogDelegate.kt
index ff18a11..1c07d00 100644
--- a/packages/SystemUI/src/com/android/systemui/recordissue/RecordIssueDialogDelegate.kt
+++ b/packages/SystemUI/src/com/android/systemui/recordissue/RecordIssueDialogDelegate.kt
@@ -17,6 +17,8 @@
 package com.android.systemui.recordissue
 
 import android.annotation.SuppressLint
+import android.app.BroadcastOptions
+import android.app.PendingIntent
 import android.content.Context
 import android.content.res.ColorStateList
 import android.graphics.Color
@@ -41,6 +43,8 @@
 import com.android.systemui.mediaprojection.devicepolicy.ScreenCaptureDisabledDialogDelegate
 import com.android.systemui.qs.tiles.RecordIssueTile
 import com.android.systemui.res.R
+import com.android.systemui.screenrecord.RecordingService
+import com.android.systemui.settings.UserContextProvider
 import com.android.systemui.settings.UserFileManager
 import com.android.systemui.settings.UserTracker
 import com.android.systemui.statusbar.phone.SystemUIDialog
@@ -48,12 +52,12 @@
 import dagger.assisted.AssistedFactory
 import dagger.assisted.AssistedInject
 import java.util.concurrent.Executor
-import java.util.function.Consumer
 
 class RecordIssueDialogDelegate
 @AssistedInject
 constructor(
     private val factory: SystemUIDialog.Factory,
+    private val userContextProvider: UserContextProvider,
     private val userTracker: UserTracker,
     private val flags: FeatureFlagsClassic,
     @Background private val bgExecutor: Executor,
@@ -62,14 +66,14 @@
     private val mediaProjectionMetricsLogger: MediaProjectionMetricsLogger,
     private val userFileManager: UserFileManager,
     private val screenCaptureDisabledDialogDelegate: ScreenCaptureDisabledDialogDelegate,
-    @Assisted private val onStarted: Consumer<IssueRecordingConfig>,
+    @Assisted private val onStarted: Runnable,
 ) : SystemUIDialog.Delegate {
 
     /** To inject dependencies and allow for easier testing */
     @AssistedFactory
     interface Factory {
         /** Create a dialog object */
-        fun create(onStarted: Consumer<IssueRecordingConfig>): RecordIssueDialogDelegate
+        fun create(onStarted: Runnable): RecordIssueDialogDelegate
     }
 
     @SuppressLint("UseSwitchCompatOrMaterialCode") private lateinit var screenRecordSwitch: Switch
@@ -83,12 +87,10 @@
             setIcon(R.drawable.qs_record_issue_icon_off)
             setNegativeButton(R.string.cancel) { _, _ -> dismiss() }
             setPositiveButton(R.string.qs_record_issue_start) { _, _ ->
-                onStarted.accept(
-                    IssueRecordingConfig(
-                        screenRecordSwitch.isChecked,
-                        true /* TODO: Base this on issueType selected */
-                    )
-                )
+                onStarted.run()
+                if (screenRecordSwitch.isChecked) {
+                    requestScreenCapture()
+                }
                 dismiss()
             }
         }
@@ -175,4 +177,13 @@
             show()
         }
     }
+
+    private fun requestScreenCapture() =
+        PendingIntent.getForegroundService(
+                userContextProvider.userContext,
+                RecordingService.REQUEST_CODE,
+                IssueRecordingService.getStartIntent(userContextProvider.userContext),
+                PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
+            )
+            .send(BroadcastOptions.makeBasic().apply { isInteractive = true }.toBundle())
 }
diff --git a/packages/SystemUI/src/com/android/systemui/screenrecord/RecordingService.java b/packages/SystemUI/src/com/android/systemui/screenrecord/RecordingService.java
index ac94f39..b355d2d 100644
--- a/packages/SystemUI/src/com/android/systemui/screenrecord/RecordingService.java
+++ b/packages/SystemUI/src/com/android/systemui/screenrecord/RecordingService.java
@@ -60,27 +60,25 @@
     public static final int REQUEST_CODE = 2;
 
     private static final int USER_ID_NOT_SPECIFIED = -1;
-    protected static final int NOTIF_BASE_ID = 4273;
+    private static final int NOTIF_BASE_ID = 4273;
     private static final String TAG = "RecordingService";
     private static final String CHANNEL_ID = "screen_record";
     private static final String GROUP_KEY = "screen_record_saved";
     private static final String EXTRA_RESULT_CODE = "extra_resultCode";
-    protected static final String EXTRA_PATH = "extra_path";
+    private static final String EXTRA_PATH = "extra_path";
     private static final String EXTRA_AUDIO_SOURCE = "extra_useAudio";
     private static final String EXTRA_SHOW_TAPS = "extra_showTaps";
     private static final String EXTRA_CAPTURE_TARGET = "extra_captureTarget";
 
     protected static final String ACTION_START = "com.android.systemui.screenrecord.START";
-    protected static final String ACTION_SHOW_START_NOTIF =
-            "com.android.systemui.screenrecord.START_NOTIF";
     protected static final String ACTION_STOP = "com.android.systemui.screenrecord.STOP";
-    protected static final String ACTION_STOP_NOTIF =
+    private static final String ACTION_STOP_NOTIF =
             "com.android.systemui.screenrecord.STOP_FROM_NOTIF";
-    protected static final String ACTION_SHARE = "com.android.systemui.screenrecord.SHARE";
+    private static final String ACTION_SHARE = "com.android.systemui.screenrecord.SHARE";
     private static final String PERMISSION_SELF = "com.android.systemui.permission.SELF";
 
     private final RecordingController mController;
-    protected final KeyguardDismissUtil mKeyguardDismissUtil;
+    private final KeyguardDismissUtil mKeyguardDismissUtil;
     private final Handler mMainHandler;
     private ScreenRecordingAudioSource mAudioSource;
     private boolean mShowTaps;
@@ -88,9 +86,9 @@
     private ScreenMediaRecorder mRecorder;
     private final Executor mLongExecutor;
     private final UiEventLogger mUiEventLogger;
-    protected final NotificationManager mNotificationManager;
-    protected final UserContextProvider mUserContextTracker;
-    protected int mNotificationId = NOTIF_BASE_ID;
+    private final NotificationManager mNotificationManager;
+    private final UserContextProvider mUserContextTracker;
+    private int mNotificationId = NOTIF_BASE_ID;
     private RecordingServiceStrings mStrings;
 
     @Inject
@@ -187,10 +185,7 @@
                     return Service.START_NOT_STICKY;
                 }
                 break;
-            case ACTION_SHOW_START_NOTIF:
-                createRecordingNotification();
-                mUiEventLogger.log(Events.ScreenRecordEvent.SCREEN_RECORD_START);
-                break;
+
             case ACTION_STOP_NOTIF:
             case ACTION_STOP:
                 // only difference for actions is the log event
@@ -237,7 +232,6 @@
         super.onCreate();
     }
 
-    @Nullable
     @VisibleForTesting
     protected ScreenMediaRecorder getRecorder() {
         return mRecorder;
@@ -343,9 +337,8 @@
     }
 
     @VisibleForTesting
-    protected Notification createSaveNotification(
-            @Nullable ScreenMediaRecorder.SavedRecording recording) {
-        Uri uri = recording != null ? recording.getUri() : null;
+    protected Notification createSaveNotification(ScreenMediaRecorder.SavedRecording recording) {
+        Uri uri = recording.getUri();
         Intent viewIntent = new Intent(Intent.ACTION_VIEW)
                 .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION)
                 .setDataAndType(uri, "video/mp4");
@@ -356,7 +349,7 @@
                 PendingIntent.getService(
                         this,
                         REQUEST_CODE,
-                        getShareIntent(this, uri != null ? uri.toString() : null),
+                        getShareIntent(this, uri.toString()),
                         PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE))
                 .build();
 
@@ -378,10 +371,9 @@
                 .addExtras(extras);
 
         // Add thumbnail if available
-        Icon thumbnail = recording != null ? recording.getThumbnail() : null;
-        if (thumbnail != null) {
+        if (recording.getThumbnail() != null) {
             Notification.BigPictureStyle pictureStyle = new Notification.BigPictureStyle()
-                    .bigPicture(thumbnail)
+                    .bigPicture(recording.getThumbnail())
                     .showBigPictureWhenCollapsed(true);
             builder.setStyle(pictureStyle);
         }
@@ -416,29 +408,27 @@
         }
         Log.d(getTag(), "notifying for user " + userId);
         setTapsVisible(mOriginalShowTaps);
-        try {
-            if (getRecorder() != null) {
+        if (getRecorder() != null) {
+            try {
                 getRecorder().end();
-            }
-            saveRecording(userId);
-        } catch (RuntimeException exception) {
-            if (getRecorder() != null) {
+                saveRecording(userId);
+            } catch (RuntimeException exception) {
                 // RuntimeException could happen if the recording stopped immediately after starting
                 // let's release the recorder and delete all temporary files in this case
                 getRecorder().release();
-            }
-            showErrorToast(R.string.screenrecord_start_error);
-            Log.e(getTag(), "stopRecording called, but there was an error when ending"
-                    + "recording");
-            exception.printStackTrace();
-            createErrorNotification();
-        } catch (Throwable throwable) {
-            if (getRecorder() != null) {
+                showErrorToast(R.string.screenrecord_start_error);
+                Log.e(getTag(), "stopRecording called, but there was an error when ending"
+                        + "recording");
+                exception.printStackTrace();
+                createErrorNotification();
+            } catch (Throwable throwable) {
                 // Something unexpected happen, SystemUI will crash but let's delete
                 // the temporary files anyway
                 getRecorder().release();
+                throw new RuntimeException(throwable);
             }
-            throw new RuntimeException(throwable);
+        } else {
+            Log.e(getTag(), "stopRecording called, but recorder was null");
         }
         updateState(false);
         stopForeground(STOP_FOREGROUND_DETACH);
@@ -453,8 +443,7 @@
         mLongExecutor.execute(() -> {
             try {
                 Log.d(getTag(), "saving recording");
-                Notification notification = createSaveNotification(
-                        getRecorder() != null ? getRecorder().save() : null);
+                Notification notification = createSaveNotification(getRecorder().save());
                 postGroupNotification(currentUser);
                 mNotificationManager.notifyAsUser(null, mNotificationId,  notification,
                         currentUser);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/recordissue/RecordIssueDialogDelegateTest.kt b/packages/SystemUI/tests/src/com/android/systemui/recordissue/RecordIssueDialogDelegateTest.kt
index 2e8160b..ada93db 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/recordissue/RecordIssueDialogDelegateTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/recordissue/RecordIssueDialogDelegateTest.kt
@@ -37,6 +37,7 @@
 import com.android.systemui.model.SysUiState
 import com.android.systemui.qs.tiles.RecordIssueTile
 import com.android.systemui.res.R
+import com.android.systemui.settings.UserContextProvider
 import com.android.systemui.settings.UserFileManager
 import com.android.systemui.settings.UserTracker
 import com.android.systemui.statusbar.phone.SystemUIDialog
@@ -70,11 +71,12 @@
     @Mock private lateinit var devicePolicyResolver: ScreenCaptureDevicePolicyResolver
     @Mock private lateinit var dprLazy: dagger.Lazy<ScreenCaptureDevicePolicyResolver>
     @Mock private lateinit var mediaProjectionMetricsLogger: MediaProjectionMetricsLogger
+    @Mock private lateinit var userContextProvider: UserContextProvider
     @Mock private lateinit var userTracker: UserTracker
     @Mock private lateinit var userFileManager: UserFileManager
     @Mock private lateinit var sharedPreferences: SharedPreferences
-    @Mock
-    private lateinit var screenCaptureDisabledDialogDelegate: ScreenCaptureDisabledDialogDelegate
+    @Mock private lateinit var screenCaptureDisabledDialogDelegate:
+            ScreenCaptureDisabledDialogDelegate
     @Mock private lateinit var screenCaptureDisabledDialog: SystemUIDialog
 
     @Mock private lateinit var sysuiState: SysUiState
@@ -94,8 +96,9 @@
         MockitoAnnotations.initMocks(this)
         whenever(dprLazy.get()).thenReturn(devicePolicyResolver)
         whenever(sysuiState.setFlag(anyInt(), anyBoolean())).thenReturn(sysuiState)
+        whenever(userContextProvider.userContext).thenReturn(mContext)
         whenever(screenCaptureDisabledDialogDelegate.createDialog())
-            .thenReturn(screenCaptureDisabledDialog)
+                .thenReturn(screenCaptureDisabledDialog)
         whenever(
                 userFileManager.getSharedPreferences(
                     eq(RecordIssueTile.TILE_SPEC),
@@ -120,6 +123,7 @@
         dialog =
             RecordIssueDialogDelegate(
                     factory,
+                    userContextProvider,
                     userTracker,
                     flags,
                     bgExecutor,