diff options
author | Adrian Roos <roosa@google.com> | 2014-11-20 19:48:56 +0100 |
---|---|---|
committer | Adrian Roos <roosa@google.com> | 2014-11-20 21:48:38 +0100 |
commit | 481a6df99fea124bc4354da34ff668750cdc9041 (patch) | |
tree | cfdf0dafeb00887d67fbb02d8046fba0dfab4685 /packages/Keyguard/test | |
parent | 50bfeec868157106e8b60abf8964cb24462af182 (diff) | |
download | frameworks_base-481a6df99fea124bc4354da34ff668750cdc9041.zip frameworks_base-481a6df99fea124bc4354da34ff668750cdc9041.tar.gz frameworks_base-481a6df99fea124bc4354da34ff668750cdc9041.tar.bz2 |
Add device locked API for TrustAgentService
Bug: 18414067
Change-Id: I96c68af9ccc9940acf9fab3b5bd39a3485f01045
Diffstat (limited to 'packages/Keyguard/test')
3 files changed, 49 insertions, 5 deletions
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 bb72c12..00193ed 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,6 +44,12 @@ android:paddingTop="8dp" android:paddingBottom="8dp" android:text="Report unlock attempts" /> + <CheckBox android:id="@+id/report_device_locked" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:paddingTop="8dp" + android:paddingBottom="8dp" + android:text="Report device locked or unlocked" /> <LinearLayout android:layout_width="match_parent" diff --git a/packages/Keyguard/test/SampleTrustAgent/src/com/android/trustagent/test/SampleTrustAgent.java b/packages/Keyguard/test/SampleTrustAgent/src/com/android/trustagent/test/SampleTrustAgent.java index f28d0e4..e6a0dd7 100644 --- a/packages/Keyguard/test/SampleTrustAgent/src/com/android/trustagent/test/SampleTrustAgent.java +++ b/packages/Keyguard/test/SampleTrustAgent/src/com/android/trustagent/test/SampleTrustAgent.java @@ -56,6 +56,7 @@ public class SampleTrustAgent extends TrustAgentService = "preference.report_unlock_attempts"; private static final String PREFERENCE_MANAGING_TRUST = "preference.managing_trust"; + private static final String PREFERENCE_REPORT_DEVICE_LOCKED = "preference.report_device_locked"; private static final String TAG = "SampleTrustAgent"; @@ -80,17 +81,37 @@ public class SampleTrustAgent extends TrustAgentService @Override public void onTrustTimeout() { super.onTrustTimeout(); - Toast.makeText(this, "onTrustTimeout(): timeout expired", Toast.LENGTH_SHORT).show(); + logAndShowToast("onTrustTimeout(): timeout expired"); + } + + @Override + public void onDeviceLocked() { + super.onDeviceLocked(); + if (getReportDeviceLocked(this)) { + logAndShowToast("onDeviceLocked(): device is now locked"); + } + } + + @Override + public void onDeviceUnlocked() { + super.onDeviceUnlocked(); + if (getReportDeviceLocked(this)) { + logAndShowToast("onDeviceUnlocked(): device is now unlocked"); + } } @Override public void onUnlockAttempt(boolean successful) { if (getReportUnlockAttempts(this)) { - Toast.makeText(this, "onUnlockAttempt(successful=" + successful + ")", - Toast.LENGTH_SHORT).show(); + logAndShowToast("onUnlockAttempt(successful=" + successful + ")"); } } + private void logAndShowToast(String text) { + Log.i(TAG, text); + Toast.makeText(this, text, Toast.LENGTH_SHORT).show(); + } + @Override public boolean onConfigure(List<PersistableBundle> options) { if (options != null) { @@ -125,8 +146,7 @@ public class SampleTrustAgent extends TrustAgentService intent.getLongExtra(EXTRA_DURATION, 0), intent.getBooleanExtra(EXTRA_INITIATED_BY_USER, false)); } catch (IllegalStateException e) { - Toast.makeText(context, - "IllegalStateException: " + e.getMessage(), Toast.LENGTH_SHORT).show(); + logAndShowToast("IllegalStateException: " + e.getMessage()); } } else if (ACTION_REVOKE_TRUST.equals(action)) { revokeTrust(); @@ -160,6 +180,18 @@ public class SampleTrustAgent extends TrustAgentService return sharedPreferences.getBoolean(PREFERENCE_REPORT_UNLOCK_ATTEMPTS, false); } + public static void setReportDeviceLocked(Context context, boolean enabled) { + SharedPreferences sharedPreferences = PreferenceManager + .getDefaultSharedPreferences(context); + sharedPreferences.edit().putBoolean(PREFERENCE_REPORT_DEVICE_LOCKED, enabled).apply(); + } + + public static boolean getReportDeviceLocked(Context context) { + SharedPreferences sharedPreferences = PreferenceManager + .getDefaultSharedPreferences(context); + return sharedPreferences.getBoolean(PREFERENCE_REPORT_DEVICE_LOCKED, false); + } + public static void setIsManagingTrust(Context context, boolean enabled) { SharedPreferences sharedPreferences = PreferenceManager .getDefaultSharedPreferences(context); 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 7edf2bb..29b15cb 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 @@ -31,6 +31,7 @@ public class SampleTrustAgentSettings extends Activity implements View.OnClickLi private static final int TRUST_DURATION_MS = 30 * 1000; private CheckBox mReportUnlockAttempts; + private CheckBox mReportDeviceLocked; private CheckBox mManagingTrust; private TextView mCheckDeviceLockedResult; @@ -53,6 +54,9 @@ public class SampleTrustAgentSettings extends Activity implements View.OnClickLi mReportUnlockAttempts = (CheckBox) findViewById(R.id.report_unlock_attempts); mReportUnlockAttempts.setOnCheckedChangeListener(this); + mReportDeviceLocked = (CheckBox) findViewById(R.id.report_device_locked); + mReportDeviceLocked.setOnCheckedChangeListener(this); + mManagingTrust = (CheckBox) findViewById(R.id.managing_trust); mManagingTrust.setOnCheckedChangeListener(this); @@ -88,6 +92,8 @@ public class SampleTrustAgentSettings extends Activity implements View.OnClickLi SampleTrustAgent.setReportUnlockAttempts(this, isChecked); } else if (buttonView == mManagingTrust) { SampleTrustAgent.setIsManagingTrust(this, isChecked); + } else if (buttonView == mReportDeviceLocked) { + SampleTrustAgent.setReportDeviceLocked(this, isChecked); } } |