Loading core/res/res/values/attrs.xml +4 −2 Original line number Diff line number Diff line Loading @@ -7442,6 +7442,8 @@ i <attr name="title" /> <!-- @SystemApi Summary for the same preference as the title. @hide --> <attr name="summary" /> <!-- @SystemApi Whether trust agent can unlock a user profile @hide --> <attr name="unlockProfile" format="boolean"/> </declare-styleable> <!-- =============================== --> Loading packages/Keyguard/test/SampleTrustAgent/AndroidManifest.xml +1 −0 Original line number Diff line number Diff line Loading @@ -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" /> Loading packages/Keyguard/test/SampleTrustAgent/res/layout-v26/sample_trust_agent_settings.xml 0 → 100644 +74 −0 Original line number Diff line number Diff line <?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 packages/Keyguard/test/SampleTrustAgent/res/xml-v26/sample_trust_agent.xml 0 → 100644 +19 −0 Original line number Diff line number Diff line <?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" /> packages/Keyguard/test/SampleTrustAgent/src/com/android/trustagent/test/SampleTrustAgent.java +50 −3 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 Loading Loading @@ -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) { Loading @@ -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(); } } }; Loading Loading @@ -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(); } Loading @@ -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)) { Loading Loading
core/res/res/values/attrs.xml +4 −2 Original line number Diff line number Diff line Loading @@ -7442,6 +7442,8 @@ i <attr name="title" /> <!-- @SystemApi Summary for the same preference as the title. @hide --> <attr name="summary" /> <!-- @SystemApi Whether trust agent can unlock a user profile @hide --> <attr name="unlockProfile" format="boolean"/> </declare-styleable> <!-- =============================== --> Loading
packages/Keyguard/test/SampleTrustAgent/AndroidManifest.xml +1 −0 Original line number Diff line number Diff line Loading @@ -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" /> Loading
packages/Keyguard/test/SampleTrustAgent/res/layout-v26/sample_trust_agent_settings.xml 0 → 100644 +74 −0 Original line number Diff line number Diff line <?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
packages/Keyguard/test/SampleTrustAgent/res/xml-v26/sample_trust_agent.xml 0 → 100644 +19 −0 Original line number Diff line number Diff line <?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" />
packages/Keyguard/test/SampleTrustAgent/src/com/android/trustagent/test/SampleTrustAgent.java +50 −3 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 Loading Loading @@ -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) { Loading @@ -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(); } } }; Loading Loading @@ -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(); } Loading @@ -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)) { Loading