-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #186 from ooni/battery-optimizations
Request to ignore battery optimizations
- Loading branch information
Showing
13 changed files
with
268 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
composeApp/src/androidMain/kotlin/org/ooni/probe/MainActivityLifecycleCallbacks.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.ooni.probe | ||
|
||
import android.app.Activity | ||
import android.app.Application.ActivityLifecycleCallbacks | ||
import android.os.Bundle | ||
|
||
class MainActivityLifecycleCallbacks : ActivityLifecycleCallbacks { | ||
var activity: MainActivity? = null | ||
private set | ||
|
||
override fun onActivityCreated( | ||
activity: Activity, | ||
savedInstanceState: Bundle?, | ||
) { | ||
this.activity = activity as? MainActivity | ||
} | ||
|
||
override fun onActivityStarted(activity: Activity) {} | ||
|
||
override fun onActivityResumed(activity: Activity) {} | ||
|
||
override fun onActivityPaused(activity: Activity) {} | ||
|
||
override fun onActivityStopped(activity: Activity) {} | ||
|
||
override fun onActivitySaveInstanceState( | ||
activity: Activity, | ||
outState: Bundle, | ||
) {} | ||
|
||
override fun onActivityDestroyed(activity: Activity) { | ||
this.activity = null | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
composeApp/src/androidMain/kotlin/org/ooni/probe/config/AndroidBatteryOptimization.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.ooni.probe.config | ||
|
||
import android.os.PowerManager | ||
|
||
class AndroidBatteryOptimization( | ||
private val powerManager: PowerManager, | ||
private val packageName: String, | ||
private val requestCall: (() -> Unit) -> Unit, | ||
) : BatteryOptimization { | ||
override val isSupported = true | ||
|
||
override val isIgnoring: Boolean | ||
get() = powerManager.isIgnoringBatteryOptimizations(packageName) | ||
|
||
override fun requestIgnore(onResponse: (Boolean) -> Unit) { | ||
requestCall { | ||
onResponse(isIgnoring) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
composeApp/src/commonMain/kotlin/org/ooni/probe/config/BatteryOptimization.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.ooni.probe.config | ||
|
||
interface BatteryOptimization { | ||
val isSupported: Boolean get() = false | ||
|
||
val isIgnoring: Boolean | ||
get() = throw IllegalStateException("Battery Optimization not supported") | ||
|
||
fun requestIgnore(onResponse: (Boolean) -> Unit) { | ||
throw IllegalStateException("Battery Optimization not supported") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.