• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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.CARRIER_ID_MISMATCH_REPORTED;
20 import static com.android.internal.telephony.TelephonyStatsLog.CARRIER_ID_TABLE_UPDATED;
21 
22 import com.android.internal.telephony.PhoneFactory;
23 import com.android.internal.telephony.TelephonyStatsLog;
24 import com.android.internal.telephony.nano.PersistAtomsProto.CarrierIdMismatch;
25 import com.android.telephony.Rlog;
26 
27 /** Metrics for the carrier id matching. */
28 public class CarrierIdMatchStats {
29     private static final String TAG = CarrierIdMatchStats.class.getSimpleName();
30 
CarrierIdMatchStats()31     private CarrierIdMatchStats() { }
32 
33     /** Generate metrics when carrier ID mismatch occurs. */
onCarrierIdMismatch( int cid, String mccMnc, String gid1, String spn, String pnn)34     public static void onCarrierIdMismatch(
35             int cid, String mccMnc, String gid1, String spn, String pnn) {
36         PersistAtomsStorage storage = PhoneFactory.getMetricsCollector().getAtomsStorage();
37 
38         CarrierIdMismatch carrierIdMismatch = new CarrierIdMismatch();
39         carrierIdMismatch.mccMnc = nullToEmpty(mccMnc);
40         carrierIdMismatch.gid1 = nullToEmpty(gid1);
41         carrierIdMismatch.spn = nullToEmpty(spn);
42         carrierIdMismatch.pnn = carrierIdMismatch.spn.isEmpty() ? nullToEmpty(pnn) : "";
43 
44         // Add to storage and generate atom only if it was added (new SIM card).
45         boolean isAdded = storage.addCarrierIdMismatch(carrierIdMismatch);
46         if (isAdded) {
47             Rlog.d(TAG, "New carrier ID mismatch event: " + carrierIdMismatch.toString());
48             TelephonyStatsLog.write(CARRIER_ID_MISMATCH_REPORTED, cid, mccMnc, gid1, spn, pnn);
49         }
50     }
51 
52     /** Generate metrics for the carrier ID table version. */
sendCarrierIdTableVersion(int carrierIdTableVersion)53     public static void sendCarrierIdTableVersion(int carrierIdTableVersion) {
54         PersistAtomsStorage storage = PhoneFactory.getMetricsCollector().getAtomsStorage();
55 
56         if (storage.setCarrierIdTableVersion(carrierIdTableVersion)) {
57             Rlog.d(TAG, "New carrier ID table version: " + carrierIdTableVersion);
58             TelephonyStatsLog.write(CARRIER_ID_TABLE_UPDATED, carrierIdTableVersion);
59         }
60     }
61 
nullToEmpty(String string)62     private static String nullToEmpty(String string) {
63         return string != null ? string : "";
64     }
65 }
66