blob: f75fd4b8d0ff5bc8e80ca6366d90d55ab535753f [file] [log] [blame]
Doris Ling1b3ec042016-11-30 17:33:50 -08001/*
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
17package com.android.settings.notification;
18
19import android.content.Context;
Matthew Fritze097dc802018-05-11 08:35:42 -070020import android.content.IntentFilter;
21import android.media.AudioManager;
Doris Ling1b3ec042016-11-30 17:33:50 -080022import android.os.UserHandle;
23import android.os.UserManager;
Doris Ling1b3ec042016-11-30 17:33:50 -080024
Fan Zhang23f8d592018-08-28 15:11:40 -070025import androidx.annotation.VisibleForTesting;
26import androidx.preference.Preference;
27
Doris Ling1b3ec042016-11-30 17:33:50 -080028import com.android.settings.accounts.AccountRestrictionHelper;
Julia Reynolds56063792018-04-03 13:48:55 -040029import com.android.settings.core.SliderPreferenceController;
Edgar Wangcdff5c62021-06-08 09:10:41 +000030import com.android.settingslib.RestrictedPreference;
Fan Zhangc7162cd2018-06-18 15:21:41 -070031
Doris Ling1b3ec042016-11-30 17:33:50 -080032/**
33 * Base class for preference controller that handles preference that enforce adjust volume
34 * restriction
35 */
Tony Mantler1d583e12017-06-13 13:09:25 -070036public abstract class AdjustVolumeRestrictedPreferenceController extends
Fan Zhangb1b07e22019-03-29 15:43:46 -070037 SliderPreferenceController {
Doris Ling1b3ec042016-11-30 17:33:50 -080038
39 private AccountRestrictionHelper mHelper;
40
Julia Reynolds56063792018-04-03 13:48:55 -040041 public AdjustVolumeRestrictedPreferenceController(Context context, String key) {
42 this(context, new AccountRestrictionHelper(context), key);
Doris Ling1b3ec042016-11-30 17:33:50 -080043 }
44
45 @VisibleForTesting
Julia Reynolds56063792018-04-03 13:48:55 -040046 AdjustVolumeRestrictedPreferenceController(Context context, AccountRestrictionHelper helper,
47 String key) {
48 super(context, key);
Doris Ling1b3ec042016-11-30 17:33:50 -080049 mHelper = helper;
50 }
51
52 @Override
53 public void updateState(Preference preference) {
Edgar Wangcdff5c62021-06-08 09:10:41 +000054 if (!(preference instanceof RestrictedPreference)) {
Doris Ling1b3ec042016-11-30 17:33:50 -080055 return;
56 }
Edgar Wangcdff5c62021-06-08 09:10:41 +000057 mHelper.enforceRestrictionOnPreference((RestrictedPreference) preference,
Doris Ling1b3ec042016-11-30 17:33:50 -080058 UserManager.DISALLOW_ADJUST_VOLUME, UserHandle.myUserId());
59 }
60
Matthew Fritze097dc802018-05-11 08:35:42 -070061 @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 Chiu2c7b77d2020-08-20 16:22:44 +080067 filter.addAction(AudioManager.STREAM_DEVICES_CHANGED_ACTION);
Matthew Fritze097dc802018-05-11 08:35:42 -070068 return filter;
69 }
Doris Ling1b3ec042016-11-30 17:33:50 -080070}