Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android InstantApp cannot create Realm instance #500

Open
pmpuro opened this issue Oct 12, 2021 · 7 comments
Open

Android InstantApp cannot create Realm instance #500

pmpuro opened this issue Oct 12, 2021 · 7 comments

Comments

@pmpuro
Copy link

pmpuro commented Oct 12, 2021

The constructor of Realm fails with the following exception:

2021-10-12 13:12:07.981 676-676/? E/audit: type=1400 audit(1634033527.971:7153): avc:  denied  { create } for  pid=6348 comm="com.example.app" name="access_control.new_commit.cv" scontext=u:r:ephemeral_app:s0:c126,c257,c512,c768 tcontext=u:object_r:app_data_file:s0:c126,c257,c512,c768 tclass=fifo_file permissive=0 SEPF_SM-A805F_11_0010 audit_filtered
2021-10-12 13:12:07.981 676-676/? E/audit: type=1300 audit(1634033527.971:7153): arch=c00000b7 syscall=33 success=no exit=-13 a0=ffffff9c a1=b400006f85c120d0 a2=1180 a3=0 items=0 ppid=696 pid=6348 auid=4294967295 uid=10382 gid=10382 euid=10382 suid=10382 fsuid=10382 egid=10382 sgid=10382 fsgid=10382 tty=(none) ses=4294967295 comm="com.example.app" exe="/system/bin/app_process64" subj=u:r:ephemeral_app:s0:c126,c257,c512,c768 key=(null)
2021-10-12 13:12:07.981 676-676/? E/audit: type=1327 audit(1634033527.971:7153): proctitle="com.example.app"
2021-10-12 13:12:07.984 6348-6348/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.app, PID: 6348
    java.lang.RuntimeException: Unable to create application com.example.app.app.Application: java.lang.RuntimeException: [2]: Read-only file system
        at android.app.ActivityThread.handleMakeApplication(ActivityThread.java:7512)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7446)
        at android.app.ActivityThread.access$1400(ActivityThread.java:301)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2148)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:246)
        at android.app.ActivityThread.main(ActivityThread.java:8512)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1139)
     Caused by: java.lang.RuntimeException: [2]: Read-only file system
        at io.realm.interop.realmcJNI.realm_open(Native Method)
        at io.realm.interop.realmc.realm_open(realmc.java:291)
        at io.realm.interop.RealmInterop.realm_open(RealmInterop.kt:139)
        at io.realm.interop.RealmInterop.realm_open$default(RealmInterop.kt:138)
        at io.realm.Realm.<init>(Realm.kt:117)
        at com.example.app.shared.impl.db.Db.<init>(Db.kt:27)

The name nor path are not specified in the RealmConfiguration that is given to the constructor.

It seems that the actual data base file and a lock files are created. However, the run-time exception is thrown saying "Read-only file system". As I understand the first line of the log, access_control.new_commit.cv FIFO file is tried to be created but denied by the sandbox of InstantApp.

@pmpuro
Copy link
Author

pmpuro commented Oct 12, 2021

I used the 0.5.0 version.

@rorbech
Copy link
Contributor

rorbech commented Oct 12, 2021

Is this 100% reproducible? Also on different devices?

@pmpuro
Copy link
Author

pmpuro commented Oct 12, 2021

Yes, that's reproducible 100 %. I've tried with two devices: Samsung A80 (A805F)/Android 11 and Nokia 7.2.

I'll attach a link to a repo shortly.

@pmpuro
Copy link
Author

pmpuro commented Oct 12, 2021

An example code can be found in this repo.

See that you need to run it as an InstantApp to see the error. Launching it as a regular app works.

Also, note that the original stack trace is from our private KMM project, but the problem can be seen in a Kotlin Android app project as well.

@nhachicha
Copy link
Collaborator

Hi @pmpuro thanks for the repro, I can reproduce the error, it's unfortunately related to SELinux default policy on Android preventing the creation of the named pipes as you can see in the log

avc: denied { create } for name="access_control.new_commit.cv" scontext=u:r:ephemeral_app:s0:c156,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c156,c256,c512,c768 tclass=fifo_file permissive=0

The rest of Realm files are created correctly in the internal storage though (when running in Instant App mode).
I don't understand why Google set a default policy that prevents creating pipes inside an already writable folder (maybe a feature request/ticket could be created in their issue tracker)

Could you delay the usage of Realm until the app is installed? you can detect it by InstantApps.getPackageManagerCompat(this).isInstantApp

@pmpuro
Copy link
Author

pmpuro commented Oct 22, 2021

Thanks for response. Okay, I realized that it's about Android itself. That's a shame still.

@pmpuro
Copy link
Author

pmpuro commented Oct 25, 2021

Filed an issue on this for Google.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants