From b7487f867c2ff1bd0459182934b4040a0cf1d865 Mon Sep 17 00:00:00 2001 From: jayaprakashs Date: Wed, 23 Sep 2020 22:46:36 -0700 Subject: [PATCH] [Search] [People] Pass intent to People view instead of URI. Tested: On Phone Bug: 169294622 Change-Id: I4e379a80a256e018761af2925e640745456faeec --- .../views/SearchResultPeopleView.java | 49 +++++++------------ 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/src/com/android/launcher3/views/SearchResultPeopleView.java b/src/com/android/launcher3/views/SearchResultPeopleView.java index eacc095188..0c9a22f672 100644 --- a/src/com/android/launcher3/views/SearchResultPeopleView.java +++ b/src/com/android/launcher3/views/SearchResultPeopleView.java @@ -15,9 +15,6 @@ */ package com.android.launcher3.views; -import static android.content.Intent.URI_ALLOW_UNSAFE; -import static android.content.Intent.URI_ANDROID_APP_SCHEME; - import static com.android.launcher3.util.Executors.MAIN_EXECUTOR; import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR; @@ -28,7 +25,6 @@ import android.content.pm.PackageManager; import android.graphics.Bitmap; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; -import android.net.Uri; import android.os.Bundle; import android.util.AttributeSet; import android.view.View; @@ -50,7 +46,6 @@ import com.android.systemui.plugins.AllAppsSearchPlugin; import com.android.systemui.plugins.shared.SearchTarget; import com.android.systemui.plugins.shared.SearchTargetEvent; -import java.net.URISyntaxException; import java.util.ArrayList; /** @@ -66,7 +61,7 @@ public class SearchResultPeopleView extends LinearLayout implements private TextView mTitleView; private ImageButton[] mProviderButtons = new ImageButton[3]; private AllAppsSearchPlugin mPlugin; - private Uri mContactUri; + private Intent mIntent; private final Object[] mTargetInfo = createTargetInfo(); public SearchResultPeopleView(Context context) { @@ -109,7 +104,7 @@ public class SearchResultPeopleView extends LinearLayout implements Bundle payload = adapterItemWithPayload.getPayload(); mPlugin = adapterItemWithPayload.getPlugin(); mTitleView.setText(payload.getString("title")); - mContactUri = payload.getParcelable("contact_uri"); + mIntent = payload.getParcelable("intent"); Bitmap icon = payload.getParcelable("icon"); if (icon != null) { RoundedBitmapDrawable d = RoundedBitmapDrawableFactory.create(getResources(), icon); @@ -125,25 +120,20 @@ public class SearchResultPeopleView extends LinearLayout implements for (int i = 0; i < mProviderButtons.length; i++) { ImageButton button = mProviderButtons[i]; if (providers != null && i < providers.size()) { - try { - Bundle provider = providers.get(i); - Intent intent = Intent.parseUri(provider.getString("intent_uri_str"), - URI_ANDROID_APP_SCHEME | URI_ALLOW_UNSAFE); - setupProviderButton(button, provider, intent, adapterItemWithPayload); - String pkg = provider.getString("package_name"); - UI_HELPER_EXECUTOR.post(() -> { - try { - ApplicationInfo applicationInfo = mPackageManager.getApplicationInfo( - pkg, 0); - Drawable appIcon = applicationInfo.loadIcon(mPackageManager); - MAIN_EXECUTOR.post(() -> button.setImageDrawable(appIcon)); - } catch (PackageManager.NameNotFoundException ignored) { - } + Bundle provider = providers.get(i); + Intent intent = provider.getParcelable("intent"); + setupProviderButton(button, provider, intent, adapterItemWithPayload); + String pkg = provider.getString("package_name"); + UI_HELPER_EXECUTOR.post(() -> { + try { + ApplicationInfo applicationInfo = mPackageManager.getApplicationInfo( + pkg, 0); + Drawable appIcon = applicationInfo.loadIcon(mPackageManager); + MAIN_EXECUTOR.post(() -> button.setImageDrawable(appIcon)); + } catch (PackageManager.NameNotFoundException ignored) { + } - }); - } catch (URISyntaxException ex) { - button.setVisibility(GONE); - } + }); } else { button.setVisibility(GONE); } @@ -165,7 +155,7 @@ public class SearchResultPeopleView extends LinearLayout implements SearchTarget.ItemType.PEOPLE, SearchTargetEvent.CHILD_SELECT); searchTargetEvent.bundle = new Bundle(); - searchTargetEvent.bundle.putParcelable("contact_uri", mContactUri); + searchTargetEvent.bundle.putParcelable("intent", mIntent); searchTargetEvent.bundle.putBundle("provider", provider); if (mPlugin != null) { mPlugin.notifySearchTargetEvent(searchTargetEvent); @@ -175,14 +165,13 @@ public class SearchResultPeopleView extends LinearLayout implements private void handleSelection(int eventType) { - if (mContactUri != null) { + if (mIntent != null) { Launcher launcher = Launcher.getLauncher(getContext()); - launcher.startActivitySafely(this, new Intent(Intent.ACTION_VIEW, mContactUri).setFlags( - Intent.FLAG_ACTIVITY_NEW_TASK), null); + launcher.startActivitySafely(this, mIntent, null); SearchTargetEvent searchTargetEvent = getSearchTargetEvent(SearchTarget.ItemType.PEOPLE, eventType); searchTargetEvent.bundle = new Bundle(); - searchTargetEvent.bundle.putParcelable("contact_uri", mContactUri); + searchTargetEvent.bundle.putParcelable("intent", mIntent); if (mPlugin != null) { mPlugin.notifySearchTargetEvent(searchTargetEvent); }