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

Commit 483548e6 authored by Neil Fuller's avatar Neil Fuller
Browse files

Tidy up synchronization / threading

Tidy up synchronization / threading around the LocationTimeZoneProvider
binder event simulation code.

Test steps:

Prep:
adb shell setprop persist.sys.location_time_zone_detection_feature_enabled 1
adb shell setprop persist.sys.location_tz_simulation_mode.secondary 1
adb shell settings put --user current secure location_time_zone_detection_enabled 1
adb reboot

Testing:
adb shell dumpsys location_time_zone_manager
[Observe detection feature is enabled, user setting is enabled and the
secondary provider is in simulation mode]
adb shell cmd location_time_zone_manager simulate_binder secondary onBind
adb shell cmd location_time_zone_manager simulate_binder secondary \
    locationTimeZoneEvent SUCCESS America/Los_Angeles
[Observe the device local time has changed to America/Los_Angeles]
adb shell cmd location_time_zone_manager simulate_binder secondary \
    locationTimeZoneEvent SUCCESS Europe/London
[Observe the device local time has changed to Europe/London]
adb shell dumpsys location_time_zone_manager
[Observe events in the dumped output]

Reset:
[Revert changes from prep]
adb reboot

Bug: 152744911
Bug: 149014708
Test: Manual testing (see above)
Change-Id: Id0b9f9d0b2040ecd81b7d8c9df96abfa14d05aaf
parent 85036ff7
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -211,6 +211,8 @@ class BinderLocationTimeZoneProvider extends LocationTimeZoneProvider {
     * {@link SimulatedLocationTimeZoneProviderProxy}. If not, the event is logged but discarded.
     */
    void simulateBinderProviderEvent(SimulatedBinderProviderEvent event) {
        mThreadingDomain.assertCurrentThread();

        if (!(mProxy instanceof SimulatedLocationTimeZoneProviderProxy)) {
            Slog.w(TAG, mProxy + " is not a " + SimulatedLocationTimeZoneProviderProxy.class
                    + ", event=" + event);
+3 −1
Original line number Diff line number Diff line
@@ -560,10 +560,12 @@ class ControllerImpl extends LocationTimeZoneProviderController {
    }

    /**
     * Asynchronously passes a {@link SimulatedBinderProviderEvent] to the appropriate provider.
     * Passes a {@link SimulatedBinderProviderEvent] to the appropriate provider.
     * If the provider name does not match a known provider, then the event is logged and discarded.
     */
    void simulateBinderProviderEvent(@NonNull SimulatedBinderProviderEvent event) {
        mThreadingDomain.assertCurrentThread();

        String targetProviderName = event.getProviderName();
        LocationTimeZoneProvider targetProvider;
        if (Objects.equals(mPrimaryProvider.getName(), targetProviderName)) {
+32 −24
Original line number Diff line number Diff line
@@ -37,10 +37,11 @@ import java.util.Objects;
 */
class SimulatedLocationTimeZoneProviderProxy extends LocationTimeZoneProviderProxy {

    @GuardedBy("mProxyLock")
    @GuardedBy("mSharedLock")
    @NonNull private LocationTimeZoneProviderRequest mRequest;

    @NonNull private ReferenceWithHistory<String> mLastEvent = new ReferenceWithHistory<>(50);
    @GuardedBy("mSharedLock")
    @NonNull private final ReferenceWithHistory<String> mLastEvent = new ReferenceWithHistory<>(50);

    SimulatedLocationTimeZoneProviderProxy(
            @NonNull Context context, @NonNull ThreadingDomain threadingDomain) {
@@ -49,6 +50,11 @@ class SimulatedLocationTimeZoneProviderProxy extends LocationTimeZoneProviderPro
    }

    void simulate(@NonNull SimulatedBinderProviderEvent event) {
        mThreadingDomain.assertCurrentThread();

        Objects.requireNonNull(event);

        synchronized (mSharedLock) {
            switch (event.getEventType()) {
                case INJECTED_EVENT_TYPE_ON_BIND: {
                    mLastEvent.set("Simulating onProviderBound(), event=" + event);
@@ -71,7 +77,9 @@ class SimulatedLocationTimeZoneProviderProxy extends LocationTimeZoneProviderPro
                }
                default: {
                    mLastEvent.set("Unknown simulated event type. event=" + event);
                throw new IllegalArgumentException("Unknown simulated event type. event=" + event);
                    throw new IllegalArgumentException(
                            "Unknown simulated event type. event=" + event);
                }
            }
        }
    }