diff options
author | Adrian Roos <roosa@google.com> | 2014-07-25 15:37:28 +0200 |
---|---|---|
committer | Adrian Roos <roosa@google.com> | 2014-07-30 12:33:33 +0000 |
commit | 7861c663fd64af33ec2a4c5ad653c806dc8bd994 (patch) | |
tree | 84404afe7c7438fddbd9c659202a34e1d8e24515 /packages/Keyguard/test/SampleTrustAgent | |
parent | 8c146ae9be387da55b5cbf57314543a4fa16052b (diff) | |
download | frameworks_base-7861c663fd64af33ec2a4c5ad653c806dc8bd994.zip frameworks_base-7861c663fd64af33ec2a4c5ad653c806dc8bd994.tar.gz frameworks_base-7861c663fd64af33ec2a4c5ad653c806dc8bd994.tar.bz2 |
Add setManagingTrust and expose it on lockscreen
Adds a facility for trust agents to indicate if they
are ready to manage trust. Also adds an indication to
the lock icon on the lockscreen to show whether trust is
being managed.
Bug: 15518469
Bug: 16123013
Change-Id: Ie17f588aebeafe66c81dea4a69c733b0d2c72fd4
Diffstat (limited to 'packages/Keyguard/test/SampleTrustAgent')
3 files changed, 52 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 06a06bf..796cefb 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 @@ -32,8 +32,16 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Crash" /> + <CheckBox android:id="@+id/managing_trust" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:paddingTop="8dp" + android:paddingBottom="8dp" + android:text="Managing trust" /> <CheckBox android:id="@+id/report_unlock_attempts" android:layout_width="match_parent" android:layout_height="wrap_content" + android:paddingTop="8dp" + android:paddingBottom="8dp" android:text="Report unlock attempts" /> </LinearLayout>
\ No newline at end of file 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 50a3f82..ed17494 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 @@ -28,7 +28,8 @@ import android.support.v4.content.LocalBroadcastManager; import android.util.Log; import android.widget.Toast; -public class SampleTrustAgent extends TrustAgentService { +public class SampleTrustAgent extends TrustAgentService + implements SharedPreferences.OnSharedPreferenceChangeListener { LocalBroadcastManager mLocalBroadcastManager; @@ -41,6 +42,8 @@ public class SampleTrustAgent extends TrustAgentService { private static final String PREFERENCE_REPORT_UNLOCK_ATTEMPTS = "preference.report_unlock_attempts"; + private static final String PREFERENCE_MANAGING_TRUST + = "preference.managing_trust"; private static final String TAG = "SampleTrustAgent"; @@ -52,6 +55,9 @@ public class SampleTrustAgent extends TrustAgentService { filter.addAction(ACTION_REVOKE_TRUST); mLocalBroadcastManager = LocalBroadcastManager.getInstance(this); mLocalBroadcastManager.registerReceiver(mReceiver, filter); + setManagingTrust(getIsManagingTrust(this)); + PreferenceManager.getDefaultSharedPreferences(this) + .registerOnSharedPreferenceChangeListener(this); } @Override @@ -73,6 +79,8 @@ public class SampleTrustAgent extends TrustAgentService { public void onDestroy() { super.onDestroy(); mLocalBroadcastManager.unregisterReceiver(mReceiver); + PreferenceManager.getDefaultSharedPreferences(this) + .unregisterOnSharedPreferenceChangeListener(this); } private BroadcastReceiver mReceiver = new BroadcastReceiver() { @@ -80,9 +88,14 @@ public class SampleTrustAgent extends TrustAgentService { public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (ACTION_GRANT_TRUST.equals(action)) { - grantTrust(intent.getStringExtra(EXTRA_MESSAGE), - intent.getLongExtra(EXTRA_DURATION, 0), - false /* initiatedByUser */); + try { + grantTrust(intent.getStringExtra(EXTRA_MESSAGE), + intent.getLongExtra(EXTRA_DURATION, 0), + false /* initiatedByUser */); + } catch (IllegalStateException e) { + Toast.makeText(context, + "IllegalStateException: " + e.getMessage(), Toast.LENGTH_SHORT).show(); + } } else if (ACTION_REVOKE_TRUST.equals(action)) { revokeTrust(); } @@ -114,4 +127,23 @@ public class SampleTrustAgent extends TrustAgentService { .getDefaultSharedPreferences(context); return sharedPreferences.getBoolean(PREFERENCE_REPORT_UNLOCK_ATTEMPTS, false); } + + public static void setIsManagingTrust(Context context, boolean enabled) { + SharedPreferences sharedPreferences = PreferenceManager + .getDefaultSharedPreferences(context); + sharedPreferences.edit().putBoolean(PREFERENCE_MANAGING_TRUST, enabled).apply(); + } + + public static boolean getIsManagingTrust(Context context) { + SharedPreferences sharedPreferences = PreferenceManager + .getDefaultSharedPreferences(context); + return sharedPreferences.getBoolean(PREFERENCE_MANAGING_TRUST, false); + } + + @Override + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { + if (PREFERENCE_MANAGING_TRUST.equals(key)) { + setManagingTrust(getIsManagingTrust(this)); + } + } } 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 6b5f78b..2c85609 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 @@ -29,6 +29,7 @@ public class SampleTrustAgentSettings extends Activity implements View.OnClickLi private static final int TRUST_DURATION_MS = 30 * 1000; private CheckBox mReportUnlockAttempts; + private CheckBox mManagingTrust; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -41,12 +42,16 @@ public class SampleTrustAgentSettings extends Activity implements View.OnClickLi mReportUnlockAttempts = (CheckBox) findViewById(R.id.report_unlock_attempts); mReportUnlockAttempts.setOnCheckedChangeListener(this); + + mManagingTrust = (CheckBox) findViewById(R.id.managing_trust); + mManagingTrust.setOnCheckedChangeListener(this); } @Override protected void onResume() { super.onResume(); mReportUnlockAttempts.setChecked(SampleTrustAgent.getReportUnlockAttempts(this)); + mManagingTrust.setChecked(SampleTrustAgent.getIsManagingTrust(this)); } @Override @@ -64,8 +69,10 @@ public class SampleTrustAgentSettings extends Activity implements View.OnClickLi @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if (buttonView.getId() == R.id.report_unlock_attempts) { + if (buttonView == mReportUnlockAttempts) { SampleTrustAgent.setReportUnlockAttempts(this, isChecked); + } else if (buttonView == mManagingTrust) { + SampleTrustAgent.setIsManagingTrust(this, isChecked); } } } |