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

Commit 20091903 authored by Stanislav Zholnin's avatar Stanislav Zholnin
Browse files

Make DiscreteRegistry react only to offsetHistory() calls made as TestApi call.

Initialize DiscreteRegistry first as it doesn't depend on HistoricalRegistry.

There was a wrong assumption that HistoricalRegistry.offsetHistory() is used only for
testing, which was not correct, thus calls to offsetHistory() made during normal
operations of HistoricalRegistry could lead to deadlocks and corruption of timestamps
in DiscreteRegistry.

Fix: 188111112
Fix: 187490443
Bug: 187907266

Test: atest DiscreteAppopsTest

Change-Id: I97aadab497ffea5dd91e6d581bdc39e0a5df3718
parent 7f1f8d0b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -6454,6 +6454,7 @@ public class AppOpsService extends IAppOpsService.Stub {
                "offsetHistory");
        // Must not hold the appops lock
        mHistoricalRegistry.offsetHistory(offsetMillis);
        mHistoricalRegistry.offsetDiscreteHistory(offsetMillis);
    }

    @Override
+4 −1
Original line number Diff line number Diff line
@@ -212,6 +212,7 @@ final class HistoricalRegistry {
    }

    void systemReady(@NonNull ContentResolver resolver) {
        mDiscreteRegistry.systemReady();
        final Uri uri = Settings.Global.getUriFor(Settings.Global.APPOP_HISTORY_PARAMETERS);
        resolver.registerContentObserver(uri, false, new ContentObserver(
                FgThread.getHandler()) {
@@ -249,7 +250,6 @@ final class HistoricalRegistry {
                }
            }
        }
        mDiscreteRegistry.systemReady();
    }

    private boolean isPersistenceInitializedMLocked() {
@@ -594,6 +594,9 @@ final class HistoricalRegistry {
                mPersistence.persistHistoricalOpsDLocked(history);
            }
        }
    }

    void offsetDiscreteHistory(long offsetMillis) {
        mDiscreteRegistry.offsetHistory(offsetMillis);
    }