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

Backup/restore (WIP) #311

Closed
wants to merge 17 commits into from
Closed

Backup/restore (WIP) #311

wants to merge 17 commits into from

Conversation

TrianguloY
Copy link
Owner

@TrianguloY TrianguloY commented Jan 28, 2024

Even though it's still a work in progress, and things may (and probably will) change, I'm creating this PR for people to try it if you want (check the automatic bot reply).

Any comment will be greatly appreciated!

This will close #175

@github-actions github-actions bot added Core Change the core code (set automatically) Assets Changes some assets (set automatically) labels Jan 28, 2024
Copy link
Contributor

This PR builds correctly, here is the generated apk.
This unsigned version can be installed alongside the original app and should only be used for testing the changes, not for daily usage.

Download testing apk

You must be logged in for the link to work.
The link will expire at 2024-02-11T21:14:27Z.


This is an automatic comment created by a Github Action

private static final String CACHE_FOLDER = "cache/";
private static final String PREF_VALUE = "value";
private static final String PREF_TYPE = "type";
private static final String EMPTY = ".empty";

Check warning

Code scanning / Pmd (reported by Codacy)

Fields should be declared at the top of the class, before any method declarations, constructors, initializers or inner classes. Warning

Fields should be declared at the top of the class, before any method declarations, constructors, initializers or inner classes.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {

Check notice

Code scanning / Pmd (reported by Codacy)

Switch statements should be exhaustive, add a default case (or missing enum branches) Note

Switch statements should be exhaustive, add a default case (or missing enum branches)
Copy link
Contributor

This PR builds correctly, here is the generated apk.
This unsigned version can be installed alongside the original app and should only be used for testing the changes, not for daily usage.

Download testing apk

You must be logged in for the link to work.
The link will expire at 2024-02-12T22:30:26Z.


This is an automatic comment created by a Github Action

Copy link
Contributor

This PR builds correctly, here is the generated apk.
This unsigned version can be installed alongside the original app and should only be used for testing the changes, not for daily usage.

Download testing apk

You must be logged in for the link to work.
The link will expire at 2024-02-12T22:40:22Z.


This is an automatic comment created by a Github Action

@PabloOQ
Copy link
Collaborator

PabloOQ commented Jan 31, 2024

First I should mention that I haven't looked at the code so I can give proper feedback as a user and not a dev.

I have tested all 3 versions and it didn't work on my phone. When doing the backup it shows a toast "Can't create backup", however it doesn't explain why, leaving me totally clueless on the reason on why it can't. I looked in the android settings of the app and it has the same permissions as the release version (full network access), nothing about storage. In the version with the broken dialog it just stays at 0% and the dialog can't be closed.

The restore button does show me a file explorer to choose files, because I can't create a backup I could only test with the wrong file, I tested a random image from my gallery, it correctly shows a toast "Unable to restore the backup file", although I don't know if this is because it is not a .backup or because it has no permissions to read the file.

Deleting through the advanced options seemed to work correctly, I tested reordering modules, disabling them, some options inside the modules, modify some files and the tutorial pops again too.

@TrianguloY
Copy link
Owner Author

First I should mention that I haven't looked at the code so I can give proper feedback as a user and not a dev.

That's exactly what I need right now, thanks!

I have tested all 3 versions

In the version with the broken dialog it just stays at 0% and the dialog can't be closed.

Just need to check the last version, the others have issues or just lack improvements.

and it didn't work on my phone.

:O that's unexpected...but better to detect now than later! Can you remind me which android version do you have?

When doing the backup it shows a toast "Can't create backup", however it doesn't explain why, leaving me totally clueless on the reason on why it can't.

Exception management is not yet implemented, although it's difficult to do in this case. I'll try to improve it though.
For now you can try to check the logcat, there you should find the good-old red stacktrace with more info.

I looked in the android settings of the app and it has the same permissions as the release version (full network access), nothing about storage.

According to android (and tested on a couple devices) you don't need any permission to create a file in the downloads folder. Which is strange...I know

The restore button does show me a file explorer to choose files, because I can't create a backup I could only test with the wrong file, I tested a random image from my gallery, it correctly shows a toast "Unable to restore the backup file", although I don't know if this is because it is not a .backup or because it has no permissions to read the file.

It's expecting a zip file, so that's probably the reason. You can test with any zip (it should just not restore anything) but I'll try to upload a sample zip here so you can test. I'll also try to improve the error messages here too.

Deleting through the advanced options seemed to work correctly, I tested reordering modules, disabling them, some options inside the modules, modify some files and the tutorial pops again too.

Well, at least something is working. But the delete option does not imply zips at all so...that's probably the reason.

Copy link
Contributor

This PR builds correctly, here is the generated apk.
This unsigned version can be installed alongside the original app and should only be used for testing the changes, not for daily usage.

Download testing apk

You must be logged in for the link to work.
The link will expire at 2024-02-14T22:28:09Z.


This is an automatic comment created by a Github Action

@TrianguloY
Copy link
Owner Author

OK, so, you do need the permission for some specific android version (between 6.0 and 11).
I'll add the popup to grant it next, but for now if you manually add it from the settings it should hopefully work!

@PabloOQ
Copy link
Collaborator

PabloOQ commented Feb 1, 2024

According to android (and tested on a couple devices) you don't need any permission to create a file in the downloads folder. Which is strange...I know

Not so weird, I think Firefox Desktop does the same with addons, but I might be wrong, I know I have seen this behaviour somewhere, in fact I was suspecting this was the case here too, still I wanted to check.

Can you remind me which android version do you have?

Yeah, about that... I have been stuck with a Huawei phone (kind of ironic considering I joined this project mainly because of privacy with the ClearURLs module) since I broke my last phone, and this one is from the "bad batch", when Huawei was banned from using google services, which translates to "a lot of broken stuff because missing libraries", maybe it's because of that? Although, looking at the error it doesn't seem that way. In any case, android 10, EMUI 10.1.0.

It's expecting a zip file, so that's probably the reason. You can test with any zip (it should just not restore anything) but I'll try to upload a sample zip here so you can test. I'll also try to improve the error messages here too.

Check this out, coincidentally the GitHub download link for the testing APK is... a .zip file! So of course I had to test it with the app itself, I honestly find it very funny. Jokes aside, it says "Backup restored", and obviusly doesn't restore anything.

but for now if you manually add it from the settings it should hopefully work!

Still it doesn't work.

java.io.FileNotFoundException: /storage/emulated/0/Download/UrlChecker_20240201164930.backup: open failed: EACCES (Permission denied)
    at libcore.io.IoBridge.open(IoBridge.java:496)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:235)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:186)
    at com.trianguloy.urlchecker.utilities.wrappers.ZipWriter.<init>(ZipWriter.java:25)
    at com.trianguloy.urlchecker.activities.BackupActivity.lambda$backup$4(BackupActivity.java:144)
    at com.trianguloy.urlchecker.activities.BackupActivity.$r8$lambda$jpT3LsUIhEHLbiRWyMFub3o39mM(Unknown Source:0)
    at com.trianguloy.urlchecker.activities.BackupActivity$$ExternalSyntheticLambda6.accept(Unknown Source:6)
    at com.trianguloy.urlchecker.utilities.wrappers.ProgressDialog.lambda$new$0(ProgressDialog.java:43)
    at com.trianguloy.urlchecker.utilities.wrappers.ProgressDialog.$r8$lambda$mHOfL2_pyMAAGoscqxjichzblcc(Unknown Source:0)
    at com.trianguloy.urlchecker.utilities.wrappers.ProgressDialog$$ExternalSyntheticLambda0.run(Unknown Source:4)
    at java.lang.Thread.run(Thread.java:929)

@TrianguloY
Copy link
Owner Author

Yeah, about that... I have been stuck with a Huawei phone (kind of ironic considering I joined this project mainly because of privacy with the ClearURLs module) since I broke my last phone, and this one is from the "bad batch", when Huawei was banned from using google services, which translates to "a lot of broken stuff because missing libraries", maybe it's because of that? Although, looking at the error it doesn't seem that way. In any case, android 10, EMUI 10.1.0.

No, I don't think so. Maybe, but it would be strange. I'll test with an android 10 emulator.

Check this out, coincidentally the GitHub download link for the testing APK is... a .zip file! So of course I had to test it with the app itself, I honestly find it very funny. Jokes aside, it says "Backup restored", and obviusly doesn't restore anything.

Oh, right! At least we can confirm that the app can read zips, so that's something.
And yes, it doesn't restores anything because the data is not there, but it's not deleting existing data either because I didn't want to delete things just in case you are restoring a backup that was made without that specific data, even if you are selecting it on the screen. I think this makes sense, but I would like to hear other opinions.

Still it doesn't work.

Oh :(
Let's see if the emulator can reproduce the issue.

@davidj77
Copy link

davidj77 commented Feb 2, 2024

Hi, I'm testing it by using a Moto phone with Android 7
I was able to create a backup by giving access to phone storage and restore it with no fails.
Gallery_1706869138558

Copy link
Contributor

github-actions bot commented Feb 2, 2024

This PR builds correctly, here is the generated apk.
This unsigned version can be installed alongside the original app and should only be used for testing the changes, not for daily usage.

Download testing apk

You must be logged in for the link to work.
The link will expire at 2024-02-16T19:35:40Z.


This is an automatic comment created by a Github Action

@TrianguloY
Copy link
Owner Author

Good and bad news. I think I fixed the permission issue, turns out there is an official Android way to ask the user to create a file, and it can be created anywhere (it even asks to confirm if it exists!).
The bad news is that it requires api 19 (Android 4.4, Kitkat, from 2013) and current min is 14 (Android 4.0.1 – 4.0.2, Ice cream sandwich, from 2011).

I started adding the code for those older versions, but it was becoming a hassle and even failing in some situations.

So instead, I decided to increase the minSdk and remove support for those older versions. I don't like it, I feel that older devices are still capable of running most apps and if they can't it's just because developers don't spend a bit of time trying to support both. In this case however the burden of supporting the previous version is too much for me.
If there is a user using android 4.3 or less and really wants to keep using the app, please tell me and I may consider keeping the minSdk (but probably disabling the backup feature). Otherwise...that min needs to increase from time to time, and I think this is the best moment to do so.

@PabloOQ
Copy link
Collaborator

PabloOQ commented Feb 3, 2024

It works now! And without requiring any extra permissions, great.

I decided to increase the minSdk and remove support for those older versions

I am sorry to hear that, but at least it wasn't a big jump.

Copy link
Contributor

github-actions bot commented Feb 4, 2024

This PR builds correctly, here is the generated apk.
This unsigned version can be installed alongside the original app and should only be used for testing the changes, not for daily usage.

Download testing apk

You must be logged in for the link to work.
The link will expire at 2024-02-18T11:04:44Z.


This is an automatic comment created by a Github Action

Copy link
Contributor

github-actions bot commented Feb 5, 2024

This PR builds correctly, here is the generated apk.
This unsigned version can be installed alongside the original app and should only be used for testing the changes, not for daily usage.

Download testing apk

You must be logged in for the link to work.
The link will expire at 2024-02-19T21:30:27Z.


This is an automatic comment created by a Github Action

ask before restoring file
changed file extension and registered the app with it (may not always work, blame android)
advanced options are restored on reload
tweaked strings
Copy link
Contributor

This PR builds correctly, here is the generated apk.
This unsigned version can be installed alongside the original app and should only be used for testing the changes, not for daily usage.

Download testing apk

You must be logged in for the link to work.
The link will expire at 2024-02-24T22:52:06Z.


This is an automatic comment created by a Github Action

@TrianguloY TrianguloY self-assigned this Feb 10, 2024
Copy link
Contributor

This PR builds correctly, here is the generated apk.
This unsigned version can be installed alongside the original app and should only be used for testing the changes, not for daily usage.

Download testing apk

You must be logged in for the link to work.
The link will expire at 2024-03-09T11:59:00Z.


This is an automatic comment created by a Github Action

@TrianguloY
Copy link
Owner Author

With these, all the minimal required things I can think of are fulfilled, so unless a bug is discovered I'll merge this on the following days.

There are some things and improvements I would like to add, but to avoid postponing this update even more I'll release this and improve later.

Thanks for all of you that helped with testing!

@PabloOQ
Copy link
Collaborator

PabloOQ commented Feb 26, 2024

I tried it yesterday and it worked as intended. I have already uninstalled it, but I have one question on the behaviour. If I want to backup ClearURLs custom rules, would I need to toggle the cache files?

@TrianguloY
Copy link
Owner Author

TrianguloY commented Feb 26, 2024

No, it is considered user data.

ClearUrls setting has both "official" and custom rules on the same object (the idea was for the user to be able to edit the rules themselves). I could have added logic to know if the official subobject was modified or not, but to keep things simple for now I just considered it user data. This means that the backup does contains some redundant data, but as I said I wanted to keep things simple for now.

Currently, the only thing considered cache is the hosts database (the one you need to press "build" to generate, not the settings) which internally is not editable by the user. This consists on pretty big files, that's why I added a toggle for them.

Btw, if you need to check what is being saved, just open it! The backup is a zip!

@TrianguloY TrianguloY closed this Mar 3, 2024
@TrianguloY TrianguloY deleted the backupRestore branch March 3, 2024 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Assets Changes some assets (set automatically) Core Change the core code (set automatically)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Export/Import app configuration
3 participants