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

Commit fd98c576 authored by Galia Peycheva's avatar Galia Peycheva Committed by Android (Google) Code Review
Browse files

Merge changes from topic "add-runtime-blur-disabling" into sc-dev

* changes:
  Create listener for dynamic blurEnabled changes
  Make WM.LP.blurBehindRadius a setter+getter
parents fcbd636e 6e842a73
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -49724,9 +49724,12 @@ package android.view {
  }
  public interface WindowManager extends android.view.ViewManager {
    method public default void addCrossWindowBlurEnabledListener(@NonNull java.util.function.Consumer<java.lang.Boolean>);
    method @NonNull public default android.view.WindowMetrics getCurrentWindowMetrics();
    method @Deprecated public android.view.Display getDefaultDisplay();
    method @NonNull public default android.view.WindowMetrics getMaximumWindowMetrics();
    method public default boolean isCrossWindowBlurEnabled();
    method public default void removeCrossWindowBlurEnabledListener(@NonNull java.util.function.Consumer<java.lang.Boolean>);
    method public void removeViewImmediate(android.view.View);
  }
@@ -49751,12 +49754,14 @@ package android.view {
    method public final int copyFrom(android.view.WindowManager.LayoutParams);
    method public String debug(String);
    method public int describeContents();
    method public int getBlurBehindRadius();
    method public int getColorMode();
    method public int getFitInsetsSides();
    method public int getFitInsetsTypes();
    method public final CharSequence getTitle();
    method public boolean isFitInsetsIgnoringVisibility();
    method public static boolean mayUseInputMethod(int);
    method public void setBlurBehindRadius(@IntRange(from=0) int);
    method public void setColorMode(int);
    method public void setFitInsetsIgnoringVisibility(boolean);
    method public void setFitInsetsSides(int);
@@ -49867,7 +49872,6 @@ package android.view {
    field @Deprecated public static final int TYPE_TOAST = 2005; // 0x7d5
    field public static final int TYPE_WALLPAPER = 2013; // 0x7dd
    field public float alpha;
    field public int blurBehindRadius;
    field public float buttonBrightness;
    field public float dimAmount;
    field public int flags;
+0 −1
Original line number Diff line number Diff line
@@ -2549,7 +2549,6 @@ package android.content.pm {
    field public static final String FEATURE_BROADCAST_RADIO = "android.hardware.broadcastradio";
    field public static final String FEATURE_CAMERA_TOGGLE = "android.hardware.camera.toggle";
    field public static final String FEATURE_CONTEXT_HUB = "android.hardware.context_hub";
    field public static final String FEATURE_CROSS_LAYER_BLUR = "android.software.cross_layer_blur";
    field @Deprecated public static final String FEATURE_INCREMENTAL_DELIVERY = "android.software.incremental_delivery";
    field public static final String FEATURE_INCREMENTAL_DELIVERY_VERSION = "android.software.incremental_delivery_version";
    field public static final String FEATURE_MICROPHONE_TOGGLE = "android.hardware.microphone.toggle";
+0 −11
Original line number Diff line number Diff line
@@ -3655,17 +3655,6 @@ public abstract class PackageManager {
    @SdkConstant(SdkConstantType.FEATURE)
    public static final String FEATURE_APP_ENUMERATION = "android.software.app_enumeration";

    /**
     * Feature for {@link android.view.WindowManager.LayoutParams.backgroundBlurRedius} and
     * {@link android.graphics.drawable.BackgroundBlurDrawable}: the device supports cross-layer
     * blurring.
     *
     * @hide
     */
    @SystemApi
    @SdkConstant(SdkConstantType.FEATURE)
    public static final String FEATURE_CROSS_LAYER_BLUR = "android.software.cross_layer_blur";

    /**
     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}: The device has
     * a Keystore implementation that can only enforce limited use key in hardware with max usage
+137 −0
Original line number Diff line number Diff line
/**
 * Copyright (C) 2021 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 android.view;

import android.os.Handler;
import android.os.Looper;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.util.ArraySet;
import android.util.Log;

import java.util.function.Consumer;

/**
 * Class that holds all registered {@link CrossWindowBlurEnabledListener}s. It listens
 * for updates from the WindowManagerService and updates all registered listeners.
 * @hide
 */
public final class CrossWindowBlurListeners {
    private static final String TAG = "CrossWindowBlurListeners";

    // property for background blur support in surface flinger
    private static final String BLUR_PROPERTY = "ro.surface_flinger.supports_background_blur";
    public static final boolean CROSS_WINDOW_BLUR_SUPPORTED =
            SystemProperties.get(BLUR_PROPERTY, "default").equals("1");

    private static volatile CrossWindowBlurListeners sInstance;
    private static final Object sLock = new Object();

    private final BlurEnabledListenerInternal mListenerInternal = new BlurEnabledListenerInternal();
    private final ArraySet<Consumer<Boolean>> mListeners = new ArraySet();
    private final Handler mMainHandler = new Handler(Looper.getMainLooper());
    private boolean mInternalListenerAttached = false;
    private boolean mCrossWindowBlurEnabled;

    private CrossWindowBlurListeners() {}

    /**
     * Returns a CrossWindowBlurListeners instance
     */
    public static CrossWindowBlurListeners getInstance() {
        CrossWindowBlurListeners instance = sInstance;
        if (instance == null) {

            synchronized (sLock) {
                instance = sInstance;
                if (instance == null) {
                    instance = new CrossWindowBlurListeners();
                    sInstance = instance;
                }
            }
        }
        return instance;
    }

    boolean isCrossWindowBlurEnabled() {
        synchronized (sLock) {
            attachInternalListenerIfNeededLocked();
            return mCrossWindowBlurEnabled;
        }
    }

    void addListener(Consumer<Boolean> listener) {
        if (listener == null) return;

        synchronized (sLock) {
            attachInternalListenerIfNeededLocked();

            mListeners.add(listener);
            notifyListenerOnMain(listener, mCrossWindowBlurEnabled);
        }
    }


    void removeListener(Consumer<Boolean> listener) {
        if (listener == null) return;

        synchronized (sLock) {
            mListeners.remove(listener);

            if (mInternalListenerAttached && mListeners.size() == 0) {
                try {
                    WindowManagerGlobal.getWindowManagerService()
                            .unregisterCrossWindowBlurEnabledListener(mListenerInternal);
                    mInternalListenerAttached = false;
                } catch (RemoteException e) {
                    Log.d(TAG, "Could not unregister ICrossWindowBlurEnabledListener");
                }
            }
        }
    }

    private void attachInternalListenerIfNeededLocked() {
        if (!mInternalListenerAttached) {
            try {
                mCrossWindowBlurEnabled = WindowManagerGlobal.getWindowManagerService()
                        .registerCrossWindowBlurEnabledListener(mListenerInternal);
                mInternalListenerAttached = true;
            } catch (RemoteException e) {
                Log.d(TAG, "Could not register ICrossWindowBlurEnabledListener");
            }
        }
    }

    private void notifyListenerOnMain(Consumer<Boolean> listener, boolean enabled) {
        mMainHandler.post(() -> {
            listener.accept(enabled);
        });
    }

    private final class BlurEnabledListenerInternal extends ICrossWindowBlurEnabledListener.Stub {
        @Override
        public void onCrossWindowBlurEnabledChanged(boolean enabled) {
            synchronized (sLock) {
                mCrossWindowBlurEnabled = enabled;

                for (int i = 0; i < mListeners.size(); i++) {
                    notifyListenerOnMain(mListeners.valueAt(i), enabled);
                }
            }
        }
    }
}
+29 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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 android.view;

/**
 * Listener to be invoked when cross-window blur is enabled or disabled.
 * {@hide}
 */
oneway interface ICrossWindowBlurEnabledListener {
    /**
     * Method that will be invoked when cross-window blur is enabled or disabled.
     * @param enabled True if cross-window blur is enabled.
     */
    void onCrossWindowBlurEnabledChanged(boolean enabled);
}
Loading