• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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.car.settings.location;
18 
19 import android.car.drivingstate.CarUxRestrictions;
20 import android.content.Context;
21 import android.content.pm.PackageManager;
22 import android.location.LocationManager;
23 import android.os.Process;
24 
25 import com.android.car.settings.common.FragmentController;
26 import com.android.car.settings.common.LogicalPreferenceGroup;
27 import com.android.car.settings.common.PreferenceController;
28 import com.android.car.ui.preference.CarUiTwoActionTextPreference;
29 import com.android.internal.annotations.VisibleForTesting;
30 
31 import java.util.Collection;
32 
33 /**
34  * Displays a list of ADAS apps with their privacy policy and a link to their location permission
35  * settings.
36  */
37 public final class AdasPrivacyPolicyDisclosurePreferenceController
38         extends PreferenceController<LogicalPreferenceGroup> {
39 
40     private final PackageManager mPackageManager;
41     private final LocationManager mLocationManager;
42 
AdasPrivacyPolicyDisclosurePreferenceController( Context context, String preferenceKey, FragmentController fragmentController, CarUxRestrictions uxRestrictions)43     public AdasPrivacyPolicyDisclosurePreferenceController(
44             Context context,
45             String preferenceKey,
46             FragmentController fragmentController,
47             CarUxRestrictions uxRestrictions) {
48         this(
49                 context,
50                 preferenceKey,
51                 fragmentController,
52                 uxRestrictions,
53                 context.getPackageManager(),
54                 context.getSystemService(LocationManager.class));
55     }
56 
57     @VisibleForTesting
AdasPrivacyPolicyDisclosurePreferenceController( Context context, String preferenceKey, FragmentController fragmentController, CarUxRestrictions uxRestrictions, PackageManager packageManager, LocationManager locationManager)58     public AdasPrivacyPolicyDisclosurePreferenceController(
59             Context context,
60             String preferenceKey,
61             FragmentController fragmentController,
62             CarUxRestrictions uxRestrictions,
63             PackageManager packageManager,
64             LocationManager locationManager) {
65         super(context, preferenceKey, fragmentController, uxRestrictions);
66         mPackageManager = packageManager;
67         mLocationManager = locationManager;
68     }
69 
70     @Override
getPreferenceType()71     protected Class<LogicalPreferenceGroup> getPreferenceType() {
72         return LogicalPreferenceGroup.class;
73     }
74 
75     @Override
updateState(LogicalPreferenceGroup preference)76     public void updateState(LogicalPreferenceGroup preference) {
77         super.updateState(preference);
78         loadAppsWithLocationPermission();
79     }
80 
loadAppsWithLocationPermission()81     private void loadAppsWithLocationPermission() {
82         getPreference().removeAll();
83 
84         Collection<String> adasApps = mLocationManager.getAdasAllowlist().getPackages();
85         for (String adasApp : adasApps) {
86             CarUiTwoActionTextPreference perf =
87                     AdasPrivacyPolicyUtil.createPrivacyPolicyPreference(
88                             getContext(), mPackageManager, adasApp, Process.myUserHandle());
89             if (perf != null) {
90                 getPreference().addPreference(perf);
91             }
92         }
93     }
94 }
95