From 07f81ea602d764f0654dedb2a683f42f26a8787e Mon Sep 17 00:00:00 2001 From: Harsh Bhikadia Date: Sat, 24 Apr 2021 23:38:30 +0530 Subject: [PATCH] - [giveResult] not sending `data` param if `null` - [Utils] `getApplicationSignature`: returning `SHA-256` signature instead of `SHA` - [Utils] `jsonToBundle`: changed approach --- .idea/libraries/Dart_SDK.xml | 31 +++++++++----- .../com/bhikadia/receive_intent/Utils.kt | 41 ++++++++++--------- lib/receive_intent.dart | 5 ++- 3 files changed, 45 insertions(+), 32 deletions(-) diff --git a/.idea/libraries/Dart_SDK.xml b/.idea/libraries/Dart_SDK.xml index 76fd1d6..62be7ea 100644 --- a/.idea/libraries/Dart_SDK.xml +++ b/.idea/libraries/Dart_SDK.xml @@ -1,17 +1,26 @@ - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + diff --git a/android/src/main/kotlin/com/bhikadia/receive_intent/Utils.kt b/android/src/main/kotlin/com/bhikadia/receive_intent/Utils.kt index b27ea98..d637276 100644 --- a/android/src/main/kotlin/com/bhikadia/receive_intent/Utils.kt +++ b/android/src/main/kotlin/com/bhikadia/receive_intent/Utils.kt @@ -15,24 +15,27 @@ import java.security.MessageDigest fun jsonToBundle(json: JSONObject): Bundle { val bundle = Bundle() - json.keys().forEach { - val k = it - val v = json.get(k) - when (v) { - is Byte -> bundle.putByte(k, v) - is ByteArray -> bundle.putByteArray(k, v) - is Char -> bundle.putChar(k, v) - is CharArray -> bundle.putCharArray(k, v) - is CharSequence -> bundle.putCharSequence(k, v) - is Float -> bundle.putFloat(k, v) - is FloatArray -> bundle.putFloatArray(k, v) - is Parcelable -> bundle.putParcelable(k, v) - is Short -> bundle.putShort(k, v) - is ShortArray -> bundle.putShortArray(k, v) - else -> throw IllegalArgumentException("$v is of a type that is not currently supported") + try { + val iterator: Iterator = json.keys() + while (iterator.hasNext()) { + val key = iterator.next() + val value: Any = json.get(key) + when (value.javaClass.getSimpleName()) { + "String" -> bundle.putString(key, value as String) + "Integer" -> bundle.putInt(key, value as Int) + "Long" -> bundle.putLong(key, value as Long) + "Boolean" -> bundle.putBoolean(key, value as Boolean) + "JSONObject" -> bundle.putBundle(key, jsonToBundle(value as JSONObject)) + "Float" -> bundle.putFloat(key, value as Float) + "Double" -> bundle.putDouble(key, value as Double) + else -> bundle.putString(key, value.toString()) + } } + } catch (e: JSONException) { + e.printStackTrace() } - return bundle; + return bundle + } fun jsonToIntent(json: JSONObject): Intent = Intent().apply { @@ -125,14 +128,14 @@ fun getApplicationSignature(context: Context, packageName: String): List signatureList = if (sig.hasMultipleSigners()) { // Send all with apkContentsSigners sig.apkContentsSigners.map { - val digest = MessageDigest.getInstance("SHA") + val digest = MessageDigest.getInstance("SHA-256") digest.update(it.toByteArray()) bytesToHex(digest.digest()) } } else { // Send one with signingCertificateHistory sig.signingCertificateHistory.map { - val digest = MessageDigest.getInstance("SHA") + val digest = MessageDigest.getInstance("SHA-256") digest.update(it.toByteArray()) bytesToHex(digest.digest()) } @@ -140,7 +143,7 @@ fun getApplicationSignature(context: Context, packageName: String): List } else { val sig = context.packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES).signatures signatureList = sig.map { - val digest = MessageDigest.getInstance("SHA") + val digest = MessageDigest.getInstance("SHA-256") digest.update(it.toByteArray()) bytesToHex(digest.digest()) } diff --git a/lib/receive_intent.dart b/lib/receive_intent.dart index 51dd417..c9faffc 100644 --- a/lib/receive_intent.dart +++ b/lib/receive_intent.dart @@ -69,10 +69,11 @@ class ReceiveIntent { .receiveBroadcastStream() .map((event) => ReceivedIntent.fromMap(event as Map?)); - static Future giveResult(int resultCode, {Map? data, bool shouldFinish: false}) async { + static Future giveResult(int resultCode, + {Map? data, bool shouldFinish: false}) async { await _methodChannel.invokeMethod('giveResult', { "resultCode": resultCode, - "data": json.encode(data), + if (data != null) "data": json.encode(data), "shouldFinish": shouldFinish, }); }