Skip to content

Commit

Permalink
Merge pull request #205 from DP-3T/feature/fix-check-for-location-ser…
Browse files Browse the repository at this point in the history
…vices-needed

use settings value to check if locationLess scanning is supported
  • Loading branch information
simonroesch authored Sep 15, 2020
2 parents 73823b3 + 4318676 commit 7a03c1d
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2020 Ubique Innovation AG <https://www.ubique.ch>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* SPDX-License-Identifier: MPL-2.0
*/

package org.dpppt.android.sdk.internal.nearby;

import android.content.Context;
import android.os.Build;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;

import org.dpppt.android.sdk.internal.ErrorHelper;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.assertEquals;

@RunWith(AndroidJUnit4.class)
public class LocationLessScanningTest {

private Context context;

@Before
public void setup() {
context = InstrumentationRegistry.getInstrumentation().getContext();
}

@Test
public void checkLocationLessScanningOnAndroidR(){
assertEquals(Build.VERSION.SDK_INT >= Build.VERSION_CODES.R, ErrorHelper.deviceSupportsLocationlessScanning(context));
}
}
3 changes: 1 addition & 2 deletions dp3t-sdk/sdk/src/main/java/org/dpppt/android/sdk/DP3T.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.location.LocationManager;
import android.os.Build;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.util.Consumer;
Expand Down Expand Up @@ -100,7 +99,7 @@ private static void executeInit(Context context, AppConfigManager appConfigManag
new BluetoothStateBroadcastReceiver(),
new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED)
);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
if (!ErrorHelper.deviceSupportsLocationlessScanning(context)) {
context.registerReceiver(
new LocationServiceBroadcastReceiver(),
new IntentFilter(LocationManager.MODE_CHANGED_ACTION)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.PowerManager;
import android.provider.Settings;
import android.system.ErrnoException;
import android.system.OsConstants;

Expand All @@ -22,7 +22,6 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import javax.net.ssl.SSLException;

import com.google.android.gms.common.api.ApiException;
Expand Down Expand Up @@ -63,7 +62,7 @@ public static Collection<ErrorState> checkTracingErrorStatus(Context context, Ap
}
}

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R && !LocationServiceUtil.isLocationEnabled(context)) {
if (!deviceSupportsLocationlessScanning(context) && !LocationServiceUtil.isLocationEnabled(context)) {
errors.add(ErrorState.LOCATION_SERVICE_DISABLED);
}

Expand Down Expand Up @@ -106,6 +105,11 @@ public static Collection<ErrorState> checkTracingErrorStatus(Context context, Ap
return errors;
}

public static boolean deviceSupportsLocationlessScanning(Context context) {
return Settings.Global.getInt(context.getApplicationContext().getContentResolver(),
"bluetooth_sanitized_exposure_notification_supported", 0) == 1;
}

public static Collection<ErrorState> getDelayableSyncErrors() {
return new HashSet<>(DELAYABLE_SYNC_ERRORS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*
* SPDX-License-Identifier: MPL-2.0
*/

package org.dpppt.android.sdk.internal.util;

import android.content.Context;
Expand All @@ -17,7 +16,7 @@

public class LocationServiceUtil {

public static Boolean isLocationEnabled(Context context) {
public static boolean isLocationEnabled(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
return lm != null && lm.isLocationEnabled();
Expand Down

0 comments on commit 7a03c1d

Please sign in to comment.