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.Manifest; 20 import android.car.drivingstate.CarUxRestrictions; 21 import android.content.Context; 22 import android.content.pm.PackageManager; 23 import android.os.Process; 24 25 import com.android.car.settings.Flags; 26 import com.android.car.settings.common.FragmentController; 27 import com.android.car.settings.common.LogicalPreferenceGroup; 28 import com.android.car.settings.privacy.RequiredInfotainmentAppsUtils; 29 import com.android.car.ui.preference.CarUiTwoActionTextPreference; 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 LocationStateListenerBasePreferenceController<LogicalPreferenceGroup> { 39 private final PackageManager mPackageManager; 40 AdasPrivacyPolicyDisclosurePreferenceController( Context context, String preferenceKey, FragmentController fragmentController, CarUxRestrictions uxRestrictions)41 public AdasPrivacyPolicyDisclosurePreferenceController( 42 Context context, 43 String preferenceKey, 44 FragmentController fragmentController, 45 CarUxRestrictions uxRestrictions) { 46 super(context, preferenceKey, fragmentController, uxRestrictions); 47 mPackageManager = context.getPackageManager(); 48 } 49 50 @Override getPreferenceType()51 protected Class<LogicalPreferenceGroup> getPreferenceType() { 52 return LogicalPreferenceGroup.class; 53 } 54 55 @Override onCreateInternal()56 protected void onCreateInternal() { 57 if (Flags.requiredInfotainmentAppsSettingsPage()) { 58 addDefaultBypassLocationStateListener(); 59 } 60 } 61 62 @Override updateState(LogicalPreferenceGroup preference)63 protected void updateState(LogicalPreferenceGroup preference) { 64 loadAppsWithLocationPermission(); 65 } 66 loadAppsWithLocationPermission()67 private void loadAppsWithLocationPermission() { 68 getPreference().removeAll(); 69 70 Collection<String> adasApps = getLocationManager().getAdasAllowlist().getPackages(); 71 boolean showSummary = getLocationManager().isAdasGnssLocationEnabled(); 72 for (String adasApp : adasApps) { 73 CarUiTwoActionTextPreference preference; 74 if (com.android.internal.camera.flags.Flags.cameraPrivacyAllowlist() 75 && Flags.requiredInfotainmentAppsSettingsPage()) { 76 preference = RequiredInfotainmentAppsUtils.createRequiredAppPreference( 77 getContext(), mPackageManager, adasApp, Process.myUserHandle(), 78 Manifest.permission_group.LOCATION, showSummary); 79 } else { 80 preference = AdasPrivacyPolicyUtil.createPrivacyPolicyPreference( 81 getContext(), mPackageManager, adasApp, Process.myUserHandle()); 82 } 83 if (preference != null) { 84 getPreference().addPreference(preference); 85 } 86 } 87 } 88 } 89