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

Fixed, Reduce mass-storage consumption with Android custom apps with embedded ZIM #3516

Merged
merged 8 commits into from
Nov 12, 2023

Conversation

MohitMaliFtechiz
Copy link
Collaborator

@MohitMaliFtechiz MohitMaliFtechiz commented Oct 26, 2023

Fixes #56
Fixes #3519
Fixes #3522

  • We are introducing reading zim file content through fileDescriptor instead of creating a file to avoid using storage twice for the same zim file.
  • As now we are using fileDescriptor for custom apps, and our notes functionality breaks with this change so we have refactored our notes functionality to properly work with fileDescriptor.
  • Fix The same Note saves multiple times while we are updating existing notes from NotesFragment. #3519. The problem was that we were saving the note name combined with zimFileTitle and articleTitle. When opening the saved note from NotesFragment, it retrieved the noteTitle from the database, which already contained the combined name. Subsequently, when saving the note again, it redundantly combined the name. To resolve this issue, we now extract the articleName when updating notes in NotesFragment, ensuring that it updates existing notes instead of creating new ones.
notesissuefixed.mp4
  • Fixed the issue where the Zim File was not displaying in the ZimHostFragment for custom apps.
    • In ZimHostFragment, we show Zim files that are saved in the database. These files are typically saved when downloading Zim files. In a custom app, where Zim files are already included within the app and not downloaded separately that's why they are not showing on the ZimHostFragment, we have addressed this issue by saving the Zim files in the database to ensure they appear in the ZimHostFragment.
    • Regarding the FileDescriptor, there are no file objects available because we read Zim files using FileDescriptor. To address this, we have created a demo.zim file to save it in the database so that it will be displayed in the ZimHostFragment. We handle this file within the KiwixServer. When the current Zim file is demo.zim, we create an Archive object with the FileDescriptor to host the Zim file on the KiwixServer.
  • We are temporarily hiding the kiwixServer feature from Custom Apps. Since we are now using fd (FileDescriptor) to read the zim file from the asset folder. Currently, 'KiwixServer' is unable to host zim files via fd. This feature is temporarily hidden for custom apps. We will re-enable it for custom apps once the issue is resolved. Unable to host books with FileDescriptor on Server libkiwix#1015
DisebleServerFeatureFromCustomApps.mp4

@MohitMaliFtechiz MohitMaliFtechiz marked this pull request as draft October 26, 2023 13:19
@MohitMaliFtechiz
Copy link
Collaborator Author

I have tried many ways to get the FileDescriptor from the asset folder, but no one works.

  • In our current approach we are taking inputStream from the asset and creating a file and after that reading it, only this method is working.
  • I have used another method of AssetManager class named openFd("fileName") but this method is only working for jpg/png types when we are trying to access the zim file with it, it shows a file compressed error.
Unable to copy the content of asset java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed
  • Then I tell Android to not compress zim files and after that, it tries to read the file but then Archive is not able to read this file and shows an error.
Attempting to create a reader with fd: 215
2023-10-30 18:43:46.700 28363-28363 kiwix                   org.kiwix.kiwixcustomcustomexample   E  Error opening ZIM file
2023-10-30 18:43:46.700 28363-28363 kiwix                   org.kiwix.kiwixcustomcustomexample   E  Invalid magic number
2023-10-30 18:43:46.942 28363-28363 libc                    org.kiwix.kiwixcustomcustomexample   A  Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 28363 (omcustomexample), pid 28363 (omcustomexample)
2023-10-30 18:43:47.303 28488-28488 DEBUG                   pid-28488                            A  Cmdline: org.kiwix.kiwixcustomcustomexample
2023-10-30 18:43:47.303 28488-28488 DEBUG                   pid-28488                            A  pid: 28363, tid: 28363, name: omcustomexample  >>> org.kiwix.kiwixcustomcustomexample <<<
2023-10-30 18:43:47.303 28488-28488 DEBUG                   pid-28488                            A        #00 pc 0000000000025464  /data/app/~~XBEH-64WCYluxR5Dux4QWg==/org.kiwix.kiwixcustomcustomexample-WVFT-phkdc8RDEnQAOwjHg==/base.apk!libzim_wrapper.so (Java_org_kiwix_libzim_SuggestionSearcher_setNativeSearcher+112) (BuildId: 6c0d6ee977af86c7d817e067ec4176543043faa4)
2023-10-30 18:43:47.303 28488-28488 DEBUG                   pid-28488                            A        #07 pc 0000000000337626  [anon:dalvik-classes23.dex extracted in memory from /data/app/~~XBEH-64WCYluxR5Dux4QWg==/org.kiwix.kiwixcustomcustomexample-WVFT-phkdc8RDEnQAOwjHg==/base.apk!classes23.dex] (org.kiwix.libzim.SuggestionSearcher.<init>+22)
2023-10-30 18:43:47.303 28488-28488 DEBUG                   pid-28488                            A        #13 pc 000000000000857e  [anon:dalvik-classes13.dex extracted in memory from /data/app/~~XBEH-64WCYluxR5Dux4QWg==/org.kiwix.kiwixcustomcustomexample-WVFT-phkdc8RDEnQAOwjHg==/base.apk!classes13.dex] (org.kiwix.kiwixmobile.core.reader.ZimFileReader.<init>+66)
2023-10-30 18:43:47.303 28488-28488 DEBUG                   pid-28488                            A        #19 pc 0000000000006c7c  [anon:dalvik-classes13.dex extracted in memory from /data/app/~~XBEH-64WCYluxR5Dux4QWg==/org.kiwix.kiwixcustomcustomexample-WVFT-phkdc8RDEnQAOwjHg==/base.apk!classes13.dex] (org.kiwix.kiwixmobile.core.reader.ZimFileReader$Factory$Impl.create+84)
2023-10-30 18:43:47.303 28488-28488 DEBUG                   pid-28488                            A        #25 pc 00000000000093d0  [anon:dalvik-classes13.dex extracted in memory from /data/app/~~XBEH-64WCYluxR5Dux4QWg==/org.kiwix.kiwixcustomcustomexample-WVFT-phkdc8RDEnQAOwjHg==/base.apk!classes13.dex] (org.kiwix.kiwixmobile.core.reader.ZimReaderContainer.setZimFileDescriptor+44)
2023-10-30 18:43:47.303 28488-28488 DEBUG                   pid-28488                            A        #31 pc 000000000001a81c  [anon:dalvik-classes5.dex extracted in memory from /data/app/~~XBEH-64WCYluxR5Dux4QWg==/org.kiwix.kiwixcustomcustomexample-WVFT-phkdc8RDEnQAOwjHg==/base.apk!classes5.dex] (org.kiwix.kiwixmobile.core.main.CoreReaderFragment.openAndSetInContainer+148)
2023-10-30 18:43:47.303 28488-28488 DEBUG                   pid-28488                            A        #37 pc 000000000001a750  [anon:dalvik-classes5.dex extracted in memory from /data/app/~~XBEH-64WCYluxR5Dux4QWg==/org.kiwix.kiwixcustomcustomexample-WVFT-phkdc8RDEnQAOwjHg==/base.apk!classes5.dex] (org.kiwix.kiwixmobile.core.main.CoreReaderFragment.openAndSetInContainer$default+72)
2023-10-30 18:43:47.304 28488-28488 DEBUG                   pid-28488                            A        #40 pc 000000000001aff2  [anon:dalvik-classes5.dex extracted in memory from /data/app/~~XBEH-64WCYluxR5Dux4QWg==/org.kiwix.kiwixcustomcustomexample-WVFT-phkdc8RDEnQAOwjHg==/base.apk!classes5.dex] (org.kiwix.kiwixmobile.core.main.CoreReaderFragment.openZimFile+154)
2023-10-30 18:43:47.304 28488-28488 DEBUG                   pid-28488                            A        #46 pc 000000000000547a  /data/data/org.kiwix.kiwixcustomcustomexample/code_cache/.overlay/base.apk/classes19.dex (org.kiwix.kiwixmobile.custom.main.CustomReaderFragment.access$openZimFile+18)
2023-10-30 18:43:47.304 28488-28488 DEBUG                   pid-28488                            A        #49 pc 0000000000003e86  /data/data/org.kiwix.kiwixcustomcustomexample/code_cache/.overlay/base.apk/classes19.dex (org.kiwix.kiwixmobile.custom.main.CustomReaderFragment$openObbOrZim$1.invoke+78)
2023-10-30 18:43:47.304 28488-28488 DEBUG                   pid-28488                            A        #55 pc 0000000000003de6  /data/data/org.kiwix.kiwixcustomcustomexample/code_cache/.overlay/base.apk/classes19.dex (org.kiwix.kiwixmobile.custom.main.CustomReaderFragment$openObbOrZim$1.invoke+14)
2023-10-30 18:43:47.304 28488-28488 DEBUG                   pid-28488                            A        #61 pc 0000000000002e0a  /data/data/org.kiwix.kiwixcustomcustomexample/code_cache/.overlay/base.apk/classes19.dex (org.kiwix.kiwixmobile.custom.main.CustomFileValidator.validate+90)
2023-10-30 18:43:47.304 28488-28488 DEBUG                   pid-28488                            A        #67 pc 0000000000005aac  /data/data/org.kiwix.kiwixcustomcustomexample/code_cache/.overlay/base.apk/classes19.dex (org.kiwix.kiwixmobile.custom.main.CustomReaderFragment.openObbOrZim+44)
2023-10-30 18:43:47.304 28488-28488 DEBUG                   pid-28488                            A        #73 pc 00000000000056c0  /data/data/org.kiwix.kiwixcustomcustomexample/code_cache/.overlay/base.apk/classes19.dex (org.kiwix.kiwixmobile.custom.main.CustomReaderFragment.loadPageFromNavigationArguments+136)
2023-10-30 18:43:47.304 28488-28488 DEBUG                   pid-28488                            A        #79 pc 00000000000059a0  /data/data/org.kiwix.kiwixcustomcustomexample/code_cache/.overlay/base.apk/classes19.dex (org.kiwix.kiwixmobile.custom.main.CustomReaderFragment.onViewCreated+368)
2023-10-30 18:43:47.304 28488-28488 DEBUG                   pid-28488                            A        #85 pc 000000000033ffb0  [anon:dalvik-classes.dex extracted in memory from /data/app/~~XBEH-64WCYluxR5Dux4QWg==/org.kiwix.kiwixcustomcustomexample-WVFT-phkdc8RDEnQAOwjHg==/base.apk] (androidx.fragment.app.Fragment.performViewCreated+16)
2023-10-30 18:43:47.304 28488-28488 DEBUG                   pid-28488                            A        #91 pc 000000000033238c  [anon:dalvik-classes.dex extracted in memory from /data/app/~~XBEH-64WCYluxR5Dux4QWg==/org.kiwix.kiwixcustomcustomexample-WVFT-phkdc8RDEnQAOwjHg==/base.apk] (androidx.fragment.app.FragmentStateManager.createView+816)
2023-10-30 18:43:47.304 28488-28488 DEBUG                   pid-28488                            A        #97 pc 0000000000332f58  [anon:dalvik-classes.dex extracted in memory from /data/app/~~XBEH-64WCYluxR5Dux4QWg==/org.kiwix.kiwixcustomcustomexample-WVFT-phkdc8RDEnQAOwjHg==/base.apk] (androidx.fragment.app.FragmentStateManager.moveToExpectedState+372)
2023-10-30 18:43:47.304 28488-28488 DEBUG                   pid-28488                            A        #103 pc 0000000000335f9c  [anon:dalvik-classes.dex extracted in memory from /data/app/~~XBEH-64WCYluxR5Dux4QWg==/org.kiwix.kiwixcustomcustomexample-WVFT-phkdc8RDEnQAOwjHg==/base.apk] (androidx.fragment.app.FragmentStore.moveToExpectedState+104)
2023-10-30 18:43:47.304 28488-28488 DEBUG                   pid-28488                            A        #109 pc 000000000032ef58  [anon:dalvik-classes.dex extracted in memory from /data/app/~~XBEH-64WCYluxR5Dux4QWg==/org.kiwix.kiwixcustomcustomexample-WVFT-phkdc8RDEnQAOwjHg==/base.apk] (androidx.fragment.app.FragmentManager.moveToState+88)
2023-10-30 18:43:47.305 28488-28488 DEBUG                   pid-28488                            A        #115 pc 000000000032d80a  [anon:dalvik-classes.dex extracted in memory from /data/app/~~XBEH-64WCYluxR5Dux4QWg==/org.kiwix.kiwixcustomcustomexample-WVFT-phkdc8RDEnQAOwjHg==/base.apk] (androidx.fragment.app.FragmentManager.dispatchStateChange+42)
2023-10-30 18:43:47.305 28488-28488 DEBUG                   pid-28488                            A        #121 pc 000000000032d902  [anon:dalvik-classes.dex extracted in memory from /data/app/~~XBEH-64WCYluxR5Dux4QWg==/org.kiwix.kiwixcustomcustomexample-WVFT-phkdc8RDEnQAOwjHg==/base.apk] (androidx.fragment.app.FragmentManager.dispatchViewCreated+10)
2023-10-30 18:43:47.305 28488-28488 DEBUG                   pid-28488                            A        #127 pc 000000000033ffc4  [anon:dalvik-classes.dex extracted in memory from /data/app/~~XBEH-64WCYluxR5Dux4QWg==/org.kiwix.kiwixcustomcustomexample-WVFT-phkdc8RDEnQAOwjHg==/base.apk] (androidx.fragment.app.Fragment.performViewCreated+36)
2023-10-30 18:43:47.305 28488-28488 DEBUG                   pid-28488                            A        #133 pc 000000000033238c  [anon:dalvik-classes.dex extracted in memory from /data/app/~~XBEH-64WCYluxR5Dux4QWg==/org.kiwix.kiwixcustomcustomexample-WVFT-phkdc8RDEnQAOwjHg==/base.apk] (androidx.fragment.app.FragmentStateManager.createView+816)
2023-10-30 18:43:47.305 28488-28488 DEBUG                   pid-28488                            A        #139 pc 0000000000332f58  [anon:dalvik-classes.dex extracted in memory from /data/app/~~XBEH-64WCYluxR5Dux4QWg==/org.kiwix.kiwixcustomcustomexample-WVFT-phkdc8RDEnQAOwjHg==/base.apk] (androidx.fragment.app.FragmentStateManager.moveToExpectedState+372)
2023-10-30 18:43:47.305 28488-28488 DEBUG                   pid-28488                            A        #145 pc 0000000000335f9c  [anon:dalvik-classes.dex extracted in memory from /data/app/~~XBEH-64WCYluxR5Dux4QWg==/org.kiwix.kiwixcustomcustomexample-WVFT-phkdc8RDEnQAOwjHg==/base.apk] (androidx.fragment.app.FragmentStore.moveToExpectedState+104)
2023-10-30 18:43:47.305 28488-28488 DEBUG                   pid-28488                            A        #151 pc 000000000032ef58  [anon:dalvik-classes.dex extracted in memory from /data/app/~~XBEH-64WCYluxR5Dux4QWg==/org.kiwix.kiwixcustomcustomexample-WVFT-phkdc8RDEnQAOwjHg==/base.apk] (androidx.fragment.app.FragmentManager.moveToState+88)
2023-10-30 18:43:47.305 28488-28488 DEBUG                   pid-28488                            A        #157 pc 000000000032d80a  [anon:dalvik-classes.dex extracted in memory from /data/app/~~XBEH-64WCYluxR5Dux4QWg==/org.kiwix.kiwixcustomcustomexample-WVFT-phkdc8RDEnQAOwjHg==/base.apk] (androidx.fragment.app.FragmentManager.dispatchStateChange+42)
2023-10-30 18:43:47.305 28488-28488 DEBUG                   pid-28488                            A        #163 pc 000000000032ce30  [anon:dalvik-classes.dex extracted in memory from /data/app/~~XBEH-64WCYluxR5Dux4QWg==/org.kiwix.kiwixcustomcustomexample-WVFT-phkdc8RDEnQAOwjHg==/base.apk] (androidx.fragment.app.FragmentManager.dispatchActivityCreated+48)
2023-10-30 18:43:47.305 28488-28488 DEBUG                   pid-28488                            A        #169 pc 0000000000323ef8  [anon:dalvik-classes.dex extracted in memory from /data/app/~~XBEH-64WCYluxR5Dux4QWg==/org.kiwix.kiwixcustomcustomexample-WVFT-phkdc8RDEnQAOwjHg==/base.apk] (androidx.fragment.app.FragmentController.dispatchActivityCreated+16)
2023-10-30 18:43:47.305 28488-28488 DEBUG                   pid-28488                            A        #175 pc 00000000003220ae  [anon:dalvik-classes.dex extracted in memory from /data/app/~~XBEH-64WCYluxR5Dux4QWg==/org.kiwix.kiwixcustomcustomexample-WVFT-phkdc8RDEnQAOwjHg==/base.apk] (androidx.fragment.app.FragmentActivity.onStart+74)
2023-10-30 18:43:47.305 28488-28488 DEBUG                   pid-28488                            A        #181 pc 0000000000177498  [anon:dalvik-classes.dex extracted in memory from /data/app/~~XBEH-64WCYluxR5Dux4QWg==/org.kiwix.kiwixcustomcustomexample-WVFT-phkdc8RDEnQAOwjHg==/base.apk] (androidx.appcompat.app.AppCompatActivity.onStart+8)
2023-10-30 18:43:47.306 28488-28488 DEBUG                   pid-28488                            A        #187 pc 0000000000013710  [anon:dalvik-classes5.dex extracted in memory from /data/app/~~XBEH-64WCYluxR5Dux4QWg==/org.kiwix.kiwixcustomcustomexample-WVFT-phkdc8RDEnQAOwjHg==/base.apk!classes5.dex] (org.kiwix.kiwixmobile.core.main.CoreMainActivity.onStart+8)
2023-10-30 18:43:47.306 28488-28488 DEBUG                   pid-28488                            A        #193 pc 0000000000003c58  /data/data/org.kiwix.kiwixcustomcustomexample/code_cache/.overlay/base.apk/classes19.dex (org.kiwix.kiwixmobile.custom.main.CustomMainActivity.onStart+8)

But this error is not with libkiwix/libkiwix because I have tried to access the same file from the storage location with the AssetManager class and it is able to read the zim file. So it is probably occurring when we are accessing the zim file from the asset folder then Android somehow does some changes in that file.

  • We can not directly access this file with their file path because assets are not stored as standalone files on the device's file system. They are, instead, part of this package, and without AssetManager API we can not get them.

@kelson42, @mgautierfr is it possible to read the zim file via InputStream I am not sure how much code refactoring it will need, but if we achieve this then we can get rid of this problem.

@kelson42
Copy link
Collaborator

kelson42 commented Oct 30, 2023

@mgautierfr This is for you.
@MohitMaliFtechiz Asset should not be compressed obviously
@MohitMaliFtechiz Please show us rhe source code where you get the fd and open it with libkiwix

}
}
}
val inputStream = assetManager.openFd(BuildConfig.PLAY_ASSET_FILE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

openFd returns a AssetFileDescriptor which is AutoCloseable.

So I suspect (to verify) that when we exit the function, inputStream is closed and so the fileDescriptor become invalid.
(You can check that with the valid function before passing it to Archive.)

It seems you can use getParcelFileDescriptor which return ParcelFileDescriptor which is also AutoCloseable.
So with some luck the ParcelFileDescriptor keep the fd open where FileDescriptor doesn't.

Comment on lines 1390 to 1394
protected fun openZimFile(
file: File?,
isCustomApp: Boolean = false,
fileDescriptor: FileDescriptor? = null
) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit disturb by this function signature.

I think it would be better to have two methods call openZimFile and openZimFd instead of having option arguments.

(But it is maybe because I'm not familiar with Kotlin language)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mgautierfr Here we only need to check if it is file or fileDescriptor that comes from the CustomFileValidator class and we are creating an Archive object accordingly. We will improve our code but first it should work with fileDescriptor.

@MohitMaliFtechiz
Copy link
Collaborator Author

MohitMaliFtechiz commented Oct 31, 2023

@MohitMaliFtechiz Asset should not be compressed obviously

@kelson42 I have made changes locally to not compress the asset noCompress (But somehow it is doing changes in asset folder or might be .zim extension is not generic it is treating it like a compressed file because if I access it with same codebase from storage location than it is working normally), after that, it is showing an error in libkiwix/libzim. Before doing changes it was showing this error.

Unable to copy the content of asset java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed

(You can check that with the valid function before passing it to Archive.)

@mgautierfr Thanks for your feedback, yes we are checking fileDescriptor is valid or not before passing it to libkiwix.

 fun setZimFileDescriptor(fileDescriptor: FileDescriptor) {
    zimFileReader =
      if (fileDescriptor.valid()) zimFileReaderFactory.create(fileDescriptor)
      else null
  }

It seems you can use getParcelFileDescriptor which return ParcelFileDescriptor which is also AutoCloseable.
So with some luck the ParcelFileDescriptor keep the fd open where FileDescriptor doesn't.

@mgautierfr Thanks for the suggestion, I have tried it, and it is giving the same error Invalid magic number while creating the Archive object from it.

Attempting to create reader with fd: 5
2023-10-31 11:32:02.398  9069-9069  kiwix                   org.kiwix.kiwixcustomcustomexample   E  Error opening ZIM file
2023-10-31 11:32:02.398  9069-9069  kiwix                   org.kiwix.kiwixcustomcustomexample   E  Invalid magic number
2023-10-31 11:32:02.948  9069-9069  libc                    org.kiwix.kiwixcustomcustomexample   A  Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 9069 (omcustomexample), pid 9069 (omcustomexample)
2023-10-31 11:32:03.477  9692-9692  DEBUG                   pid-9692                             A  Cmdline: org.kiwix.kiwixcustomcustomexample
2023-10-31 11:32:03.477  9692-9692  DEBUG                   pid-9692                             A  pid: 9069, tid: 9069, name: omcustomexample  >>> org.kiwix.kiwixcustomcustomexample <<<
2023-10-31 11:32:03.477  9692-9692  DEBUG                   pid-9692                             A        #00 pc 0000000000025464  /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk!libzim_wrapper.so (Java_org_kiwix_libzim_SuggestionSearcher_setNativeSearcher+112) (BuildId: 6c0d6ee977af86c7d817e067ec4176543043faa4)
2023-10-31 11:32:03.477  9692-9692  DEBUG                   pid-9692                             A        #07 pc 0000000000337626  [anon:dalvik-classes23.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk!classes23.dex] (org.kiwix.libzim.SuggestionSearcher.<init>+22)
2023-10-31 11:32:03.478  9692-9692  DEBUG                   pid-9692                             A        #13 pc 00000000000085a2  [anon:dalvik-classes13.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk!classes13.dex] (org.kiwix.kiwixmobile.core.reader.ZimFileReader.<init>+66)
2023-10-31 11:32:03.478  9692-9692  DEBUG                   pid-9692                             A        #19 pc 0000000000006bac  [anon:dalvik-classes13.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk!classes13.dex] (org.kiwix.kiwixmobile.core.reader.ZimFileReader$Factory$Impl.create+92)
2023-10-31 11:32:03.478  9692-9692  DEBUG                   pid-9692                             A        #25 pc 00000000000093ec  [anon:dalvik-classes13.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk!classes13.dex] (org.kiwix.kiwixmobile.core.reader.ZimReaderContainer.setZimFileDescriptor+60)
2023-10-31 11:32:03.478  9692-9692  DEBUG                   pid-9692                             A        #31 pc 000000000001a81c  [anon:dalvik-classes5.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk!classes5.dex] (org.kiwix.kiwixmobile.core.main.CoreReaderFragment.openAndSetInContainer+148)
2023-10-31 11:32:03.478  9692-9692  DEBUG                   pid-9692                             A        #37 pc 000000000001a750  [anon:dalvik-classes5.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk!classes5.dex] (org.kiwix.kiwixmobile.core.main.CoreReaderFragment.openAndSetInContainer$default+72)
2023-10-31 11:32:03.478  9692-9692  DEBUG                   pid-9692                             A        #40 pc 000000000001aff2  [anon:dalvik-classes5.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk!classes5.dex] (org.kiwix.kiwixmobile.core.main.CoreReaderFragment.openZimFile+154)
2023-10-31 11:32:03.478  9692-9692  DEBUG                   pid-9692                             A        #46 pc 0000000000005476  [anon:dalvik-classes19.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk!classes19.dex] (org.kiwix.kiwixmobile.custom.main.CustomReaderFragment.access$openZimFile+18)
2023-10-31 11:32:03.478  9692-9692  DEBUG                   pid-9692                             A        #49 pc 0000000000003e82  [anon:dalvik-classes19.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk!classes19.dex] (org.kiwix.kiwixmobile.custom.main.CustomReaderFragment$openObbOrZim$1.invoke+78)
2023-10-31 11:32:03.478  9692-9692  DEBUG                   pid-9692                             A        #55 pc 0000000000003de2  [anon:dalvik-classes19.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk!classes19.dex] (org.kiwix.kiwixmobile.custom.main.CustomReaderFragment$openObbOrZim$1.invoke+14)
2023-10-31 11:32:03.478  9692-9692  DEBUG                   pid-9692                             A        #61 pc 0000000000002e06  [anon:dalvik-classes19.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk!classes19.dex] (org.kiwix.kiwixmobile.custom.main.CustomFileValidator.validate+90)
2023-10-31 11:32:03.478  9692-9692  DEBUG                   pid-9692                             A        #67 pc 0000000000005aa8  [anon:dalvik-classes19.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk!classes19.dex] (org.kiwix.kiwixmobile.custom.main.CustomReaderFragment.openObbOrZim+44)
2023-10-31 11:32:03.478  9692-9692  DEBUG                   pid-9692                             A        #73 pc 00000000000056bc  [anon:dalvik-classes19.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk!classes19.dex] (org.kiwix.kiwixmobile.custom.main.CustomReaderFragment.loadPageFromNavigationArguments+136)
2023-10-31 11:32:03.478  9692-9692  DEBUG                   pid-9692                             A        #79 pc 000000000000599c  [anon:dalvik-classes19.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk!classes19.dex] (org.kiwix.kiwixmobile.custom.main.CustomReaderFragment.onViewCreated+368)
2023-10-31 11:32:03.478  9692-9692  DEBUG                   pid-9692                             A        #85 pc 000000000033ffb0  [anon:dalvik-classes.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk] (androidx.fragment.app.Fragment.performViewCreated+16)
2023-10-31 11:32:03.478  9692-9692  DEBUG                   pid-9692                             A        #91 pc 000000000033238c  [anon:dalvik-classes.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk] (androidx.fragment.app.FragmentStateManager.createView+816)
2023-10-31 11:32:03.479  9692-9692  DEBUG                   pid-9692                             A        #97 pc 0000000000332f58  [anon:dalvik-classes.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk] (androidx.fragment.app.FragmentStateManager.moveToExpectedState+372)
2023-10-31 11:32:03.479  9692-9692  DEBUG                   pid-9692                             A        #103 pc 0000000000335f9c  [anon:dalvik-classes.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk] (androidx.fragment.app.FragmentStore.moveToExpectedState+104)
2023-10-31 11:32:03.479  9692-9692  DEBUG                   pid-9692                             A        #109 pc 000000000032ef58  [anon:dalvik-classes.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk] (androidx.fragment.app.FragmentManager.moveToState+88)
2023-10-31 11:32:03.479  9692-9692  DEBUG                   pid-9692                             A        #115 pc 000000000032d80a  [anon:dalvik-classes.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk] (androidx.fragment.app.FragmentManager.dispatchStateChange+42)
2023-10-31 11:32:03.479  9692-9692  DEBUG                   pid-9692                             A        #121 pc 000000000032d902  [anon:dalvik-classes.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk] (androidx.fragment.app.FragmentManager.dispatchViewCreated+10)
2023-10-31 11:32:03.479  9692-9692  DEBUG                   pid-9692                             A        #127 pc 000000000033ffc4  [anon:dalvik-classes.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk] (androidx.fragment.app.Fragment.performViewCreated+36)
2023-10-31 11:32:03.479  9692-9692  DEBUG                   pid-9692                             A        #133 pc 000000000033238c  [anon:dalvik-classes.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk] (androidx.fragment.app.FragmentStateManager.createView+816)
2023-10-31 11:32:03.479  9692-9692  DEBUG                   pid-9692                             A        #139 pc 0000000000332f58  [anon:dalvik-classes.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk] (androidx.fragment.app.FragmentStateManager.moveToExpectedState+372)
2023-10-31 11:32:03.479  9692-9692  DEBUG                   pid-9692                             A        #145 pc 0000000000335f9c  [anon:dalvik-classes.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk] (androidx.fragment.app.FragmentStore.moveToExpectedState+104)
2023-10-31 11:32:03.479  9692-9692  DEBUG                   pid-9692                             A        #151 pc 000000000032ef58  [anon:dalvik-classes.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk] (androidx.fragment.app.FragmentManager.moveToState+88)
2023-10-31 11:32:03.479  9692-9692  DEBUG                   pid-9692                             A        #157 pc 000000000032d80a  [anon:dalvik-classes.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk] (androidx.fragment.app.FragmentManager.dispatchStateChange+42)
2023-10-31 11:32:03.479  9692-9692  DEBUG                   pid-9692                             A        #163 pc 000000000032ce30  [anon:dalvik-classes.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk] (androidx.fragment.app.FragmentManager.dispatchActivityCreated+48)
2023-10-31 11:32:03.480  9692-9692  DEBUG                   pid-9692                             A        #169 pc 0000000000323ef8  [anon:dalvik-classes.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk] (androidx.fragment.app.FragmentController.dispatchActivityCreated+16)
2023-10-31 11:32:03.480  9692-9692  DEBUG                   pid-9692                             A        #175 pc 00000000003220ae  [anon:dalvik-classes.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk] (androidx.fragment.app.FragmentActivity.onStart+74)
2023-10-31 11:32:03.480  9692-9692  DEBUG                   pid-9692                             A        #181 pc 0000000000177498  [anon:dalvik-classes.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk] (androidx.appcompat.app.AppCompatActivity.onStart+8)
2023-10-31 11:32:03.480  9692-9692  DEBUG                   pid-9692                             A        #187 pc 0000000000013710  [anon:dalvik-classes5.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk!classes5.dex] (org.kiwix.kiwixmobile.core.main.CoreMainActivity.onStart+8)
2023-10-31 11:32:03.480  9692-9692  DEBUG                   pid-9692                             A        #193 pc 0000000000003c54  [anon:dalvik-classes19.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk!classes19.dex] (org.kiwix.kiwixmobile.custom.main.CustomMainActivity.onStart+8)

@mgautierfr It seems not related to valid fd because I have tried directly creating an Archive object in CustomFileValidator before returning it and there also it is showing the same error.

Screenshot from 2023-10-31 12-04-32

2023-10-31 11:49:57.131 14295-14295 kiwix                   org.kiwix.kiwixcustomcustomexample   E  Attempting to create reader with fd: 227
2023-10-31 11:49:57.281 14295-14295 kiwix                   org.kiwix.kiwixcustomcustomexample   E  Error opening ZIM file
2023-10-31 11:49:57.281 14295-14295 kiwix                   org.kiwix.kiwixcustomcustomexample   E  Invalid magic number
2023-10-31 11:49:57.710 14295-14295 libc                    org.kiwix.kiwixcustomcustomexample   A  Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 14295 (omcustomexample), pid 14295 (omcustomexample)
2023-10-31 11:49:58.240 14444-14444 DEBUG                   crash_dump64                         A  Cmdline: org.kiwix.kiwixcustomcustomexample
2023-10-31 11:49:58.240 14444-14444 DEBUG                   crash_dump64                         A  pid: 14295, tid: 14295, name: omcustomexample  >>> org.kiwix.kiwixcustomcustomexample <<<
2023-10-31 11:49:58.240 14444-14444 DEBUG                   crash_dump64                         A        #00 pc 000000000000c920  /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk!libzim_wrapper.so (Java_org_kiwix_libzim_Archive_getFilename+96) (BuildId: 6c0d6ee977af86c7d817e067ec4176543043faa4)
2023-10-31 11:49:58.240 14444-14444 DEBUG                   crash_dump64                         A        #07 pc 000000000000294e  /data/data/org.kiwix.kiwixcustomcustomexample/code_cache/.overlay/base.apk/classes19.dex (org.kiwix.kiwixmobile.custom.main.CustomFileValidator.getParcelFileDescriptorFromPlayAssetDelivery+154)
2023-10-31 11:49:58.240 14444-14444 DEBUG                   crash_dump64                         A        #13 pc 0000000000002d8c  /data/data/org.kiwix.kiwixcustomcustomexample/code_cache/.overlay/base.apk/classes19.dex (org.kiwix.kiwixmobile.custom.main.CustomFileValidator.detectInstallationState$default+120)
2023-10-31 11:49:58.240 14444-14444 DEBUG                   crash_dump64                         A        #16 pc 0000000000002e88  /data/data/org.kiwix.kiwixcustomcustomexample/code_cache/.overlay/base.apk/classes19.dex (org.kiwix.kiwixmobile.custom.main.CustomFileValidator.validate+48)
2023-10-31 11:49:58.240 14444-14444 DEBUG                   crash_dump64                         A        #22 pc 0000000000005b54  /data/data/org.kiwix.kiwixcustomcustomexample/code_cache/.overlay/base.apk/classes19.dex (org.kiwix.kiwixmobile.custom.main.CustomReaderFragment.openObbOrZim+44)
2023-10-31 11:49:58.241 14444-14444 DEBUG                   crash_dump64                         A        #28 pc 0000000000005768  /data/data/org.kiwix.kiwixcustomcustomexample/code_cache/.overlay/base.apk/classes19.dex (org.kiwix.kiwixmobile.custom.main.CustomReaderFragment.loadPageFromNavigationArguments+136)
2023-10-31 11:49:58.241 14444-14444 DEBUG                   crash_dump64                         A        #34 pc 0000000000005a48  /data/data/org.kiwix.kiwixcustomcustomexample/code_cache/.overlay/base.apk/classes19.dex (org.kiwix.kiwixmobile.custom.main.CustomReaderFragment.onViewCreated+368)
2023-10-31 11:49:58.241 14444-14444 DEBUG                   crash_dump64                         A        #40 pc 000000000033ffb0  [anon:dalvik-classes.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk] (androidx.fragment.app.Fragment.performViewCreated+16)
2023-10-31 11:49:58.241 14444-14444 DEBUG                   crash_dump64                         A        #46 pc 000000000033238c  [anon:dalvik-classes.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk] (androidx.fragment.app.FragmentStateManager.createView+816)
2023-10-31 11:49:58.241 14444-14444 DEBUG                   crash_dump64                         A        #52 pc 0000000000332f58  [anon:dalvik-classes.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk] (androidx.fragment.app.FragmentStateManager.moveToExpectedState+372)
2023-10-31 11:49:58.241 14444-14444 DEBUG                   crash_dump64                         A        #58 pc 0000000000335f9c  [anon:dalvik-classes.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk] (androidx.fragment.app.FragmentStore.moveToExpectedState+104)
2023-10-31 11:49:58.241 14444-14444 DEBUG                   crash_dump64                         A        #64 pc 000000000032ef58  [anon:dalvik-classes.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk] (androidx.fragment.app.FragmentManager.moveToState+88)
2023-10-31 11:49:58.241 14444-14444 DEBUG                   crash_dump64                         A        #70 pc 000000000032d80a  [anon:dalvik-classes.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk] (androidx.fragment.app.FragmentManager.dispatchStateChange+42)
2023-10-31 11:49:58.241 14444-14444 DEBUG                   crash_dump64                         A        #76 pc 000000000032d902  [anon:dalvik-classes.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk] (androidx.fragment.app.FragmentManager.dispatchViewCreated+10)
2023-10-31 11:49:58.241 14444-14444 DEBUG                   crash_dump64                         A        #82 pc 000000000033ffc4  [anon:dalvik-classes.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk] (androidx.fragment.app.Fragment.performViewCreated+36)
2023-10-31 11:49:58.241 14444-14444 DEBUG                   crash_dump64                         A        #88 pc 000000000033238c  [anon:dalvik-classes.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk] (androidx.fragment.app.FragmentStateManager.createView+816)
2023-10-31 11:49:58.241 14444-14444 DEBUG                   crash_dump64                         A        #94 pc 0000000000332f58  [anon:dalvik-classes.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk] (androidx.fragment.app.FragmentStateManager.moveToExpectedState+372)
2023-10-31 11:49:58.242 14444-14444 DEBUG                   crash_dump64                         A        #100 pc 0000000000335f9c  [anon:dalvik-classes.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk] (androidx.fragment.app.FragmentStore.moveToExpectedState+104)
2023-10-31 11:49:58.242 14444-14444 DEBUG                   crash_dump64                         A        #106 pc 000000000032ef58  [anon:dalvik-classes.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk] (androidx.fragment.app.FragmentManager.moveToState+88)
2023-10-31 11:49:58.242 14444-14444 DEBUG                   crash_dump64                         A        #112 pc 000000000032d80a  [anon:dalvik-classes.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk] (androidx.fragment.app.FragmentManager.dispatchStateChange+42)
2023-10-31 11:49:58.242 14444-14444 DEBUG                   crash_dump64                         A        #118 pc 000000000032ce30  [anon:dalvik-classes.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk] (androidx.fragment.app.FragmentManager.dispatchActivityCreated+48)
2023-10-31 11:49:58.242 14444-14444 DEBUG                   crash_dump64                         A        #124 pc 0000000000323ef8  [anon:dalvik-classes.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk] (androidx.fragment.app.FragmentController.dispatchActivityCreated+16)
2023-10-31 11:49:58.242 14444-14444 DEBUG                   crash_dump64                         A        #130 pc 00000000003220ae  [anon:dalvik-classes.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk] (androidx.fragment.app.FragmentActivity.onStart+74)
2023-10-31 11:49:58.242 14444-14444 DEBUG                   crash_dump64                         A        #136 pc 0000000000177498  [anon:dalvik-classes.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk] (androidx.appcompat.app.AppCompatActivity.onStart+8)
2023-10-31 11:49:58.242 14444-14444 DEBUG                   crash_dump64                         A        #142 pc 0000000000013710  [anon:dalvik-classes5.dex extracted in memory from /data/app/~~yrInXn84-phOxoJ-0kyV_g==/org.kiwix.kiwixcustomcustomexample-8Z8mZNEjF-LmbjFxmYNV2w==/base.apk!classes5.dex] (org.kiwix.kiwixmobile.core.main.CoreMainActivity.onStart+8)
2023-10-31 11:49:58.242 14444-14444 DEBUG                   crash_dump64                         A        #148 pc 0000000000003d00  /data/data/org.kiwix.kiwixcustomcustomexample/code_cache/.overlay/base.apk/classes19.dex (org.kiwix.kiwixmobile.custom.main.CustomMainActivity.onStart+8)

@kelson42
Copy link
Collaborator

@MohitMaliDeveloper Can you please read the first 100 bytes in Java from the fd you try to pass to the libkiwix and dump it here in hexa?

@codecov
Copy link

codecov bot commented Oct 31, 2023

Codecov Report

Attention: 61 lines in your changes are missing coverage. Please review.

Comparison is base (969ad0d) 49.15% compared to head (1b1d874) 48.99%.
Report is 5 commits behind head on develop.

❗ Current head 1b1d874 differs from pull request most recent head 8b1cb8b. Consider uploading reports for the commit 8b1cb8b to get more accurate results

Additional details and impacted files
@@              Coverage Diff              @@
##             develop    #3516      +/-   ##
=============================================
- Coverage      49.15%   48.99%   -0.16%     
+ Complexity      1075     1073       -2     
=============================================
  Files            285      285              
  Lines          10365    10382      +17     
  Branches        1382     1393      +11     
=============================================
- Hits            5095     5087       -8     
- Misses          4451     4473      +22     
- Partials         819      822       +3     
Files Coverage Δ
.../kiwixmobile/core/extensions/ActivityExtensions.kt 38.70% <0.00%> (-0.64%) ⬇️
...xmobile/core/page/bookmark/adapter/BookmarkItem.kt 0.00% <0.00%> (ø)
...obile/core/page/history/adapter/HistoryListItem.kt 58.53% <0.00%> (-2.44%) ⬇️
...iwixmobile/core/page/notes/adapter/NoteListItem.kt 0.00% <0.00%> (ø)
...rg/kiwix/kiwixmobile/core/utils/files/FileUtils.kt 28.64% <0.00%> (-0.15%) ⬇️
...a/org/kiwix/kiwixmobile/core/main/AddNoteDialog.kt 0.00% <0.00%> (ø)
...wix/kiwixmobile/core/main/MainRepositoryActions.kt 25.92% <0.00%> (-4.51%) ⬇️
...page/notes/viewmodel/effects/ShowOpenNoteDialog.kt 0.00% <0.00%> (ø)
...iwix/kiwixmobile/core/reader/ZimReaderContainer.kt 40.74% <0.00%> (-4.16%) ⬇️
...iwix/kiwixmobile/core/webserver/ZimHostFragment.kt 18.50% <0.00%> (-0.62%) ⬇️
... and 3 more

... and 5 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MohitMaliFtechiz
Copy link
Collaborator Author

MohitMaliFtechiz commented Oct 31, 2023

@kelson42 Here is the first 100 bytes read from fd which is returned by assetManager.openFd() method.

PK��????????�??!�!���;~V	????��????�??????assets/credits.html�X�r�H���S��*��DZ3���P����`�??Ǜ�k���Hj�[���y�}��ڻ��~�

But I wonder because the assetManager.open() method returned different data for same file.

ZIM��??????��ȕ,������3N�qn�????�??????z$/??????????�?/??????????�M/??????????P??????????????��????�����M/??????????application/javascrip

@kelson42
Copy link
Collaborator

@MohitMaliFtechiz In hexadecimal?!

@MohitMaliFtechiz
Copy link
Collaborator Author

@kelson42 Here is the hexadecimal with assetManager.openFd() method.

504B0304000000000800210821021C063B7E56090000FD150000130000006173736574732F637265646974732E68746D6CFD58FD72FD4816FDFD53FDFD2AFDFDF133FDFDFD50FDFDFDFD60FD00DBFD6BFD06FD486AFD5B02FDFD79FD7DFDFDBBFDFD7EFD

and this is with assetManager.open() method.

5A494D04050000007FFD152CFDFD18FDFDFD330D4EFD716E030000060000007A242F0000000000FD3F2F0000000000FD4D2F00000000005000000000000000FD010000FDFDFDFDFD4D2F00000000006170706C69636174696F6E2F6A6176617363726970

@kelson42
Copy link
Collaborator

@mgautierfr To me it looks the fd is OK, so this is probably some kind of stupid problem around the fd mgmt.

@mgautierfr
Copy link
Member

@MohitMaliFtechiz You need to use the Archive constructor with an offset and size (https://github.com/kiwix/java-libkiwix/blob/main/lib/src/main/java/org/kiwix/libzim/Archive.java#L41).
If you pass only the fd, it will use offset==0 and size==size of file(ie, whole package)

getStartOffset and getLength should be the proper way to get the offset and size.

@mgautierfr
Copy link
Member

⚠️ zim::Archive will take ownerchip of the fd (and so will close it at the end). However the wrapper will "share" the native fd with java FileDescriptor.
So we must be sure that the FileDescriptor will not close the native fd when it is destructed.

I think the best way to do it is :

val offset = assetFileDescriptor.getStartOffset();
val size = assetFileDescriptor.getLength();
val parcelFileDescriptor = assetFileDescriptor.getParcelFileDescriptor().dup();
val jniKiwixReader = Archive(parcelFileDescriptor.fileDescriptor, offset, size);
parcelFileDescriptor.detachFd();

@kelson42
Copy link
Collaborator

kelson42 commented Oct 31, 2023

@kelson42 @mgautierfr I didn't read the comment of Mohit properly. The fd() method does not return the proper content!

@MohitMaliFtechiz
Copy link
Collaborator Author

@MohitMaliFtechiz You need to use the Archive constructor with an offset and size (https://github.com/kiwix/java-libkiwix/blob/main/lib/src/main/java/org/kiwix/libzim/Archive.java#L41).
If you pass only the fd, it will use offset==0 and size==size of file(ie, whole package)
getStartOffset and getLength should be the proper way to get the offset and size.

@mgautierfr Thanks for providing more details now i am able to read the zim file with locally with FileDescriptor.

This method of the Archive works for me.

public Archive(FileDescriptor fd, long offset, long size)
          throws ZimFileFormatException
  {
    setNativeArchiveEmbedded(fd, offset, size);
  }

Before it, i was using but this method was not working.

 public Archive(FileDescriptor fd) throws ZimFileFormatException
  {
    setNativeArchiveByFD(fd);
  }

Now with the updated code i am able to read the file from asset folder with fileDescriptor, i am testing this with Play asset delivery on my local machine hope this will work there as well.

Screenrecorder-2023-10-31-16-33-39-182.mp4

@MohitMaliFtechiz
Copy link
Collaborator Author

@kelson42, @mgautierfr This is working with Play asset Delivery 🎉.

Screenshot from 2023-10-31 18-15-58

@MohitMaliFtechiz
Copy link
Collaborator Author

MohitMaliFtechiz commented Nov 2, 2023

@kelson42, @mgautierfr We have refactored our app code to create KiwixServer with FileDescriptor in ca4254b. But on KiwixServer the zim file is not showing, however, the language code is showing on the Server as you can see in the below video.

Having an issue uploading video on Github please see here https://drive.google.com/file/d/17evixXjjQdwphOWlMUTY1BIia2baDr2E/view?usp=drive_link

The archive object is created with valid fd since I have printed the values from the archive object.

Attempting to create a reader with fd: 252
createKiwixServer: Size = 354893501 
MainEntryTitle =  mainPage 
Article count = 244057

Apart from this, I have tried to get fd from the File object and tried to run a server with that, showing the same error. So it is probably the error with fd on the server.

@mgautierfr can you please have a look at this?

Edited:

ZimFileNotHostedOnKiwixServerWithFileDescriptor.mp4

@kelson42
Copy link
Collaborator

kelson42 commented Nov 4, 2023

@MohitMaliFtechiz Pretty sure this is a bug (already known) in the libkiwix. If this is the only problem left, please open:

  • deactivate the feature (not sure if this impacts only custom apps or Kiwix as well… but do what is necessary)
  • Open a dedicated ticket to this problem
  • Put this PR in review

@veloman-yunkan @mgautierfr Might that be that libkiwix HTTP service can not work properly if ZIM files are loaded via an fd (no filename, so no humanid)?

@kelson42
Copy link
Collaborator

kelson42 commented Nov 4, 2023

@MohitMaliFtechiz This line buildConfigField("String", "PLAY_ASSET_FILE", "\"${customApp.name}.zim\"") and its handling should also disapear I guess!?

@mgautierfr
Copy link
Member

mgautierfr commented Nov 6, 2023

Might that be that libkiwix HTTP service can not work properly if ZIM files are loaded via an fd (no filename, so no humanid)?

This is probably that. We can't store in library.xml information about fd (offset, ...). We can only store a path. And we need a path to open the archive later.

We have no way to start a server on a existing zim archive. Server on libkiwix now always work on library, and on library pointing to plain zim file. (And it is somehow a constraints as it is the server/library which handle opening/closing/caching zim archive).

@MohitMaliFtechiz
Copy link
Collaborator Author

deactivate the feature (not sure if this impacts only custom apps or Kiwix as well… but do what is necessary)

@kelson42 I have deactivated the feature for custom apps, and it does not impact the KiwixAndroid since as of now we are mainly using FileDescriptor for Custom Apps.

Open a dedicated ticket to this problem

I have opened a ticket for this kiwix/libkiwix#1015.

@MohitMaliFtechiz This line buildConfigField("String", "PLAY_ASSET_FILE", "\"${customApp.name}.zim\"") and its handling should also disapear I guess!?

No, this is required for getting the FileDescriptor from the asset folder, since we are creating the file in asset folder with the app name

File("$projectDir/../install_time_asset/src/main/assets", "$name.zim").let {

So we need this to get the FileDescriptor from the asset folder.

assetManager.openFd(BuildConfig.PLAY_ASSET_FILE).

@MohitMaliFtechiz MohitMaliFtechiz marked this pull request as ready for review November 6, 2023 11:01
… of creating a file to avoid using storage twice for same zim file.
* Telling android to not compress the `.zim` files in asset folder while building the apk/bundle.
* Now we are using fileDescriptor for custom apps to read zim file from asset folder, so we have improved our notes saving functionality according to this change.
* The problem was that we were saving the note name combined with `zimFileTitle` and `articleTitle`. When opening the saved note from `NotesFragment`, it retrieved the `noteTitle` from the database, which already contained the combined name. Subsequently, when saving the note again, it redundantly combined the name. To resolve this issue, we now extract the `articleName` when updating notes in `NotesFragment`, ensuring that it updates existing notes instead of creating new ones.
…Fragment` for custom apps.

* In `ZimHostFragment`, we show Zim files that are saved in the database. These files are typically saved when downloading Zim files. In a custom app, where Zim files are already included within the app and not downloaded separately that's why they are not showing on the `ZimHostFragment`, we have addressed this issue by saving the Zim files in the database to ensure they appear in the `ZimHostFragment`.
* Regarding the `FileDescriptor`, there are no file objects available because we read Zim files using `FileDescriptor`. To address this, we have created a `demo.zim` file to save it in the database so that it will be displayed in the `ZimHostFragment`. We handle this file within the `KiwixServer`. When the current Zim file is `demo.zim`, we create an `Archive` object with the `FileDescriptor` to host the Zim file on the `KiwixServer`.
* Since we are now using fd (FileDescriptor) to read the zim file from the asset folder. Currently, 'KiwixServer' is unable to host zim files via fd. This feature is temporarily hidden for custom apps. We will re-enable it for custom apps once the issue is resolved.
@kelson42
Copy link
Collaborator

Unfortunately no review, but I have to merge.

@kelson42 kelson42 merged commit 3716b72 into develop Nov 12, 2023
7 of 8 checks passed
@kelson42 kelson42 deleted the Issue#56 branch November 12, 2023 17:06
@gouri-panda
Copy link
Collaborator

@kelson42 @MohitMaliDeveloper I'll review/test this. I'll open a ticket if I'll find something.

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