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

Using microG EN as library #1179

Closed
cgrigis opened this issue Sep 17, 2020 · 19 comments
Closed

Using microG EN as library #1179

cgrigis opened this issue Sep 17, 2020 · 19 comments

Comments

@cgrigis
Copy link
Contributor

cgrigis commented Sep 17, 2020

I am attempting to use microG as a library for the SwissCovid app as has been suggested by @mar-v-in.

My apologies in advance if I am doing something silly, just starting up with microG...

What I have done so far is remove the dependencies on GMS in my project, put the relevant modules in (play-services-core etc.), implement provideDiagnosisKeys() in the client lib, and minor fixes until the app compiles. Now the app starts running, but as soon as it tries to start EN (sending com.google.android.gms.nearby.exposurenotification.START Intent), it fails to bind in MultiConnectionKeeper.this.context.bindService() (returns false), eventually returning API_UNAVAILABLE to the app. I have tried to change GMS_PACKAGE_NAME to org.microg.gms or the app package, with no success.

From logcat:

2020-09-17 15:14:18.645 4340-5972/? W/ActivityManager: Unable to start service Intent { act=com.google.android.gms.nearby.exposurenotification.START pkg=org.microg.gms } U=0: not found

My questions are:

  • Any hints on what I should be changing to make it work?
  • Can the app as such even run on a phone with Google GMS installed (which is what I am testing on right now)? Should I rename all com.google.android.gms to avoid conflicts?
  • Am I missing something to enable microG, some sort of init()?

Thank you in advance for any help!

@cgrigis
Copy link
Contributor Author

cgrigis commented Sep 17, 2020

OK, some progress.

  • I had to change GMS_PACKAGE_NAME to the full package name of the app 🤦‍♂️ [wears brown paper bag over head].
  • After that, the service was binding, but would return FAILED_UNAUTHORIZED in ExposureNotificationService.handleServiceRequest(). I fixed this by using checkCallingOrSelfPermission() instead of checkCallingPermission(); not sure yet if that is the proper way (is this because, unlike normal usage of microG, in this case the caller and the service are in the same process?)
  • After a few more dependencies fixes, it looks like the app is running.

Now on to see if it does what it should be doing. :)

@mar-v-in
Copy link
Member

Just FYI, the following modules should be enough for your usecase:

play-services-base-api
play-services-base-core
play-services-base
play-services-basement
play-services-nearby-api
play-services-nearby-core-proto
play-services-nearby-core
play-services-nearby
play-services-tasks

@cgrigis
Copy link
Contributor Author

cgrigis commented Sep 17, 2020

Yes that is precisely the list that I have reached, by pulling the strings and see what was coming with. :)
Thank you for the confirmation!
More tests tomorrow...

@cgrigis
Copy link
Contributor Author

cgrigis commented Sep 18, 2020

As much as I can see, the app looks to be working: debug traces look good, and with a scanner, I can see beacons being generated, which stop when I change the app to stop advertising. I have to find out how to execute more sophisticated tests.
I now need to try running on a phone which does NOT have GMS installed, which is the real target.

@cgrigis
Copy link
Contributor Author

cgrigis commented Sep 24, 2020

Tried with a phone installed with stock LineageOS 17.1 (no microG).
The app at first did not work, but it turned out to be the way it was detecting whether GAEN was available: checking whether the com.google.android.gms.settings.EXPOSURE_NOTIFICATION_SETTINGS intent was resolved by an activity. This was easily fixed by adding a dummy activity with an intent filter.
So it looks like it's working without GMS!

@cgrigis
Copy link
Contributor Author

cgrigis commented Oct 7, 2020

I am trying to verify that SwissCovid bundled with microG as libraries properly computes an exposure. I have the following scenario (using the SwissCovid calibration app):

  1. Two phones are in in proximity for a while.
  2. One is declared with a positive diagnosis
  3. The other should receive a notification the next day.

Unfortunately, 3. never happens, and I am having a hard time debugging it.

@mar-v-in: I did not find unit or integration tests regarding matching... how did you proceed to verify proper operation?

@mar-v-in
Copy link
Member

mar-v-in commented Oct 7, 2020

@cgrigis I did the following tests:

  • RPI generation is tested using unit tests from the test vectors provided by Google
  • I tested scanning on real devices by verifying that RPIs emitted using a test app from another phones are stored in the database
  • I tested advertising on real devices by verifying that RPIs (as displayed in the settings) show up in a test app on another phone
  • I tested matching and risk calculation by picking one of the reported keys from the German CWA app, generating RPIs for it and inject those into the database of an emulator device as if they've been received and then see what the CWA app reports.
RPI generation code for reference Code to generate RPIs from within unit tests. Replace hex string and start interval number with appropriate values from real key. Prints out SQL statements to be executed on the `exposure.db`.
  public void testGenerateSample() {
      key = new TemporaryExposureKey.TemporaryExposureKeyBuilder()
              .setKeyData(ByteString.decodeHex("00024acc19391ca7523e1bdf8deeb018").toByteArray())
              .setRollingStartIntervalNumber(2668896)
              .setRollingPeriod(TestVectors.KEY_ROLLING_PERIOD_MULTIPLE_OF_ID_PERIOD)
              .build();
      for (int i = 0; i < TestVectors.KEY_ROLLING_PERIOD_MULTIPLE_OF_ID_PERIOD; i++) {
          byte[] rpi = CryptoKt.generateRpiId(key, key.getRollingStartIntervalNumber() + i);
          byte[] aem = CryptoKt.cryptAem(key, rpi, TestVectors.get_BLE_METADATA());
          System.out.println("INSERT INTO advertisements(rpi, aem, timestamp, rssi, duration) VALUES (X'" + ByteString.of(rpi).hex() + "', X'" + ByteString.of(aem).hex() + "', "+((long)(key.getRollingStartIntervalNumber() + i)) * 600000L+", 0, 600000);");
      }
  }

@cgrigis
Copy link
Contributor Author

cgrigis commented Oct 8, 2020

@mar-v-in Thank you for the details.

I tracked my issue down to an overflow in the finish*Matching() methods (or just finishMatching() in v0.2.12.203315) that ignored my key 🎆 (see #1215).

@cgrigis
Copy link
Contributor Author

cgrigis commented Oct 9, 2020

@mar-v-in As you pointed out in #1215, the fix already exists in master. However, would you agree that the issue exists in the latest release (v0.2.12.203315), and renders EN essentially non-functional, because exposures will not be detected, which one could argue is the whole point of it ;-) ?
Maybe there should be a new release with the fix, or at least a mention in the status page... What do you think?

@jellelicht
Copy link

jellelicht commented Oct 14, 2020

@cgrigis do you have a fork of the EN application you are working on? I would like to do something similar with the Dutch app and would love to see exactly how you did this with SwissCovid

@cgrigis
Copy link
Contributor Author

cgrigis commented Oct 19, 2020

@jellelicht There is a fork, but we're still working on it before releasing the code... should be a matter of a few days.

@oscaropenness
Copy link

should be a matter of a few days.

Any news on this? I would also be interested in a GMS free version of the SwissCovid App.
Would you mind sharing the .apk for testing purposes?

@cgrigis
Copy link
Contributor Author

cgrigis commented Dec 8, 2020

Any news on this? I would also be interested in a GMS free version of the SwissCovid App.
Would you mind sharing the .apk for testing purposes?

@oscaropenness There were some issues related to the backend that brought some delays due to testing, but there is now a very-alpha release of SwissCovid 1.2.0 available here: https://github.com/c4dt/dp3t-app-android-ch/releases/tag/nogaen-1-alpha2 . It uses the current master of microG instead of the latest release due to this blocking issue.
Keep in mind it is preliminary and not yet official, but if you would like to give it a test, I appreciate any feedback. :)

@oscaropenness
Copy link

oscaropenness commented Dec 8, 2020

if you would like to give it a test, I appreciate any feedback

Thank you very much!
Installed it under LineageOS 17.1 without microG and at a first glance everything seems to work. RaMBLE on another phone detects the beacon advertising the Exposure Notification as expected.
I cannot test the backend server, but at least the app does not throw any error messages.

Anything in particular you would like to have tested?

(Just mentioning some issues that are all related to this and might profit from your work.)
SwissCovid/swisscovid-app-android#59
SwissCovid/swisscovid-app-android#60
DP-3T/dp3t-sdk-android#10
SwissCovid/swisscovid-app-android#252

@cgrigis
Copy link
Contributor Author

cgrigis commented Dec 18, 2020

@oscaropenness Thank you for testing!
I will update soon now that there is a new release of microG.

The next step is to make a release on F-Droid. If anyone has experience with the process, I would be happy to have some pointers. :)

@Bubu
Copy link
Contributor

Bubu commented Dec 18, 2020

@cgrigis

https://codeberg.org/corona-contact-tracing-germany/cwa-android/src/branch/main/fdroidrepo/metadata/de.corona.tracing.yml + https://codeberg.org/corona-contact-tracing-germany/cwa-android/src/branch/main/metadata

feel free to ask any questions that come up.

@cgrigis
Copy link
Contributor Author

cgrigis commented Jan 21, 2021

@Bubu Thank you for the links! I will try to mimic this, but I have a quick question: SwissCovid depends on the DP3T-SDK library; what is the proper way to do this in F-Droid? Using a srclibs: entry pointing to the library, which F-Droid builds before building the app?

@Bubu
Copy link
Contributor

Bubu commented Jan 21, 2021

Yes, either as a srclib built in the fdroid build run or pushed to jcenter/mavencentral/included via jitpack.

@cgrigis
Copy link
Contributor Author

cgrigis commented May 6, 2021

A version of SwissCovid using microG as a library is now available on F-Droid.
Thank you @Bubu and @fynngodau for your help!

@cgrigis cgrigis closed this as completed May 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants