From f2bc5f5baad7b9e5796d931b99d18b6ba1c46a6d Mon Sep 17 00:00:00 2001 From: Christian Grigis Date: Thu, 22 Oct 2020 19:16:15 +0200 Subject: [PATCH] Add some methods to client library --- .../ExposureNotificationStatusCodes.java | 3 + .../exposurenotification/Constants.java | 3 + .../ExposureNotificationClient.java | 16 ++ .../nearby/ExposureNotificationApiClient.java | 30 ++++ .../ExposureNotificationClientImpl.java | 146 ++++++++++++++++++ 5 files changed, 198 insertions(+) diff --git a/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/ExposureNotificationStatusCodes.java b/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/ExposureNotificationStatusCodes.java index 4efe5508..35e98886 100644 --- a/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/ExposureNotificationStatusCodes.java +++ b/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/ExposureNotificationStatusCodes.java @@ -20,6 +20,7 @@ public class ExposureNotificationStatusCodes extends CommonStatusCodes { public static final int FAILED_TEMPORARILY_DISABLED = 39505; public static final int FAILED_DISK_IO = 39506; public static final int FAILED_UNAUTHORIZED = 39507; + public static final int FAILED_RATE_LIMITED = 39508; public static String getStatusCodeString(final int statusCode) { switch (statusCode) { @@ -39,6 +40,8 @@ public class ExposureNotificationStatusCodes extends CommonStatusCodes { return "FAILED_DISK_IO"; case FAILED_UNAUTHORIZED: return "FAILED_UNAUTHORIZED"; + case FAILED_RATE_LIMITED: + return "FAILED_RATE_LIMITED"; default: return CommonStatusCodes.getStatusCodeString(statusCode); } diff --git a/play-services-nearby-api/src/main/java/org/microg/gms/nearby/exposurenotification/Constants.java b/play-services-nearby-api/src/main/java/org/microg/gms/nearby/exposurenotification/Constants.java index c55d2ddc..288ff47e 100644 --- a/play-services-nearby-api/src/main/java/org/microg/gms/nearby/exposurenotification/Constants.java +++ b/play-services-nearby-api/src/main/java/org/microg/gms/nearby/exposurenotification/Constants.java @@ -9,6 +9,9 @@ public class Constants { public static final String ACTION_EXPOSURE_NOTIFICATION_SETTINGS = "com.google.android.gms.settings.EXPOSURE_NOTIFICATION_SETTINGS"; public static final String ACTION_EXPOSURE_NOT_FOUND = "com.google.android.gms.exposurenotification.ACTION_EXPOSURE_NOT_FOUND"; public static final String ACTION_EXPOSURE_STATE_UPDATED = "com.google.android.gms.exposurenotification.ACTION_EXPOSURE_STATE_UPDATED"; + public static final String ACTION_SERVICE_STATE_UPDATED = "com.google.android.gms.exposurenotification.ACTION_SERVICE_STATE_UPDATED"; public static final String EXTRA_EXPOSURE_SUMMARY = "com.google.android.gms.exposurenotification.EXTRA_EXPOSURE_SUMMARY"; + public static final String EXTRA_SERVICE_STATE = "com.google.android.gms.exposurenotification.EXTRA_SERVICE_STATE"; public static final String EXTRA_TOKEN = "com.google.android.gms.exposurenotification.EXTRA_TOKEN"; + public static final String TOKEN_A = "TYZWQ32170AXEUVCDW7A"; } diff --git a/play-services-nearby/src/main/java/com/google/android/gms/nearby/exposurenotification/ExposureNotificationClient.java b/play-services-nearby/src/main/java/com/google/android/gms/nearby/exposurenotification/ExposureNotificationClient.java index f7bdd897..3d9d36e0 100644 --- a/play-services-nearby/src/main/java/com/google/android/gms/nearby/exposurenotification/ExposureNotificationClient.java +++ b/play-services-nearby/src/main/java/com/google/android/gms/nearby/exposurenotification/ExposureNotificationClient.java @@ -23,8 +23,15 @@ public interface ExposureNotificationClient extends HasApiKey getVersion(); + + Task getCalibrationConfidence(); Task start(); @@ -39,4 +46,13 @@ public interface ExposureNotificationClient extends HasApiKey getExposureSummary(String token); Task> getExposureInformation(String token); + + Task> getExposureWindows(String token); + Task> getExposureWindows(); + + Task> getDailySummaries(DailySummariesConfig config); + + Task setDiagnosisKeysDataMapping(DiagnosisKeysDataMapping mapping); + + Task getDiagnosisKeysDataMapping(); } diff --git a/play-services-nearby/src/main/java/org/microg/gms/nearby/ExposureNotificationApiClient.java b/play-services-nearby/src/main/java/org/microg/gms/nearby/ExposureNotificationApiClient.java index 8ecee441..cd7e5611 100644 --- a/play-services-nearby/src/main/java/org/microg/gms/nearby/ExposureNotificationApiClient.java +++ b/play-services-nearby/src/main/java/org/microg/gms/nearby/ExposureNotificationApiClient.java @@ -9,12 +9,18 @@ import android.content.Context; import android.os.IBinder; import android.os.RemoteException; +import com.google.android.gms.nearby.exposurenotification.internal.GetCalibrationConfidenceParams; +import com.google.android.gms.nearby.exposurenotification.internal.GetDailySummariesParams; +import com.google.android.gms.nearby.exposurenotification.internal.GetDiagnosisKeysDataMappingParams; import com.google.android.gms.nearby.exposurenotification.internal.GetExposureInformationParams; import com.google.android.gms.nearby.exposurenotification.internal.GetExposureSummaryParams; +import com.google.android.gms.nearby.exposurenotification.internal.GetExposureWindowsParams; import com.google.android.gms.nearby.exposurenotification.internal.GetTemporaryExposureKeyHistoryParams; +import com.google.android.gms.nearby.exposurenotification.internal.GetVersionParams; import com.google.android.gms.nearby.exposurenotification.internal.INearbyExposureNotificationService; 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.SetDiagnosisKeysDataMappingParams; import com.google.android.gms.nearby.exposurenotification.internal.StartParams; import com.google.android.gms.nearby.exposurenotification.internal.StopParams; @@ -34,6 +40,14 @@ public class ExposureNotificationApiClient extends GmsClient getVersion() { + return scheduleTask((PendingGoogleApiCall) (client, completionSource) -> { + GetVersionParams params = new GetVersionParams(new ILongCallback.Stub() { + @Override + public void onResult(Status status, long result) { + if (status == Status.SUCCESS) { + completionSource.setResult(result); + } else { + completionSource.setException(new ApiException(status)); + } + } + }); + try { + client.getVersion(params); + } catch (Exception e) { + completionSource.setException(e); + } + }); + } + + @Override + public Task getCalibrationConfidence() { + return scheduleTask((PendingGoogleApiCall) (client, completionSource) -> { + GetCalibrationConfidenceParams params = new GetCalibrationConfidenceParams(new IIntCallback.Stub() { + @Override + public void onResult(Status status, int result) { + if (status == Status.SUCCESS) { + completionSource.setResult(result); + } else { + completionSource.setException(new ApiException(status)); + } + } + }); + try { + client.getCalibrationConfidence(params); + } catch (Exception e) { + completionSource.setException(e); + } + }); + } + @Override public Task start() { return scheduleTask((PendingGoogleApiCall) (client, completionSource) -> { @@ -216,6 +273,95 @@ public class ExposureNotificationClientImpl extends GoogleApi> getExposureWindows(String token) { + return scheduleTask((PendingGoogleApiCall, ExposureNotificationApiClient>) (client, completionSource) -> { + GetExposureWindowsParams params = new GetExposureWindowsParams(new IExposureWindowListCallback.Stub() { + @Override + public void onResult(Status status, List result) { + if (status == Status.SUCCESS) { + completionSource.setResult(result); + } else { + completionSource.setException(new ApiException(status)); + } + } + }, token); + try { + client.getExposureWindows(params); + } catch (Exception e) { + completionSource.setException(e); + } + }); + } + + @Override + public Task> getExposureWindows() { + return getExposureWindows(TOKEN_A); + } + + @Override + public Task> getDailySummaries(DailySummariesConfig config) { + return scheduleTask((PendingGoogleApiCall, ExposureNotificationApiClient>) (client, completionSource) -> { + GetDailySummariesParams params = new GetDailySummariesParams(new IDailySummaryListCallback.Stub() { + @Override + public void onResult(Status status, List result) { + if (status == Status.SUCCESS) { + completionSource.setResult(result); + } else { + completionSource.setException(new ApiException(status)); + } + } + }, config); + try { + client.getDailySummaries(params); + } catch (Exception e) { + completionSource.setException(e); + } + }); + } + + @Override + public Task setDiagnosisKeysDataMapping(DiagnosisKeysDataMapping mapping) { + return scheduleTask((PendingGoogleApiCall) (client, completionSource) -> { + SetDiagnosisKeysDataMappingParams params = new SetDiagnosisKeysDataMappingParams(new IStatusCallback.Stub() { + @Override + public void onResult(Status status) { + if (status == Status.SUCCESS) { + completionSource.setResult(null); + } else { + completionSource.setException(new ApiException(status)); + } + } + }, mapping); + try { + client.setDiagnosisKeysDataMapping(params); + } catch (Exception e) { + completionSource.setException(e); + } + }); + } + + @Override + public Task getDiagnosisKeysDataMapping() { + return scheduleTask((PendingGoogleApiCall) (client, completionSource) -> { + GetDiagnosisKeysDataMappingParams params = new GetDiagnosisKeysDataMappingParams(new IDiagnosisKeysDataMappingCallback.Stub() { + @Override + public void onResult(Status status, DiagnosisKeysDataMapping result) { + if (status == Status.SUCCESS) { + completionSource.setResult(result); + } else { + completionSource.setException(new ApiException(status)); + } + } + }); + try { + client.getDiagnosisKeysDataMapping(params); + } catch (Exception e) { + completionSource.setException(e); + } + }); + } + @Override public ApiKey getApiKey() { return null;