WD: picking otp and providing the code to flutter channel

merge-update-with-lab-changes
taha.alam 1 year ago
parent c4de4c1bd9
commit 8509c3d94d

@ -1,51 +1,82 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
package="com.ejada.hmg"> package="com.ejada.hmg">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that <!--
io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method. calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. --> FlutterApplication and put your custom class here.
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" tools:node="remove"/> -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" tools:node="remove"/> <uses-permission
<!-- <uses-permission android:name="android.permission.BLUETOOTH" tools:node="remove"/>--> android:name="android.permission.ACTIVITY_RECOGNITION"
<!-- <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" tools:node="remove"/>--> tools:node="remove" />
<!-- <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" tools:node="remove"/>--> <uses-permission
<!-- <uses-permission android:name="android.permission.BLUETOOTH_SCAN" tools:node="remove"/>--> android:name="android.permission.READ_PHONE_STATE"
<uses-permission android:name="android.permission.BROADCAST_STICKY" tools:node="remove"/> tools:node="remove" /> <!-- <uses-permission android:name="android.permission.BLUETOOTH" tools:node="remove"/> -->
<uses-permission android:name="com.google.android.gms.permission.AD_ID" tools:node="remove"/> <!-- <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" tools:node="remove"/> -->
<!-- <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />--> <!-- <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" tools:node="remove"/> -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" tools:node="remove"/> <!-- <uses-permission android:name="android.permission.BLUETOOTH_SCAN" tools:node="remove"/> -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CONNECTED_DEVICE" tools:node="remove"/> <uses-permission
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_PHONE_CALL" tools:node="remove"/> android:name="android.permission.BROADCAST_STICKY"
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" tools:node="remove"/> tools:node="remove" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" tools:node="remove"/> <uses-permission
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" tools:node="remove"/> android:name="com.google.android.gms.permission.AD_ID"
tools:node="remove" /> <!-- <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> -->
<uses-permission
android:name="android.permission.FOREGROUND_SERVICE"
tools:node="remove" />
<uses-permission
android:name="android.permission.FOREGROUND_SERVICE_CONNECTED_DEVICE"
tools:node="remove" />
<uses-permission
android:name="android.permission.FOREGROUND_SERVICE_PHONE_CALL"
tools:node="remove" />
<uses-permission
android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION"
tools:node="remove" />
<uses-permission
android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK"
tools:node="remove" />
<uses-permission
android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE"
tools:node="remove" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" tools:node="remove" /> <uses-permission
android:name="android.permission.ACCESS_BACKGROUND_LOCATION"
<!-- <uses-permission android:name="android.permission.INTERNET" />--> tools:node="remove" /> <!-- <uses-permission android:name="android.permission.INTERNET" /> -->
<!-- <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />--> <!-- <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" /> <uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" /> <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.HIGH_SAMPLING_RATE_SENSORS" /> <uses-permission android:name="android.permission.HIGH_SAMPLING_RATE_SENSORS" />
<uses-feature android:name="android.hardware.sensor.stepcounter" android:required="false" tools:node="replace"/> <uses-feature
<uses-feature android:name="android.hardware.sensor.stepdetector" android:required="false" tools:node="replace"/> android:name="android.hardware.sensor.stepcounter"
android:required="false"
tools:node="replace" />
<uses-feature
android:name="android.hardware.sensor.stepdetector"
android:required="false"
tools:node="replace" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/> <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/> <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera.autofocus"/>
<uses-feature android:name="android.hardware.camera" android:required="true"/> <uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature
android:name="android.hardware.camera"
android:required="true" />
<uses-permission android:name="android.permission.RECORD_AUDIO" /> <uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
@ -53,111 +84,146 @@
<uses-permission android:name="android.permission.READ_CALENDAR" /> <uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" /> <uses-permission android:name="android.permission.WRITE_CALENDAR" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-feature android:name="android.hardware.location.network" android:required="false" />
<uses-feature android:name="android.hardware.location.gps" android:required="false" />
<uses-permission android:name="com.huawei.appmarket.service.commondata.permission.GET_COMMON_DATA"/>
<!-- <uses-permission android:name="android.permission.HIGH_SAMPLING_RATE_SENSORS" />-->
<uses-feature
android:name="android.hardware.location.network"
android:required="false" />
<uses-feature
android:name="android.hardware.location.gps"
android:required="false" />
<!-- Wifi Permissions--> <uses-permission android:name="com.huawei.appmarket.service.commondata.permission.GET_COMMON_DATA" /> <!-- <uses-permission android:name="android.permission.HIGH_SAMPLING_RATE_SENSORS" /> -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> <!-- Wifi Permissions -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>--> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> <!-- <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/> -->
<!-- Detect Reboot Permission --> <!-- Detect Reboot Permission -->
<!-- <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>--> <!-- <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> -->
<queries> <queries>
<intent> <intent>
<action android:name="android.speech.RecognitionService" /> <action android:name="android.speech.RecognitionService" />
</intent> </intent>
<package android:name="com.whatsapp"/>
<package android:name="com.whatsapp.w4b"/> <package android:name="com.whatsapp" />
<package android:name="com.whatsapp.w4b" />
</queries> </queries>
<application <application
android:name=".Application" android:name=".Application"
android:icon="@mipmap/ic_launcher_local"
android:usesCleartextTraffic="true"
android:showOnLockScreen="true"
android:screenOrientation="sensorPortrait"
android:allowBackup="false" android:allowBackup="false"
android:extractNativeLibs="true" android:extractNativeLibs="true"
tools:replace="android:extractNativeLibs,android:label" android:icon="@mipmap/ic_launcher_local"
android:label="Dr. Alhabib"> android:label="Dr. Alhabib"
android:screenOrientation="sensorPortrait"
android:showOnLockScreen="true"
android:usesCleartextTraffic="true"
tools:replace="android:extractNativeLibs,android:label">
<activity
android:name=".WhatsAppCodeActivity"
android:exported="true"
android:enabled="true"
android:launchMode="standard"
>
<intent-filter>
<action android:name="com.whatsapp.otp.OTP_RETRIEVED" />
</intent-filter>
</activity>
<meta-data
android:name="push_kit_auto_init_enabled"
android:value="true" />
<meta-data android:name="push_kit_auto_init_enabled" android:value="true" />
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:enabled="true"
android:exported="true"
android:hardwareAccelerated="true" android:hardwareAccelerated="true"
android:launchMode="singleTop" android:launchMode="singleTop"
android:showOnLockScreen="true" android:showOnLockScreen="true"
android:theme="@style/LaunchTheme" android:theme="@style/LaunchTheme"
android:exported="true" android:windowSoftInputMode="adjustResize"
android:enabled="true" tools:node="merge">
tools:node="merge"
android:windowSoftInputMode="adjustResize"> <!--
<!-- Specifies an Android theme to apply to this Activity as soon as Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. --> to determine the Window background behind the Flutter UI.
-->
<meta-data <meta-data
android:name="io.flutter.embedding.android.NormalTheme" android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme" /> android:resource="@style/NormalTheme" />
<!-- Displays an Android View that continues showing the launch screen <!--
Displays an Android View that continues showing the launch screen
Drawable until Flutter paints its first frame, then this splash Drawable until Flutter paints its first frame, then this splash
screen fades out. A splash screen is useful to avoid any visual screen fades out. A splash screen is useful to avoid any visual
gap between the end of Android's launch screen and the painting of gap between the end of Android's launch screen and the painting of
Flutter's first frame. --> Flutter's first frame.
-->
<meta-data <meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable" android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background" /> android:resource="@drawable/launch_background" />
<intent-filter>
<action android:name="com.whatsapp.otp.OTP_RETRIEVED" />
</intent-filter>
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
<intent-filter> <intent-filter>
<action android:name="FLUTTER_NOTIFICATION_CLICK" /> <action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
</intent-filter> </intent-filter>
</activity> </activity> <!-- <receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver" android:exported="true"> -->
<!-- <intent-filter> -->
<!-- <action android:name="android.intent.action.BOOT_COMPLETED"/> -->
<!-- <action android:name="android.intent.action.MY_PACKAGE_REPLACED"/> -->
<!-- </intent-filter> -->
<!-- </receiver> -->
<!-- Geofencing -->
<service
android:name=".geofence.intent_receivers.GeofenceTransitionsJobIntentService"
android:exported="true"
android:permission="android.permission.BIND_JOB_SERVICE" />
<!-- <receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver" android:exported="true">--> <receiver
<!-- <intent-filter>--> android:name=".geofence.intent_receivers.GeofenceBroadcastReceiver"
<!-- <action android:name="android.intent.action.BOOT_COMPLETED"/>--> android:enabled="true"
<!-- <action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>--> android:exported="false" />
<!-- </intent-filter>--> <receiver
<!-- </receiver>--> android:name=".geofence.intent_receivers.GeofencingRebootBroadcastReceiver"
android:enabled="true"
<!-- Geofencing --> android:exported="false">
<service android:name=".geofence.intent_receivers.GeofenceTransitionsJobIntentService" android:exported="true" android:permission="android.permission.BIND_JOB_SERVICE" />
<receiver android:name=".geofence.intent_receivers.GeofenceBroadcastReceiver" android:enabled="true" android:exported="false" />
<receiver android:name=".geofence.intent_receivers.GeofencingRebootBroadcastReceiver" android:enabled="true" android:exported="false">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/> <action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.MY_PACKAGE_REPLACED"/> <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
</intent-filter> </intent-filter>
</receiver> </receiver>
<receiver android:name=".geofence.intent_receivers.LocationProviderChangeReceiver" android:exported="false"> <receiver
android:name=".geofence.intent_receivers.LocationProviderChangeReceiver"
android:exported="false">
<intent-filter> <intent-filter>
<action android:name="android.location.PROVIDERS_CHANGED"/> <action android:name="android.location.PROVIDERS_CHANGED" />
</intent-filter> </intent-filter>
</receiver> </receiver>
<service android:name=".geofence.intent_receivers.ReregisterGeofenceJobService" android:exported="true" android:permission="android.permission.BIND_JOB_SERVICE" />
<!-- Geofencing -->
<service
android:name=".geofence.intent_receivers.ReregisterGeofenceJobService"
android:exported="true"
android:permission="android.permission.BIND_JOB_SERVICE" /> <!-- Geofencing -->
<!-- <!--
Huawei Push Notifications Huawei Push Notifications
Set push kit auto enable to true (for obtaining the token on initialize) Set push kit auto enable to true (for obtaining the token on initialize)
--> -->
<!-- <meta-data--> <!-- <meta-data -->
<!-- android:name="push_kit_auto_init_enabled"--> <!-- android:name="push_kit_auto_init_enabled" -->
<!-- android:value="true" />--> <!-- android:value="true" /> -->
<!-- These receivers are for sending scheduled local notifications --> <!-- These receivers are for sending scheduled local notifications -->
<receiver android:name="com.huawei.hms.flutter.push.receiver.local.HmsLocalNotificationBootEventReceiver" android:exported="false"> <receiver
android:name="com.huawei.hms.flutter.push.receiver.local.HmsLocalNotificationBootEventReceiver"
android:exported="false">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter> </intent-filter>
@ -173,26 +239,17 @@
<intent-filter> <intent-filter>
<action android:name="com.huawei.hms.flutter.push.receiver.BACKGROUND_REMOTE_MESSAGE" /> <action android:name="com.huawei.hms.flutter.push.receiver.BACKGROUND_REMOTE_MESSAGE" />
</intent-filter> </intent-filter>
</receiver> </receiver> <!-- Huawei Push Notifications -->
<!-- Huawei Push Notifications --> <meta-data
android:name="com.google.android.geo.API_KEY"
<meta-data android:name="com.google.android.geo.API_KEY" android:value="AIzaSyCyDbWUM9d_sBUGIE8PcuShzPaqO08NSC8" />
android:value="AIzaSyCyDbWUM9d_sBUGIE8PcuShzPaqO08NSC8"/> <!--
Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java
<!-- Don't delete the meta-data below. -->
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data <meta-data
android:name="flutterEmbedding" android:name="flutterEmbedding"
android:value="2" /> android:value="2" />
</application> </application>
<!-- <uses-permission android:name="android.permission.INTERNET" />--> </manifest>
<!-- <uses-permission android:name="android.permission.USE_FINGERPRINT" />-->
<!-- <uses-permission android:name="android.permission.READ_CALENDAR" />-->
<!-- <uses-permission android:name="android.permission.WRITE_CALENDAR" />-->
</manifest>

@ -1,4 +1,5 @@
package com.ejada.hmg package com.ejada.hmg
import android.app.PendingIntent
import android.content.Intent import android.content.Intent
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.os.Build import android.os.Build
@ -7,6 +8,7 @@ import android.view.WindowManager
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi import androidx.annotation.RequiresApi
import com.cloud.diplomaticquarterapp.PenguinInPlatformBridge import com.cloud.diplomaticquarterapp.PenguinInPlatformBridge
import com.cloud.diplomaticquarterapp.whatsapp.AppSignatureRetriever
import com.ejada.hmg.utils.* import com.ejada.hmg.utils.*
import io.flutter.embedding.android.FlutterFragmentActivity import io.flutter.embedding.android.FlutterFragmentActivity
import io.flutter.embedding.engine.FlutterEngine import io.flutter.embedding.engine.FlutterEngine
@ -26,11 +28,8 @@ class MainActivity: FlutterFragmentActivity() {
OpenTokPlatformBridge(flutterEngine, this).create() OpenTokPlatformBridge(flutterEngine, this).create()
PenguinInPlatformBridge(flutterEngine, this).create() PenguinInPlatformBridge(flutterEngine, this).create()
WhatsAppOtpPlatformBridge(flutterEngine, this).invoke() WhatsAppOtpPlatformBridge(flutterEngine, this).invoke()
WhatsApp.handleOTP(intent){code -> AppSignatureRetriever().logSignatures(this)
WhatsAppOtpPlatformBridge.result?.success(code); // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {x
}
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// val mChannel = NotificationChannel("video_call_noti", "video call", NotificationManager.IMPORTANCE_HIGH) // val mChannel = NotificationChannel("video_call_noti", "video call", NotificationManager.IMPORTANCE_HIGH)
// val soundUri = Uri.parse("android.resource://" + getApplicationContext() // val soundUri = Uri.parse("android.resource://" + getApplicationContext()
// .getPackageName() + "/" + R.raw.alert) // .getPackageName() + "/" + R.raw.alert)

@ -0,0 +1,81 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.cloud.diplomaticquarterapp.whatsapp;
import static java.sql.DriverManager.println;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.util.Base64;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Collection;
import java.util.stream.Collectors;
public class AppSignatureRetriever {
private static final String HASH_TYPE = "SHA-256";
public static final int NUM_HASHED_BYTES = 9;
public static final int NUM_BASE64_CHAR = 11;
public void logSignatures(Context context) {
Collection<String> appSignatures = getAppSignatures(context);
appSignatures.forEach(signature -> println("Signature: " + signature));
}
/**
* Get all the app signatures for the current package.
*
* @return signatures for current app
*/
public Collection<String> getAppSignatures(Context context) {
try {
// Get all package signatures for the current package
String packageName = context.getPackageName();
println("Package name: " + packageName);
PackageManager packageManager = context.getPackageManager();
Signature[] signatures = packageManager.getPackageInfo(packageName,
PackageManager.GET_SIGNATURES).signatures;
// For each signature create a compatible hash
Collection<String> appCodes = Arrays.stream(signatures)
.map(signature -> hash(packageName, signature.toCharsString()))
.collect(Collectors.toList());
return appCodes;
} catch (PackageManager.NameNotFoundException e) {
println("Unable to find package to obtain hash.");
throw new RuntimeException("Unable to find package to obtain hash.", e);
}
}
private String hash(String packageName, String signature) {
String appInfo = packageName + " " + signature;
try {
MessageDigest messageDigest = MessageDigest.getInstance(HASH_TYPE);
messageDigest.update(appInfo.getBytes(StandardCharsets.UTF_8));
byte[] hashSignature = messageDigest.digest();
// truncated into NUM_HASHED_BYTES
hashSignature = Arrays.copyOfRange(hashSignature, 0, NUM_HASHED_BYTES);
// encode into Base64
String base64Hash = Base64.encodeToString(hashSignature, Base64.NO_PADDING | Base64.NO_WRAP);
base64Hash = base64Hash.substring(0, NUM_BASE64_CHAR);
println(String.format("pkg: %s -- hash: %s", packageName, base64Hash));
return base64Hash;
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException("Unable to generate hash for application", e);
}
}
}

@ -14,7 +14,11 @@ object WhatsApp {
intent, intent,
// call your function to validate // call your function to validate
{code -> validateOTP(code) }, {code -> validateOTP(code) },
{_,_->}) {error,exception->
println("the error is ${error.name}")
println("the exception stacktrace is ${exception.message}")
println("the exception is cause ${exception.cause}")
})
fun performHandShake(context : WeakReference<Context>) = whatsAppOtpHandler.sendOtpIntentToWhatsApp(context.get()!!) fun performHandShake(context : WeakReference<Context>) = whatsAppOtpHandler.sendOtpIntentToWhatsApp(context.get()!!)

@ -0,0 +1,18 @@
package com.ejada.hmg
import android.app.PendingIntent
import android.content.Intent
import android.os.Bundle
import com.cloud.diplomaticquarterapp.whatsapp.WhatsApp
import com.cloud.diplomaticquarterapp.whatsapp.WhatsAppOtpPlatformBridge
import io.flutter.embedding.android.FlutterFragmentActivity
class WhatsAppCodeActivity : FlutterFragmentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
WhatsApp.handleOTP(intent){code ->
WhatsAppOtpPlatformBridge.result?.success(code);
println("the code is $code")
finish()
}
}
}

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".WhatsAppCodeActivity">
</androidx.constraintlayout.widget.ConstraintLayout>

@ -1,23 +1,23 @@
<resources> <resources>
<string name="app_name">HMG Patient App</string> <string name="app_name">HMG Patient App</string>
<string name="geofence_unknown_error"> <string name="geofence_unknown_error">
Unknown error: the Geofence service is not available now. Unknown error: the Geofence service is not available now.
</string> </string>
<string name="geofence_not_available"> <string name="geofence_not_available">
Geofence service is not available now. Go to Settings>Location>Mode and choose High accuracy. Geofence service is not available now. Go to Settings>Location>Mode and choose High accuracy.
</string> </string>
<string name="geofence_too_many_geofences"> <string name="geofence_too_many_geofences">
Your app has registered too many geofences. Your app has registered too many geofences.
</string> </string>
<string name="geofence_too_many_pending_intents"> <string name="geofence_too_many_pending_intents">
You have provided too many PendingIntents to the addGeofences() call. You have provided too many PendingIntents to the addGeofences() call.
</string> </string>
<string name="GEOFENCE_INSUFFICIENT_LOCATION_PERMISSION"> <string name="GEOFENCE_INSUFFICIENT_LOCATION_PERMISSION">
App do not have permission to access location service. App do not have permission to access location service.
</string> </string>
<string name="GEOFENCE_REQUEST_TOO_FREQUENT"> <string name="GEOFENCE_REQUEST_TOO_FREQUENT">
Geofence requests happened too frequently. Geofence requests happened too frequently.
</string> </string>
<string name="mapbox_access_token" translatable="false">sk.eyJ1IjoicndhaWQiLCJhIjoiY2x6NWo0bTMzMWZodzJrcGZpemYzc3Z4dSJ9.uSSZuwNSGCcCdPAiORECmg</string> <string name="mapbox_access_token" translatable="false">sk.eyJ1IjoicndhaWQiLCJhIjoiY2x6NWo0bTMzMWZodzJrcGZpemYzc3Z4dSJ9.uSSZuwNSGCcCdPAiORECmg</string>
</resources> </resources>

@ -346,10 +346,16 @@ class _ConfirmLogin extends State<ConfirmLogin> {
} }
loginWithSMS(type) async { loginWithSMS(type) async {
// if (type == 4) { if (type == 4) {
// var channel = WhatsappMethodChannel(); var channel = WhatsappMethodChannel();
// await channel.handleHandShake(); // var whatsappStatus = await channel.isWhatsAppInstalled();
// } // if(whatsappStatus) {
// print("whatapp is installed");
channel.handleHandShake();
// }else{
// print("whatapp is not installed");
// }
}
//if (!el.disabled) { //if (!el.disabled) {
if (this.user != null && this.registerd_data == null) { if (this.user != null && this.registerd_data == null) {

@ -24,9 +24,11 @@ class WhatsappMethodChannel {
Future<String> startListening() async { Future<String> startListening() async {
try{ try{
return await _channel.invokeMethod("startListening"); String code = await _channel.invokeMethod("startListening");
print("the code in flutter is ${code}");
return code;
}catch(e){ }catch(e){
return ""; return "";
} }
} }
} }

@ -103,9 +103,10 @@ class SMSOTP {
child: StatefulBuilder(builder: (context, setState) { child: StatefulBuilder(builder: (context, setState) {
if (displayTime == '') { if (displayTime == '') {
startTimer(setState); startTimer(setState);
if (Platform.isAndroid ) {
// startLister(); if (type == 1) checkSignature();
if (Platform.isAndroid && type == 1) checkSignature(); else if(type == 4) _listenWhatsAppCode();
}
} }
return Container( return Container(
@ -297,17 +298,15 @@ class SMSOTP {
SmsVerification.stopListening(); SmsVerification.stopListening();
// }); // });
}); });
}
void _listenWhatsAppCode(){
WhatsappMethodChannel().startListening().then((message) { WhatsappMethodChannel().startListening().then((message) {
// setState(() {
final intRegex = RegExp(r'\d+', multiLine: true); final intRegex = RegExp(r'\d+', multiLine: true);
var otp = SmsVerification.getCode(message, intRegex); var otp = SmsVerification.getCode(message, intRegex);
_pinPutController.text = otp; _pinPutController.text = otp;
onSuccess(otp); onSuccess(otp);
SmsVerification.stopListening();
// });
}); });
} }
// startLister() { // startLister() {

Loading…
Cancel
Save