From 6756d023351db4c1ad79b5ee425f549d88b6f850 Mon Sep 17 00:00:00 2001 From: Jarrad Hope Date: Wed, 8 Jun 2016 12:43:02 +0200 Subject: [PATCH 1/2] warn user if root before starting geth Former-commit-id: 1f0a4214b814da17d596f368c962c30152843327 --- .../main/java/com/statusim/MainActivity.java | 44 +++++++++++++++++-- .../src/main/java/com/statusim/RootUtil.java | 41 +++++++++++++++++ android/app/src/main/res/values/strings.xml | 7 ++- 3 files changed, 86 insertions(+), 6 deletions(-) create mode 100644 android/app/src/main/java/com/statusim/RootUtil.java diff --git a/android/app/src/main/java/com/statusim/MainActivity.java b/android/app/src/main/java/com/statusim/MainActivity.java index 3d411d9213..eeb1c628e8 100644 --- a/android/app/src/main/java/com/statusim/MainActivity.java +++ b/android/app/src/main/java/com/statusim/MainActivity.java @@ -8,6 +8,10 @@ import com.facebook.react.shell.MainReactPackage; import com.rt2zz.reactnativecontacts.ReactNativeContacts; import android.os.Bundle; import android.os.Environment; +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.content.DialogInterface.OnClickListener; +import android.content.DialogInterface.OnCancelListener; import com.github.ethereum.go_ethereum.cmd.Geth; import com.bitgo.randombytes.RandomBytesPackage; import com.BV.LinearGradient.LinearGradientPackage; @@ -18,20 +22,20 @@ import java.util.List; import java.util.Properties; import java.io.File; + import com.i18n.reactnativei18n.ReactNativeI18n; import io.realm.react.RealmReactPackage; + public class MainActivity extends ReactActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); + protected void startStatus() { // Required for android-16 (???) System.loadLibrary("gethraw"); System.loadLibrary("geth"); - // Required because of crazy APN settings redirecting localhost + // Required because of crazy APN settings redirecting localhost (found in GB) Properties properties = System.getProperties(); properties.setProperty("http.nonProxyHosts", "localhost|127.0.0.1"); properties.setProperty("https.nonProxyHosts", "localhost|127.0.0.1"); @@ -50,6 +54,38 @@ public class MainActivity extends ReactActivity { }).start(); } + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + if(!RootUtil.isDeviceRooted()) { + startStatus(); + } else { + AlertDialog dialog = new AlertDialog.Builder(MainActivity.this).setMessage(getResources().getString(R.string.root_warning)) + .setPositiveButton(getResources().getString(R.string.root_okay), new OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + startStatus(); + } + }).setNegativeButton(getResources().getString(R.string.root_cancel), new OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + MainActivity.this.finishAffinity(); + } + }).setOnCancelListener(new OnCancelListener() { + @Override + public void onCancel(DialogInterface dialog) { + dialog.dismiss(); + MainActivity.this.finishAffinity(); + } + }).create(); + dialog.show(); + } + + } + /** * Returns the name of the main component registered from JavaScript. * This is used to schedule rendering of the component. diff --git a/android/app/src/main/java/com/statusim/RootUtil.java b/android/app/src/main/java/com/statusim/RootUtil.java new file mode 100644 index 0000000000..c5b9e88df0 --- /dev/null +++ b/android/app/src/main/java/com/statusim/RootUtil.java @@ -0,0 +1,41 @@ +package com.statusim; + +import java.io.File; +import java.io.BufferedReader; +import java.io.InputStreamReader; + +/** @author Kevin Kowalewski */ +public class RootUtil { + + public static boolean isDeviceRooted() { + return checkRootMethod1() || checkRootMethod2() || checkRootMethod3(); + } + + private static boolean checkRootMethod1() { + String buildTags = android.os.Build.TAGS; + return buildTags != null && buildTags.contains("test-keys"); + } + + private static boolean checkRootMethod2() { + String[] paths = { "/system/app/Superuser.apk", "/sbin/su", "/system/bin/su", "/system/xbin/su", "/data/local/xbin/su", "/data/local/bin/su", "/system/sd/xbin/su", + "/system/bin/failsafe/su", "/data/local/su" }; + for (String path : paths) { + if (new File(path).exists()) return true; + } + return false; + } + + private static boolean checkRootMethod3() { + Process process = null; + try { + process = Runtime.getRuntime().exec(new String[] { "/system/xbin/which", "su" }); + BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream())); + if (in.readLine() != null) return true; + return false; + } catch (Throwable t) { + return false; + } finally { + if (process != null) process.destroy(); + } + } +} diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml index fb87cafc71..714ecb8518 100644 --- a/android/app/src/main/res/values/strings.xml +++ b/android/app/src/main/res/values/strings.xml @@ -1,3 +1,6 @@ - StatusIm - + Status + Your phone appears to be ROOTED, this is a serious security concern, continue only if you understand and accept the risks. + Continue + Exit + \ No newline at end of file From 4b43096ba8eab77be3186fb808b6adfe7d97c19b Mon Sep 17 00:00:00 2001 From: Jarrad Hope Date: Wed, 8 Jun 2016 15:29:48 +0200 Subject: [PATCH 2/2] System.loadLibrary voodoo magic Former-commit-id: 97ff59f95bcdd80a57833263c5a8191223683be6 --- .re-natal | 2 +- android/app/src/main/java/com/statusim/MainActivity.java | 9 +++++---- env/dev/env/android/main.cljs | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.re-natal b/.re-natal index 1455b14c43..b4f25ba62a 100644 --- a/.re-natal +++ b/.re-natal @@ -1,7 +1,7 @@ { "name": "StatusIm", "interface": "reagent", - "androidHost": "localhost", + "androidHost": "10.0.3.2", "modules": [ "react-native-contacts", "react-native-invertible-scroll-view", diff --git a/android/app/src/main/java/com/statusim/MainActivity.java b/android/app/src/main/java/com/statusim/MainActivity.java index 1a7986b3c0..7d14e08627 100644 --- a/android/app/src/main/java/com/statusim/MainActivity.java +++ b/android/app/src/main/java/com/statusim/MainActivity.java @@ -35,10 +35,6 @@ public class MainActivity extends ReactActivity { final Handler handler = new Handler(); protected void startStatus() { - // Required for android-16 (???) - System.loadLibrary("gethraw"); - System.loadLibrary("geth"); - // Required because of crazy APN settings redirecting localhost (found in GB) Properties properties = System.getProperties(); properties.setProperty("http.nonProxyHosts", "localhost|127.0.0.1"); @@ -70,6 +66,11 @@ public class MainActivity extends ReactActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + // Required for android-16 (???) + // Crash if put in startStatus() ? + System.loadLibrary("gethraw"); + System.loadLibrary("geth"); + if(!RootUtil.isDeviceRooted()) { startStatus(); } else { diff --git a/env/dev/env/android/main.cljs b/env/dev/env/android/main.cljs index 1bf474e505..f0c3d96fca 100644 --- a/env/dev/env/android/main.cljs +++ b/env/dev/env/android/main.cljs @@ -10,7 +10,7 @@ (def root-el (r/as-element [reloader])) (figwheel/watch-and-reload - :websocket-url "ws://localhost:3449/figwheel-ws" + :websocket-url "ws://10.0.3.2:3449/figwheel-ws" :heads-up-display false :jsload-callback #(swap! cnt inc))