Change for android package name based on app type

M committed Jan 5, 2022 at 17:11 UTC e756490c31fc899d457babd53a00a589073f1793
5 files changed +101 -2
android/app/build.gradle
+2 -1
@@ -44,7 +44,8 @@ android {
44 versionCode flutterVersionCode.toInteger()
45 versionName flutterVersionName
46 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
47 - manifestPlaceholders = [APP_NAME: System.getenv('APP_ANDROID_NAME')]
47 + manifestPlaceholders = [APP_NAME: System.getenv('APP_ANDROID_NAME'),
48 + APP_PACKAGE: System.getenv('APP_ANDROID_PACKAGE')]
49
50 externalNativeBuild {
51 cmake {
android/app/src/main/AndroidManifest.xml
+1 -1
@@ -1,5 +1,5 @@
1 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2 - package="com.cakewallet.cake_wallet">
2 + package="${APP_PACKAGE}">
3
4 <uses-permission android:name="android.permission.INTERNET"/>
5 <uses-permission android:name="android.permission.USE_FINGERPRINT"/>
android/app/src/main/java/com/monero/app/Application.java new
+11
@@ -0,0 +1,11 @@
1 +package com.monero.app;
2 +
3 +import io.flutter.app.FlutterApplication;
4 +import io.flutter.plugin.common.PluginRegistry;
5 +import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback;
6 +import io.flutter.plugins.GeneratedPluginRegistrant;
7 +
8 +public class Application extends FlutterApplication implements PluginRegistrantCallback {
9 + @Override
10 + public void registerWith(PluginRegistry registry) {}
11 +}
\ No newline at end of file
android/app/src/main/java/com/monero/app/MainActivity.java new
+81
@@ -0,0 +1,81 @@
1 +package com.monero.app;
2 +
3 +import androidx.annotation.NonNull;
4 +
5 +import io.flutter.embedding.android.FlutterFragmentActivity;
6 +import io.flutter.embedding.engine.FlutterEngine;
7 +import io.flutter.plugins.GeneratedPluginRegistrant;
8 +
9 +import io.flutter.plugin.common.MethodCall;
10 +import io.flutter.plugin.common.MethodChannel;
11 +
12 +import android.os.AsyncTask;
13 +import android.os.Build;
14 +import android.os.Handler;
15 +import android.os.Looper;
16 +
17 +import com.unstoppabledomains.resolution.DomainResolution;
18 +import com.unstoppabledomains.resolution.Resolution;
19 +
20 +import java.security.SecureRandom;
21 +
22 +public class MainActivity extends FlutterFragmentActivity {
23 + final String UTILS_CHANNEL = "com.cake_wallet/native_utils";
24 + final int UNSTOPPABLE_DOMAIN_MIN_VERSION_SDK = 24;
25 +
26 + @Override
27 + public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
28 + GeneratedPluginRegistrant.registerWith(flutterEngine);
29 +
30 + MethodChannel utilsChannel =
31 + new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(),
32 + UTILS_CHANNEL);
33 +
34 + utilsChannel.setMethodCallHandler(this::handle);
35 + }
36 +
37 + private void handle(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
38 + Handler handler = new Handler(Looper.getMainLooper());
39 +
40 + try {
41 + switch (call.method) {
42 + case "sec_random":
43 + int count = call.argument("count");
44 + SecureRandom random = new SecureRandom();
45 + byte bytes[] = new byte[count];
46 + random.nextBytes(bytes);
47 + handler.post(() -> result.success(bytes));
48 + break;
49 + case "getUnstoppableDomainAddress":
50 + int version = Build.VERSION.SDK_INT;
51 + if (version >= UNSTOPPABLE_DOMAIN_MIN_VERSION_SDK) {
52 + getUnstoppableDomainAddress(call, result);
53 + } else {
54 + handler.post(() -> result.success(""));
55 + }
56 + break;
57 + default:
58 + handler.post(() -> result.notImplemented());
59 + }
60 + } catch (Exception e) {
61 + handler.post(() -> result.error("UNCAUGHT_ERROR", e.getMessage(), null));
62 + }
63 + }
64 +
65 + private void getUnstoppableDomainAddress(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
66 + DomainResolution resolution = new Resolution();
67 + Handler handler = new Handler(Looper.getMainLooper());
68 + String domain = call.argument("domain");
69 + String ticker = call.argument("ticker");
70 +
71 + AsyncTask.execute(() -> {
72 + try {
73 + String address = resolution.getAddress(domain, ticker);
74 + handler.post(() -> result.success(address));
75 + } catch (Exception e) {
76 + System.out.println("Expected Address, but got " + e.getMessage());
77 + handler.post(() -> result.success(""));
78 + }
79 + });
80 + }
81 +}
\ No newline at end of file
scripts/android/app_env.sh
+6
@@ -4,6 +4,7 @@ APP_ANDROID_NAME=""
4 APP_ANDROID_VERSION=""
5 APP_ANDROID_BUILD_VERSION=""
6 APP_ANDROID_ID=""
7 +APP_ANDROID_PACKAGE=""
8
9 MONERO_COM="monero.com"
10 CAKEWALLET="cakewallet"
@@ -15,11 +16,13 @@ MONERO_COM_NAME="Monero.com"
16 MONERO_COM_VERSION="1.0.0"
17 MONERO_COM_BUILD_NUMBER=6
18 MONERO_COM_BUNDLE_ID="com.cakewallet.monero"
19 +MONERO_COM_PACKAGE="com.monero.app"
20
21 CAKEWALLET_NAME="Cake Wallet"
22 CAKEWALLET_VERSION="4.2.8"
23 CAKEWALLET_BUILD_NUMBER=69
24 CAKEWALLET_BUNDLE_ID="com.fotolockr.cakewallet"
25 +CAKEWALLET_PACKAGE="com.cakewallet.cake_wallet"
26
27 if ! [[ " ${TYPES[*]} " =~ " ${APP_ANDROID_TYPE} " ]]; then
28 echo "Wrong app type."
@@ -32,12 +35,14 @@ case $APP_ANDROID_TYPE in
35 APP_ANDROID_VERSION=$MONERO_COM_VERSION
36 APP_ANDROID_BUILD_NUMBER=$MONERO_COM_BUILD_NUMBER
37 APP_ANDROID_BUNDLE_ID=$MONERO_COM_BUNDLE_ID
38 + APP_ANDROID_PACKAGE=$MONERO_COM_PACKAGE
39 ;;
40 $CAKEWALLET)
41 APP_ANDROID_NAME=$CAKEWALLET_NAME
42 APP_ANDROID_VERSION=$CAKEWALLET_VERSION
43 APP_ANDROID_BUILD_NUMBER=$CAKEWALLET_BUILD_NUMBER
44 APP_ANDROID_BUNDLE_ID=$CAKEWALLET_BUNDLE_ID
45 + APP_ANDROID_PACKAGE=$CAKEWALLET_PACKAGE
46 ;;
47 esac
48
@@ -46,3 +51,4 @@ export APP_ANDROID_NAME
51 export APP_ANDROID_VERSION
52 export APP_ANDROID_BUILD_NUMBER
53 export APP_ANDROID_BUNDLE_ID
54 +export APP_ANDROID_PACKAGE
\ No newline at end of file