SampleTrustAgent: Exercise KeyguardManager.isKeyguardInTrustedState

Bug: 18084166
Change-Id: I7d8695f4b576676cc6da1fe07fea05e72d04f33e
diff --git a/packages/Keyguard/test/SampleTrustAgent/res/layout/sample_trust_agent_settings.xml b/packages/Keyguard/test/SampleTrustAgent/res/layout/sample_trust_agent_settings.xml
index 796cefb..63694a8 100644
--- a/packages/Keyguard/test/SampleTrustAgent/res/layout/sample_trust_agent_settings.xml
+++ b/packages/Keyguard/test/SampleTrustAgent/res/layout/sample_trust_agent_settings.xml
@@ -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
diff --git a/packages/Keyguard/test/SampleTrustAgent/src/com/android/trustagent/test/SampleTrustAgentSettings.java b/packages/Keyguard/test/SampleTrustAgent/src/com/android/trustagent/test/SampleTrustAgentSettings.java
index bea74ab..39a599e 100644
--- a/packages/Keyguard/test/SampleTrustAgent/src/com/android/trustagent/test/SampleTrustAgentSettings.java
+++ b/packages/Keyguard/test/SampleTrustAgent/src/com/android/trustagent/test/SampleTrustAgentSettings.java
@@ -18,10 +18,12 @@
 
 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 @@
 
     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 @@
         super.onResume();
         mReportUnlockAttempts.setChecked(SampleTrustAgent.getReportUnlockAttempts(this));
         mManagingTrust.setChecked(SampleTrustAgent.getIsManagingTrust(this));
+        updateTrustedState();
     }
 
     @Override
@@ -64,6 +77,8 @@
             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 @@
             SampleTrustAgent.setIsManagingTrust(this, isChecked);
         }
     }
+
+    private void updateTrustedState() {
+        mCheckTrustedStateResult.setText(Boolean.toString(
+                mKeyguardManager.isKeyguardInTrustedState()));
+    }
 }