Allow overriding PUSH_URL and RATE_LIMIT_URL in gradle.properties (#1032)

* Extract PUSH_URL and RATE_LIMIT_URL as BuildConfig values that can be overriden in local.properties

* Put push and rate limit URLs in gradle.properties instead of local.properties which can be overwritten by Android Studio
This commit is contained in:
Patrick Decat 2020-10-11 20:14:49 +02:00 committed by GitHub
parent 46dde1912e
commit cce1608bf0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 3 deletions

View File

@ -43,7 +43,15 @@ If you get stuck while setting up your own environment, you can ask questions in
### Push Notifications
If you want to work on push notifications or use a development build with push notifications please go the server side code [HERE](https://github.com/home-assistant/mobile-apps-fcm-push) and deploy it to your firebase project. Once you have your androidV1 URL to the deployed service, exchange that for your local builds [PUSH_URL](https://github.com/home-assistant/android/blob/master/common/src/main/java/io/homeassistant/companion/android/common/data/integration/impl/IntegrationRepositoryImpl.kt#L43).
If you want to work on push notifications or use a development build with push notifications, please go the server side code [HERE](https://github.com/home-assistant/mobile-apps-fcm-push) and deploy it to your firebase project. Once you have your androidV1 URL to the deployed service, set it in to your `${GRADLE_USER_HOME}/gradle.properties` file, e.g.:
```properties
homeAssistantAndroidPushUrl=https://mydomain.cloudfunctions.net/androidV1
```
You can also define the rate limit function URL, e.g.:
```properties
homeAssistantAndroidRateLimitUrl=https://mydomain.cloudfunctions.net/checkRateLimits
```
## App Flavors

View File

@ -4,11 +4,16 @@ plugins {
id("kotlin-kapt")
}
val homeAssistantAndroidPushUrl: String by project
val homeAssistantAndroidRateLimitUrl: String by project
android {
compileSdkVersion(Config.Android.compileSdk)
defaultConfig {
minSdkVersion(Config.Android.minSdk)
buildConfigField("String", "PUSH_URL", "\"$homeAssistantAndroidPushUrl\"")
buildConfigField("String", "RATE_LIMIT_URL", "\"$homeAssistantAndroidRateLimitUrl\"")
}
}

View File

@ -1,6 +1,7 @@
package io.homeassistant.companion.android.common.data.integration.impl
import android.util.Log
import io.homeassistant.companion.android.common.BuildConfig
import io.homeassistant.companion.android.common.data.LocalStorage
import io.homeassistant.companion.android.common.data.authentication.AuthenticationRepository
import io.homeassistant.companion.android.common.data.integration.DeviceRegistration
@ -44,7 +45,7 @@ class IntegrationRepositoryImpl @Inject constructor(
private const val APP_ID = "io.homeassistant.companion.android"
private const val APP_NAME = "Home Assistant"
private const val OS_NAME = "Android"
private const val PUSH_URL = "https://mobile-apps.home-assistant.io/api/sendPush/android/v1"
private const val PUSH_URL = BuildConfig.PUSH_URL
private const val PREF_APP_VERSION = "app_version"
private const val PREF_DEVICE_NAME = "device_name"
@ -57,7 +58,7 @@ class IntegrationRepositoryImpl @Inject constructor(
private const val PREF_SESSION_EXPIRE = "session_expire"
private const val PREF_SENSORS_REGISTERED = "sensors_registered"
private const val TAG = "IntegrationRepository"
private const val RATE_LIMIT_URL = "https://mobile-apps.home-assistant.io/api/checkRateLimits"
private const val RATE_LIMIT_URL = BuildConfig.RATE_LIMIT_URL
}
override suspend fun registerDevice(deviceRegistration: DeviceRegistration) {

View File

@ -15,3 +15,8 @@ org.gradle.jvmargs=-Xmx1536m
kotlin.code.style=official
android.useAndroidX = true
# The default API URL used by the Home Assistant Android application.
# Override these in your ${GRADLE_USER_HOME}/gradle.properties file if needed.
homeAssistantAndroidPushUrl=https://mobile-apps.home-assistant.io/api/sendPush/android/v1
homeAssistantAndroidRateLimitUrl=https://mobile-apps.home-assistant.io/api/checkRateLimits