Loading cmds/statsd/src/StatsService.cpp +32 −0 Original line number Original line Diff line number Diff line Loading @@ -161,6 +161,38 @@ StatsService::doLoadConfig(FILE* in) } } } } Status StatsService::informAnomalyAlarmFired() { ALOGD("StatsService::informAnomalyAlarmFired was called"); if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) { return Status::fromExceptionCode(Status::EX_SECURITY, "Only system uid can call informAnomalyAlarmFired"); } ALOGD("StatsService::informAnomalyAlarmFired succeeded"); // TODO: check through all counters/timers and see if an anomaly has indeed occurred. return Status::ok(); } Status StatsService::informPollAlarmFired() { ALOGD("StatsService::informPollAlarmFired was called"); if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) { return Status::fromExceptionCode(Status::EX_SECURITY, "Only system uid can call informPollAlarmFired"); } ALOGD("StatsService::informPollAlarmFired succeeded"); // TODO: determine what services to poll and poll (or ask StatsCompanionService to poll) them. return Status::ok(); } Status Status StatsService::systemRunning() StatsService::systemRunning() { { Loading cmds/statsd/src/StatsService.h +4 −0 Original line number Original line Diff line number Diff line Loading @@ -49,6 +49,10 @@ public: virtual Status systemRunning(); virtual Status systemRunning(); virtual Status informAnomalyAlarmFired(); virtual Status informPollAlarmFired(); virtual status_t setProcessor(const sp<StatsLogProcessor>& main_processor); virtual status_t setProcessor(const sp<StatsLogProcessor>& main_processor); private: private: Loading core/java/android/os/IStatsCompanionService.aidl +3 −1 Original line number Original line Diff line number Diff line Loading @@ -20,7 +20,7 @@ package android.os; * Binder interface to communicate with the Java-based statistics service helper. * Binder interface to communicate with the Java-based statistics service helper. * {@hide} * {@hide} */ */ interface IStatsCompanionService { oneway interface IStatsCompanionService { /** /** * Register an alarm for anomaly detection to fire at the given timestamp (ms since epoch). * 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. * If anomaly alarm had already been registered, it will be replaced with the new timestamp. Loading @@ -28,6 +28,7 @@ interface IStatsCompanionService { * alarm is inexact. * alarm is inexact. */ */ void setAnomalyAlarm(long timestampMs); void setAnomalyAlarm(long timestampMs); /** Cancel any anomaly detection alarm. */ /** Cancel any anomaly detection alarm. */ void cancelAnomalyAlarm(); void cancelAnomalyAlarm(); Loading @@ -39,6 +40,7 @@ interface IStatsCompanionService { * and alarm is inexact. * and alarm is inexact. */ */ void setPollingAlarms(long timestampMs, long intervalMs); void setPollingAlarms(long timestampMs, long intervalMs); /** Cancel any repeating polling alarm. */ /** Cancel any repeating polling alarm. */ void cancelPollingAlarms(); void cancelPollingAlarms(); } } core/java/android/os/IStatsManager.aidl +13 −2 Original line number Original line Diff line number Diff line Loading @@ -17,12 +17,23 @@ package android.os; package android.os; /** /** * Binder interface to communicate with the statistics collection service. * Binder interface to communicate with the statistics management service. * {@hide} * {@hide} */ */ oneway interface IStatsManager { oneway interface IStatsManager { /** /** * Tell the incident daemon that the android system server is up and running. * Tell the stats daemon that the android system server is up and running. */ */ void systemRunning(); void systemRunning(); /** * Tells statsd that an anomaly may have occurred, so statsd can check whether this is so and * act accordingly. */ 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. */ void informPollAlarmFired(); } } services/core/java/com/android/server/stats/StatsCompanionService.java +24 −6 Original line number Original line Diff line number Diff line Loading @@ -24,6 +24,7 @@ import android.os.Binder; import android.os.IStatsCompanionService; import android.os.IStatsCompanionService; import android.os.IStatsManager; import android.os.IStatsManager; import android.os.Process; import android.os.Process; import android.os.RemoteException; import android.os.ServiceManager; import android.os.ServiceManager; import android.util.Slog; import android.util.Slog; Loading @@ -39,7 +40,7 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { private final Context mContext; private final Context mContext; private final AlarmManager mAlarmManager; private final AlarmManager mAlarmManager; private final IStatsManager mStatsd; private static IStatsManager sStatsd; private final PendingIntent mAnomalyAlarmIntent; private final PendingIntent mAnomalyAlarmIntent; private final PendingIntent mPollingAlarmIntent; private final PendingIntent mPollingAlarmIntent; Loading @@ -48,7 +49,14 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { @Override @Override public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) { Slog.i(TAG, "StatsCompanionService believes an anomaly has occurred."); Slog.i(TAG, "StatsCompanionService believes an anomaly has occurred."); // TODO: mStatsd.informAlarm(); // should be twoway so device won't sleep before acting? try { // TODO: should be twoway so device won't sleep before acting? getStatsdService().informAnomalyAlarmFired(); } catch (RemoteException e) { Slog.e(TAG, "failed to inform statsd of anomaly alarm firing", e); } catch (NullPointerException e) { Slog.e(TAG, "could not access statsd to inform it of anomaly alarm firing", e); } // AlarmManager releases its own wakelock here. // AlarmManager releases its own wakelock here. } } }; }; Loading @@ -57,7 +65,15 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { @Override @Override public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) { if (DEBUG) Slog.d(TAG, "Time to poll something."); if (DEBUG) Slog.d(TAG, "Time to poll something."); // TODO: mStatsd.poll(); // should be twoway so device won't sleep before acting? if (DEBUG) Slog.d(TAG, "Time to poll something."); try { // TODO: should be twoway so device won't sleep before acting? getStatsdService().informPollAlarmFired(); } catch (RemoteException e) { Slog.e(TAG, "failed to inform statsd of polling alarm firing",e); } catch (NullPointerException e) { Slog.e(TAG, "could not access statsd to inform it of polling alarm firing", e); } // AlarmManager releases its own wakelock here. // AlarmManager releases its own wakelock here. } } }; }; Loading @@ -71,13 +87,15 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { new Intent(mContext, AnomalyAlarmReceiver.class), 0); new Intent(mContext, AnomalyAlarmReceiver.class), 0); mPollingAlarmIntent = PendingIntent.getBroadcast(mContext, 0, mPollingAlarmIntent = PendingIntent.getBroadcast(mContext, 0, new Intent(mContext, PollingAlarmReceiver.class), 0); new Intent(mContext, PollingAlarmReceiver.class), 0); mStatsd = getStatsdService(); } } /** Returns the statsd IBinder service */ /** Returns the statsd IBinder service */ public static IStatsManager getStatsdService() { public static IStatsManager getStatsdService() { return IStatsManager.Stub.asInterface(ServiceManager.getService("statsd")); if (sStatsd != null) { return sStatsd; } sStatsd = IStatsManager.Stub.asInterface(ServiceManager.getService("stats")); return sStatsd; } } public static final class Lifecycle extends SystemService { public static final class Lifecycle extends SystemService { Loading Loading
cmds/statsd/src/StatsService.cpp +32 −0 Original line number Original line Diff line number Diff line Loading @@ -161,6 +161,38 @@ StatsService::doLoadConfig(FILE* in) } } } } Status StatsService::informAnomalyAlarmFired() { ALOGD("StatsService::informAnomalyAlarmFired was called"); if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) { return Status::fromExceptionCode(Status::EX_SECURITY, "Only system uid can call informAnomalyAlarmFired"); } ALOGD("StatsService::informAnomalyAlarmFired succeeded"); // TODO: check through all counters/timers and see if an anomaly has indeed occurred. return Status::ok(); } Status StatsService::informPollAlarmFired() { ALOGD("StatsService::informPollAlarmFired was called"); if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) { return Status::fromExceptionCode(Status::EX_SECURITY, "Only system uid can call informPollAlarmFired"); } ALOGD("StatsService::informPollAlarmFired succeeded"); // TODO: determine what services to poll and poll (or ask StatsCompanionService to poll) them. return Status::ok(); } Status Status StatsService::systemRunning() StatsService::systemRunning() { { Loading
cmds/statsd/src/StatsService.h +4 −0 Original line number Original line Diff line number Diff line Loading @@ -49,6 +49,10 @@ public: virtual Status systemRunning(); virtual Status systemRunning(); virtual Status informAnomalyAlarmFired(); virtual Status informPollAlarmFired(); virtual status_t setProcessor(const sp<StatsLogProcessor>& main_processor); virtual status_t setProcessor(const sp<StatsLogProcessor>& main_processor); private: private: Loading
core/java/android/os/IStatsCompanionService.aidl +3 −1 Original line number Original line Diff line number Diff line Loading @@ -20,7 +20,7 @@ package android.os; * Binder interface to communicate with the Java-based statistics service helper. * Binder interface to communicate with the Java-based statistics service helper. * {@hide} * {@hide} */ */ interface IStatsCompanionService { oneway interface IStatsCompanionService { /** /** * Register an alarm for anomaly detection to fire at the given timestamp (ms since epoch). * 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. * If anomaly alarm had already been registered, it will be replaced with the new timestamp. Loading @@ -28,6 +28,7 @@ interface IStatsCompanionService { * alarm is inexact. * alarm is inexact. */ */ void setAnomalyAlarm(long timestampMs); void setAnomalyAlarm(long timestampMs); /** Cancel any anomaly detection alarm. */ /** Cancel any anomaly detection alarm. */ void cancelAnomalyAlarm(); void cancelAnomalyAlarm(); Loading @@ -39,6 +40,7 @@ interface IStatsCompanionService { * and alarm is inexact. * and alarm is inexact. */ */ void setPollingAlarms(long timestampMs, long intervalMs); void setPollingAlarms(long timestampMs, long intervalMs); /** Cancel any repeating polling alarm. */ /** Cancel any repeating polling alarm. */ void cancelPollingAlarms(); void cancelPollingAlarms(); } }
core/java/android/os/IStatsManager.aidl +13 −2 Original line number Original line Diff line number Diff line Loading @@ -17,12 +17,23 @@ package android.os; package android.os; /** /** * Binder interface to communicate with the statistics collection service. * Binder interface to communicate with the statistics management service. * {@hide} * {@hide} */ */ oneway interface IStatsManager { oneway interface IStatsManager { /** /** * Tell the incident daemon that the android system server is up and running. * Tell the stats daemon that the android system server is up and running. */ */ void systemRunning(); void systemRunning(); /** * Tells statsd that an anomaly may have occurred, so statsd can check whether this is so and * act accordingly. */ 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. */ void informPollAlarmFired(); } }
services/core/java/com/android/server/stats/StatsCompanionService.java +24 −6 Original line number Original line Diff line number Diff line Loading @@ -24,6 +24,7 @@ import android.os.Binder; import android.os.IStatsCompanionService; import android.os.IStatsCompanionService; import android.os.IStatsManager; import android.os.IStatsManager; import android.os.Process; import android.os.Process; import android.os.RemoteException; import android.os.ServiceManager; import android.os.ServiceManager; import android.util.Slog; import android.util.Slog; Loading @@ -39,7 +40,7 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { private final Context mContext; private final Context mContext; private final AlarmManager mAlarmManager; private final AlarmManager mAlarmManager; private final IStatsManager mStatsd; private static IStatsManager sStatsd; private final PendingIntent mAnomalyAlarmIntent; private final PendingIntent mAnomalyAlarmIntent; private final PendingIntent mPollingAlarmIntent; private final PendingIntent mPollingAlarmIntent; Loading @@ -48,7 +49,14 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { @Override @Override public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) { Slog.i(TAG, "StatsCompanionService believes an anomaly has occurred."); Slog.i(TAG, "StatsCompanionService believes an anomaly has occurred."); // TODO: mStatsd.informAlarm(); // should be twoway so device won't sleep before acting? try { // TODO: should be twoway so device won't sleep before acting? getStatsdService().informAnomalyAlarmFired(); } catch (RemoteException e) { Slog.e(TAG, "failed to inform statsd of anomaly alarm firing", e); } catch (NullPointerException e) { Slog.e(TAG, "could not access statsd to inform it of anomaly alarm firing", e); } // AlarmManager releases its own wakelock here. // AlarmManager releases its own wakelock here. } } }; }; Loading @@ -57,7 +65,15 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { @Override @Override public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) { if (DEBUG) Slog.d(TAG, "Time to poll something."); if (DEBUG) Slog.d(TAG, "Time to poll something."); // TODO: mStatsd.poll(); // should be twoway so device won't sleep before acting? if (DEBUG) Slog.d(TAG, "Time to poll something."); try { // TODO: should be twoway so device won't sleep before acting? getStatsdService().informPollAlarmFired(); } catch (RemoteException e) { Slog.e(TAG, "failed to inform statsd of polling alarm firing",e); } catch (NullPointerException e) { Slog.e(TAG, "could not access statsd to inform it of polling alarm firing", e); } // AlarmManager releases its own wakelock here. // AlarmManager releases its own wakelock here. } } }; }; Loading @@ -71,13 +87,15 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { new Intent(mContext, AnomalyAlarmReceiver.class), 0); new Intent(mContext, AnomalyAlarmReceiver.class), 0); mPollingAlarmIntent = PendingIntent.getBroadcast(mContext, 0, mPollingAlarmIntent = PendingIntent.getBroadcast(mContext, 0, new Intent(mContext, PollingAlarmReceiver.class), 0); new Intent(mContext, PollingAlarmReceiver.class), 0); mStatsd = getStatsdService(); } } /** Returns the statsd IBinder service */ /** Returns the statsd IBinder service */ public static IStatsManager getStatsdService() { public static IStatsManager getStatsdService() { return IStatsManager.Stub.asInterface(ServiceManager.getService("statsd")); if (sStatsd != null) { return sStatsd; } sStatsd = IStatsManager.Stub.asInterface(ServiceManager.getService("stats")); return sStatsd; } } public static final class Lifecycle extends SystemService { public static final class Lifecycle extends SystemService { Loading