Skip to content

Conversation

@MohitMaliFtechiz
Copy link
Collaborator

@MohitMaliFtechiz MohitMaliFtechiz commented Jan 27, 2023

Fixes #2537
Fixes #3219

Whats the issue
We are not updating Adapter item after server is started.

How I fix this

  • I have added a new feature to this. when the server is already started then the checkbox will be showing there(which previously we hidden from the user) and the user can select and unselect the zim file there. It will automatically update on the Kiwix server (Basically if the server already started then it will restart the server with an updated zim file list).

  • Added UI test cases for testing this functionality, we have bypassed this test case on API level 24 since wifi and hotspot is not available on below Api Level 25 as mentioned in the official docs https://developer.android.com/studio/run/emulator-wifi
    Screenshot from 2023-09-26 15-02-29

  • Fixed memory leak in ZimHostFragment and CoreReaderFragment. When the application goes in the background from ZimHostFragment, KiwixReaderFragment/ZimHostFragment without starting the Service then the ReadAloudService, and HotspotService variables are not used and GC try to clear those objects but we are not clearing those objects, that's why memory leak is happening. So now we have free those objects if they are not in use.

  • Fixed ZimHostFragment failing on API level 33 (Android 13) because it has the SYSTEM_ALERT_WINDOW permission which is not grantable through code on Android 13, so we have removed this permission from our ZimHostFragment test as well as from our other test cases since we had added this to fix the test cases in Fixed Bookmark toggle is not ON for saved bookmarks #3473 because without this permission test cases were not launching on API level 21, and now our minimum SDK version is 24 so this permission is no longer needed.

org.kiwix.kiwixmobile.webserver.ZimHostFragmentTest > testZimHostFragment[test(AVD) - 13] �[31mFAILED �[0m
2023-10-20T14:00:47.4457130Z 	junit.framework.AssertionFailedError: Failed to grant permissions, see logcat for details
2023-10-20T14:00:47.4558590Z 	at junit.framework.Assert.fail(Assert.java:50)
  • In the ZimHostFragment, there were occasional test failures due to specific conditions. When reattempting the test, it failed to detect the 'WiFi connection detected' dialog because the server was already running. To resolve this issue, we have improved our test case. Now, we first check if the server is already running. If it is, we close the server before running the test case.
  • In previous test failures within the ZimHostFragment, there were instances where the zim file was unselected, causing our test case to fail to locate the required views. To mitigate this, we now check whether the zim file is selected. If it's not selected, we first select the zim file before running the test case.
failed: testZimHostFragment(org.kiwix.kiwixmobile.webserver.ZimHostFragmentTest)�[0m
TestRunner: ----- begin exception -----�[0m
TestRunner: java.lang.RuntimeException: No view found with text WiFi connection detected
  • In the LocalLibraryFragment test, there were cases where it was unable to locate the 'file_management_no_files' view due to variations in the order of test cases. This occurred because a zim file was sometimes present in the LocalLibrary. To address this, we now check for the presence of any zim files in the LocalLibrary and delete them before running our test case.
failed: testLocalLibrary(org.kiwix.kiwixmobile.nav.destination.library.LocalLibraryTest)�[0m
TestRunner: ----- begin exception -----�[0m
TestRunner: java.lang.RuntimeException: No view found with Id org.kiwix.kiwixmobile:id/file_management_no_files�[0m

@codecov
Copy link

codecov bot commented Jan 27, 2023

Codecov Report

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

Comparison is base (3babc62) 49.19% compared to head (969ad0d) 49.15%.
Report is 1 commits behind head on develop.

Additional details and impacted files
@@              Coverage Diff              @@
##             develop    #3218      +/-   ##
=============================================
- Coverage      49.19%   49.15%   -0.05%     
- Complexity      1071     1075       +4     
=============================================
  Files            285      285              
  Lines          10330    10365      +35     
  Branches        1378     1382       +4     
=============================================
+ Hits            5082     5095      +13     
- Misses          4432     4451      +19     
- Partials         816      819       +3     
Files Coverage Δ
...wix/kiwixmobile/core/utils/SharedPreferenceUtil.kt 64.58% <100.00%> (+3.94%) ⬆️
.../kiwix/kiwixmobile/core/main/CoreReaderFragment.kt 37.60% <90.90%> (+0.36%) ⬆️
...bile/core/webserver/wifi_hotspot/HotspotService.kt 34.84% <0.00%> (-1.09%) ⬇️
...iwix/kiwixmobile/core/webserver/WebServerHelper.kt 8.51% <0.00%> (-1.25%) ⬇️
...iwix/kiwixmobile/core/webserver/ZimHostFragment.kt 19.11% <23.80%> (+0.68%) ⬆️

... and 2 files with indirect coverage changes

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

@MohitMaliFtechiz MohitMaliFtechiz marked this pull request as ready for review January 27, 2023 10:22
@kelson42
Copy link
Collaborator

@MohitMaliDeveloper #3219 should be implemented, this was the solution, not this. I can not figure out why you did this although i have proposed #3219 (a new ticket was not necessary as we already have a bug ticket).

@MohitMaliFtechiz
Copy link
Collaborator Author

MohitMaliFtechiz commented Jan 27, 2023

@MohitMaliDeveloper #3219 should be implemented, this was the solution, not this. I can not figure out why you did this although i have proposed #3219 (a new ticket was not necessary as we already have a bug ticket).

hi @kelson42 ,

I have created separate ticket because there was changes on the UI so just to make sure we have direct reference to changes. To me its more sort of like new feature.

@MohitMaliFtechiz
Copy link
Collaborator Author

Solutions placed in #3219

@kelson42
Copy link
Collaborator

OK for me, @gouri-panda This is on you now for the revirw.

@kelson42 kelson42 force-pushed the Issue#2537 branch 3 times, most recently from 233c07f to f26a3a8 Compare January 30, 2023 10:59
@gouri-panda
Copy link
Collaborator

@MohitMaliFtechiz #3219 has already close. Why are you mentioning that it closes that issue?

@kelson42
Copy link
Collaborator

@gouri-panda ticket chaos, forget about it.

@gouri-panda
Copy link
Collaborator

@kelson42 Ok

gouri-panda

This comment was marked as duplicate.

Copy link
Collaborator

@gouri-panda gouri-panda left a comment

Choose a reason for hiding this comment

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

@MohitMaliDeveloper The update items still don't update after the server starts and the server crashes if the app goes in the background or switches to another application.

@MohitMaliFtechiz
Copy link
Collaborator Author

MohitMaliFtechiz commented Feb 2, 2023

@MohitMaliDeveloper The update items still don't update after the server starts and the server crashes if the app goes in the background or switches to another application.

@gouri-panda ,
I have some questions for server crashed

  • is this server crash is different from Hosted books doesn't show on the web #3118 ?.
  • Your mobile connected with WiFi or mobile network?
  • If you connected with WiFi and mobile internet is also on, then please turn off the mobile internet and only try with WiFi (for this case, i had faced this problem with server).

@gouri-panda
Copy link
Collaborator

is this server crash is different from #3118 ?.

No, it is completely different. In this case, the if the app goes to the background and if refresh the page after sometime it stops it crashes.

Your mobile connected with WiFi or mobile network?

Mobile Network.

If you connected with WiFi and mobile internet is also on, then please turn off the mobile internet and only try with WiFi (for this case, i had faced this problem with server).

No, I was not connected to WIFI. But if you face that problem also that isn't idol case. We should work on that too.

Also, I found a small memory leak. It's happening because we are forgetting to unbind some services in the ZimHostFragment.

@MohitMaliFtechiz
Copy link
Collaborator Author

MohitMaliFtechiz commented Feb 6, 2023

is this server crash is different from #3118 ?.

No, it is completely different. In this case, the if the app goes to the background and if refresh the page after sometime it stops it crashes.

Your mobile connected with WiFi or mobile network?

Mobile Network.

If you connected with WiFi and mobile internet is also on, then please turn off the mobile internet and only try with WiFi (for this case, i had faced this problem with server).

No, I was not connected to WIFI. But if you face that problem also that isn't idol case. We should work on that too.

Also, I found a small memory leak. It's happening because we are forgetting to unbind some services in the ZimHostFragment.

hi @gouri-panda , thanks

  • I have tested this again in both scenario (WIFI and mobile network) and it's working fine.
  • I'm attaching both video

WIFI

wifi.mp4

Mobile Network

Screenrecorder-2023-02-06-15-26-46-0.mp4

@MohitMaliFtechiz
Copy link
Collaborator Author

Also, I found a small memory leak. It's happening because we are forgetting to unbind some services in the ZimHostFragment.

@gouri-panda , can you please provide the logs?

@kelson42
Copy link
Collaborator

@gouri-panda any feedback?

@gouri-panda
Copy link
Collaborator

gouri-panda commented Feb 13, 2023

@MohitMaliDeveloper @kelson42 Sorry for the late reply. Here are the logs and video.

Logs

StrictMode policy violation; ~duration=24 ms: android.os.strictmode.DiskReadViolation
                                                                                                    	at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1596)
                                                                                                    	at libcore.io.BlockGuardOs.open(BlockGuardOs.java:249)
                                                                                                    	at libcore.io.IoBridge.open(IoBridge.java:478)
                                                                                                    	at java.io.FileOutputStream.<init>(FileOutputStream.java:236)
                                                                                                    	at java.io.FileOutputStream.<init>(FileOutputStream.java:186)
                                                                                                    	at java.io.FileWriter.<init>(FileWriter.java:90)
                                                                                                    	at com.android.server.am.OomAdjuster.updataKernelTopUid(OomAdjuster.java:2178)
                                                                                                    	at com.android.server.am.OomAdjuster.computeOomAdjLocked(OomAdjuster.java:2065)
                                                                                                    	at com.android.server.am.OomAdjuster.updateOomAdjLocked(OomAdjuster.java:344)
                                                                                                    	at com.android.server.am.OomAdjuster.updateOomAdjLocked(OomAdjuster.java:423)
                                                                                                    	at com.android.server.am.ActivityManagerService.updateOomAdjLocked(ActivityManagerService.java:19440)
                                                                                                    	at com.android.server.am.ActiveServices.bindServiceLocked(ActiveServices.java:2309)
                                                                                                    	at com.android.server.am.ActivityManagerService.bindIsolatedService(ActivityManagerService.java:16199)
                                                                                                    	at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:2645)
                                                                                                    	at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:3168)
                                                                                                    	at com.android.server.am.OppoActivityManagerService.onTransact(OppoActivityManagerService.java:169)
                                                                                                    	at android.os.Binder.execTransactInternal(Binder.java:1161)
                                                                                                    	at android.os.Binder.execTransact(Binder.java:1130)
                                                                                                    # via Binder call with stack:
                                                                                                    	at android.os.StrictMode.readAndHandleBinderCallViolations(StrictMode.java:2358)
                                                                                                    	at android.os.Parcel.readExceptionCode(Parcel.java:2334)
                                                                                                    	at android.os.Parcel.readException(Parcel.java:2295)
                                                                                                    	at android.app.IActivityManager$Stub$Proxy.bindIsolatedService(IActivityManager.java:6130)
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method)
                                                                                                    	at leakcanary.ServiceWatcher$install$4$2.invoke(ServiceWatcher.kt:93)
                                                                                                    	at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
                                                                                                    	at $Proxy2.bindIsolatedService(Unknown Source)
                                                                                                    	at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1888)
                                                                                                    	at android.app.ContextImpl.bindService(ContextImpl.java:1804)
                                                                                                    	at android.content.ContextWrapper.bindService(ContextWrapper.java:766)
                                                                                                    	at android.content.ContextWrapper.bindService(ContextWrapper.java:766)
                                                                                                    	at org.kiwix.kiwixmobile.webserver.ZimHostFragment.bindService(ZimHostFragment.kt:285)
                                                                                                    	at org.kiwix.kiwixmobile.webserver.ZimHostFragment.onStart(ZimHostFragment.kt:276)
                                                                                                    	at androidx.fragment.app.Fragment.performStart(Fragment.java:3162)
                                                                                                    	at androidx.fragment.app.FragmentStateManager.start(FragmentStateManager.java:588)
                                                                                                    	at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:279)
                                                                                                    	at androidx.fragment.app.FragmentStore.moveToExpectedState(FragmentStore.java:113)
                                                                                                    	at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1433)
                                                                                                    	at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2977)
                                                                                                    	at androidx.fragment.app.FragmentManager.dispatchStart(FragmentManager.java:2902)
                                                                                                    	at androidx.fragment.app.Fragment.performStart(Fragment.java:3171)
                                                                                                    	at androidx.fragment.app.FragmentStateManager.start(FragmentStateManager.java:588)
                                                                                                    	at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:279)
                                                                                                    	at androidx.fragment.app.FragmentStore.moveToExpectedState(FragmentStore.java:113)
                                                                                                    	at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1433)
                                                                                                    	at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2977)
                                                                                                    	at androidx.fragment.app.FragmentManager.dispatchStart(FragmentManager.java:2902)
                                                                                                    	at androidx.fragment.app.FragmentController.dispatchStart(FragmentController.java:274)
                                                                                                    	at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:359)
                                                                                                    	at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:210)
                                                                                                    	at org.kiwix.kiwixmobile.core.main.CoreMainActivity.onStart(CoreMainActivity.kt:107)
2023-02-13 14:10:58.170 11566-11566 StrictMode              org.kiwix.kiwixmobile                D  	at org.kiwix.kiwixmobile.main.KiwixMainActivity.onStart(KiwixMainActivity.kt:135)

Record_2023-02-13-14-17-38.mp4

@MohitMaliFtechiz
Copy link
Collaborator Author

MohitMaliFtechiz commented Feb 13, 2023

hi @gouri-panda , this is not the memory leak, it's StrictMode disk violation warning. it's device and android versions specific, below android 10 this error not happen but above android 10 it's happen, when we read any data from storage. I guess you are using above android 10 device.

We can avoid this by using permitDiskWrites() , permitDiskReads() method of StrictMode.ThreadPolicy.Builder() .

@gouri-panda
Copy link
Collaborator

@MohitMaliFtechiz But it still crashes the App. Have you tried successfully reproduce the crash?

@MohitMaliFtechiz
Copy link
Collaborator Author

@MohitMaliFtechiz But it still crashes the App. Have you tried successfully reproduce the crash?

@gouri-panda , I'm unable to reproduce this crash. it's working fine in my device (I have checked on multiple devices like in Samsung , Vivo , Redmi).

@gouri-panda
Copy link
Collaborator

@MohitMaliFtechiz Ok . I'll send the video of a crash in slack.

@kelson42
Copy link
Collaborator

kelson42 commented Oct 8, 2023

@gouri-panda Here too we need a new review pass. PR is mandatory for 3.8 and we want to release.

@kelson42
Copy link
Collaborator

@MohitMaliFtechiz Can you please rebase and fix conflicts?
@gouri-panda we really need your review! Waiting for weeks creates a significant overhead for Mothit.

@kelson42
Copy link
Collaborator

@MohitMaliFtechiz Why this PR is in draft?

@MohitMaliFtechiz
Copy link
Collaborator Author

MohitMaliFtechiz commented Oct 20, 2023

@kelson42 TestCases have failed on API level 33 twice after merging a PR, that's why I have marked this PR as draft. I have not tested this PR yet why the test cases are falling after merging another PR.

@kelson42
Copy link
Collaborator

@MohitMaliFtechiz OK, please complete once current issues around custom apps are fixed

@MohitMaliFtechiz MohitMaliFtechiz marked this pull request as ready for review October 27, 2023 14:01
@MohitMaliFtechiz
Copy link
Collaborator Author

@kelson42, @gouri-panda Test cases are fixed, now this PR is ready for review.

…nd unselect zim files when server already started
* Created a new class to match the how many checkbox is checked in the recyclerview, it will also help to test this type of functionality in future.
*  When the application goes in the background from `ZimHostFragment`, `KiwixReaderFragment/ZimHostFragment` without starting the Service then the `ReadAloudService`, and `HotspotService` variables are not used and GC try to clear those objects but we are not clearing those objects, that's why memory leak is happening. So now we have free those objects if they are not in use.
* We have made improvements to `ZimHostFragmentTest`. We added the `ACCESS_FINE_LOCATION` permission, which is required for running this test case on real devices. Additionally, we have enhanced the permission array and removed unnecessary permissions from the test case.
…it has the `SYSTEM_ALERT_WINDOW` permission which is not grantable through code on Android 13, so we have removed this permission from our `ZimHostFragment` test as well as from our other test cases since we had added this to fix the test cases because without this permission test cases were not launching on API level 21, and now our minimum SDK version is 24 so this permission is no longer needed.
* In the `ZimHostFragment`, there were occasional test failures due to specific conditions. When reattempting the test, it failed to detect the 'WiFi connection detected' dialog because the server was already running. To resolve this issue, we have improved our test case. Now, we first check if the server is already running. If it is, we close the server before running the test case.
* In previous test failures within the `ZimHostFragment`, there were instances where the zim file was unselected, causing our test case to fail to locate the required views. To mitigate this, we now check whether the zim file is selected. If it's not selected, we first select the zim file before running the test case.
* n the `LocalLibraryFragment` test, there were cases where it was unable to locate the 'file_management_no_files' view due to variations in the order of test cases. This occurred because a zim file was sometimes present in the `LocalLibrary`. To address this, we now check for the presence of any zim files in the `LocalLibrary` and delete them before running our test case.
@kelson42
Copy link
Collaborator

@gouri-panda Any update?

@kelson42
Copy link
Collaborator

Merging... without review :(

@kelson42 kelson42 merged commit f53809a into develop Nov 12, 2023
@kelson42 kelson42 deleted the Issue#2537 branch November 12, 2023 17:00
Copy link
Collaborator

@gouri-panda gouri-panda left a comment

Choose a reason for hiding this comment

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

@MohitMaliFtechiz Looks good to me! Thanks for the tests. I can't produce the error that i was talking about. Unfortunately, i can't find the commit that fixed.

@MohitMaliFtechiz
Copy link
Collaborator Author

Unfortunately, i can't find the commit that fixed.

@gouri-panda The issue was on the server side, after adapting the latest java-libkiwix that issue was automatically resolved.

@gouri-panda
Copy link
Collaborator

@MohitMaliFtechiz Ok. Thanks!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Checkbox always visible to user in Wifi Hotspot Host Books don't update on Application

5 participants