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

Commit c6463e0d authored by Roman Birg's avatar Roman Birg Committed by Gerrit Code Review
Browse files

Setting: broadcast protected app result if requested



Change-Id: I8124fc8569123e8a631bf35593626a76ee3741dc
Signed-off-by: default avatarRoman Birg <roman@cyngn.com>
parent 9ac5f204
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.settings.applications;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
@@ -42,6 +43,10 @@ import java.util.List;
public class LockPatternActivity extends Activity implements OnNotifyAccountReset {
    public static final String PATTERN_LOCK_PROTECTED_APPS = "pattern_lock_protected_apps";
    public static final String RECREATE_PATTERN = "recreate_pattern_lock";
    public static final String ACTION_BROADCAST_RESULT = "com.android.settings.applications.LockPatternActivity.ACTION_BROADCAST_RESULT";

    // used for incoming and outgoing broadcast intents
    public static final String EXTRA_BROADCAST_RESULT = "broadcast_result";

    private static final int MIN_PATTERN_SIZE = 4;
    private static final int MAX_PATTERN_RETRY = 5;
@@ -63,6 +68,7 @@ public class LockPatternActivity extends Activity implements OnNotifyAccountRese
    boolean mCreate;
    boolean mRetryPattern = true;
    boolean mConfirming = false;
    boolean mBroadcastResult = false;

    Runnable mCancelPatternRunnable = new Runnable() {
        public void run() {
@@ -96,6 +102,7 @@ public class LockPatternActivity extends Activity implements OnNotifyAccountRese
            }
            setResult(RESULT_CANCELED);
            finish();
            maybeSendBroadcast(false);
        }
    };

@@ -183,6 +190,10 @@ public class LockPatternActivity extends Activity implements OnNotifyAccountRese
        super.onCreate(savedInstanceState);
        setContentView(R.layout.patternlock);

        if (getIntent() != null) {
            mBroadcastResult = getIntent().getBooleanExtra(EXTRA_BROADCAST_RESULT, false);
        }

        mPatternLockHeader = (TextView) findViewById(R.id.pattern_lock_header);
        mCancel = (Button) findViewById(R.id.pattern_lock_btn_cancel);
        mCancel.setOnClickListener(mCancelOnClickListener);
@@ -202,6 +213,14 @@ public class LockPatternActivity extends Activity implements OnNotifyAccountRese

    }

    @Override
    protected void onPause() {
        super.onPause();
        if (!isFinishing()) {
            maybeSendBroadcast(false);
        }
    }

    private void resetPatternState(boolean clear) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        String pattern = prefs.getString(PATTERN_LOCK_PROTECTED_APPS, null);
@@ -225,6 +244,14 @@ public class LockPatternActivity extends Activity implements OnNotifyAccountRese
        invalidateOptionsMenu();
    }

    private void maybeSendBroadcast(boolean result) {
        if (mBroadcastResult) {
            Intent broadcastResult = new Intent(ACTION_BROADCAST_RESULT);
            broadcastResult.putExtra(EXTRA_BROADCAST_RESULT, result);
            sendBroadcast(broadcastResult);
        }
    }

    private class UnlockPatternListener implements LockPatternView.OnPatternListener {

        public void onPatternStart() {
@@ -287,6 +314,7 @@ public class LockPatternActivity extends Activity implements OnNotifyAccountRese
                if (Arrays.equals(mPatternHash, patternToHash(pattern))) {
                    setResult(RESULT_OK);
                    finish();
                    maybeSendBroadcast(true);
                } else {
                    mRetry++;
                    mPatternLockHeader.setText(getResources().getString(