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.tv.settings; 18 19 import static android.hardware.SensorPrivacyManager.TOGGLE_TYPE_SOFTWARE; 20 import static android.provider.Settings.Global.RECEIVE_EXPLICIT_USER_INTERACTION_AUDIO_ENABLED; 21 22 import android.content.BroadcastReceiver; 23 import android.content.Context; 24 import android.content.Intent; 25 import android.hardware.SensorPrivacyManager; 26 import android.os.Build; 27 import android.provider.Settings; 28 import android.util.Log; 29 30 31 /** The {@link BroadcastReceiver} for performing actions upon device boot after OTA. */ 32 public class PreBootCompleteReceiver extends BroadcastReceiver { 33 private static final String TAG = "PreBootCompleteReceiver"; 34 private static final boolean DEBUG = Build.IS_DEBUGGABLE; 35 36 @Override onReceive(Context context, Intent intent)37 public void onReceive(Context context, Intent intent) { 38 if (!Intent.ACTION_PRE_BOOT_COMPLETED.equals(intent.getAction())) { 39 return; 40 } 41 42 if (DEBUG) { 43 Log.d(TAG, "onReceive PRE_BOOT_COMPLETED"); 44 } 45 try { 46 Settings.Global.getInt( 47 context.getContentResolver(), 48 RECEIVE_EXPLICIT_USER_INTERACTION_AUDIO_ENABLED); 49 } catch (Settings.SettingNotFoundException e) { 50 // If there is no default value for "mic on remote" toggle, set the value as the 51 // opposite of mic sensor privacy enable state. 52 boolean micPrivacyEnabled = context.getSystemService(SensorPrivacyManager.class) 53 .isSensorPrivacyEnabled( 54 TOGGLE_TYPE_SOFTWARE, SensorPrivacyManager.Sensors.MICROPHONE); 55 Settings.Global.putInt( 56 context.getContentResolver(), 57 RECEIVE_EXPLICIT_USER_INTERACTION_AUDIO_ENABLED, 58 micPrivacyEnabled ? 0 : 1); 59 if (DEBUG) { 60 Log.d(TAG, 61 "Set default state for RECEIVE_EXPLICIT_USER_INTERACTION_AUDIO_ENABLED: " 62 + (micPrivacyEnabled ? 0 : 1)); 63 64 } 65 } 66 } 67 } 68