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,6 +16,7 @@
|
||||
|
||||
package com.android.settings.applications.credentials;
|
||||
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -24,7 +25,6 @@ import android.content.pm.ServiceInfo;
|
||||
import android.credentials.CredentialProviderInfo;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.service.autofill.AutofillServiceInfo;
|
||||
import android.text.TextUtils;
|
||||
import android.util.IconDrawableFactory;
|
||||
@@ -49,7 +49,7 @@ public final class CombinedProviderInfo {
|
||||
private static final String TAG = "CombinedProviderInfo";
|
||||
private static final String SETTINGS_ACTIVITY_INTENT_ACTION = "android.intent.action.MAIN";
|
||||
private static final String SETTINGS_ACTIVITY_INTENT_CATEGORY =
|
||||
"android.intent.category.LAUNCHER";
|
||||
"android.intent.category.DEFAULT";
|
||||
|
||||
private final List<CredentialProviderInfo> mCredentialProviderInfos;
|
||||
private final @Nullable AutofillServiceInfo mAutofillServiceInfo;
|
||||
@@ -327,10 +327,8 @@ public final class CombinedProviderInfo {
|
||||
}
|
||||
|
||||
public static @Nullable Intent createSettingsActivityIntent(
|
||||
@NonNull Context context,
|
||||
@Nullable CharSequence packageName,
|
||||
@Nullable CharSequence settingsActivity,
|
||||
int currentUserId) {
|
||||
@Nullable CharSequence settingsActivity) {
|
||||
if (TextUtils.isEmpty(packageName) || TextUtils.isEmpty(settingsActivity)) {
|
||||
return null;
|
||||
}
|
||||
@@ -350,19 +348,25 @@ public final class CombinedProviderInfo {
|
||||
Intent intent = new Intent(SETTINGS_ACTIVITY_INTENT_ACTION);
|
||||
intent.addCategory(SETTINGS_ACTIVITY_INTENT_CATEGORY);
|
||||
intent.setComponent(cn);
|
||||
|
||||
int contextUserId = context.getUser().getIdentifier();
|
||||
if (currentUserId != contextUserId && UserManager.isHeadlessSystemUserMode()) {
|
||||
Log.w(
|
||||
TAG,
|
||||
"onLeftSideClicked(): using context for current user ("
|
||||
+ currentUserId
|
||||
+ ") instead of user "
|
||||
+ contextUserId
|
||||
+ " on headless system user mode");
|
||||
context = context.createContextAsUser(UserHandle.of(currentUserId), /* flags= */ 0);
|
||||
}
|
||||
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
return intent;
|
||||
}
|
||||
|
||||
/** Launches the settings activity intent. */
|
||||
public static void launchSettingsActivityIntent(
|
||||
@NonNull Context context,
|
||||
@Nullable CharSequence packageName,
|
||||
@Nullable CharSequence settingsActivity,
|
||||
int userId) {
|
||||
Intent settingsIntent = createSettingsActivityIntent(packageName, settingsActivity);
|
||||
if (settingsIntent == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
context.startActivityAsUser(settingsIntent, UserHandle.of(userId));
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Log.e(TAG, "Failed to open settings activity", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user