1 /* 2 * Copyright (C) 2014 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.app.admin.DevicePolicyManager; 20 import android.content.Context; 21 import android.content.Intent; 22 import android.os.Bundle; 23 import android.os.UserManager; 24 import android.provider.Settings; 25 import android.view.LayoutInflater; 26 import android.view.View; 27 import android.view.ViewGroup; 28 import android.widget.Button; 29 import android.widget.CompoundButton; 30 import android.widget.LinearLayout; 31 import android.widget.RadioButton; 32 import android.widget.RadioGroup; 33 import android.widget.TextView; 34 35 import com.android.internal.logging.MetricsProto.MetricsEvent; 36 import com.android.settings.R; 37 import com.android.settings.RestrictedCheckBox; 38 import com.android.settings.RestrictedRadioButton; 39 import com.android.settings.SettingsActivity; 40 import com.android.settings.SettingsPreferenceFragment; 41 import com.android.settings.Utils; 42 import com.android.settingslib.RestrictedLockUtils; 43 44 import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS; 45 import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS; 46 47 import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin; 48 49 public class RedactionInterstitial extends SettingsActivity { 50 51 @Override 52 public Intent getIntent() { 53 Intent modIntent = new Intent(super.getIntent()); 54 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, RedactionInterstitialFragment.class.getName()); 55 return modIntent; 56 } 57 58 @Override 59 protected boolean isValidFragment(String fragmentName) { 60 return RedactionInterstitialFragment.class.getName().equals(fragmentName); 61 } 62 63 @Override 64 protected void onCreate(Bundle savedInstance) { 65 super.onCreate(savedInstance); 66 LinearLayout layout = (LinearLayout) findViewById(R.id.content_parent); 67 layout.setFitsSystemWindows(false); 68 } 69 70 /** 71 * Create an intent for launching RedactionInterstitial. 72 * @return An intent to launch the activity is if is available, @null if the activity is not 73 * available to be launched. 74 */ 75 public static Intent createStartIntent(Context ctx, int userId) { 76 return new Intent(ctx, RedactionInterstitial.class) 77 .putExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, 78 Utils.isManagedProfile(UserManager.get(ctx), userId) 79 ? R.string.lock_screen_notifications_interstitial_title_profile 80 : R.string.lock_screen_notifications_interstitial_title) 81 .putExtra(Intent.EXTRA_USER_ID, userId); 82 } 83 84 public static class RedactionInterstitialFragment extends SettingsPreferenceFragment 85 implements RadioGroup.OnCheckedChangeListener, View.OnClickListener { 86 87 private RadioGroup mRadioGroup; 88 private RestrictedRadioButton mShowAllButton; 89 private RestrictedRadioButton mRedactSensitiveButton; 90 private int mUserId; 91 92 @Override 93 protected int getMetricsCategory() { 94 return MetricsEvent.NOTIFICATION_REDACTION; 95 } 96 97 @Override 98 public View onCreateView(LayoutInflater inflater, ViewGroup container, 99 Bundle savedInstanceState) { 100 return inflater.inflate(R.layout.redaction_interstitial, container, false); 101 } 102 103 @Override 104 public void onViewCreated(View view, Bundle savedInstanceState) { 105 super.onViewCreated(view, savedInstanceState); 106 mRadioGroup = (RadioGroup) view.findViewById(R.id.radio_group); 107 mShowAllButton = (RestrictedRadioButton) view.findViewById(R.id.show_all); 108 mRedactSensitiveButton = 109 (RestrictedRadioButton) view.findViewById(R.id.redact_sensitive); 110 111 mRadioGroup.setOnCheckedChangeListener(this); 112 mUserId = Utils.getUserIdFromBundle( 113 getContext(), getActivity().getIntent().getExtras()); 114 if (Utils.isManagedProfile(UserManager.get(getContext()), mUserId)) { 115 ((TextView) view.findViewById(R.id.message)) 116 .setText(R.string.lock_screen_notifications_interstitial_message_profile); 117 mShowAllButton.setText(R.string.lock_screen_notifications_summary_show_profile); 118 mRedactSensitiveButton 119 .setText(R.string.lock_screen_notifications_summary_hide_profile); 120 ((RadioButton) view.findViewById(R.id.hide_all)) 121 .setText(R.string.lock_screen_notifications_summary_disable_profile); 122 } 123 124 final Button button = (Button) view.findViewById(R.id.redaction_done_button); 125 button.setOnClickListener(this); 126 } 127 128 @Override 129 public void onClick(View v) { 130 if (v.getId() == R.id.redaction_done_button) { 131 final RedactionInterstitial activity = (RedactionInterstitial) getActivity(); 132 if (activity != null) { 133 activity.setResult(RESULT_OK, activity.getResultIntentData()); 134 finish(); 135 } 136 } 137 } 138 139 @Override 140 public void onResume() { 141 super.onResume(); 142 // Disable buttons according to policy. 143 144 checkNotificationFeaturesAndSetDisabled(mShowAllButton, 145 KEYGUARD_DISABLE_SECURE_NOTIFICATIONS | 146 KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS); 147 checkNotificationFeaturesAndSetDisabled(mRedactSensitiveButton, 148 KEYGUARD_DISABLE_SECURE_NOTIFICATIONS); 149 loadFromSettings(); 150 } 151 152 private void checkNotificationFeaturesAndSetDisabled(RestrictedRadioButton button, 153 int keyguardNotifications) { 154 EnforcedAdmin admin = RestrictedLockUtils.checkIfKeyguardFeaturesDisabled( 155 getActivity(), keyguardNotifications, mUserId); 156 button.setDisabledByAdmin(admin); 157 } 158 159 private void loadFromSettings() { 160 final boolean enabled = Settings.Secure.getIntForUser(getContentResolver(), 161 Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0, mUserId) != 0; 162 final boolean show = Settings.Secure.getIntForUser(getContentResolver(), 163 Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1, mUserId) != 0; 164 165 int checkedButtonId = R.id.hide_all; 166 if (enabled) { 167 if (show && !mShowAllButton.isDisabledByAdmin()) { 168 checkedButtonId = R.id.show_all; 169 } else if (!mRedactSensitiveButton.isDisabledByAdmin()) { 170 checkedButtonId = R.id.redact_sensitive; 171 } 172 } 173 174 mRadioGroup.check(checkedButtonId); 175 } 176 177 @Override 178 public void onCheckedChanged(RadioGroup group, int checkedId) { 179 final boolean show = (checkedId == R.id.show_all); 180 final boolean enabled = (checkedId != R.id.hide_all); 181 182 Settings.Secure.putIntForUser(getContentResolver(), 183 Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, show ? 1 : 0, mUserId); 184 Settings.Secure.putIntForUser(getContentResolver(), 185 Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, enabled ? 1 : 0, mUserId); 186 187 } 188 } 189 } 190