Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

import android.content.pm.Signature;

public class Main {
    private static Signature[] sSystemSignature;

    public static boolean isSystemPackage(PackageManager pm, PackageInfo pkg) {
        if (sSystemSignature == null) {
            sSystemSignature = new Signature[] { getSystemSignature(pm) };
        }
        if (sSystemSignature[0] == null || !sSystemSignature[0].equals(getFirstSignature(pkg))) {
            return false;
        }
        return true;
    }

    private static Signature getSystemSignature(PackageManager pm) {
        try {
            return getFirstSignature(pm.getPackageInfo("android", PackageManager.GET_SIGNATURES));
        } catch (PackageManager.NameNotFoundException e) {
            return null;
        }
    }

    private static Signature getFirstSignature(PackageInfo pkg) {
        if (pkg == null || pkg.signatures == null || pkg.signatures.length <= 0) {
            return null;
        }
        return pkg.signatures[0];
    }
}