• 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 
17 package com.android.wifitrackerlib;
18 
19 import android.app.admin.DevicePolicyManager;
20 import android.content.Context;
21 import android.os.UserManager;
22 import android.provider.DeviceConfig;
23 import android.util.ArraySet;
24 
25 import androidx.annotation.NonNull;
26 
27 import java.util.Set;
28 
29 /**
30  * Wrapper class for commonly referenced objects and static data.
31  */
32 public class WifiTrackerInjector {
33     private static final String DEVICE_CONFIG_NAMESPACE = "wifi";
34 
35     @NonNull private final Context mContext;
36     private final boolean mIsDemoMode;
37     private final UserManager mUserManager;
38     private final DevicePolicyManager mDevicePolicyManager;
39     @NonNull private final Set<String> mNoAttributionAnnotationPackages;
40 
41     // TODO(b/201571677): Migrate the rest of the common objects to WifiTrackerInjector.
WifiTrackerInjector(@onNull Context context)42     WifiTrackerInjector(@NonNull Context context) {
43         mContext = context;
44         mIsDemoMode = NonSdkApiWrapper.isDemoMode(context);
45         mUserManager = context.getSystemService(UserManager.class);
46         mDevicePolicyManager = context.getSystemService(DevicePolicyManager.class);
47         mNoAttributionAnnotationPackages = new ArraySet<>();
48         String[] noAttributionAnnotationPackages = context.getString(
49                 R.string.wifitrackerlib_no_attribution_annotation_packages).split(",");
50         for (int i = 0; i < noAttributionAnnotationPackages.length; i++) {
51             mNoAttributionAnnotationPackages.add(noAttributionAnnotationPackages[i]);
52         }
53     }
54 
getContext()55     @NonNull Context getContext() {
56         return mContext;
57     }
58 
isDemoMode()59     boolean isDemoMode() {
60         return mIsDemoMode;
61     }
62 
getUserManager()63     public UserManager getUserManager() {
64         return mUserManager;
65     }
66 
getDevicePolicyManager()67     public DevicePolicyManager getDevicePolicyManager() {
68         return mDevicePolicyManager;
69     }
70 
71     /**
72      * Returns the set of package names which we should not show attribution annotations for.
73      */
getNoAttributionAnnotationPackages()74     @NonNull Set<String> getNoAttributionAnnotationPackages() {
75         return mNoAttributionAnnotationPackages;
76     }
77 
isSharedConnectivityFeatureEnabled()78     public boolean isSharedConnectivityFeatureEnabled() {
79         return DeviceConfig.getBoolean(DEVICE_CONFIG_NAMESPACE,
80                 "shared_connectivity_enabled", false);
81     }
82 }
83