am 5d9ee149: Merge change 25397 into eclair

Merge commit '5d9ee1490258d56e0e1074b5e9b9a4bff39dd602' into eclair-plus-aosp

* commit '5d9ee1490258d56e0e1074b5e9b9a4bff39dd602':
  Fix issues with updating list when applications get installed while ManageApps is paused or stopped.
This commit is contained in:
Suchi Amalapurapu
2009-09-17 08:46:20 -07:00
committed by Android Git Automerger

View File

@@ -66,7 +66,6 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.text.Collator; import java.text.Collator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
@@ -178,7 +177,7 @@ public class ManageApplications extends ListActivity implements
private boolean mComputeSizes = false; private boolean mComputeSizes = false;
// default icon thats used when displaying applications initially before resource info is // default icon thats used when displaying applications initially before resource info is
// retrieved // retrieved
private Drawable mDefaultAppIcon; private static Drawable mDefaultAppIcon;
// temporary dialog displayed while the application info loads // temporary dialog displayed while the application info loads
private static final int DLG_BASE = 0; private static final int DLG_BASE = 0;
@@ -277,6 +276,7 @@ public class ManageApplications extends ListActivity implements
if(localLOGV) Log.i(TAG, "Message INIT_PKG_INFO, justCreated = " + mJustCreated); if(localLOGV) Log.i(TAG, "Message INIT_PKG_INFO, justCreated = " + mJustCreated);
List<ApplicationInfo> newList = null; List<ApplicationInfo> newList = null;
if (!mJustCreated) { if (!mJustCreated) {
if (localLOGV) Log.i(TAG, "List already created");
// Add or delete newly created packages by comparing lists // Add or delete newly created packages by comparing lists
newList = getInstalledApps(FILTER_APPS_ALL); newList = getInstalledApps(FILTER_APPS_ALL);
updateAppList(newList); updateAppList(newList);
@@ -372,8 +372,7 @@ public class ManageApplications extends ListActivity implements
if (status) { if (status) {
size = data.getLong(ATTR_PKG_STATS); size = data.getLong(ATTR_PKG_STATS);
formattedSize = data.getString(ATTR_PKG_SIZE_STR); formattedSize = data.getString(ATTR_PKG_SIZE_STR);
int idx = mAppInfoAdapter.getIndex(pkgName); if (!mAppInfoAdapter.isInstalled(pkgName)) {
if (idx == -1) {
mAppInfoAdapter.addToList(pkgName, size, formattedSize); mAppInfoAdapter.addToList(pkgName, size, formattedSize);
} else { } else {
mAppInfoAdapter.updatePackage(pkgName, size, formattedSize); mAppInfoAdapter.updatePackage(pkgName, size, formattedSize);
@@ -567,7 +566,9 @@ public class ManageApplications extends ListActivity implements
Set<String> existingList = new HashSet<String>(); Set<String> existingList = new HashSet<String>();
boolean ret = false; boolean ret = false;
// Loop over new list and find out common elements between old and new lists // Loop over new list and find out common elements between old and new lists
for (ApplicationInfo info : newList) { int N = newList.size();
for (int i = (N-1); i >= 0; i--) {
ApplicationInfo info = newList.get(i);
String pkgName = info.packageName; String pkgName = info.packageName;
AppInfo aInfo = mCache.getEntry(pkgName); AppInfo aInfo = mCache.getEntry(pkgName);
if (aInfo != null) { if (aInfo != null) {
@@ -576,10 +577,14 @@ public class ManageApplications extends ListActivity implements
// New package. update info by refreshing // New package. update info by refreshing
if (localLOGV) Log.i(TAG, "New pkg :"+pkgName+" installed when paused"); if (localLOGV) Log.i(TAG, "New pkg :"+pkgName+" installed when paused");
updatePackageList(Intent.ACTION_PACKAGE_ADDED, pkgName); updatePackageList(Intent.ACTION_PACKAGE_ADDED, pkgName);
// Remove from current list so that the newly added package can
// be handled later
newList.remove(i);
ret = true; ret = true;
} }
} }
// Loop over old list and figure out state entries
// Loop over old list and figure out stale entries
List<String> deletedList = null; List<String> deletedList = null;
Set<String> staleList = mCache.getPkgList(); Set<String> staleList = mCache.getPkgList();
for (String pkgName : staleList) { for (String pkgName : staleList) {
@@ -594,6 +599,7 @@ public class ManageApplications extends ListActivity implements
} }
// Delete right away // Delete right away
if (deletedList != null) { if (deletedList != null) {
if (localLOGV) Log.i(TAG, "Deleting right away");
mAppInfoAdapter.removeFromList(deletedList); mAppInfoAdapter.removeFromList(deletedList);
} }
return ret; return ret;
@@ -867,7 +873,7 @@ public class ManageApplications extends ListActivity implements
/* Internal class representing an application or packages displayable attributes /* Internal class representing an application or packages displayable attributes
* *
*/ */
class AppInfo { static private class AppInfo {
public String pkgName; public String pkgName;
int index; int index;
public CharSequence appName; public CharSequence appName;
@@ -1049,22 +1055,17 @@ public class ManageApplications extends ListActivity implements
return mAppLocalList.get(position); return mAppLocalList.get(position);
} }
/* public boolean isInstalled(String pkgName) {
* This method returns the index of the package position in the application list
*/
public int getIndex(String pkgName) {
if(pkgName == null) { if(pkgName == null) {
Log.w(TAG, "Getting index of null package in List Adapter"); if (localLOGV) Log.w(TAG, "Null pkg name when checking if installed");
return false;
} }
int imax = mAppLocalList.size(); for (ApplicationInfo info : mAppList) {
ApplicationInfo appInfo; if (info.packageName.equalsIgnoreCase(pkgName)) {
for(int i = 0; i < imax; i++) { return true;
appInfo = mAppLocalList.get(i);
if(appInfo.packageName.equalsIgnoreCase(pkgName)) {
return i;
} }
} }
return -1; return false;
} }
public ApplicationInfo getApplicationInfo(int position) { public ApplicationInfo getApplicationInfo(int position) {
@@ -1274,7 +1275,6 @@ public class ManageApplications extends ListActivity implements
if (pkgName == null) { if (pkgName == null) {
return; return;
} }
boolean notInList = true;
// Get ApplicationInfo // Get ApplicationInfo
ApplicationInfo info = null; ApplicationInfo info = null;
try { try {
@@ -1288,30 +1288,38 @@ public class ManageApplications extends ListActivity implements
Log.i(TAG, "Null ApplicationInfo for package:"+pkgName); Log.i(TAG, "Null ApplicationInfo for package:"+pkgName);
return; return;
} }
// Add entry to local list // Add entry to base list
mAppList.add(info); mAppList.add(info);
// Add entry to map. Note that the index gets adjusted later on based on // Add entry to map. Note that the index gets adjusted later on based on
// whether the newly added package is part of displayed list // whether the newly added package is part of displayed list
CharSequence label = info.loadLabel(mPm); CharSequence label = info.loadLabel(mPm);
mCache.addEntry(new AppInfo(pkgName, -1, mCache.addEntry(new AppInfo(pkgName, -1,
label, info.loadIcon(mPm), size, formattedSize)); label, info.loadIcon(mPm), size, formattedSize));
if (addLocalEntry(info, label)) {
notifyDataSetChanged();
}
}
private boolean addLocalEntry(ApplicationInfo info, CharSequence label) {
String pkgName = info.packageName;
// Add to list // Add to list
if (notInList && (shouldBeInList(mFilterApps, info))) { if (shouldBeInList(mFilterApps, info)) {
// Binary search returns a negative index (ie -index) of the position where // Binary search returns a negative index (ie -index) of the position where
// this might be inserted. // this might be inserted.
int newIdx = Collections.binarySearch(mAppLocalList, info, int newIdx = Collections.binarySearch(mAppLocalList, info,
getAppComparator(mSortOrder)); getAppComparator(mSortOrder));
if(newIdx >= 0) { if(newIdx >= 0) {
Log.i(TAG, "Strange. Package:"+pkgName+" is not new"); if (localLOGV) Log.i(TAG, "Strange. Package:" + pkgName + " is not new");
return; return false;
} }
// New entry // New entry
newIdx = -newIdx-1; newIdx = -newIdx-1;
addFilterListLocked(newIdx, info, label); addFilterListLocked(newIdx, info, label);
// Adjust index // Adjust index
adjustIndex(); adjustIndex();
notifyDataSetChanged(); return true;
} }
return false;
} }
public void updatePackage(String pkgName, public void updatePackage(String pkgName,
@@ -1325,9 +1333,13 @@ public class ManageApplications extends ListActivity implements
} }
AppInfo aInfo = mCache.getEntry(pkgName); AppInfo aInfo = mCache.getEntry(pkgName);
if (aInfo != null) { if (aInfo != null) {
aInfo.refreshLabel(info.loadLabel(mPm)); CharSequence label = info.loadLabel(mPm);
aInfo.refreshLabel(label);
aInfo.refreshIcon(info.loadIcon(mPm)); aInfo.refreshIcon(info.loadIcon(mPm));
aInfo.setSize(size, formattedSize); aInfo.setSize(size, formattedSize);
// Check if the entry has to be added to the displayed list
addLocalEntry(info, label);
// Refresh list since size might have changed
notifyDataSetChanged(); notifyDataSetChanged();
} }
} }