Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6de72663 authored by Esteban Talavera's avatar Esteban Talavera
Browse files

Take into account other profiles when deciding whether to show ResolverActivity

Show ResolverActivity even if there is only one target
on the current profile that listens to that intent,
if other profiles can also handle it.
Also, fix crash while trying to access out of bounds
element on the list.

BUG: 18701336,18713763
Change-Id: I3a5e9cc5c0eedb2792b8f6d8a5d4aa8ee9e1256b
parent fb967585
Loading
Loading
Loading
Loading
+15 −18
Original line number Diff line number Diff line
@@ -248,12 +248,14 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic
        }
        mAlwaysUseOption = alwaysUseOption;

        int count = mAdapter.mList.size();
        if (mLaunchedFromUid < 0 || UserHandle.isIsolated(mLaunchedFromUid)) {
            // Gulp!
            finish();
            return;
        } else if (count > 1) {
        }

        int count = mAdapter.mList.size();
        if (count > 1 || (count == 1 && mAdapter.getOtherProfile() != null)) {
            setContentView(layoutId);
            mListView = (ListView) findViewById(R.id.resolver_list);
            mListView.setAdapter(mAdapter);
@@ -797,11 +799,9 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic
        }

        public void handlePackagesChanged() {
            final int oldItemCount = getCount();
            rebuildList();
            notifyDataSetChanged();
            final int newItemCount = getCount();
            if (newItemCount == 0) {
            if (getCount() == 0) {
                // We no longer have any items...  just finish the activity.
                finish();
            }
@@ -963,14 +963,9 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic
            // Process labels from start to i
            int num = end - start+1;
            if (num == 1) {
                if (mLastChosen != null
                        && mLastChosen.activityInfo.packageName.equals(
                                ro.activityInfo.packageName)
                        && mLastChosen.activityInfo.name.equals(ro.activityInfo.name)) {
                    mLastChosenPosition = mList.size();
                }
                // No duplicate labels. Use label for entry at start
                addResolveInfo(new DisplayResolveInfo(ro, roLabel, null, null));
                updateLastChosenPosition(ro);
            } else {
                mShowExtended = true;
                boolean usePkg = false;
@@ -998,12 +993,6 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic
                }
                for (int k = start; k <= end; k++) {
                    ResolveInfo add = rList.get(k);
                    if (mLastChosen != null
                            && mLastChosen.activityInfo.packageName.equals(
                                    add.activityInfo.packageName)
                            && mLastChosen.activityInfo.name.equals(add.activityInfo.name)) {
                        mLastChosenPosition = mList.size();
                    }
                    if (usePkg) {
                        // Use application name for all entries from start to end-1
                        addResolveInfo(new DisplayResolveInfo(add, roLabel,
@@ -1013,7 +1002,16 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic
                        addResolveInfo(new DisplayResolveInfo(add, roLabel,
                                add.activityInfo.applicationInfo.loadLabel(mPm), null));
                    }
                    updateLastChosenPosition(add);
                }
            }
        }

        private void updateLastChosenPosition(ResolveInfo info) {
            if (mLastChosen != null
                    && mLastChosen.activityInfo.packageName.equals(info.activityInfo.packageName)
                    && mLastChosen.activityInfo.name.equals(info.activityInfo.name)) {
                mLastChosenPosition = mList.size() - 1;
            }
        }

@@ -1217,4 +1215,3 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic
        }
    }
}