Skip to content

Commit

Permalink
Remove unnecessary dependency on lifecycle-extension
Browse files Browse the repository at this point in the history
  • Loading branch information
deepanshu42 committed Jun 23, 2022
1 parent 06307ff commit 39d458c
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 97 deletions.
3 changes: 0 additions & 3 deletions chuck-mqtt/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ dependencies {

implementation(deps.android.gson)

implementation(deps.android.androidx.lifecycleExtensions)
implementation(deps.android.androidx.lifecycleCommons)

implementation(deps.android.androidx.appcompact)
implementation(deps.android.androidx.fragmentExtensions)
implementation(deps.android.androidx.coreKtx)
Expand Down
4 changes: 1 addition & 3 deletions courier-core-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ apiValidation {

dependencies {
api(project(":courier-core"))
implementation(deps.android.androidx.lifecycleExtensions)
implementation(deps.android.androidx.lifecycleCommons)
implementation(deps.android.androidx.lifecycleProcess)
implementation(deps.android.androidx.annotation)
}

apply(from = "${rootProject.projectDir}/gradle/publish-module.gradle")

This file was deleted.

4 changes: 0 additions & 4 deletions mqtt-client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,8 @@ dependencies {
implementation(project(":paho"))
implementation(project(":adaptive-keep-alive"))
implementation(project(":network-tracker"))
implementation(project(":app-state-manager"))
implementation(project(":timer-pingsender"))

implementation(deps.android.androidx.lifecycleExtensions)
implementation(deps.android.androidx.lifecycleCommons)

implementation(deps.android.room.roomRuntime)
kapt(deps.android.room.roomCompiler)

Expand Down
3 changes: 0 additions & 3 deletions network-tracker/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ apiValidation {
dependencies {
api(project(":courier-core"))
implementation(deps.android.androidx.coreKtx)
implementation(deps.android.androidx.lifecycleExtensions)
implementation(deps.android.androidx.lifecycleCommons)
implementation(deps.android.androidx.lifecycleProcess)

testImplementation(deps.android.test.kotlinTestJunit)
}
Expand Down
16 changes: 6 additions & 10 deletions pingsender/alarm-pingsender/api/alarm-pingsender.api
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
public final class com/gojek/alarm/pingsender/AlarmPingSenderConfig {
public fun <init> ()V
public fun <init> (ZZZIIZ)V
public synthetic fun <init> (ZZZIIZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (ZZIZ)V
public synthetic fun <init> (ZZIZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Z
public final fun component2 ()Z
public final fun component3 ()Z
public final fun component4 ()I
public final fun component5 ()I
public final fun component6 ()Z
public final fun copy (ZZZIIZ)Lcom/gojek/alarm/pingsender/AlarmPingSenderConfig;
public static synthetic fun copy$default (Lcom/gojek/alarm/pingsender/AlarmPingSenderConfig;ZZZIIZILjava/lang/Object;)Lcom/gojek/alarm/pingsender/AlarmPingSenderConfig;
public final fun component3 ()I
public final fun component4 ()Z
public final fun copy (ZZIZ)Lcom/gojek/alarm/pingsender/AlarmPingSenderConfig;
public static synthetic fun copy$default (Lcom/gojek/alarm/pingsender/AlarmPingSenderConfig;ZZIZILjava/lang/Object;)Lcom/gojek/alarm/pingsender/AlarmPingSenderConfig;
public fun equals (Ljava/lang/Object;)Z
public final fun getMaxNumberOfBackgroundAlarmPingsAllowed ()I
public final fun getPingWakeLockTimeout ()I
public final fun getShouldLimitBackgroundPings ()Z
public final fun getUseElapsedRealTimeAlarm ()Z
public fun hashCode ()I
public final fun isMqttAllowWhileIdle ()Z
Expand Down
3 changes: 0 additions & 3 deletions pingsender/alarm-pingsender/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ apiValidation {
dependencies {
api(project(":mqtt-pingsender"))
implementation(project(":courier-core-android"))
implementation(deps.android.androidx.lifecycleExtensions)
implementation(deps.android.androidx.lifecycleCommons)
implementation(deps.android.androidx.lifecycleProcess)

testImplementation(deps.android.test.kotlinTestJunit)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
/*
* Copyright (c) 2014 IBM Corp.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package com.gojek.alarm.pingsender

import android.annotation.SuppressLint
Expand All @@ -25,25 +13,17 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.os.Handler
import android.os.Looper
import android.os.PowerManager
import android.os.PowerManager.WakeLock
import android.os.SystemClock
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent
import androidx.lifecycle.ProcessLifecycleOwner
import com.gojek.courier.extensions.fromMillisToSeconds
import com.gojek.courier.extensions.fromNanosToMillis
import com.gojek.courier.utils.AppStateProvider
import com.gojek.courier.utils.BuildInfoProvider
import com.gojek.courier.utils.Clock
import com.gojek.courier.utils.extensions.addImmutableFlag
import com.gojek.mqtt.pingsender.IPingSenderEvents
import com.gojek.mqtt.pingsender.MqttPingSender
import com.gojek.mqtt.pingsender.NoOpPingSenderEvents
import java.util.concurrent.atomic.AtomicInteger
import org.eclipse.paho.client.mqttv3.ILogger
import org.eclipse.paho.client.mqttv3.IMqttActionListener
import org.eclipse.paho.client.mqttv3.IMqttToken
Expand All @@ -64,9 +44,8 @@ internal class AlarmPingSender(
private val applicationContext: Context,
private val alarmPingSenderConfig: AlarmPingSenderConfig,
private val clock: Clock = Clock(),
private val buildInfoProvider: BuildInfoProvider = BuildInfoProvider(),
private val appStateProvider: AppStateProvider = AppStateProvider()
) : MqttPingSender, LifecycleObserver {
private val buildInfoProvider: BuildInfoProvider = BuildInfoProvider()
) : MqttPingSender {
private lateinit var comms: ClientComms
private lateinit var logger: ILogger
private val alarmReceiver = AlarmReceiver()
Expand All @@ -76,7 +55,6 @@ internal class AlarmPingSender(

@Volatile
private var hasStarted = false
private val bgAlarmPingsCounter = AtomicInteger(0)

override fun init(comms: ClientComms, logger: ILogger) {
this.comms = comms
Expand Down Expand Up @@ -132,7 +110,6 @@ internal class AlarmPingSender(
// Ignore unregister errors.
}
}
resetBGAlarmPingsCounter()
}

override fun schedule(delayInMilliseconds: Long) {
Expand Down Expand Up @@ -228,26 +205,9 @@ internal class AlarmPingSender(

// No ping has been sent.
if (token == null) {
resetBGAlarmPingsCounter()
pingSenderEvents.pingMqttTokenNull(serverUri, comms.keepAlive.fromMillisToSeconds())
return
}
if (alarmPingSenderConfig.shouldLimitBackgroundPings && !appStateProvider.isAppInForeground) {
if (bgAlarmPingsCounter.get() >= alarmPingSenderConfig.maxNumberOfBackgroundAlarmPingsAllowed) {
logger.d(
TAG,
"background alarm pings limit reached. Not scheduling now"
)
pingSenderEvents.onBackgroundAlarmPingLimitReached()
return
} else {
bgAlarmPingsCounter.getAndIncrement()
logger.d(
TAG,
"background alarm pings counter increased to " + bgAlarmPingsCounter.get()
)
}
}
try {
// Assign new callback to token to execute code after PingResq
// arrives. Get another wakelock even receiver already has one,
Expand Down Expand Up @@ -309,15 +269,6 @@ internal class AlarmPingSender(
}
}

@OnLifecycleEvent(Lifecycle.Event.ON_START)
fun onForeground() {
resetBGAlarmPingsCounter()
}

private fun resetBGAlarmPingsCounter() {
bgAlarmPingsCounter.set(0)
}

companion object {
// Identifier for Intents, log messages, etc..
private const val TAG = "AlarmPingSender"
Expand All @@ -328,10 +279,4 @@ internal class AlarmPingSender(
private const val PING_WAKELOCK = "$MQTT.client"
private const val wakeLockTag = PING_WAKELOCK
}

init {
Handler(Looper.getMainLooper()).post {
ProcessLifecycleOwner.get().lifecycle.addObserver(this)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ package com.gojek.alarm.pingsender
data class AlarmPingSenderConfig(
val isMqttPingWakeUp: Boolean = true,
val isMqttAllowWhileIdle: Boolean = true,
val shouldLimitBackgroundPings: Boolean = false,
val pingWakeLockTimeout: Int = DEFAULT_PING_WAKELOCK_TIMEOUT_IN_SECONDS,
val maxNumberOfBackgroundAlarmPingsAllowed: Int = MAX_NUMBER_OF_BACKGROUND_ALARM_PINGS,
val useElapsedRealTimeAlarm: Boolean = false
)

private const val MAX_NUMBER_OF_BACKGROUND_ALARM_PINGS = 4
private const val DEFAULT_PING_WAKELOCK_TIMEOUT_IN_SECONDS = 0 // 0 seconds

0 comments on commit 39d458c

Please sign in to comment.