1 /* 2 * Copyright (C) 2023 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.internal.telephony.metrics; 18 19 import static com.android.internal.telephony.TelephonyStatsLog.CELLULAR_RADIO_POWER_STATE_CHANGED; 20 import static com.android.internal.telephony.TelephonyStatsLog.CELLULAR_RADIO_POWER_STATE_CHANGED__STATE__RADIO_POWER_STATE_OFF; 21 import static com.android.internal.telephony.TelephonyStatsLog.CELLULAR_RADIO_POWER_STATE_CHANGED__STATE__RADIO_POWER_STATE_ON; 22 import static com.android.internal.telephony.TelephonyStatsLog.CELLULAR_RADIO_POWER_STATE_CHANGED__STATE__RADIO_POWER_STATE_UNAVAILABLE; 23 import static com.android.internal.telephony.TelephonyStatsLog.CELLULAR_RADIO_POWER_STATE_CHANGED__STATE__RADIO_POWER_STATE_UNKNOWN; 24 25 import android.telephony.Annotation; 26 import android.telephony.TelephonyManager; 27 28 import com.android.internal.telephony.TelephonyStatsLog; 29 30 /** Logs cellular radio power state changes to statsd */ 31 public class RadioPowerStateStats { 32 33 /** Logs cellular radio power state changes to statsd */ onRadioStateChanged(@nnotation.RadioPowerState int state)34 public static void onRadioStateChanged(@Annotation.RadioPowerState int state) { 35 TelephonyStatsLog.write(CELLULAR_RADIO_POWER_STATE_CHANGED, 36 radioPowerStateToProtoEnum(state)); 37 } 38 radioPowerStateToProtoEnum(@nnotation.RadioPowerState int state)39 private static int radioPowerStateToProtoEnum(@Annotation.RadioPowerState int state) { 40 switch (state) { 41 case TelephonyManager.RADIO_POWER_OFF: 42 return CELLULAR_RADIO_POWER_STATE_CHANGED__STATE__RADIO_POWER_STATE_OFF; 43 case TelephonyManager.RADIO_POWER_ON: 44 return CELLULAR_RADIO_POWER_STATE_CHANGED__STATE__RADIO_POWER_STATE_ON; 45 case TelephonyManager.RADIO_POWER_UNAVAILABLE: 46 return CELLULAR_RADIO_POWER_STATE_CHANGED__STATE__RADIO_POWER_STATE_UNAVAILABLE; 47 default: 48 return CELLULAR_RADIO_POWER_STATE_CHANGED__STATE__RADIO_POWER_STATE_UNKNOWN; 49 } 50 } 51 52 } 53