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:
@ -2148,31 +2148,7 @@ class ContextImpl extends Context {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override public Drawable getApplicationIcon(ApplicationInfo info) {
|
@Override public Drawable getApplicationIcon(ApplicationInfo info) {
|
||||||
final int icon = info.icon;
|
return info.loadIcon(this);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public Drawable getApplicationIcon(String packageName)
|
@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
|
@Override
|
||||||
public CharSequence getText(String packageName, int resid,
|
public CharSequence getText(String packageName, int resid,
|
||||||
ApplicationInfo appInfo) {
|
ApplicationInfo appInfo) {
|
||||||
@ -2493,17 +2450,7 @@ class ContextImpl extends Context {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getApplicationLabel(ApplicationInfo info) {
|
public CharSequence getApplicationLabel(ApplicationInfo info) {
|
||||||
if (info.nonLocalizedLabel != null) {
|
return info.loadLabel(this);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -16,6 +16,9 @@
|
|||||||
|
|
||||||
package android.content.pm;
|
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.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.util.Printer;
|
import android.util.Printer;
|
||||||
@ -496,7 +499,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
|
|||||||
*/
|
*/
|
||||||
public CharSequence loadDescription(PackageManager pm) {
|
public CharSequence loadDescription(PackageManager pm) {
|
||||||
if (descriptionRes != 0) {
|
if (descriptionRes != 0) {
|
||||||
CharSequence label = pm.getText(packageName, descriptionRes, null);
|
CharSequence label = pm.getText(packageName, descriptionRes, this);
|
||||||
if (label != null) {
|
if (label != null) {
|
||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
@ -514,4 +517,31 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
|
|||||||
FLAG_SUPPORTS_SMALL_SCREENS | FLAG_RESIZEABLE_FOR_SCREENS |
|
FLAG_SUPPORTS_SMALL_SCREENS | FLAG_RESIZEABLE_FOR_SCREENS |
|
||||||
FLAG_SUPPORTS_SCREEN_DENSITIES);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,24 +99,6 @@ public class ComponentInfo extends PackageItemInfo {
|
|||||||
return name;
|
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
|
* Return the icon resource identifier to use for this component. If
|
||||||
* the component defines an icon, that is used; else, the application
|
* the component defines an icon, that is used; else, the application
|
||||||
@ -164,4 +146,18 @@ public class ComponentInfo extends PackageItemInfo {
|
|||||||
enabled = (source.readInt() != 0);
|
enabled = (source.readInt() != 0);
|
||||||
exported = (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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ public class PackageItemInfo {
|
|||||||
return nonLocalizedLabel;
|
return nonLocalizedLabel;
|
||||||
}
|
}
|
||||||
if (labelRes != 0) {
|
if (labelRes != 0) {
|
||||||
CharSequence label = pm.getText(packageName, labelRes, null);
|
CharSequence label = pm.getText(packageName, labelRes, getApplicationInfo());
|
||||||
if (label != null) {
|
if (label != null) {
|
||||||
return label.toString().trim();
|
return label.toString().trim();
|
||||||
}
|
}
|
||||||
@ -123,15 +123,31 @@ public class PackageItemInfo {
|
|||||||
* the PackageManager from which you originally retrieved this item.
|
* the PackageManager from which you originally retrieved this item.
|
||||||
*
|
*
|
||||||
* @return Returns a Drawable containing the item's icon. If the
|
* @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) {
|
public Drawable loadIcon(PackageManager pm) {
|
||||||
if (icon != 0) {
|
if (icon != 0) {
|
||||||
Drawable dr = pm.getDrawable(packageName, icon, null);
|
Drawable dr = pm.getDrawable(packageName, icon, getApplicationInfo());
|
||||||
if (dr != null) {
|
if (dr != null) {
|
||||||
return dr;
|
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();
|
return pm.getDefaultActivityIcon();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,7 +168,7 @@ public class PackageItemInfo {
|
|||||||
if (metaData != null) {
|
if (metaData != null) {
|
||||||
int resid = metaData.getInt(name);
|
int resid = metaData.getInt(name);
|
||||||
if (resid != 0) {
|
if (resid != 0) {
|
||||||
return pm.getXml(packageName, resid, null);
|
return pm.getXml(packageName, resid, getApplicationInfo());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -193,6 +209,18 @@ public class PackageItemInfo {
|
|||||||
metaData = source.readBundle();
|
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
|
public static class DisplayNameComparator
|
||||||
implements Comparator<PackageItemInfo> {
|
implements Comparator<PackageItemInfo> {
|
||||||
public DisplayNameComparator(PackageManager pm) {
|
public DisplayNameComparator(PackageManager pm) {
|
||||||
|
@ -163,8 +163,6 @@ public class ResolveInfo implements Parcelable {
|
|||||||
* item does not have an icon, the default activity icon is returned.
|
* item does not have an icon, the default activity icon is returned.
|
||||||
*/
|
*/
|
||||||
public Drawable loadIcon(PackageManager pm) {
|
public Drawable loadIcon(PackageManager pm) {
|
||||||
ComponentInfo ci = activityInfo != null ? activityInfo : serviceInfo;
|
|
||||||
ApplicationInfo ai = ci.applicationInfo;
|
|
||||||
Drawable dr;
|
Drawable dr;
|
||||||
if (resolvePackageName != null && icon != 0) {
|
if (resolvePackageName != null && icon != 0) {
|
||||||
dr = pm.getDrawable(resolvePackageName, icon, null);
|
dr = pm.getDrawable(resolvePackageName, icon, null);
|
||||||
@ -172,6 +170,8 @@ public class ResolveInfo implements Parcelable {
|
|||||||
return dr;
|
return dr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ComponentInfo ci = activityInfo != null ? activityInfo : serviceInfo;
|
||||||
|
ApplicationInfo ai = ci.applicationInfo;
|
||||||
if (icon != 0) {
|
if (icon != 0) {
|
||||||
dr = pm.getDrawable(ci.packageName, icon, ai);
|
dr = pm.getDrawable(ci.packageName, icon, ai);
|
||||||
if (dr != null) {
|
if (dr != null) {
|
||||||
|
BIN
core/res/res/drawable-hdpi/sym_app_on_sd_unavailable_icon.png
Normal file
BIN
core/res/res/drawable-hdpi/sym_app_on_sd_unavailable_icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.3 KiB |
BIN
core/res/res/drawable-mdpi/sym_app_on_sd_unavailable_icon.png
Normal file
BIN
core/res/res/drawable-mdpi/sym_app_on_sd_unavailable_icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.3 KiB |
@ -6278,7 +6278,7 @@ class PackageManagerService extends IPackageManager.Stub {
|
|||||||
Log.i(TAG, "Removing non-system package:"+p.packageName);
|
Log.i(TAG, "Removing non-system package:"+p.packageName);
|
||||||
// Kill application pre-emptively especially for apps on sd.
|
// Kill application pre-emptively especially for apps on sd.
|
||||||
killApplication(packageName, p.applicationInfo.uid);
|
killApplication(packageName, p.applicationInfo.uid);
|
||||||
ret = deleteInstalledPackageLI (p, deleteCodeAndResources, flags, outInfo);
|
ret = deleteInstalledPackageLI(p, deleteCodeAndResources, flags, outInfo);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -7605,9 +7605,10 @@ class PackageManagerService extends IPackageManager.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setFlags(int pkgFlags) {
|
void setFlags(int pkgFlags) {
|
||||||
this.pkgFlags = (pkgFlags & ApplicationInfo.FLAG_SYSTEM) |
|
this.pkgFlags = pkgFlags & (
|
||||||
(pkgFlags & ApplicationInfo.FLAG_FORWARD_LOCK) |
|
ApplicationInfo.FLAG_SYSTEM |
|
||||||
(pkgFlags & ApplicationInfo.FLAG_EXTERNAL_STORAGE);
|
ApplicationInfo.FLAG_FORWARD_LOCK |
|
||||||
|
ApplicationInfo.FLAG_EXTERNAL_STORAGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user