Skip to content

Commit 94f524d

Browse files
authored
Merge pull request #15 from Manabu-GT/develop
Develop
2 parents 5fc44f8 + 3b7b2aa commit 94f524d

File tree

4 files changed

+38
-20
lines changed

4 files changed

+38
-20
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
## Version 1.1.1 *(2017-09-02)*
4+
5+
* Fix to close filereaders in CpuFreqDataModule after reading data
6+
37
## Version 1.1.0 *(2017-09-01)*
48

59
* Android O support (Note: CpuUsageModule/CpuFreqModule will not work on Android O and above)

README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,25 @@ so you just need to add the followings to your ***build.gradle*** file:
2424

2525
```groovy
2626
dependencies {
27-
debugCompile 'com.ms-square:debugoverlay:1.1.0'
28-
releaseCompile 'com.ms-square:debugoverlay-no-op:1.1.0'
29-
testCompile 'com.ms-square:debugoverlay-no-op:1.1.0'
27+
debugCompile 'com.ms-square:debugoverlay:1.1.1'
28+
releaseCompile 'com.ms-square:debugoverlay-no-op:1.1.1'
29+
testCompile 'com.ms-square:debugoverlay-no-op:1.1.1'
3030
}
3131
```
3232

33-
Please note that `com.ms-square:debugoverlay:1.1.0` will add `android.permission.SYSTEM_ALERT_WINDOW` to your app.
33+
Please note that `com.ms-square:debugoverlay:1.1.1` will add `android.permission.SYSTEM_ALERT_WINDOW` to your app.
3434
Threfore, you should avoid to use that dependency for your release build.
3535

3636
FYI, the following table describes the total number of method/field references in this library's release aar.
3737
This data is acquired by using [Dexcount Gradle Plugin](https://github.com/KeepSafe/dexcount-gradle-plugin).
3838

3939
| library | methods | fields |
4040
|:------------- |:-------------|:-------------|
41-
|com.ms-square:debugoverlay:1.1.0|565|249|
42-
|com.ms-square:debugoverlay-no-op:1.1.0|142|37|
41+
|com.ms-square:debugoverlay:1.1.1|565|249|
42+
|com.ms-square:debugoverlay-no-op:1.1.1|142|37|
4343

4444
Due to the extensibility of this library, no-op version unfortunately has more than a few methods.
45-
If you want to eliminate such method count in your release build, consider having separate `Application` class only for your debug build which uses this library and just specify `debugCompile 'com.ms-square:debugoverlay:1.1.0'` in the dependencies section of build.gradle.
45+
If you want to eliminate such method count in your release build, consider having separate `Application` class only for your debug build which uses this library and just specify `debugCompile 'com.ms-square:debugoverlay:1.1.1'` in the dependencies section of build.gradle.
4646

4747
Usage
4848
------

debugoverlay/src/main/java/com/ms_square/debugoverlay/modules/CpuFreqDataModule.java

+25-11
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ public void run() {
5656
for (File cpuFile : cpuFiles) {
5757
double minFreq = -1f;
5858
double maxFreq = -1f;
59+
BufferedReader minFreqReader = null;
60+
BufferedReader maxFreqReader = null;
5961
try {
60-
BufferedReader minFreqReader =
61-
new BufferedReader(new FileReader(cpuFile.getAbsolutePath() + "/cpufreq/cpuinfo_min_freq"));
62-
BufferedReader maxFreqReader =
63-
new BufferedReader(new FileReader(cpuFile.getAbsolutePath() + "/cpufreq/cpuinfo_max_freq"));
62+
minFreqReader = new BufferedReader(new FileReader(cpuFile.getAbsolutePath() + "/cpufreq/cpuinfo_min_freq"));
63+
maxFreqReader = new BufferedReader(new FileReader(cpuFile.getAbsolutePath() + "/cpufreq/cpuinfo_max_freq"));
6464
minFreq = parseDouble(minFreqReader.readLine());
6565
maxFreq = parseDouble(maxFreqReader.readLine());
6666

@@ -70,6 +70,17 @@ public void run() {
7070
}
7171
} catch (IOException ie) {
7272
Log.w(TAG, "Error reading the min/max cpufreq", ie);
73+
} finally {
74+
if (minFreqReader != null) {
75+
try {
76+
minFreqReader.close();
77+
} catch (IOException ignore) {}
78+
}
79+
if (maxFreqReader != null) {
80+
try {
81+
maxFreqReader.close();
82+
} catch (IOException ignore) {}
83+
}
7384
}
7485
cachedFrequencies.put(cpuFile, new CpuFreq(cpuFile.getName(), minFreq, -1f, maxFreq));
7586
}
@@ -81,8 +92,9 @@ public void run() {
8192
for (File cpuFile : cachedFrequencies.keySet()) {
8293
CpuFreq cached = cachedFrequencies.get(cpuFile);
8394
double curFreq = -1f;
95+
BufferedReader curFreqReader = null;
8496
try {
85-
BufferedReader curFreqReader = new BufferedReader(new FileReader(cpuFile.getAbsolutePath() + "/cpufreq/scaling_cur_freq"));
97+
curFreqReader = new BufferedReader(new FileReader(cpuFile.getAbsolutePath() + "/cpufreq/scaling_cur_freq"));
8698
curFreq = parseDouble(curFreqReader.readLine());
8799

88100
if (DebugOverlay.isDebugLoggingEnabled()) {
@@ -91,6 +103,12 @@ public void run() {
91103

92104
} catch (IOException ie) {
93105
Log.w(TAG, "Error reading the current cpufreq", ie);
106+
} finally {
107+
if (curFreqReader != null) {
108+
try {
109+
curFreqReader.close();
110+
} catch (IOException ignore) {}
111+
}
94112
}
95113

96114
newCpuFreqList.add(new CpuFreq(cached.getCpuName(), cached.getMinFreq(), curFreq, cached.getMaxFreq()));
@@ -144,15 +162,11 @@ protected List<CpuFreq> getLatestData() {
144162

145163
private static File[] getCpuFiles() {
146164
File dir = new File("/sys/devices/system/cpu/");
147-
File[] files = dir.listFiles(new FileFilter() {
165+
return dir.listFiles(new FileFilter() {
148166
@Override
149167
public boolean accept(File file) {
150-
if(Pattern.matches("cpu[0-9]+", file.getName())) {
151-
return true;
152-
}
153-
return false;
168+
return Pattern.matches("cpu[0-9]+", file.getName());
154169
}
155170
});
156-
return files;
157171
}
158172
}

gradle.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ android.enableBuildCache=true
2626

2727
# For maven central
2828
GROUP=com.ms-square
29-
VERSION_NAME=1.1.0
30-
VERSION_CODE=3
29+
VERSION_NAME=1.1.1
30+
VERSION_CODE=4
3131
POM_PACKAGING=aar
3232
POM_DESCRIPTION=Android library to display various debugging information in an overlay window
3333

0 commit comments

Comments
 (0)