• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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.Manifest;
20 import android.car.drivingstate.CarUxRestrictions;
21 import android.content.Context;
22 import android.content.pm.PackageInfo;
23 import android.content.pm.PackageManager;
24 import android.os.Process;
25 import android.os.UserHandle;
26 
27 import com.android.car.settings.common.FragmentController;
28 import com.android.car.settings.common.LogicalPreferenceGroup;
29 import com.android.car.settings.privacy.PermissionUtils;
30 import com.android.car.settings.privacy.RequiredInfotainmentAppsUtils;
31 import com.android.car.ui.preference.CarUiPreference;
32 
33 import java.util.Collection;
34 import java.util.List;
35 
36 /**
37  * Displays a list of location infotainment apps and a link to their location permission
38  * settings.
39  */
40 public final class LocationInfotainmentAppsPreferenceController extends
41         LocationStateListenerBasePreferenceController<LogicalPreferenceGroup> {
42     private final PackageManager mPackageManager;
43 
LocationInfotainmentAppsPreferenceController( Context context, String preferenceKey, FragmentController fragmentController, CarUxRestrictions uxRestrictions)44     public LocationInfotainmentAppsPreferenceController(
45             Context context,
46             String preferenceKey,
47             FragmentController fragmentController,
48             CarUxRestrictions uxRestrictions) {
49         super(context, preferenceKey, fragmentController, uxRestrictions);
50         mPackageManager = context.getPackageManager();
51     }
52 
53     @Override
getPreferenceType()54     protected Class<LogicalPreferenceGroup> getPreferenceType() {
55         return LogicalPreferenceGroup.class;
56     }
57 
58     @Override
onCreateInternal()59     protected void onCreateInternal() {
60         addDefaultMainLocationStateListener();
61     }
62 
63     @Override
updateState(LogicalPreferenceGroup preference)64     protected void updateState(LogicalPreferenceGroup preference) {
65         loadInfotainmentAppsWithLocationPermission();
66     }
67 
loadInfotainmentAppsWithLocationPermission()68     private void loadInfotainmentAppsWithLocationPermission() {
69         getPreference().removeAll();
70 
71         UserHandle userHandle = Process.myUserHandle();
72         List<PackageInfo> packagesWithPermissions = PermissionUtils.getPackagesWithPermissionGroup(
73                 getContext(), Manifest.permission_group.LOCATION, userHandle,
74                 /* showSystem= */ false);
75 
76         Collection<String> locationAdasAllowlist =
77                 getLocationManager().getAdasAllowlist().getPackages();
78         boolean showSummary = getLocationManager().isLocationEnabled();
79         for (PackageInfo packageInfo : packagesWithPermissions) {
80             if (locationAdasAllowlist.contains(packageInfo.packageName)) {
81                 continue;
82             }
83             CarUiPreference preference =
84                     RequiredInfotainmentAppsUtils.createInfotainmentAppPreference(
85                             getContext(), mPackageManager, packageInfo.packageName, userHandle,
86                             Manifest.permission_group.LOCATION, showSummary);
87             if (preference != null) {
88                 getPreference().addPreference(preference);
89             }
90         }
91     }
92 }
93