Merge "Password settings: Fix work profile" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
e6cff5497d
@@ -55,6 +55,7 @@ import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settingslib.widget.AppPreference;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
@@ -76,28 +77,30 @@ public class PasswordsPreferenceController extends BasePreferenceController
|
||||
private LifecycleOwner mLifecycleOwner;
|
||||
|
||||
public PasswordsPreferenceController(Context context, String preferenceKey) {
|
||||
this(context, preferenceKey,
|
||||
AutofillServiceInfo.getAvailableServices(context, UserHandle.myUserId()));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public PasswordsPreferenceController(
|
||||
Context context, String preferenceKey, List<AutofillServiceInfo> availableServices) {
|
||||
super(context, preferenceKey);
|
||||
mPm = context.getPackageManager();
|
||||
mIconFactory = IconDrawableFactory.newInstance(mContext);
|
||||
mServices = new ArrayList<>();
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(ON_CREATE)
|
||||
void onCreate(LifecycleOwner lifecycleOwner) {
|
||||
init(lifecycleOwner, AutofillServiceInfo.getAvailableServices(mContext, getUser()));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void init(LifecycleOwner lifecycleOwner, List<AutofillServiceInfo> availableServices) {
|
||||
mLifecycleOwner = lifecycleOwner;
|
||||
|
||||
for (int i = availableServices.size() - 1; i >= 0; i--) {
|
||||
final String passwordsActivity = availableServices.get(i).getPasswordsActivity();
|
||||
if (TextUtils.isEmpty(passwordsActivity)) {
|
||||
availableServices.remove(i);
|
||||
}
|
||||
}
|
||||
mServices = availableServices;
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(ON_CREATE)
|
||||
void onCreate(LifecycleOwner lifecycleOwner) {
|
||||
mLifecycleOwner = lifecycleOwner;
|
||||
// TODO: Reverse the loop above and add to mServices directly.
|
||||
mServices.clear();
|
||||
mServices.addAll(availableServices);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -109,8 +112,7 @@ public class PasswordsPreferenceController extends BasePreferenceController
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
final PreferenceGroup group = screen.findPreference(getPreferenceKey());
|
||||
// TODO(b/169455298): Show work profile passwords too.
|
||||
addPasswordPreferences(screen.getContext(), UserHandle.myUserId(), group);
|
||||
addPasswordPreferences(screen.getContext(), getUser(), group);
|
||||
}
|
||||
|
||||
private void addPasswordPreferences(
|
||||
@@ -126,9 +128,15 @@ public class PasswordsPreferenceController extends BasePreferenceController
|
||||
serviceInfo.applicationInfo,
|
||||
user);
|
||||
pref.setIcon(Utils.getSafeIcon(icon));
|
||||
pref.setIntent(
|
||||
new Intent(Intent.ACTION_MAIN)
|
||||
.setClassName(serviceInfo.packageName, service.getPasswordsActivity()));
|
||||
pref.setOnPreferenceClickListener(p -> {
|
||||
final Intent intent =
|
||||
new Intent(Intent.ACTION_MAIN)
|
||||
.setClassName(
|
||||
serviceInfo.packageName,
|
||||
service.getPasswordsActivity());
|
||||
prefContext.startActivityAsUser(intent, UserHandle.of(user));
|
||||
return true;
|
||||
});
|
||||
// Set an empty summary to avoid a UI flicker when the value loads.
|
||||
pref.setSummary(R.string.summary_placeholder);
|
||||
|
||||
@@ -213,4 +221,9 @@ public class PasswordsPreferenceController extends BasePreferenceController
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int getUser() {
|
||||
UserHandle workUser = getWorkProfileUser();
|
||||
return workUser != null ? workUser.getIdentifier() : UserHandle.myUserId();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user