summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Diego Vela <diegovela@google.com> 2024-07-19 22:25:42 +0000
committer Diego Vela <diegovela@google.com> 2024-07-22 19:27:07 +0000
commitc8cd48a6b64e971199a4341245323fa3950cb1ca (patch)
treea4decd4c0a280269aff1ca604306f80611729ba8
parent35016bb429daafc339253dec6101ff19f40913e1 (diff)
Delete DataProducer abstraction.
Remove DataProducer abstraction. It adds needless complexity to the implementation but does not add any value. The abstract class BaseDataProducer is sufficient. Flag: EXEMPT refactor Bug: 347964255 Test: n/a refactor Change-Id: I57a8bf4ea742172260222a3c4910c89cea6171c9
-rw-r--r--libs/WindowManager/Jetpack/src/androidx/window/common/RawFoldingFeatureProducer.java2
-rw-r--r--libs/WindowManager/Jetpack/src/androidx/window/util/AcceptOnceConsumer.java2
-rw-r--r--libs/WindowManager/Jetpack/src/androidx/window/util/BaseDataProducer.java21
-rw-r--r--libs/WindowManager/Jetpack/src/androidx/window/util/DataProducer.java44
4 files changed, 14 insertions, 55 deletions
diff --git a/libs/WindowManager/Jetpack/src/androidx/window/common/RawFoldingFeatureProducer.java b/libs/WindowManager/Jetpack/src/androidx/window/common/RawFoldingFeatureProducer.java
index 8906e6d3d02e..88264f383153 100644
--- a/libs/WindowManager/Jetpack/src/androidx/window/common/RawFoldingFeatureProducer.java
+++ b/libs/WindowManager/Jetpack/src/androidx/window/common/RawFoldingFeatureProducer.java
@@ -34,7 +34,7 @@ import java.util.Optional;
import java.util.function.Consumer;
/**
- * Implementation of {@link androidx.window.util.DataProducer} that produces a
+ * Implementation of {@link androidx.window.util.BaseDataProducer} that produces a
* {@link String} that can be parsed to a {@link CommonFoldingFeature}.
* {@link RawFoldingFeatureProducer} searches for the value in two places. The first check is in
* settings where the {@link String} property is saved with the key
diff --git a/libs/WindowManager/Jetpack/src/androidx/window/util/AcceptOnceConsumer.java b/libs/WindowManager/Jetpack/src/androidx/window/util/AcceptOnceConsumer.java
index fe60037483c4..63828ab2e62b 100644
--- a/libs/WindowManager/Jetpack/src/androidx/window/util/AcceptOnceConsumer.java
+++ b/libs/WindowManager/Jetpack/src/androidx/window/util/AcceptOnceConsumer.java
@@ -23,7 +23,7 @@ import java.util.function.Consumer;
/**
* A base class that works with {@link BaseDataProducer} to add/remove a consumer that should
* only be used once when {@link BaseDataProducer#notifyDataChanged} is called.
- * @param <T> The type of data this producer returns through {@link DataProducer#getData}.
+ * @param <T> The type of data this producer returns through {@link BaseDataProducer#getData}.
*/
public class AcceptOnceConsumer<T> implements Consumer<T> {
private final Consumer<T> mCallback;
diff --git a/libs/WindowManager/Jetpack/src/androidx/window/util/BaseDataProducer.java b/libs/WindowManager/Jetpack/src/androidx/window/util/BaseDataProducer.java
index de52f0969fa8..cd26efd4fdb6 100644
--- a/libs/WindowManager/Jetpack/src/androidx/window/util/BaseDataProducer.java
+++ b/libs/WindowManager/Jetpack/src/androidx/window/util/BaseDataProducer.java
@@ -26,13 +26,12 @@ import java.util.Set;
import java.util.function.Consumer;
/**
- * Base class that provides the implementation for the callback mechanism of the
- * {@link DataProducer} API. This class is thread safe for adding, removing, and notifying
- * consumers.
+ * Base class that manages listeners when listening to a piece of data that changes. This class is
+ * thread safe for adding, removing, and notifying consumers.
*
- * @param <T> The type of data this producer returns through {@link DataProducer#getData}.
+ * @param <T> The type of data this producer returns through {@link BaseDataProducer#getData}.
*/
-public abstract class BaseDataProducer<T> implements DataProducer<T>,
+public abstract class BaseDataProducer<T> implements
AcceptOnceConsumer.AcceptOnceProducerCallback<T> {
private final Object mLock = new Object();
@@ -42,12 +41,17 @@ public abstract class BaseDataProducer<T> implements DataProducer<T>,
private final Set<Consumer<T>> mCallbacksToRemove = new HashSet<>();
/**
+ * Emits the first available data at that point in time.
+ * @param dataConsumer a {@link Consumer} that will receive one value.
+ */
+ public abstract void getData(@NonNull Consumer<T> dataConsumer);
+
+ /**
* Adds a callback to the set of callbacks listening for data. Data is delivered through
* {@link BaseDataProducer#notifyDataChanged(Object)}. This method is thread safe. Callers
* should ensure that callbacks are thread safe.
* @param callback that will receive data from the producer.
*/
- @Override
public final void addDataChangedCallback(@NonNull Consumer<T> callback) {
synchronized (mLock) {
mCallbacks.add(callback);
@@ -63,7 +67,6 @@ public abstract class BaseDataProducer<T> implements DataProducer<T>,
* @param callback that was registered in
* {@link BaseDataProducer#addDataChangedCallback(Consumer)}.
*/
- @Override
public final void removeDataChangedCallback(@NonNull Consumer<T> callback) {
synchronized (mLock) {
mCallbacks.remove(callback);
@@ -92,8 +95,8 @@ public abstract class BaseDataProducer<T> implements DataProducer<T>,
/**
* Called to notify all registered consumers that the data provided
- * by {@link DataProducer#getData} has changed. Calls to this are thread save but callbacks need
- * to ensure thread safety.
+ * by {@link BaseDataProducer#getData} has changed. Calls to this are thread save but callbacks
+ * need to ensure thread safety.
*/
protected void notifyDataChanged(T value) {
synchronized (mLock) {
diff --git a/libs/WindowManager/Jetpack/src/androidx/window/util/DataProducer.java b/libs/WindowManager/Jetpack/src/androidx/window/util/DataProducer.java
deleted file mode 100644
index ec301dc34aaa..000000000000
--- a/libs/WindowManager/Jetpack/src/androidx/window/util/DataProducer.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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 androidx.window.util;
-
-import android.annotation.NonNull;
-
-import java.util.function.Consumer;
-
-/**
- * Produces data through {@link DataProducer#getData} and provides a mechanism for receiving
- * a callback when the data managed by the produces has changed.
- *
- * @param <T> The type of data this producer returns through {@link DataProducer#getData}.
- */
-public interface DataProducer<T> {
- /**
- * Emits the first available data at that point in time.
- * @param dataConsumer a {@link Consumer} that will receive one value.
- */
- void getData(@NonNull Consumer<T> dataConsumer);
-
- /**
- * Adds a callback to be notified when the data returned
- * from {@link DataProducer#getData} has changed.
- */
- void addDataChangedCallback(@NonNull Consumer<T> callback);
-
- /** Removes a callback previously added with {@link #addDataChangedCallback(Consumer)}. */
- void removeDataChangedCallback(@NonNull Consumer<T> callback);
-}