16f60f7ed22f94891156115643452a32d0324f65aAdrian Roos/* 26f60f7ed22f94891156115643452a32d0324f65aAdrian Roos * Copyright (C) 2014 The Android Open Source Project 36f60f7ed22f94891156115643452a32d0324f65aAdrian Roos * 46f60f7ed22f94891156115643452a32d0324f65aAdrian Roos * Licensed under the Apache License, Version 2.0 (the "License"); 56f60f7ed22f94891156115643452a32d0324f65aAdrian Roos * you may not use this file except in compliance with the License. 66f60f7ed22f94891156115643452a32d0324f65aAdrian Roos * You may obtain a copy of the License at 76f60f7ed22f94891156115643452a32d0324f65aAdrian Roos * 86f60f7ed22f94891156115643452a32d0324f65aAdrian Roos * http://www.apache.org/licenses/LICENSE-2.0 96f60f7ed22f94891156115643452a32d0324f65aAdrian Roos * 106f60f7ed22f94891156115643452a32d0324f65aAdrian Roos * Unless required by applicable law or agreed to in writing, software 116f60f7ed22f94891156115643452a32d0324f65aAdrian Roos * distributed under the License is distributed on an "AS IS" BASIS, 126f60f7ed22f94891156115643452a32d0324f65aAdrian Roos * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 136f60f7ed22f94891156115643452a32d0324f65aAdrian Roos * See the License for the specific language governing permissions and 146f60f7ed22f94891156115643452a32d0324f65aAdrian Roos * limitations under the License 156f60f7ed22f94891156115643452a32d0324f65aAdrian Roos */ 166f60f7ed22f94891156115643452a32d0324f65aAdrian Roos 176f60f7ed22f94891156115643452a32d0324f65aAdrian Roospackage com.android.settings.notification; 186f60f7ed22f94891156115643452a32d0324f65aAdrian Roos 19957fc67af21b87c01e2c5939f0611021d8fe6c31Maurice Lamimport static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS; 20957fc67af21b87c01e2c5939f0611021d8fe6c31Maurice Lamimport static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS; 21c29b984a98156b34be07cc9026a31d40a9a8656cPavel Grafovimport static android.provider.Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS; 22c29b984a98156b34be07cc9026a31d40a9a8656cPavel Grafovimport static android.provider.Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS; 23957fc67af21b87c01e2c5939f0611021d8fe6c31Maurice Lam 24957fc67af21b87c01e2c5939f0611021d8fe6c31Maurice Lamimport static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin; 25957fc67af21b87c01e2c5939f0611021d8fe6c31Maurice Lam 266f60f7ed22f94891156115643452a32d0324f65aAdrian Roosimport android.content.Context; 276f60f7ed22f94891156115643452a32d0324f65aAdrian Roosimport android.content.Intent; 289990f397220703f4d2c922560a8e29e60bcce39fMaurice Lamimport android.content.res.Resources; 296f60f7ed22f94891156115643452a32d0324f65aAdrian Roosimport android.os.Bundle; 30f6077f4757183ae8b31af0928c895c806241b593Clara Bayarriimport android.os.UserManager; 316f60f7ed22f94891156115643452a32d0324f65aAdrian Roosimport android.provider.Settings; 326f60f7ed22f94891156115643452a32d0324f65aAdrian Roosimport android.view.LayoutInflater; 336f60f7ed22f94891156115643452a32d0324f65aAdrian Roosimport android.view.View; 346f60f7ed22f94891156115643452a32d0324f65aAdrian Roosimport android.view.ViewGroup; 35d189ac52a4e49291b729d817fc903116abc086d0Maurice Lamimport android.widget.Button; 36d189ac52a4e49291b729d817fc903116abc086d0Maurice Lamimport android.widget.LinearLayout; 376f60f7ed22f94891156115643452a32d0324f65aAdrian Roosimport android.widget.RadioButton; 38ccade402782d9b39331ada3859aa00893132e5c9Alex Chauimport android.widget.RadioGroup; 39f6077f4757183ae8b31af0928c895c806241b593Clara Bayarriimport android.widget.TextView; 406f60f7ed22f94891156115643452a32d0324f65aAdrian Roos 41265d3c2a0c36251bf8a9f571d7239b6dd404d942Tamas Berghammerimport com.android.internal.logging.nano.MetricsProto.MetricsEvent; 4239b467482d1bf256a111c757e9b7621c6f523271Jason Monkimport com.android.settings.R; 431901ae3b3bddafc938bcbc0b03f18d7e12efef12Sudheer Shankaimport com.android.settings.RestrictedRadioButton; 4439b467482d1bf256a111c757e9b7621c6f523271Jason Monkimport com.android.settings.SettingsActivity; 4539b467482d1bf256a111c757e9b7621c6f523271Jason Monkimport com.android.settings.SettingsPreferenceFragment; 46957fc67af21b87c01e2c5939f0611021d8fe6c31Maurice Lamimport com.android.settings.SetupRedactionInterstitial; 479990f397220703f4d2c922560a8e29e60bcce39fMaurice Lamimport com.android.settings.SetupWizardUtils; 48f6077f4757183ae8b31af0928c895c806241b593Clara Bayarriimport com.android.settings.Utils; 491901ae3b3bddafc938bcbc0b03f18d7e12efef12Sudheer Shankaimport com.android.settingslib.RestrictedLockUtils; 501901ae3b3bddafc938bcbc0b03f18d7e12efef12Sudheer Shanka 516f60f7ed22f94891156115643452a32d0324f65aAdrian Roospublic class RedactionInterstitial extends SettingsActivity { 526f60f7ed22f94891156115643452a32d0324f65aAdrian Roos 536f60f7ed22f94891156115643452a32d0324f65aAdrian Roos @Override 546f60f7ed22f94891156115643452a32d0324f65aAdrian Roos public Intent getIntent() { 556f60f7ed22f94891156115643452a32d0324f65aAdrian Roos Intent modIntent = new Intent(super.getIntent()); 566f60f7ed22f94891156115643452a32d0324f65aAdrian Roos modIntent.putExtra(EXTRA_SHOW_FRAGMENT, RedactionInterstitialFragment.class.getName()); 576f60f7ed22f94891156115643452a32d0324f65aAdrian Roos return modIntent; 586f60f7ed22f94891156115643452a32d0324f65aAdrian Roos } 596f60f7ed22f94891156115643452a32d0324f65aAdrian Roos 606f60f7ed22f94891156115643452a32d0324f65aAdrian Roos @Override 619990f397220703f4d2c922560a8e29e60bcce39fMaurice Lam protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) { 629990f397220703f4d2c922560a8e29e60bcce39fMaurice Lam resid = SetupWizardUtils.getTheme(getIntent()); 639990f397220703f4d2c922560a8e29e60bcce39fMaurice Lam super.onApplyThemeResource(theme, resid, first); 649990f397220703f4d2c922560a8e29e60bcce39fMaurice Lam } 659990f397220703f4d2c922560a8e29e60bcce39fMaurice Lam 669990f397220703f4d2c922560a8e29e60bcce39fMaurice Lam @Override 676f60f7ed22f94891156115643452a32d0324f65aAdrian Roos protected boolean isValidFragment(String fragmentName) { 686f60f7ed22f94891156115643452a32d0324f65aAdrian Roos return RedactionInterstitialFragment.class.getName().equals(fragmentName); 696f60f7ed22f94891156115643452a32d0324f65aAdrian Roos } 706f60f7ed22f94891156115643452a32d0324f65aAdrian Roos 71d189ac52a4e49291b729d817fc903116abc086d0Maurice Lam @Override 72d189ac52a4e49291b729d817fc903116abc086d0Maurice Lam protected void onCreate(Bundle savedInstance) { 73d189ac52a4e49291b729d817fc903116abc086d0Maurice Lam super.onCreate(savedInstance); 74d189ac52a4e49291b729d817fc903116abc086d0Maurice Lam LinearLayout layout = (LinearLayout) findViewById(R.id.content_parent); 75d189ac52a4e49291b729d817fc903116abc086d0Maurice Lam layout.setFitsSystemWindows(false); 76d189ac52a4e49291b729d817fc903116abc086d0Maurice Lam } 77d189ac52a4e49291b729d817fc903116abc086d0Maurice Lam 78ccade402782d9b39331ada3859aa00893132e5c9Alex Chau /** 79ccade402782d9b39331ada3859aa00893132e5c9Alex Chau * Create an intent for launching RedactionInterstitial. 80ccade402782d9b39331ada3859aa00893132e5c9Alex Chau * @return An intent to launch the activity is if is available, @null if the activity is not 81ccade402782d9b39331ada3859aa00893132e5c9Alex Chau * available to be launched. 82ccade402782d9b39331ada3859aa00893132e5c9Alex Chau */ 83f6077f4757183ae8b31af0928c895c806241b593Clara Bayarri public static Intent createStartIntent(Context ctx, int userId) { 841901ae3b3bddafc938bcbc0b03f18d7e12efef12Sudheer Shanka return new Intent(ctx, RedactionInterstitial.class) 851901ae3b3bddafc938bcbc0b03f18d7e12efef12Sudheer Shanka .putExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, 86788671647c6d615684d159a94ffb5b4367df6896Robin Lee UserManager.get(ctx).isManagedProfile(userId) 87f6077f4757183ae8b31af0928c895c806241b593Clara Bayarri ? R.string.lock_screen_notifications_interstitial_title_profile 88f6077f4757183ae8b31af0928c895c806241b593Clara Bayarri : R.string.lock_screen_notifications_interstitial_title) 89f6077f4757183ae8b31af0928c895c806241b593Clara Bayarri .putExtra(Intent.EXTRA_USER_ID, userId); 906f60f7ed22f94891156115643452a32d0324f65aAdrian Roos } 916f60f7ed22f94891156115643452a32d0324f65aAdrian Roos 926f60f7ed22f94891156115643452a32d0324f65aAdrian Roos public static class RedactionInterstitialFragment extends SettingsPreferenceFragment 93fa2bbcc2887a815ff69a8675e0a0e4c6a616b84dAdrian Roos implements RadioGroup.OnCheckedChangeListener, View.OnClickListener { 946f60f7ed22f94891156115643452a32d0324f65aAdrian Roos 95ccade402782d9b39331ada3859aa00893132e5c9Alex Chau private RadioGroup mRadioGroup; 961901ae3b3bddafc938bcbc0b03f18d7e12efef12Sudheer Shanka private RestrictedRadioButton mShowAllButton; 971901ae3b3bddafc938bcbc0b03f18d7e12efef12Sudheer Shanka private RestrictedRadioButton mRedactSensitiveButton; 98f6077f4757183ae8b31af0928c895c806241b593Clara Bayarri private int mUserId; 996f60f7ed22f94891156115643452a32d0324f65aAdrian Roos 1006f60f7ed22f94891156115643452a32d0324f65aAdrian Roos @Override 1016507613ebcd22e4691c2af92a5c161bd327db336Fan Zhang public int getMetricsCategory() { 1029d1bfd1e8de6e46137a9571507c03526880d6a46Chris Wren return MetricsEvent.NOTIFICATION_REDACTION; 1038a963babe2e36b7a41f77b8d2598c97658196e58Chris Wren } 1048a963babe2e36b7a41f77b8d2598c97658196e58Chris Wren 1058a963babe2e36b7a41f77b8d2598c97658196e58Chris Wren @Override 1066f60f7ed22f94891156115643452a32d0324f65aAdrian Roos public View onCreateView(LayoutInflater inflater, ViewGroup container, 1076f60f7ed22f94891156115643452a32d0324f65aAdrian Roos Bundle savedInstanceState) { 10825e30815752ab961c72617e8a84bd964449f874bMaurice Lam return inflater.inflate(R.layout.redaction_interstitial, container, false); 10925e30815752ab961c72617e8a84bd964449f874bMaurice Lam } 11025e30815752ab961c72617e8a84bd964449f874bMaurice Lam 11125e30815752ab961c72617e8a84bd964449f874bMaurice Lam @Override 11225e30815752ab961c72617e8a84bd964449f874bMaurice Lam public void onViewCreated(View view, Bundle savedInstanceState) { 11325e30815752ab961c72617e8a84bd964449f874bMaurice Lam super.onViewCreated(view, savedInstanceState); 114ccade402782d9b39331ada3859aa00893132e5c9Alex Chau mRadioGroup = (RadioGroup) view.findViewById(R.id.radio_group); 1151901ae3b3bddafc938bcbc0b03f18d7e12efef12Sudheer Shanka mShowAllButton = (RestrictedRadioButton) view.findViewById(R.id.show_all); 116f6077f4757183ae8b31af0928c895c806241b593Clara Bayarri mRedactSensitiveButton = 117f6077f4757183ae8b31af0928c895c806241b593Clara Bayarri (RestrictedRadioButton) view.findViewById(R.id.redact_sensitive); 1186f60f7ed22f94891156115643452a32d0324f65aAdrian Roos 119ccade402782d9b39331ada3859aa00893132e5c9Alex Chau mRadioGroup.setOnCheckedChangeListener(this); 120f6077f4757183ae8b31af0928c895c806241b593Clara Bayarri mUserId = Utils.getUserIdFromBundle( 121f6077f4757183ae8b31af0928c895c806241b593Clara Bayarri getContext(), getActivity().getIntent().getExtras()); 122788671647c6d615684d159a94ffb5b4367df6896Robin Lee if (UserManager.get(getContext()).isManagedProfile(mUserId)) { 123f6077f4757183ae8b31af0928c895c806241b593Clara Bayarri ((TextView) view.findViewById(R.id.message)) 12472137f3aad67a3bf16d0e9f82a68f3dd8072be0aPavel Grafov .setText(R.string.lock_screen_notifications_interstitial_message_profile); 125f6077f4757183ae8b31af0928c895c806241b593Clara Bayarri mShowAllButton.setText(R.string.lock_screen_notifications_summary_show_profile); 126f6077f4757183ae8b31af0928c895c806241b593Clara Bayarri mRedactSensitiveButton 12772137f3aad67a3bf16d0e9f82a68f3dd8072be0aPavel Grafov .setText(R.string.lock_screen_notifications_summary_hide_profile); 12872137f3aad67a3bf16d0e9f82a68f3dd8072be0aPavel Grafov 12972137f3aad67a3bf16d0e9f82a68f3dd8072be0aPavel Grafov ((RadioButton) view.findViewById(R.id.hide_all)).setVisibility(View.GONE); 130f6077f4757183ae8b31af0928c895c806241b593Clara Bayarri } 131d189ac52a4e49291b729d817fc903116abc086d0Maurice Lam 132d189ac52a4e49291b729d817fc903116abc086d0Maurice Lam final Button button = (Button) view.findViewById(R.id.redaction_done_button); 133d189ac52a4e49291b729d817fc903116abc086d0Maurice Lam button.setOnClickListener(this); 134d189ac52a4e49291b729d817fc903116abc086d0Maurice Lam } 135d189ac52a4e49291b729d817fc903116abc086d0Maurice Lam 136d189ac52a4e49291b729d817fc903116abc086d0Maurice Lam @Override 137d189ac52a4e49291b729d817fc903116abc086d0Maurice Lam public void onClick(View v) { 138d189ac52a4e49291b729d817fc903116abc086d0Maurice Lam if (v.getId() == R.id.redaction_done_button) { 139957fc67af21b87c01e2c5939f0611021d8fe6c31Maurice Lam SetupRedactionInterstitial.setEnabled(getContext(), false); 140d189ac52a4e49291b729d817fc903116abc086d0Maurice Lam final RedactionInterstitial activity = (RedactionInterstitial) getActivity(); 141d189ac52a4e49291b729d817fc903116abc086d0Maurice Lam if (activity != null) { 1420b431fc003d2ffa93d90ac3b1a92eb46b4d3f55aMatthew Fritze activity.setResult(RESULT_OK, null); 143d189ac52a4e49291b729d817fc903116abc086d0Maurice Lam finish(); 144d189ac52a4e49291b729d817fc903116abc086d0Maurice Lam } 145d189ac52a4e49291b729d817fc903116abc086d0Maurice Lam } 1466f60f7ed22f94891156115643452a32d0324f65aAdrian Roos } 1476f60f7ed22f94891156115643452a32d0324f65aAdrian Roos 1486f60f7ed22f94891156115643452a32d0324f65aAdrian Roos @Override 1496f60f7ed22f94891156115643452a32d0324f65aAdrian Roos public void onResume() { 1506f60f7ed22f94891156115643452a32d0324f65aAdrian Roos super.onResume(); 1511901ae3b3bddafc938bcbc0b03f18d7e12efef12Sudheer Shanka // Disable buttons according to policy. 1521901ae3b3bddafc938bcbc0b03f18d7e12efef12Sudheer Shanka 1531901ae3b3bddafc938bcbc0b03f18d7e12efef12Sudheer Shanka checkNotificationFeaturesAndSetDisabled(mShowAllButton, 1541901ae3b3bddafc938bcbc0b03f18d7e12efef12Sudheer Shanka KEYGUARD_DISABLE_SECURE_NOTIFICATIONS | 1551901ae3b3bddafc938bcbc0b03f18d7e12efef12Sudheer Shanka KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS); 1561901ae3b3bddafc938bcbc0b03f18d7e12efef12Sudheer Shanka checkNotificationFeaturesAndSetDisabled(mRedactSensitiveButton, 1571901ae3b3bddafc938bcbc0b03f18d7e12efef12Sudheer Shanka KEYGUARD_DISABLE_SECURE_NOTIFICATIONS); 1586f60f7ed22f94891156115643452a32d0324f65aAdrian Roos loadFromSettings(); 1596f60f7ed22f94891156115643452a32d0324f65aAdrian Roos } 1606f60f7ed22f94891156115643452a32d0324f65aAdrian Roos 1611901ae3b3bddafc938bcbc0b03f18d7e12efef12Sudheer Shanka private void checkNotificationFeaturesAndSetDisabled(RestrictedRadioButton button, 1621901ae3b3bddafc938bcbc0b03f18d7e12efef12Sudheer Shanka int keyguardNotifications) { 1635590e2eb44bc8a301c8f4647b739d6788e9c1512Sudheer Shanka EnforcedAdmin admin = RestrictedLockUtils.checkIfKeyguardFeaturesDisabled( 164f6077f4757183ae8b31af0928c895c806241b593Clara Bayarri getActivity(), keyguardNotifications, mUserId); 1651901ae3b3bddafc938bcbc0b03f18d7e12efef12Sudheer Shanka button.setDisabledByAdmin(admin); 1661901ae3b3bddafc938bcbc0b03f18d7e12efef12Sudheer Shanka } 1671901ae3b3bddafc938bcbc0b03f18d7e12efef12Sudheer Shanka 1686f60f7ed22f94891156115643452a32d0324f65aAdrian Roos private void loadFromSettings() { 169c29b984a98156b34be07cc9026a31d40a9a8656cPavel Grafov final boolean managedProfile = UserManager.get(getContext()).isManagedProfile(mUserId); 170c29b984a98156b34be07cc9026a31d40a9a8656cPavel Grafov // Hiding all notifications is device-wide setting, managed profiles can only set 171c29b984a98156b34be07cc9026a31d40a9a8656cPavel Grafov // whether their notifications are show in full or redacted. 172c29b984a98156b34be07cc9026a31d40a9a8656cPavel Grafov final boolean showNotifications = managedProfile || Settings.Secure.getIntForUser( 173c29b984a98156b34be07cc9026a31d40a9a8656cPavel Grafov getContentResolver(), LOCK_SCREEN_SHOW_NOTIFICATIONS, 0, mUserId) != 0; 174c29b984a98156b34be07cc9026a31d40a9a8656cPavel Grafov final boolean showUnredacted = Settings.Secure.getIntForUser( 175c29b984a98156b34be07cc9026a31d40a9a8656cPavel Grafov getContentResolver(), LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1, mUserId) != 0; 176ccade402782d9b39331ada3859aa00893132e5c9Alex Chau 177ccade402782d9b39331ada3859aa00893132e5c9Alex Chau int checkedButtonId = R.id.hide_all; 178c29b984a98156b34be07cc9026a31d40a9a8656cPavel Grafov if (showNotifications) { 179c29b984a98156b34be07cc9026a31d40a9a8656cPavel Grafov if (showUnredacted && !mShowAllButton.isDisabledByAdmin()) { 180ccade402782d9b39331ada3859aa00893132e5c9Alex Chau checkedButtonId = R.id.show_all; 1811901ae3b3bddafc938bcbc0b03f18d7e12efef12Sudheer Shanka } else if (!mRedactSensitiveButton.isDisabledByAdmin()) { 182ccade402782d9b39331ada3859aa00893132e5c9Alex Chau checkedButtonId = R.id.redact_sensitive; 183ccade402782d9b39331ada3859aa00893132e5c9Alex Chau } 184ccade402782d9b39331ada3859aa00893132e5c9Alex Chau } 185ccade402782d9b39331ada3859aa00893132e5c9Alex Chau 186ccade402782d9b39331ada3859aa00893132e5c9Alex Chau mRadioGroup.check(checkedButtonId); 1876f60f7ed22f94891156115643452a32d0324f65aAdrian Roos } 1886f60f7ed22f94891156115643452a32d0324f65aAdrian Roos 1896f60f7ed22f94891156115643452a32d0324f65aAdrian Roos @Override 190ccade402782d9b39331ada3859aa00893132e5c9Alex Chau public void onCheckedChanged(RadioGroup group, int checkedId) { 191ccade402782d9b39331ada3859aa00893132e5c9Alex Chau final boolean show = (checkedId == R.id.show_all); 192ccade402782d9b39331ada3859aa00893132e5c9Alex Chau final boolean enabled = (checkedId != R.id.hide_all); 1936f60f7ed22f94891156115643452a32d0324f65aAdrian Roos 194f6077f4757183ae8b31af0928c895c806241b593Clara Bayarri Settings.Secure.putIntForUser(getContentResolver(), 195c29b984a98156b34be07cc9026a31d40a9a8656cPavel Grafov LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, show ? 1 : 0, mUserId); 196f6077f4757183ae8b31af0928c895c806241b593Clara Bayarri Settings.Secure.putIntForUser(getContentResolver(), 197c29b984a98156b34be07cc9026a31d40a9a8656cPavel Grafov LOCK_SCREEN_SHOW_NOTIFICATIONS, enabled ? 1 : 0, mUserId); 1986f4edf822fbbb1cabf7b76f126021e303ead454dAdrian Roos 1996f60f7ed22f94891156115643452a32d0324f65aAdrian Roos } 2006f60f7ed22f94891156115643452a32d0324f65aAdrian Roos } 2013e2afb6ef788dd80a619e467773490a1886d74cfDan Sandler} 202