Exemple #1
0
  /**
   * getApkFileStatus
   *
   * @param newinfo
   * @return status with the new application info<br>
   *     return 0: installed with same signature<br>
   *     return 1: installed with different signature<br>
   *     return 2: no need update<br>
   *     return 3: not installed<br>
   *     return 4: error
   */
  public static int getApkFileStatus(Context context, DataappInfo newinfo) {
    try {
      String packageName = newinfo.info.packageName;
      ApplicationInfo installedInfo = null;
      try {
        installedInfo = context.getPackageManager().getApplicationInfo(packageName, 0);
      } catch (NameNotFoundException e) {

      }
      if (installedInfo == null) {
        return 3;
      }
      int newVer = DeviceUtils.getAppVersionCode(context, newinfo.localPath);
      int oldVer = DeviceUtils.getAppVersionCode(context, installedInfo);
      if (newVer <= oldVer) {
        return 2;
      }
      boolean compare =
          SignatureUtils.compareSignature(newinfo.localPath, installedInfo.publicSourceDir);
      // int compare = GlobalInstance.pm.checkSignatures(newinfo.info.uid, installedInfo.uid);
      return (compare ? 0 : 1);
    } catch (Exception e) {
      return 4;
    }
  }
Exemple #2
0
 public static boolean checkSignature(String apk1, String apk2) {
   // check signature
   List<String> sig1 = null;
   try {
     sig1 = SignatureUtils.getSignaturesFromApk(apk1);
   } catch (IOException e) {
   }
   List<String> sig2 = null;
   try {
     sig2 = SignatureUtils.getSignaturesFromApk(apk2);
   } catch (IOException e) {
   }
   if (sig1 == null || sig2 == null) {
     return false;
   } else {
     return sig1.equals(sig2);
   }
 }