88import android .content .pm .PackageInfo ;
99import android .content .pm .PackageManager ;
1010import android .content .pm .Signature ;
11+ import android .content .pm .SigningInfo ;
1112import android .graphics .drawable .Drawable ;
1213import android .net .Uri ;
1314import android .os .Build ;
@@ -498,8 +499,8 @@ public static int getAppVersionCode(final String packageName) {
498499 *
499500 * @return the application's signature
500501 */
501- public static Signature [] getAppSignature () {
502- return getAppSignature (Utils .getApp ().getPackageName ());
502+ public static Signature [] getAppSignatures () {
503+ return getAppSignatures (Utils .getApp ().getPackageName ());
503504 }
504505
505506 /**
@@ -508,17 +509,26 @@ public static Signature[] getAppSignature() {
508509 * @param packageName The name of the package.
509510 * @return the application's signature
510511 */
511- public static Signature [] getAppSignature (final String packageName ) {
512+ public static Signature [] getAppSignatures (final String packageName ) {
512513 if (UtilsBridge .isSpace (packageName )) return null ;
513514 try {
514515 PackageManager pm = Utils .getApp ().getPackageManager ();
515- PackageInfo pi ;
516516 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .P ) {
517- pi = pm .getPackageInfo (packageName , PackageManager .GET_SIGNING_CERTIFICATES );
517+ PackageInfo pi = pm .getPackageInfo (packageName , PackageManager .GET_SIGNING_CERTIFICATES );
518+ if (pi == null ) return null ;
519+
520+ SigningInfo signingInfo = pi .signingInfo ;
521+ if (signingInfo .hasMultipleSigners ()) {
522+ return signingInfo .getApkContentsSigners ();
523+ } else {
524+ return signingInfo .getSigningCertificateHistory ();
525+ }
518526 } else {
519- pi = pm .getPackageInfo (packageName , PackageManager .GET_SIGNATURES );
527+ PackageInfo pi = pm .getPackageInfo (packageName , PackageManager .GET_SIGNATURES );
528+ if (pi == null ) return null ;
529+
530+ return pi .signatures ;
520531 }
521- return pi == null ? null : pi .signatures ;
522532 } catch (PackageManager .NameNotFoundException e ) {
523533 e .printStackTrace ();
524534 return null ;
@@ -531,25 +541,34 @@ public static Signature[] getAppSignature(final String packageName) {
531541 * @param file The file.
532542 * @return the application's signature
533543 */
534- public static Signature [] getAppSignature (final File file ) {
544+ public static Signature [] getAppSignatures (final File file ) {
535545 if (file == null ) return null ;
536546 PackageManager pm = Utils .getApp ().getPackageManager ();
537- PackageInfo pi ;
538547 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .P ) {
539- pi = pm .getPackageArchiveInfo (file .getAbsolutePath (), PackageManager .GET_SIGNING_CERTIFICATES );
548+ PackageInfo pi = pm .getPackageArchiveInfo (file .getAbsolutePath (), PackageManager .GET_SIGNING_CERTIFICATES );
549+ if (pi == null ) return null ;
550+
551+ SigningInfo signingInfo = pi .signingInfo ;
552+ if (signingInfo .hasMultipleSigners ()) {
553+ return signingInfo .getApkContentsSigners ();
554+ } else {
555+ return signingInfo .getSigningCertificateHistory ();
556+ }
540557 } else {
541- pi = pm .getPackageArchiveInfo (file .getAbsolutePath (), PackageManager .GET_SIGNATURES );
558+ PackageInfo pi = pm .getPackageArchiveInfo (file .getAbsolutePath (), PackageManager .GET_SIGNATURES );
559+ if (pi == null ) return null ;
560+
561+ return pi .signatures ;
542562 }
543- return pi == null ? null : pi .signatures ;
544563 }
545564
546565 /**
547566 * Return the application's signature for SHA1 value.
548567 *
549568 * @return the application's signature for SHA1 value
550569 */
551- public static String getAppSignatureSHA1 () {
552- return getAppSignatureSHA1 (Utils .getApp ().getPackageName ());
570+ public static List < String > getAppSignaturesSHA1 () {
571+ return getAppSignaturesSHA1 (Utils .getApp ().getPackageName ());
553572 }
554573
555574 /**
@@ -558,17 +577,17 @@ public static String getAppSignatureSHA1() {
558577 * @param packageName The name of the package.
559578 * @return the application's signature for SHA1 value
560579 */
561- public static String getAppSignatureSHA1 (final String packageName ) {
562- return getAppSignatureHash (packageName , "SHA1" );
580+ public static List < String > getAppSignaturesSHA1 (final String packageName ) {
581+ return getAppSignaturesHash (packageName , "SHA1" );
563582 }
564583
565584 /**
566585 * Return the application's signature for SHA256 value.
567586 *
568587 * @return the application's signature for SHA256 value
569588 */
570- public static String getAppSignatureSHA256 () {
571- return getAppSignatureSHA256 (Utils .getApp ().getPackageName ());
589+ public static List < String > getAppSignaturesSHA256 () {
590+ return getAppSignaturesSHA256 (Utils .getApp ().getPackageName ());
572591 }
573592
574593 /**
@@ -577,17 +596,17 @@ public static String getAppSignatureSHA256() {
577596 * @param packageName The name of the package.
578597 * @return the application's signature for SHA256 value
579598 */
580- public static String getAppSignatureSHA256 (final String packageName ) {
581- return getAppSignatureHash (packageName , "SHA256" );
599+ public static List < String > getAppSignaturesSHA256 (final String packageName ) {
600+ return getAppSignaturesHash (packageName , "SHA256" );
582601 }
583602
584603 /**
585604 * Return the application's signature for MD5 value.
586605 *
587606 * @return the application's signature for MD5 value
588607 */
589- public static String getAppSignatureMD5 () {
590- return getAppSignatureMD5 (Utils .getApp ().getPackageName ());
608+ public static List < String > getAppSignaturesMD5 () {
609+ return getAppSignaturesMD5 (Utils .getApp ().getPackageName ());
591610 }
592611
593612 /**
@@ -596,11 +615,10 @@ public static String getAppSignatureMD5() {
596615 * @param packageName The name of the package.
597616 * @return the application's signature for MD5 value
598617 */
599- public static String getAppSignatureMD5 (final String packageName ) {
600- return getAppSignatureHash (packageName , "MD5" );
618+ public static List < String > getAppSignaturesMD5 (final String packageName ) {
619+ return getAppSignaturesHash (packageName , "MD5" );
601620 }
602621
603-
604622 /**
605623 * Return the application's user-ID.
606624 *
@@ -625,12 +643,17 @@ public static int getAppUid(String pkgName) {
625643 }
626644 }
627645
628- private static String getAppSignatureHash (final String packageName , final String algorithm ) {
629- if (UtilsBridge .isSpace (packageName )) return "" ;
630- Signature [] signature = getAppSignature (packageName );
631- if (signature == null || signature .length <= 0 ) return "" ;
632- return UtilsBridge .bytes2HexString (UtilsBridge .hashTemplate (signature [0 ].toByteArray (), algorithm ))
633- .replaceAll ("(?<=[0-9A-F]{2})[0-9A-F]{2}" , ":$0" );
646+ private static List <String > getAppSignaturesHash (final String packageName , final String algorithm ) {
647+ ArrayList <String > result = new ArrayList <>();
648+ if (UtilsBridge .isSpace (packageName )) return result ;
649+ Signature [] signatures = getAppSignatures (packageName );
650+ if (signatures == null || signatures .length <= 0 ) return result ;
651+ for (Signature signature : signatures ) {
652+ String hash = UtilsBridge .bytes2HexString (UtilsBridge .hashTemplate (signature .toByteArray (), algorithm ))
653+ .replaceAll ("(?<=[0-9A-F]{2})[0-9A-F]{2}" , ":$0" );
654+ result .add (hash );
655+ }
656+ return result ;
634657 }
635658
636659 /**
0 commit comments