• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.content.IntentFilter;
21 import android.media.AudioManager;
22 import android.os.UserHandle;
23 import android.os.UserManager;
24 
25 import androidx.annotation.VisibleForTesting;
26 import androidx.preference.Preference;
27 
28 import com.android.settings.accounts.AccountRestrictionHelper;
29 import com.android.settings.core.SliderPreferenceController;
30 import com.android.settingslib.RestrictedPreference;
31 
32 /**
33  * Base class for preference controller that handles preference that enforce adjust volume
34  * restriction
35  */
36 public abstract class AdjustVolumeRestrictedPreferenceController extends
37         SliderPreferenceController {
38 
39     private AccountRestrictionHelper mHelper;
40 
AdjustVolumeRestrictedPreferenceController(Context context, String key)41     public AdjustVolumeRestrictedPreferenceController(Context context, String key) {
42         this(context, new AccountRestrictionHelper(context), key);
43     }
44 
45     @VisibleForTesting
AdjustVolumeRestrictedPreferenceController(Context context, AccountRestrictionHelper helper, String key)46     AdjustVolumeRestrictedPreferenceController(Context context, AccountRestrictionHelper helper,
47             String key) {
48         super(context, key);
49         mHelper = helper;
50     }
51 
52     @Override
updateState(Preference preference)53     public void updateState(Preference preference) {
54         if (!(preference instanceof RestrictedPreference)) {
55             return;
56         }
57         mHelper.enforceRestrictionOnPreference((RestrictedPreference) preference,
58                 UserManager.DISALLOW_ADJUST_VOLUME, UserHandle.myUserId());
59     }
60 
61     @Override
getIntentFilter()62     public IntentFilter getIntentFilter() {
63         final IntentFilter filter = new IntentFilter();
64         filter.addAction(AudioManager.VOLUME_CHANGED_ACTION);
65         filter.addAction(AudioManager.STREAM_MUTE_CHANGED_ACTION);
66         filter.addAction(AudioManager.MASTER_MUTE_CHANGED_ACTION);
67         return filter;
68     }
69 }
70