From 78593e0391fcd5e2b9a0fa0a2ede346211e28503 Mon Sep 17 00:00:00 2001 From: MM20 <15646950+MM2-0@users.noreply.github.com> Date: Tue, 10 May 2022 18:40:53 +0200 Subject: [PATCH] Add signature to crash reporter info --- .../crashreporter/utils/AppUtils.java | 3 ++ .../crashreporter/utils/AppUtils.kt | 28 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 crashreporter/src/main/java/com/balsikandar/crashreporter/utils/AppUtils.kt diff --git a/crashreporter/src/main/java/com/balsikandar/crashreporter/utils/AppUtils.java b/crashreporter/src/main/java/com/balsikandar/crashreporter/utils/AppUtils.java index 357f59f0..2dd74393 100644 --- a/crashreporter/src/main/java/com/balsikandar/crashreporter/utils/AppUtils.java +++ b/crashreporter/src/main/java/com/balsikandar/crashreporter/utils/AppUtils.java @@ -11,6 +11,8 @@ import android.util.Log; import java.util.TimeZone; import java.util.UUID; +import static com.balsikandar.crashreporter.utils.AppUtilsKt.getAppSignature; + /** * Created by bali on 12/08/17. */ @@ -37,6 +39,7 @@ public class AppUtils { return "APP.VERSION : " + getAppVersion(context) + "\nAPP.VERSIONCODE : " + getAppVersionCode(context) + + "\nAPP.SIGNATURE : " + getAppSignature(context) + "\nLAUNCHER.APP : " + getCurrentLauncherApp(context) + "\nTIMEZONE : " + timeZone() + "\nVERSION.RELEASE : " + Build.VERSION.RELEASE diff --git a/crashreporter/src/main/java/com/balsikandar/crashreporter/utils/AppUtils.kt b/crashreporter/src/main/java/com/balsikandar/crashreporter/utils/AppUtils.kt new file mode 100644 index 00000000..ed092368 --- /dev/null +++ b/crashreporter/src/main/java/com/balsikandar/crashreporter/utils/AppUtils.kt @@ -0,0 +1,28 @@ +package com.balsikandar.crashreporter.utils + +import android.content.Context +import android.content.pm.PackageManager +import android.os.Build +import android.util.Base64 +import java.security.MessageDigest + +internal fun getAppSignature(context: Context): String { + val signature = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + val pi = context.packageManager.getPackageInfo( + context.packageName, + PackageManager.GET_SIGNING_CERTIFICATES + ) + pi.signingInfo.apkContentsSigners.firstOrNull() + } else { + val pi = context.packageManager.getPackageInfo( + context.packageName, + PackageManager.GET_SIGNATURES + ) + pi.signatures.firstOrNull() + } + return if (signature != null) { + val digest = MessageDigest.getInstance("SHA") + digest.update(signature.toByteArray()) + Base64.encodeToString(digest.digest(), Base64.NO_WRAP) + } else "null" +} \ No newline at end of file