1 /* 2 * Copyright (C) 2021 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 */ 16 17 package com.android.imsserviceentitlement.utils; 18 19 import static android.os.SystemClock.uptimeMillis; 20 21 import static com.android.imsserviceentitlement.ImsServiceEntitlementStatsLog.IMS_SERVICE_ENTITLEMENT_UPDATED; 22 import static com.android.imsserviceentitlement.ImsServiceEntitlementStatsLog.IMS_SERVICE_ENTITLEMENT_UPDATED__PURPOSE__UNKNOWN_PURPOSE; 23 24 import com.android.imsserviceentitlement.ImsServiceEntitlementStatsLog; 25 26 /** Utility for writing the metrics logs. */ 27 public class MetricsLogger { 28 private final TelephonyUtils mTelephonyUtils; 29 30 private int mPurpose = IMS_SERVICE_ENTITLEMENT_UPDATED__PURPOSE__UNKNOWN_PURPOSE; 31 private long mStartTime = uptimeMillis(); 32 MetricsLogger(TelephonyUtils telephonyUtils)33 public MetricsLogger(TelephonyUtils telephonyUtils) { 34 mTelephonyUtils = telephonyUtils; 35 } 36 37 /** Starts the log session for the purpose as well as record the start time. */ start(int purpose)38 public void start(int purpose) { 39 mStartTime = uptimeMillis(); 40 mPurpose = purpose; 41 } 42 43 /** Writes the metrics log. */ write(int appId, int appResult)44 public void write(int appId, int appResult) { 45 ImsServiceEntitlementStatsLog.write( 46 IMS_SERVICE_ENTITLEMENT_UPDATED, 47 mTelephonyUtils.getCarrierId(), 48 mTelephonyUtils.getSpecificCarrierId(), 49 mPurpose, 50 appId, 51 appResult, 52 uptimeMillis() - mStartTime); 53 } 54 } 55