Add provideDiagnosisKeys() implementation

This commit is contained in:
Christian Grigis 2020-09-04 19:28:57 +02:00 committed by Marvin W
parent a2afbe07fd
commit bd20634bd9
2 changed files with 57 additions and 2 deletions

View File

@ -27,5 +27,17 @@ public class ProvideDiagnosisKeysParams extends AutoSafeParcelable {
@Field(5)
public String token;
public ProvideDiagnosisKeysParams(IStatusCallback callback, List<TemporaryExposureKey> keys, List<ParcelFileDescriptor> keyFiles, ExposureConfiguration configuration, String token) {
this(callback, keyFiles, configuration, token);
this.keys = keys;
}
public ProvideDiagnosisKeysParams(IStatusCallback callback, List<ParcelFileDescriptor> keyFiles, ExposureConfiguration configuration, String token) {
this.callback = callback;
this.keyFiles = keyFiles;
this.configuration = configuration;
this.token = token;
}
public static final Creator<ProvideDiagnosisKeysParams> CREATOR = new AutoCreator<>(ProvideDiagnosisKeysParams.class);
}

View File

@ -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<Api.ApiOptions.NoOptions> implements ExposureNotificationClient {
@ -41,6 +47,8 @@ public class ExposureNotificationClientImpl extends GoogleApi<Api.ApiOptions.NoO
super(context, API);
}
private static final String TAG = "ENClientImpl";
@Override
public Task<Void> start() {
return scheduleTask((PendingGoogleApiCall<Void, ExposureNotificationApiClient>) (client, completionSource) -> {
@ -126,8 +134,43 @@ public class ExposureNotificationClientImpl extends GoogleApi<Api.ApiOptions.NoO
}
@Override
public Task<Void> provideDiagnosisKeys(List<File> keys, ExposureConfiguration configuration, String token) {
return null;
public Task<Void> provideDiagnosisKeys(List<File> keyFiles, ExposureConfiguration configuration, String token) {
return scheduleTask((PendingGoogleApiCall<Void, ExposureNotificationApiClient>) (client, completionSource) -> {
List<ParcelFileDescriptor> 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