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

Commit 39074df9 authored by Tej Singh's avatar Tej Singh
Browse files

Remove dead code for AnomalyAlarm

Anomaly alarms now rely on the flow of events into statsd's socket for
firing alarms. Remove the StatsCompanionService code path, which is
unused now.

Test: m
Bug: 161326200
Bug: 152642091
Change-Id: Ife0b17c281984fc489ef46039cbf5aa7b1346bdb
Merged-In: Ife0b17c281984fc489ef46039cbf5aa7b1346bdb
parent 8b914c0f
Loading
Loading
Loading
Loading
+0 −11
Original line number Diff line number Diff line
@@ -26,17 +26,6 @@ interface IStatsCompanionService {
     */
    oneway void statsdReady();

    /**
    * Register an alarm for anomaly detection to fire at the given timestamp (ms since epoch).
    * If anomaly alarm had already been registered, it will be replaced with the new timestamp.
    * Uses AlarmManager.set API, so  if the timestamp is in the past, alarm fires immediately, and
    * alarm is inexact.
    */
    oneway void setAnomalyAlarm(long timestampMs);

    /** Cancel any anomaly detection alarm. */
    oneway void cancelAnomalyAlarm();

    /**
      * Register a repeating alarm for pulling to fire at the given timestamp and every
      * intervalMs thereafter (in ms since epoch).
+0 −7
Original line number Diff line number Diff line
@@ -41,13 +41,6 @@ interface IStatsd {
     */
    void statsCompanionReady();

    /**
     * Tells statsd that an anomaly may have occurred, so statsd can check whether this is so and
     * act accordingly.
     * Two-way binder call so that caller's method (and corresponding wakelocks) will linger.
     */
    void informAnomalyAlarmFired();

    /**
     * Tells statsd that it is time to poll some stats. Statsd will be responsible for determing
     * what stats to poll and initiating the polling.
+0 −66
Original line number Diff line number Diff line
@@ -100,7 +100,6 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
    private static IStatsd sStatsd;
    private static final Object sStatsdLock = new Object();

    private final OnAlarmListener mAnomalyAlarmListener;
    private final OnAlarmListener mPullingAlarmListener;
    private final OnAlarmListener mPeriodicAlarmListener;

@@ -124,7 +123,6 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
        handlerThread.start();
        mHandler = new CompanionHandler(handlerThread.getLooper());

        mAnomalyAlarmListener = new AnomalyAlarmListener(context);
        mPullingAlarmListener = new PullingAlarmListener(context);
        mPeriodicAlarmListener = new PeriodicAlarmListener(context);
    }
@@ -336,41 +334,6 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
        }
    }

    public static final class AnomalyAlarmListener implements OnAlarmListener {
        private final Context mContext;

        AnomalyAlarmListener(Context context) {
            mContext = context;
        }

        @Override
        public void onAlarm() {
            if (DEBUG) {
                Log.i(TAG, "StatsCompanionService believes an anomaly has occurred at time "
                        + System.currentTimeMillis() + "ms.");
            }
            IStatsd statsd = getStatsdNonblocking();
            if (statsd == null) {
                Log.w(TAG, "Could not access statsd to inform it of anomaly alarm firing");
                return;
            }

            // Wakelock needs to be retained while calling statsd.
            Thread thread = new WakelockThread(mContext,
                    AnomalyAlarmListener.class.getCanonicalName(), new Runnable() {
                        @Override
                        public void run() {
                            try {
                                statsd.informAnomalyAlarmFired();
                            } catch (RemoteException e) {
                                Log.w(TAG, "Failed to inform statsd of anomaly alarm firing", e);
                            }
                        }
                    });
            thread.start();
        }
    }

    public final static class PullingAlarmListener implements OnAlarmListener {
        private final Context mContext;

@@ -468,34 +431,6 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
        }
    }

    @Override // Binder call
    public void setAnomalyAlarm(long timestampMs) {
        StatsCompanion.enforceStatsdCallingUid();
        if (DEBUG) Log.d(TAG, "Setting anomaly alarm for " + timestampMs);
        final long callingToken = Binder.clearCallingIdentity();
        try {
            // using ELAPSED_REALTIME, not ELAPSED_REALTIME_WAKEUP, so if device is asleep, will
            // only fire when it awakens.
            // AlarmManager will automatically cancel any previous mAnomalyAlarmListener alarm.
            mAlarmManager.setExact(AlarmManager.ELAPSED_REALTIME, timestampMs, TAG + ".anomaly",
                    mAnomalyAlarmListener, mHandler);
        } finally {
            Binder.restoreCallingIdentity(callingToken);
        }
    }

    @Override // Binder call
    public void cancelAnomalyAlarm() {
        StatsCompanion.enforceStatsdCallingUid();
        if (DEBUG) Log.d(TAG, "Cancelling anomaly alarm");
        final long callingToken = Binder.clearCallingIdentity();
        try {
            mAlarmManager.cancel(mAnomalyAlarmListener);
        } finally {
            Binder.restoreCallingIdentity(callingToken);
        }
    }

    @Override // Binder call
    public void setAlarmForSubscriberTriggering(long timestampMs) {
        StatsCompanion.enforceStatsdCallingUid();
@@ -666,7 +601,6 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
        // instead of in binder death because statsd can come back and set different alarms, or not
        // want to set an alarm when it had been set. This guarantees that when we get a new statsd,
        // we cancel any alarms before it is able to set them.
        cancelAnomalyAlarm();
        cancelPullingAlarm();
        cancelAlarmForSubscriberTriggering();

+0 −6
Original line number Diff line number Diff line
@@ -971,12 +971,6 @@ Status StatsService::informOnePackageRemoved(const string& app, int32_t uid) {
    return Status::ok();
}

Status StatsService::informAnomalyAlarmFired() {
    ENFORCE_UID(AID_SYSTEM);
    // Anomaly alarms are handled internally now. This code should be fully deleted.
    return Status::ok();
}

Status StatsService::informAlarmForSubscriberTriggeringFired() {
    ENFORCE_UID(AID_SYSTEM);

+0 −1
Original line number Diff line number Diff line
@@ -66,7 +66,6 @@ public:
    virtual Status systemRunning();
    virtual Status statsCompanionReady();
    virtual Status bootCompleted();
    virtual Status informAnomalyAlarmFired();
    virtual Status informPollAlarmFired();
    virtual Status informAlarmForSubscriberTriggeringFired();