| Doris Ling | 1b3ec04 | 2016-11-30 17:33:50 -0800 | [diff] [blame] | 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; |
| Matthew Fritze | 097dc80 | 2018-05-11 08:35:42 -0700 | [diff] [blame] | 20 | import android.content.IntentFilter; |
| 21 | import android.media.AudioManager; |
| Doris Ling | 1b3ec04 | 2016-11-30 17:33:50 -0800 | [diff] [blame] | 22 | import android.os.UserHandle; |
| 23 | import android.os.UserManager; |
| Doris Ling | 1b3ec04 | 2016-11-30 17:33:50 -0800 | [diff] [blame] | 24 | |
| Fan Zhang | 23f8d59 | 2018-08-28 15:11:40 -0700 | [diff] [blame] | 25 | import androidx.annotation.VisibleForTesting; |
| 26 | import androidx.preference.Preference; |
| 27 | |
| Doris Ling | 1b3ec04 | 2016-11-30 17:33:50 -0800 | [diff] [blame] | 28 | import com.android.settings.accounts.AccountRestrictionHelper; |
| Julia Reynolds | 5606379 | 2018-04-03 13:48:55 -0400 | [diff] [blame] | 29 | import com.android.settings.core.SliderPreferenceController; |
| Edgar Wang | cdff5c6 | 2021-06-08 09:10:41 +0000 | [diff] [blame] | 30 | import com.android.settingslib.RestrictedPreference; |
| Fan Zhang | c7162cd | 2018-06-18 15:21:41 -0700 | [diff] [blame] | 31 | |
| Doris Ling | 1b3ec04 | 2016-11-30 17:33:50 -0800 | [diff] [blame] | 32 | /** |
| 33 | * Base class for preference controller that handles preference that enforce adjust volume |
| 34 | * restriction |
| 35 | */ |
| Tony Mantler | 1d583e1 | 2017-06-13 13:09:25 -0700 | [diff] [blame] | 36 | public abstract class AdjustVolumeRestrictedPreferenceController extends |
| Fan Zhang | b1b07e2 | 2019-03-29 15:43:46 -0700 | [diff] [blame] | 37 | SliderPreferenceController { |
| Doris Ling | 1b3ec04 | 2016-11-30 17:33:50 -0800 | [diff] [blame] | 38 | |
| 39 | private AccountRestrictionHelper mHelper; |
| 40 | |
| Julia Reynolds | 5606379 | 2018-04-03 13:48:55 -0400 | [diff] [blame] | 41 | public AdjustVolumeRestrictedPreferenceController(Context context, String key) { |
| 42 | this(context, new AccountRestrictionHelper(context), key); |
| Doris Ling | 1b3ec04 | 2016-11-30 17:33:50 -0800 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | @VisibleForTesting |
| Julia Reynolds | 5606379 | 2018-04-03 13:48:55 -0400 | [diff] [blame] | 46 | AdjustVolumeRestrictedPreferenceController(Context context, AccountRestrictionHelper helper, |
| 47 | String key) { |
| 48 | super(context, key); |
| Doris Ling | 1b3ec04 | 2016-11-30 17:33:50 -0800 | [diff] [blame] | 49 | mHelper = helper; |
| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | public void updateState(Preference preference) { |
| Edgar Wang | cdff5c6 | 2021-06-08 09:10:41 +0000 | [diff] [blame] | 54 | if (!(preference instanceof RestrictedPreference)) { |
| Doris Ling | 1b3ec04 | 2016-11-30 17:33:50 -0800 | [diff] [blame] | 55 | return; |
| 56 | } |
| Edgar Wang | cdff5c6 | 2021-06-08 09:10:41 +0000 | [diff] [blame] | 57 | mHelper.enforceRestrictionOnPreference((RestrictedPreference) preference, |
| Doris Ling | 1b3ec04 | 2016-11-30 17:33:50 -0800 | [diff] [blame] | 58 | UserManager.DISALLOW_ADJUST_VOLUME, UserHandle.myUserId()); |
| 59 | } |
| 60 | |
| Matthew Fritze | 097dc80 | 2018-05-11 08:35:42 -0700 | [diff] [blame] | 61 | @Override |
| 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); |
| Jason Chiu | 2c7b77d | 2020-08-20 16:22:44 +0800 | [diff] [blame] | 67 | filter.addAction(AudioManager.STREAM_DEVICES_CHANGED_ACTION); |
| Matthew Fritze | 097dc80 | 2018-05-11 08:35:42 -0700 | [diff] [blame] | 68 | return filter; |
| 69 | } |
| Doris Ling | 1b3ec04 | 2016-11-30 17:33:50 -0800 | [diff] [blame] | 70 | } |