1 /* 2 * Copyright (C) 2021 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.systemui.sensorprivacy.television; 18 19 import static android.hardware.SensorPrivacyManager.Sensors.CAMERA; 20 import static android.hardware.SensorPrivacyManager.Sensors.MICROPHONE; 21 import static android.hardware.SensorPrivacyManager.Sources.OTHER; 22 23 import android.hardware.SensorPrivacyManager; 24 import android.os.Bundle; 25 import android.util.Log; 26 import android.view.View; 27 import android.view.WindowManager; 28 import android.widget.Button; 29 import android.widget.ImageView; 30 import android.widget.TextView; 31 32 import com.android.systemui.R; 33 import com.android.systemui.statusbar.policy.IndividualSensorPrivacyController; 34 import com.android.systemui.tv.TvBottomSheetActivity; 35 36 import javax.inject.Inject; 37 38 /** 39 * Bottom sheet that is shown when the camera/mic sensors are blocked by the global toggle and 40 * allows the user to re-enable them. 41 */ 42 public class TvUnblockSensorActivity extends TvBottomSheetActivity { 43 44 private static final String TAG = TvUnblockSensorActivity.class.getSimpleName(); 45 46 private static final int ALL_SENSORS = Integer.MAX_VALUE; 47 private int mSensor = -1; 48 49 private final IndividualSensorPrivacyController mSensorPrivacyController; 50 private IndividualSensorPrivacyController.Callback mSensorPrivacyCallback; 51 52 @Inject TvUnblockSensorActivity( IndividualSensorPrivacyController individualSensorPrivacyController)53 public TvUnblockSensorActivity( 54 IndividualSensorPrivacyController individualSensorPrivacyController) { 55 mSensorPrivacyController = individualSensorPrivacyController; 56 } 57 58 @Override onCreate(Bundle savedInstanceState)59 public void onCreate(Bundle savedInstanceState) { 60 super.onCreate(savedInstanceState); 61 getWindow().addSystemFlags( 62 WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS); 63 64 boolean allSensors = getIntent().getBooleanExtra(SensorPrivacyManager.EXTRA_ALL_SENSORS, 65 false); 66 if (allSensors) { 67 mSensor = ALL_SENSORS; 68 } else { 69 mSensor = getIntent().getIntExtra(SensorPrivacyManager.EXTRA_SENSOR, -1); 70 } 71 72 if (mSensor == -1) { 73 Log.v(TAG, "Invalid extras"); 74 finish(); 75 return; 76 } 77 78 mSensorPrivacyCallback = (sensor, blocked) -> { 79 if (mSensor == ALL_SENSORS) { 80 if (!mSensorPrivacyController.isSensorBlocked(CAMERA) 81 && !mSensorPrivacyController.isSensorBlocked(MICROPHONE)) { 82 finish(); 83 } 84 } else if (this.mSensor == sensor && !blocked) { 85 finish(); 86 } 87 }; 88 89 initUI(); 90 } 91 initUI()92 private void initUI() { 93 TextView title = findViewById(R.id.bottom_sheet_title); 94 TextView content = findViewById(R.id.bottom_sheet_body); 95 ImageView icon = findViewById(R.id.bottom_sheet_icon); 96 // mic icon if both icons are shown 97 ImageView secondIcon = findViewById(R.id.bottom_sheet_second_icon); 98 Button unblockButton = findViewById(R.id.bottom_sheet_positive_button); 99 Button cancelButton = findViewById(R.id.bottom_sheet_negative_button); 100 101 switch (mSensor) { 102 case MICROPHONE: 103 title.setText(R.string.sensor_privacy_start_use_mic_dialog_title); 104 content.setText(R.string.sensor_privacy_start_use_mic_dialog_content); 105 icon.setImageResource(com.android.internal.R.drawable.perm_group_microphone); 106 secondIcon.setVisibility(View.GONE); 107 break; 108 case CAMERA: 109 title.setText(R.string.sensor_privacy_start_use_camera_dialog_title); 110 content.setText(R.string.sensor_privacy_start_use_camera_dialog_content); 111 icon.setImageResource(com.android.internal.R.drawable.perm_group_camera); 112 secondIcon.setVisibility(View.GONE); 113 break; 114 case ALL_SENSORS: 115 default: 116 title.setText(R.string.sensor_privacy_start_use_mic_camera_dialog_title); 117 content.setText(R.string.sensor_privacy_start_use_mic_camera_dialog_content); 118 icon.setImageResource(com.android.internal.R.drawable.perm_group_camera); 119 secondIcon.setImageResource(com.android.internal.R.drawable.perm_group_microphone); 120 break; 121 } 122 unblockButton.setText( 123 com.android.internal.R.string.sensor_privacy_start_use_dialog_turn_on_button); 124 unblockButton.setOnClickListener(v -> { 125 if (mSensor == ALL_SENSORS) { 126 mSensorPrivacyController.setSensorBlocked(OTHER, CAMERA, false); 127 mSensorPrivacyController.setSensorBlocked(OTHER, MICROPHONE, false); 128 } else { 129 mSensorPrivacyController.setSensorBlocked(OTHER, mSensor, false); 130 } 131 }); 132 133 cancelButton.setText(android.R.string.cancel); 134 cancelButton.setOnClickListener(v -> finish()); 135 } 136 137 @Override onResume()138 public void onResume() { 139 super.onResume(); 140 mSensorPrivacyController.addCallback(mSensorPrivacyCallback); 141 } 142 143 @Override onPause()144 public void onPause() { 145 mSensorPrivacyController.removeCallback(mSensorPrivacyCallback); 146 super.onPause(); 147 } 148 149 } 150