Add restricted padlocks to radio buttons.

Change-Id: Ibaf312a4c6c5fd9126ab7d45ccb094fc1bd46a1f
This commit is contained in:
Sudheer Shanka
2016-01-08 20:40:55 +00:00
parent 3375206f46
commit 1901ae3b3b
3 changed files with 118 additions and 43 deletions

View File

@@ -16,7 +16,6 @@
package com.android.settings.notification;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
@@ -29,8 +28,15 @@ import android.widget.RadioGroup;
import com.android.internal.logging.MetricsLogger;
import com.android.settings.R;
import com.android.settings.RestrictedRadioButton;
import com.android.settings.SettingsActivity;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settingslib.RestrictedLockUtils;
import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS;
import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS;
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
public class RedactionInterstitial extends SettingsActivity {
@@ -52,40 +58,21 @@ public class RedactionInterstitial extends SettingsActivity {
* available to be launched.
*/
public static Intent createStartIntent(Context ctx) {
if (isSecureNotificationsDisabled(ctx)) {
// If there is no choices for the user, we should not start the activity.
return null;
} else {
return new Intent(ctx, RedactionInterstitial.class)
.putExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, true)
.putExtra(EXTRA_PREFS_SET_BACK_TEXT, (String) null)
.putExtra(EXTRA_PREFS_SET_NEXT_TEXT, ctx.getString(
R.string.app_notifications_dialog_done))
.putExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID,
R.string.lock_screen_notifications_interstitial_title);
}
}
private static boolean isSecureNotificationsDisabled(Context context) {
final DevicePolicyManager dpm =
(DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
return dpm != null && (dpm.getKeyguardDisabledFeatures(null)
& DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS) != 0;
}
private static boolean isUnredactedNotificationsDisabled(Context context) {
final DevicePolicyManager dpm =
(DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
return dpm != null && (dpm.getKeyguardDisabledFeatures(null)
& DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS) != 0;
return new Intent(ctx, RedactionInterstitial.class)
.putExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, true)
.putExtra(EXTRA_PREFS_SET_BACK_TEXT, (String) null)
.putExtra(EXTRA_PREFS_SET_NEXT_TEXT, ctx.getString(
R.string.app_notifications_dialog_done))
.putExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID,
R.string.lock_screen_notifications_interstitial_title);
}
public static class RedactionInterstitialFragment extends SettingsPreferenceFragment
implements RadioGroup.OnCheckedChangeListener {
private RadioGroup mRadioGroup;
private RadioButton mShowAllButton;
private RadioButton mRedactSensitiveButton;
private RestrictedRadioButton mShowAllButton;
private RestrictedRadioButton mRedactSensitiveButton;
@Override
protected int getMetricsCategory() {
@@ -102,26 +89,32 @@ public class RedactionInterstitial extends SettingsActivity {
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mRadioGroup = (RadioGroup) view.findViewById(R.id.radio_group);
mShowAllButton = (RadioButton) view.findViewById(R.id.show_all);
mRedactSensitiveButton = (RadioButton) view.findViewById(R.id.redact_sensitive);
mShowAllButton = (RestrictedRadioButton) view.findViewById(R.id.show_all);
mRedactSensitiveButton = (RestrictedRadioButton) view.findViewById(R.id.redact_sensitive);
mRadioGroup.setOnCheckedChangeListener(this);
// Disable buttons according to policy.
if (isSecureNotificationsDisabled(getActivity())) {
mShowAllButton.setEnabled(false);
mRedactSensitiveButton.setEnabled(false);
} else if (isUnredactedNotificationsDisabled(getActivity())) {
mShowAllButton.setEnabled(false);
}
}
@Override
public void onResume() {
super.onResume();
// Disable buttons according to policy.
checkNotificationFeaturesAndSetDisabled(mShowAllButton,
KEYGUARD_DISABLE_SECURE_NOTIFICATIONS |
KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS);
checkNotificationFeaturesAndSetDisabled(mRedactSensitiveButton,
KEYGUARD_DISABLE_SECURE_NOTIFICATIONS);
loadFromSettings();
}
private void checkNotificationFeaturesAndSetDisabled(RestrictedRadioButton button,
int keyguardNotifications) {
EnforcedAdmin admin = RestrictedLockUtils.checkIfKeyguardNotificationFeaturesDisabled(
getActivity(), keyguardNotifications);
button.setDisabledByAdmin(admin);
}
private void loadFromSettings() {
final boolean enabled = Settings.Secure.getInt(getContentResolver(),
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0) != 0;
@@ -130,9 +123,9 @@ public class RedactionInterstitial extends SettingsActivity {
int checkedButtonId = R.id.hide_all;
if (enabled) {
if (show && mShowAllButton.isEnabled()) {
if (show && !mShowAllButton.isDisabledByAdmin()) {
checkedButtonId = R.id.show_all;
} else if (mRedactSensitiveButton.isEnabled()) {
} else if (!mRedactSensitiveButton.isDisabledByAdmin()) {
checkedButtonId = R.id.redact_sensitive;
}
}