Do not connect to KeyChainService when user is not started
Bug: 27418671
Change-Id: Id1bca405e8b0ebea79726f623aaa0c59bce0331c
This commit is contained in:
@@ -18,8 +18,12 @@ package com.android.settings;
|
|||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
|
import android.app.KeyguardManager;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.content.pm.UserInfo;
|
import android.content.pm.UserInfo;
|
||||||
import android.net.http.SslCertificate;
|
import android.net.http.SslCertificate;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
@@ -50,8 +54,10 @@ import android.widget.Switch;
|
|||||||
import android.widget.TabHost;
|
import android.widget.TabHost;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.android.internal.app.UnlaunchableAppActivity;
|
||||||
import com.android.internal.logging.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.MetricsProto.MetricsEvent;
|
||||||
import com.android.internal.util.ParcelableString;
|
import com.android.internal.util.ParcelableString;
|
||||||
|
import com.android.internal.widget.LockPatternUtils;
|
||||||
|
|
||||||
import java.security.cert.CertificateEncodingException;
|
import java.security.cert.CertificateEncodingException;
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
@@ -65,6 +71,7 @@ public class TrustedCredentialsSettings extends InstrumentedFragment {
|
|||||||
private static final String TAG = "TrustedCredentialsSettings";
|
private static final String TAG = "TrustedCredentialsSettings";
|
||||||
|
|
||||||
private UserManager mUserManager;
|
private UserManager mUserManager;
|
||||||
|
private KeyguardManager mKeyguardManager;
|
||||||
|
|
||||||
private static final String USER_ACTION = "com.android.settings.TRUSTED_CREDENTIALS_USER";
|
private static final String USER_ACTION = "com.android.settings.TRUSTED_CREDENTIALS_USER";
|
||||||
|
|
||||||
@@ -173,13 +180,43 @@ public class TrustedCredentialsSettings extends InstrumentedFragment {
|
|||||||
private final SparseArray<KeyChainConnection>
|
private final SparseArray<KeyChainConnection>
|
||||||
mKeyChainConnectionByProfileId = new SparseArray<KeyChainConnection>();
|
mKeyChainConnectionByProfileId = new SparseArray<KeyChainConnection>();
|
||||||
|
|
||||||
|
private BroadcastReceiver mWorkProfileChangedReceiver = new BroadcastReceiver() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
final String action = intent.getAction();
|
||||||
|
if (Intent.ACTION_MANAGED_PROFILE_AVAILABILITY_CHANGED.equals(action) ||
|
||||||
|
Intent.ACTION_MANAGED_PROFILE_UNLOCKED.equals(action)) {
|
||||||
|
// Reload all alias
|
||||||
|
final ExpandableListView systemView = (ExpandableListView) mTabHost
|
||||||
|
.findViewById(Tab.SYSTEM.mExpandableList);
|
||||||
|
if (systemView != null) {
|
||||||
|
((TrustedCertificateExpandableAdapter) systemView.getExpandableListAdapter())
|
||||||
|
.load();
|
||||||
|
}
|
||||||
|
final ExpandableListView userView = (ExpandableListView) mTabHost
|
||||||
|
.findViewById(Tab.USER.mExpandableList);
|
||||||
|
if (userView != null) {
|
||||||
|
((TrustedCertificateExpandableAdapter) userView.getExpandableListAdapter())
|
||||||
|
.load();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
mUserManager = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
|
mUserManager = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
|
||||||
|
mKeyguardManager = (KeyguardManager) getActivity()
|
||||||
|
.getSystemService(Context.KEYGUARD_SERVICE);
|
||||||
|
IntentFilter filter = new IntentFilter();
|
||||||
|
filter.addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABILITY_CHANGED);
|
||||||
|
filter.addAction(Intent.ACTION_MANAGED_PROFILE_UNLOCKED);
|
||||||
|
getActivity().registerReceiver(mWorkProfileChangedReceiver, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override public View onCreateView(
|
@Override public View onCreateView(
|
||||||
LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
|
LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
|
||||||
mTabHost = (TabHost) inflater.inflate(R.layout.trusted_credentials, parent, false);
|
mTabHost = (TabHost) inflater.inflate(R.layout.trusted_credentials, parent, false);
|
||||||
@@ -195,6 +232,7 @@ public class TrustedCredentialsSettings extends InstrumentedFragment {
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
|
getActivity().unregisterReceiver(mWorkProfileChangedReceiver);
|
||||||
for (AdapterData.AliasLoader aliasLoader : mAliasLoaders.values()) {
|
for (AdapterData.AliasLoader aliasLoader : mAliasLoaders.values()) {
|
||||||
aliasLoader.cancel(true);
|
aliasLoader.cancel(true);
|
||||||
}
|
}
|
||||||
@@ -225,6 +263,29 @@ public class TrustedCredentialsSettings extends InstrumentedFragment {
|
|||||||
final TrustedCertificateExpandableAdapter adapter =
|
final TrustedCertificateExpandableAdapter adapter =
|
||||||
new TrustedCertificateExpandableAdapter(tab);
|
new TrustedCertificateExpandableAdapter(tab);
|
||||||
lv.setAdapter(adapter);
|
lv.setAdapter(adapter);
|
||||||
|
lv.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition,
|
||||||
|
long id) {
|
||||||
|
final UserHandle groupUser = adapter.getGroup(groupPosition);
|
||||||
|
final int groupUserId = groupUser.getIdentifier();
|
||||||
|
if (mUserManager.isQuietModeEnabled(groupUser)) {
|
||||||
|
final Intent intent = UnlaunchableAppActivity.createInQuietModeDialogIntent(
|
||||||
|
groupUserId);
|
||||||
|
getActivity().startActivity(intent);
|
||||||
|
return true;
|
||||||
|
} else if (!mUserManager.isUserUnlocked(groupUser)) {
|
||||||
|
final LockPatternUtils lockPatternUtils = new LockPatternUtils(
|
||||||
|
getActivity());
|
||||||
|
if (lockPatternUtils.isSeparateProfileChallengeEnabled(groupUserId)) {
|
||||||
|
startWorkChallenge(groupUserId);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
lv.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
|
lv.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onChildClick(ExpandableListView parent, View v,
|
public boolean onChildClick(ExpandableListView parent, View v,
|
||||||
@@ -246,6 +307,17 @@ public class TrustedCredentialsSettings extends InstrumentedFragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start work challenge activity. TODO: Move and refactor this method as a util function.
|
||||||
|
*/
|
||||||
|
private void startWorkChallenge(int userId) {
|
||||||
|
final Intent newIntent = mKeyguardManager.createConfirmDeviceCredentialIntent(null, null,
|
||||||
|
userId);
|
||||||
|
newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
|
| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||||
|
getActivity().startActivity(newIntent);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common interface for adapters of both expandable and non-expandable certificate lists.
|
* Common interface for adapters of both expandable and non-expandable certificate lists.
|
||||||
*/
|
*/
|
||||||
@@ -418,6 +490,11 @@ public class TrustedCredentialsSettings extends InstrumentedFragment {
|
|||||||
mAliasLoaders.put(mTab, this);
|
mAliasLoaders.put(mTab, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean shouldSkipProfile(UserHandle userHandle) {
|
||||||
|
return mUserManager.isQuietModeEnabled(userHandle)
|
||||||
|
|| !mUserManager.isUserUnlocked(userHandle.getIdentifier());
|
||||||
|
}
|
||||||
|
|
||||||
@Override protected void onPreExecute() {
|
@Override protected void onPreExecute() {
|
||||||
View content = mTabHost.getTabContentView();
|
View content = mTabHost.getTabContentView();
|
||||||
mProgressBar = (ProgressBar) content.findViewById(mTab.mProgress);
|
mProgressBar = (ProgressBar) content.findViewById(mTab.mProgress);
|
||||||
@@ -440,6 +517,9 @@ public class TrustedCredentialsSettings extends InstrumentedFragment {
|
|||||||
for (int i = 0; i < n; ++i) {
|
for (int i = 0; i < n; ++i) {
|
||||||
UserHandle profile = profiles.get(i);
|
UserHandle profile = profiles.get(i);
|
||||||
int profileId = profile.getIdentifier();
|
int profileId = profile.getIdentifier();
|
||||||
|
if (shouldSkipProfile(profile)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
KeyChainConnection keyChainConnection = KeyChain.bindAsUser(mContext,
|
KeyChainConnection keyChainConnection = KeyChain.bindAsUser(mContext,
|
||||||
profile);
|
profile);
|
||||||
// Saving the connection for later use on the certificate dialog.
|
// Saving the connection for later use on the certificate dialog.
|
||||||
@@ -455,6 +535,10 @@ public class TrustedCredentialsSettings extends InstrumentedFragment {
|
|||||||
for (int i = 0; i < n; ++i) {
|
for (int i = 0; i < n; ++i) {
|
||||||
UserHandle profile = profiles.get(i);
|
UserHandle profile = profiles.get(i);
|
||||||
int profileId = profile.getIdentifier();
|
int profileId = profile.getIdentifier();
|
||||||
|
if (shouldSkipProfile(profile)) {
|
||||||
|
certHoldersByProfile.put(profileId, new ArrayList<CertHolder>(0));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
List<ParcelableString> aliases = aliasesByProfileId.get(profileId);
|
List<ParcelableString> aliases = aliasesByProfileId.get(profileId);
|
||||||
if (isCancelled()) {
|
if (isCancelled()) {
|
||||||
return new SparseArray<List<CertHolder>>();
|
return new SparseArray<List<CertHolder>>();
|
||||||
|
Reference in New Issue
Block a user