Skip to content

Commit 0fec3e5

Browse files
authored
Merge pull request #13 from Manabu-GT/develop
Develop
2 parents 7825c9e + 0aca734 commit 0fec3e5

31 files changed

+509
-51
lines changed

CHANGELOG.md

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

3+
## Version 1.1.0 *(2017-09-01)*
4+
5+
* Android O support (Note: CpuUsageModule/CpuFreqModule will not work on Android O and above)
6+
* Add a CpuFreqModule to show current/max frequencies of all the cpu cores
7+
* Support Library 25.3.1 -> 26.0.1
8+
39
## Version 1.0.1 *(2017-04-05)*
410

511
* Use split v4 support library as dependencies for less size

README.md

+20-11
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,25 @@ so you just need to add the followings to your ***build.gradle*** file:
2323

2424
```groovy
2525
dependencies {
26-
debugCompile 'com.ms-square:debugoverlay:1.0.1'
27-
releaseCompile 'com.ms-square:debugoverlay-no-op:1.0.1'
28-
testCompile 'com.ms-square:debugoverlay-no-op:1.0.1'
26+
debugCompile 'com.ms-square:debugoverlay:1.1.0'
27+
releaseCompile 'com.ms-square:debugoverlay-no-op:1.1.0'
28+
testCompile 'com.ms-square:debugoverlay-no-op:1.1.0'
2929
}
3030
```
3131

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

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

3838
| library | methods | fields |
3939
|:------------- |:-------------|:-------------|
40-
|com.ms-square:debugoverlay:1.0.1|515|227|
41-
|com.ms-square:debugoverlay-no-op:1.0.1|127|36|
40+
|com.ms-square:debugoverlay:1.1.0|565|249|
41+
|com.ms-square:debugoverlay-no-op:1.1.0|142|37|
4242

4343
Due to the extensibility of this library, no-op version unfortunately has more than a few methods.
44-
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.0.1'` in the dependencies section of build.gradle.
44+
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.
4545

4646
Usage
4747
------
@@ -62,7 +62,7 @@ public class ExampleApplication extends Application {
6262
```
6363
It will show a debug overlay on system layer with the follwing three default modules just like the gif animation image displayed on this README.
6464

65-
- [CpuUsageModule](#cpuusagemodule)
65+
- [CpuUsageModule](#cpuusagemodule) - will not be shown on Android O and above
6666
- [MemInfoModule](#meminfomodule)
6767
- [FpsModule](#fpsmodule)
6868

@@ -125,6 +125,8 @@ Provided Modules
125125
`default`
126126
> Collects total and app cpu usage % by reading `/proc/stat` and `/proc/[myPid]/stat` respectively.
127127
128+
Note: CpuUsageModule will be no-op on Android O and above. Please see this [issue](https://github.com/Manabu-GT/DebugOverlay-Android/issues/11) for why.
129+
128130
#### MemInfoModule
129131

130132
`default`
@@ -142,6 +144,12 @@ If low memory situation is detected by reading [lowMemory](https://developer.and
142144
`optional`
143145
> Collects logcat messages generated by your own app even on non-rooted devices.
144146
147+
#### CpuFreqModule
148+
`optional`
149+
> Collects each cpu core's current and max frequency by reading `/sys/devices/system/cpu/cpu[num]/cpufreq/scaling_cur_freq` and `/sys/devices/system/cpu/cpu[num]/cpufreq/cpuinfo_max_freq` respectively.
150+
151+
Note: CpuFreqModule will be no-op on Android O and above. Please see this [issue](https://github.com/Manabu-GT/DebugOverlay-Android/issues/11) for why.
152+
145153
Customization
146154
------
147155

@@ -198,7 +206,7 @@ Example:
198206
module = new CpuUsageModule(new MyCpuViewModule());
199207
```
200208

201-
For **CpuUsage, MemInfo, and Fps modules**, you can pass your own layout resource id as long as it contains TextView as a direct child with id set to `debugoverlay_overlay_text` which is already defined in this library. This allows you to style the TextView used within those modules very easily without fully implementing new [ViewModule][5] by yourself.
209+
For **CpuUsage, CpuFreq, MemInfo, and Fps modules**, you can pass your own layout resource id as long as it contains TextView as a direct child with id set to `debugoverlay_overlay_text` which is already defined in this library. This allows you to style the TextView used within those modules very easily without fully implementing new [ViewModule][5] by yourself.
202210

203211
### Adding your own overlay module
204212

@@ -254,7 +262,8 @@ Since a new custom module called `IPAddressModule` is created, let's actually sh
254262
```java
255263
// inside Application's onCreate()
256264
new DebugOverlay.Builder(this)
257-
.modules(new CpuUsageModule(),
265+
.modules(new CpuFreqModule(),
266+
new CpuUsageModule(),
258267
new MemInfoModule(this),
259268
new FpsModule(),
260269
new IPAddressModule(this))
@@ -264,7 +273,7 @@ new DebugOverlay.Builder(this)
264273

265274
Now, the overlay successfully shows the newly added custom module at the bottom.
266275

267-
<img src="art/overlay_with_custom_module_small.png" width="50%" alt="DebugOverlay Screen Capture">
276+
<img src="art/overlay_with_custom_module_and_cpufreq_small.png" width="50%" alt="DebugOverlay Screen Capture">
268277

269278
Thanks for reading!
270279

Loading

build.gradle

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@ buildscript {
55
jcenter()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:2.3.0'
8+
classpath 'com.android.tools.build:gradle:2.3.3'
99

1010
// NOTE: Do not place your application dependencies here; they belong
1111
// in the individual module build.gradle files
12-
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.6.3'
12+
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.7.3'
1313
}
1414
}
1515

1616
allprojects {
1717
repositories {
1818
jcenter()
19+
maven {
20+
url "https://maven.google.com"
21+
}
1922
}
2023
}
2124

debugoverlay-no-op/build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ apply plugin: 'com.android.library'
33
apply plugin: 'com.getkeepsafe.dexcount'
44

55
android {
6-
compileSdkVersion 25
7-
buildToolsVersion "25.0.2"
6+
compileSdkVersion 26
7+
buildToolsVersion "26.0.1"
88

99
defaultConfig {
1010
minSdkVersion 16
11-
targetSdkVersion 25
11+
targetSdkVersion 26
1212
}
1313

1414
// force usage of prefix to avoid naming conflicts,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.ms_square.debugoverlay.modules;
2+
3+
public class CpuFreq {
4+
5+
public CpuFreq(String cpuName, double minFreq, double curFreq, double maxFreq) {
6+
}
7+
8+
public String getCpuName() {
9+
return null;
10+
}
11+
12+
public double getMinFreq() {
13+
return 0f;
14+
}
15+
16+
public double getCurFreq() {
17+
return 0f;
18+
}
19+
20+
public double getMaxFreq() {
21+
return 0f;
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.ms_square.debugoverlay.modules;
2+
3+
import com.ms_square.debugoverlay.OverlayModule;
4+
import com.ms_square.debugoverlay.ViewModule;
5+
6+
import java.util.List;
7+
8+
public class CpuFreqModule extends OverlayModule<List<CpuFreq>> {
9+
10+
public static final int DEFAULT_INTERVAL = 2000; // 2000ms
11+
12+
public CpuFreqModule() {
13+
super(null, null);
14+
}
15+
16+
public CpuFreqModule(int interval) {
17+
super(null, null);
18+
}
19+
20+
public CpuFreqModule(int interval, int layoutResId) {
21+
super(null, null);
22+
}
23+
24+
public CpuFreqModule(ViewModule<List<CpuFreq>> viewModule) {
25+
super(null, null);
26+
}
27+
28+
public CpuFreqModule(int interval, ViewModule<List<CpuFreq>> viewModule) {
29+
super(null, null);
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.ms_square.debugoverlay.modules;
2+
3+
import android.view.View;
4+
import android.view.ViewGroup;
5+
6+
import java.util.List;
7+
8+
public class CpuFreqViewModule extends BaseViewModule<List<CpuFreq>> {
9+
10+
public CpuFreqViewModule() {
11+
super(0);
12+
}
13+
14+
public CpuFreqViewModule(int layoutResId) {
15+
super(layoutResId);
16+
}
17+
18+
@Override
19+
public void onDataAvailable(List<CpuFreq> cpuFreqList) {
20+
}
21+
22+
@Override
23+
public View createView(ViewGroup root, int textColor, float textSize, float textAlpha) {
24+
return null;
25+
}
26+
}

debugoverlay-no-op/src/test/java/com/ms_square/debugoverlay/DebugOverlayNoOpTest.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.app.Application;
44
import android.graphics.Color;
55

6+
import com.ms_square.debugoverlay.modules.CpuFreqModule;
67
import com.ms_square.debugoverlay.modules.CpuUsageModule;
78
import com.ms_square.debugoverlay.modules.FpsModule;
89
import com.ms_square.debugoverlay.modules.LogcatLine;
@@ -38,7 +39,7 @@ public class DebugOverlayNoOpTest {
3839
OverlayModule mockOverlayModule;
3940

4041
@Test
41-
public void cpuModuleConstructors() {
42+
public void cpuUsageModuleConstructors() {
4243
new CpuUsageModule();
4344
new CpuUsageModule(0);
4445
new CpuUsageModule(0, 0);
@@ -48,6 +49,17 @@ public void cpuModuleConstructors() {
4849
Mockito.verifyZeroInteractions(mockViewModule);
4950
}
5051

52+
@Test
53+
public void cpuFreqModuleConstructors() {
54+
new CpuFreqModule();
55+
new CpuFreqModule(0);
56+
new CpuFreqModule(0, 0);
57+
new CpuFreqModule(mockViewModule);
58+
new CpuFreqModule(0, mockViewModule);
59+
60+
Mockito.verifyZeroInteractions(mockViewModule);
61+
}
62+
5163
@Test
5264
public void fpsModuleConstructors() {
5365
new FpsModule();

debugoverlay/build.gradle

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ apply plugin: 'com.android.library'
33
apply plugin: 'com.getkeepsafe.dexcount'
44

55
android {
6-
compileSdkVersion 25
7-
buildToolsVersion "25.0.2"
6+
compileSdkVersion 26
7+
buildToolsVersion "26.0.1"
88

99
defaultConfig {
1010
minSdkVersion 16
11-
targetSdkVersion 25
11+
targetSdkVersion 26
1212
}
1313

1414
// force usage of prefix to avoid naming conflicts
@@ -29,9 +29,9 @@ android {
2929

3030
dependencies {
3131
compile fileTree(dir: 'libs', include: ['*.jar'])
32-
compile 'com.android.support:support-compat:25.3.1'
33-
compile 'com.android.support:support-core-utils:25.3.1'
34-
compile 'com.android.support:support-annotations:25.3.1'
32+
compile 'com.android.support:support-compat:26.0.1'
33+
compile 'com.android.support:support-core-utils:26.0.1'
34+
compile 'com.android.support:support-annotations:26.0.1'
3535
}
3636

3737
// for maven central deployment

debugoverlay/src/main/java/com/ms_square/debugoverlay/DebugOverlay.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import android.content.IntentFilter;
1010
import android.content.ServiceConnection;
1111
import android.graphics.Color;
12+
import android.os.Build;
1213
import android.os.Bundle;
1314
import android.os.IBinder;
1415
import android.os.Parcel;
@@ -21,18 +22,20 @@
2122
import android.support.v4.content.LocalBroadcastManager;
2223
import android.util.Log;
2324

25+
import com.ms_square.debugoverlay.modules.CpuFreqModule;
2426
import com.ms_square.debugoverlay.modules.CpuUsageModule;
2527
import com.ms_square.debugoverlay.modules.FpsModule;
2628
import com.ms_square.debugoverlay.modules.MemInfoModule;
2729

2830
import java.util.ArrayList;
31+
import java.util.Iterator;
2932
import java.util.List;
3033
import java.util.Map;
3134
import java.util.WeakHashMap;
3235

3336
public class DebugOverlay {
3437

35-
private static final String TAG = DebugOverlay.class.getSimpleName();
38+
private static final String TAG = "DebugOverlay";
3639

3740
public static final Position DEFAULT_POSITION = Position.BOTTOM_START;
3841
public static final int DEFAULT_BG_COLOR = Color.parseColor("#40000000");
@@ -302,6 +305,18 @@ public DebugOverlay build() {
302305
overlayModules.add(new MemInfoModule(application));
303306
overlayModules.add(new FpsModule());
304307
}
308+
309+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
310+
// Removes any CpuUsageModule/CpuFreqModule if a device is running Android O and above
311+
Iterator<OverlayModule> iterator = overlayModules.iterator();
312+
while (iterator.hasNext()) {
313+
OverlayModule overlayModule = iterator.next();
314+
if (overlayModule instanceof CpuUsageModule || overlayModule instanceof CpuFreqModule) {
315+
iterator.remove();
316+
}
317+
}
318+
}
319+
305320
return new DebugOverlay(application, overlayModules,
306321
new Config(position, bgColor, textColor, textSize, textAlpha, allowSystemLayer,
307322
showNotification, activityName));

debugoverlay/src/main/java/com/ms_square/debugoverlay/DebugOverlayService.java

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.ms_square.debugoverlay;
22

3+
import android.app.NotificationChannel;
34
import android.app.NotificationManager;
45
import android.app.PendingIntent;
56
import android.app.Service;
@@ -13,6 +14,7 @@
1314
import android.graphics.drawable.BitmapDrawable;
1415
import android.graphics.drawable.Drawable;
1516
import android.os.Binder;
17+
import android.os.Build;
1618
import android.os.IBinder;
1719
import android.support.annotation.NonNull;
1820
import android.support.annotation.Nullable;
@@ -25,9 +27,10 @@
2527

2628
public class DebugOverlayService extends Service {
2729

28-
private static final String TAG = DebugOverlayService.class.getSimpleName();
30+
private static final String TAG = "DebugOverlayService";
2931

30-
private static final int NOTIFICATION_ID = 10000;
32+
private static final String NOTIFICATION_CHANNEL_ID = "com.ms_square.debugoverlay";
33+
private static final int NOTIFICATION_ID = Integer.MAX_VALUE - 100;
3134

3235
private static final String ACTION_SHOW_SUFFIX = ".debugoverlay_ACTION_SHOW";
3336
private static final String ACTION_HIDE_SUFFIX = ".debugoverlay_ACTION_HIDE";
@@ -65,6 +68,8 @@ public void onCreate() {
6568
}
6669
notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
6770

71+
createNotificationChannel();
72+
6873
String packageName = getPackageName();
6974
actionShow = packageName + ACTION_SHOW_SUFFIX;
7075
actionHide = packageName + ACTION_HIDE_SUFFIX;
@@ -156,8 +161,18 @@ public void updateNotification() {
156161
showNotification();
157162
}
158163

164+
private void createNotificationChannel() {
165+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
166+
if (notificationManager.getNotificationChannel(NOTIFICATION_CHANNEL_ID) == null) {
167+
NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID,
168+
getString(R.string.debugoverlay_notification_channel_name), NotificationManager.IMPORTANCE_LOW);
169+
notificationManager.createNotificationChannel(channel);
170+
}
171+
}
172+
}
173+
159174
private void showNotification() {
160-
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
175+
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
161176
.setStyle(new NotificationCompat.BigTextStyle().bigText(getString(R.string.debugoverlay_notification_big_text)))
162177
.setSmallIcon(R.drawable.debugoverlay_ic_notification)
163178
.setLargeIcon(getAppIcon(this))

0 commit comments

Comments
 (0)