Skip to content

Commit

Permalink
ApplicationUtils added
Browse files Browse the repository at this point in the history
  • Loading branch information
murgupluoglu committed May 14, 2020
1 parent 9eae933 commit fe20949
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {

}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.1'
classpath 'com.android.tools.build:gradle:3.6.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
2 changes: 1 addition & 1 deletion extensions/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
testImplementation 'junit:junit:4.12'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.applogist.extensions

import android.content.Context
import android.content.pm.PackageManager
import android.os.Build
import android.util.Log
import java.security.MessageDigest

/*
* Created by Mustafa Ürgüplüoğlu on 10.04.2020.
* Copyright © 2020 Mustafa Ürgüplüoğlu. All rights reserved.
*/

fun Context.getApplicationSignature(packageName: String, type : String = "SHA256"): List<String> {
val signatureList: List<String>
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
// New signature
val sig = packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNING_CERTIFICATES).signingInfo
signatureList = if (sig.hasMultipleSigners()) {
// Send all with apkContentsSigners
sig.apkContentsSigners.map {
val digest = MessageDigest.getInstance(type)
digest.update(it.toByteArray())
digest.digest().bytesToHex()
}
} else {
// Send one with signingCertificateHistory
sig.signingCertificateHistory.map {
val digest = MessageDigest.getInstance(type)
digest.update(it.toByteArray())
digest.digest().bytesToHex()
}
}
} else {
val sig = packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES).signatures
signatureList = sig.map {
val digest = MessageDigest.getInstance(type)
digest.update(it.toByteArray())
digest.digest().bytesToHex()
}
}

return signatureList
} catch (e: Exception) {
Log.e("ApplicationUtils", e.toString())
}
return emptyList()
}
18 changes: 18 additions & 0 deletions extensions/src/main/java/com/applogist/extensions/HexUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.applogist.extensions

/*
* Created by Mustafa Ürgüplüoğlu on 10.04.2020.
* Copyright © 2020 Mustafa Ürgüplüoğlu. All rights reserved.
*/

fun ByteArray.bytesToHex(): String {
val hexArray = charArrayOf('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F')
val hexChars = CharArray(this.size * 2)
var v: Int
for (j in this.indices) {
v = this[j].toInt() and 0xFF
hexChars[j * 2] = hexArray[v.ushr(4)]
hexChars[j * 2 + 1] = hexArray[v and 0x0F]
}
return String(hexChars)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.applogist.extensions

import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.util.Log

Expand Down
2 changes: 1 addition & 1 deletion extensions/src/main/java/com/applogist/helpers/Common.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import java.util.concurrent.TimeUnit
/**
* Check time difference between current time and given time
* @param lastTime = Given time in millis format
* @param isMinutes = different should me minutes or hour
* @param isMinutes = different should be minutes or hour
* @param checkTime = amount of time difference
*/
fun isTimePassed(lastTime : Long, isMinutes : Boolean = false, checkTime : Int = 8) : Boolean {
Expand Down

0 comments on commit fe20949

Please sign in to comment.