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

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

Merge cherrypicks of ['googleplex-android-review.googlesource.com/22634065',...

Merge cherrypicks of ['googleplex-android-review.googlesource.com/22634065', 'googleplex-android-review.googlesource.com/22901260'] into tm-qpr3-c-release.

Change-Id: I1ed6c0674f4b40af7a1c3a399823e525be240a01
parents 0bead2d7 95cf483d
Loading
Loading
Loading
Loading
+5 −7
Original line number Diff line number Diff line
@@ -38,7 +38,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;

/**
@@ -129,14 +128,13 @@ public final class DeviceStateManagerFoldingFeatureProducer
    }

    @Override
    protected void onListenersChanged(
            @NonNull Set<Consumer<List<CommonFoldingFeature>>> callbacks) {
        super.onListenersChanged(callbacks);
        if (callbacks.isEmpty()) {
    protected void onListenersChanged() {
        super.onListenersChanged();
        if (hasListeners()) {
            mRawFoldSupplier.addDataChangedCallback(this::notifyFoldingFeatureChange);
        } else {
            mCurrentDeviceState = INVALID_DEVICE_STATE;
            mRawFoldSupplier.removeDataChangedCallback(this::notifyFoldingFeatureChange);
        } else {
            mRawFoldSupplier.addDataChangedCallback(this::notifyFoldingFeatureChange);
        }
    }

+4 −5
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@ import androidx.window.util.BaseDataProducer;
import com.android.internal.R;

import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;

/**
@@ -86,11 +85,11 @@ public final class RawFoldingFeatureProducer extends BaseDataProducer<String> {
    }

    @Override
    protected void onListenersChanged(Set<Consumer<String>> callbacks) {
        if (callbacks.isEmpty()) {
            unregisterObserversIfNeeded();
        } else {
    protected void onListenersChanged() {
        if (hasListeners()) {
            registerObserversIfNeeded();
        } else {
            unregisterObserversIfNeeded();
        }
    }

+16 −5
Original line number Diff line number Diff line
@@ -51,10 +51,10 @@ public abstract class BaseDataProducer<T> implements DataProducer<T>,
    public final void addDataChangedCallback(@NonNull Consumer<T> callback) {
        synchronized (mLock) {
            mCallbacks.add(callback);
        }
        Optional<T> currentData = getCurrentData();
        currentData.ifPresent(callback);
            onListenersChanged(mCallbacks);
        }
        onListenersChanged();
    }

    /**
@@ -67,11 +67,22 @@ public abstract class BaseDataProducer<T> implements DataProducer<T>,
    public final void removeDataChangedCallback(@NonNull Consumer<T> callback) {
        synchronized (mLock) {
            mCallbacks.remove(callback);
            onListenersChanged(mCallbacks);
        }
        onListenersChanged();
    }

    /**
     * Returns {@code true} if there are any registered callbacks {@code false} if there are no
     * registered callbacks.
     */
    // TODO(b/278132889) Improve the structure of BaseDataProdcuer while avoiding known issues.
    public final boolean hasListeners() {
        synchronized (mLock) {
            return !mCallbacks.isEmpty();
        }
    }

    protected void onListenersChanged(Set<Consumer<T>> callbacks) {}
    protected void onListenersChanged() {}

    /**
     * @return the current data if available and {@code Optional.empty()} otherwise.
+4 −0
Original line number Diff line number Diff line
@@ -3867,7 +3867,11 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        // configuration update when the window has requested to be hidden. Doing so can lead to
        // the client erroneously accepting a configuration that would have otherwise caused an
        // activity restart. We instead hand back the last reported {@link MergedConfiguration}.
        // Also note since starting window isn't a window of activity, it won't make activity
        // restart, so here should allow starting window to set the last reported configuration
        // during relayout, which could happen before activity request visible.
        if (useLatestConfig || (relayoutVisible && (mActivityRecord == null
                || mAttrs.type == TYPE_APPLICATION_STARTING
                || mActivityRecord.isVisibleRequested()))) {
            final Configuration globalConfig = getProcessGlobalConfiguration();
            final Configuration overrideConfig = getMergedOverrideConfiguration();