1212
1313import androidx .annotation .IntDef ;
1414import androidx .annotation .NonNull ;
15+ import androidx .annotation .Nullable ;
1516import androidx .annotation .WorkerThread ;
1617import androidx .core .content .pm .PackageInfoCompat ;
1718
1819import java .lang .annotation .Retention ;
1920import java .lang .annotation .RetentionPolicy ;
21+ import java .security .cert .CertificateEncodingException ;
22+ import java .security .cert .X509Certificate ;
2023import java .util .ArrayList ;
2124import java .util .Arrays ;
2225import java .util .HashMap ;
2528import java .util .Set ;
2629
2730import io .github .muntashirakon .AppManager .R ;
31+ import io .github .muntashirakon .AppManager .apk .signing .CertUtils ;
32+ import io .github .muntashirakon .AppManager .apk .signing .SignerInfo ;
2833import io .github .muntashirakon .AppManager .rules .RuleType ;
2934import io .github .muntashirakon .AppManager .rules .compontents .ComponentUtils ;
3035import io .github .muntashirakon .AppManager .utils .ArrayUtils ;
36+ import io .github .muntashirakon .AppManager .utils .DigestUtils ;
3137import io .github .muntashirakon .AppManager .utils .LangUtils ;
3238import io .github .muntashirakon .AppManager .utils .PackageUtils ;
3339import io .github .muntashirakon .AppManager .utils .ThreadUtils ;
@@ -48,12 +54,12 @@ public class ApkWhatsNewFinder {
4854 public static final int CHANGE_INFO = 3 ;
4955
5056 public static final int VERSION_INFO = 0 ;
51- public static final int TRACKER_INFO = 1 ;
52- public static final int SIGNING_CERT_SHA256 = 2 ;
53- public static final int PERMISSION_INFO = 3 ;
54- public static final int COMPONENT_INFO = 4 ;
55- public static final int FEATURE_INFO = 5 ;
56- public static final int SDK_INFO = 6 ;
57+ public static final int SDK_INFO = 1 ;
58+ public static final int TRACKER_INFO = 2 ;
59+ public static final int SIGNING_CERT_SHA256 = 3 ;
60+ public static final int PERMISSION_INFO = 4 ;
61+ public static final int COMPONENT_INFO = 5 ;
62+ public static final int FEATURE_INFO = 6 ;
5763
5864 private static final int INFO_COUNT = 7 ;
5965
@@ -129,8 +135,8 @@ public Change[][] getWhatsNew(@NonNull Context context, @NonNull PackageInfo new
129135 return changes ;
130136 }
131137 // Sha256 of signing certificates
132- Set <String > newCertSha256 = new HashSet <>( Arrays . asList ( PackageUtils .getSigningCertSha256Checksum (newPkgInfo , true ) ));
133- Set <String > oldCertSha256 = new HashSet <>( Arrays . asList ( PackageUtils .getSigningCertSha256Checksum (oldPkgInfo ) ));
138+ Set <String > newCertSha256 = getReadableSignerInfo ( PackageUtils .getSignerInfo (newPkgInfo , true ));
139+ Set <String > oldCertSha256 = getReadableSignerInfo ( PackageUtils .getSignerInfo (oldPkgInfo , false ));
134140 List <Change > certSha256Changes = new ArrayList <>();
135141 certSha256Changes .add (new Change (CHANGE_INFO , componentInfo [SIGNING_CERT_SHA256 ]));
136142 certSha256Changes .addAll (findChanges (newCertSha256 , oldCertSha256 ));
@@ -211,6 +217,25 @@ private List<Change> findChanges(Set<String> newInfo, Set<String> oldInfo) {
211217 return changeList ;
212218 }
213219
220+ private Set <String > getReadableSignerInfo (@ Nullable SignerInfo signerInfo ) {
221+ Set <String > readableSignerInfo = new HashSet <>();
222+ X509Certificate [] x509Certificates = signerInfo == null ? null : signerInfo .getAllSignerCerts ();
223+ if (x509Certificates != null ) {
224+ for (X509Certificate cert : x509Certificates ) {
225+ StringBuilder builder = new StringBuilder ();
226+ try {
227+ String sha = DigestUtils .getHexDigest (DigestUtils .SHA_256 , cert .getEncoded ());
228+ builder .append (sha .substring (0 , 4 )).append (" - " );
229+ } catch (CertificateEncodingException e ) {
230+ throw new RuntimeException (e );
231+ }
232+ builder .append (CertUtils .getReadableSubject (cert ));
233+ readableSignerInfo .add (builder .toString ());
234+ }
235+ }
236+ return readableSignerInfo ;
237+ }
238+
214239 public static class Change {
215240 @ ChangeType
216241 public int changeType ;
0 commit comments