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