-
import android.os.Parcel;
-
import android.os.Parcelable;
-
import android.util.Printer;
-
import java.text.Collator;
-
import java.util.Comparator;
-
/**
-
* Information you can retrieve about a particular application. This
-
* corresponds to information collected from the AndroidManifest.xml’s
-
* tag.
-
*/
-
public class ApplicationInfo extends PackageItemInfo implements Parcelable {
-
/**
-
* Default task affinity of all activities in this application. See
-
* {@link ActivityInfo#taskAffinity} for more information. This comes
-
* from the “taskAffinity” attribute.
-
*/
-
public String taskAffinity;
-
/**
-
* Optional name of a permission required to be able to access this
-
* application’s components. From the “permission” attribute.
-
*/
-
public String permission;
-
/**
-
* The name of the process this application should run in. From the
-
* “process” attribute or, if not set, the same as
-
* packageName.
-
*/
-
public String processName;
-
/**
-
* Class implementing the Application object. From the “class”
-
* attribute.
-
*/
-
public String className;
-
/**
-
* A style resource identifier (in the package’s resources) of the
-
* description of an application. From the “description” attribute
-
* or, if not set, 0.
-
*/
-
public int descriptionRes;
-
/**
-
* A style resource identifier (in the package’s resources) of the
-
* default visual theme of the application. From the “theme” attribute
-
* or, if not set, 0.
-
*/
-
public int theme;
-
/**
-
* Class implementing the Application’s manage space
-
* functionality. From the “manageSpaceActivity”
-
* attribute. This is an optional attribute and will be null if
-
* applications don’t specify it in their manifest
-
*/
-
public String manageSpaceActivityName;
-
/**
-
* Class implementing the Application’s backup functionality. From
-
* the “backupAgent” attribute. This is an optional attribute and
-
* will be null if the application does not specify it in its manifest.
-
*
-
*
If android:allowBackup is set to false, this attribute is ignored.
-
*/
-
public String backupAgentName;
-
/**
-
* The default extra UI options for activities in this application.
-
* Set from the {@link android.R.attr#uiOptions} attribute in the
-
* activity’s manifest.
-
*/
-
public int uiOptions = 0;
-
/**
-
* Value for {@link #flags}: if set, this application is installed in the
-
* device’s system image.
-
*/
-
public static final int FLAG_SYSTEM = 1<<0;
-
/**
-
* Value for {@link #flags}: set to true if this application would like to
-
* allow debugging of its
-
* code, even when installed on a non-development system. Comes
-
* from {@link android.R.styleable#AndroidManifestApplication_debuggable
-
* android:debuggable} of the tag.
-
*/
-
public static final int FLAG_DEBUGGABLE = 1<<1;
-
/**
-
* Value for {@link #flags}: set to true if this application has code
-
* associated with it. Comes
-
* from {@link android.R.styleable#AndroidManifestApplication_hasCode
-
* android:hasCode} of the tag.
-
*/
-
public static final int FLAG_HAS_CODE = 1<<2;
-
/**
-
* Value for {@link #flags}: set to true if this application is persistent.
-
* Comes from {@link android.R.styleable#AndroidManifestApplication_persistent
-
* android:persistent} of the tag.
-
*/
-
public static final int FLAG_PERSISTENT = 1<<3;
-
/**
-
* Value for {@link #flags}: set to true if this application holds the
-
* {@link android.Manifest.permission#FACTORY_TEST} permission and the
-
* device is running in factory test mode.
-
*/
-
public static final int FLAG_FACTORY_TEST = 1<<4;
-
/**
-
* Value for {@link #flags}: default value for the corresponding ActivityInfo flag.
-
* Comes from {@link android.R.styleable#AndroidManifestApplication_allowTaskReparenting
-
* android:allowTaskReparenting} of the tag.
-
*/
-
public static final int FLAG_ALLOW_TASK_REPARENTING = 1<<5;
-
/**
-
* Value for {@link #flags}: default value for the corresponding ActivityInfo flag.
-
* Comes from {@link android.R.styleable#AndroidManifestApplication_allowClearUserData
-
* android:allowClearUserData} of the tag.
-
*/
-
public static final int FLAG_ALLOW_CLEAR_USER_DATA = 1<<6;
-
/**
-
* Value for {@link #flags}: this is set if this application has been
-
* install as an update to a built-in system application.
-
*/
-
public static final int FLAG_UPDATED_SYSTEM_APP = 1<<7;
-
/**
-
* Value for {@link #flags}: this is set of the application has specified
-
* {@link android.R.styleable#AndroidManifestApplication_testOnly
-
* android:testOnly} to be true.
-
*/
-
public static final int FLAG_TEST_ONLY = 1<<8;
-
/**
-
* Value for {@link #flags}: true when the application’s window can be
-
* reduced in size for smaller screens. Corresponds to
-
* {@link android.R.styleable#AndroidManifestSupportsScreens_smallScreens
-
* android:smallScreens}.
-
*/
-
public static final int FLAG_SUPPORTS_SMALL_SCREENS = 1<<9;
-
/**
-
* Value for {@link #flags}: true when the application’s window can be
-
* displayed on normal screens. Corresponds to
-
* {@link android.R.styleable#AndroidManifestSupportsScreens_normalScreens
-
* android:normalScreens}.
-
*/
-
public static final int FLAG_SUPPORTS_NORMAL_SCREENS = 1<<10;
-
/**
-
* Value for {@link #flags}: true when the application’s window can be
-
* increased in size for larger screens. Corresponds to
-
* {@link android.R.styleable#AndroidManifestSupportsScreens_largeScreens
-
* android:largeScreens}.
-
*/
-
public static final int FLAG_SUPPORTS_LARGE_SCREENS = 1<<11;
-
/**
-
* Value for {@link #flags}: true when the application knows how to adjust
-
* its UI for different screen sizes. Corresponds to
-
* {@link android.R.styleable#AndroidManifestSupportsScreens_resizeable
-
* android:resizeable}.
-
*/
-
public static final int FLAG_RESIZEABLE_FOR_SCREENS = 1<<12;
-
/**
-
* Value for {@link #flags}: true when the application knows how to
-
* accomodate different screen densities. Corresponds to
-
* {@link android.R.styleable#AndroidManifestSupportsScreens_anyDensity
-
* android:anyDensity}.
-
*/
-
public static final int FLAG_SUPPORTS_SCREEN_DENSITIES = 1<<13;
-
/**
-
* Value for {@link #flags}: set to true if this application would like to
-
* request the VM to operate under the safe mode. Comes from
-
* {@link android.R.styleable#AndroidManifestApplication_vmSafeMode
-
* android:vmSafeMode} of the tag.
-
*/
-
public static final int FLAG_VM_SAFE_MODE = 1<<14;
-
/**
-
* Value for {@link #flags}: set to
false
if the application does not wish -
* to permit any OS-driven backups of its data;
true
otherwise. -
*
-
*
Comes from the
-
* {@link android.R.styleable#AndroidManifestApplication_allowBackup android:allowBackup}
-
* attribute of the tag.
-
*/
-
public static final int FLAG_ALLOW_BACKUP = 1<<15;
-
/**
-
* Value for {@link #flags}: set to
false
if the application must be kept -
* in memory following a full-system restore operation;
true
otherwise. -
* Ordinarily, during a full system restore operation each application is shut down
-
* following execution of its agent’s onRestore() method. Setting this attribute to
-
*
false
prevents this. Most applications will not need to set this attribute. -
*
-
*
If
-
* {@link android.R.styleable#AndroidManifestApplication_allowBackup android:allowBackup}
-
* is set to
false
or no -
* {@link android.R.styleable#AndroidManifestApplication_backupAgent android:backupAgent}
-
* is specified, this flag will be ignored.
-
*
-
*
Comes from the
-
* {@link android.R.styleable#AndroidManifestApplication_killAfterRestore android:killAfterRestore}
-
* attribute of the tag.
-
*/
-
public static final int FLAG_KILL_AFTER_RESTORE = 1<<16;
-
/**
-
* Value for {@link #flags}: Set to
true
if the application’s backup -
* agent claims to be able to handle restore data even “from the future,”
-
* i.e. from versions of the application with a versionCode greater than
-
* the one currently installed on the device. Use with caution! By default
-
* this attribute is
false
and the Backup Manager will ensure that data -
* from “future” versions of the application are never supplied during a restore operation.
-
*
-
*
If
-
* {@link android.R.styleable#AndroidManifestApplication_allowBackup android:allowBackup}
-
* is set to
false
or no -
* {@link android.R.styleable#AndroidManifestApplication_backupAgent android:backupAgent}
-
* is specified, this flag will be ignored.
-
*
-
*
Comes from the
-
* {@link android.R.styleable#AndroidManifestApplication_restoreAnyVersion android:restoreAnyVersion}
-
* attribute of the tag.
-
*/
-
public static final int FLAG_RESTORE_ANY_VERSION = 1<<17;
-
/**
-
* Value for {@link #flags}: Set to true if the application is
-
* currently installed on external/removable/unprotected storage. Such
-
* applications may not be available if their storage is not currently
-
* mounted. When the storage it is on is not available, it will look like
-
* the application has been uninstalled (its .apk is no longer available)
-
* but its persistent data is not removed.
-
*/
-
public static final int FLAG_EXTERNAL_STORAGE = 1<<18;
-
/**
-
* Value for {@link #flags}: true when the application’s window can be
-
* increased in size for extra large screens. Corresponds to
-
* {@link android.R.styleable#AndroidManifestSupportsScreens_xlargeScreens
-
* android:xlargeScreens}.
-
*/
-
public static final int FLAG_SUPPORTS_XLARGE_SCREENS = 1<<19;
-
/**
-
* Value for {@link #flags}: true when the application has requested a
-
* large heap for its processes. Corresponds to
-
* {@link android.R.styleable#AndroidManifestApplication_largeHeap
-
* android:largeHeap}.
-
*/
-
public static final int FLAG_LARGE_HEAP = 1<<20;
-
/**
-
* Value for {@link #flags}: true if this application’s package is in
-
* the stopped state.
-
*/
-
public static final int FLAG_STOPPED = 1<<21;
-
/**
-
* Value for {@link #flags}: true when the application is willing to support
-
* RTL (right to left). All activities will inherit this value.
-
*
-
* Set from the {@link android.R.attr#supportsRtl} attribute in the
-
* activity’s manifest.
-
*
-
* Default value is false (no support for RTL).
-
*/
-
public static final int FLAG_SUPPORTS_RTL = 1<<22;
-
/**
-
* Value for {@link #flags}: true if the application is currently
-
* installed for the calling user.
-
*/
-
public static final int FLAG_INSTALLED = 1<<23;
-
/**
-
* Value for {@link #flags}: true if the application only has its
-
* data installed; the application package itself does not currently
-
* exist on the device.
-
*/
-
public static final int FLAG_IS_DATA_ONLY = 1<<24;
-
/**
-
* Value for {@link #flags}: Set to true if the application has been
-
* installed using the forward lock option.
-
*
-
* NOTE: DO NOT CHANGE THIS VALUE! It is saved in packages.xml.
-
*
-
* {@hide}
-
*/
-
public static final int FLAG_FORWARD_LOCK = 1<<29;
-
/**
-
* Value for {@link #flags}: set to
true
if the application -
* has reported that it is heavy-weight, and thus can not participate in
-
* the normal application lifecycle.
-
*
-
*
Comes from the
-
* {@link android.R.styleable#AndroidManifestApplication_cantSaveState android:cantSaveState}
-
* attribute of the tag.
-
*
-
* {@hide}
-
*/
-
public static final int FLAG_CANT_SAVE_STATE = 1<<28;
-
/**
-
* Flags associated with the application. Any combination of
-
* {@link #FLAG_SYSTEM}, {@link #FLAG_DEBUGGABLE}, {@link #FLAG_HAS_CODE},
-
* {@link #FLAG_PERSISTENT}, {@link #FLAG_FACTORY_TEST}, and
-
* {@link #FLAG_ALLOW_TASK_REPARENTING}
-
* {@link #FLAG_ALLOW_CLEAR_USER_DATA}, {@link #FLAG_UPDATED_SYSTEM_APP},
-
* {@link #FLAG_TEST_ONLY}, {@link #FLAG_SUPPORTS_SMALL_SCREENS},
-
* {@link #FLAG_SUPPORTS_NORMAL_SCREENS},
-
* {@link #FLAG_SUPPORTS_LARGE_SCREENS}, {@link #FLAG_SUPPORTS_XLARGE_SCREENS},
-
* {@link #FLAG_RESIZEABLE_FOR_SCREENS},
-
* {@link #FLAG_SUPPORTS_SCREEN_DENSITIES}, {@link #FLAG_VM_SAFE_MODE},
-
* {@link #FLAG_INSTALLED}.
-
*/
-
public int flags = 0;
-
/**
-
* The required smallest screen width the application can run on. If 0,
-
* nothing has been specified. Comes from
-
* {@link android.R.styleable#AndroidManifestSupportsScreens_requiresSmallestWidthDp
-
* android:requiresSmallestWidthDp} attribute of the tag.
-
*/
-
public int requiresSmallestWidthDp = 0;
-
/**
-
* The maximum smallest screen width the application is designed for. If 0,
-
* nothing has been specified. Comes from
-
* {@link android.R.styleable#AndroidManifestSupportsScreens_compatibleWidthLimitDp
-
* android:compatibleWidthLimitDp} attribute of the tag.
-
*/
-
public int compatibleWidthLimitDp = 0;
-
/**
-
* The maximum smallest screen width the application will work on. If 0,
-
* nothing has been specified. Comes from
-
* {@link android.R.styleable#AndroidManifestSupportsScreens_largestWidthLimitDp
-
* android:largestWidthLimitDp} attribute of the tag.
-
*/
-
public int largestWidthLimitDp = 0;
-
/**
-
* Full path to the location of this package.
-
*/
-
public String sourceDir;
-
/**
-
* Full path to the location of the publicly available parts of this
-
* package (i.e. the primary resource package and manifest). For
-
* non-forward-locked apps this will be the same as {@link #sourceDir).
-
*/
-
public String publicSourceDir;
-
/**
-
* Full paths to the locations of extra resource packages this application
-
* uses. This field is only used if there are extra resource packages,
-
* otherwise it is null.
-
*
-
* {@hide}
-
*/
-
public String[] resourceDirs;
-
/**
-
* Paths to all shared libraries this application is linked against. This
-
* field is only set if the {@link PackageManager#GET_SHARED_LIBRARY_FILES
-
* PackageManager.GET_SHARED_LIBRARY_FILES} flag was used when retrieving
-
* the structure.
-
*/
-
public String[] sharedLibraryFiles;
-
/**
-
* Full path to a directory assigned to the package for its persistent
-
* data.
-
*/
-
public String dataDir;
-
/**
-
* Full path to the directory where native JNI libraries are stored.
-
*/
-
public String nativeLibraryDir;
-
/**
-
* The kernel user-ID that has been assigned to this application;
-
* currently this is not a unique ID (multiple applications can have
-
* the same uid).
-
*/
-
public int uid;
-
/**
-
* The minimum SDK version this application targets. It may run on earlier
-
* versions, but it knows how to work with any new behavior added at this
-
* version. Will be {@link android.os.Build.VERSION_CODES#CUR_DEVELOPMENT}
-
* if this is a development build and the app is targeting that. You should
-
* compare that this number is >= the SDK version number at which your
-
* behavior was introduced.
-
*/
-
public int targetSdkVersion;
-
/**
-
* When false, indicates that all components within this application are
-
* considered disabled, regardless of their individually set enabled status.
-
*/
-
public boolean enabled = true;
-
/**
-
* For convenient access to the current enabled setting of this app.
-
* @hide
-
*/
-
public int enabledSetting = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
-
/**
-
* For convenient access to package’s install location.
-
* @hide
-
*/
-
public int installLocation = PackageInfo.INSTALL_LOCATION_UNSPECIFIED;
-
public void dump(Printer pw, String prefix) {
-
super.dumpFront(pw, prefix);
-
if (className != null) {
-
pw.println(prefix + “className=” + className);
-
}
-
if (permission != null) {
-
pw.println(prefix + “permission=” + permission);
-
}
-
pw.println(prefix + “processName=” + processName);
-
pw.println(prefix + “taskAffinity=” + taskAffinity);
-
pw.println(prefix + “uid=” + uid + " flags=0x" + Integer.toHexString(flags)
-
+ " theme=0x" + Integer.toHexString(theme));
-
pw.println(prefix + “requiresSmallestWidthDp=” + requiresSmallestWidthDp
-
+ " compatibleWidthLimitDp=" + compatibleWidthLimitDp
-
+ " largestWidthLimitDp=" + largestWidthLimitDp);
-
pw.println(prefix + “sourceDir=” + sourceDir);
-
if (sourceDir == null) {
-
if (publicSourceDir != null) {
-
pw.println(prefix + “publicSourceDir=” + publicSourceDir);
-
}
-
} else if (!sourceDir.equals(publicSourceDir)) {
-
pw.println(prefix + “publicSourceDir=” + publicSourceDir);
-
}
-
if (resourceDirs != null) {
-
pw.println(prefix + “resourceDirs=” + resourceDirs);
-
}
-
pw.println(prefix + “dataDir=” + dataDir);
-
if (sharedLibraryFiles != null) {
-
pw.println(prefix + “sharedLibraryFiles=” + sharedLibraryFiles);
-
}
-
pw.println(prefix + “enabled=” + enabled + " targetSdkVersion=" + targetSdkVersion);
-
if (manageSpaceActivityName != null) {
-
pw.println(prefix + “manageSpaceActivityName=”+manageSpaceActivityName);
-
}
-
if (descriptionRes != 0) {
-
pw.println(prefix + “description=0x”+Integer.toHexString(descriptionRes));
-
}
-
if (uiOptions != 0) {
-
pw.println(prefix + “uiOptions=0x” + Integer.toHexString(uiOptions));
-
}
-
pw.println(prefix + “supportsRtl=” + (hasRtlSupport() ? “true” : “false”));
-
super.dumpBack(pw, prefix);
-
}
-
/**
-
* @return true if “supportsRtl” has been set to true in the AndroidManifest
-
* @hide
-
*/
-
public boolean hasRtlSupport() {
-
return (flags & FLAG_SUPPORTS_RTL) == FLAG_SUPPORTS_RTL;
-
}
-
public static class DisplayNameComparator
-
implements Comparator {
-
public DisplayNameComparator(PackageManager pm) {
-
mPM = pm;
-
}
-
public final int compare(ApplicationInfo aa, ApplicationInfo ab) {
-
CharSequence sa = mPM.getApplicationLabel(aa);
-
if (sa == null) {
-
sa = aa.packageName;
-
}
-
CharSequence sb = mPM.getApplicationLabel(ab);
-
if (sb == null) {
-
sb = ab.packageName;
-
}
-
return sCollator.compare(sa.toString(), sb.toString());
-
}
-
private final Collator sCollator = Collator.getInstance();
-
private PackageManager mPM;
-
}
-
public ApplicationInfo() {
-
}
-
public ApplicationInfo(ApplicationInfo orig) {
-
super(orig);
-
taskAffinity = orig.taskAffinity;
-
permission = orig.permission;
-
processName = orig.processName;
-
className = orig.className;
-
theme = orig.theme;
-
flags = orig.flags;
-
requiresSmallestWidthDp = orig.requiresSmallestWidthDp;
-
compatibleWidthLimitDp = orig.compatibleWidthLimitDp;
-
largestWidthLimitDp = orig.largestWidthLimitDp;
-
sourceDir = orig.sourceDir;
-
publicSourceDir = orig.publicSourceDir;
-
nativeLibraryDir = orig.nativeLibraryDir;
-
resourceDirs = orig.resourceDirs;
-
sharedLibraryFiles = orig.sharedLibraryFiles;
-
dataDir = orig.dataDir;
-
uid = orig.uid;
-
targetSdkVersion = orig.targetSdkVersion;
-
enabled = orig.enabled;
-
enabledSetting = orig.enabledSetting;
-
installLocation = orig.installLocation;
-
manageSpaceActivityName = orig.manageSpaceActivityName;
-
descriptionRes = orig.descriptionRes;
-
uiOptions = orig.uiOptions;
-
backupAgentName = orig.backupAgentName;
-
}
-
public String toString() {
-
return “ApplicationInfo{”
-
+ Integer.toHexString(System.identityHashCode(this))
-
+ " " + packageName + “}”;
-
}
-
public int describeContents() {
-
return 0;
-
}
-
public void writeToParcel(Parcel dest, int parcelableFlags) {
-
super.writeToParcel(dest, parcelableFlags);
-
dest.writeString(taskAffinity);
-
dest.writeString(permission);
-
dest.writeString(processName);
-
dest.writeString(className);
-
dest.writeInt(theme);
-
dest.writeInt(flags);
-
dest.writeInt(requiresSmallestWidthDp);
-
dest.writeInt(compatibleWidthLimitDp);
-
dest.writeInt(largestWidthLimitDp);
-
dest.writeString(sourceDir);
-
dest.writeString(publicSourceDir);
-
dest.writeString(nativeLibraryDir);
-
dest.writeStringArray(resourceDirs);
-
dest.writeStringArray(sharedLibraryFiles);
-
dest.writeString(dataDir);
-
dest.writeInt(uid);
-
dest.writeInt(targetSdkVersion);
-
dest.writeInt(enabled ? 1 : 0);
-
dest.writeInt(enabledSetting);
-
dest.writeInt(installLocation);
-
dest.writeString(manageSpaceActivityName);
-
dest.writeString(backupAgentName);
-
dest.writeInt(descriptionRes);
-
dest.writeInt(uiOptions);
-
}
-
public static final Parcelable.Creator CREATOR
-
= new Parcelable.Creator() {
-
public ApplicationInfo createFromParcel(Parcel source) {
-
return new ApplicationInfo(source);
-
}
-
public ApplicationInfo[] newArray(int size) {
-
return new ApplicationInfo[size];
-
}
-
};
-
private ApplicationInfo(Parcel source) {
-
super(source);
-
taskAffinity = source.readString();
-
permission = source.readString();
-
processName = source.readString();
-
className = source.readString();
-
theme = source.readInt();
-
flags = source.readInt();
-
requiresSmallestWidthDp = source.readInt();
-
compatibleWidthLimitDp = source.readInt();
-
largestWidthLimitDp = source.readInt();
-
sourceDir = source.readString();
-
publicSourceDir = source.readString();
-
nativeLibraryDir = source.readString();
-
resourceDirs = source.readStringArray();
-
sharedLibraryFiles = source.readStringArray();
-
dataDir = source.readString();
-
uid = source.readInt();
-
targetSdkVersion = source.readInt();
-
enabled = source.readInt() != 0;
-
enabledSetting = source.readInt();
-
installLocation = source.readInt();
-
manageSpaceActivityName = source.readString();
-
backupAgentName = source.readString();
-
descriptionRes = source.readInt();
-
uiOptions = source.readInt();
-
}
-
/**
-
* Retrieve the textual description of the application. This
-
* will call back on the given PackageManager to load the description from
-
* the application.
-
*
-
* @param pm A PackageManager from which the label can be loaded; usually
-
* the PackageManager from which you originally retrieved this item.
-
*
-
* @return Returns a CharSequence containing the application’s description.
-
* If there is no description, null is returned.
-
*/
-
public CharSequence loadDescription(PackageManager pm) {
-
if (descriptionRes != 0) {
-
CharSequence label = pm.getText(packageName, descriptionRes, this);
-
if (label != null) {
-
return label;
-
}
-
}
-
return null;
-
}
-
/**
-
* Disable compatibility mode
-
*
-
* @hide
-
*/
-
public void disableCompatibilityMode() {
-
flags |= (FLAG_SUPPORTS_LARGE_SCREENS | FLAG_SUPPORTS_NORMAL_SCREENS |
-
FLAG_SUPPORTS_SMALL_SCREENS | FLAG_RESIZEABLE_FOR_SCREENS |
-
FLAG_SUPPORTS_SCREEN_DENSITIES | FLAG_SUPPORTS_XLARGE_SCREENS);
-
}
-
/**
-
* @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;
-
}
-
}
PackageItemInfo.java源码:
[java] view plain copy
-
/*
-
* Copyright © 2007 The Android Open Source Project
-
*
-
* Licensed under the Apache License, Version 2.0 (the “License”);
-
* you may not use this file except in compliance with the License.
-
* You may obtain a copy of the License at
-
*
-
* http://www.apache.org/licenses/LICENSE-2.0
-
*
-
* Unless required by applicable law or agreed to in writing, software
-
* distributed under the License is distributed on an “AS IS” BASIS,
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-
* See the License for the specific language governing permissions and
-
* limitations under the License.
-
*/
-
package android.content.pm;
-
import android.content.res.XmlResourceParser;
-
import android.graphics.drawable.Drawable;
-
import android.os.Bundle;
-
import android.os.Parcel;
-
import android.text.TextUtils;
-
import android.util.Printer;
-
import java.text.Collator;
-
import java.util.Comparator;
-
/**
-
* Base class containing information common to all package items held by
-
* the package manager. This provides a very common basic set of attributes:
-
* a label, icon, and meta-data. This class is not intended
-
* to be used by itself; it is simply here to share common definitions
-
* between all items returned by the package manager. As such, it does not
-
* itself implement Parcelable, but does provide convenience methods to assist
-
* in the implementation of Parcelable in subclasses.
-
*/
-
public class PackageItemInfo {
-
/**
-
* Public name of this item. From the “android:name” attribute.
-
*/
-
public String name;
-
/**
-
* Name of the package that this item is in.
-
*/
-
public String packageName;
-
/**
-
* A string resource identifier (in the package’s resources) of this
-
* component’s label. From the “label” attribute or, if not set, 0.
-
*/
-
public int labelRes;
-
/**
-
* The string provided in the AndroidManifest file, if any. You
-
* probably don’t want to use this. You probably want
-
* {@link PackageManager#getApplicationLabel}
-
*/
-
public CharSequence nonLocalizedLabel;
-
/**
-
* A drawable resource identifier (in the package’s resources) of this
-
* component’s icon. From the “icon” attribute or, if not set, 0.
-
*/
-
public int icon;
-
/**
-
* A drawable resource identifier (in the package’s resources) of this
-
* component’s logo. Logos may be larger/wider than icons and are
-
* displayed by certain UI elements in place of a name or name/icon
-
* combination. From the “logo” attribute or, if not set, 0.
-
*/
-
public int logo;
-
/**
-
* Additional meta-data associated with this component. This field
-
* will only be filled in if you set the
-
* {@link PackageManager#GET_META_DATA} flag when requesting the info.
-
*/
-
public Bundle metaData;
-
public PackageItemInfo() {
-
}
-
public PackageItemInfo(PackageItemInfo orig) {
-
name = orig.name;
-
if (name != null) name = name.trim();
-
packageName = orig.packageName;
-
labelRes = orig.labelRes;
-
nonLocalizedLabel = orig.nonLocalizedLabel;
-
if (nonLocalizedLabel != null) nonLocalizedLabel = nonLocalizedLabel.toString().trim();
-
icon = orig.icon;
-
logo = orig.logo;
-
metaData = orig.metaData;
-
}
-
/**
-
* Retrieve the current textual label associated with this item. This
-
* will call back on the given PackageManager to load the label from
-
* the application.
-
*
-
* @param pm A PackageManager from which the label can be loaded; usually
-
* the PackageManager from which you originally retrieved this item.
-
*
-
* @return Returns a CharSequence containing the item’s label. If the
-
* item does not have a label, its name is returned.
-
*/
-
public CharSequence loadLabel(PackageManager pm) {
-
if (nonLocalizedLabel != null) {
-
return nonLocalizedLabel;
-
}
-
if (labelRes != 0) {
-
CharSequence label = pm.getText(packageName, labelRes, getApplicationInfo());
-
if (label != null) {
-
return label.toString().trim();
-
}
-
}
-
if (name != null) {
-
return name;
-
}
-
return packageName;
-
}
-
/**
-
* Retrieve the current graphical icon associated with this item. This
-
* will call back on the given PackageManager to load the icon from
-
* the application.
-
*
-
* @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 icon. If the
-
* 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, 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();
-
}
-
/**
-
* Retrieve the current graphical logo associated with this item. This
-
* will call back on the given PackageManager to load the logo from
-
* the application.
-
*
-
* @param pm A PackageManager from which the logo can be loaded; usually
-
* the PackageManager from which you originally retrieved this item.
-
*
-
* @return Returns a Drawable containing the item’s logo. If the item
-
* does not have a logo, this method will return null.
-
*/
-
public Drawable loadLogo(PackageManager pm) {
-
if (logo != 0) {
-
Drawable d = pm.getDrawable(packageName, logo, getApplicationInfo());
-
if (d != null) {
-
return d;
-
}
-
}
-
return loadDefaultLogo(pm);
-
}
-
/**
-
* Retrieve the default graphical logo associated with this item.
-
*
-
* @param pm A PackageManager from which the logo can be loaded; usually
-
* the PackageManager from which you originally retrieved this item.
-
*
-
* @return Returns a Drawable containing the item’s default logo
-
* or null if no default logo is available.
-
*
-
* @hide
-
*/
-
protected Drawable loadDefaultLogo(PackageManager pm) {
-
return null;
-
}
-
/**
-
* Load an XML resource attached to the meta-data of this item. This will
-
* retrieved the name meta-data entry, and if defined call back on the
-
* given PackageManager to load its XML file from the application.
-
*
-
* @param pm A PackageManager from which the XML can be loaded; usually
-
* the PackageManager from which you originally retrieved this item.
-
* @param name Name of the meta-date you would like to load.
-
*
-
* @return Returns an XmlPullParser you can use to parse the XML file
-
* assigned as the given meta-data. If the meta-data name is not defined
-
* or the XML resource could not be found, null is returned.
-
*/
-
public XmlResourceParser loadXmlMetaData(PackageManager pm, String name) {
-
if (metaData != null) {
-
int resid = metaData.getInt(name);
-
if (resid != 0) {
-
return pm.getXml(packageName, resid, getApplicationInfo());
-
}
-
}
-
return null;
-
}
-
protected void dumpFront(Printer pw, String prefix) {
-
if (name != null) {
-
pw.println(prefix + “name=” + name);
-
}
-
pw.println(prefix + “packageName=” + packageName);
-
if (labelRes != 0 || nonLocalizedLabel != null || icon != 0) {
-
pw.println(prefix + “labelRes=0x” + Integer.toHexString(labelRes)
-
+ " nonLocalizedLabel=" + nonLocalizedLabel
-
+ " icon=0x" + Integer.toHexString(icon));
-
}
-
}
-
protected void dumpBack(Printer pw, String prefix) {
-
// no back here
-
}
-
public void writeToParcel(Parcel dest, int parcelableFlags) {
-
dest.writeString(name);
-
dest.writeString(packageName);
-
dest.writeInt(labelRes);
-
TextUtils.writeToParcel(nonLocalizedLabel, dest, parcelableFlags);
-
dest.writeInt(icon);
总结
**其实上面说了这么多,钱是永远赚不完的,在这个知识付费的时代,知识技能提升才是是根本!我作为一名8年的高级工程师,知识技能已经学习的差不多。**在看这篇文章的可能有刚刚入门,刚刚开始工作,或者大佬级人物。
像刚刚开始学Android开发小白想要快速提升自己,最快捷的方式,就是有人可以带着你一起分析,这样学习起来最为高效,所以这里分享一套高手学习的源码和框架视频等精品Android架构师教程,保证你学了以后保证薪资上升一个台阶。
这么重要的事情说三遍啦!点赞+点赞+点赞!
【Android高级架构师系统学习资料】高级架构师进阶必备——设计思想解读开源框架
第一章、热修复设计
第二章、插件化框架设计
第三章、组件化框架设计
第四章、图片加载框架
第五章、网络访问框架设计
第六章、RXJava 响应式编程框架设计
第七章、IOC 架构设计
第八章、Android 架构组件 Jetpack
《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》,点击传送门,即可获取!
pm.getXml(packageName, resid, getApplicationInfo());
-
}
-
}
-
return null;
-
}
-
protected void dumpFront(Printer pw, String prefix) {
-
if (name != null) {
-
pw.println(prefix + “name=” + name);
-
}
-
pw.println(prefix + “packageName=” + packageName);
-
if (labelRes != 0 || nonLocalizedLabel != null || icon != 0) {
-
pw.println(prefix + “labelRes=0x” + Integer.toHexString(labelRes)
-
+ " nonLocalizedLabel=" + nonLocalizedLabel
-
+ " icon=0x" + Integer.toHexString(icon));
-
}
-
}
-
protected void dumpBack(Printer pw, String prefix) {
-
// no back here
-
}
-
public void writeToParcel(Parcel dest, int parcelableFlags) {
-
dest.writeString(name);
-
dest.writeString(packageName);
-
dest.writeInt(labelRes);
-
TextUtils.writeToParcel(nonLocalizedLabel, dest, parcelableFlags);
-
dest.writeInt(icon);
总结
**其实上面说了这么多,钱是永远赚不完的,在这个知识付费的时代,知识技能提升才是是根本!我作为一名8年的高级工程师,知识技能已经学习的差不多。**在看这篇文章的可能有刚刚入门,刚刚开始工作,或者大佬级人物。
像刚刚开始学Android开发小白想要快速提升自己,最快捷的方式,就是有人可以带着你一起分析,这样学习起来最为高效,所以这里分享一套高手学习的源码和框架视频等精品Android架构师教程,保证你学了以后保证薪资上升一个台阶。
这么重要的事情说三遍啦!点赞+点赞+点赞!
[外链图片转存中…(img-2BliUUcI-1714450815493)]
【Android高级架构师系统学习资料】高级架构师进阶必备——设计思想解读开源框架
第一章、热修复设计
第二章、插件化框架设计
第三章、组件化框架设计
第四章、图片加载框架
第五章、网络访问框架设计
第六章、RXJava 响应式编程框架设计
第七章、IOC 架构设计
第八章、Android 架构组件 Jetpack
[外链图片转存中…(img-xOUwSbkT-1714450815494)]
《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》,点击传送门,即可获取!