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

Commit 2478cc71 authored by Michał Brzeziński's avatar Michał Brzeziński Committed by Android (Google) Code Review
Browse files

Merge "Waiting for FakeLatencyTracker’s listener to be registered" into main

parents d1047770 6688f6ec
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
@@ -84,6 +84,7 @@ import com.android.internal.os.BackgroundThread;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Locale;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;

@@ -441,7 +442,8 @@ public class LatencyTracker {

        static {
            sLatencyTracker = new LatencyTracker();
            sLatencyTracker.startListeningForLatencyTrackerConfigChanges();
            sLatencyTracker.startListeningForLatencyTrackerConfigChanges(
                    BackgroundThread.getExecutor());
        }
    }

@@ -496,10 +498,13 @@ public class LatencyTracker {
     *
     * <p>This is not used for production usages of this class outside of testing as we are
     * using a single static object.
     *
     * @param executor used for reading initial properties, listener registration and running
     *                 callbacks from that listener
     */
    @VisibleForTesting
    @RequiresPermission(Manifest.permission.READ_DEVICE_CONFIG)
    public void startListeningForLatencyTrackerConfigChanges() {
    public void startListeningForLatencyTrackerConfigChanges(Executor executor) {
        final Context context = ActivityThread.currentApplication();
        if (context == null) {
            Log.e(
@@ -521,12 +526,12 @@ public class LatencyTracker {
        }

        // Post initialization to the background in case we're running on the main thread.
        BackgroundThread.getHandler().post(() -> {
        executor.execute(() -> {
            try {
                this.updateProperties(
                        DeviceConfig.getProperties(NAMESPACE_LATENCY_TRACKER));
                DeviceConfig.addOnPropertiesChangedListener(NAMESPACE_LATENCY_TRACKER,
                        BackgroundThread.getExecutor(), mOnPropertiesChangedListener);
                        executor, mOnPropertiesChangedListener);
            } catch (SecurityException ex) {
                // In case of running tests that the main thread passes the check,
                // but the background thread doesn't have necessary permissions.
+1 −1
Original line number Diff line number Diff line
@@ -59,7 +59,7 @@ public final class FakeLatencyTracker extends LatencyTracker {
        Log.i(TAG, "done disabling all actions");
        FakeLatencyTracker fakeLatencyTracker = new FakeLatencyTracker();
        Log.i(TAG, "done creating tracker object");
        fakeLatencyTracker.startListeningForLatencyTrackerConfigChanges();
        fakeLatencyTracker.startListeningForLatencyTrackerConfigChanges(Runnable::run);
        // always return the fake in the disabled state and let the client control the desired state
        fakeLatencyTracker.waitForGlobalEnabledState(false);
        fakeLatencyTracker.waitForAllPropertiesEnableState(false);