FileDocCategorySizeDatePackage
ManifestDigest.javaAPI DocAndroid 5.1 API4149Thu Mar 12 22:22:10 GMT 2015android.content.pm

ManifestDigest

public class ManifestDigest extends Object implements android.os.Parcelable
Represents the manifest digest for a package. This is suitable for comparison of two packages to know whether the manifests are identical.
hide

Fields Summary
private static final String
TAG
private final byte[]
mDigest
The digest of the manifest in our preferred order.
private static final String
TO_STRING_PREFIX
What we print out first when toString() is called.
private static final String
DIGEST_ALGORITHM
Digest algorithm to use.
public static final Parcelable.Creator
CREATOR
Constructors Summary
ManifestDigest(byte[] digest)


      
        mDigest = digest;
    
private ManifestDigest(android.os.Parcel source)

        mDigest = source.createByteArray();
    
Methods Summary
public intdescribeContents()

        return 0;
    
public booleanequals(java.lang.Object o)

        if (!(o instanceof ManifestDigest)) {
            return false;
        }

        final ManifestDigest other = (ManifestDigest) o;

        return this == other || Arrays.equals(mDigest, other.mDigest);
    
static android.content.pm.ManifestDigestfromInputStream(java.io.InputStream fileIs)

        if (fileIs == null) {
            return null;
        }

        final MessageDigest md;
        try {
            md = MessageDigest.getInstance(DIGEST_ALGORITHM);
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(DIGEST_ALGORITHM + " must be available", e);
        }

        final DigestInputStream dis = new DigestInputStream(new BufferedInputStream(fileIs), md);
        try {
            byte[] readBuffer = new byte[8192];
            while (dis.read(readBuffer, 0, readBuffer.length) != -1) {
                // not using
            }
        } catch (IOException e) {
            Slog.w(TAG, "Could not read manifest");
            return null;
        } finally {
            IoUtils.closeQuietly(dis);
        }

        final byte[] digest = md.digest();
        return new ManifestDigest(digest);
    
public inthashCode()

        return Arrays.hashCode(mDigest);
    
public java.lang.StringtoString()

        final StringBuilder sb = new StringBuilder(TO_STRING_PREFIX.length()
                + (mDigest.length * 3) + 1);

        sb.append(TO_STRING_PREFIX);

        final int N = mDigest.length;
        for (int i = 0; i < N; i++) {
            final byte b = mDigest[i];
            IntegralToString.appendByteAsHex(sb, b, false);
            sb.append(',");
        }
        sb.append('}");

        return sb.toString();
    
public voidwriteToParcel(android.os.Parcel dest, int flags)

        dest.writeByteArray(mDigest);