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

Commit 7fc9ec8a authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

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

parents f688098b c29cd454
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()");
                        }
                    });