diff options
author | Lingjun Li <lingjunl@google.com> | 2016-11-14 15:39:13 -0800 |
---|---|---|
committer | Lingjun Li <lingjunl@google.com> | 2016-12-09 12:33:52 -0800 |
commit | 20914d79393aead044848a337ff4f802e4afb48e (patch) | |
tree | fec31bac55f7434e5883482ec0feda959969decf /packages/Keyguard | |
parent | 99820db99a4dd2db6a49b91dcca0aa5b1d4ad348 (diff) |
Adding unlockProfile to trust-agent meta data and makes TrustAgent runnable under direct boot
Test: manual
Change-Id: I1f0ccafac08be2cc3f4540232e764ef21d4fed38
Diffstat (limited to 'packages/Keyguard')
6 files changed, 152 insertions, 4 deletions
diff --git a/packages/Keyguard/test/SampleTrustAgent/AndroidManifest.xml b/packages/Keyguard/test/SampleTrustAgent/AndroidManifest.xml index a7c91058283b..edcea0e64ac7 100644 --- a/packages/Keyguard/test/SampleTrustAgent/AndroidManifest.xml +++ b/packages/Keyguard/test/SampleTrustAgent/AndroidManifest.xml @@ -24,6 +24,7 @@ android:name=".SampleTrustAgent" android:label="@string/app_name" android:permission="android.permission.BIND_TRUST_AGENT" + android:directBootAware="true" android:exported="true"> <intent-filter> <action android:name="android.service.trust.TrustAgentService" /> diff --git a/packages/Keyguard/test/SampleTrustAgent/res/layout-v26/sample_trust_agent_settings.xml b/packages/Keyguard/test/SampleTrustAgent/res/layout-v26/sample_trust_agent_settings.xml new file mode 100644 index 000000000000..4669971e9be3 --- /dev/null +++ b/packages/Keyguard/test/SampleTrustAgent/res/layout-v26/sample_trust_agent_settings.xml @@ -0,0 +1,74 @@ +<?xml version="1.0" encoding="utf-8"?> + +<!-- + ~ Copyright (C) 2014 The Android Open Source Project + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License + --> + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="match_parent"> + <Button android:id="@+id/enable_trust" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="Grant trust for 30 seconds" /> + <Button android:id="@+id/revoke_trust" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="Revoke trust" /> + <Button android:id="@+id/crash" + 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/managing_trust_direct_boot" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:paddingTop="8dp" + android:paddingBottom="8dp" + android:text="Managing trust direct boot"/> + + <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" /> + <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" + android:layout_height="wrap_content"> + <Button android:id="@+id/check_device_locked" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Device locked?" /> + <TextView android:id="@+id/check_device_locked_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/res/xml-v26/sample_trust_agent.xml b/packages/Keyguard/test/SampleTrustAgent/res/xml-v26/sample_trust_agent.xml new file mode 100644 index 000000000000..26d5aa0c26f3 --- /dev/null +++ b/packages/Keyguard/test/SampleTrustAgent/res/xml-v26/sample_trust_agent.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2014 The Android Open Source Project + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License + --> +<trust-agent xmlns:android="http://schemas.android.com/apk/res/android" + android:settingsActivity=".SampleTrustAgentSettings" + android:unlockProfile="true" /> diff --git a/packages/Keyguard/test/SampleTrustAgent/res/xml/sample_trust_agent.xml b/packages/Keyguard/test/SampleTrustAgent/res/xml/sample_trust_agent.xml index b363ab459c6d..6cd34bbab8e0 100644 --- a/packages/Keyguard/test/SampleTrustAgent/res/xml/sample_trust_agent.xml +++ b/packages/Keyguard/test/SampleTrustAgent/res/xml/sample_trust_agent.xml @@ -15,4 +15,4 @@ ~ limitations under the License --> <trust-agent xmlns:android="http://schemas.android.com/apk/res/android" - android:settingsActivity=".SampleTrustAgentSettings" /> + android:settingsActivity=".SampleTrustAgentSettings" /> 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 b8f16e7929dc..4b50cf8c9fd5 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 @@ -22,6 +22,7 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; import android.os.PersistableBundle; +import android.os.UserManager; import android.preference.PreferenceManager; import android.service.trust.TrustAgentService; import android.support.v4.content.LocalBroadcastManager; @@ -57,26 +58,47 @@ public class SampleTrustAgent extends TrustAgentService = "preference.report_unlock_attempts"; private static final String PREFERENCE_MANAGING_TRUST = "preference.managing_trust"; + private static final String PREFERENCE_MANAGING_TRUST_DIRECT_BOOT + = "preference.managing_trust_direct_boot"; private static final String PREFERENCE_REPORT_DEVICE_LOCKED = "preference.report_device_locked"; private static final String TAG = "SampleTrustAgent"; + private static final BroadcastReceiver mUnlockReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + + } + }; + + private boolean mIsUserUnlocked; + @Override public void onCreate() { super.onCreate(); + UserManager um = (UserManager) getSystemService(Context.USER_SERVICE); + mIsUserUnlocked = um.isUserUnlocked(); + Log.i(TAG,, "onCreate, is user unlocked=" + mIsUserUnlocked); mLocalBroadcastManager = LocalBroadcastManager.getInstance(this); IntentFilter filter = new IntentFilter(); filter.addAction(ACTION_GRANT_TRUST); filter.addAction(ACTION_REVOKE_TRUST); + if (!mIsUserUnlocked) { + filter.addAction(Intent.ACTION_BOOT_COMPLETED); + } mLocalBroadcastManager.registerReceiver(mReceiver, filter); if (ALLOW_EXTERNAL_BROADCASTS) { registerReceiver(mReceiver, filter); } - setManagingTrust(getIsManagingTrust(this)); - PreferenceManager.getDefaultSharedPreferences(this) - .registerOnSharedPreferenceChangeListener(this); + if (!mIsUserUnlocked) { + boolean trustManaged = getIsManagingTrustDirectBoot(this); + Log.i(TAG, "in Direct boot." + (trustManaged ? "manage" : "cannot manage") + "trust"); + setManagingTrust(getIsManagingTrustDirectBoot(this)); + } else { + onBootCompleted(); + } } @Override @@ -137,6 +159,12 @@ public class SampleTrustAgent extends TrustAgentService .unregisterOnSharedPreferenceChangeListener(this); } + private void onBootCompleted() { + PreferenceManager.getDefaultSharedPreferences(this) + .registerOnSharedPreferenceChangeListener(this); + setManagingTrust(getIsManagingTrust(this)); + } + private BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { @@ -158,6 +186,9 @@ public class SampleTrustAgent extends TrustAgentService } } else if (ACTION_REVOKE_TRUST.equals(action)) { revokeTrust(); + } else if (intent.ACTION_BOOT_COMPLETED.equals(action)) { + Log.d(TAG, "User unlocked and boot completed."); + onBootCompleted(); } } }; @@ -203,6 +234,7 @@ public class SampleTrustAgent extends TrustAgentService public static void setIsManagingTrust(Context context, boolean enabled) { SharedPreferences sharedPreferences = PreferenceManager .getDefaultSharedPreferences(context); + Log.d("AAAA", "save manage trust preference. Enabled=" + enabled); sharedPreferences.edit().putBoolean(PREFERENCE_MANAGING_TRUST, enabled).apply(); } @@ -212,6 +244,21 @@ public class SampleTrustAgent extends TrustAgentService return sharedPreferences.getBoolean(PREFERENCE_MANAGING_TRUST, false); } + public static void setIsManagingTrustDirectBoot(Context context, boolean enabled) { + Context directBootContext = context.createDeviceProtectedStorageContext(); + SharedPreferences sharedPreferences = PreferenceManager + .getDefaultSharedPreferences(directBootContext); + Log.d("AAAA", "save to direct boot preference. Enabled=" + enabled); + sharedPreferences.edit().putBoolean(PREFERENCE_MANAGING_TRUST_DIRECT_BOOT, enabled).apply(); + } + + public static boolean getIsManagingTrustDirectBoot(Context context) { + Context directBootContext = context.createDeviceProtectedStorageContext(); + SharedPreferences sharedPreferences = PreferenceManager + .getDefaultSharedPreferences(directBootContext); + return sharedPreferences.getBoolean(PREFERENCE_MANAGING_TRUST_DIRECT_BOOT, false); + } + @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (PREFERENCE_MANAGING_TRUST.equals(key)) { 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 29b15cbff1fd..1b171693a6c9 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 @@ -33,6 +33,7 @@ public class SampleTrustAgentSettings extends Activity implements View.OnClickLi private CheckBox mReportUnlockAttempts; private CheckBox mReportDeviceLocked; private CheckBox mManagingTrust; + private CheckBox mManagingTrustDirectBoot; private TextView mCheckDeviceLockedResult; private KeyguardManager mKeyguardManager; @@ -59,6 +60,8 @@ public class SampleTrustAgentSettings extends Activity implements View.OnClickLi mManagingTrust = (CheckBox) findViewById(R.id.managing_trust); mManagingTrust.setOnCheckedChangeListener(this); + mManagingTrustDirectBoot = (CheckBox) findViewById(R.id.managing_trust_direct_boot); + mManagingTrustDirectBoot.setOnCheckedChangeListener(this); mCheckDeviceLockedResult = (TextView) findViewById(R.id.check_device_locked_result); } @@ -68,6 +71,8 @@ public class SampleTrustAgentSettings extends Activity implements View.OnClickLi super.onResume(); mReportUnlockAttempts.setChecked(SampleTrustAgent.getReportUnlockAttempts(this)); mManagingTrust.setChecked(SampleTrustAgent.getIsManagingTrust(this)); + mManagingTrustDirectBoot.setChecked( + SampleTrustAgent.getIsManagingTrustDirectBoot(this)); updateTrustedState(); } @@ -94,6 +99,8 @@ public class SampleTrustAgentSettings extends Activity implements View.OnClickLi SampleTrustAgent.setIsManagingTrust(this, isChecked); } else if (buttonView == mReportDeviceLocked) { SampleTrustAgent.setReportDeviceLocked(this, isChecked); + } else if (buttonView == mManagingTrustDirectBoot) { + SampleTrustAgent.setIsManagingTrustDirectBoot(this, isChecked); } } |