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