Commit d2f41886 authored by stopcovid@lunabee.com's avatar stopcovid@lunabee.com
Browse files

Update to 1.0.1

parent 96cd0184
......@@ -6,6 +6,10 @@ Component: Kotlinx Coroutines
License Text URL: https://github.com/Kotlin/kotlinx.coroutines/blob/master/LICENSE.txt
Source Code: https://github.com/Kotlin/kotlinx.coroutines
Component: Timber
License Text URL: https://github.com/JakeWharton/timber/blob/master/LICENSE.txt
Source Code: https://github.com/JakeWharton/timber
================================================================================
BSD 3-Clause
================================================================================
......
......@@ -17,8 +17,8 @@ android {
defaultConfig {
minSdkVersion 21
targetSdkVersion 29
versionCode 8
versionName "1.0.0"
versionCode 9
versionName "1.1.0"
}
compileOptions {
......@@ -43,6 +43,7 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
api 'no.nordicsemi.android.support.v18:scanner:1.4.3'
implementation 'com.jakewharton.timber:timber:4.7.1'
testImplementation 'junit:junit:4.13'
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
......
......@@ -8,8 +8,7 @@
~ Created by Orange / Date - 2020/04/27 - for the STOP-COVID project
-->
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.orange.proximitynotification">
......@@ -30,4 +29,5 @@
</application>
</manifest>
......@@ -16,7 +16,6 @@ import android.bluetooth.BluetoothAdapter
import android.content.Intent
import android.content.IntentFilter
import android.os.IBinder
import android.util.Log
import com.orange.proximitynotification.ble.BleProximityNotification
import com.orange.proximitynotification.ble.BleProximityNotificationFactory
import com.orange.proximitynotification.ble.BleSettings
......@@ -25,6 +24,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import timber.log.Timber
import kotlin.coroutines.CoroutineContext
/**
......@@ -33,10 +33,6 @@ import kotlin.coroutines.CoroutineContext
abstract class ProximityNotificationService : Service(),
ProximityNotificationCallback, ProximityPayloadProvider, CoroutineScope {
companion object {
private val TAG = ProximityNotificationService::class.java.simpleName
}
private var bleProximityNotification: BleProximityNotification? = null
private var bluetoothStateBroadcastReceiver: BluetoothStateBroadcastReceiver? = null
......@@ -88,6 +84,17 @@ abstract class ProximityNotificationService : Service(),
bleProximityNotification?.notifyPayloadUpdated()
}
/**
* Notify that [BleSettings] have changed
* It will restart [BleProximityNotification]
*/
fun notifyBleSettingsUpdate() {
if (isRunning()) {
stopBleProximityNotification()
startBleProximityNotification()
}
}
/**
* @return true if ProximityNotification is running, false otherwise
*/
......@@ -157,7 +164,7 @@ abstract class ProximityNotificationService : Service(),
* @see ProximityNotification#stop
*/
protected open fun onBluetoothDisabled() {
Log.d(TAG, "Bluetooth disabled")
Timber.d("Bluetooth disabled")
doStop()
}
......@@ -169,7 +176,7 @@ abstract class ProximityNotificationService : Service(),
* @see ProximityNotification#start
*/
protected open fun onBluetoothEnabled() {
Log.d(TAG, "Bluetooth enabled")
Timber.d("Bluetooth enabled")
doStart()
}
......
......@@ -35,8 +35,6 @@ class BleProximityNotification(
) : ProximityNotification {
companion object {
private val TAG: String = BleProximityNotification::class.java.simpleName
private const val VERSION = 1
}
......
......@@ -15,29 +15,25 @@ import android.bluetooth.le.AdvertiseData
import android.bluetooth.le.AdvertiseSettings
import android.bluetooth.le.BluetoothLeAdvertiser
import android.os.ParcelUuid
import android.util.Log
import com.orange.proximitynotification.ble.BleSettings
import timber.log.Timber
class BleAdvertiserImpl(
override val settings: BleSettings,
private val bluetoothAdvertiser: BluetoothLeAdvertiser
) : BleAdvertiser {
companion object {
private val TAG: String = BleAdvertiserImpl::class.java.simpleName
}
private var advertiseCallback: InnerAdvertiseCallback? = null
override fun start(data: ByteArray, callback: BleAdvertiser.Callback) {
Log.d(TAG, "Starting Advertising")
Timber.d("Starting Advertising")
doStop()
doStart(data, callback)
}
override fun stop() {
Log.d(TAG, "Stopping Advertising")
Timber.d("Stopping Advertising")
doStop()
}
......@@ -80,13 +76,13 @@ class BleAdvertiserImpl(
AdvertiseCallback() {
override fun onStartFailure(errorCode: Int) {
super.onStartFailure(errorCode)
Log.w(TAG, "Advertising failed errorCode=$errorCode")
Timber.w("Advertising failed errorCode=$errorCode")
callback.onError(errorCode)
}
override fun onStartSuccess(settingsInEffect: AdvertiseSettings) {
super.onStartSuccess(settingsInEffect)
Log.d(TAG, "Advertising successfully started")
Timber.d("Advertising successfully started")
}
}
......
......@@ -19,20 +19,16 @@ import android.bluetooth.BluetoothProfile
import android.content.Context
import android.os.Build.VERSION.SDK_INT
import android.os.Build.VERSION_CODES.M
import android.util.Log
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.Channel.Factory.CONFLATED
import kotlinx.coroutines.channels.SendChannel
import timber.log.Timber
internal class BleGattClientImpl(
override val bluetoothDevice: BluetoothDevice,
private val context: Context
) : BleGattClient {
companion object {
private val TAG = BleGattClientImpl::class.java.simpleName
}
private val remoteRssiChannel = Channel<ValueWithStatus<Int>>(CONFLATED)
private val connectionStateChannel = Channel<ValueWithStatus<Int>>(CONFLATED)
......@@ -79,7 +75,7 @@ internal class BleGattClientImpl(
private inner class Callback : BluetoothGattCallback() {
override fun onConnectionStateChange(gatt: BluetoothGatt, status: Int, newState: Int) {
Log.d(TAG, "onConnectionStateChange status=$status, newState=$newState")
Timber.d("onConnectionStateChange status=$status, newState=$newState")
_isConnected = status == GATT_SUCCESS && newState == BluetoothProfile.STATE_CONNECTED
when (status) {
......@@ -89,7 +85,7 @@ internal class BleGattClientImpl(
}
override fun onReadRemoteRssi(gatt: BluetoothGatt, rssi: Int, status: Int) {
Log.d(TAG, "onReadRemoteRssi status=$status, rssi=$rssi")
Timber.d("onReadRemoteRssi status=$status, rssi=$rssi")
remoteRssiChannel.safeOffer(ValueWithStatus(status = status, value = rssi))
}
}
......
......@@ -18,7 +18,6 @@ import android.bluetooth.BluetoothGattServerCallback
import android.bluetooth.BluetoothGattService
import android.bluetooth.BluetoothManager
import android.content.Context
import android.util.Log
import com.orange.proximitynotification.ble.BleSettings
import com.orange.proximitynotification.tools.CoroutineContextProvider
import kotlinx.coroutines.CoroutineScope
......@@ -32,6 +31,7 @@ import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.launch
import kotlinx.coroutines.withTimeout
import timber.log.Timber
internal class BleGattManagerImpl(
override val settings: BleSettings,
......@@ -42,10 +42,6 @@ internal class BleGattManagerImpl(
private val coroutineContextProvider: CoroutineContextProvider = CoroutineContextProvider.Default()
) : BleGattManager {
companion object {
private val TAG = BleGattManagerImpl::class.java.simpleName
}
private lateinit var executionChannel: Channel<suspend () -> Unit>
private var executionJob: Job? = null
......@@ -59,7 +55,7 @@ internal class BleGattManagerImpl(
)
override fun start(callback: BleGattManager.Callback) {
Log.d(TAG, "Starting GATT server")
Timber.d("Starting GATT server")
stop()
......@@ -73,7 +69,7 @@ internal class BleGattManagerImpl(
}
override fun stop() {
Log.d(TAG, "Stopping GATT server")
Timber.d("Stopping GATT server")
executionJob?.cancel()
executionJob = null
......@@ -100,10 +96,10 @@ internal class BleGattManagerImpl(
val rssi = client.readRemoteRssi()
rssiChannel.send(rssi)
} catch (e: TimeoutCancellationException) {
Log.d(TAG, "Request remote rssi failed. Connection timeout", e)
Timber.d(e, "Request remote rssi failed. Connection timeout")
rssiChannel.close()
} catch (t: Throwable) {
Log.d(TAG, "Request remote rssi failed with exception", t)
Timber.d(t, "Request remote rssi failed with exception")
rssiChannel.close()
} finally {
client.close()
......@@ -160,7 +156,7 @@ internal class BleGattManagerImpl(
value
)
Log.d(TAG, "onCharacteristicWriteRequest")
Timber.d("onCharacteristicWriteRequest")
val result = when (characteristic.uuid) {
payloadCharacteristic.uuid -> {
......@@ -175,7 +171,7 @@ internal class BleGattManagerImpl(
}
Log.d(TAG, "onCharacteristicWriteRequest result=$result")
Timber.d("onCharacteristicWriteRequest result=$result")
if (responseNeeded) {
bluetoothGattServer?.sendResponse(device, requestId, result, offset, null)
}
......
......@@ -11,13 +11,13 @@
package com.orange.proximitynotification.ble.scanner
import android.os.ParcelUuid
import android.util.Log
import com.orange.proximitynotification.ble.BleSettings
import no.nordicsemi.android.support.v18.scanner.BluetoothLeScannerCompat
import no.nordicsemi.android.support.v18.scanner.ScanCallback
import no.nordicsemi.android.support.v18.scanner.ScanFilter
import no.nordicsemi.android.support.v18.scanner.ScanResult
import no.nordicsemi.android.support.v18.scanner.ScanSettings
import timber.log.Timber
class BleScannerImpl(
override val settings: BleSettings,
......@@ -25,22 +25,20 @@ class BleScannerImpl(
) : BleScanner {
companion object {
private val TAG: String = BleScannerImpl::class.java.simpleName
private const val APPLE_MANUFACTURER_ID = 76
}
private var scanCallback: ScanCallback? = null
override fun start(callback: BleScanner.Callback) {
Log.d(TAG, "Starting scanner")
Timber.d("Starting scanner")
doStop()
doStart(callback)
}
override fun stop() {
Log.d(TAG, "Stopping scanner")
Timber.d("Stopping scanner")
doStop()
}
......@@ -108,7 +106,7 @@ class BleScannerImpl(
override fun onScanFailed(errorCode: Int) {
super.onScanFailed(errorCode)
Log.w(TAG, "onScanFailed errorCode = $errorCode")
Timber.w("onScanFailed errorCode = $errorCode")
callback.onError(errorCode)
}
}
......
......@@ -17,7 +17,7 @@ buildscript {
}
dependencies {
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.2.2"
classpath 'com.android.tools.build:gradle:3.6.3'
classpath 'com.android.tools.build:gradle:4.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.karumi:shot:4.3.0"
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.12'
......
......@@ -30,6 +30,7 @@ android {
buildConfigField 'String', 'SERVER_URL', '"https://app.stopcovid.gouv.fr/json/version-22/"'
buildConfigField 'String', 'SERVER_CERTIFICATE_SHA256', '"sha256/sXQojvwsiyblrpMQIVRXGC5u7AgknzTJm+VIK1kQmD8="'
buildConfigField 'String', 'CONFIG_JSON', '"config.json"'
}
compileOptions {
......@@ -45,7 +46,7 @@ android {
dependencies {
// Fix https://stackoverflow.com/questions/41025200/android-view-inflateexception-error-inflating-class-android-webkit-webview/58131421#58131421
api 'androidx.appcompat:appcompat:1.2.0-beta01'
api 'androidx.appcompat:appcompat:1.2.0-rc01'
api 'androidx.constraintlayout:constraintlayout:2.0.0-beta6'
api 'androidx.core:core-ktx:1.3.0'
api 'androidx.lifecycle:lifecycle-extensions:2.2.0'
......@@ -59,7 +60,7 @@ dependencies {
api 'androidx.emoji:emoji-appcompat:1.0.0'
api 'androidx.emoji:emoji-bundled:1.0.0'
api 'com.google.android.material:material:1.2.0-alpha06'
api 'com.google.android.material:material:1.2.0-beta01'
api 'com.google.code.gson:gson:2.8.6'
api 'com.jakewharton.timber:timber:4.7.1'
......
......@@ -22,6 +22,8 @@ import androidx.emoji.text.EmojiCompat
import com.lunabeestudio.stopcovid.coreui.BuildConfig
import com.lunabeestudio.stopcovid.coreui.network.OkHttpClient
import okhttp3.Request
import retrofit2.HttpException
import retrofit2.Response
import timber.log.Timber
import java.io.File
import java.text.Normalizer
......@@ -38,7 +40,7 @@ fun String.download(context: Context): String {
response.body!!.string()
} else {
Timber.d(response.body?.string())
throw Exception()
throw HttpException(Response.error<Any>(response.body!!, response))
}
}
......@@ -57,7 +59,7 @@ fun String.saveTo(context: Context, file: File) {
}
} else {
Timber.d(response.body?.string())
throw Exception()
throw HttpException(Response.error<Any>(response.body!!, response))
}
}
......
......@@ -18,7 +18,7 @@ import timber.log.Timber
object ConfigManager {
private const val URL: String = BuildConfig.SERVER_URL + "config.json"
private const val URL: String = BuildConfig.SERVER_URL + BuildConfig.CONFIG_JSON
@WorkerThread
fun fetchLast(context: Context): String {
......
......@@ -36,10 +36,8 @@ class StringsManager : ServerManager() {
fun getStrings(): HashMap<String, String> = _strings
fun init(context: Context) {
CoroutineScope(Dispatchers.IO).launch {
prevLanguage = Locale.getDefault().language
_strings = StringsManager().loadLocal(context)
}
prevLanguage = Locale.getDefault().language
_strings = StringsManager().loadLocal(context)
}
fun appForeground(context: Context) {
......
......@@ -48,10 +48,10 @@ object OkHttpClient {
}
addInterceptor(getDefaultHeaderInterceptor())
addInterceptor(getLogInterceptor())
callTimeout(1L, TimeUnit.MINUTES)
connectTimeout(1L, TimeUnit.MINUTES)
readTimeout(1L, TimeUnit.MINUTES)
writeTimeout(1L, TimeUnit.MINUTES)
callTimeout(30L, TimeUnit.SECONDS)
connectTimeout(30L, TimeUnit.SECONDS)
readTimeout(30L, TimeUnit.SECONDS)
writeTimeout(30L, TimeUnit.SECONDS)
}.build()
}
......
......@@ -41,7 +41,7 @@ class SingleLiveEvent<T> : MutableLiveData<T>() {
}
// Observe the internal MutableLiveData
super.observe(owner, Observer<T> { t ->
super.observe(owner, Observer { t ->
if (pending.compareAndSet(true, false)) {
observer.onChanged(t)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment