-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
188431a
commit 7057e4a
Showing
8 changed files
with
234 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,11 @@ | |
* 凤凰卫视增强画质 | ||
* 凤凰卫视增加EPG | ||
|
||
### v1.6.5(安卓5及以上专用) | ||
|
||
* 增加CETV1图标 | ||
* 稳定性提升 | ||
|
||
### v1.6.4(通用) | ||
|
||
* 增加CETV1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
@file:Suppress("DEPRECATION") | ||
|
||
package com.lizongying.mytv | ||
|
||
import android.content.Context | ||
import android.content.pm.PackageInfo | ||
import android.content.pm.PackageManager | ||
import android.content.pm.Signature | ||
import android.content.pm.SigningInfo | ||
import android.os.Build | ||
import android.util.Log | ||
import java.security.MessageDigest | ||
|
||
private const val TAG = "Extensions" | ||
|
||
private val Context.packageInfo: PackageInfo | ||
get() { | ||
val flag = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) { | ||
PackageManager.GET_SIGNATURES | ||
} else { | ||
PackageManager.GET_SIGNING_CERTIFICATES | ||
} | ||
return if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) { | ||
packageManager.getPackageInfo(packageName, flag) | ||
} else { | ||
packageManager.getPackageInfo( | ||
packageName, | ||
PackageManager.PackageInfoFlags.of(PackageManager.GET_SIGNING_CERTIFICATES.toLong()) | ||
) | ||
} | ||
} | ||
|
||
/** | ||
* Return the version code of the app which is defined in build.gradle. | ||
* eg:100 | ||
*/ | ||
val Context.appVersionCode: Long | ||
get() { | ||
val packageInfo = this.packageInfo | ||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { | ||
packageInfo.longVersionCode | ||
} else { | ||
packageInfo.versionCode.toLong() | ||
} | ||
} | ||
|
||
/** | ||
* Return the version name of the app which is defined in build.gradle. | ||
* eg:1.0.0 | ||
*/ | ||
val Context.appVersionName: String get() = packageInfo.versionName | ||
|
||
val Context.appSignature: String | ||
get() { | ||
val packageInfo = this.packageInfo | ||
var sign: Signature? = null | ||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) { | ||
val signatures: Array<out Signature>? = packageInfo.signatures | ||
if (signatures != null) { | ||
sign = signatures[0] | ||
} | ||
} else { | ||
val signingInfo: SigningInfo? = packageInfo.signingInfo | ||
if (signingInfo != null) { | ||
sign = signingInfo.apkContentsSigners[0] | ||
} | ||
} | ||
if (sign == null) { | ||
return "" | ||
} | ||
return hashSignature(sign) | ||
} | ||
|
||
private fun hashSignature(signature: Signature): String { | ||
return try { | ||
val md = MessageDigest.getInstance("MD5") | ||
md.update(signature.toByteArray()) | ||
val digest = md.digest() | ||
digest.let { it -> it.joinToString("") { "%02x".format(it) } } | ||
} catch (e: Exception) { | ||
Log.e(TAG, "Error hashing signature", e) | ||
"" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.