2 * Copyright (C) 2016 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 import android.os.Parcelable;
19 import android.os.RemoteException;
20 import android.os.ServiceManager;
21 import android.util.Log;
24 public class ConnectivityMetricsLogger {
25 private static String TAG = "ConnectivityMetricsLogger";
26 private static final boolean DBG = true;
28 public static final String CONNECTIVITY_METRICS_LOGGER_SERVICE = "connectivity_metrics_logger";
31 public static final int COMPONENT_TAG_CONNECTIVITY = 1;
32 public static final int COMPONENT_TAG_BLUETOOTH = 2;
33 public static final int COMPONENT_TAG_WIFI = 3;
34 public static final int COMPONENT_TAG_TELECOM = 4;
35 public static final int COMPONENT_TAG_TELEPHONY = 5;
37 private IConnectivityMetricsLogger mService;
39 public ConnectivityMetricsLogger() {
40 mService = IConnectivityMetricsLogger.Stub.asInterface(ServiceManager.getService(
41 CONNECTIVITY_METRICS_LOGGER_SERVICE));
44 public void logEvent(long timestamp, int componentTag, int eventTag, Parcelable data) {
45 if (mService == null) {
47 Log.d(TAG, "logEvent(" + componentTag + "," + eventTag + ") Service not ready");
51 mService.logEvent(new ConnectivityMetricsEvent(timestamp, componentTag, eventTag, data));
52 } catch (RemoteException e) {
53 Log.e(TAG, "Error logging event " + e.getMessage());