• 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.util.ArraySet;
23 
24 import androidx.annotation.NonNull;
25 
26 import java.util.Set;
27 
28 /**
29  * Wrapper class for commonly referenced objects and static data.
30  */
31 class WifiTrackerInjector {
32     private final boolean mIsDemoMode;
33     private final UserManager mUserManager;
34     private final DevicePolicyManager mDevicePolicyManager;
35     @NonNull private final Set<String> mNoAttributionAnnotationPackages;
36 
37     // TODO(b/201571677): Migrate the rest of the common objects to WifiTrackerInjector.
WifiTrackerInjector(@onNull Context context)38     WifiTrackerInjector(@NonNull Context context) {
39         mIsDemoMode = NonSdkApiWrapper.isDemoMode(context);
40         mUserManager = context.getSystemService(UserManager.class);
41         mDevicePolicyManager = context.getSystemService(DevicePolicyManager.class);
42         mNoAttributionAnnotationPackages = new ArraySet<>();
43         String[] noAttributionAnnotationPackages = context.getString(
44                 R.string.wifitrackerlib_no_attribution_annotation_packages).split(",");
45         for (int i = 0; i < noAttributionAnnotationPackages.length; i++) {
46             mNoAttributionAnnotationPackages.add(noAttributionAnnotationPackages[i]);
47         }
48     }
49 
isDemoMode()50     boolean isDemoMode() {
51         return mIsDemoMode;
52     }
53 
getUserManager()54     public UserManager getUserManager() {
55         return mUserManager;
56     }
57 
getDevicePolicyManager()58     public DevicePolicyManager getDevicePolicyManager() {
59         return mDevicePolicyManager;
60     }
61 
62     /**
63      * Returns the set of package names which we should not show attribution annotations for.
64      */
getNoAttributionAnnotationPackages()65     @NonNull Set<String> getNoAttributionAnnotationPackages() {
66         return mNoAttributionAnnotationPackages;
67     }
68 }
69