• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package com.google.android.car.networking.preferenceupdater.components;
17 
18 import static android.net.OemNetworkPreferences.OEM_NETWORK_PREFERENCE_OEM_PAID;
19 import static android.net.OemNetworkPreferences.OEM_NETWORK_PREFERENCE_OEM_PAID_NO_FALLBACK;
20 import static android.net.OemNetworkPreferences.OEM_NETWORK_PREFERENCE_OEM_PAID_ONLY;
21 import static android.net.OemNetworkPreferences.OEM_NETWORK_PREFERENCE_OEM_PRIVATE_ONLY;
22 
23 import android.annotation.NonNull;
24 import android.content.Context;
25 import android.util.ArraySet;
26 
27 import com.google.android.car.networking.preferenceupdater.R;
28 
29 import java.util.Arrays;
30 import java.util.Set;
31 
32 /** Maintains list of applications per OEM network preference. Singleton class. */
33 public final class OemAppsManager {
getDefaultAppsFor(@onNull Context ctx, int type)34     public static Set<String> getDefaultAppsFor(@NonNull Context ctx, int type) {
35         switch (type) {
36             case OEM_NETWORK_PREFERENCE_OEM_PAID:
37                 return getRes(ctx, R.array.config_network_preference_oem_paid_apps);
38             case OEM_NETWORK_PREFERENCE_OEM_PAID_NO_FALLBACK:
39                 return getRes(ctx, R.array.config_network_preference_oem_paid_no_fallback_apps);
40             case OEM_NETWORK_PREFERENCE_OEM_PAID_ONLY:
41                 return getRes(ctx, R.array.config_network_preference_oem_paid_only);
42             case OEM_NETWORK_PREFERENCE_OEM_PRIVATE_ONLY:
43                 return getRes(ctx, R.array.config_network_preference_oem_private_only);
44             default:
45                 throw new IllegalArgumentException("Unknown OEM_NETWORK_PREFERENCE type: " + type);
46         }
47     }
48 
getRes(Context ctx, int resId)49     private static ArraySet<String> getRes(Context ctx, int resId) {
50         return new ArraySet<String>(Arrays.asList(ctx.getResources().getStringArray(resId)));
51     }
52 }
53