Fix enterprise settings bug
This fixes a bug where the picker is not using the correct user id and also ensures that the settings activity uses the correct user when launched. Test: flash & test w/ work profile Bug 322071206 Change-Id: I846593ff9ae320d9bb774e3e79ed9ef41f101ff5
This commit is contained in:
@@ -16,15 +16,53 @@
|
||||
|
||||
package com.android.settings.applications.credentials;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.util.Slog;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.settings.SettingsActivity;
|
||||
|
||||
/** Standalone activity used to launch a {@link DefaultCombinedPicker} fragment. */
|
||||
/**
|
||||
* Standalone activity used to launch a {@link DefaultCombinedPicker} fragment if the user is a
|
||||
* normal user, a {@link DefaultCombinedPickerWork} fragment if the user is a work profile or {@link
|
||||
* DefaultCombinedPickerPrivate} fragment if the user is a private profile.
|
||||
*/
|
||||
public class CredentialsPickerActivity extends SettingsActivity {
|
||||
private static final String TAG = "CredentialsPickerActivity";
|
||||
|
||||
/** Injects the fragment name into the intent so the correct fragment is opened. */
|
||||
@VisibleForTesting
|
||||
public static void injectFragmentIntoIntent(Context context, Intent intent) {
|
||||
final int userId = UserHandle.myUserId();
|
||||
final UserManager userManager = UserManager.get(context);
|
||||
|
||||
if (DefaultCombinedPickerWork.isUserHandledByFragment(userManager, userId)) {
|
||||
Slog.d(TAG, "Creating picker fragment using work profile");
|
||||
intent.putExtra(EXTRA_SHOW_FRAGMENT, DefaultCombinedPickerWork.class.getName());
|
||||
} else if (DefaultCombinedPickerPrivate.isUserHandledByFragment(userManager)) {
|
||||
Slog.d(TAG, "Creating picker fragment using private profile");
|
||||
intent.putExtra(EXTRA_SHOW_FRAGMENT, DefaultCombinedPickerPrivate.class.getName());
|
||||
} else {
|
||||
Slog.d(TAG, "Creating picker fragment using normal profile");
|
||||
intent.putExtra(EXTRA_SHOW_FRAGMENT, DefaultCombinedPicker.class.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
injectFragmentIntoIntent(this, getIntent());
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isValidFragment(String fragmentName) {
|
||||
return super.isValidFragment(fragmentName)
|
||||
|| DefaultCombinedPicker.class.getName().equals(fragmentName);
|
||||
|| DefaultCombinedPicker.class.getName().equals(fragmentName)
|
||||
|| DefaultCombinedPickerWork.class.getName().equals(fragmentName)
|
||||
|| DefaultCombinedPickerPrivate.class.getName().equals(fragmentName);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user