2 * Copyright (C) 2016 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.settings.notification;
19 import android.content.Context;
20 import android.content.pm.PackageManager;
21 import android.os.UserHandle;
22 import android.os.UserManager;
23 import android.support.annotation.VisibleForTesting;
24 import android.support.v7.preference.Preference;
26 import com.android.settings.accounts.AccountRestrictionHelper;
27 import com.android.settings.core.PreferenceController;
28 import com.android.settingslib.RestrictedPreference;
31 * Base class for preference controller that handles preference that enforce adjust volume
34 public class EmergencyBroadcastPreferenceController extends PreferenceController {
36 private final String mPrefKey;
38 private AccountRestrictionHelper mHelper;
39 private UserManager mUserManager;
40 private PackageManager mPm;
41 private boolean mCellBroadcastAppLinkEnabled;
43 public EmergencyBroadcastPreferenceController(Context context, String prefKey) {
44 this(context, new AccountRestrictionHelper(context), prefKey);
47 @VisibleForTesting(otherwise = VisibleForTesting.NONE)
48 EmergencyBroadcastPreferenceController(Context context, AccountRestrictionHelper helper,
53 mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
54 mPm = mContext.getPackageManager();
55 // Enable link to CMAS app settings depending on the value in config.xml.
56 mCellBroadcastAppLinkEnabled = isCellBroadcastAppLinkEnabled();
60 public void updateState(Preference preference) {
61 if (!(preference instanceof RestrictedPreference)) {
64 ((RestrictedPreference) preference).checkRestrictionAndSetDisabled(
65 UserManager.DISALLOW_CONFIG_CELL_BROADCASTS);
69 public boolean handlePreferenceTreeClick(Preference preference) {
74 public String getPreferenceKey() {
79 public boolean isAvailable() {
80 return mUserManager.isAdminUser() && mCellBroadcastAppLinkEnabled
81 && !mHelper.hasBaseUserRestriction(
82 UserManager.DISALLOW_CONFIG_CELL_BROADCASTS, UserHandle.myUserId());
85 private boolean isCellBroadcastAppLinkEnabled() {
86 boolean enabled = mContext.getResources().getBoolean(
87 com.android.internal.R.bool.config_cellBroadcastAppLinks);
90 if (mPm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver")
91 == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
92 enabled = false; // CMAS app disabled
94 } catch (IllegalArgumentException ignored) {
95 enabled = false; // CMAS app not installed