Snap for 11975806 from d6608db204f14e5815cc0b755feabcd2bc5292eb to 24Q3-release

Change-Id: Iaf3bc0fa300f42d21f4694aded2d56e2af249201
diff --git a/framework/java/android/os/ProfilingManager.java b/framework/java/android/os/ProfilingManager.java
index 41b9d9e..011738f 100644
--- a/framework/java/android/os/ProfilingManager.java
+++ b/framework/java/android/os/ProfilingManager.java
@@ -147,16 +147,33 @@
     /**
      * Request system profiling.
      *
-     * <p class="note"> Note: use of this API directly is not recommended for most use cases.
-     * Please use the higher level wrappers provided by androidx that will construct the request
-     * correctly based on available options and simplified user provided request parameters.</p>
+     * <p class="note">
+     *   Note: use of this API directly is not recommended for most use cases.
+     *   Consider using the higher level wrappers provided by AndroidX that will construct the
+     *   request correctly, supporting available options with simplified request parameters
+     * </p>
      *
-     * <p class="note"> Note: requests are not guaranteed to be filled.</p>
+     * <p>
+     *   Both a listener and an executor must be set at the time of the request for the request to
+     *   be considered for fulfillment. Listener/executor pairs can be set in this method, with
+     *   {@link registerForAllProfilingResults}, or both. The listener and executor must be set
+     *   together, in the same call. If no listener and executor combination is set, the request
+     *   will be discarded and no callback will be received.
+     * </p>
      *
-     * <p class="note"> Note: Both a listener and executor must be set for the request to be
-     * considered for fulfillment.
-     * Listeners can be set in this method, with {@link #registerForAllProfilingResults}, or both.
-     * If no listener and executor is set the request will be discarded.</p>
+     * <p>
+     *   Requests will be rate limited and are not guaranteed to be filled.
+     * </p>
+     *
+     * <p>
+     *   There might be a delay before profiling begins.
+     *   For continuous profiling types (system tracing, stack sampling, and heap profiling),
+     *   we recommend starting the collection early and stopping it with {@link cancellationSignal}
+     *   immediately after the area of interest to ensure that the section you want profiled is
+     *   captured.
+     *   For heap dumps, we recommend testing locally to ensure that the heap dump is collected at
+     *   the proper time.
+     * </p>
      *
      * @param profilingType Type of profiling to collect.
      * @param parameters Bundle of request related parameters. If the bundle contains any
diff --git a/service/java/com/android/os/profiling/Configs.java b/service/java/com/android/os/profiling/Configs.java
index 782cbd2..bbc6f77 100644
--- a/service/java/com/android/os/profiling/Configs.java
+++ b/service/java/com/android/os/profiling/Configs.java
@@ -417,10 +417,6 @@
                 // This should be unnecessary, but make sure configs are initialized just in case.
                 initializeSystemTraceConfigsIfNecessary();
 
-                if (!Flags.redactionEnabled()) {
-                    throw new IllegalArgumentException("Trace is not currently supported");
-                }
-
                 if (sKillswitchSystemTrace) {
                     throw new IllegalArgumentException("System trace is disabled");
                 }
diff --git a/service/java/com/android/os/profiling/ProfilingService.java b/service/java/com/android/os/profiling/ProfilingService.java
index 4863472..b21181f 100644
--- a/service/java/com/android/os/profiling/ProfilingService.java
+++ b/service/java/com/android/os/profiling/ProfilingService.java
@@ -1132,11 +1132,12 @@
     private void handleRedactionComplete(TracingSession session) {
         int redactionErrorCode = session.getActiveRedaction().exitValue();
         if (redactionErrorCode != 0) {
-            // Redaction process failed.
+            // Redaction process failed. This failure cannot be recovered.
             if (DEBUG) {
                 Log.d(TAG, String.format("Redaction processed failed with error code: %s",
                         redactionErrorCode));
             }
+            cleanupTracingSession(session);
             processResultCallback(session, ProfilingResult.ERROR_FAILED_POST_PROCESSING, null);
             return;
         }