From f2bc5f5baad7b9e5796d931b99d18b6ba1c46a6d Mon Sep 17 00:00:00 2001 From: Christian Grigis Date: Thu, 22 Oct 2020 19:16:15 +0200 Subject: [PATCH 01/72] 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; From 42da7aa2fa01daf702884df9820830d9b36a1c11 Mon Sep 17 00:00:00 2001 From: Christian Grigis Date: Tue, 27 Oct 2020 10:42:24 +0100 Subject: [PATCH 02/72] Handle callback when returning early --- .../exposurenotification/ExposureNotificationServiceImpl.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/ExposureNotificationServiceImpl.kt b/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/ExposureNotificationServiceImpl.kt index b734fb6e..0ebe73c5 100644 --- a/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/ExposureNotificationServiceImpl.kt +++ b/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/ExposureNotificationServiceImpl.kt @@ -86,7 +86,10 @@ class ExposureNotificationServiceImpl(private val context: Context, private val } override fun start(params: StartParams) { - if (ExposurePreferences(context).enabled) return + if (ExposurePreferences(context).enabled) { + params.callback.onResult(Status.SUCCESS) + return + } lifecycleScope.launchWhenStarted { val status = confirmPermission(CONFIRM_ACTION_START) if (status.isSuccess) { From 5ef114413174c5afab229609071e0c08a82e93f0 Mon Sep 17 00:00:00 2001 From: Christian Grigis Date: Mon, 9 Nov 2020 21:15:52 +0100 Subject: [PATCH 03/72] Mark deprecated APIs and add the two other versions of provideDiagnosisKeys() --- .../DiagnosisKeyFileProvider.java | 31 +++++++++++++++++++ .../ExposureConfiguration.java | 1 + .../ExposureInformation.java | 1 + .../exposurenotification/ExposureSummary.java | 1 + .../ExposureNotificationClient.java | 10 ++++++ .../ExposureNotificationClientImpl.java | 12 +++++++ 6 files changed, 56 insertions(+) create mode 100644 play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/DiagnosisKeyFileProvider.java diff --git a/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/DiagnosisKeyFileProvider.java b/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/DiagnosisKeyFileProvider.java new file mode 100644 index 00000000..621201a0 --- /dev/null +++ b/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/DiagnosisKeyFileProvider.java @@ -0,0 +1,31 @@ +/* + * SPDX-FileCopyrightText: 2020, microG Project Team + * SPDX-License-Identifier: Apache-2.0 + * Notice: Portions of this file are reproduced from work created and shared by Google and used + * according to terms described in the Creative Commons 4.0 Attribution License. + * See https://developers.google.com/readme/policies for details. + */ + +package com.google.android.gms.nearby.exposurenotification; + +import org.microg.gms.common.PublicApi; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +/** + * Provider which holds a list of diagnosis key files and can open/supply them one by one as they are ready to be processed. + */ +@PublicApi +public class DiagnosisKeyFileProvider { + private List files; + + public DiagnosisKeyFileProvider(List files) { + this.files = new ArrayList<>(files); + } + + public List getFiles() { + return files; + } +} diff --git a/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/ExposureConfiguration.java b/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/ExposureConfiguration.java index 5fe7f650..01cb2a10 100644 --- a/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/ExposureConfiguration.java +++ b/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/ExposureConfiguration.java @@ -12,6 +12,7 @@ import org.microg.safeparcel.AutoSafeParcelable; import java.util.Arrays; +@Deprecated public class ExposureConfiguration extends AutoSafeParcelable { @Field(1) private int minimumRiskScore; diff --git a/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/ExposureInformation.java b/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/ExposureInformation.java index 8157ce64..fb42ba2d 100644 --- a/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/ExposureInformation.java +++ b/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/ExposureInformation.java @@ -13,6 +13,7 @@ import org.microg.safeparcel.AutoSafeParcelable; import java.util.Arrays; import java.util.Date; +@Deprecated public class ExposureInformation extends AutoSafeParcelable { @Field(1) private long dateMillisSinceEpoch; diff --git a/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/ExposureSummary.java b/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/ExposureSummary.java index f1fb086a..91852b4b 100644 --- a/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/ExposureSummary.java +++ b/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/ExposureSummary.java @@ -12,6 +12,7 @@ import org.microg.safeparcel.AutoSafeParcelable; import java.util.Arrays; +@Deprecated public class ExposureSummary extends AutoSafeParcelable { @Field(1) private int daysSinceLastExposure; 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 3d9d36e0..38d586fb 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 @@ -24,9 +24,12 @@ public interface ExposureNotificationClient extends HasApiKey getVersion(); @@ -41,12 +44,19 @@ public interface ExposureNotificationClient extends HasApiKey> getTemporaryExposureKeyHistory(); + @Deprecated Task provideDiagnosisKeys(List keys, ExposureConfiguration configuration, String token); + @Deprecated + Task provideDiagnosisKeys(List keys); + Task provideDiagnosisKeys(DiagnosisKeyFileProvider provider); + @Deprecated Task getExposureSummary(String token); + @Deprecated Task> getExposureInformation(String token); + @Deprecated Task> getExposureWindows(String token); Task> getExposureWindows(); 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 ef723432..583797c8 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 @@ -17,6 +17,7 @@ import com.google.android.gms.common.api.internal.ApiKey; import com.google.android.gms.common.api.internal.IStatusCallback; import com.google.android.gms.nearby.exposurenotification.DailySummariesConfig; import com.google.android.gms.nearby.exposurenotification.DailySummary; +import com.google.android.gms.nearby.exposurenotification.DiagnosisKeyFileProvider; import com.google.android.gms.nearby.exposurenotification.DiagnosisKeysDataMapping; import com.google.android.gms.nearby.exposurenotification.ExposureConfiguration; import com.google.android.gms.nearby.exposurenotification.ExposureInformation; @@ -231,6 +232,17 @@ public class ExposureNotificationClientImpl extends GoogleApi provideDiagnosisKeys(List keyFiles) { + return provideDiagnosisKeys(keyFiles, null, TOKEN_A); + } + + @Override + public Task provideDiagnosisKeys(DiagnosisKeyFileProvider provider) { + // NOTE: This will probably need to be modified according to how the provider is used + return provideDiagnosisKeys(provider.getFiles()); + } + @Override public Task getExposureSummary(String token) { return scheduleTask((PendingGoogleApiCall) (client, completionSource) -> { From 12905d6621b870dff1e17ad92026bab224185336 Mon Sep 17 00:00:00 2001 From: Christian Grigis Date: Mon, 9 Nov 2020 21:16:25 +0100 Subject: [PATCH 04/72] Add new fields to TemporaryExposureKey --- .../TemporaryExposureKey.java | 42 ++++++++++++++++++- .../exposurenotification/Constants.java | 1 + 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/TemporaryExposureKey.java b/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/TemporaryExposureKey.java index 15f02f4d..4514c9a4 100644 --- a/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/TemporaryExposureKey.java +++ b/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/TemporaryExposureKey.java @@ -8,6 +8,7 @@ package com.google.android.gms.nearby.exposurenotification; +import org.microg.gms.nearby.exposurenotification.Constants; import org.microg.safeparcel.AutoSafeParcelable; import java.util.Arrays; @@ -22,15 +23,24 @@ public class TemporaryExposureKey extends AutoSafeParcelable { private int transmissionRiskLevel; @Field(4) private int rollingPeriod; + @Field(5) + @ReportType + private int reportType; + @Field(6) + int daysSinceOnsetOfSymptoms; + + public static final int DAYS_SINCE_ONSET_OF_SYMPTOMS_UNKNOWN = Constants.DAYS_SINCE_ONSET_OF_SYMPTOMS_UNKNOWN; private TemporaryExposureKey() { } - TemporaryExposureKey(byte[] keyData, int rollingStartIntervalNumber, @RiskLevel int transmissionRiskLevel, int rollingPeriod) { + TemporaryExposureKey(byte[] keyData, int rollingStartIntervalNumber, @RiskLevel int transmissionRiskLevel, int rollingPeriod, @ReportType int reportType, int daysSinceOnsetOfSymptoms) { this.keyData = (keyData == null ? new byte[0] : keyData); this.rollingStartIntervalNumber = rollingStartIntervalNumber; this.transmissionRiskLevel = transmissionRiskLevel; this.rollingPeriod = rollingPeriod; + this.reportType = reportType; + this.daysSinceOnsetOfSymptoms = daysSinceOnsetOfSymptoms; } public byte[] getKeyData() { @@ -50,6 +60,15 @@ public class TemporaryExposureKey extends AutoSafeParcelable { return rollingPeriod; } + @ReportType + public int getReportType() { + return reportType; + } + + int getDaysSinceOnsetOfSymptoms() { + return daysSinceOnsetOfSymptoms; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -60,6 +79,8 @@ public class TemporaryExposureKey extends AutoSafeParcelable { if (rollingStartIntervalNumber != that.rollingStartIntervalNumber) return false; if (transmissionRiskLevel != that.transmissionRiskLevel) return false; if (rollingPeriod != that.rollingPeriod) return false; + if (reportType != that.reportType) return false; + if (daysSinceOnsetOfSymptoms != that.daysSinceOnsetOfSymptoms) return false; return Arrays.equals(keyData, that.keyData); } @@ -69,6 +90,8 @@ public class TemporaryExposureKey extends AutoSafeParcelable { result = 31 * result + rollingStartIntervalNumber; result = 31 * result + transmissionRiskLevel; result = 31 * result + rollingPeriod; + result = 31 * result + reportType; + result = 31 * result + daysSinceOnsetOfSymptoms; return result; } @@ -79,6 +102,8 @@ public class TemporaryExposureKey extends AutoSafeParcelable { ", rollingStartIntervalNumber=" + rollingStartIntervalNumber + ", transmissionRiskLevel=" + transmissionRiskLevel + ", rollingPeriod=" + rollingPeriod + + ", reportType=" + reportType + + ", daysSinceOnsetOfSymptoms=" + daysSinceOnsetOfSymptoms + '}'; } @@ -88,6 +113,9 @@ public class TemporaryExposureKey extends AutoSafeParcelable { @RiskLevel private int transmissionRiskLevel; private int rollingPeriod; + @ReportType + private int reportType; + private int daysSinceOnsetOfSymptoms = DAYS_SINCE_ONSET_OF_SYMPTOMS_UNKNOWN; public TemporaryExposureKeyBuilder setKeyData(byte[] keyData) { this.keyData = Arrays.copyOf(keyData, keyData.length); @@ -109,8 +137,18 @@ public class TemporaryExposureKey extends AutoSafeParcelable { return this; } + public TemporaryExposureKeyBuilder setReportType(@ReportType int reportType) { + this.reportType = reportType; + return this; + } + + public TemporaryExposureKeyBuilder setDaysSinceOnsetOfSymptoms(int daysSinceOnsetOfSymptoms) { + this.daysSinceOnsetOfSymptoms = daysSinceOnsetOfSymptoms; + return this; + } + public TemporaryExposureKey build() { - return new TemporaryExposureKey(keyData, rollingStartIntervalNumber, transmissionRiskLevel, rollingPeriod); + return new TemporaryExposureKey(keyData, rollingStartIntervalNumber, transmissionRiskLevel, rollingPeriod, reportType, daysSinceOnsetOfSymptoms); } } 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 288ff47e..b87dbfbe 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 @@ -14,4 +14,5 @@ public class Constants { 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"; + public static final int DAYS_SINCE_ONSET_OF_SYMPTOMS_UNKNOWN = Integer.MAX_VALUE; } From 0bb46d6af655c4d479bbecbf2ae060680c383cf2 Mon Sep 17 00:00:00 2001 From: Marvin W Date: Fri, 6 Nov 2020 19:31:03 +0100 Subject: [PATCH 05/72] Update a few dependencies --- build.gradle | 10 +++++----- gradle/wrapper/gradle-wrapper.properties | 5 ++++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 539c6bb8..e5e466ab 100644 --- a/build.gradle +++ b/build.gradle @@ -9,17 +9,17 @@ buildscript { ext.safeParcelVersion = '1.6.0' ext.wearableVersion = '0.1.1' - ext.kotlinVersion = '1.3.72' + ext.kotlinVersion = '1.4.10' ext.coroutineVersion = '1.3.7' ext.annotationVersion = '1.1.0' - ext.appcompatVersion = '1.1.0' + ext.appcompatVersion = '1.2.0' ext.coreVersion = '1.3.0' ext.fragmentVersion = '1.2.5' ext.lifecycleVersion = '2.2.0' - ext.mediarouterVersion = '1.1.0' + ext.mediarouterVersion = '1.2.0' ext.multidexVersion = '2.0.1' - ext.navigationVersion = '2.3.0' + ext.navigationVersion = '2.3.1' ext.preferenceVersion = '1.1.1' ext.recyclerviewVersion = '1.1.0' @@ -28,7 +28,7 @@ buildscript { ext.volleyVersion = '1.1.1' ext.wireVersion = '3.2.2' - ext.androidBuildGradleVersion = '3.6.3' + ext.androidBuildGradleVersion = '4.1.0' ext.androidBuildVersionTools = '29.0.3' diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 21a8fe40..e2993c8f 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,8 @@ +# SPDX-FileCopyrightText: 2015, microG Project Team +# SPDX-License-Identifier: CC0-1.0 + distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.4-all.zip From 8006b2c8a9229021df5dddc418b0f6468af07c56 Mon Sep 17 00:00:00 2001 From: Marvin W Date: Fri, 6 Nov 2020 19:07:16 +0100 Subject: [PATCH 06/72] ProviderInstaller: Use conscrypt-gmscore instead of original conscrypt Helps with bunch of apps that use OkHttp --- .../gms/security/ProviderInstaller.java | 61 +++++ .../build.gradle | 28 +++ .../src/main/AndroidManifest.xml | 9 + .../security/ProviderInstallerImpl.java | 220 ++++++++++++++++++ play-services-core/build.gradle | 6 +- .../security/ProviderInstallerImpl.java | 184 --------------- settings.gradle | 1 + 7 files changed, 321 insertions(+), 188 deletions(-) create mode 100644 play-services-basement/src/main/java/com/google/android/gms/security/ProviderInstaller.java create mode 100644 play-services-conscrypt-provider-core/build.gradle create mode 100644 play-services-conscrypt-provider-core/src/main/AndroidManifest.xml create mode 100644 play-services-conscrypt-provider-core/src/main/java/com/google/android/gms/common/security/ProviderInstallerImpl.java delete mode 100644 play-services-core/src/main/java/com/google/android/gms/common/security/ProviderInstallerImpl.java diff --git a/play-services-basement/src/main/java/com/google/android/gms/security/ProviderInstaller.java b/play-services-basement/src/main/java/com/google/android/gms/security/ProviderInstaller.java new file mode 100644 index 00000000..74481ff9 --- /dev/null +++ b/play-services-basement/src/main/java/com/google/android/gms/security/ProviderInstaller.java @@ -0,0 +1,61 @@ +/* + * SPDX-FileCopyrightText: 2020, microG Project Team + * SPDX-License-Identifier: Apache-2.0 + * Notice: Portions of this file are reproduced from work created and shared by Google and used + * according to terms described in the Creative Commons 4.0 Attribution License. + * See https://developers.google.com/readme/policies for details. + */ + +package com.google.android.gms.security; + +import android.content.Context; +import android.content.Intent; + +import java.security.Provider; + +/** + * A utility class for installing a dynamically updatable {@link Provider} to replace the platform default provider. + */ +public class ProviderInstaller { + public static final String PROVIDER_NAME = "GmsCore_OpenSSL"; + + /** + * Installs the dynamically updatable security provider, if it's not already installed. + * + * @throws GooglePlayServicesRepairableException + * @throws GooglePlayServicesNotAvailableException + */ + public static void installIfNeeded(Context context) { + + } + + /** + * Asynchronously installs the dynamically updatable security provider, if it's not already installed. This method must be called on the UI thread. + * + * @param context + * @param listener called when the installation completes + */ + public static void installIfNeededAsync(Context context, ProviderInstallListener listener) { + if (listener != null) listener.onProviderInstalled(); + } + + /** + * Callback for notification of the result of provider installation. + */ + public interface ProviderInstallListener { + /** + * Called when installing the provider fails. This method is always called on the UI thread. + *

+ * Implementers may use {@code errorCode} with the standard UI elements provided by {@link GoogleApiAvailability}; or {@code recoveryIntent} to implement custom UI. + * + * @param errorCode error code for the failure, for use with {@link GoogleApiAvailability#showErrorDialogFragment(Activity, int, int)} or {@link GoogleApiAvailability#showErrorNotification(Context, ConnectionResult)} + * @param recoveryIntent if non-null, an intent that can be used to install or update Google Play Services such that the provider can be installed + */ + void onProviderInstallFailed(int errorCode, Intent recoveryIntent); + + /** + * Called when installing the provider succeeds. This method is always called on the UI thread. + */ + void onProviderInstalled(); + } +} diff --git a/play-services-conscrypt-provider-core/build.gradle b/play-services-conscrypt-provider-core/build.gradle new file mode 100644 index 00000000..71c785b0 --- /dev/null +++ b/play-services-conscrypt-provider-core/build.gradle @@ -0,0 +1,28 @@ +/* + * SPDX-FileCopyrightText: 2020, microG Project Team + * SPDX-License-Identifier: Apache-2.0 + */ + +apply plugin: 'com.android.library' + +dependencies { + implementation "org.microg.gms:conscrypt-gmscore:2.5.1" + implementation "androidx.annotation:annotation:$annotationVersion" + implementation project(":play-services-base-core") +} + +android { + compileSdkVersion androidCompileSdk + buildToolsVersion "$androidBuildVersionTools" + + defaultConfig { + versionName version + minSdkVersion androidMinSdk + targetSdkVersion androidTargetSdk + } + + compileOptions { + sourceCompatibility = 1.8 + targetCompatibility = 1.8 + } +} diff --git a/play-services-conscrypt-provider-core/src/main/AndroidManifest.xml b/play-services-conscrypt-provider-core/src/main/AndroidManifest.xml new file mode 100644 index 00000000..b06f1e9f --- /dev/null +++ b/play-services-conscrypt-provider-core/src/main/AndroidManifest.xml @@ -0,0 +1,9 @@ + + + + + + diff --git a/play-services-conscrypt-provider-core/src/main/java/com/google/android/gms/common/security/ProviderInstallerImpl.java b/play-services-conscrypt-provider-core/src/main/java/com/google/android/gms/common/security/ProviderInstallerImpl.java new file mode 100644 index 00000000..b1d3851e --- /dev/null +++ b/play-services-conscrypt-provider-core/src/main/java/com/google/android/gms/common/security/ProviderInstallerImpl.java @@ -0,0 +1,220 @@ +/* + * SPDX-FileCopyrightText: 2020, microG Project Team + * SPDX-License-Identifier: Apache-2.0 + */ + +package com.google.android.gms.common.security; + +import android.content.Context; +import android.content.pm.ApplicationInfo; +import android.os.Build; +import android.os.Process; +import android.util.Log; + +import androidx.annotation.Keep; + +import com.google.android.gms.org.conscrypt.Conscrypt; +import com.google.android.gms.org.conscrypt.NativeCrypto; + +import org.microg.gms.common.PackageUtils; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.security.Provider; +import java.security.Security; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Set; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; + +import static com.google.android.gms.security.ProviderInstaller.PROVIDER_NAME; + +@Keep +public class ProviderInstallerImpl { + private static final String TAG = "GmsProviderInstaller"; + private static final List DISABLED = Collections.unmodifiableList(Arrays.asList("com.bankid.bus")); + + private static final Object lock = new Object(); + private static Provider provider; + + private static String getRealSelfPackageName(Context context) { + String packageName = PackageUtils.packageFromProcessId(context, Process.myPid()); + if (packageName != null && packageName.contains(".")) return packageName; + try { + Method getBasePackageName = Context.class.getDeclaredMethod("getBasePackageName"); + packageName = (String) getBasePackageName.invoke(context); + if (packageName != null) return packageName; + } catch (Exception e) { + + } + if (Build.VERSION.SDK_INT >= 29) { + return context.getOpPackageName(); + } + Context applicationContext = context.getApplicationContext(); + if (applicationContext != null) { + return applicationContext.getPackageName(); + } + return context.getPackageName(); + } + + @Keep + public static void insertProvider(Context context) { + String packageName = getRealSelfPackageName(context); + try { + if (DISABLED.contains(packageName)) { + Log.d(TAG, "Package " + packageName + " is excluded from usage of provider installer"); + return; + } + if (Security.getProvider(PROVIDER_NAME) != null) { + Log.d(TAG, "Provider already inserted in " + packageName); + return; + } + + synchronized (lock) { + initProvider(context, packageName); + + if (provider == null) { + Log.w(TAG, "Failed to initialize Conscrypt"); + return; + } + + int res = Security.insertProviderAt(provider, 1); + if (res == 1) { + Security.setProperty("ssl.SocketFactory.provider", "com.google.android.gms.org.conscrypt.OpenSSLSocketFactoryImpl"); + Security.setProperty("ssl.ServerSocketFactory.provider", "com.google.android.gms.org.conscrypt.OpenSSLServerSocketFactoryImpl"); + + SSLContext sslContext = SSLContext.getInstance("Default"); + SSLContext.setDefault(sslContext); + HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory()); + + Log.d(TAG, "Installed default security provider " + PROVIDER_NAME); + } else { + throw new SecurityException("Failed to install security provider " + PROVIDER_NAME + ", result: " + res); + } + } + } catch (Throwable e) { + Log.w(TAG, e); + } + } + + private static void initProvider(Context context, String packageName) { + Log.d(TAG, "Initializing provider for " + packageName); + + try { + provider = Conscrypt.newProviderBuilder().setName(PROVIDER_NAME).defaultTlsProtocol("TLSv1.2").build(); + } catch (UnsatisfiedLinkError e) { + Log.w(TAG, "Could not link conscrypt via default loader, trying manual loading"); + + try { + loadConscryptDirect(context, packageName); + provider = Conscrypt.newProviderBuilder().setName(PROVIDER_NAME).defaultTlsProtocol("TLSv1.2").build(); + } catch (Exception e2) { + Log.w(TAG, e2); + } + } + } + + private static void loadConscryptDirect(Context context, String packageName) throws Exception { + ApplicationInfo otherAppInfo = context.getPackageManager().getApplicationInfo(packageName, 0); + + // TODO: Move manual loading into helper function (as it is also used in both maps implementations) + String primaryCpuAbi = (String) ApplicationInfo.class.getField("primaryCpuAbi").get(otherAppInfo); + if (primaryCpuAbi != null) { + String path = "lib/" + primaryCpuAbi + "/libconscrypt_jni.so"; + File cacheFile = new File(context.createPackageContext(packageName, 0).getCacheDir().getAbsolutePath() + "/.gmscore/" + path); + cacheFile.getParentFile().mkdirs(); + File apkFile = new File(context.getPackageCodePath()); + if (!cacheFile.exists() || cacheFile.lastModified() < apkFile.lastModified()) { + ZipFile zipFile = new ZipFile(apkFile); + ZipEntry entry = zipFile.getEntry(path); + if (entry != null) { + copyInputStream(zipFile.getInputStream(entry), new FileOutputStream(cacheFile)); + } else { + Log.d(TAG, "Can't load native library: " + path + " does not exist in " + apkFile); + } + } + Log.d(TAG, "Loading conscrypt_jni from " + cacheFile.getPath()); + System.load(cacheFile.getAbsolutePath()); + + Class clazz = NativeCrypto.class; + + Field loadError = clazz.getDeclaredField("loadError"); + loadError.setAccessible(true); + loadError.set(null, null); + + Method clinit = clazz.getDeclaredMethod("clinit"); + clinit.setAccessible(true); + + Method get_cipher_names = clazz.getDeclaredMethod("get_cipher_names", String.class); + get_cipher_names.setAccessible(true); + + Method cipherSuiteToJava = clazz.getDeclaredMethod("cipherSuiteToJava", String.class); + cipherSuiteToJava.setAccessible(true); + + Method EVP_has_aes_hardware = clazz.getDeclaredMethod("EVP_has_aes_hardware"); + EVP_has_aes_hardware.setAccessible(true); + + Field f = clazz.getDeclaredField("SUPPORTED_TLS_1_2_CIPHER_SUITES_SET"); + f.setAccessible(true); + + Set SUPPORTED_TLS_1_2_CIPHER_SUITES_SET = (Set) f.get(null); + f = clazz.getDeclaredField("SUPPORTED_LEGACY_CIPHER_SUITES_SET"); + f.setAccessible(true); + + Set SUPPORTED_LEGACY_CIPHER_SUITES_SET = (Set) f.get(null); + f = clazz.getDeclaredField("SUPPORTED_TLS_1_2_CIPHER_SUITES"); + f.setAccessible(true); + + try { + clinit.invoke(null); + + String[] allCipherSuites = (String[]) get_cipher_names.invoke(null, "ALL:!DHE"); + int size = allCipherSuites.length; + + String[] SUPPORTED_TLS_1_2_CIPHER_SUITES = new String[size / 2 + 2]; + for (int i = 0; i < size; i += 2) { + String cipherSuite = (String) cipherSuiteToJava.invoke(null, allCipherSuites[i]); + + SUPPORTED_TLS_1_2_CIPHER_SUITES[i / 2] = cipherSuite; + SUPPORTED_TLS_1_2_CIPHER_SUITES_SET.add(cipherSuite); + + SUPPORTED_LEGACY_CIPHER_SUITES_SET.add(allCipherSuites[i + 1]); + } + SUPPORTED_TLS_1_2_CIPHER_SUITES[size / 2] = "TLS_EMPTY_RENEGOTIATION_INFO_SCSV"; + SUPPORTED_TLS_1_2_CIPHER_SUITES[size / 2 + 1] = "TLS_FALLBACK_SCSV"; + f.set(null, SUPPORTED_TLS_1_2_CIPHER_SUITES); + + f = clazz.getDeclaredField("HAS_AES_HARDWARE"); + f.setAccessible(true); + f.set(null, (int) EVP_has_aes_hardware.invoke(null) == 1); + + } catch (InvocationTargetException inner) { + if (inner.getTargetException() instanceof UnsatisfiedLinkError) { + loadError.set(null, inner.getTargetException()); + } + } + } + } + + private static final void copyInputStream(InputStream in, OutputStream out) throws IOException { + byte[] buffer = new byte[1024]; + int len; + + while ((len = in.read(buffer)) >= 0) + out.write(buffer, 0, len); + + in.close(); + out.close(); + } +} diff --git a/play-services-core/build.gradle b/play-services-core/build.gradle index f32042e3..0f3758b8 100644 --- a/play-services-core/build.gradle +++ b/play-services-core/build.gradle @@ -29,7 +29,6 @@ configurations { dependencies { implementation "com.squareup.wire:wire-runtime:$wireVersion" implementation "de.hdodenhof:circleimageview:1.3.0" - implementation "org.conscrypt:conscrypt-android:2.1.0" // TODO: Switch to upstream once raw requests are merged // https://github.com/vitalidze/chromecast-java-api-v2/pull/99 // implementation "su.litvak.chromecast:api-v2:0.10.4" @@ -44,6 +43,7 @@ dependencies { implementation project(':firebase-auth-core') implementation project(':play-services-base-core') implementation project(':play-services-base-core-ui') + implementation project(':play-services-conscrypt-provider-core') implementation project(':play-services-location-core') withNearbyImplementation project(':play-services-nearby-core') withNearbyImplementation project(':play-services-nearby-core-ui') @@ -62,11 +62,9 @@ dependencies { implementation "androidx.multidex:multidex:$multidexVersion" implementation "androidx.appcompat:appcompat:$appcompatVersion" implementation "androidx.mediarouter:mediarouter:$mediarouterVersion" - implementation "androidx.preference:preference:$preferenceVersion" + implementation "androidx.preference:preference-ktx:$preferenceVersion" // Navigation - implementation "androidx.navigation:navigation-fragment:$navigationVersion" - implementation "androidx.navigation:navigation-ui:$navigationVersion" implementation "androidx.navigation:navigation-fragment-ktx:$navigationVersion" implementation "androidx.navigation:navigation-ui-ktx:$navigationVersion" diff --git a/play-services-core/src/main/java/com/google/android/gms/common/security/ProviderInstallerImpl.java b/play-services-core/src/main/java/com/google/android/gms/common/security/ProviderInstallerImpl.java deleted file mode 100644 index 6d702279..00000000 --- a/play-services-core/src/main/java/com/google/android/gms/common/security/ProviderInstallerImpl.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (C) 2013-2017 microG Project Team - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.android.gms.common.security; - -import android.content.Context; -import android.content.pm.ApplicationInfo; -import android.os.Process; -import android.util.Log; - -import org.conscrypt.NativeCrypto; -import org.conscrypt.OpenSSLProvider; -import org.microg.gms.common.PackageUtils; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.security.Security; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Set; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; - -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLContext; - -public class ProviderInstallerImpl { - private static final String TAG = "GmsProviderInstaller"; - private static final List DISABLED = Collections.unmodifiableList(Arrays.asList("com.discord", "com.bankid.bus")); - - public static void insertProvider(Context context) { - String packageName = PackageUtils.packageFromProcessId(context, Process.myPid()); - Log.d(TAG, "Provider installer invoked for " + packageName); - try { - if (DISABLED.contains(packageName)) { - Log.d(TAG, "Package is excluded from usage of provider installer"); - return; - } - - OpenSSLProvider provider = null; - - try { - provider = new OpenSSLProvider("GmsCore_OpenSSL"); - } catch (UnsatisfiedLinkError e) { - Log.w(TAG, "Could not link conscrypt via default loader, trying manual loading"); - - // TODO: Move manual loading into helper function (as it is also used in both maps implementations) - try { - ApplicationInfo otherAppInfo = context.getPackageManager().getApplicationInfo(packageName, 0); - - String primaryCpuAbi = (String) ApplicationInfo.class.getField("primaryCpuAbi").get(otherAppInfo); - if (primaryCpuAbi != null) { - String path = "lib/" + primaryCpuAbi + "/libconscrypt_jni.so"; - File cacheFile = new File(context.createPackageContext(packageName, 0).getCacheDir().getAbsolutePath() + "/.gmscore/" + path); - cacheFile.getParentFile().mkdirs(); - File apkFile = new File(context.getPackageCodePath()); - if (!cacheFile.exists() || cacheFile.lastModified() < apkFile.lastModified()) { - ZipFile zipFile = new ZipFile(apkFile); - ZipEntry entry = zipFile.getEntry(path); - if (entry != null) { - copyInputStream(zipFile.getInputStream(entry), new FileOutputStream(cacheFile)); - } else { - Log.d(TAG, "Can't load native library: " + path + " does not exist in " + apkFile); - } - } - Log.d(TAG, "Loading conscrypt_jni from " + cacheFile.getPath()); - System.load(cacheFile.getAbsolutePath()); - - Class clazz = NativeCrypto.class; - - Field loadError = clazz.getDeclaredField("loadError"); - loadError.setAccessible(true); - loadError.set(null, null); - - Method clinit = clazz.getDeclaredMethod("clinit"); - clinit.setAccessible(true); - - Method get_cipher_names = clazz.getDeclaredMethod("get_cipher_names", String.class); - get_cipher_names.setAccessible(true); - - Method cipherSuiteToJava = clazz.getDeclaredMethod("cipherSuiteToJava", String.class); - cipherSuiteToJava.setAccessible(true); - - Method EVP_has_aes_hardware = clazz.getDeclaredMethod("EVP_has_aes_hardware"); - EVP_has_aes_hardware.setAccessible(true); - - Field f = clazz.getDeclaredField("SUPPORTED_TLS_1_2_CIPHER_SUITES_SET"); - f.setAccessible(true); - - Set SUPPORTED_TLS_1_2_CIPHER_SUITES_SET = (Set) f.get(null); - f = clazz.getDeclaredField("SUPPORTED_LEGACY_CIPHER_SUITES_SET"); - f.setAccessible(true); - - Set SUPPORTED_LEGACY_CIPHER_SUITES_SET = (Set) f.get(null); - f = clazz.getDeclaredField("SUPPORTED_TLS_1_2_CIPHER_SUITES"); - f.setAccessible(true); - - try { - clinit.invoke(null); - - String[] allCipherSuites = (String[]) get_cipher_names.invoke(null, "ALL:!DHE"); - int size = allCipherSuites.length; - - String[] SUPPORTED_TLS_1_2_CIPHER_SUITES = new String[size / 2 + 2]; - for (int i = 0; i < size; i += 2) { - String cipherSuite = (String) cipherSuiteToJava.invoke(null, allCipherSuites[i]); - - SUPPORTED_TLS_1_2_CIPHER_SUITES[i / 2] = cipherSuite; - SUPPORTED_TLS_1_2_CIPHER_SUITES_SET.add(cipherSuite); - - SUPPORTED_LEGACY_CIPHER_SUITES_SET.add(allCipherSuites[i + 1]); - } - SUPPORTED_TLS_1_2_CIPHER_SUITES[size / 2] = "TLS_EMPTY_RENEGOTIATION_INFO_SCSV"; - SUPPORTED_TLS_1_2_CIPHER_SUITES[size / 2 + 1] = "TLS_FALLBACK_SCSV"; - f.set(null, SUPPORTED_TLS_1_2_CIPHER_SUITES); - - f = clazz.getDeclaredField("HAS_AES_HARDWARE"); - f.setAccessible(true); - f.set(null, (int) EVP_has_aes_hardware.invoke(null) == 1); - - provider = new OpenSSLProvider("GmsCore_OpenSSL"); - } catch (InvocationTargetException inner) { - if (inner.getTargetException() instanceof UnsatisfiedLinkError) { - loadError.set(null, inner.getTargetException()); - } - } - } - } catch (Exception e2) { - Log.w(TAG, e2); - } - } - - if (provider == null) { - Log.w(TAG, "Failed to initialize conscrypt provider"); - return; - } - - if (Security.insertProviderAt(provider, 1) == 1) { - Security.setProperty("ssl.SocketFactory.provider", "org.conscrypt.OpenSSLSocketFactoryImpl"); - Security.setProperty("ssl.ServerSocketFactory.provider", "org.conscrypt.OpenSSLServerSocketFactoryImpl"); - - SSLContext.setDefault(SSLContext.getInstance("Default")); - HttpsURLConnection.setDefaultSSLSocketFactory(SSLContext.getDefault().getSocketFactory()); - Log.d(TAG, "SSL provider installed"); - } else { - Log.w(TAG, "Did not insert the new SSL provider"); - } - } catch (Throwable e) { - Log.w(TAG, e); - } - } - - - private static final void copyInputStream(InputStream in, OutputStream out) throws IOException { - byte[] buffer = new byte[1024]; - int len; - - while ((len = in.read(buffer)) >= 0) - out.write(buffer, 0, len); - - in.close(); - out.close(); - } -} diff --git a/settings.gradle b/settings.gradle index ad2ea320..a2b24335 100644 --- a/settings.gradle +++ b/settings.gradle @@ -18,6 +18,7 @@ include ':play-services-nearby-core-proto' include ':play-services-wearable-proto' include ':play-services-base-core' +include ':play-services-conscrypt-provider-core' include ':play-services-location-core' include ':play-services-maps-core-mapbox' include ':play-services-maps-core-vtm' From 4c2ef04364691b04aace378415b9a85c011829d3 Mon Sep 17 00:00:00 2001 From: Marvin W Date: Wed, 18 Nov 2020 17:06:29 +0100 Subject: [PATCH 07/72] EN API: Update --- gradle/publish-android.gradle | 67 ++++++ gradle/publish-java.gradle | 57 +++++ play-services-base-api/build.gradle | 4 + play-services-base-core-ui/build.gradle | 4 + play-services-base-core/build.gradle | 4 + play-services-base/build.gradle | 4 + .../gms/common/MultiConnectionKeeper.java | 15 +- play-services-basement/build.gradle | 4 + play-services-nearby-api/build.gradle | 4 + .../PackageConfiguration.aidl | 8 + .../GetPackageConfigurationParams.aidl | 8 + .../internal/GetStatusParams.aidl | 8 + .../internal/IDiagnosisKeyFileSupplier.aidl | 12 + .../INearbyExposureNotificationService.aidl | 4 + .../IPackageConfigurationCallback.aidl | 13 ++ .../DiagnosisKeyFileProvider.java | 11 +- .../ExposureNotificationStatus.java | 98 ++++++++ .../PackageConfiguration.java | 57 +++++ .../TemporaryExposureKey.java | 33 ++- .../GetPackageConfigurationParams.java | 21 ++ .../internal/GetStatusParams.java | 21 ++ .../internal/ProvideDiagnosisKeysParams.java | 7 + play-services-nearby-core-proto/build.gradle | 4 + play-services-nearby-core-ui/build.gradle | 8 +- ...sureNotificationsAppPreferencesFragment.kt | 6 +- .../ExposureNotificationsConfirmActivity.kt | 37 ++- ...xposure_notifications_confirm_activity.xml | 31 +++ .../src/main/res/values/strings.xml | 2 + play-services-nearby-core/build.gradle | 4 + .../src/main/AndroidManifest.xml | 3 + .../exposurenotification/AdvertiserService.kt | 1 + .../exposurenotification/CleanupService.kt | 2 + .../nearby/exposurenotification/DeviceInfo.kt | 3 + .../exposurenotification/ExposureDatabase.kt | 53 +++-- .../ExposureNotificationService.kt | 11 +- .../ExposureNotificationServiceImpl.kt | 185 +++++++++++++-- .../exposurenotification/MeasuredExposure.kt | 11 +- .../exposurenotification/ScannerService.kt | 1 + .../exposurenotification/ServiceTrigger.kt | 3 + play-services-nearby/build.gradle | 4 + .../ExposureNotificationClient.java | 212 ++++++++++++++++-- .../nearby/ExposureNotificationApiClient.java | 10 + .../ExposureNotificationClientImpl.java | 101 ++++++++- play-services-tasks/build.gradle | 4 + 44 files changed, 1085 insertions(+), 75 deletions(-) create mode 100644 gradle/publish-android.gradle create mode 100644 gradle/publish-java.gradle create mode 100644 play-services-nearby-api/src/main/aidl/com/google/android/gms/nearby/exposurenotification/PackageConfiguration.aidl create mode 100644 play-services-nearby-api/src/main/aidl/com/google/android/gms/nearby/exposurenotification/internal/GetPackageConfigurationParams.aidl create mode 100644 play-services-nearby-api/src/main/aidl/com/google/android/gms/nearby/exposurenotification/internal/GetStatusParams.aidl create mode 100644 play-services-nearby-api/src/main/aidl/com/google/android/gms/nearby/exposurenotification/internal/IDiagnosisKeyFileSupplier.aidl create mode 100644 play-services-nearby-api/src/main/aidl/com/google/android/gms/nearby/exposurenotification/internal/IPackageConfigurationCallback.aidl create mode 100644 play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/ExposureNotificationStatus.java create mode 100644 play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/PackageConfiguration.java create mode 100644 play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/internal/GetPackageConfigurationParams.java create mode 100644 play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/internal/GetStatusParams.java diff --git a/gradle/publish-android.gradle b/gradle/publish-android.gradle new file mode 100644 index 00000000..d41ae07a --- /dev/null +++ b/gradle/publish-android.gradle @@ -0,0 +1,67 @@ +/* + * SPDX-FileCopyrightText: 2020, microG Project Team + * SPDX-License-Identifier: Apache-2.0 + */ + +task androidSourcesJar(type: Jar) { + archiveClassifier.set("sources") + from android.sourceSets.main.java.source +} + +artifacts { + archives androidSourcesJar +} + +afterEvaluate { + publishing { + publications { + release(MavenPublication) { + pom { + name = project.name + url = 'https://github.com/microg/GmsCore' + licenses { + license { + name = 'The Apache Software License, Version 2.0' + url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' + } + } + developers { + developer { + id = 'microg' + name = 'microG Team' + } + developer { + id = 'mar-v-in' + name = 'Marvin W.' + } + } + scm { + url = 'https://github.com/microg/GmsCore' + connection = 'scm:git:https://github.com/microg/GmsCore.git' + developerConnection = 'scm:git:ssh://github.com/microg/GmsCore.git' + } + } + + from components.release + artifact androidSourcesJar + } + } + if (project.hasProperty('sonatype.username')) { + repositories { + maven { + name = 'sonatype' + url = 'https://oss.sonatype.org/service/local/staging/deploy/maven2/' + credentials { + username project.getProperty('sonatype.username') + password project.getProperty('sonatype.password') + } + } + } + } + } + if (project.hasProperty('signing.keyId')) { + signing { + sign publishing.publications + } + } +} diff --git a/gradle/publish-java.gradle b/gradle/publish-java.gradle new file mode 100644 index 00000000..2956bf97 --- /dev/null +++ b/gradle/publish-java.gradle @@ -0,0 +1,57 @@ +/* + * SPDX-FileCopyrightText: 2020, microG Project Team + * SPDX-License-Identifier: Apache-2.0 + */ + +afterEvaluate { + publishing { + publications { + release(MavenPublication) { + pom { + name = project.name + url = 'https://github.com/microg/GmsCore' + licenses { + license { + name = 'The Apache Software License, Version 2.0' + url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' + } + } + developers { + developer { + id = 'microg' + name = 'microG Team' + } + developer { + id = 'mar-v-in' + name = 'Marvin W.' + } + } + scm { + url = 'https://github.com/microg/GmsCore' + connection = 'scm:git:https://github.com/microg/GmsCore.git' + developerConnection = 'scm:git:ssh://github.com/microg/GmsCore.git' + } + } + + from components.java + } + } + if (project.hasProperty('sonatype.username')) { + repositories { + maven { + name = 'sonatype' + url = 'https://oss.sonatype.org/service/local/staging/deploy/maven2/' + credentials { + username project.getProperty('sonatype.username') + password project.getProperty('sonatype.password') + } + } + } + } + } + if (project.hasProperty('signing.keyId')) { + signing { + sign publishing.publications + } + } +} diff --git a/play-services-base-api/build.gradle b/play-services-base-api/build.gradle index 70d9d624..44bb7b0f 100644 --- a/play-services-base-api/build.gradle +++ b/play-services-base-api/build.gradle @@ -15,6 +15,8 @@ */ apply plugin: 'com.android.library' +apply plugin: 'maven-publish' +apply plugin: 'signing' dependencies { api project(':play-services-basement') @@ -38,3 +40,5 @@ android { targetCompatibility = 1.8 } } + +apply from: '../gradle/publish-android.gradle' diff --git a/play-services-base-core-ui/build.gradle b/play-services-base-core-ui/build.gradle index 8abe5ce5..bed6a1a6 100644 --- a/play-services-base-core-ui/build.gradle +++ b/play-services-base-core-ui/build.gradle @@ -7,6 +7,8 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' apply plugin: 'kotlin-android-extensions' +apply plugin: 'maven-publish' +apply plugin: 'signing' dependencies { api project(':play-services-base') @@ -56,3 +58,5 @@ android { targetCompatibility = 1.8 } } + +apply from: '../gradle/publish-android.gradle' diff --git a/play-services-base-core/build.gradle b/play-services-base-core/build.gradle index 3ff54ab1..ef8f393b 100644 --- a/play-services-base-core/build.gradle +++ b/play-services-base-core/build.gradle @@ -4,6 +4,8 @@ */ apply plugin: 'com.android.library' +apply plugin: 'maven-publish' +apply plugin: 'signing' dependencies { api project(':play-services-basement') @@ -27,3 +29,5 @@ android { targetCompatibility = 1.8 } } + +apply from: '../gradle/publish-android.gradle' diff --git a/play-services-base/build.gradle b/play-services-base/build.gradle index 3d47a737..92d371a9 100644 --- a/play-services-base/build.gradle +++ b/play-services-base/build.gradle @@ -15,6 +15,8 @@ */ apply plugin: 'com.android.library' +apply plugin: 'maven-publish' +apply plugin: 'signing' android { compileSdkVersion androidCompileSdk @@ -32,6 +34,8 @@ android { } } +apply from: '../gradle/publish-android.gradle' + dependencies { api project(':play-services-basement') api project(':play-services-tasks') diff --git a/play-services-base/src/main/java/org/microg/gms/common/MultiConnectionKeeper.java b/play-services-base/src/main/java/org/microg/gms/common/MultiConnectionKeeper.java index ea4cfbe6..d6c7ea48 100644 --- a/play-services-base/src/main/java/org/microg/gms/common/MultiConnectionKeeper.java +++ b/play-services-base/src/main/java/org/microg/gms/common/MultiConnectionKeeper.java @@ -122,7 +122,20 @@ public class MultiConnectionKeeper { @SuppressLint("InlinedApi") public void bind() { Log.d(TAG, "Connection(" + actionString + ") : bind()"); - Intent intent = new Intent(actionString).setPackage(GMS_PACKAGE_NAME); + Intent gmsIntent = new Intent(actionString).setPackage(GMS_PACKAGE_NAME); + Intent selfIntent = new Intent(actionString).setPackage(context.getPackageName()); + Intent intent; + if (context.getPackageManager().resolveService(gmsIntent, 0) == null) { + Log.w(TAG, "No GMS service found for " + actionString); + if (context.getPackageManager().resolveService(selfIntent, 0) != null) { + Log.d(TAG, "Found service for "+actionString+" in self package, using it instead"); + intent = selfIntent; + } else { + return; + } + } else { + intent = gmsIntent; + } int flags = Context.BIND_AUTO_CREATE; if (SDK_INT >= ICE_CREAM_SANDWICH) { flags |= Context.BIND_ADJUST_WITH_ACTIVITY; diff --git a/play-services-basement/build.gradle b/play-services-basement/build.gradle index 201ce74e..56c53a9e 100644 --- a/play-services-basement/build.gradle +++ b/play-services-basement/build.gradle @@ -17,6 +17,8 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'maven-publish' +apply plugin: 'signing' dependencies { api "org.microg:safe-parcel:$safeParcelVersion" @@ -49,3 +51,5 @@ android { targetCompatibility = 1.8 } } + +apply from: '../gradle/publish-android.gradle' diff --git a/play-services-nearby-api/build.gradle b/play-services-nearby-api/build.gradle index 650fe429..9a567128 100644 --- a/play-services-nearby-api/build.gradle +++ b/play-services-nearby-api/build.gradle @@ -4,6 +4,8 @@ */ apply plugin: 'com.android.library' +apply plugin: 'maven-publish' +apply plugin: 'signing' android { compileSdkVersion androidCompileSdk @@ -21,6 +23,8 @@ android { } } +apply from: '../gradle/publish-android.gradle' + dependencies { api project(':play-services-basement') api project(':play-services-base-api') diff --git a/play-services-nearby-api/src/main/aidl/com/google/android/gms/nearby/exposurenotification/PackageConfiguration.aidl b/play-services-nearby-api/src/main/aidl/com/google/android/gms/nearby/exposurenotification/PackageConfiguration.aidl new file mode 100644 index 00000000..5b097519 --- /dev/null +++ b/play-services-nearby-api/src/main/aidl/com/google/android/gms/nearby/exposurenotification/PackageConfiguration.aidl @@ -0,0 +1,8 @@ +/* + * SPDX-FileCopyrightText: 2020, microG Project Team + * SPDX-License-Identifier: Apache-2.0 + */ + +package com.google.android.gms.nearby.exposurenotification; + +parcelable PackageConfiguration; diff --git a/play-services-nearby-api/src/main/aidl/com/google/android/gms/nearby/exposurenotification/internal/GetPackageConfigurationParams.aidl b/play-services-nearby-api/src/main/aidl/com/google/android/gms/nearby/exposurenotification/internal/GetPackageConfigurationParams.aidl new file mode 100644 index 00000000..cc229837 --- /dev/null +++ b/play-services-nearby-api/src/main/aidl/com/google/android/gms/nearby/exposurenotification/internal/GetPackageConfigurationParams.aidl @@ -0,0 +1,8 @@ +/* + * SPDX-FileCopyrightText: 2020, microG Project Team + * SPDX-License-Identifier: Apache-2.0 + */ + +package com.google.android.gms.nearby.exposurenotification.internal; + +parcelable GetPackageConfigurationParams; diff --git a/play-services-nearby-api/src/main/aidl/com/google/android/gms/nearby/exposurenotification/internal/GetStatusParams.aidl b/play-services-nearby-api/src/main/aidl/com/google/android/gms/nearby/exposurenotification/internal/GetStatusParams.aidl new file mode 100644 index 00000000..8230bc53 --- /dev/null +++ b/play-services-nearby-api/src/main/aidl/com/google/android/gms/nearby/exposurenotification/internal/GetStatusParams.aidl @@ -0,0 +1,8 @@ +/* + * SPDX-FileCopyrightText: 2020, microG Project Team + * SPDX-License-Identifier: Apache-2.0 + */ + +package com.google.android.gms.nearby.exposurenotification.internal; + +parcelable GetStatusParams; diff --git a/play-services-nearby-api/src/main/aidl/com/google/android/gms/nearby/exposurenotification/internal/IDiagnosisKeyFileSupplier.aidl b/play-services-nearby-api/src/main/aidl/com/google/android/gms/nearby/exposurenotification/internal/IDiagnosisKeyFileSupplier.aidl new file mode 100644 index 00000000..e5498ac8 --- /dev/null +++ b/play-services-nearby-api/src/main/aidl/com/google/android/gms/nearby/exposurenotification/internal/IDiagnosisKeyFileSupplier.aidl @@ -0,0 +1,12 @@ +/* + * SPDX-FileCopyrightText: 2020, microG Project Team + * SPDX-License-Identifier: Apache-2.0 + */ + +package com.google.android.gms.nearby.exposurenotification.internal; + +interface IDiagnosisKeyFileSupplier { + boolean hasNext(); + ParcelFileDescriptor next(); + boolean isAvailable(); +} diff --git a/play-services-nearby-api/src/main/aidl/com/google/android/gms/nearby/exposurenotification/internal/INearbyExposureNotificationService.aidl b/play-services-nearby-api/src/main/aidl/com/google/android/gms/nearby/exposurenotification/internal/INearbyExposureNotificationService.aidl index b5dcfbe8..fad4f590 100644 --- a/play-services-nearby-api/src/main/aidl/com/google/android/gms/nearby/exposurenotification/internal/INearbyExposureNotificationService.aidl +++ b/play-services-nearby-api/src/main/aidl/com/google/android/gms/nearby/exposurenotification/internal/INearbyExposureNotificationService.aidl @@ -18,6 +18,8 @@ import com.google.android.gms.nearby.exposurenotification.internal.GetCalibratio import com.google.android.gms.nearby.exposurenotification.internal.GetDailySummariesParams; import com.google.android.gms.nearby.exposurenotification.internal.SetDiagnosisKeysDataMappingParams; import com.google.android.gms.nearby.exposurenotification.internal.GetDiagnosisKeysDataMappingParams; +import com.google.android.gms.nearby.exposurenotification.internal.GetStatusParams; +import com.google.android.gms.nearby.exposurenotification.internal.GetPackageConfigurationParams; interface INearbyExposureNotificationService{ void start(in StartParams params) = 0; @@ -35,4 +37,6 @@ interface INearbyExposureNotificationService{ void getDailySummaries(in GetDailySummariesParams params) = 15; void setDiagnosisKeysDataMapping(in SetDiagnosisKeysDataMappingParams params) = 16; void getDiagnosisKeysDataMapping(in GetDiagnosisKeysDataMappingParams params) = 17; + void getStatus(in GetStatusParams params) = 18; + void getPackageConfiguration(in GetPackageConfigurationParams params) = 19; } diff --git a/play-services-nearby-api/src/main/aidl/com/google/android/gms/nearby/exposurenotification/internal/IPackageConfigurationCallback.aidl b/play-services-nearby-api/src/main/aidl/com/google/android/gms/nearby/exposurenotification/internal/IPackageConfigurationCallback.aidl new file mode 100644 index 00000000..1f2b45d4 --- /dev/null +++ b/play-services-nearby-api/src/main/aidl/com/google/android/gms/nearby/exposurenotification/internal/IPackageConfigurationCallback.aidl @@ -0,0 +1,13 @@ +/* + * SPDX-FileCopyrightText: 2020, microG Project Team + * SPDX-License-Identifier: Apache-2.0 + */ + +package com.google.android.gms.nearby.exposurenotification.internal; + +import com.google.android.gms.common.api.Status; +import com.google.android.gms.nearby.exposurenotification.PackageConfiguration; + +interface IPackageConfigurationCallback { + void onResult(in Status status, in PackageConfiguration result); +} diff --git a/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/DiagnosisKeyFileProvider.java b/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/DiagnosisKeyFileProvider.java index 621201a0..53801d54 100644 --- a/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/DiagnosisKeyFileProvider.java +++ b/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/DiagnosisKeyFileProvider.java @@ -19,13 +19,20 @@ import java.util.List; */ @PublicApi public class DiagnosisKeyFileProvider { + private int index; private List files; public DiagnosisKeyFileProvider(List files) { this.files = new ArrayList<>(files); } - public List getFiles() { - return files; + @PublicApi(exclude = true) + public boolean hasNext() { + return files.size() > index; + } + + @PublicApi(exclude = true) + public File next() { + return files.get(index++); } } diff --git a/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/ExposureNotificationStatus.java b/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/ExposureNotificationStatus.java new file mode 100644 index 00000000..feabbaf9 --- /dev/null +++ b/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/ExposureNotificationStatus.java @@ -0,0 +1,98 @@ +/* + * SPDX-FileCopyrightText: 2020, microG Project Team + * SPDX-License-Identifier: Apache-2.0 + * Notice: Portions of this file are reproduced from work created and shared by Google and used + * according to terms described in the Creative Commons 4.0 Attribution License. + * See https://developers.google.com/readme/policies for details. + */ + +package com.google.android.gms.nearby.exposurenotification; + +import org.microg.gms.common.PublicApi; + +import java.util.HashSet; +import java.util.Set; + +/** + * Detail status for exposure notification service. + */ +@PublicApi +public enum ExposureNotificationStatus { + /** + * Exposure notification is running. + */ + ACTIVATED, + /** + * Exposure notification is not running. + */ + INACTIVATED, + /** + * Bluetooth is not enabled. + */ + BLUETOOTH_DISABLED, + /** + * Location is not enabled. + */ + LOCATION_DISABLED, + /** + * User is not consent for the client. + */ + NO_CONSENT, + /** + * The client is not in approved client list. + */ + NOT_IN_WHITELIST, + /** + * Can't detected the BLE supporting of this device due to bluetooth is not enabled. + */ + BLUETOOTH_SUPPORT_UNKNOWN, + /** + * Hardware of this device doesn't support exposure notification. + */ + HW_NOT_SUPPORT, + /** + * There is another client running as active client. + */ + FOCUS_LOST, + /** + * Device storage is not sufficient for exposure notification. + */ + LOW_STORAGE, + /** + * Current status is unknown. + */ + UNKNOWN, + /** + * Exposure notification is not supported. + */ + EN_NOT_SUPPORT, + /** + * Exposure notification is not supported for current user profile. + */ + USER_PROFILE_NOT_SUPPORT + ; + + private long flag() { + return 1 << ordinal(); + } + + @PublicApi(exclude = true) + public static long setToFlags(Set set) { + long res = 0; + for (ExposureNotificationStatus status : set) { + res |= status.flag(); + } + return res; + } + + @PublicApi(exclude = true) + public static Set flagsToSet(long flags) { + Set set = new HashSet<>(); + for (ExposureNotificationStatus status : values()) { + if ((flags & status.flag()) > 0) { + set.add(status); + } + } + return set; + } +} diff --git a/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/PackageConfiguration.java b/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/PackageConfiguration.java new file mode 100644 index 00000000..8f699236 --- /dev/null +++ b/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/PackageConfiguration.java @@ -0,0 +1,57 @@ +/* + * SPDX-FileCopyrightText: 2020, microG Project Team + * SPDX-License-Identifier: Apache-2.0 + */ + +package com.google.android.gms.nearby.exposurenotification; + +import android.os.Bundle; + +import org.microg.gms.common.PublicApi; +import org.microg.safeparcel.AutoSafeParcelable; + +/** + * Holds configuration values that can be passed onto the client app after it has finished installing via {@link ExposureNotificationClient#getPackageConfiguration()}. + */ +@PublicApi +public class PackageConfiguration extends AutoSafeParcelable { + @Field(1) + private Bundle values; + + @PublicApi(exclude = true) + public PackageConfiguration() { + } + + @PublicApi(exclude = true) + public PackageConfiguration(Bundle values) { + this.values = values; + } + + public Bundle getValues() { + return values; + } + + /** + * A builder for {@link PackageConfiguration}. + */ + public static final class PackageConfigurationBuilder { + private Bundle values; + + /** + * Sets a Bundle containing configuration options. + */ + public PackageConfigurationBuilder setValues(Bundle values) { + this.values = values; + return this; + } + + /** + * Builds a {@link PackageConfiguration}. + */ + public PackageConfiguration build() { + return new PackageConfiguration(values); + } + } + + public static final Creator CREATOR = new AutoCreator<>(PackageConfiguration.class); +} diff --git a/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/TemporaryExposureKey.java b/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/TemporaryExposureKey.java index 4514c9a4..8c8bc58a 100644 --- a/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/TemporaryExposureKey.java +++ b/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/TemporaryExposureKey.java @@ -13,6 +13,9 @@ import org.microg.safeparcel.AutoSafeParcelable; import java.util.Arrays; +/** + * A key generated for advertising over a window of time. + */ public class TemporaryExposureKey extends AutoSafeParcelable { @Field(1) private byte[] keyData; @@ -29,6 +32,11 @@ public class TemporaryExposureKey extends AutoSafeParcelable { @Field(6) int daysSinceOnsetOfSymptoms; + /** + * The default value for {@link #getDaysSinceOnsetOfSymptoms()}. + * + * See {@link DiagnosisKeysDataMapping#getDaysSinceOnsetToInfectiousness()} for more information. + */ public static final int DAYS_SINCE_ONSET_OF_SYMPTOMS_UNKNOWN = Constants.DAYS_SINCE_ONSET_OF_SYMPTOMS_UNKNOWN; private TemporaryExposureKey() { @@ -43,29 +51,49 @@ public class TemporaryExposureKey extends AutoSafeParcelable { this.daysSinceOnsetOfSymptoms = daysSinceOnsetOfSymptoms; } + /** + * The randomly generated Temporary Exposure Key information. + */ public byte[] getKeyData() { return Arrays.copyOf(keyData, keyData.length); } + /** + * A number describing when a key starts. It is equal to startTimeOfKeySinceEpochInSecs / (60 * 10). + */ public int getRollingStartIntervalNumber() { return rollingStartIntervalNumber; } + /** + * Risk of transmission associated with the person this key came from. + */ @RiskLevel public int getTransmissionRiskLevel() { return transmissionRiskLevel; } + /** + * A number describing how long a key is valid. It is expressed in increments of 10 minutes (e.g. 144 for 24 hours). + */ public int getRollingPeriod() { return rollingPeriod; } + /** + * Type of diagnosis associated with a key. + */ @ReportType public int getReportType() { return reportType; } - int getDaysSinceOnsetOfSymptoms() { + /** + * Number of days elapsed between symptom onset and the key being used. + *

+ * E.g. 2 means the key is 2 days after onset of symptoms. + */ + public int getDaysSinceOnsetOfSymptoms() { return daysSinceOnsetOfSymptoms; } @@ -107,6 +135,9 @@ public class TemporaryExposureKey extends AutoSafeParcelable { '}'; } + /** + * A builder for {@link TemporaryExposureKey}. + */ public static class TemporaryExposureKeyBuilder { private byte[] keyData; private int rollingStartIntervalNumber; diff --git a/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/internal/GetPackageConfigurationParams.java b/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/internal/GetPackageConfigurationParams.java new file mode 100644 index 00000000..700eaa67 --- /dev/null +++ b/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/internal/GetPackageConfigurationParams.java @@ -0,0 +1,21 @@ +/* + * SPDX-FileCopyrightText: 2020, microG Project Team + * SPDX-License-Identifier: Apache-2.0 + */ + +package com.google.android.gms.nearby.exposurenotification.internal; + +import org.microg.safeparcel.AutoSafeParcelable; + +public class GetPackageConfigurationParams extends AutoSafeParcelable { + @Field(1) + public IPackageConfigurationCallback callback; + + private GetPackageConfigurationParams() {} + + public GetPackageConfigurationParams(IPackageConfigurationCallback callback) { + this.callback = callback; + } + + public static final Creator CREATOR = new AutoCreator<>(GetPackageConfigurationParams.class); +} diff --git a/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/internal/GetStatusParams.java b/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/internal/GetStatusParams.java new file mode 100644 index 00000000..5e6a6cb6 --- /dev/null +++ b/play-services-nearby-api/src/main/java/com/google/android/gms/nearby/exposurenotification/internal/GetStatusParams.java @@ -0,0 +1,21 @@ +/* + * SPDX-FileCopyrightText: 2020, microG Project Team + * SPDX-License-Identifier: Apache-2.0 + */ + +package com.google.android.gms.nearby.exposurenotification.internal; + +import org.microg.safeparcel.AutoSafeParcelable; + +public class GetStatusParams extends AutoSafeParcelable { + @Field(1) + public ILongCallback callback; + + private GetStatusParams() {} + + public GetStatusParams(ILongCallback callback) { + this.callback = callback; + } + + public static final Creator CREATOR = new AutoCreator<>(GetStatusParams.class); +} 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 f429d712..a38a8c88 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 @@ -26,6 +26,8 @@ public class ProvideDiagnosisKeysParams extends AutoSafeParcelable { public ExposureConfiguration configuration; @Field(5) public String token; + @Field(6) + public IDiagnosisKeyFileSupplier keyFileSupplier; private ProvideDiagnosisKeysParams() { } @@ -42,5 +44,10 @@ public class ProvideDiagnosisKeysParams extends AutoSafeParcelable { this.token = token; } + public ProvideDiagnosisKeysParams(IStatusCallback callback, IDiagnosisKeyFileSupplier keyFileSupplier) { + this.callback = callback; + this.keyFileSupplier = keyFileSupplier; + } + public static final Creator CREATOR = new AutoCreator<>(ProvideDiagnosisKeysParams.class); } diff --git a/play-services-nearby-core-proto/build.gradle b/play-services-nearby-core-proto/build.gradle index 10577dc3..49acc5fe 100644 --- a/play-services-nearby-core-proto/build.gradle +++ b/play-services-nearby-core-proto/build.gradle @@ -5,6 +5,8 @@ apply plugin: 'com.squareup.wire' apply plugin: 'kotlin' +apply plugin: 'maven-publish' +apply plugin: 'signing' dependencies { implementation "com.squareup.wire:wire-runtime:$wireVersion" @@ -21,3 +23,5 @@ compileKotlin { compileTestKotlin { kotlinOptions.jvmTarget = 1.8 } + +apply from: '../gradle/publish-java.gradle' diff --git a/play-services-nearby-core-ui/build.gradle b/play-services-nearby-core-ui/build.gradle index 8fed8856..df354be7 100644 --- a/play-services-nearby-core-ui/build.gradle +++ b/play-services-nearby-core-ui/build.gradle @@ -7,6 +7,8 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' apply plugin: 'kotlin-android-extensions' +apply plugin: 'maven-publish' +apply plugin: 'signing' dependencies { implementation project(':play-services-nearby-core') @@ -17,11 +19,9 @@ dependencies { // AndroidX UI implementation "androidx.multidex:multidex:$multidexVersion" implementation "androidx.appcompat:appcompat:$appcompatVersion" - implementation "androidx.preference:preference:$preferenceVersion" + implementation "androidx.preference:preference-ktx:$preferenceVersion" // Navigation - implementation "androidx.navigation:navigation-fragment:$navigationVersion" - implementation "androidx.navigation:navigation-ui:$navigationVersion" implementation "androidx.navigation:navigation-fragment-ktx:$navigationVersion" implementation "androidx.navigation:navigation-ui-ktx:$navigationVersion" @@ -62,3 +62,5 @@ android { jvmTarget = 1.8 } } + +apply from: '../gradle/publish-android.gradle' diff --git a/play-services-nearby-core-ui/src/main/kotlin/org/microg/gms/nearby/core/ui/ExposureNotificationsAppPreferencesFragment.kt b/play-services-nearby-core-ui/src/main/kotlin/org/microg/gms/nearby/core/ui/ExposureNotificationsAppPreferencesFragment.kt index 9ce7f3c1..35ce9a44 100644 --- a/play-services-nearby-core-ui/src/main/kotlin/org/microg/gms/nearby/core/ui/ExposureNotificationsAppPreferencesFragment.kt +++ b/play-services-nearby-core-ui/src/main/kotlin/org/microg/gms/nearby/core/ui/ExposureNotificationsAppPreferencesFragment.kt @@ -12,6 +12,7 @@ import androidx.core.text.HtmlCompat import androidx.lifecycle.lifecycleScope import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat +import com.google.android.gms.nearby.exposurenotification.ExposureConfiguration import org.json.JSONObject import org.microg.gms.nearby.exposurenotification.ExposureDatabase import org.microg.gms.nearby.exposurenotification.merge @@ -50,6 +51,9 @@ class ExposureNotificationsAppPreferencesFragment : PreferenceFragmentCompat() { updateContent() } + private fun ExposureConfiguration?.orDefault() = this + ?: ExposureConfiguration.ExposureConfigurationBuilder().build() + fun updateContent() { packageName?.let { packageName -> lifecycleScope.launchWhenResumed { @@ -70,7 +74,7 @@ class ExposureNotificationsAppPreferencesFragment : PreferenceFragmentCompat() { getString(R.string.pref_exposure_app_last_report_summary_encounters_no) } else { database.findAllMeasuredExposures(config.first).merge().map { - val riskScore = it.getRiskScore(config.second) + val riskScore = it.getRiskScore(config.second.orDefault()) "· " + getString(R.string.pref_exposure_app_last_report_summary_encounters_line, DateUtils.formatDateRange(requireContext(), it.timestamp, it.timestamp + it.durationInMinutes * 60 * 1000L, DateUtils.FORMAT_SHOW_TIME or DateUtils.FORMAT_SHOW_DATE), riskScore) }.joinToString("
").let { getString(R.string.pref_exposure_app_last_report_summary_encounters_prefix, merged.size) + "
$it
" + getString(R.string.pref_exposure_app_last_report_summary_encounters_suffix) + "" } } diff --git a/play-services-nearby-core-ui/src/main/kotlin/org/microg/gms/nearby/core/ui/ExposureNotificationsConfirmActivity.kt b/play-services-nearby-core-ui/src/main/kotlin/org/microg/gms/nearby/core/ui/ExposureNotificationsConfirmActivity.kt index 2b1bdbdb..a6eb168a 100644 --- a/play-services-nearby-core-ui/src/main/kotlin/org/microg/gms/nearby/core/ui/ExposureNotificationsConfirmActivity.kt +++ b/play-services-nearby-core-ui/src/main/kotlin/org/microg/gms/nearby/core/ui/ExposureNotificationsConfirmActivity.kt @@ -5,12 +5,15 @@ package org.microg.gms.nearby.core.ui +import android.content.pm.PackageManager +import android.os.Build import android.os.Bundle import android.os.ResultReceiver +import android.view.View import android.widget.Button import android.widget.TextView import androidx.appcompat.app.AppCompatActivity -import org.microg.gms.nearby.core.ui.R +import androidx.core.content.ContextCompat import org.microg.gms.nearby.exposurenotification.* import org.microg.gms.ui.getApplicationInfoIfExists @@ -31,12 +34,16 @@ class ExposureNotificationsConfirmActivity : AppCompatActivity() { super.onCreate(savedInstanceState) setContentView(R.layout.exposure_notifications_confirm_activity) val applicationInfo = packageManager.getApplicationInfoIfExists(targetPackageName) + val selfApplicationInfo = packageManager.getApplicationInfoIfExists(packageName) when (action) { CONFIRM_ACTION_START -> { findViewById(android.R.id.title).text = getString(R.string.exposure_confirm_start_title) findViewById(android.R.id.summary).text = getString(R.string.exposure_confirm_start_summary, applicationInfo?.loadLabel(packageManager) ?: targetPackageName) findViewById