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

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

SampleTrustAgent: Exercise KeyguardManager.isKeyguardInTrustedState

Bug: 18084166
Change-Id: I7d8695f4b576676cc6da1fe07fea05e72d04f33e
parent bcd07652
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -44,4 +44,18 @@
            android:paddingTop="8dp"
            android:paddingBottom="8dp"
            android:text="Report unlock attempts" />

    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        <Button android:id="@+id/check_trusted"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Keyguard in trusted state?" />
        <TextView android:id="@+id/check_trusted_result"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1" />
    </LinearLayout>

</LinearLayout>
 No newline at end of file
+20 −0
Original line number Diff line number Diff line
@@ -18,10 +18,12 @@ package com.android.trustagent.test;

import android.annotation.Nullable;
import android.app.Activity;
import android.app.KeyguardManager;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;

public class SampleTrustAgentSettings extends Activity implements View.OnClickListener,
        CompoundButton.OnCheckedChangeListener {
@@ -30,21 +32,31 @@ public class SampleTrustAgentSettings extends Activity implements View.OnClickLi

    private CheckBox mReportUnlockAttempts;
    private CheckBox mManagingTrust;
    private TextView mCheckTrustedStateResult;

    private KeyguardManager mKeyguardManager;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mKeyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);

        setContentView(R.layout.sample_trust_agent_settings);

        findViewById(R.id.enable_trust).setOnClickListener(this);
        findViewById(R.id.revoke_trust).setOnClickListener(this);
        findViewById(R.id.crash).setOnClickListener(this);
        findViewById(R.id.check_trusted).setOnClickListener(this);

        mReportUnlockAttempts = (CheckBox) findViewById(R.id.report_unlock_attempts);
        mReportUnlockAttempts.setOnCheckedChangeListener(this);

        mManagingTrust = (CheckBox) findViewById(R.id.managing_trust);
        mManagingTrust.setOnCheckedChangeListener(this);

        mCheckTrustedStateResult = (TextView) findViewById(R.id.check_trusted_result);
    }

    @Override
@@ -52,6 +64,7 @@ public class SampleTrustAgentSettings extends Activity implements View.OnClickLi
        super.onResume();
        mReportUnlockAttempts.setChecked(SampleTrustAgent.getReportUnlockAttempts(this));
        mManagingTrust.setChecked(SampleTrustAgent.getIsManagingTrust(this));
        updateTrustedState();
    }

    @Override
@@ -64,6 +77,8 @@ public class SampleTrustAgentSettings extends Activity implements View.OnClickLi
            SampleTrustAgent.sendRevokeTrust(this);
        } else if (id == R.id.crash) {
            throw new RuntimeException("crash");
        } else if (id == R.id.check_trusted) {
            updateTrustedState();
        }
    }

@@ -75,4 +90,9 @@ public class SampleTrustAgentSettings extends Activity implements View.OnClickLi
            SampleTrustAgent.setIsManagingTrust(this, isChecked);
        }
    }

    private void updateTrustedState() {
        mCheckTrustedStateResult.setText(Boolean.toString(
                mKeyguardManager.isKeyguardInTrustedState()));
    }
}