Merge "Take into account other profiles when deciding whether to show ResolverActivity" into lmp-mr1-dev

This commit is contained in:
Esteban Talavera
2014-12-12 16:59:28 +00:00
committed by Gerrit Code Review

View File

@@ -248,12 +248,14 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic
} }
mAlwaysUseOption = alwaysUseOption; mAlwaysUseOption = alwaysUseOption;
int count = mAdapter.mList.size();
if (mLaunchedFromUid < 0 || UserHandle.isIsolated(mLaunchedFromUid)) { if (mLaunchedFromUid < 0 || UserHandle.isIsolated(mLaunchedFromUid)) {
// Gulp! // Gulp!
finish(); finish();
return; return;
} else if (count > 1) { }
int count = mAdapter.mList.size();
if (count > 1 || (count == 1 && mAdapter.getOtherProfile() != null)) {
setContentView(layoutId); setContentView(layoutId);
mListView = (ListView) findViewById(R.id.resolver_list); mListView = (ListView) findViewById(R.id.resolver_list);
mListView.setAdapter(mAdapter); mListView.setAdapter(mAdapter);
@@ -797,11 +799,9 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic
} }
public void handlePackagesChanged() { public void handlePackagesChanged() {
final int oldItemCount = getCount();
rebuildList(); rebuildList();
notifyDataSetChanged(); notifyDataSetChanged();
final int newItemCount = getCount(); if (getCount() == 0) {
if (newItemCount == 0) {
// We no longer have any items... just finish the activity. // We no longer have any items... just finish the activity.
finish(); finish();
} }
@@ -963,14 +963,9 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic
// Process labels from start to i // Process labels from start to i
int num = end - start+1; int num = end - start+1;
if (num == 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 // No duplicate labels. Use label for entry at start
addResolveInfo(new DisplayResolveInfo(ro, roLabel, null, null)); addResolveInfo(new DisplayResolveInfo(ro, roLabel, null, null));
updateLastChosenPosition(ro);
} else { } else {
mShowExtended = true; mShowExtended = true;
boolean usePkg = false; boolean usePkg = false;
@@ -998,12 +993,6 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic
} }
for (int k = start; k <= end; k++) { for (int k = start; k <= end; k++) {
ResolveInfo add = rList.get(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) { if (usePkg) {
// Use application name for all entries from start to end-1 // Use application name for all entries from start to end-1
addResolveInfo(new DisplayResolveInfo(add, roLabel, addResolveInfo(new DisplayResolveInfo(add, roLabel,
@@ -1013,10 +1002,19 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic
addResolveInfo(new DisplayResolveInfo(add, roLabel, addResolveInfo(new DisplayResolveInfo(add, roLabel,
add.activityInfo.applicationInfo.loadLabel(mPm), null)); 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) { private void addResolveInfo(DisplayResolveInfo dri) {
if (dri.ri.targetUserId != UserHandle.USER_CURRENT && mOtherProfile == null) { if (dri.ri.targetUserId != UserHandle.USER_CURRENT && mOtherProfile == null) {
// So far we only support a single other profile at a time. // So far we only support a single other profile at a time.
@@ -1217,4 +1215,3 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic
} }
} }
} }