• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 android.timezone;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 
22 import com.android.icu.Flags;
23 
24 import java.util.Objects;
25 
26 /**
27  * A class that can find telephony network information loaded via {@link TelephonyLookup}.
28  *
29  * @hide
30  */
31 public final class TelephonyNetworkFinder {
32 
33     @NonNull
34     private final com.android.i18n.timezone.TelephonyNetworkFinder mDelegate;
35 
TelephonyNetworkFinder(com.android.i18n.timezone.TelephonyNetworkFinder delegate)36     TelephonyNetworkFinder(com.android.i18n.timezone.TelephonyNetworkFinder delegate) {
37         mDelegate = Objects.requireNonNull(delegate);
38     }
39 
40     /**
41      * Returns information held about a specific MCC + MNC combination. It is expected for this
42      * method to return {@code null}. Only known, unusual networks will typically have information
43      * returned, e.g. if they operate in countries other than the one suggested by their MCC.
44      */
45     @Nullable
findNetworkByMccMnc(@onNull String mcc, @NonNull String mnc)46     public TelephonyNetwork findNetworkByMccMnc(@NonNull String mcc, @NonNull String mnc) {
47         Objects.requireNonNull(mcc);
48         Objects.requireNonNull(mnc);
49 
50         com.android.i18n.timezone.TelephonyNetwork telephonyNetworkDelegate =
51                 mDelegate.findNetworkByMccMnc(mcc, mnc);
52         return telephonyNetworkDelegate != null
53                 ? new TelephonyNetwork(telephonyNetworkDelegate) : null;
54     }
55 
56     /**
57      * Returns the countries where a given MCC is in use.
58      */
59     @Nullable
findCountriesByMcc(@onNull String mcc)60     public MobileCountries findCountriesByMcc(@NonNull String mcc) {
61         if (!Flags.telephonyLookupMccExtension()) {
62             return null;
63         }
64         Objects.requireNonNull(mcc);
65 
66         com.android.i18n.timezone.MobileCountries countriesByMcc =
67                 mDelegate.findCountriesByMcc(mcc);
68         return countriesByMcc != null ? new MobileCountries(countriesByMcc) : null;
69     }
70 }
71