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.privacy; 18 19 import android.Manifest; 20 import android.annotation.FlaggedApi; 21 import android.car.drivingstate.CarUxRestrictions; 22 import android.content.Context; 23 import android.content.pm.PackageManager; 24 import android.hardware.SensorPrivacyManager; 25 import android.os.Process; 26 27 import com.android.car.settings.R; 28 import com.android.car.settings.common.FragmentController; 29 import com.android.car.settings.common.Logger; 30 import com.android.car.settings.common.LogicalPreferenceGroup; 31 import com.android.car.settings.common.PreferenceController; 32 import com.android.car.ui.preference.CarUiTwoActionTextPreference; 33 import com.android.internal.annotations.VisibleForTesting; 34 import com.android.internal.camera.flags.Flags; 35 36 import java.util.List; 37 38 /** 39 * Displays a list of apps which are required for driving with their privacy policy and a 40 * link to their camera permission settings. 41 */ 42 @FlaggedApi(Flags.FLAG_CAMERA_PRIVACY_ALLOWLIST) 43 public final class CameraRequiredAppsPreferenceController 44 extends PreferenceController<LogicalPreferenceGroup> { 45 46 private static final Logger LOG = new Logger(CameraRequiredAppsPreferenceController.class); 47 private static final String PRIVACY_POLICY_KEY = "privacy_policy"; 48 private final PackageManager mPackageManager; 49 private final SensorPrivacyManager mSensorPrivacyManager; 50 private List<String> mCameraPrivacyAllowlist; 51 CameraRequiredAppsPreferenceController(Context context, String preferenceKey, FragmentController fragmentController, CarUxRestrictions uxRestrictions)52 public CameraRequiredAppsPreferenceController(Context context, String preferenceKey, 53 FragmentController fragmentController, CarUxRestrictions uxRestrictions) { 54 this(context, preferenceKey, fragmentController, uxRestrictions, 55 context.getPackageManager(), SensorPrivacyManager.getInstance(context)); 56 } 57 58 @VisibleForTesting CameraRequiredAppsPreferenceController(Context context, String preferenceKey, FragmentController fragmentController, CarUxRestrictions uxRestrictions, PackageManager packageManager, SensorPrivacyManager sensorPrivacyManager)59 CameraRequiredAppsPreferenceController(Context context, String preferenceKey, 60 FragmentController fragmentController, CarUxRestrictions uxRestrictions, 61 PackageManager packageManager, SensorPrivacyManager sensorPrivacyManager) { 62 super(context, preferenceKey, fragmentController, uxRestrictions); 63 mPackageManager = packageManager; 64 mSensorPrivacyManager = sensorPrivacyManager; 65 mCameraPrivacyAllowlist = mSensorPrivacyManager.getCameraPrivacyAllowlist(); 66 } 67 68 @Override getPreferenceType()69 protected Class<LogicalPreferenceGroup> getPreferenceType() { 70 return LogicalPreferenceGroup.class; 71 } 72 73 @Override getDefaultAvailabilityStatus()74 protected int getDefaultAvailabilityStatus() { 75 boolean hasRequiredApps = !mCameraPrivacyAllowlist.isEmpty(); 76 return hasRequiredApps ? AVAILABLE : CONDITIONALLY_UNAVAILABLE; 77 } 78 79 @Override onCreateInternal()80 protected void onCreateInternal() { 81 super.onCreateInternal(); 82 loadCameraRequiredAppsWithCameraPermission(); 83 } 84 loadCameraRequiredAppsWithCameraPermission()85 private void loadCameraRequiredAppsWithCameraPermission() { 86 LogicalPreferenceGroup requiredappsPref = getPreference().findPreference(getContext() 87 .getString(R.string.pk_camera_required_apps_list)); 88 89 for (String app : mCameraPrivacyAllowlist) { 90 CarUiTwoActionTextPreference preference = 91 RequiredInfotainmentAppsUtils.createRequiredAppPreference( 92 getContext(), mPackageManager, app, Process.myUserHandle(), 93 Manifest.permission_group.CAMERA, /* showSummary= */ true); 94 if (preference != null) { 95 requiredappsPref.addPreference(preference); 96 } 97 } 98 } 99 } 100