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.car.drivingstate.CarUxRestrictions; 20 import android.content.Context; 21 import android.hardware.SensorPrivacyManager; 22 23 import androidx.preference.Preference; 24 25 import com.android.car.settings.common.FragmentController; 26 import com.android.car.settings.common.PreferenceController; 27 28 /** 29 * Abstract PreferenceController that listens to OnSensorPrivacyChangedListener 30 * and will refresh the UI when the sensor privacy changed event happens. 31 * 32 * @param <V> the upper bound on the type of {@link Preference} on which the controller expects 33 * to operate. 34 */ 35 public abstract class CameraPrivacyBasePreferenceController<V extends Preference> extends 36 PreferenceController<V> { 37 private final SensorPrivacyManager mSensorPrivacyManager; 38 private final SensorPrivacyManager.OnSensorPrivacyChangedListener mListener = 39 new SensorPrivacyManager.OnSensorPrivacyChangedListener() { 40 @Override 41 public void onSensorPrivacyChanged(SensorPrivacyChangedParams params) { 42 refreshUi(); 43 } 44 45 @Override 46 public void onSensorPrivacyChanged(int sensor, boolean enabled) { 47 // handled in onSensorPrivacyChanged(SensorPrivacyChangedParams) 48 } 49 }; 50 CameraPrivacyBasePreferenceController(Context context, String preferenceKey, FragmentController fragmentController, CarUxRestrictions uxRestrictions, SensorPrivacyManager sensorPrivacyManager)51 public CameraPrivacyBasePreferenceController(Context context, String preferenceKey, 52 FragmentController fragmentController, CarUxRestrictions uxRestrictions, 53 SensorPrivacyManager sensorPrivacyManager) { 54 super(context, preferenceKey, fragmentController, uxRestrictions); 55 mSensorPrivacyManager = sensorPrivacyManager; 56 } 57 58 @Override onStartInternal()59 protected void onStartInternal() { 60 super.onStartInternal(); 61 mSensorPrivacyManager.addSensorPrivacyListener( 62 SensorPrivacyManager.Sensors.CAMERA, mListener); 63 } 64 65 @Override onStopInternal()66 protected void onStopInternal() { 67 super.onStopInternal(); 68 mSensorPrivacyManager.removeSensorPrivacyListener(SensorPrivacyManager.Sensors.CAMERA, 69 mListener); 70 } 71 getSensorPrivacyManager()72 public SensorPrivacyManager getSensorPrivacyManager() { 73 return mSensorPrivacyManager; 74 } 75 } 76 77