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