From 8e8a69e90fbc35f794fa9f6d3bd9e1227ed1a6e8 Mon Sep 17 00:00:00 2001 From: Mady Mellor Date: Mon, 14 Mar 2016 12:30:10 -0700 Subject: [PATCH] Adds security challenge when changing notification settings from lock screen Bug: 27335311 Change-Id: Ifb9391e371472077447db4603b5ac7e9fba93c20 --- .../systemui/statusbar/BaseStatusBar.java | 46 +++++++++++++------ .../systemui/statusbar/NotificationGuts.java | 37 +++++++++------ .../statusbar/phone/PhoneStatusBar.java | 6 +++ 3 files changed, 61 insertions(+), 28 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java index 143f1601e21a3..53f4edef46271 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java @@ -1003,24 +1003,42 @@ public abstract class BaseStatusBar extends SystemUI implements row.findViewById(R.id.done).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - guts.saveImportance(sbn); - - int[] rowLocation = new int[2]; - int[] doneLocation = new int[2]; - row.getLocationOnScreen(rowLocation); - v.getLocationOnScreen(doneLocation); - - final int centerX = v.getWidth() / 2; - final int centerY = v.getHeight() / 2; - final int x = doneLocation[0] - rowLocation[0] + centerX; - final int y = doneLocation[1] - rowLocation[1] + centerY; - dismissPopups(x, y); + // If the user has security enabled, show challenge if the setting is changed. + if (guts.hasImportanceChanged() && isLockscreenPublicMode() && + (mState == StatusBarState.KEYGUARD + || mState == StatusBarState.SHADE_LOCKED)) { + OnDismissAction dismissAction = new OnDismissAction() { + @Override + public boolean onDismiss() { + saveImportanceCloseControls(sbn, row, guts, v); + return true; + } + }; + onLockedNotificationImportanceChange(dismissAction); + } else { + saveImportanceCloseControls(sbn, row, guts, v); + } } }); - guts.bindImportance(pmUser, sbn, row, mNotificationData.getImportance(sbn.getKey())); } + private void saveImportanceCloseControls(StatusBarNotification sbn, + ExpandableNotificationRow row, NotificationGuts guts, View done) { + guts.saveImportance(sbn); + + int[] rowLocation = new int[2]; + int[] doneLocation = new int[2]; + row.getLocationOnScreen(rowLocation); + done.getLocationOnScreen(doneLocation); + + final int centerX = done.getWidth() / 2; + final int centerY = done.getHeight() / 2; + final int x = doneLocation[0] - rowLocation[0] + centerX; + final int y = doneLocation[1] - rowLocation[1] + centerY; + dismissPopups(x, y); + } + protected GearDisplayedListener getGearDisplayedListener() { return this; } @@ -1409,6 +1427,8 @@ public abstract class BaseStatusBar extends SystemUI implements } } + protected void onLockedNotificationImportanceChange(OnDismissAction dismissAction) {} + protected void onLockedRemoteInput(ExpandableNotificationRow row, View clickedView) {} @Override diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationGuts.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationGuts.java index 45a24a0b38224..3e0542f97e480 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationGuts.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationGuts.java @@ -130,30 +130,23 @@ public class NotificationGuts extends LinearLayout implements TunerService.Tunab importanceSlider.setVisibility(View.VISIBLE); importanceButtons.setVisibility(View.GONE); } else { - int userImportance = NotificationListenerService.Ranking.IMPORTANCE_UNSPECIFIED; + mStartingImportance = NotificationListenerService.Ranking.IMPORTANCE_UNSPECIFIED; try { - userImportance = + mStartingImportance = mINotificationManager.getImportance(sbn.getPackageName(), sbn.getUid()); } catch (RemoteException e) {} - bindToggles(importanceButtons, userImportance, systemApp); + bindToggles(importanceButtons, mStartingImportance, systemApp); importanceButtons.setVisibility(View.VISIBLE); importanceSlider.setVisibility(View.GONE); } } + public boolean hasImportanceChanged() { + return mStartingImportance != getSelectedImportance(); + } + void saveImportance(final StatusBarNotification sbn) { - int progress; - if (mSeekBar!= null && mSeekBar.isShown()) { - progress = mSeekBar.getProgress(); - } else { - if (mBlock.isChecked()) { - progress = NotificationListenerService.Ranking.IMPORTANCE_NONE; - } else if (mSilent.isChecked()) { - progress = NotificationListenerService.Ranking.IMPORTANCE_LOW; - } else { - progress = NotificationListenerService.Ranking.IMPORTANCE_UNSPECIFIED; - } - } + int progress = getSelectedImportance(); MetricsLogger.action(mContext, MetricsEvent.ACTION_SAVE_IMPORTANCE, progress - mStartingImportance); try { @@ -163,6 +156,20 @@ public class NotificationGuts extends LinearLayout implements TunerService.Tunab } } + private int getSelectedImportance() { + if (mSeekBar!= null && mSeekBar.isShown()) { + return mSeekBar.getProgress(); + } else { + if (mBlock.isChecked()) { + return NotificationListenerService.Ranking.IMPORTANCE_NONE; + } else if (mSilent.isChecked()) { + return NotificationListenerService.Ranking.IMPORTANCE_LOW; + } else { + return NotificationListenerService.Ranking.IMPORTANCE_UNSPECIFIED; + } + } + } + private void bindToggles(final View importanceButtons, final int importance, final boolean systemApp) { mBlock = (RadioButton) importanceButtons.findViewById(R.id.block_importance); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java index 906bd0ff4b574..9bf0710e07f1c 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java @@ -4132,6 +4132,12 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, } } + @Override + public void onLockedNotificationImportanceChange(OnDismissAction dismissAction) { + mLeaveOpenOnKeyguardHide = true; + dismissKeyguardThenExecute(dismissAction, true /* afterKeyguardGone */); + } + @Override protected void onLockedRemoteInput(ExpandableNotificationRow row, View clicked) { mLeaveOpenOnKeyguardHide = true;