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