1 /* 2 * Copyright (C) 2017 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.settings.notification; 18 19 import android.content.Context; 20 import android.os.SystemProperties; 21 import android.support.annotation.VisibleForTesting; 22 import android.support.v14.preference.SwitchPreference; 23 import android.support.v7.preference.Preference; 24 import android.support.v7.preference.PreferenceScreen; 25 import com.android.settings.core.PreferenceController; 26 27 public class BootSoundPreferenceController extends PreferenceController { 28 29 // Boot Sounds needs to be a system property so it can be accessed during boot. 30 private static final String KEY_BOOT_SOUNDS = "boot_sounds"; 31 @VisibleForTesting 32 static final String PROPERTY_BOOT_SOUNDS = "persist.sys.bootanim.play_sound"; 33 BootSoundPreferenceController(Context context)34 public BootSoundPreferenceController(Context context) { 35 super(context); 36 } 37 38 @Override displayPreference(PreferenceScreen screen)39 public void displayPreference(PreferenceScreen screen) { 40 super.displayPreference(screen); 41 if (isAvailable()) { 42 SwitchPreference preference = (SwitchPreference) screen.findPreference(KEY_BOOT_SOUNDS); 43 preference.setChecked(SystemProperties.getBoolean(PROPERTY_BOOT_SOUNDS, true)); 44 } 45 } 46 47 @Override handlePreferenceTreeClick(Preference preference)48 public boolean handlePreferenceTreeClick(Preference preference) { 49 if (KEY_BOOT_SOUNDS.equals(preference.getKey())) { 50 SwitchPreference switchPreference = (SwitchPreference) preference; 51 SystemProperties.set(PROPERTY_BOOT_SOUNDS, switchPreference.isChecked() ? "1" : "0"); 52 } 53 return false; 54 } 55 56 @Override getPreferenceKey()57 public String getPreferenceKey() { 58 return KEY_BOOT_SOUNDS; 59 } 60 61 @Override isAvailable()62 public boolean isAvailable() { 63 return mContext.getResources().getBoolean(com.android.settings.R.bool.has_boot_sounds); 64 } 65 66 }