Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_47647075
emmagee
提交
408aacbb
E
emmagee
项目概览
weixin_47647075
/
emmagee
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
emmagee
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
408aacbb
编写于
8月 14, 2013
作者:
A
andrewleo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add batt monitor
上级
6f1f27df
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
194 addition
and
10 deletion
+194
-10
res/layout/floating.xml
res/layout/floating.xml
+10
-0
src/com/netease/qa/emmagee/service/EmmageeService.java
src/com/netease/qa/emmagee/service/EmmageeService.java
+8
-3
src/com/netease/qa/emmagee/utils/CpuInfo.java
src/com/netease/qa/emmagee/utils/CpuInfo.java
+15
-7
src/com/netease/qa/emmagee/utils/CurrentInfo.java
src/com/netease/qa/emmagee/utils/CurrentInfo.java
+161
-0
未找到文件。
res/layout/floating.xml
浏览文件 @
408aacbb
...
...
@@ -46,6 +46,16 @@
android:layout_weight=
"0.4"
android:gravity=
"right"
android:paddingRight=
"10.0dip"
android:textColor=
"#FFFFFF"
/>
<TextView
android:id=
"@+id/batt"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginBottom=
"3dp"
android:layout_weight=
"0.4"
android:gravity=
"right"
android:paddingRight=
"10.0dip"
android:textColor=
"#FFFFFF"
/>
<TextView
android:id=
"@+id/traffic"
...
...
src/com/netease/qa/emmagee/service/EmmageeService.java
浏览文件 @
408aacbb
...
...
@@ -86,6 +86,7 @@ public class EmmageeService extends Service {
private
TextView
txtTotalMem
;
private
TextView
txtUnusedMem
;
private
TextView
txtTraffic
;
private
TextView
txtBatt
;
private
ImageView
imgViIcon
;
private
Button
btnWifi
;
private
int
delaytime
;
...
...
@@ -146,7 +147,7 @@ public class EmmageeService extends Service {
int
level
=
intent
.
getIntExtra
(
BatteryManager
.
EXTRA_LEVEL
,
0
);
int
scale
=
intent
.
getIntExtra
(
BatteryManager
.
EXTRA_SCALE
,
-
1
);
current
Batt
=
String
.
valueOf
(
level
*
100
/
scale
)
+
"%"
;
total
Batt
=
String
.
valueOf
(
level
*
100
/
scale
)
+
"%"
;
voltage
=
String
.
valueOf
(
intent
.
getIntExtra
(
BatteryManager
.
EXTRA_VOLTAGE
,
-
1
)
*
1.0
/
1000
);
...
...
@@ -188,6 +189,8 @@ public class EmmageeService extends Service {
.
findViewById
(
R
.
id
.
memunused
);
txtTotalMem
=
(
TextView
)
viFloatingWindow
.
findViewById
(
R
.
id
.
memtotal
);
txtBatt
=
(
TextView
)
viFloatingWindow
.
findViewById
(
R
.
id
.
batt
);
txtTraffic
=
(
TextView
)
viFloatingWindow
.
findViewById
(
R
.
id
.
traffic
);
btnWifi
=
(
Button
)
viFloatingWindow
.
findViewById
(
R
.
id
.
wifi
);
...
...
@@ -277,7 +280,7 @@ public class EmmageeService extends Service {
+
uid
+
"\r\n"
);
bw
.
write
(
"时间"
+
","
+
"应用占用内存PSS(MB)"
+
","
+
"应用占用内存比(%)"
+
","
+
" 机器剩余内存(MB)"
+
","
+
"应用占用CPU率(%)"
+
","
+
"CPU总使用率(%)"
+
","
+
"流量(KB)
:
"
+
"\r\n"
);
+
","
+
"流量(KB)
"
+
","
+
"电量(%)"
+
","
+
"电流(mA)"
+
","
+
"温度(C)"
+
","
+
"电压(V)
"
+
"\r\n"
);
}
catch
(
IOException
e
)
{
Log
.
e
(
LOG_TAG
,
e
.
getMessage
());
}
...
...
@@ -400,7 +403,8 @@ public class EmmageeService extends Service {
long
freeMemory
=
memoryInfo
.
getFreeMemorySize
(
getBaseContext
());
String
freeMemoryKb
=
fomart
.
format
((
double
)
freeMemory
/
1024
);
String
processMemory
=
fomart
.
format
((
double
)
pidMemory
/
1024
);
ArrayList
<
String
>
processInfo
=
cpuInfo
.
getCpuRatioInfo
();
String
currentBatt
=
String
.
valueOf
(
currentInfo
.
getValue
());
ArrayList
<
String
>
processInfo
=
cpuInfo
.
getCpuRatioInfo
(
totalBatt
,
currentBatt
,
temperature
,
voltage
);
if
(
isFloating
)
{
String
processCpuRatio
=
"0"
;
String
totalCpuRatio
=
"0"
;
...
...
@@ -430,6 +434,7 @@ public class EmmageeService extends Service {
+
freeMemoryKb
+
"MB"
);
txtTotalMem
.
setText
(
"占用CPU:"
+
processCpuRatio
+
"%"
+
",总体CPU:"
+
totalCpuRatio
+
"%"
);
txtBatt
.
setText
(
"电量:"
+
totalBatt
+
",电流:"
+
currentBatt
+
"mA"
);
if
(
"-1"
.
equals
(
trafficSize
))
{
txtTraffic
.
setText
(
"本程序或本设备不支持流量统计"
);
}
else
if
(
isMb
)
...
...
src/com/netease/qa/emmagee/utils/CpuInfo.java
浏览文件 @
408aacbb
...
...
@@ -139,7 +139,8 @@ public class CpuInfo {
* @return network traffic ,used ratio of process CPU and total CPU in
* certain interval
*/
public
ArrayList
<
String
>
getCpuRatioInfo
()
{
public
ArrayList
<
String
>
getCpuRatioInfo
(
String
totalBatt
,
String
currentBatt
,
String
temperature
,
String
voltage
)
{
DecimalFormat
fomart
=
new
DecimalFormat
();
fomart
.
setMaximumFractionDigits
(
2
);
...
...
@@ -155,6 +156,10 @@ public class CpuInfo {
||
(
Build
.
MODEL
.
equals
(
"google_sdk"
)))
{
mDateTime2
=
formatterFile
.
format
(
cal
.
getTime
().
getTime
()
+
8
*
60
*
60
*
1000
);
totalBatt
=
"N/A"
;
currentBatt
=
"N/A"
;
temperature
=
"N/A"
;
voltage
=
"N/A"
;
}
else
mDateTime2
=
formatterFile
.
format
(
cal
.
getTime
().
getTime
());
...
...
@@ -167,10 +172,10 @@ public class CpuInfo {
traffic
=
-
1
;
else
traffic
=
(
lastestTraffic
-
initialTraffic
+
1023
)
/
1024
;
processCpuRatio
=
fomart
.
format
(
100
*
((
double
)
(
processCpu
-
processCpu2
)
/
((
double
)
(
totalCpu
-
totalCpu2
))));
totalCpuRatio
=
fomart
.
format
(
100
*
((
double
)
((
totalCpu
-
idleCpu
)
-
(
totalCpu2
-
idleCpu2
))
/
(
double
)
(
totalCpu
-
totalCpu2
)));
processCpuRatio
=
fomart
.
format
(
100
*
((
double
)
(
processCpu
-
processCpu2
)
/
((
double
)
(
totalCpu
-
totalCpu2
))));
totalCpuRatio
=
fomart
.
format
(
100
*
((
double
)
((
totalCpu
-
idleCpu
)
-
(
totalCpu2
-
idleCpu2
))
/
(
double
)
(
totalCpu
-
totalCpu2
)));
long
pidMemory
=
mi
.
getPidMemorySize
(
pid
,
context
);
String
pMemory
=
fomart
.
format
((
double
)
pidMemory
/
1024
);
long
freeMemory
=
mi
.
getFreeMemorySize
(
context
);
...
...
@@ -186,11 +191,14 @@ public class CpuInfo {
EmmageeService
.
bw
.
write
(
mDateTime2
+
","
+
pMemory
+
","
+
percent
+
","
+
fMemory
+
","
+
processCpuRatio
+
","
+
totalCpuRatio
+
","
+
"本程序或本设备不支持流量统计"
+
"\r\n"
);
+
","
+
totalBatt
+
","
+
currentBatt
+
","
+
temperature
+
","
+
voltage
+
"\r\n"
);
}
else
{
EmmageeService
.
bw
.
write
(
mDateTime2
+
","
+
pMemory
+
","
+
percent
+
","
+
fMemory
+
","
+
processCpuRatio
+
","
+
totalCpuRatio
+
","
+
traffic
+
"\r\n"
);
+
","
+
totalCpuRatio
+
","
+
traffic
+
","
+
totalBatt
+
","
+
currentBatt
+
","
+
temperature
+
","
+
voltage
+
"\r\n"
);
}
}
totalCpu2
=
totalCpu
;
...
...
src/com/netease/qa/emmagee/utils/CurrentInfo.java
浏览文件 @
408aacbb
package
com.netease.qa.emmagee.utils
;
import
java.io.BufferedReader
;
import
java.io.DataInputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileReader
;
import
android.os.Build
;
import
android.util.Log
;
public
class
CurrentInfo
{
private
static
final
String
LOG_TAG
=
"Emmagee-CurrentInfo"
;
public
Long
getValue
()
{
File
f
=
null
;
// htc desire hd / desire z?
if
(
Build
.
MODEL
.
toLowerCase
().
contains
(
"desire hd"
)
||
Build
.
MODEL
.
toLowerCase
().
contains
(
"desire z"
))
{
f
=
new
File
(
"/sys/class/power_supply/battery/batt_current"
);
if
(
f
.
exists
())
return
getCurrentValue
(
f
,
false
);
}
// sony ericsson xperia x1
f
=
new
File
(
"/sys/devices/platform/i2c-adapter/i2c-0/0-0036/power_supply/ds2746-battery/current_now"
);
if
(
f
.
exists
())
return
getCurrentValue
(
f
,
false
);
// xdandroid
/* if (Build.MODEL.equalsIgnoreCase("MSM")) { */
f
=
new
File
(
"/sys/devices/platform/i2c-adapter/i2c-0/0-0036/power_supply/battery/current_now"
);
if
(
f
.
exists
())
return
getCurrentValue
(
f
,
false
);
/* } */
// droid eris
f
=
new
File
(
"/sys/class/power_supply/battery/smem_text"
);
if
(
f
.
exists
())
return
getSMemValue
();
// some htc devices
f
=
new
File
(
"/sys/class/power_supply/battery/batt_current"
);
if
(
f
.
exists
())
return
getCurrentValue
(
f
,
false
);
// nexus one
f
=
new
File
(
"/sys/class/power_supply/battery/current_now"
);
if
(
f
.
exists
())
return
getCurrentValue
(
f
,
true
);
// samsung galaxy vibrant
f
=
new
File
(
"/sys/class/power_supply/battery/batt_chg_current"
);
if
(
f
.
exists
())
return
getCurrentValue
(
f
,
false
);
// sony ericsson x10
f
=
new
File
(
"/sys/class/power_supply/battery/charger_current"
);
if
(
f
.
exists
())
return
getCurrentValue
(
f
,
false
);
return
null
;
}
public
static
Long
getSMemValue
()
{
boolean
success
=
false
;
String
text
=
null
;
try
{
FileReader
fr
=
new
FileReader
(
"/sys/class/power_supply/battery/smem_text"
);
BufferedReader
br
=
new
BufferedReader
(
fr
);
String
line
=
br
.
readLine
();
while
(
line
!=
null
)
{
if
(
line
.
contains
(
"I_MBAT"
))
{
text
=
line
.
substring
(
line
.
indexOf
(
"I_MBAT: "
)
+
8
);
success
=
true
;
break
;
}
line
=
br
.
readLine
();
}
br
.
close
();
fr
.
close
();
}
catch
(
Exception
ex
)
{
Log
.
e
(
LOG_TAG
,
ex
.
getMessage
());
ex
.
printStackTrace
();
}
Long
value
=
null
;
if
(
success
)
{
try
{
value
=
Long
.
parseLong
(
text
);
}
catch
(
NumberFormatException
nfe
)
{
Log
.
e
(
LOG_TAG
,
nfe
.
getMessage
());
value
=
null
;
}
}
return
value
;
}
public
static
Long
getBattAttrValue
(
File
f
,
String
dischargeField
,
String
chargeField
)
{
String
text
=
null
;
Long
value
=
null
;
try
{
// @@@ debug
// StringReader fr = new
// StringReader("vref: 1248\r\nbatt_id: 3\r\nbatt_vol: 4068\r\nbatt_current: 0\r\nbatt_discharge_current: 123\r\nbatt_temperature: 329\r\nbatt_temp_protection:normal\r\nPd_M:0\r\nI_MBAT:-313\r\npercent_last(RP): 94\r\npercent_update: 71\r\nlevel: 71\r\nfirst_level: 100\r\nfull_level:100\r\ncapacity:1580\r\ncharging_source: USB\r\ncharging_enabled: Slow\r\n");
FileReader
fr
=
new
FileReader
(
f
);
BufferedReader
br
=
new
BufferedReader
(
fr
);
String
line
=
br
.
readLine
();
final
String
chargeFieldHead
=
chargeField
+
": "
;
final
String
dischargeFieldHead
=
dischargeField
+
": "
;
while
(
line
!=
null
)
{
if
(
line
.
contains
(
chargeField
))
{
text
=
line
.
substring
(
line
.
indexOf
(
chargeFieldHead
)
+
chargeFieldHead
.
length
());
try
{
value
=
Long
.
parseLong
(
text
);
if
(
value
!=
0
)
break
;
}
catch
(
NumberFormatException
nfe
)
{
Log
.
e
(
LOG_TAG
,
nfe
.
getMessage
(),
nfe
);
}
}
// "batt_discharge_current:"
if
(
line
.
contains
(
dischargeField
))
{
text
=
line
.
substring
(
line
.
indexOf
(
dischargeFieldHead
)
+
dischargeFieldHead
.
length
());
try
{
value
=
(-
1
)
*
Math
.
abs
(
Long
.
parseLong
(
text
));
}
catch
(
NumberFormatException
nfe
)
{
Log
.
e
(
LOG_TAG
,
nfe
.
getMessage
(),
nfe
);
}
break
;
}
line
=
br
.
readLine
();
}
br
.
close
();
fr
.
close
();
}
catch
(
Exception
ex
)
{
Log
.
e
(
LOG_TAG
,
ex
.
getMessage
(),
ex
);
}
return
value
;
}
public
Long
getCurrentValue
(
File
file
,
boolean
convertToMillis
)
{
String
text
=
null
;
try
{
FileInputStream
fs
=
new
FileInputStream
(
file
);
DataInputStream
ds
=
new
DataInputStream
(
fs
);
text
=
ds
.
readLine
();
ds
.
close
();
fs
.
close
();
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
}
Long
value
=
null
;
if
(
text
!=
null
)
{
try
{
value
=
Long
.
parseLong
(
text
);
}
catch
(
NumberFormatException
nfe
)
{
value
=
null
;
}
if
(
convertToMillis
)
value
=
value
/
1000
;
// convert to milliampere
}
return
value
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录