public static final String DATA_KEY_EVENTS_COUNT = "count";
- /** {@hide} */ protected final IConnectivityMetricsLogger mService;
+ /** {@hide} */ protected IConnectivityMetricsLogger mService;
/** {@hide} */ protected volatile long mServiceUnblockedTimestampMillis;
private int mNumSkippedEvents;
public ConnectivityMetricsLogger() {
+ // TODO: consider not initializing mService in constructor
this(IConnectivityMetricsLogger.Stub.asInterface(
ServiceManager.getService(CONNECTIVITY_METRICS_LOGGER_SERVICE)));
}
mService = service;
}
+ /** {@hide} */
+ protected boolean checkLoggerService() {
+ if (mService != null) {
+ return true;
+ }
+ // Two threads racing here will write the same pointer because getService
+ // is idempotent once MetricsLoggerService is initialized.
+ mService = IConnectivityMetricsLogger.Stub.asInterface(
+ ServiceManager.getService(CONNECTIVITY_METRICS_LOGGER_SERVICE));
+ return mService != null;
+ }
+
/**
* Log a ConnectivityMetricsEvent.
*
*/
public class IpConnectivityLog extends ConnectivityMetricsLogger {
private static String TAG = "IpConnectivityMetricsLogger";
- private static final boolean DBG = false;
+ private static final boolean DBG = true;
public IpConnectivityLog() {
// mService initialized in super constructor.
* @return true if the event was successfully logged.
*/
public boolean log(long timestamp, Parcelable data) {
- if (mService == null) {
+ if (!checkLoggerService()) {
if (DBG) {
- Log.d(TAG, CONNECTIVITY_METRICS_LOGGER_SERVICE + " service not ready");
+ Log.d(TAG, CONNECTIVITY_METRICS_LOGGER_SERVICE + " service was not ready");
}
return false;
}