Show SD unavailable icon for apps on SD when ejected.

This change include a minor refactoring of PackageItemInfo and related
classes to eliminate code duplication and to avoid redundant work
searching for an ApplicationInfo instance we already have.

Bug: b/2537578
Change-Id: Id0794c3f055ea58b943028f7a84abc7dec9d0aac
This commit is contained in:
Jeff Brown
2010-03-30 19:57:08 -07:00
parent 966fcb81ee
commit 0733079111
8 changed files with 90 additions and 88 deletions

View File

@ -2148,31 +2148,7 @@ class ContextImpl extends Context {
}
@Override public Drawable getApplicationIcon(ApplicationInfo info) {
final int icon = info.icon;
if (icon != 0) {
ResourceName name = new ResourceName(info, icon);
Drawable dr = getCachedIcon(name);
if (dr != null) {
return dr;
}
try {
Resources r = getResourcesForApplication(info);
dr = r.getDrawable(icon);
if (DEBUG_ICONS) Log.v(TAG, "Getting drawable 0x"
+ Integer.toHexString(icon) + " from " + r
+ ": " + dr);
putCachedIcon(name, dr);
return dr;
} catch (NameNotFoundException e) {
Log.w("PackageManager", "Failure retrieving resources for"
+ info.packageName);
} catch (RuntimeException e) {
// If an exception was thrown, fall through to return
// default icon.
Log.w("PackageManager", "Failure retrieving app icon", e);
}
}
return getDefaultActivityIcon();
return info.loadIcon(this);
}
@Override public Drawable getApplicationIcon(String packageName)
@ -2413,25 +2389,6 @@ class ContextImpl extends Context {
}
}
private CharSequence getLabel(ResourceName name, ApplicationInfo app, int id) {
CharSequence cs = getCachedString(name);
if (cs != null) {
return cs;
}
try {
Resources r = getResourcesForApplication(app);
cs = r.getText(id);
putCachedString(name, cs);
} catch (NameNotFoundException e) {
Log.w("PackageManager", "Failure retrieving resources for"
+ app.packageName);
} catch (RuntimeException e) {
// If an exception was thrown, fall through to return null
Log.w("ApplicationInfo", "Failure retrieving activity name", e);
}
return cs;
}
@Override
public CharSequence getText(String packageName, int resid,
ApplicationInfo appInfo) {
@ -2493,17 +2450,7 @@ class ContextImpl extends Context {
@Override
public CharSequence getApplicationLabel(ApplicationInfo info) {
if (info.nonLocalizedLabel != null) {
return info.nonLocalizedLabel;
}
final int id = info.labelRes;
if (id != 0) {
CharSequence cs = getLabel(new ResourceName(info, id), info, id);
if (cs != null) {
return cs;
}
}
return info.packageName;
return info.loadLabel(this);
}
@Override

View File

@ -16,6 +16,9 @@
package android.content.pm;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Printer;
@ -496,7 +499,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
*/
public CharSequence loadDescription(PackageManager pm) {
if (descriptionRes != 0) {
CharSequence label = pm.getText(packageName, descriptionRes, null);
CharSequence label = pm.getText(packageName, descriptionRes, this);
if (label != null) {
return label;
}
@ -514,4 +517,31 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
FLAG_SUPPORTS_SMALL_SCREENS | FLAG_RESIZEABLE_FOR_SCREENS |
FLAG_SUPPORTS_SCREEN_DENSITIES);
}
/**
* @hide
*/
@Override protected Drawable loadDefaultIcon(PackageManager pm) {
if ((flags & FLAG_EXTERNAL_STORAGE) != 0
&& isPackageUnavailable(pm)) {
return Resources.getSystem().getDrawable(
com.android.internal.R.drawable.sym_app_on_sd_unavailable_icon);
}
return pm.getDefaultActivityIcon();
}
private boolean isPackageUnavailable(PackageManager pm) {
try {
return pm.getPackageInfo(packageName, 0) == null;
} catch (NameNotFoundException ex) {
return true;
}
}
/**
* @hide
*/
@Override protected ApplicationInfo getApplicationInfo() {
return this;
}
}

View File

@ -99,24 +99,6 @@ public class ComponentInfo extends PackageItemInfo {
return name;
}
@Override public Drawable loadIcon(PackageManager pm) {
ApplicationInfo ai = applicationInfo;
Drawable dr;
if (icon != 0) {
dr = pm.getDrawable(packageName, icon, ai);
if (dr != null) {
return dr;
}
}
if (ai.icon != 0) {
dr = pm.getDrawable(packageName, ai.icon, ai);
if (dr != null) {
return dr;
}
}
return pm.getDefaultActivityIcon();
}
/**
* Return the icon resource identifier to use for this component. If
* the component defines an icon, that is used; else, the application
@ -164,4 +146,18 @@ public class ComponentInfo extends PackageItemInfo {
enabled = (source.readInt() != 0);
exported = (source.readInt() != 0);
}
/**
* @hide
*/
@Override protected Drawable loadDefaultIcon(PackageManager pm) {
return applicationInfo.loadIcon(pm);
}
/**
* @hide
*/
@Override protected ApplicationInfo getApplicationInfo() {
return applicationInfo;
}
}

View File

@ -103,7 +103,7 @@ public class PackageItemInfo {
return nonLocalizedLabel;
}
if (labelRes != 0) {
CharSequence label = pm.getText(packageName, labelRes, null);
CharSequence label = pm.getText(packageName, labelRes, getApplicationInfo());
if (label != null) {
return label.toString().trim();
}
@ -123,15 +123,31 @@ public class PackageItemInfo {
* the PackageManager from which you originally retrieved this item.
*
* @return Returns a Drawable containing the item's icon. If the
* item does not have an icon, the default activity icon is returned.
* item does not have an icon, the item's default icon is returned
* such as the default activity icon.
*/
public Drawable loadIcon(PackageManager pm) {
if (icon != 0) {
Drawable dr = pm.getDrawable(packageName, icon, null);
Drawable dr = pm.getDrawable(packageName, icon, getApplicationInfo());
if (dr != null) {
return dr;
}
}
return loadDefaultIcon(pm);
}
/**
* Retrieve the default graphical icon associated with this item.
*
* @param pm A PackageManager from which the icon can be loaded; usually
* the PackageManager from which you originally retrieved this item.
*
* @return Returns a Drawable containing the item's default icon
* such as the default activity icon.
*
* @hide
*/
protected Drawable loadDefaultIcon(PackageManager pm) {
return pm.getDefaultActivityIcon();
}
@ -152,7 +168,7 @@ public class PackageItemInfo {
if (metaData != null) {
int resid = metaData.getInt(name);
if (resid != 0) {
return pm.getXml(packageName, resid, null);
return pm.getXml(packageName, resid, getApplicationInfo());
}
}
return null;
@ -193,6 +209,18 @@ public class PackageItemInfo {
metaData = source.readBundle();
}
/**
* Get the ApplicationInfo for the application to which this item belongs,
* if available, otherwise returns null.
*
* @return Returns the ApplicationInfo of this item, or null if not known.
*
* @hide
*/
protected ApplicationInfo getApplicationInfo() {
return null;
}
public static class DisplayNameComparator
implements Comparator<PackageItemInfo> {
public DisplayNameComparator(PackageManager pm) {

View File

@ -163,8 +163,6 @@ public class ResolveInfo implements Parcelable {
* item does not have an icon, the default activity icon is returned.
*/
public Drawable loadIcon(PackageManager pm) {
ComponentInfo ci = activityInfo != null ? activityInfo : serviceInfo;
ApplicationInfo ai = ci.applicationInfo;
Drawable dr;
if (resolvePackageName != null && icon != 0) {
dr = pm.getDrawable(resolvePackageName, icon, null);
@ -172,6 +170,8 @@ public class ResolveInfo implements Parcelable {
return dr;
}
}
ComponentInfo ci = activityInfo != null ? activityInfo : serviceInfo;
ApplicationInfo ai = ci.applicationInfo;
if (icon != 0) {
dr = pm.getDrawable(ci.packageName, icon, ai);
if (dr != null) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

View File

@ -7605,9 +7605,10 @@ class PackageManagerService extends IPackageManager.Stub {
}
void setFlags(int pkgFlags) {
this.pkgFlags = (pkgFlags & ApplicationInfo.FLAG_SYSTEM) |
(pkgFlags & ApplicationInfo.FLAG_FORWARD_LOCK) |
(pkgFlags & ApplicationInfo.FLAG_EXTERNAL_STORAGE);
this.pkgFlags = pkgFlags & (
ApplicationInfo.FLAG_SYSTEM |
ApplicationInfo.FLAG_FORWARD_LOCK |
ApplicationInfo.FLAG_EXTERNAL_STORAGE);
}
}