• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.voicemail.impl;
18 
19 import android.annotation.TargetApi;
20 import android.content.Context;
21 import android.os.Build.VERSION_CODES;
22 import android.telecom.PhoneAccountHandle;
23 import android.telephony.TelephonyManager;
24 import com.google.auto.value.AutoValue;
25 
26 /** Identifies a carrier. */
27 @AutoValue
28 @TargetApi(VERSION_CODES.O)
29 @SuppressWarnings("missingpermission")
30 public abstract class CarrierIdentifier {
31 
mccMnc()32   public abstract String mccMnc();
33 
34   /**
35    * Group ID Level 1. Used to identify MVNO(Mobile Virtual Network Operators) who subleases other
36    * carrier's network and share their mccMnc. MVNO should have a GID1 different from the host.
37    */
gid1()38   public abstract String gid1();
39 
40   /** Builder for the matcher */
41   @AutoValue.Builder
42   public abstract static class Builder {
43 
setMccMnc(String mccMnc)44     public abstract Builder setMccMnc(String mccMnc);
45 
setGid1(String gid1)46     public abstract Builder setGid1(String gid1);
47 
build()48     public abstract CarrierIdentifier build();
49   }
50 
builder()51   public static Builder builder() {
52     return new AutoValue_CarrierIdentifier.Builder().setGid1("");
53   }
54 
forHandle( Context context, PhoneAccountHandle phoneAccountHandle)55   public static CarrierIdentifier forHandle(
56       Context context, PhoneAccountHandle phoneAccountHandle) {
57     TelephonyManager telephonyManager =
58         context
59             .getSystemService(TelephonyManager.class)
60             .createForPhoneAccountHandle(phoneAccountHandle);
61     if (telephonyManager == null) {
62       throw new IllegalArgumentException("Invalid PhoneAccountHandle");
63     }
64     String gid1 = telephonyManager.getGroupIdLevel1();
65     if (gid1 == null) {
66       gid1 = "";
67     }
68 
69     return builder().setMccMnc(telephonyManager.getSimOperator()).setGid1(gid1).build();
70   }
71 }
72