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

Commit 43e83c81 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 10314561 from 29668d51 to udc-release

Change-Id: Id4ec6903e1e314f4d62012560fc7e63e718eb836
parents 9ca9b1af 29668d51
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -39,7 +39,6 @@ import android.os.ServiceManager;
import android.os.UserHandle;
import android.permission.IPermissionManager;
import android.util.Log;
import android.util.Pair;
import android.view.IWindowManager;
import android.view.InputDevice;
import android.view.InputEvent;
@@ -52,7 +51,8 @@ import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.IAccessibilityManager;
import android.window.ScreenCapture;
import android.window.ScreenCapture.CaptureArgs;
import android.window.ScreenCapture.ScreenCaptureListener;
import android.window.ScreenCapture.ScreenshotHardwareBuffer;
import android.window.ScreenCapture.SynchronousScreenCaptureListener;

import libcore.io.IoUtils;

@@ -235,12 +235,12 @@ public final class UiAutomationConnection extends IUiAutomationConnection.Stub {
            final CaptureArgs captureArgs = new CaptureArgs.Builder<>()
                    .setSourceCrop(crop)
                    .build();
            Pair<ScreenCaptureListener, ScreenCapture.ScreenshotSync> syncScreenCapture =
            SynchronousScreenCaptureListener syncScreenCapture =
                    ScreenCapture.createSyncCaptureListener();
            mWindowManager.captureDisplay(DEFAULT_DISPLAY, captureArgs,
                    syncScreenCapture.first);
            final ScreenCapture.ScreenshotHardwareBuffer screenshotBuffer =
                    syncScreenCapture.second.get();
                    syncScreenCapture);
            final ScreenshotHardwareBuffer screenshotBuffer =
                    syncScreenCapture.getBuffer();
            return screenshotBuffer == null ? null : screenshotBuffer.asBitmap();
        } catch (RemoteException re) {
            re.rethrowAsRuntimeException();
+19 −65
Original line number Diff line number Diff line
@@ -913,7 +913,7 @@ public class WallpaperManager {
     *     instead the default system wallpaper is returned
     *     (some versions of T may throw a {@code SecurityException}).</li>
     *     <li>From version U, this method should not be used
     *     and will always throw a @code SecurityException}.</li>
     *     and will always throw a {@code SecurityException}.</li>
     *     <li> Apps with {@link android.Manifest.permission#MANAGE_EXTERNAL_STORAGE}
     *     can still access the real wallpaper on all versions. </li>
     * </ul>
@@ -935,18 +935,9 @@ public class WallpaperManager {
    }

    /**
     * <strong> Important note: </strong>
     * <ul>
     *     <li>Up to version S, this method requires the
     *     {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission.</li>
     *     <li>Starting in T, directly accessing the wallpaper is not possible anymore,
     *     instead the default system wallpaper is returned
     *     (some versions of T may throw a {@code SecurityException}).</li>
     *     <li>From version U, this method should not be used
     *     and will always throw a @code SecurityException}.</li>
     *     <li> Apps with {@link android.Manifest.permission#MANAGE_EXTERNAL_STORAGE}
     *     can still access the real wallpaper on all versions. </li>
     * </ul>
     * <strong> Important note: </strong> only apps with
     * {@link android.Manifest.permission#MANAGE_EXTERNAL_STORAGE} should use this method.
     * Otherwise, a {@code SecurityException} will be thrown.
     *
     * <p>
     * Retrieve the requested wallpaper for the specified wallpaper type if the wallpaper is not
@@ -1206,7 +1197,7 @@ public class WallpaperManager {
     *     instead the default system wallpaper is returned
     *     (some versions of T may throw a {@code SecurityException}).</li>
     *     <li>From version U, this method should not be used
     *     and will always throw a @code SecurityException}.</li>
     *     and will always throw a {@code SecurityException}.</li>
     *     <li> Apps with {@link android.Manifest.permission#MANAGE_EXTERNAL_STORAGE}
     *     can still access the real wallpaper on all versions. </li>
     * </ul>
@@ -1228,18 +1219,9 @@ public class WallpaperManager {
    }

    /**
     * <strong> Important note: </strong>
     * <ul>
     *     <li>Up to version S, this method requires the
     *     {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission.</li>
     *     <li>Starting in T, directly accessing the wallpaper is not possible anymore,
     *     instead the default system wallpaper is returned
     *     (some versions of T may throw a {@code SecurityException}).</li>
     *     <li>From version U, this method should not be used
     *     and will always throw a @code SecurityException}.</li>
     *     <li> Apps with {@link android.Manifest.permission#MANAGE_EXTERNAL_STORAGE}
     *     can still access the real wallpaper on all versions. </li>
     * </ul>
     * <strong> Important note: </strong> only apps with
     * {@link android.Manifest.permission#MANAGE_EXTERNAL_STORAGE} should use this method.
     * Otherwise, a {@code SecurityException} will be thrown.
     *
     * <p>
     * Equivalent to {@link #getDrawable(int)}.
@@ -1268,7 +1250,7 @@ public class WallpaperManager {
     *     instead the default wallpaper is returned
     *     (some versions of T may throw a {@code SecurityException}).</li>
     *     <li>From version U, this method should not be used
     *     and will always throw a @code SecurityException}.</li>
     *     and will always throw a {@code SecurityException}.</li>
     *     <li> Apps with {@link android.Manifest.permission#MANAGE_EXTERNAL_STORAGE}
     *     can still access the real wallpaper on all versions. </li>
     * </ul>
@@ -1290,19 +1272,9 @@ public class WallpaperManager {
    }

    /**
     * <strong> Important note: </strong>
     * <ul>
     *     <li>Up to version S, this method requires the
     *     {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission.</li>
     *     <li>Starting in T, directly accessing the wallpaper is not possible anymore,
     *     instead the default system wallpaper is returned
     *     (some versions of T may throw a {@code SecurityException}).</li>
     *     <li>From version U, this method should not be used
     *     and will always throw a @code SecurityException}.</li>
     *     <li> Apps with {@link android.Manifest.permission#MANAGE_EXTERNAL_STORAGE}
     *     can still access the real wallpaper on all versions. </li>
     * </ul>
     * <br>
     * <strong> Important note: </strong> only apps with
     * {@link android.Manifest.permission#MANAGE_EXTERNAL_STORAGE} should use this method.
     * Otherwise, a {@code SecurityException} will be thrown.
     *
     * Like {@link #getDrawable(int)}, but the returned Drawable has a number
     * of limitations to reduce its overhead as much as possible. It will
@@ -1334,18 +1306,9 @@ public class WallpaperManager {
    }

    /**
     * <strong> Important note: </strong>
     * <ul>
     *     <li>Up to version S, this method requires the
     *     {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission.</li>
     *     <li>Starting in T, directly accessing the wallpaper is not possible anymore,
     *     instead the default system wallpaper is returned
     *     (some versions of T may throw a {@code SecurityException}).</li>
     *     <li>From version U, this method should not be used
     *     and will always throw a @code SecurityException}.</li>
     *     <li> Apps with {@link android.Manifest.permission#MANAGE_EXTERNAL_STORAGE}
     *     can still access the real wallpaper on all versions. </li>
     * </ul>
     * <strong> Important note: </strong> only apps with
     * {@link android.Manifest.permission#MANAGE_EXTERNAL_STORAGE} should use this method.
     * Otherwise, a {@code SecurityException} will be thrown.
     *
     * <p>
     * Equivalent to {@link #getFastDrawable()}.
@@ -1364,18 +1327,9 @@ public class WallpaperManager {
    }

    /**
     * <strong> Important note: </strong>
     * <ul>
     *     <li>Up to version S, this method requires the
     *     {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission.</li>
     *     <li>Starting in T, directly accessing the wallpaper is not possible anymore,
     *     instead the default system wallpaper is returned
     *     (some versions of T may throw a {@code SecurityException}).</li>
     *     <li>From version U, this method should not be used
     *     and will always throw a @code SecurityException}.</li>
     *     <li> Apps with {@link android.Manifest.permission#MANAGE_EXTERNAL_STORAGE}
     *     can still access the real wallpaper on all versions. </li>
     * </ul>
     * <strong> Important note: </strong> only apps with
     * {@link android.Manifest.permission#MANAGE_EXTERNAL_STORAGE}
     * should use this method. Otherwise, a {@code SecurityException} will be thrown.
     *
     * <p>
     * Equivalent to {@link #getFastDrawable(int)}.
@@ -1562,7 +1516,7 @@ public class WallpaperManager {
     *     instead the default system wallpaper is returned
     *     (some versions of T may throw a {@code SecurityException}).</li>
     *     <li>From version U, this method should not be used
     *     and will always throw a @code SecurityException}.</li>
     *     and will always throw a {@code SecurityException}.</li>
     *     <li> Apps with {@link android.Manifest.permission#MANAGE_EXTERNAL_STORAGE}
     *     can still access the real wallpaper on all versions. </li>
     * </ul>
+7 −0
Original line number Diff line number Diff line
@@ -135,6 +135,10 @@ public final class WifiSsidPolicy implements Parcelable {
        dest.writeArraySet(mSsids);
    }

    /**
     * Two instances of WifiSsidPolicy is considered equal if they have
     * the same WifiSsidPolicyType and the same set of WifiSsids
     */
    @Override
    public boolean equals(Object thatObject) {
        if (this == thatObject) {
@@ -147,6 +151,9 @@ public final class WifiSsidPolicy implements Parcelable {
        return mPolicyType == that.mPolicyType && Objects.equals(mSsids, that.mSsids);
    }

    /**
     * Returns the hash code value of WifiSsidPolicyType and WifiSsid set
     */
    @Override
    public int hashCode() {
        return Objects.hash(mPolicyType, mSsids);
+38 −31
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ import android.os.IBinder;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;
import android.util.Pair;
import android.view.SurfaceControl;

import libcore.util.NativeAllocationRegistry;
@@ -73,14 +72,14 @@ public class ScreenCapture {
     */
    public static ScreenshotHardwareBuffer captureDisplay(
            DisplayCaptureArgs captureArgs) {
        Pair<ScreenCaptureListener, ScreenshotSync> syncScreenCapture = createSyncCaptureListener();
        int status = captureDisplay(captureArgs, syncScreenCapture.first);
        SynchronousScreenCaptureListener syncScreenCapture = createSyncCaptureListener();
        int status = captureDisplay(captureArgs, syncScreenCapture);
        if (status != 0) {
            return null;
        }

        try {
            return syncScreenCapture.second.get();
            return syncScreenCapture.getBuffer();
        } catch (Exception e) {
            return null;
        }
@@ -133,14 +132,14 @@ public class ScreenCapture {
     * @hide
     */
    public static ScreenshotHardwareBuffer captureLayers(LayerCaptureArgs captureArgs) {
        Pair<ScreenCaptureListener, ScreenshotSync> syncScreenCapture = createSyncCaptureListener();
        int status = captureLayers(captureArgs, syncScreenCapture.first);
        SynchronousScreenCaptureListener syncScreenCapture = createSyncCaptureListener();
        int status = captureLayers(captureArgs, syncScreenCapture);
        if (status != 0) {
            return null;
        }

        try {
            return syncScreenCapture.second.get();
            return syncScreenCapture.getBuffer();
        } catch (Exception e) {
            return null;
        }
@@ -743,14 +742,35 @@ public class ScreenCapture {
     * A helper method to handle the async screencapture callbacks synchronously. This should only
     * be used if the screencapture caller doesn't care that it blocks waiting for a screenshot.
     *
     * @return a Pair that holds the {@link ScreenCaptureListener} that should be used for capture
     * calls into SurfaceFlinger and a {@link ScreenshotSync} object to retrieve the results.
     */
    public static Pair<ScreenCaptureListener, ScreenshotSync> createSyncCaptureListener() {
        final ScreenshotSync screenshotSync = new ScreenshotSync();
        final ScreenCaptureListener screenCaptureListener = new ScreenCaptureListener(
                screenshotSync::setScreenshotHardwareBuffer);
        return new Pair<>(screenCaptureListener, screenshotSync);
     * @return a {@link SynchronousScreenCaptureListener} that should be used for capture
     * calls into SurfaceFlinger.
     */
    public static SynchronousScreenCaptureListener createSyncCaptureListener() {
        ScreenshotHardwareBuffer[] bufferRef = new ScreenshotHardwareBuffer[1];
        CountDownLatch latch = new CountDownLatch(1);
        Consumer<ScreenshotHardwareBuffer> consumer = buffer -> {
            bufferRef[0] = buffer;
            latch.countDown();
        };

        return new SynchronousScreenCaptureListener(consumer) {
            // In order to avoid requiring two GC cycles to clean up the consumer and the buffer
            // it references, the underlying JNI listener holds a weak reference to the consumer.
            // This property exists to ensure the consumer stays alive during the listener's
            // lifetime.
            private Consumer<ScreenshotHardwareBuffer> mConsumer = consumer;

            @Override
            public ScreenshotHardwareBuffer getBuffer() {
                try {
                    latch.await(SCREENSHOT_WAIT_TIME_S, TimeUnit.SECONDS);
                    return bufferRef[0];
                } catch (Exception e) {
                    Log.e(TAG, "Failed to wait for screen capture result", e);
                    return null;
                }
            }
        };
    }

    /**
@@ -758,28 +778,15 @@ public class ScreenCapture {
     * {@link #captureLayers(LayerCaptureArgs, ScreenCaptureListener)} or
     * {@link #captureDisplay(DisplayCaptureArgs, ScreenCaptureListener)}
     */
    public static class ScreenshotSync {
        private final CountDownLatch mCountDownLatch = new CountDownLatch(1);
        private ScreenshotHardwareBuffer mScreenshotHardwareBuffer;

        private void setScreenshotHardwareBuffer(
                ScreenshotHardwareBuffer screenshotHardwareBuffer) {
            mScreenshotHardwareBuffer = screenshotHardwareBuffer;
            mCountDownLatch.countDown();
    public abstract static class SynchronousScreenCaptureListener extends ScreenCaptureListener {
        SynchronousScreenCaptureListener(Consumer<ScreenshotHardwareBuffer> consumer) {
            super(consumer);
        }

        /**
         * Get the {@link ScreenshotHardwareBuffer} synchronously. This can be null if the
         * screenshot failed or if there was no callback in {@link #SCREENSHOT_WAIT_TIME_S} seconds.
         */
        public ScreenshotHardwareBuffer get() {
            try {
                mCountDownLatch.await(SCREENSHOT_WAIT_TIME_S, TimeUnit.SECONDS);
                return mScreenshotHardwareBuffer;
            } catch (Exception e) {
                Log.e(TAG, "Failed to wait for screen capture result", e);
                return null;
            }
        }
        public abstract ScreenshotHardwareBuffer getBuffer();
    }
}
+14 −8
Original line number Diff line number Diff line
@@ -81,22 +81,28 @@ class ScreenCaptureListenerWrapper : public gui::BnScreenCaptureListener {
public:
    explicit ScreenCaptureListenerWrapper(JNIEnv* env, jobject jobject) {
        env->GetJavaVM(&mVm);
        mConsumerObject = env->NewGlobalRef(jobject);
        LOG_ALWAYS_FATAL_IF(!mConsumerObject, "Failed to make global ref");
        mConsumerWeak = env->NewWeakGlobalRef(jobject);
    }

    ~ScreenCaptureListenerWrapper() {
        if (mConsumerObject) {
            getenv()->DeleteGlobalRef(mConsumerObject);
            mConsumerObject = nullptr;
        if (mConsumerWeak) {
            getenv()->DeleteWeakGlobalRef(mConsumerWeak);
            mConsumerWeak = nullptr;
        }
    }

    binder::Status onScreenCaptureCompleted(
            const gui::ScreenCaptureResults& captureResults) override {
        JNIEnv* env = getenv();

        ScopedLocalRef<jobject> consumer{env, env->NewLocalRef(mConsumerWeak)};
        if (consumer == nullptr) {
            ALOGE("ScreenCaptureListenerWrapper consumer not alive.");
            return binder::Status::ok();
        }

        if (!captureResults.fenceResult.ok() || captureResults.buffer == nullptr) {
            env->CallVoidMethod(mConsumerObject, gConsumerClassInfo.accept, nullptr);
            env->CallVoidMethod(consumer.get(), gConsumerClassInfo.accept, nullptr);
            checkAndClearException(env, "accept");
            return binder::Status::ok();
        }
@@ -111,7 +117,7 @@ public:
                                            captureResults.capturedSecureLayers,
                                            captureResults.capturedHdrLayers);
        checkAndClearException(env, "builder");
        env->CallVoidMethod(mConsumerObject, gConsumerClassInfo.accept, screenshotHardwareBuffer);
        env->CallVoidMethod(consumer.get(), gConsumerClassInfo.accept, screenshotHardwareBuffer);
        checkAndClearException(env, "accept");
        env->DeleteLocalRef(jhardwareBuffer);
        env->DeleteLocalRef(screenshotHardwareBuffer);
@@ -119,7 +125,7 @@ public:
    }

private:
    jobject mConsumerObject;
    jweak mConsumerWeak;
    JavaVM* mVm;

    JNIEnv* getenv() {
Loading