- [giveResult] not sending data param if null

- [Utils] `getApplicationSignature`: returning `SHA-256` signature instead of `SHA`
- [Utils] `jsonToBundle`: changed approach
This commit is contained in:
Harsh Bhikadia 2021-04-24 23:38:30 +05:30
parent 61ca0ffb41
commit 07f81ea602
3 changed files with 45 additions and 32 deletions

View file

@ -1,17 +1,26 @@
<component name="libraryTable"> <component name="libraryTable">
<library name="Dart SDK"> <library name="Dart SDK">
<CLASSES> <CLASSES>
<root url="file:///home/harsh/flutter/flutter/bin/cache/dart-sdk/lib/async" /> <root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/async" />
<root url="file:///home/harsh/flutter/flutter/bin/cache/dart-sdk/lib/collection" /> <root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/cli" />
<root url="file:///home/harsh/flutter/flutter/bin/cache/dart-sdk/lib/convert" /> <root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/collection" />
<root url="file:///home/harsh/flutter/flutter/bin/cache/dart-sdk/lib/core" /> <root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/convert" />
<root url="file:///home/harsh/flutter/flutter/bin/cache/dart-sdk/lib/developer" /> <root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/core" />
<root url="file:///home/harsh/flutter/flutter/bin/cache/dart-sdk/lib/html" /> <root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/developer" />
<root url="file:///home/harsh/flutter/flutter/bin/cache/dart-sdk/lib/io" /> <root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/ffi" />
<root url="file:///home/harsh/flutter/flutter/bin/cache/dart-sdk/lib/isolate" /> <root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/html" />
<root url="file:///home/harsh/flutter/flutter/bin/cache/dart-sdk/lib/math" /> <root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/indexed_db" />
<root url="file:///home/harsh/flutter/flutter/bin/cache/dart-sdk/lib/mirrors" /> <root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/io" />
<root url="file:///home/harsh/flutter/flutter/bin/cache/dart-sdk/lib/typed_data" /> <root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/isolate" />
<root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/js" />
<root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/js_util" />
<root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/math" />
<root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/mirrors" />
<root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/svg" />
<root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/typed_data" />
<root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/web_audio" />
<root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/web_gl" />
<root url="file://$USER_HOME$/flutter/bin/cache/dart-sdk/lib/web_sql" />
</CLASSES> </CLASSES>
<JAVADOC /> <JAVADOC />
<SOURCES /> <SOURCES />

View file

@ -15,24 +15,27 @@ import java.security.MessageDigest
fun jsonToBundle(json: JSONObject): Bundle { fun jsonToBundle(json: JSONObject): Bundle {
val bundle = Bundle() val bundle = Bundle()
json.keys().forEach { try {
val k = it val iterator: Iterator<String> = json.keys()
val v = json.get(k) while (iterator.hasNext()) {
when (v) { val key = iterator.next()
is Byte -> bundle.putByte(k, v) val value: Any = json.get(key)
is ByteArray -> bundle.putByteArray(k, v) when (value.javaClass.getSimpleName()) {
is Char -> bundle.putChar(k, v) "String" -> bundle.putString(key, value as String)
is CharArray -> bundle.putCharArray(k, v) "Integer" -> bundle.putInt(key, value as Int)
is CharSequence -> bundle.putCharSequence(k, v) "Long" -> bundle.putLong(key, value as Long)
is Float -> bundle.putFloat(k, v) "Boolean" -> bundle.putBoolean(key, value as Boolean)
is FloatArray -> bundle.putFloatArray(k, v) "JSONObject" -> bundle.putBundle(key, jsonToBundle(value as JSONObject))
is Parcelable -> bundle.putParcelable(k, v) "Float" -> bundle.putFloat(key, value as Float)
is Short -> bundle.putShort(k, v) "Double" -> bundle.putDouble(key, value as Double)
is ShortArray -> bundle.putShortArray(k, v) else -> bundle.putString(key, value.toString())
else -> throw IllegalArgumentException("$v is of a type that is not currently supported") }
} }
} catch (e: JSONException) {
e.printStackTrace()
} }
return bundle; return bundle
} }
fun jsonToIntent(json: JSONObject): Intent = Intent().apply { fun jsonToIntent(json: JSONObject): Intent = Intent().apply {
@ -125,14 +128,14 @@ fun getApplicationSignature(context: Context, packageName: String): List<String>
signatureList = if (sig.hasMultipleSigners()) { signatureList = if (sig.hasMultipleSigners()) {
// Send all with apkContentsSigners // Send all with apkContentsSigners
sig.apkContentsSigners.map { sig.apkContentsSigners.map {
val digest = MessageDigest.getInstance("SHA") val digest = MessageDigest.getInstance("SHA-256")
digest.update(it.toByteArray()) digest.update(it.toByteArray())
bytesToHex(digest.digest()) bytesToHex(digest.digest())
} }
} else { } else {
// Send one with signingCertificateHistory // Send one with signingCertificateHistory
sig.signingCertificateHistory.map { sig.signingCertificateHistory.map {
val digest = MessageDigest.getInstance("SHA") val digest = MessageDigest.getInstance("SHA-256")
digest.update(it.toByteArray()) digest.update(it.toByteArray())
bytesToHex(digest.digest()) bytesToHex(digest.digest())
} }
@ -140,7 +143,7 @@ fun getApplicationSignature(context: Context, packageName: String): List<String>
} else { } else {
val sig = context.packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES).signatures val sig = context.packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES).signatures
signatureList = sig.map { signatureList = sig.map {
val digest = MessageDigest.getInstance("SHA") val digest = MessageDigest.getInstance("SHA-256")
digest.update(it.toByteArray()) digest.update(it.toByteArray())
bytesToHex(digest.digest()) bytesToHex(digest.digest())
} }

View file

@ -69,10 +69,11 @@ class ReceiveIntent {
.receiveBroadcastStream() .receiveBroadcastStream()
.map<ReceivedIntent?>((event) => ReceivedIntent.fromMap(event as Map?)); .map<ReceivedIntent?>((event) => ReceivedIntent.fromMap(event as Map?));
static Future<void> giveResult(int resultCode, {Map? data, bool shouldFinish: false}) async { static Future<void> giveResult(int resultCode,
{Map<String, dynamic?>? data, bool shouldFinish: false}) async {
await _methodChannel.invokeMethod('giveResult', <String, dynamic>{ await _methodChannel.invokeMethod('giveResult', <String, dynamic>{
"resultCode": resultCode, "resultCode": resultCode,
"data": json.encode(data), if (data != null) "data": json.encode(data),
"shouldFinish": shouldFinish, "shouldFinish": shouldFinish,
}); });
} }