Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
boinc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
einsteinathome
boinc
Commits
640be408
Unverified
Commit
640be408
authored
1 year ago
by
Vitalii Koshura
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #5333 from AenBleidd/vko_android_battery_optimization_activity
[Android] Show Battery Optimization settings when:
parents
b2a5bbc5
612c8364
Branches
Branches containing commit
Tags
gw_app_darwin_15
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
android/BOINC/app/src/main/AndroidManifest.xml
+2
-0
2 additions, 0 deletions
android/BOINC/app/src/main/AndroidManifest.xml
android/BOINC/app/src/main/java/edu/berkeley/boinc/TasksFragment.kt
+53
-4
53 additions, 4 deletions
...INC/app/src/main/java/edu/berkeley/boinc/TasksFragment.kt
with
55 additions
and
4 deletions
android/BOINC/app/src/main/AndroidManifest.xml
+
2
−
0
View file @
640be408
...
...
@@ -35,6 +35,8 @@
<uses-permission
android:name=
"android.permission.ACCESS_NETWORK_STATE"
/>
<uses-permission
android:name=
"android.permission.KILL_BACKGROUND_PROCESSES"
/>
<uses-permission
android:name=
"android.permission.FOREGROUND_SERVICE"
/>
<uses-permission
android:name=
"android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"
/>
<uses-permission
android:name=
"android.permission.IGNORE_BATTERY_OPTIMIZATION_SETTINGS"
/>
<!--
Features required for Android TV, consoles, and set-top boxes like Nexus Player, OUYA,
Razer Forge TV, Nvidia SHIELD, etc
...
...
This diff is collapsed.
Click to expand it.
android/BOINC/app/src/main/java/edu/berkeley/boinc/TasksFragment.kt
+
53
−
4
View file @
640be408
/*
* This file is part of BOINC.
* http://boinc.berkeley.edu
* Copyright (C) 202
2
University of California
* Copyright (C) 202
3
University of California
*
* BOINC is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License
...
...
@@ -18,17 +18,25 @@
*/
package
edu.berkeley.boinc
import
android.app.AlertDialog
import
android.app.Dialog
import
android.content.BroadcastReceiver
import
android.content.Context
import
android.content.DialogInterface
import
android.content.Intent
import
android.content.IntentFilter
import
android.net.Uri
import
android.os.Build.VERSION
import
android.os.Build.VERSION_CODES
import
android.os.Bundle
import
android.os.PowerManager
import
android.os.RemoteException
import
android.provider.Settings
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
android.view.Window
import
androidx.appcompat.app.AppCompatActivity
import
androidx.fragment.app.Fragment
import
androidx.lifecycle.lifecycleScope
import
androidx.preference.PreferenceManager
...
...
@@ -39,7 +47,6 @@ import edu.berkeley.boinc.databinding.TasksLayoutBinding
import
edu.berkeley.boinc.rpc.Result
import
edu.berkeley.boinc.rpc.RpcClient
import
edu.berkeley.boinc.utils.*
import
java.util.*
import
kotlin.collections.ArrayList
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.coroutineScope
...
...
@@ -53,15 +60,57 @@ class TasksFragment : Fragment() {
private
val
mClientStatusChangeRec
:
BroadcastReceiver
=
object
:
BroadcastReceiver
()
{
override
fun
onReceive
(
context
:
Context
,
intent
:
Intent
)
{
Logging
.
logVerbose
(
Logging
.
Category
.
GUI_VIEW
,
"TasksActivity onReceive"
)
loadData
()
}
}
private
val
ifcsc
=
IntentFilter
(
"edu.berkeley.boinc.clientstatuschange"
)
private
fun
showBatterySaverOptions
()
{
try
{
val
sharedPreferences
=
PreferenceManager
.
getDefaultSharedPreferences
(
requireContext
())
val
optionName
=
"batterySaverOptionsShown"
if
(
optionName
!
in
sharedPreferences
)
{
sharedPreferences
.
edit
().
putBoolean
(
optionName
,
true
).
apply
()
val
intent
=
Intent
()
if
(
VERSION
.
SDK_INT
>=
VERSION_CODES
.
M
)
{
val
packageName
=
requireActivity
().
packageName
val
powerManager
=
requireActivity
().
getSystemService
(
AppCompatActivity
.
POWER_SERVICE
)
as
PowerManager
if
(!
powerManager
.
isIgnoringBatteryOptimizations
(
packageName
))
{
intent
.
action
=
Settings
.
ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
intent
.
data
=
Uri
.
parse
(
"package:$packageName"
)
}
}
else
{
if
(
intent
.
resolveActivity
(
requireActivity
().
packageManager
)
!=
null
)
{
intent
.
action
=
Settings
.
ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS
}
}
if
(
intent
.
action
!=
null
)
{
val
builder
=
AlertDialog
.
Builder
(
requireActivity
())
builder
.
setTitle
(
"Battery Optimization"
)
builder
.
setMessage
(
"This application have been optimized for battery usage. Do you want to open Battery Optimization Settings?"
)
builder
.
setPositiveButton
(
"Yes"
,
DialogInterface
.
OnClickListener
{
_
,
_
->
startActivity
(
intent
)
})
builder
.
setNegativeButton
(
"No"
,
DialogInterface
.
OnClickListener
{
dialog
,
_
->
dialog
.
dismiss
()
})
val
dialog
:
AlertDialog
=
builder
.
create
()
dialog
.
show
()
}
}
}
catch
(
e
:
Exception
)
{
Logging
.
logException
(
Logging
.
Category
.
GUI_VIEW
,
"showBatterySaverOptions() error: "
,
e
)
}
}
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
Logging
.
logVerbose
(
Logging
.
Category
.
GUI_VIEW
,
"TasksFragment onCreateView"
)
showBatterySaverOptions
()
// Inflate the layout for this fragment
val
binding
=
TasksLayoutBinding
.
inflate
(
inflater
,
container
,
false
)
recyclerViewAdapter
=
TaskRecyclerViewAdapter
(
this
,
data
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment