Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Having the exposure database survive an Android Upgrade #1238

Closed
validev opened this issue Sep 25, 2020 · 21 comments
Closed

Having the exposure database survive an Android Upgrade #1238

validev opened this issue Sep 25, 2020 · 21 comments
Assignees
Labels
duplicate This issue or pull request already exists enhancement Improvement of an existing feature

Comments

@validev
Copy link

validev commented Sep 25, 2020

I need a way to have my exposure database survive an Lineage 16.1 -> Lineage 17.1 upgrade.

I don't want to lose my 14/14 rating and don't want to carry two devices with me for 4 weeks to have a seamless transition.

Any please don't say "out of scope". German corona app is the poster boy of all exposure noti. apps and you should be able to solve that together with Google devs.

@validev validev added the enhancement Improvement of an existing feature label Sep 25, 2020
@validev
Copy link
Author

validev commented Sep 25, 2020

Ok .. just found the dumpsite you shove these kind of issues to .. nothing to show for since at least 18.6.20 .. so two weeks of keys will go down the drain I guess m(

@daimpi
Copy link

daimpi commented Sep 25, 2020

Are you talking about a switch to a new device or an OTA update? I don't think OTA updates delete any data, even updating to a new Android version should be save. Not entirely sure why LineageOS would be different.
If you want to transfer to a new device: that's currently not possible afaik unless you have root, because Google doesn't allow ENF data to be exported.

@validev
Copy link
Author

validev commented Sep 25, 2020

Not talking about OTA. Clean flash including wipe of data partition. Hell, I'd be content with a howto to migrate the right files from /data/data/com.google.android.gms .. of course I have root.

@daimpi
Copy link

daimpi commented Sep 25, 2020

of course I have root.

great 👍

In this case migrating ENF + CWA data should be possible. I personally dunno how to do it but maybe @kbobrowski & @mh- have an idea? 🙂

@validev
Copy link
Author

validev commented Sep 25, 2020

I started by dumping these dirs and files to another device, but I get a weird error msg from GMS, so I guess sth is missing

/data/data/com.google.android.gms/
app_contact-tracing-self-tracing-key-db
app_contact-tracing-contact-record-db
app_en_diagnosis_keys
app_en-exposure-result-storage-db
app_en-matching-request-db
app_en-attempted-keys-data-store-db

/data/data/com.google.android.gms/shared_prefs/contact_tracing_data_quality_record_db.xml

@validev
Copy link
Author

validev commented Sep 25, 2020

not sure if it's enough to copy the ENF stuff though .. maybe CWA data is necessary, too, to keep the two components in sync?

@kbobrowski
Copy link
Contributor

kbobrowski commented Sep 25, 2020

@validev I think you should copy over at least app_contact-tracing-self-tracing-key-db and app_contact-tracing-contact-record-db, first db contains data with your Temporary Exposure Key (so used if you want to notify others about your positive test), and second one contains received Rolling Proximity Identifiers, from which you can infer if you were in contact with infected person. Not sure how the first db will behave on fresh CWA install, second one should be not affected.

If you want to be on the safe side regarding being notified about exposure status, then make sure to have a backup of the app_contact-tracing-contact-record-db. Then you can infer exposure status even without CWA, using https://github.com/mh-/corona-warn-companion-android (this would require to copy this DB over to the phone after flashing), or even without any app using https://github.com/mh-/diagnosis-keys

@mh-
Copy link
Contributor

mh- commented Sep 26, 2020

What is the weird GMS error message?
One thing I noted was: concurrent writes to LevelDB directories were problematic.
So I ended up copying stuff back to the device only in Recovery Mode, when GMS was inactive. Then booted into Normal Mode, and GMS would just continue to use the databases I just wrote.

Of course, making CWA keep 14/14 would involve playing with the device’s local date while re-installing it.

@MikeMcC399
Copy link
Contributor

My Samsung Galaxy preserved the Exposure Notification database when I upgraded Android from 9 to 10, but I didn't wipe the device or do a factory reset. The request from @validev requires that the device is wiped, so that is different.

The wishlist item #8 "Backup exposure history to transfer to new/reseted phone" would cover the needs if it gets implemented, which would normally need the cooperation of Google to do. So far there has been little transparency in Google's planned enhancements to the Android Exposure Notification System.

@validev
Copy link
Author

validev commented Sep 26, 2020

What is the weird GMS error message?
"Ursache: 3 Etwas ist schiefgelaufen. Fehler bei der Kommunikation mit der Google Schnittstelle (39506)"

"com.google.android.gms.com mon.api.ApiException: 39506: com.google.android.gms.leveldb.LevelDbloErrorException: IO error: /data/user/0/com.google.android.gms/app_en-exposure-result-storage-db/LOCK: Permission denied"

It's worth noting that, of course, I looked at file/directory permissions. They don't seem to make any difference. The msg appears if the LOCK file is mode 600, 660, 666, even doesn't exist at all. All changes were made in Recovery Mode, with many rebootes inbetween - boy, Android dev. is cumbersome.

@mh-
Copy link
Contributor

mh- commented Sep 26, 2020

I don't think you will gain much from restoring app_en-exposure-result-storage-db- this is just used for generating the reports.
As @kbobrowski wrote, just restore app_contact-tracing-self-tracing-key-db and app_contact-tracing-contact-record-db - this should be possible in recovery mode. All the other databases will most likely be recreated by GMS without problems.

@validev
Copy link
Author

validev commented Sep 26, 2020

Got it working now. Thanks for the support, guys.

@heinezen
Copy link
Member

Hey everyone,

as @MikeMcC399 already pointed out, this feature request is very similar to corona-warn-app/cwa-wishlist#8. @validev Even if the issue is old, I suggest making an additional comment there, so that it's back on the radar again. I will close this issue now, since your problem seems to be resolved. Discussion about the feature request can happen in the wishlist issue.

Thanks.


Corona-Warn-App Open Source Team

@heinezen
Copy link
Member

Duplicate of corona-warn-app/cwa-wishlist#8

@SAMUD
Copy link

SAMUD commented Oct 22, 2020

I just saw this and want to give my 2cents:

I use "SwiftBackup" to backup my apps (including data) on a rooted phone. However, everytime I restore the Corona-app I am getting FC / Crashs when opening the app, so I need to wipe all data / cache and loose everything.

I remember in the beginning of the Corona-App I sometimes got a Error associated with the Database when this happened. Today, the app just freezed on the SplashScreen when I restored it from the Backup.

@daimpi
Copy link

daimpi commented Oct 22, 2020

@SAMUD by

I need to wipe all data / cache and loose everything.

you mean you delete the CWA data, or are you actually deleting the ENF data?

B/c if you're just wiping the CWA data, you don't actually loose much (except if you have a test pending) and the "0 days active" is just a temporary visual problem without any functional implications.

You can even get around this visual problem by using the instructions laid out here.

@fakerli
Copy link

fakerli commented Oct 29, 2020

Got it working now. Thanks for the support, guys.

What did you copy? I tried to copy app_contact-tracing-self-tracing-key-db and app_contact-tracing-contact-record-db and it worked. But it seems that any new contact won't be tracked anymore. Any ideas?
@validev

@mh-
Copy link
Contributor

mh- commented Oct 29, 2020

Can you copy in Recovery Mode? Then, after starting up again in Normal Mode, it should work.
(I did have problems when I tried to copy in Normal Mode, while the framework was running.)

@fakerli
Copy link

fakerli commented Oct 29, 2020

I did copy in recovery mode. It worked but it didn't fetch new data. I copied the files from 26th of october and since then I had no new data. If I delete both dirs it fetches new data from today.
@mh- : Which folders did you copy?

@mh-
Copy link
Contributor

mh- commented Oct 29, 2020

I copied those two folders, but I also remember that access rights (incl. SELinux specific rights) were important.

This is my restore script for the RPIs (for recovery mode):

#!/usr/bin/env bash

chmod 771 app_contact-tracing-contact-record-db/
chmod 600 app_contact-tracing-contact-record-db/*
source dbowner
source dbgroup
gtar --owner=$DBOWNER --group=$DBGROUP -cvf rpi.tar app_contact-tracing-contact-record-db/
adb push rpi.tar /data/local/tmp/
adb shell 'tar -C /data/data/com.google.android.gms/ -xvf /data/local/tmp/rpi.tar'

adb shell 'chown -R `cat /data/data/com.google.android.gms/app_contact-tracing-contact-record-db/dbowner`   /data/data/com.google.android.gms/app_contact-tracing-contact-record-db'
adb shell 'chgrp -R `cat /data/data/com.google.android.gms/app_contact-tracing-contact-record-db/dbgroup`   /data/data/com.google.android.gms/app_contact-tracing-contact-record-db'
adb shell 'chcon -R `cat /data/data/com.google.android.gms/app_contact-tracing-contact-record-db/dbcontext` /data/data/com.google.android.gms/app_contact-tracing-contact-record-db/*'
adb shell 'rm /data/data/com.google.android.gms/app_contact-tracing-contact-record-db/dbowner'
adb shell 'rm /data/data/com.google.android.gms/app_contact-tracing-contact-record-db/dbgroup'
adb shell 'rm /data/data/com.google.android.gms/app_contact-tracing-contact-record-db/dbcontext'

# ls -lZ /data/data/com.google.android.gms/app_contact-tracing-contact-record-db/
# u:object_r:app_data_file:s0:c512,c768 CURRENT

rm rpi.tar

@fakerli
Copy link

fakerli commented Oct 30, 2020

@mh- : It seems to work but i cannot gather new contacts. If I uninstall reinstall corona-warn, it starts from scratch but then i lose my old contacts.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists enhancement Improvement of an existing feature
Projects
None yet
Development

No branches or pull requests

8 participants