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.annotation.FlaggedApi;
20 import android.car.drivingstate.CarUxRestrictions;
21 import android.content.Context;
22 import android.hardware.SensorPrivacyManager;
23 
24 import androidx.preference.Preference;
25 
26 import com.android.car.settings.common.FragmentController;
27 import com.android.car.settings.common.PreferenceController;
28 import com.android.internal.annotations.VisibleForTesting;
29 import com.android.internal.camera.flags.Flags;
30 
31 /**
32  * Controller for displaying camera access page.
33  */
34 @FlaggedApi(Flags.FLAG_CAMERA_PRIVACY_ALLOWLIST)
35 public class CameraAccessPreferenceController extends PreferenceController<Preference> {
36     private final SensorPrivacyManager mSensorPrivacyManager;
37 
CameraAccessPreferenceController(Context context, String preferenceKey, FragmentController fragmentController, CarUxRestrictions uxRestrictions)38     public CameraAccessPreferenceController(Context context, String preferenceKey,
39             FragmentController fragmentController, CarUxRestrictions uxRestrictions) {
40         this(context, preferenceKey, fragmentController, uxRestrictions,
41                 SensorPrivacyManager.getInstance(context));
42     }
43 
44     @VisibleForTesting
CameraAccessPreferenceController(Context context, String preferenceKey, FragmentController fragmentController, CarUxRestrictions uxRestrictions, SensorPrivacyManager sensorPrivacyManager)45     CameraAccessPreferenceController(Context context, String preferenceKey,
46             FragmentController fragmentController, CarUxRestrictions uxRestrictions,
47             SensorPrivacyManager sensorPrivacyManager) {
48         super(context, preferenceKey, fragmentController, uxRestrictions);
49         mSensorPrivacyManager = sensorPrivacyManager;
50     }
51 
52     @Override
getPreferenceType()53     protected Class<Preference> getPreferenceType() {
54         return Preference.class;
55     }
56 
57     @Override
getDefaultAvailabilityStatus()58     protected int getDefaultAvailabilityStatus() {
59         boolean hasFeatureCameraToggle = mSensorPrivacyManager.supportsSensorToggle(
60                 SensorPrivacyManager.Sensors.CAMERA);
61         return Flags.cameraPrivacyAllowlist() && hasFeatureCameraToggle
62                 ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
63     }
64 }
65