Merge "resolver list is not cleared on rebuild"

This commit is contained in:
Adam Powell
2012-12-03 11:04:21 -08:00
committed by Gerrit Code Review

View File

@@ -35,7 +35,6 @@ import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.PatternMatcher; import android.os.PatternMatcher;
import android.os.Process;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.UserHandle; import android.os.UserHandle;
import android.util.Log; import android.util.Log;
@@ -64,6 +63,7 @@ import java.util.Set;
*/ */
public class ResolverActivity extends AlertActivity implements AdapterView.OnItemClickListener { public class ResolverActivity extends AlertActivity implements AdapterView.OnItemClickListener {
private static final String TAG = "ResolverActivity"; private static final String TAG = "ResolverActivity";
private static final boolean DEBUG = false;
private int mLaunchedFromUid; private int mLaunchedFromUid;
private ResolveListAdapter mAdapter; private ResolveListAdapter mAdapter;
@@ -402,7 +402,6 @@ public class ResolverActivity extends AlertActivity implements AdapterView.OnIte
private final int mLaunchedFromUid; private final int mLaunchedFromUid;
private final LayoutInflater mInflater; private final LayoutInflater mInflater;
private List<ResolveInfo> mCurrentResolveList;
private List<DisplayResolveInfo> mList; private List<DisplayResolveInfo> mList;
public ResolveListAdapter(Context context, Intent intent, public ResolveListAdapter(Context context, Intent intent,
@@ -413,6 +412,7 @@ public class ResolverActivity extends AlertActivity implements AdapterView.OnIte
mBaseResolveList = rList; mBaseResolveList = rList;
mLaunchedFromUid = launchedFromUid; mLaunchedFromUid = launchedFromUid;
mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mList = new ArrayList<DisplayResolveInfo>();
rebuildList(); rebuildList();
} }
@@ -420,22 +420,23 @@ public class ResolverActivity extends AlertActivity implements AdapterView.OnIte
final int oldItemCount = getCount(); final int oldItemCount = getCount();
rebuildList(); rebuildList();
notifyDataSetChanged(); notifyDataSetChanged();
if (mList.size() <= 0) { final int newItemCount = getCount();
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();
} } else if (newItemCount != oldItemCount) {
final int newItemCount = getCount();
if (newItemCount != oldItemCount) {
resizeGrid(); resizeGrid();
} }
} }
private void rebuildList() { private void rebuildList() {
List<ResolveInfo> currentResolveList;
mList.clear();
if (mBaseResolveList != null) { if (mBaseResolveList != null) {
mCurrentResolveList = mBaseResolveList; currentResolveList = mBaseResolveList;
} else { } else {
mCurrentResolveList = mPm.queryIntentActivities( currentResolveList = mPm.queryIntentActivities(
mIntent, PackageManager.MATCH_DEFAULT_ONLY mIntent, PackageManager.MATCH_DEFAULT_ONLY
| (mAlwaysUseOption ? PackageManager.GET_RESOLVED_FILTER : 0)); | (mAlwaysUseOption ? PackageManager.GET_RESOLVED_FILTER : 0));
// Filter out any activities that the launched uid does not // Filter out any activities that the launched uid does not
@@ -443,36 +444,36 @@ public class ResolverActivity extends AlertActivity implements AdapterView.OnIte
// list of resolved activities, because that only happens when // list of resolved activities, because that only happens when
// we are being subclassed, so we can safely launch whatever // we are being subclassed, so we can safely launch whatever
// they gave us. // they gave us.
if (mCurrentResolveList != null) { if (currentResolveList != null) {
for (int i=mCurrentResolveList.size()-1; i >= 0; i--) { for (int i=currentResolveList.size()-1; i >= 0; i--) {
ActivityInfo ai = mCurrentResolveList.get(i).activityInfo; ActivityInfo ai = currentResolveList.get(i).activityInfo;
int granted = ActivityManager.checkComponentPermission( int granted = ActivityManager.checkComponentPermission(
ai.permission, mLaunchedFromUid, ai.permission, mLaunchedFromUid,
ai.applicationInfo.uid, ai.exported); ai.applicationInfo.uid, ai.exported);
if (granted != PackageManager.PERMISSION_GRANTED) { if (granted != PackageManager.PERMISSION_GRANTED) {
// Access not allowed! // Access not allowed!
mCurrentResolveList.remove(i); currentResolveList.remove(i);
} }
} }
} }
} }
int N; int N;
if ((mCurrentResolveList != null) && ((N = mCurrentResolveList.size()) > 0)) { if ((currentResolveList != null) && ((N = currentResolveList.size()) > 0)) {
// Only display the first matches that are either of equal // Only display the first matches that are either of equal
// priority or have asked to be default options. // priority or have asked to be default options.
ResolveInfo r0 = mCurrentResolveList.get(0); ResolveInfo r0 = currentResolveList.get(0);
for (int i=1; i<N; i++) { for (int i=1; i<N; i++) {
ResolveInfo ri = mCurrentResolveList.get(i); ResolveInfo ri = currentResolveList.get(i);
if (false) Log.v( if (DEBUG) Log.v(
"ResolveListActivity", "ResolveListActivity",
r0.activityInfo.name + "=" + r0.activityInfo.name + "=" +
r0.priority + "/" + r0.isDefault + " vs " + r0.priority + "/" + r0.isDefault + " vs " +
ri.activityInfo.name + "=" + ri.activityInfo.name + "=" +
ri.priority + "/" + ri.isDefault); ri.priority + "/" + ri.isDefault);
if (r0.priority != ri.priority || if (r0.priority != ri.priority ||
r0.isDefault != ri.isDefault) { r0.isDefault != ri.isDefault) {
while (i < N) { while (i < N) {
mCurrentResolveList.remove(i); currentResolveList.remove(i);
N--; N--;
} }
} }
@@ -480,11 +481,8 @@ public class ResolverActivity extends AlertActivity implements AdapterView.OnIte
if (N > 1) { if (N > 1) {
ResolveInfo.DisplayNameComparator rComparator = ResolveInfo.DisplayNameComparator rComparator =
new ResolveInfo.DisplayNameComparator(mPm); new ResolveInfo.DisplayNameComparator(mPm);
Collections.sort(mCurrentResolveList, rComparator); Collections.sort(currentResolveList, rComparator);
} }
mList = new ArrayList<DisplayResolveInfo>();
// First put the initial items at the top. // First put the initial items at the top.
if (mInitialIntents != null) { if (mInitialIntents != null) {
for (int i=0; i<mInitialIntents.length; i++) { for (int i=0; i<mInitialIntents.length; i++) {
@@ -515,7 +513,7 @@ public class ResolverActivity extends AlertActivity implements AdapterView.OnIte
// Check for applications with same name and use application name or // Check for applications with same name and use application name or
// package name if necessary // package name if necessary
r0 = mCurrentResolveList.get(0); r0 = currentResolveList.get(0);
int start = 0; int start = 0;
CharSequence r0Label = r0.loadLabel(mPm); CharSequence r0Label = r0.loadLabel(mPm);
mShowExtended = false; mShowExtended = false;
@@ -523,7 +521,7 @@ public class ResolverActivity extends AlertActivity implements AdapterView.OnIte
if (r0Label == null) { if (r0Label == null) {
r0Label = r0.activityInfo.packageName; r0Label = r0.activityInfo.packageName;
} }
ResolveInfo ri = mCurrentResolveList.get(i); ResolveInfo ri = currentResolveList.get(i);
CharSequence riLabel = ri.loadLabel(mPm); CharSequence riLabel = ri.loadLabel(mPm);
if (riLabel == null) { if (riLabel == null) {
riLabel = ri.activityInfo.packageName; riLabel = ri.activityInfo.packageName;
@@ -531,13 +529,13 @@ public class ResolverActivity extends AlertActivity implements AdapterView.OnIte
if (riLabel.equals(r0Label)) { if (riLabel.equals(r0Label)) {
continue; continue;
} }
processGroup(mCurrentResolveList, start, (i-1), r0, r0Label); processGroup(currentResolveList, start, (i-1), r0, r0Label);
r0 = ri; r0 = ri;
r0Label = riLabel; r0Label = riLabel;
start = i; start = i;
} }
// Process last group // Process last group
processGroup(mCurrentResolveList, start, (N-1), r0, r0Label); processGroup(currentResolveList, start, (N-1), r0, r0Label);
} }
} }
@@ -589,18 +587,10 @@ public class ResolverActivity extends AlertActivity implements AdapterView.OnIte
} }
public ResolveInfo resolveInfoForPosition(int position) { public ResolveInfo resolveInfoForPosition(int position) {
if (mList == null) {
return null;
}
return mList.get(position).ri; return mList.get(position).ri;
} }
public Intent intentForPosition(int position) { public Intent intentForPosition(int position) {
if (mList == null) {
return null;
}
DisplayResolveInfo dri = mList.get(position); DisplayResolveInfo dri = mList.get(position);
Intent intent = new Intent(dri.origIntent != null Intent intent = new Intent(dri.origIntent != null
@@ -614,11 +604,11 @@ public class ResolverActivity extends AlertActivity implements AdapterView.OnIte
} }
public int getCount() { public int getCount() {
return mList != null ? mList.size() : 0; return mList.size();
} }
public Object getItem(int position) { public Object getItem(int position) {
return position; return mList.get(position);
} }
public long getItemId(int position) { public long getItemId(int position) {