App Crashes on Android ~6

i run fuse version 0.36.1 on Windows 7

  • when i try to build my project it build successfully with no warnings or errors
  • when i test the app on multiple android version starting from 4~(Kitkat) to 5~ (lollipop) and it works with no problems.
  • when i test on Android 6~ (Marshmallow) the app crashes and stops working and this occurred on multiple devices that run Android Marshmallow

you can download and test the app from https://drive.google.com/file/d/0Bx5g2OVAtg0zVWFVeGRNTjZLbFE/view?usp=sharing

Hi Mohammed,

a compiled APK will in no way help us debug what might be the cause for the crashes you’re reporting. Please upload the project source code to this location, which can only be accessed by Fuse team members: https://www.dropbox.com/request/ZgndLtJQm5eGzG9cicGK

We will then take it from there and see if we can find something.

Hi Uldis

I’ve uploaded my project to dropbox using the link you provided.

please run npm install to install libraries needed by the app

Thanks for helping me.

Thanks,

we’ll get back to you once we find something, or if we have further questions.

Mohammed,

to help us nail it down more quickly, are there any pointers to what should we be looking for?

Is there a particular thing that one needs to do in the app to make it crash (e.g. open a specific screen)? Does it crash immediately? Do you have to wait for it to crash?

Have you tried running fuse preview -tandroid targeting the device you know it crashes on, and do you know if the preview crashes too? And if it does, are there any errors thrown?

unfortunately and *for now i don’t have direct access to Android 6.0 mobile to run fuse preview -tandroid on that mobile, However i got reports provided with screenshots from clients and friends that app is crashes on their devices which all share same android version.

The app stops directly after opening, basically it never reach the login screen it always stops on the Splash screen and you don’t have to wait or to do any thing , the app just steps directly after launching.

Update:
i’ve just bought Samsung galaxy J5 device that runs 6.0.1 to do some testing after finishing with the setup i’ll provide with more details

thanks in advance

i think i know the problem now

the app crash because of the community package https://github.com/MaxGraey/fuse-device and the error reported in the monitor is

ERROR: java.lang.SecurityException: getDeviceId: Neither user 10166 nor current process has android.permission.READ_PHONE_STATE.
    Uno.Exception occured.
       at Android.Base.JNI.TryGetException(Android.Base.Primitives.JNIEnvPtr,[string])
       at Android.Base.JNI.CheckException(Android.Base.Primitives.JNIEnvPtr,[string])
       at Android.Base.JNI.CheckException(Android.Base.Primitives.JNIEnvPtr)
       at Device.UUID()
       at Fuse.Scripting.NativeProperty`2.GetProperty(object[])
       at Fuse.Scripting.V8.Marshaller.CallbackWrapper.Call(Fuse.Scripting.V8.Simple.JSValue[],Fuse.Scripting.V8.Simple.JSValue&)
       at Fuse.Scripting.V8.V8SimpleExtensions.Call(Fuse.Scripting.V8.Simple.JSFunction,Fuse.Scripting.V8.Simple.JSContext,Fuse.Scripting.V8.Simple.JSObject,Fuse.Scripting.V8.Simple.JSValue[],Fuse.Scripting.V8.AutoReleasePool,Uno.Action<Fuse.Scripting.V8.Simple.JSScriptException>)
       at Fuse.Scripting.V8.Object.CallMethod(string,object[])
       at Fuse.Scripting.NativeEventEmitterModule.EmitClosure.Emit(Fuse.Scripting.Context,Fuse.Scripting.Object)
       at Uno.Threading.IDispatcherExtensions.Arg2Invoke`2.Run()
       at Fuse.Reactive.ThreadWorker.RunInner()
       at Fuse.Reactive.ThreadWorker.Run()

but when i examined the code i found that the developer requested the permissions before the foreign code

// UUID platform specific implementations
    [Foreign(Language.Java)]
    
    [Require("AndroidManifest.RootElement", "<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>")]
    [Require("AndroidManifest.RootElement", "<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>")]
    [Require("AndroidManifest.RootElement", "<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>")]
    private static extern(Android) string GetUUID()
    @{
        final android.app.Activity context = com.fuse.Activity.getRootActivity();
        final TelephonyManager tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
        final String deviceId     = "" + tm.getDeviceId();
        final String serialNum    = "" + tm.getSimSerialNumber();
        final String androidId    = "" + android.provider.Settings.Secure.getString(
                                            context.getContentResolver(),
                                            android.provider.Settings.Secure.ANDROID_ID
                                         );

        int macAdressId;

        try {
            // try to get MAC-address via NetworkInterface
            final InetAddress ip = InetAddress.getLocalHost();
            final NetworkInterface network = NetworkInterface.getByInetAddress(ip);
            macAdressId = network.getHardwareAddress().hashCode();
        } catch (Throwable e) {
            // else get MAC-address via WifiManager
            final WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
            final boolean     wifiEnabled = wifiManager.isWifiEnabled();

            if (!wifiEnabled)
                wifiManager.setWifiEnabled(true);

            macAdressId = wifiManager.getConnectionInfo().getMacAddress().hashCode();

            if (!wifiEnabled)
                wifiManager.setWifiEnabled(false);
        }

        byte[] bytes = ByteBuffer.allocate(16)
                       .putInt(androidId.hashCode())
                       .putInt(macAdressId)
                       .putInt(serialNum.hashCode())
                       .putInt(deviceId.hashCode())
                       .array();

        return UUID.nameUUIDFromBytes(bytes).toString().toUpperCase();
    @}

After some research o ended up here

This release introduces a new permissions model, where users can now directly manage app permissions at runtime. This model gives users improved visibility and control over permissions, while streamlining the installation and auto-update processes for app developers. Users can grant or revoke permissions individually for installed apps.

On your apps that target Android 6.0 (API level 23) or higher, make sure to check for and request permissions at runtime. To determine if your app has been granted a permission, call the new checkSelfPermission() method. To request a permission, call the new requestPermissions() method. Even if your app is not targeting Android 6.0 (API level 23), you should test your app under the new permissions model.

For details on supporting the new permissions model in your app, see Working with System Permissionss. For tips on how to assess the impact on your app, see Permissions Best Practices.

You could give it a try and implement the right permissions request model by following a similar approach taken here: https://github.com/bolav/fuse-contacts/blob/master/ContactsImpl.Android.uno#L147

I can’t confirm or deny if that is the root cause of the crashes before it’s tested.

i think what you provided is helpful but i’m not quite familiar with Uno :\

Learning Uno will be no problem,However i’m still waiting for more information about this if you will provide more.

i’ll go further with this and try to implement this like the contacts plugin then i’ll brief you with more details

Thanks for helping

So the problem is, specifically, with this line, which requires the run-time permissions to be requested:

final String deviceId     = "" + tm.getDeviceId();

If you don’t need it, or you can find another way, until this is fixed your best bet is to not call GetUUID()

I logged an issue on the fuse-device repository, you can follow its status there: https://github.com/MaxGraey/fuse-device/issues/3

Until you can confirm or deny that this was the cause for the crashes, I’m considering this to-be-solved.

Sorry for responding late but i had urgant things to do

thanks for your help and i managed to solve the issue

Mohammed,

did you fix the fuse-device package code? If so, I would like to ask you to submit a pull request against that repository so it’s fixed for everyone.

Thanks!

No actually i didn’t had enough time to try to fix it, finally i used a SECURITY_ID in android which can be used without asking for permissions. but in general i’m planning to submit a fix for the package soon, maybe after two days from now.

Thanks for asking

I’ll get back to you here when the fix is done.

Thanks Mohammed!

This problem has now been fixed in a particular way in this pull request.