Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 50091d0b authored by Oluwarotimi Adesina's avatar Oluwarotimi Adesina Committed by Robin Lee
Browse files

Support excluding persistent UI

BUG: 333312675
Test: manual

Change-Id: Ibcd504ee471fcd6328bae51111bd362ebcf90eae
parent 81b273a7
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -87,6 +87,7 @@ aconfig_declarations_group {
        "com.android.media.flags.performance-aconfig-java",
        "com.android.media.flags.projection-aconfig-java",
        "com.android.net.thread.platform.flags-aconfig-java",
        "com.android.server.contextualsearch.flags-java",
        "com.android.server.flags.services-aconfig-java",
        "com.android.text.flags-aconfig-java",
        "com.android.window.flags.window-aconfig-java",
@@ -801,6 +802,19 @@ java_aconfig_library {
    defaults: ["framework-minus-apex-aconfig-java-defaults"],
}

// Contextual Search system service
aconfig_declarations {
    name: "com.android.server.contextualsearch.flags-aconfig",
    package: "com.android.server.contextualsearch.flags",
    srcs: ["services/contextualsearch/flags/flags.aconfig"],
}

java_aconfig_library {
    name: "com.android.server.contextualsearch.flags-java",
    aconfig_declarations: "com.android.server.contextualsearch.flags-aconfig",
    defaults: ["framework-minus-apex-aconfig-java-defaults"],
}

// Server Services Flags
aconfig_declarations {
    name: "com.android.server.flags.services-aconfig",
+10 −0
Original line number Diff line number Diff line
package: "com.android.server.contextualsearch.flags"
container: "system"

flag {
    name: "enable_exclude_persistent_ui"
    namespace: "machine_learning"
    description: "Excluding persistent UI from contextual search screenshot."
    is_fixed_read_only: true
    bug: "333312675"
}
 No newline at end of file
+13 −1
Original line number Diff line number Diff line
@@ -23,6 +23,11 @@ import static android.content.Intent.FLAG_ACTIVITY_NO_ANIMATION;
import static android.content.Intent.FLAG_ACTIVITY_NO_USER_ACTION;
import static android.content.pm.PackageManager.MATCH_FACTORY_ONLY;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR;
import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL;
import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;

import static com.android.server.contextualsearch.flags.Flags.enableExcludePersistentUi;

import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -66,6 +71,7 @@ import java.io.FileDescriptor;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;

public class ContextualSearchManagerService extends SystemService {

@@ -192,7 +198,13 @@ public class ContextualSearchManagerService extends SystemService {
        }
        final ScreenCapture.ScreenshotHardwareBuffer shb;
        if (mWmInternal != null) {
            shb = mWmInternal.takeAssistScreenshot();
            if (enableExcludePersistentUi()) {
                shb = mWmInternal.takeAssistScreenshot(
                        Set.of(TYPE_STATUS_BAR, TYPE_NAVIGATION_BAR, TYPE_NAVIGATION_BAR_PANEL));
            } else {
                shb = mWmInternal.takeAssistScreenshot(/* windowTypesToExclude= */ Set.of());
            }

        } else {
            shb = null;
        }
+19 −3
Original line number Diff line number Diff line
@@ -246,6 +246,7 @@ import android.view.inputmethod.ImeTracker;
import android.window.DisplayWindowPolicyController;
import android.window.IDisplayAreaOrganizer;
import android.window.ScreenCapture;
import android.window.ScreenCapture.LayerCaptureArgs;
import android.window.SystemPerformanceHinter;
import android.window.TransitionRequestInfo;

@@ -5232,7 +5233,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
    /**
     * Creates a LayerCaptureArgs object to represent the entire DisplayContent
     */
    ScreenCapture.LayerCaptureArgs getLayerCaptureArgs() {
    LayerCaptureArgs getLayerCaptureArgs(Set<Integer> windowTypesToExclude) {
        if (!mWmService.mPolicy.isScreenOn()) {
            if (DEBUG_SCREENSHOT) {
                Slog.i(TAG_WM, "Attempted to take screenshot while display was off.");
@@ -5242,8 +5243,23 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp

        getBounds(mTmpRect);
        mTmpRect.offsetTo(0, 0);
        return new ScreenCapture.LayerCaptureArgs.Builder(getSurfaceControl())
                .setSourceCrop(mTmpRect).build();
        LayerCaptureArgs.Builder builder = new LayerCaptureArgs.Builder(getSurfaceControl())
                .setSourceCrop(mTmpRect);

        if (!windowTypesToExclude.isEmpty()) {
            ArrayList<SurfaceControl> surfaceControls = new ArrayList<>();
            forAllWindows(
                    window -> {
                        if (windowTypesToExclude.contains(window.getWindowType())) {
                            surfaceControls.add(window.mSurfaceControl);
                        }
                    }, true
            );
            if (!surfaceControls.isEmpty()) {
                builder.setExcludeLayers(surfaceControls.toArray(new SurfaceControl[0]));
            }
        }
        return builder.build();
    }

    @Override
+4 −2
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ import android.view.WindowInfo;
import android.view.WindowManager.DisplayImePolicy;
import android.view.inputmethod.ImeTracker;
import android.window.ScreenCapture;
import android.window.ScreenCapture.ScreenshotHardwareBuffer;

import com.android.internal.policy.KeyInterceptionInfo;
import com.android.server.input.InputManagerService;
@@ -1073,8 +1074,9 @@ public abstract class WindowManagerInternal {
    public abstract boolean moveFocusToAdjacentEmbeddedActivityIfNeeded();

    /**
     * Returns an instance of {@link ScreenCapture.ScreenshotHardwareBuffer} containing the current
     * Returns an instance of {@link ScreenshotHardwareBuffer} containing the current
     * screenshot.
     */
    public abstract ScreenCapture.ScreenshotHardwareBuffer takeAssistScreenshot();
    public abstract ScreenshotHardwareBuffer takeAssistScreenshot(
            Set<Integer> windowTypesToExclude);
}
Loading