diff options
Diffstat (limited to 'packages')
8 files changed, 112 insertions, 7 deletions
diff --git a/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitor.java b/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitor.java index f0f5772..e4d7850 100644 --- a/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitor.java +++ b/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitor.java @@ -216,6 +216,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { }; private SparseBooleanArray mUserHasTrust = new SparseBooleanArray(); + private SparseBooleanArray mUserTrustIsManaged = new SparseBooleanArray(); private SparseBooleanArray mUserFingerprintRecognized = new SparseBooleanArray(); @Override @@ -230,6 +231,18 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { } } + @Override + public void onTrustManagedChanged(boolean managed, int userId) { + mUserTrustIsManaged.put(userId, managed); + + for (int i = 0; i < mCallbacks.size(); i++) { + KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); + if (cb != null) { + cb.onTrustManagedChanged(userId); + } + } + } + private void onFingerprintRecognized(int userId) { mUserFingerprintRecognized.put(userId, true); for (int i = 0; i < mCallbacks.size(); i++) { @@ -305,6 +318,10 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { || mUserFingerprintRecognized.get(userId); } + public boolean getUserTrustIsManaged(int userId) { + return mUserTrustIsManaged.get(userId) && !isTrustDisabled(userId); + } + static class DisplayClientState { public int clientGeneration; public boolean clearing; diff --git a/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitorCallback.java b/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitorCallback.java index 14c1278..0aefa2d 100644 --- a/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitorCallback.java +++ b/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitorCallback.java @@ -174,6 +174,11 @@ public class KeyguardUpdateMonitorCallback { public void onTrustChanged(int userId) { } /** + * Called when trust being managed changes for a user. + */ + public void onTrustManagedChanged(int userId) { } + + /** * Called when a fingerprint is recognized. * @param userId */ @@ -183,5 +188,4 @@ public class KeyguardUpdateMonitorCallback { * Called when fingerprint is acquired but not yet recognized */ public void onFingerprintAcquired(int info) { } - } 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); } } } diff --git a/packages/SystemUI/res/drawable/trust_circle.xml b/packages/SystemUI/res/drawable/trust_circle.xml new file mode 100644 index 0000000..89f4a0b --- /dev/null +++ b/packages/SystemUI/res/drawable/trust_circle.xml @@ -0,0 +1,22 @@ +<?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 + --> + +<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="ring" + android:innerRadius="24dp" android:thickness="1dp"> + <solid android:color="#66ffffff" /> +</shape>
\ No newline at end of file diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java index b5f517d..82e59c0 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java @@ -237,6 +237,8 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL ? R.drawable.ic_lock_open_24dp : R.drawable.ic_lock_24dp; mLockIcon.setImageResource(iconRes); + boolean trustManaged = mUnlockMethodCache.isTrustManaged(); + mLockIcon.setBackgroundResource(trustManaged ? R.drawable.trust_circle : 0); } public KeyguardAffordanceView getPhoneView() { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/UnlockMethodCache.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/UnlockMethodCache.java index c9e0db6..58196f7 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/UnlockMethodCache.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/UnlockMethodCache.java @@ -37,6 +37,7 @@ public class UnlockMethodCache { private final KeyguardUpdateMonitor mKeyguardUpdateMonitor; private final ArrayList<OnUnlockMethodChangedListener> mListeners = new ArrayList<>(); private boolean mMethodInsecure; + private boolean mTrustManaged; private UnlockMethodCache(Context ctx) { mLockPatternUtils = new LockPatternUtils(ctx); @@ -71,9 +72,11 @@ public class UnlockMethodCache { int user = mLockPatternUtils.getCurrentUser(); boolean methodInsecure = !mLockPatternUtils.isSecure() || mKeyguardUpdateMonitor.getUserHasTrust(user); - boolean changed = methodInsecure != mMethodInsecure; + boolean trustManaged = mKeyguardUpdateMonitor.getUserTrustIsManaged(user); + boolean changed = methodInsecure != mMethodInsecure || trustManaged != mTrustManaged; if (changed || updateAlways) { mMethodInsecure = methodInsecure; + mTrustManaged = trustManaged; notifyListeners(mMethodInsecure); } } @@ -96,15 +99,25 @@ public class UnlockMethodCache { } @Override + public void onTrustManagedChanged(int userId) { + updateMethodSecure(false /* updateAlways */); + } + + @Override public void onScreenTurnedOn() { updateMethodSecure(false /* updateAlways */); } + @Override public void onFingerprintRecognized(int userId) { updateMethodSecure(false /* updateAlways */); } }; + public boolean isTrustManaged() { + return mTrustManaged; + } + public static interface OnUnlockMethodChangedListener { void onMethodSecureChanged(boolean methodSecure); } |