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

Commit 2bb8bfd1 authored by Adrian Roos's avatar Adrian Roos
Browse files

Dismiss bouncer when onTrustInitiatedByUser fires

Also modifies the SampleTrustAgent to allow testing of the feature
and adds the initiatedByUser flag to the dumpsys output.

Bug: 16840500
Change-Id: I4c08ddcdcbd0ab02c694a1873f73cb9a250f98d7
parent 959409b8
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -68,5 +68,17 @@ public class KeyguardSimpleHostView extends KeyguardViewBase {
        public void onUserSwitchComplete(int userId) {
            getSecurityContainer().showPrimarySecurityScreen(false /* turning off */);
        }

        @Override
        public void onTrustInitiatedByUser(int userId) {
            if (userId != mLockPatternUtils.getCurrentUser()) return;
            if (!isAttachedToWindow()) return;

            if (isVisibleToUser()) {
                dismiss(false /* authenticated */);
            } else {
                // TODO: Play first half of unlock sound.
            }
        }
    };
}
+23 −5
Original line number Diff line number Diff line
@@ -31,6 +31,16 @@ import android.widget.Toast;
public class SampleTrustAgent extends TrustAgentService
        implements SharedPreferences.OnSharedPreferenceChangeListener {

    /**
     * If true, allows anyone to control this trust agent, e.g. using adb:
     * <pre>
     * $ adb shell am broadcast -a action.sample_trust_agent.grant_trust\
     *  -e extra.message SampleTrust\
     *  --el extra.duration 1000 --ez extra.init_by_user false
     * </pre>
     */
    private static final boolean ALLOW_EXTERNAL_BROADCASTS = false;

    LocalBroadcastManager mLocalBroadcastManager;

    private static final String ACTION_GRANT_TRUST = "action.sample_trust_agent.grant_trust";
@@ -38,7 +48,7 @@ public class SampleTrustAgent extends TrustAgentService

    private static final String EXTRA_MESSAGE = "extra.message";
    private static final String EXTRA_DURATION = "extra.duration";
    private static final String EXTRA_EXTRA = "extra.extra";
    private static final String EXTRA_INITIATED_BY_USER = "extra.init_by_user";

    private static final String PREFERENCE_REPORT_UNLOCK_ATTEMPTS
            = "preference.report_unlock_attempts";
@@ -50,11 +60,16 @@ public class SampleTrustAgent extends TrustAgentService
    @Override
    public void onCreate() {
        super.onCreate();
        mLocalBroadcastManager = LocalBroadcastManager.getInstance(this);

        IntentFilter filter = new IntentFilter();
        filter.addAction(ACTION_GRANT_TRUST);
        filter.addAction(ACTION_REVOKE_TRUST);
        mLocalBroadcastManager = LocalBroadcastManager.getInstance(this);
        mLocalBroadcastManager.registerReceiver(mReceiver, filter);
        if (ALLOW_EXTERNAL_BROADCASTS) {
            registerReceiver(mReceiver, filter);
        }

        setManagingTrust(getIsManagingTrust(this));
        PreferenceManager.getDefaultSharedPreferences(this)
                .registerOnSharedPreferenceChangeListener(this);
@@ -79,6 +94,9 @@ public class SampleTrustAgent extends TrustAgentService
    public void onDestroy() {
        super.onDestroy();
        mLocalBroadcastManager.unregisterReceiver(mReceiver);
        if (ALLOW_EXTERNAL_BROADCASTS) {
            unregisterReceiver(mReceiver);
        }
        PreferenceManager.getDefaultSharedPreferences(this)
                .unregisterOnSharedPreferenceChangeListener(this);
    }
@@ -91,7 +109,7 @@ public class SampleTrustAgent extends TrustAgentService
                try {
                    grantTrust(intent.getStringExtra(EXTRA_MESSAGE),
                            intent.getLongExtra(EXTRA_DURATION, 0),
                            false /* initiatedByUser */);
                            intent.getBooleanExtra(EXTRA_INITIATED_BY_USER, false));
                } catch (IllegalStateException e) {
                    Toast.makeText(context,
                            "IllegalStateException: " + e.getMessage(), Toast.LENGTH_SHORT).show();
@@ -103,11 +121,11 @@ public class SampleTrustAgent extends TrustAgentService
    };

    public static void sendGrantTrust(Context context,
            String message, long durationMs, Bundle extra) {
            String message, long durationMs, boolean initiatedByUser) {
        Intent intent = new Intent(ACTION_GRANT_TRUST);
        intent.putExtra(EXTRA_MESSAGE, message);
        intent.putExtra(EXTRA_DURATION, durationMs);
        intent.putExtra(EXTRA_EXTRA, extra);
        intent.putExtra(EXTRA_INITIATED_BY_USER, initiatedByUser);
        LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
    }

+1 −1
Original line number Diff line number Diff line
@@ -59,7 +59,7 @@ public class SampleTrustAgentSettings extends Activity implements View.OnClickLi
        int id = v.getId();
        if (id == R.id.enable_trust) {
            SampleTrustAgent.sendGrantTrust(this, "SampleTrustAgent", TRUST_DURATION_MS,
                    null /* extra */);
                    false /* initiatedByUser */);
        } else if (id == R.id.revoke_trust) {
            SampleTrustAgent.sendRevokeTrust(this);
        } else if (id == R.id.crash) {
+2 −2
Original line number Diff line number Diff line
@@ -129,8 +129,8 @@ public class TrustArchive {
            }
            switch (ev.type) {
                case TYPE_GRANT_TRUST:
                    writer.printf(", message=\"%s\", duration=%s",
                            ev.message, formatDuration(ev.duration));
                    writer.printf(", message=\"%s\", duration=%s, initiatedByUser=%d",
                            ev.message, formatDuration(ev.duration), ev.userInitiated ? 1 : 0);
                    break;
                case TYPE_MANAGING_TRUST:
                    writer.printf(", managingTrust=" + ev.managingTrust);