From 6de72663fa7cba3aeac3968b9f892335c93a9457 Mon Sep 17 00:00:00 2001 From: Esteban Talavera Date: Thu, 11 Dec 2014 17:54:07 +0000 Subject: 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 --- .../com/android/internal/app/ResolverActivity.java | 33 ++++++++++------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/core/java/com/android/internal/app/ResolverActivity.java b/core/java/com/android/internal/app/ResolverActivity.java index 634d03d9fb1c..c9a271cde37a 100644 --- a/core/java/com/android/internal/app/ResolverActivity.java +++ b/core/java/com/android/internal/app/ResolverActivity.java @@ -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,10 +1002,19 @@ 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; + } + } + private void addResolveInfo(DisplayResolveInfo dri) { if (dri.ri.targetUserId != UserHandle.USER_CURRENT && mOtherProfile == null) { // So far we only support a single other profile at a time. @@ -1217,4 +1215,3 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic } } } - -- cgit v1.2.3-59-g8ed1b