ConnectivityMetricsLogger.java revision 02b3e6bfc5bbd5f1a8ce1ce68976e59142073b6f
1/* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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. 15 */ 16package android.net; 17 18import android.os.Parcelable; 19import android.os.RemoteException; 20import android.os.ServiceManager; 21import android.util.Log; 22 23/** {@hide} */ 24public class ConnectivityMetricsLogger { 25 private static String TAG = "ConnectivityMetricsLogger"; 26 private static final boolean DBG = true; 27 28 public static final String CONNECTIVITY_METRICS_LOGGER_SERVICE = "connectivity_metrics_logger"; 29 30 // Component Tags 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; 36 37 private IConnectivityMetricsLogger mService; 38 39 public ConnectivityMetricsLogger() { 40 mService = IConnectivityMetricsLogger.Stub.asInterface(ServiceManager.getService( 41 CONNECTIVITY_METRICS_LOGGER_SERVICE)); 42 } 43 44 public void logEvent(long timestamp, int componentTag, int eventTag, Parcelable data) { 45 if (mService == null) { 46 if (DBG) { 47 Log.d(TAG, "logEvent(" + componentTag + "," + eventTag + ") Service not ready"); 48 } 49 } else { 50 try { 51 mService.logEvent(new ConnectivityMetricsEvent(timestamp, componentTag, eventTag, data)); 52 } catch (RemoteException e) { 53 Log.e(TAG, "Error logging event " + e.getMessage()); 54 } 55 } 56 } 57} 58