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

Commit aea185f3 authored by Adrian Roos's avatar Adrian Roos
Browse files

AppCompatOverridesService: Remove finalizer and unregistration logic

This has no hope of currently working in production, because
DeviceConfig holds a strong reference to the listener, so the finalizer
never gets called - besides, this is a singleton service in
system_process that shouldn't ever get collected.

During testing, the finalizer is unnecessary for the same reason. The
only way the class can be finalized is if the Context and the
DeviceConfig both are unreachable, but then there's really no need to
unregister anymore.

However, during AppCompatOverridesServiceTest the finalizer invokes
DeviceConfig methods on the finalizer thread concurrently with
non-thread-safe stubbing in TestableDeviceConfig, causing occasional
test flakes (that, due to the combined effect of the bugs at b/399645852
cause every subsequent test in the class to fail).

Bug: 397997489
Test: atest AppCompatOverridesServiceTest
Flag: TEST_ONLY
Change-Id: Ic5ed380286df6cd41c9b1a504e237d320c37080c
parent e01305a7
Loading
Loading
Loading
Loading
+0 −24
Original line number Diff line number Diff line
@@ -103,12 +103,6 @@ public final class AppCompatOverridesService {
        }
    }

    @Override
    public void finalize() {
        unregisterDeviceConfigListeners();
        unregisterPackageReceiver();
    }

    @VisibleForTesting
    void registerDeviceConfigListeners() {
        for (DeviceConfigListener listener : mDeviceConfigListeners) {
@@ -116,21 +110,11 @@ public final class AppCompatOverridesService {
        }
    }

    private void unregisterDeviceConfigListeners() {
        for (DeviceConfigListener listener : mDeviceConfigListeners) {
            listener.unregister();
        }
    }

    @VisibleForTesting
    void registerPackageReceiver() {
        mPackageReceiver.register();
    }

    private void unregisterPackageReceiver() {
        mPackageReceiver.unregister();
    }

    /**
     * Same as {@link #applyOverrides(Properties, Set, Map)} except all properties of the given
     * {@code namespace} are fetched via {@link DeviceConfig#getProperties}.
@@ -374,10 +358,6 @@ public final class AppCompatOverridesService {
                    this);
        }

        private void unregister() {
            DeviceConfig.removeOnPropertiesChangedListener(this);
        }

        @Override
        public void onPropertiesChanged(Properties properties) {
            boolean removeOverridesFlagChanged = properties.getKeyset().contains(
@@ -426,10 +406,6 @@ public final class AppCompatOverridesService {
                    null, /* scheduler= */ null);
        }

        private void unregister() {
            mContext.unregisterReceiver(this);
        }

        @Override
        public void onReceive(@NonNull final Context context, @NonNull final Intent intent) {
            Uri data = intent.getData();