Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8e8a69e9 authored by Mady Mellor's avatar Mady Mellor
Browse files

Adds security challenge when changing notification settings from lock screen

Bug: 27335311
Change-Id: Ifb9391e371472077447db4603b5ac7e9fba93c20
parent 466b702c
Loading
Loading
Loading
Loading
+33 −13
Original line number Diff line number Diff line
@@ -1003,23 +1003,41 @@ public abstract class BaseStatusBar extends SystemUI implements
        row.findViewById(R.id.done).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 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);
                v.getLocationOnScreen(doneLocation);
        done.getLocationOnScreen(doneLocation);

                final int centerX = v.getWidth() / 2;
                final int centerY = v.getHeight() / 2;
        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);
    }
        });

        guts.bindImportance(pmUser, sbn, row, mNotificationData.getImportance(sbn.getKey()));
    }

    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
+22 −15
Original line number Diff line number Diff line
@@ -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);
        }
    }

    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;
            }
    public boolean hasImportanceChanged() {
        return mStartingImportance != getSelectedImportance();
    }

    void saveImportance(final StatusBarNotification sbn) {
        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);
+6 −0
Original line number Diff line number Diff line
@@ -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;