From bd20634bd985355628f22ea9ace5e7d78c5e2fbe Mon Sep 17 00:00:00 2001 From: Christian Grigis Date: Fri, 4 Sep 2020 19:28:57 +0200 Subject: [PATCH] Add provideDiagnosisKeys() implementation --- .../internal/ProvideDiagnosisKeysParams.java | 12 +++++ .../ExposureNotificationClientImpl.java | 47 ++++++++++++++++++- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/internal/ProvideDiagnosisKeysParams.java b/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/internal/ProvideDiagnosisKeysParams.java index e47f3478..d291d8c9 100644 --- a/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/internal/ProvideDiagnosisKeysParams.java +++ b/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/internal/ProvideDiagnosisKeysParams.java @@ -27,5 +27,17 @@ public class ProvideDiagnosisKeysParams extends AutoSafeParcelable { @Field(5) public String token; + public ProvideDiagnosisKeysParams(IStatusCallback callback, List keys, List keyFiles, ExposureConfiguration configuration, String token) { + this(callback, keyFiles, configuration, token); + this.keys = keys; + } + + public ProvideDiagnosisKeysParams(IStatusCallback callback, List keyFiles, ExposureConfiguration configuration, String token) { + this.callback = callback; + this.keyFiles = keyFiles; + this.configuration = configuration; + this.token = token; + } + public static final Creator CREATOR = new AutoCreator<>(ProvideDiagnosisKeysParams.class); } diff --git a/play-services-nearby/src/main/java/org/microg/gms/nearby/ExposureNotificationClientImpl.java b/play-services-nearby/src/main/java/org/microg/gms/nearby/ExposureNotificationClientImpl.java index 54afe746..5dec37ea 100644 --- a/play-services-nearby/src/main/java/org/microg/gms/nearby/ExposureNotificationClientImpl.java +++ b/play-services-nearby/src/main/java/org/microg/gms/nearby/ExposureNotificationClientImpl.java @@ -6,6 +6,8 @@ package org.microg.gms.nearby; import android.content.Context; +import android.os.ParcelFileDescriptor; +import android.util.Log; import com.google.android.gms.common.api.Api; import com.google.android.gms.common.api.GoogleApi; @@ -25,6 +27,7 @@ import com.google.android.gms.nearby.exposurenotification.internal.IExposureInfo import com.google.android.gms.nearby.exposurenotification.internal.IExposureSummaryCallback; import com.google.android.gms.nearby.exposurenotification.internal.ITemporaryExposureKeyListCallback; import com.google.android.gms.nearby.exposurenotification.internal.IsEnabledParams; +import com.google.android.gms.nearby.exposurenotification.internal.ProvideDiagnosisKeysParams; import com.google.android.gms.nearby.exposurenotification.internal.StartParams; import com.google.android.gms.nearby.exposurenotification.internal.StopParams; import com.google.android.gms.tasks.Task; @@ -32,6 +35,9 @@ import com.google.android.gms.tasks.Task; import org.microg.gms.common.api.PendingGoogleApiCall; import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; import java.util.List; public class ExposureNotificationClientImpl extends GoogleApi implements ExposureNotificationClient { @@ -41,6 +47,8 @@ public class ExposureNotificationClientImpl extends GoogleApi start() { return scheduleTask((PendingGoogleApiCall) (client, completionSource) -> { @@ -126,8 +134,43 @@ public class ExposureNotificationClientImpl extends GoogleApi provideDiagnosisKeys(List keys, ExposureConfiguration configuration, String token) { - return null; + public Task provideDiagnosisKeys(List keyFiles, ExposureConfiguration configuration, String token) { + return scheduleTask((PendingGoogleApiCall) (client, completionSource) -> { + List fds = new ArrayList<>(keyFiles.size()); + for (File kf: keyFiles) { + ParcelFileDescriptor fd; + try { + fd = ParcelFileDescriptor.open(kf, ParcelFileDescriptor.MODE_READ_ONLY); + } catch (FileNotFoundException e) { + for (ParcelFileDescriptor ofd : fds) { + try { + ofd.close(); + } catch (IOException e2) { + Log.w(TAG, "Failed to close file", e2); + } + } + completionSource.setException(e); + return; + } + fds.add(fd); + } + + ProvideDiagnosisKeysParams params = new ProvideDiagnosisKeysParams(new IStatusCallback.Stub() { + @Override + public void onResult(Status status) { + if (status == Status.SUCCESS) { + completionSource.setResult(null); + } else { + completionSource.setException(new RuntimeException("Status: " + status)); + } + } + }, fds, configuration, token); + try { + client.provideDiagnosisKeys(params); + } catch (Exception e) { + completionSource.setException(e); + } + }); } @Override