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

Commit c29cd454 authored by Geoffrey Boullanger's avatar Geoffrey Boullanger
Browse files

Modify device activity monitor to detect the start of "flight mode".

Currently it only detects when it ends. With this change, the device activity monitor notifies clients when it starts. This can help to know when the fallback needs to stop.

No change in the behavior is done yet. This only provides the capability to detect the beginning of "flight mode" and will later be used in the Fused Time Zone Detector.

go/android-tz-detector
go/ftzd-algo
go/ftzd-cases
go/ftzd-scenarios

Test: atest FrameworksTimeCoreTests
Test: atest FrameworksTimeServicesTests
Test: atest FrameworksTelephonyTests
Flag: android.timezone.flags.enable_fused_time_zone_detector
Bug: 394770805
Change-Id: I3b42dbdc78e40f08c831b454bd3a0dd868f09baa
parent e8976188
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -34,6 +34,9 @@ interface DeviceActivityMonitor extends Dumpable {
     * A listener for device activities. See {@link DeviceActivityMonitor#addListener(Listener)}.
     */
    interface Listener {
        /** A flight has started. */
        void onFlightStart();

        /** A flight has completed. */
        void onFlightComplete();
    }
+13 −2
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import com.android.internal.annotations.GuardedBy;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;

/**
 * The real implementation of {@link DeviceActivityMonitor}.
@@ -59,6 +60,8 @@ class DeviceActivityMonitorImpl implements DeviceActivityMonitor {
                            contentResolver, Settings.Global.AIRPLANE_MODE_ON);
                    if (state == 0) {
                        notifyFlightComplete();
                    } else if (state == 1) {
                        notifyFlightStart();
                    }
                } catch (Settings.SettingNotFoundException e) {
                    Slog.e(LOG_TAG, "Unable to read airplane mode state", e);
@@ -77,9 +80,17 @@ class DeviceActivityMonitorImpl implements DeviceActivityMonitor {
        mListeners.add(listener);
    }

    private void notifyFlightStart() {
        notify("notifyFlightStart", Listener::onFlightStart);
    }

    private void notifyFlightComplete() {
        notify("notifyFlightComplete", Listener::onFlightComplete);
    }

    private void notify(String logMessage, Consumer<Listener> notifier) {
        if (DBG) {
            Slog.d(LOG_TAG, "notifyFlightComplete");
            Slog.d(LOG_TAG, logMessage);
        }

        // Copy the listeners holding the "this" lock but don't hold the lock while delivering the
@@ -89,7 +100,7 @@ class DeviceActivityMonitorImpl implements DeviceActivityMonitor {
            listeners = new ArrayList<>(mListeners);
        }
        for (Listener listener : listeners) {
            listener.onFlightComplete();
            notifier.accept(listener);
        }
    }

+13 −6
Original line number Diff line number Diff line
@@ -88,10 +88,17 @@ public final class TimeZoneDetectorService extends ITimeZoneDetectorService.Stub
                    DeviceActivityMonitorImpl.create(context, handler);

            // Wire up the telephony fallback behavior to activity detection.
            deviceActivityMonitor.addListener(new DeviceActivityMonitor.Listener() {
            deviceActivityMonitor.addListener(
                    new DeviceActivityMonitor.Listener() {
                        @Override
                        public void onFlightStart() {
                            // do nothing
                        }

                        @Override
                        public void onFlightComplete() {
                    timeZoneDetectorStrategy.enableTelephonyTimeZoneFallback("onFlightComplete()");
                            timeZoneDetectorStrategy.enableTelephonyTimeZoneFallback(
                                    "onFlightComplete()");
                        }
                    });