anish-adm / trust_fall

A Flutter plugin for detecting the trust fall of the device(Jailbroken, root, emulator and mock location detection).
https://pub.dartlang.org/packages/trust_fall
MIT License
37 stars 43 forks source link

java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread #4

Open zeexan-dev opened 4 years ago

zeexan-dev commented 4 years ago

java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread

Future checkMockLocation() async { print("check mocklocation "); bool canMockLocation = await TrustFall.canMockLocation; print("mocklocation = "+ canMockLocation.toString()); }

anish-adm commented 4 years ago

@engr-zeeshan, Could you post output for flutter doctor please

zeexan-dev commented 4 years ago

@anish-adm [√] Flutter (Channel stable, v1.7.8+hotfix.3, on Microsoft Windows [Version 10.0.18362.267], locale en-PK)

[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3) [√] Android Studio (version 3.4) [√] VS Code (version 1.36.1) [!] Connected device

mateusschmidt commented 4 years ago

Same problem :/

E/TSLocationManager(22678): java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: Timer-1 E/TSLocationManager(22678): at io.flutter.embedding.engine.FlutterJNI.ensureRunningOnMainThread(FlutterJNI.java:807) E/TSLocationManager(22678): at io.flutter.embedding.engine.FlutterJNI.invokePlatformMessageResponseCallback(FlutterJNI.java:740) E/TSLocationManager(22678): at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:156) E/TSLocationManager(22678): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success(MethodChannel.java:225) E/TSLocationManager(22678): at com.anish.trust_fall.TrustFallPlugin$1.gotLocation(TrustFallPlugin.java:43) E/TSLocationManager(22678): at com.anish.trust_fall.MockLocation.MockLocationCheck$GetLastLocation.run(MockLocationCheck.java:90) E/TSLocationManager(22678): at java.util.TimerThread.mainLoop(Timer.java:562) E/TSLocationManager(22678): at java.util.TimerThread.run(Timer.java:512)

bagus-setyawan commented 4 years ago

Same problem here, anyone get this resolve ?

Edited: I found another alternative to detect just mock Location (another detection are working), with the same way this plugin do, install Geolocator flutter plugin then use this code :


Future<bool> checkMockLocation() async {
    Position position = await Geolocator().getLastKnownPosition();
    return position.mocked;
  }
alifgiant commented 4 years ago

@bagus-setyawan thanks a lot mate, this bug give me a headache. Your code can bypass the bug

shinsenter commented 4 years ago

Same issue

E/AndroidRuntime( 6244): java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: Timer-1
E/AndroidRuntime( 6244):        at io.flutter.embedding.engine.FlutterJNI.ensureRunningOnMainThread(FlutterJNI.java:781)
E/AndroidRuntime( 6244):        at io.flutter.embedding.engine.FlutterJNI.invokePlatformMessageResponseCallback(FlutterJNI.java:718)
E/AndroidRuntime( 6244):        at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:144)
E/AndroidRuntime( 6244):        at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success(MethodChannel.java:231)
E/AndroidRuntime( 6244):        at com.anish.trust_fall.TrustFallPlugin$1.gotLocation(TrustFallPlugin.java:43)
E/AndroidRuntime( 6244):        at com.anish.trust_fall.MockLocation.MockLocationCheck$GetLastLocation.run(MockLocationCheck.java:88)
E/AndroidRuntime( 6244):        at java.util.TimerThread.processTask(Timer.java:577)
E/AndroidRuntime( 6244):        at java.util.TimerThread.mainLoop(Timer.java:532)
E/AndroidRuntime( 6244):        at java.util.TimerThread.run(Timer.java:512)
I/Process ( 6244): Sending signal. PID: 6244 SIG: 9
Lzyct commented 3 years ago

@anish-adm could you check this Similiar issue, ?

i think this code make error

class GetLastLocation extends TimerTask {
        @Override
        public void run() {
            lm.removeUpdates(locationListenerGps);
            lm.removeUpdates(locationListenerNetwork);
            Location net_loc=null, gps_loc=null;
            if(gps_enabled)
                gps_loc=lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
            if(network_enabled)
                net_loc=lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
            //if there are both values use the latest one
            if(gps_loc!=null && net_loc!=null){
                if(gps_loc.getTime()>net_loc.getTime())
                    locationResult.gotLocation(gps_loc);
                else
                    locationResult.gotLocation(net_loc);
                return;
            }

            if(gps_loc!=null){
                locationResult.gotLocation(gps_loc);
                return;
            }
            if(net_loc!=null){
                locationResult.gotLocation(net_loc);
                return;
            }
            locationResult.gotLocation(null);
        }
    }
iampopal commented 3 years ago

I am also getting this error
Methods marked with @UiThread must be executed on the main thread. Current thread: Timer-0

when calling bool canMockLocation = await TrustFall.canMockLocation;

shinsenter commented 3 years ago

Still crashed with the latest Flutter version:

2020-09-07 16:35:51.858 19394-19683/com.mycompany.testapp E/AndroidRuntime: FATAL EXCEPTION: Timer-0
    Process: com.mycompany.testapp, PID: 19394
    java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: Timer-0
        at io.flutter.embedding.engine.FlutterJNI.ensureRunningOnMainThread(FlutterJNI.java:992)
        at io.flutter.embedding.engine.FlutterJNI.invokePlatformMessageResponseCallback(FlutterJNI.java:779)
        at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:144)
        at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success(MethodChannel.java:235)
        at com.anish.trust_fall.TrustFallPlugin$1.gotLocation(TrustFallPlugin.java:43)
        at com.anish.trust_fall.MockLocation.MockLocationCheck$GetLastLocation.run(MockLocationCheck.java:88)
        at java.util.TimerThread.processTask(Timer.java:577)
        at java.util.TimerThread.mainLoop(Timer.java:532)
        at java.util.TimerThread.run(Timer.java:512)
2020-09-07 16:35:52.020 19394-19505/com.mycompany.testapp D/FA: Event not sent since app measurement is disabled
2020-09-07 16:35:52.069 19394-19683/com.mycompany.testapp I/Process: Sending signal. PID: 19394 SIG: 9
sunnykinger commented 3 years ago

Same problem here, anyone get this resolve ?

Edited: I found another alternative to detect just mock Location (another detection are working), with the same way this plugin do, install Geolocator flutter plugin then use this code :

Future<bool> checkMockLocation() async {
    Position position = await Geolocator().getLastKnownPosition();
    return position.mocked;
  }

I think its now updated

Future<bool> checkMockLocation() async {
Position position = await Geolocator.getLastKnownPosition();
return position.isMocked;
}
sunnykinger commented 3 years ago

Same problem here, anyone get this resolve ?

Edited: I found another alternative to detect just mock Location (another detection are working), with the same way this plugin do, install Geolocator flutter plugin then use this code :

Future<bool> checkMockLocation() async {
    Position position = await Geolocator().getLastKnownPosition();
    return position.mocked;
  }

try to execute this code after turning off and turning on location. It gives some kind of Exception.

ghost commented 3 years ago

Is there any update on solving this error. I am also facing the same issue. I am on the latest build of TrustFall and flutter.

wisnuwiry commented 3 years ago

Same problem here, after building App in release mode.

bagus-setyawan commented 3 years ago

@sunnykinger , @rp014947 , @wisnuwiry guys just use location plugin your own choice and make sure if permission permitted and get mocked properties from that, if you look into this project code you will notice that this is same way. Or you can make a fork and resolved the issue.

But once again users can pass this checker with many ways (rooted phone etc) so add another validations if your app consent is about real user's location.

thanhit93 commented 2 years ago

Fix running on @UiThread : @Override public void onMethodCall(MethodCall call, @NonNull final Result result) { if (call.method.equals("getPlatformVersion")) { result.success("Android " + android.os.Build.VERSION.RELEASE); } else if (call.method.equals("isJailBroken")) { result.success(RootedCheck.isJailBroken(applicationContext)); } else if (call.method.equals("canMockLocation")) { MockLocationCheck.LocationResult locationResult = new MockLocationCheck.LocationResult(){ @Override public void gotLocation(final Location location){ android.os.Handler handler = new android.os.Handler(Looper.getMainLooper()); handler.post(new Runnable() { @Override public void run() { //Got the location! if(location != null){ result.success(location.isFromMockProvider()); }else { result.success(false); } } }); } }; MockLocationCheck mockLocationCheck = new MockLocationCheck(); mockLocationCheck.getLocation(applicationContext, locationResult); }else if (call.method.equals("isRealDevice")) { result.success(!EmulatorCheck.isEmulator()); }else if (call.method.equals("isOnExternalStorage")) { result.success(ExternalStorageCheck.isOnExternalStorage(applicationContext)); } else { result.notImplemented(); } }

Checking my github: https://github.com/thanhit93/trust_fall/commit/8a24ca53806124e223b5e3360e3cc280bccfea78