androidfluttersamsung-mobile

Flutter build fails in Samsung phone , Permission Denial: broadcast from android asks to run as user -1 but is calling from user 0


Trying to build a previously working app on Samsung Note 8 phone , This is the error Permission Denial: broadcast from android asks to run as user -1 but is calling from user 0

Now I understand INTERACT_ACROSS_USERS_FULL permissions are required by only system apps accessing system functionalities . This app of mine was working properly before , upgraded flutter and dart versions , also upgraded the Mobile OS .

Even added these permissions in all manifest files , still not working ,

<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS"/>
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL"/>

Tried this SO also , even worked once by tweaking the developer options on phone as I put an answer here tweaking developer options but now that also is not working .

This is my flutter doctor out ,

[✓] Flutter (Channel master, 2.6.0-1.0.pre.153, on macOS 11.5.1 20G80 darwin-x64, locale en-IN)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 12.4)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[✓] Connected device (2 available)

And the Full error is like this ,

D/vndksupport( 5675): Loading /vendor/lib64/hw/android.hardware.graphics.mapper@2.0-impl.so from current namespace instead of sphal namespace.
E/flutter ( 5675): [ERROR:flutter/fml/platform/android/jni_util.cc(182)] java.lang.SecurityException: Permission Denial: broadcast from android asks to run as user -1 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL or android.permission.INTERACT_ACROSS_USERS
E/flutter ( 5675):  at android.os.Parcel.createException(Parcel.java:1966)
E/flutter ( 5675):  at android.os.Parcel.readException(Parcel.java:1934)
E/flutter ( 5675):  at android.os.Parcel.readException(Parcel.java:1884)
E/flutter ( 5675):  at android.app.IActivityManager$Stub$Proxy.reportActivityFullyDrawn(IActivityManager.java:7312)
E/flutter ( 5675):  at android.app.Activity.reportFullyDrawn(Activity.java:2092)
E/flutter ( 5675):  at io.flutter.embedding.android.FlutterActivity.onFlutterUiDisplayed(FlutterActivity.java:1100)
E/flutter ( 5675):  at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate$1.onFlutterUiDisplayed(FlutterActivityAndFragmentDelegate.java:88)
E/flutter ( 5675):  at io.flutter.embedding.android.FlutterView$2.onFlutterUiDisplayed(FlutterView.java:133)
E/flutter ( 5675):  at io.flutter.embedding.engine.FlutterJNI.onFirstFrame(FlutterJNI.java:462)
E/flutter ( 5675):  at android.os.MessageQueue.nativePollOnce(Native Method)
E/flutter ( 5675):  at android.os.MessageQueue.next(MessageQueue.java:326)
E/flutter ( 5675):  at android.os.Looper.loop(Looper.java:181)
E/flutter ( 5675):  at android.app.ActivityThread.main(ActivityThread.java:7073)
E/flutter ( 5675):  at java.lang.reflect.Method.invoke(Native Method)
E/flutter ( 5675):  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
E/flutter ( 5675):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
E/flutter ( 5675): Caused by: android.os.RemoteException: Remote stack trace:
E/flutter ( 5675):  at com.android.server.am.UserController.handleIncomingUser(UserController.java:1818)
E/flutter ( 5675):  at com.android.server.am.ActivityManagerService.broadcastIntentLocked(ActivityManagerService.java:25789)
E/flutter ( 5675):  at com.android.server.am.ActivityManagerService.broadcastIntentLocked(ActivityManagerService.java:25720)
E/flutter ( 5675):  at com.android.server.am.ActivityManagerService.broadcastIntent(ActivityManagerService.java:26590)
E/flutter ( 5675):  at android.app.ContextImpl.sendBroadcastAsUser(ContextImpl.java:1264)
E/flutter ( 5675): 
E/flutter ( 5675): 
F/flutter ( 5675): [FATAL:flutter/shell/platform/android/platform_view_android_jni_impl.cc(1220)] Check failed: fml::jni::CheckException(env). 
F/libc    ( 5675): Fatal signal 6 (SIGABRT), code -6 (SI_TKILL) in tid 5675 (bro.neighbroapp), pid 5675 (bro.neighbroapp)

Solution

  • This is an issue with latest Flutter version , I fixed it with the below eidt ,

    This is a workaround and it works for me .

    1. go to MainActivity.kt
    2. Import import android.os.Build
    3. Paste this
        override fun onFlutterUiDisplayed() {
            if (Build.VERSION.SDK_INT >= 100) { //I gave 100 just to confirm , it shoud be android ver 10
                reportFullyDrawn();
            }
        }
    
    1. flutter clean
    2. flutter run