Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
F
File Recovery RecycleBin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wanglei
File Recovery RecycleBin
Commits
d8150eaf
Commit
d8150eaf
authored
Jul 30, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
c2ee5c97
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
8 deletions
+19
-8
BatteryActivity.kt
...ilerecoveryrecyclebin/activity/battery/BatteryActivity.kt
+19
-8
No files found.
app/src/main/java/com/base/filerecoveryrecyclebin/activity/battery/BatteryActivity.kt
View file @
d8150eaf
...
...
@@ -10,6 +10,7 @@ import com.base.filerecoveryrecyclebin.databinding.ActivityBatteryBinding
import
com.base.filerecoveryrecyclebin.help.BaseActivity
import
com.base.filerecoveryrecyclebin.receiver.BatteryReceiver
import
com.base.filerecoveryrecyclebin.utils.BarUtils
import
com.base.filerecoveryrecyclebin.utils.LogEx
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.delay
import
kotlinx.coroutines.flow.MutableSharedFlow
...
...
@@ -19,10 +20,11 @@ import kotlinx.coroutines.isActive
import
kotlinx.coroutines.launch
import
java.io.BufferedReader
import
java.io.FileReader
import
java.io.IOException
class
BatteryActivity
:
BaseActivity
<
ActivityBatteryBinding
>()
{
private
val
TAG
=
"BatteryActivity"
override
val
binding
:
ActivityBatteryBinding
by
lazy
{
ActivityBatteryBinding
.
inflate
(
layoutInflater
)
}
...
...
@@ -45,12 +47,12 @@ class BatteryActivity : BaseActivity<ActivityBatteryBinding>() {
lifecycleScope
.
launch
(
Dispatchers
.
Main
)
{
currentFlow
.
collectLatest
{
binding
.
tvElectric
.
text
=
"${
currentFlow
}mA"
binding
.
tvElectric
.
text
=
"${
it
}mA"
}
}
lifecycleScope
.
launch
(
Dispatchers
.
Main
)
{
averageFlow
.
collectLatest
{
binding
.
tvCurrentAverage
.
text
=
"${
averageFlow
}mA"
binding
.
tvCurrentAverage
.
text
=
"${
it
}mA"
}
}
...
...
@@ -81,14 +83,18 @@ class BatteryActivity : BaseActivity<ActivityBatteryBinding>() {
val
getMethod
=
systemProperties
.
getDeclaredMethod
(
"get"
,
String
::
class
.
java
)
val
platName
=
getMethod
.
invoke
(
null
,
"ro.hardware"
)
as
String
LogEx
.
logDebug
(
TAG
,
"platName=$platName"
)
val
filePath
:
String
=
if
(
platName
.
startsWith
(
"mt"
)
||
platName
.
startsWith
(
"MT"
))
{
"/sys/class/power_supply/battery/device/FG_Battery_CurrentConsumption"
// MTK平台该值不区分充放电,都为负数
}
else
if
(
platName
.
startsWith
(
"qcom"
))
{
"/sys/class/power_supply/battery/current_now"
}
else
{
}
else
if
(
platName
.
startsWith
(
"exynos"
))
"/sys/class/power_supply/battery/BatteryAverageCurrent"
else
{
""
}
LogEx
.
logDebug
(
TAG
,
"filePath=$filePath"
)
return
filePath
}
...
...
@@ -105,13 +111,13 @@ class BatteryActivity : BaseActivity<ActivityBatteryBinding>() {
var
loopCount
=
0
lifecycleScope
.
launch
(
Dispatchers
.
IO
)
{
while
(
isActive
)
{
delay
(
1500
)
val
currentValue
=
readFileValue
(
filePath
)
mCurrentFlow
.
emit
(
currentValue
)
sum
+=
currentValue
loopCount
++
val
average
=
sum
/
loopCount
.
toFloat
()
mAverageFlow
.
emit
(
average
)
delay
(
150
)
}
}
}
...
...
@@ -119,11 +125,16 @@ class BatteryActivity : BaseActivity<ActivityBatteryBinding>() {
private
fun
readFileValue
(
filePath
:
String
):
Int
{
var
value
=
0
runCatching
{
val
br
=
BufferedReader
(
FileReader
(
filePath
))
var
br
:
BufferedReader
?
=
null
try
{
br
=
BufferedReader
(
FileReader
(
filePath
))
val
line
=
br
.
readLine
()
br
.
close
()
value
=
line
?.
toInt
()
?:
0
LogEx
.
logDebug
(
TAG
,
"readFileValue value=$value"
)
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
}
finally
{
br
?.
close
()
}
return
value
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment