From 7193895c6afc52092646c9901c1ffea958182f3d Mon Sep 17 00:00:00 2001 From: Zimuzo Date: Wed, 15 Aug 2018 15:10:20 +0100 Subject: [PATCH] Launch work profile activity to add Autofill service ag/4666330 allowed choosing separate Autofill services for the main and work profile. However, the 'Add service' button for work profile always resolved action_view intent as the main user even when clicking the work profile preference. Now the intent is resolved to the right profile depending on the preference clicked. BUG: 112610177 Test: Verified manually Change-Id: I870346d7b5618e7c230edebd59ac7f52f8495d47 --- .../applications/defaultapps/DefaultAutofillPicker.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/com/android/settings/applications/defaultapps/DefaultAutofillPicker.java b/src/com/android/settings/applications/defaultapps/DefaultAutofillPicker.java index 1705dc578a6..b281336d0be 100644 --- a/src/com/android/settings/applications/defaultapps/DefaultAutofillPicker.java +++ b/src/com/android/settings/applications/defaultapps/DefaultAutofillPicker.java @@ -35,6 +35,7 @@ import android.text.Html; import android.text.TextUtils; import android.util.Log; import androidx.preference.Preference; +import androidx.preference.Preference.OnPreferenceClickListener; import com.android.internal.content.PackageMonitor; import com.android.internal.logging.nano.MetricsProto; import com.android.settings.R; @@ -168,11 +169,15 @@ public class DefaultAutofillPicker extends DefaultAppPickerFragment { } final Intent addNewServiceIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(searchUri)); - Preference preference = new Preference(getPrefContext()); + final Context context = getPrefContext(); + final Preference preference = new Preference(context); + preference.setOnPreferenceClickListener(p -> { + context.startActivityAsUser(addNewServiceIntent, UserHandle.of(mUserId)); + return true; + }); preference.setTitle(R.string.print_menu_item_add_service); preference.setIcon(R.drawable.ic_menu_add); preference.setOrder(Integer.MAX_VALUE -1); - preference.setIntent(addNewServiceIntent); preference.setPersistent(false); return preference; }