Skip to content

Commit

Permalink
Merge pull request #13 from Manabu-GT/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Manabu-GT authored Sep 2, 2017
2 parents 7825c9e + 0aca734 commit 0fec3e5
Show file tree
Hide file tree
Showing 31 changed files with 509 additions and 51 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## Version 1.1.0 *(2017-09-01)*

* Android O support (Note: CpuUsageModule/CpuFreqModule will not work on Android O and above)
* Add a CpuFreqModule to show current/max frequencies of all the cpu cores
* Support Library 25.3.1 -> 26.0.1

## Version 1.0.1 *(2017-04-05)*

* Use split v4 support library as dependencies for less size
Expand Down
31 changes: 20 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@ so you just need to add the followings to your ***build.gradle*** file:

```groovy
dependencies {
debugCompile 'com.ms-square:debugoverlay:1.0.1'
releaseCompile 'com.ms-square:debugoverlay-no-op:1.0.1'
testCompile 'com.ms-square:debugoverlay-no-op:1.0.1'
debugCompile 'com.ms-square:debugoverlay:1.1.0'
releaseCompile 'com.ms-square:debugoverlay-no-op:1.1.0'
testCompile 'com.ms-square:debugoverlay-no-op:1.1.0'
}
```

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

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

| library | methods | fields |
|:------------- |:-------------|:-------------|
|com.ms-square:debugoverlay:1.0.1|515|227|
|com.ms-square:debugoverlay-no-op:1.0.1|127|36|
|com.ms-square:debugoverlay:1.1.0|565|249|
|com.ms-square:debugoverlay-no-op:1.1.0|142|37|

Due to the extensibility of this library, no-op version unfortunately has more than a few methods.
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.
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.

Usage
------
Expand All @@ -62,7 +62,7 @@ public class ExampleApplication extends Application {
```
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.

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

Expand Down Expand Up @@ -125,6 +125,8 @@ Provided Modules
`default`
> Collects total and app cpu usage % by reading `/proc/stat` and `/proc/[myPid]/stat` respectively.
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.

#### MemInfoModule

`default`
Expand All @@ -142,6 +144,12 @@ If low memory situation is detected by reading [lowMemory](https://developer.and
`optional`
> Collects logcat messages generated by your own app even on non-rooted devices.
#### CpuFreqModule
`optional`
> 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.
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.

Customization
------

Expand Down Expand Up @@ -198,7 +206,7 @@ Example:
module = new CpuUsageModule(new MyCpuViewModule());
```

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.
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.

### Adding your own overlay module

Expand Down Expand Up @@ -254,7 +262,8 @@ Since a new custom module called `IPAddressModule` is created, let's actually sh
```java
// inside Application's onCreate()
new DebugOverlay.Builder(this)
.modules(new CpuUsageModule(),
.modules(new CpuFreqModule(),
new CpuUsageModule(),
new MemInfoModule(this),
new FpsModule(),
new IPAddressModule(this))
Expand All @@ -264,7 +273,7 @@ new DebugOverlay.Builder(this)

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

<img src="art/overlay_with_custom_module_small.png" width="50%" alt="DebugOverlay Screen Capture">
<img src="art/overlay_with_custom_module_and_cpufreq_small.png" width="50%" alt="DebugOverlay Screen Capture">

Thanks for reading!

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.android.tools.build:gradle:2.3.3'

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

allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions debugoverlay-no-op/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ apply plugin: 'com.android.library'
apply plugin: 'com.getkeepsafe.dexcount'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
compileSdkVersion 26
buildToolsVersion "26.0.1"

defaultConfig {
minSdkVersion 16
targetSdkVersion 25
targetSdkVersion 26
}

// force usage of prefix to avoid naming conflicts,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.ms_square.debugoverlay.modules;

public class CpuFreq {

public CpuFreq(String cpuName, double minFreq, double curFreq, double maxFreq) {
}

public String getCpuName() {
return null;
}

public double getMinFreq() {
return 0f;
}

public double getCurFreq() {
return 0f;
}

public double getMaxFreq() {
return 0f;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.ms_square.debugoverlay.modules;

import com.ms_square.debugoverlay.OverlayModule;
import com.ms_square.debugoverlay.ViewModule;

import java.util.List;

public class CpuFreqModule extends OverlayModule<List<CpuFreq>> {

public static final int DEFAULT_INTERVAL = 2000; // 2000ms

public CpuFreqModule() {
super(null, null);
}

public CpuFreqModule(int interval) {
super(null, null);
}

public CpuFreqModule(int interval, int layoutResId) {
super(null, null);
}

public CpuFreqModule(ViewModule<List<CpuFreq>> viewModule) {
super(null, null);
}

public CpuFreqModule(int interval, ViewModule<List<CpuFreq>> viewModule) {
super(null, null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.ms_square.debugoverlay.modules;

import android.view.View;
import android.view.ViewGroup;

import java.util.List;

public class CpuFreqViewModule extends BaseViewModule<List<CpuFreq>> {

public CpuFreqViewModule() {
super(0);
}

public CpuFreqViewModule(int layoutResId) {
super(layoutResId);
}

@Override
public void onDataAvailable(List<CpuFreq> cpuFreqList) {
}

@Override
public View createView(ViewGroup root, int textColor, float textSize, float textAlpha) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.app.Application;
import android.graphics.Color;

import com.ms_square.debugoverlay.modules.CpuFreqModule;
import com.ms_square.debugoverlay.modules.CpuUsageModule;
import com.ms_square.debugoverlay.modules.FpsModule;
import com.ms_square.debugoverlay.modules.LogcatLine;
Expand Down Expand Up @@ -38,7 +39,7 @@ public class DebugOverlayNoOpTest {
OverlayModule mockOverlayModule;

@Test
public void cpuModuleConstructors() {
public void cpuUsageModuleConstructors() {
new CpuUsageModule();
new CpuUsageModule(0);
new CpuUsageModule(0, 0);
Expand All @@ -48,6 +49,17 @@ public void cpuModuleConstructors() {
Mockito.verifyZeroInteractions(mockViewModule);
}

@Test
public void cpuFreqModuleConstructors() {
new CpuFreqModule();
new CpuFreqModule(0);
new CpuFreqModule(0, 0);
new CpuFreqModule(mockViewModule);
new CpuFreqModule(0, mockViewModule);

Mockito.verifyZeroInteractions(mockViewModule);
}

@Test
public void fpsModuleConstructors() {
new FpsModule();
Expand Down
12 changes: 6 additions & 6 deletions debugoverlay/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ apply plugin: 'com.android.library'
apply plugin: 'com.getkeepsafe.dexcount'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
compileSdkVersion 26
buildToolsVersion "26.0.1"

defaultConfig {
minSdkVersion 16
targetSdkVersion 25
targetSdkVersion 26
}

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

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-compat:25.3.1'
compile 'com.android.support:support-core-utils:25.3.1'
compile 'com.android.support:support-annotations:25.3.1'
compile 'com.android.support:support-compat:26.0.1'
compile 'com.android.support:support-core-utils:26.0.1'
compile 'com.android.support:support-annotations:26.0.1'
}

// for maven central deployment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.os.Parcel;
Expand All @@ -21,18 +22,20 @@
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;

import com.ms_square.debugoverlay.modules.CpuFreqModule;
import com.ms_square.debugoverlay.modules.CpuUsageModule;
import com.ms_square.debugoverlay.modules.FpsModule;
import com.ms_square.debugoverlay.modules.MemInfoModule;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;

public class DebugOverlay {

private static final String TAG = DebugOverlay.class.getSimpleName();
private static final String TAG = "DebugOverlay";

public static final Position DEFAULT_POSITION = Position.BOTTOM_START;
public static final int DEFAULT_BG_COLOR = Color.parseColor("#40000000");
Expand Down Expand Up @@ -302,6 +305,18 @@ public DebugOverlay build() {
overlayModules.add(new MemInfoModule(application));
overlayModules.add(new FpsModule());
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// Removes any CpuUsageModule/CpuFreqModule if a device is running Android O and above
Iterator<OverlayModule> iterator = overlayModules.iterator();
while (iterator.hasNext()) {
OverlayModule overlayModule = iterator.next();
if (overlayModule instanceof CpuUsageModule || overlayModule instanceof CpuFreqModule) {
iterator.remove();
}
}
}

return new DebugOverlay(application, overlayModules,
new Config(position, bgColor, textColor, textSize, textAlpha, allowSystemLayer,
showNotification, activityName));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.ms_square.debugoverlay;

import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
Expand All @@ -13,6 +14,7 @@
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Binder;
import android.os.Build;
import android.os.IBinder;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
Expand All @@ -25,9 +27,10 @@

public class DebugOverlayService extends Service {

private static final String TAG = DebugOverlayService.class.getSimpleName();
private static final String TAG = "DebugOverlayService";

private static final int NOTIFICATION_ID = 10000;
private static final String NOTIFICATION_CHANNEL_ID = "com.ms_square.debugoverlay";
private static final int NOTIFICATION_ID = Integer.MAX_VALUE - 100;

private static final String ACTION_SHOW_SUFFIX = ".debugoverlay_ACTION_SHOW";
private static final String ACTION_HIDE_SUFFIX = ".debugoverlay_ACTION_HIDE";
Expand Down Expand Up @@ -65,6 +68,8 @@ public void onCreate() {
}
notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

createNotificationChannel();

String packageName = getPackageName();
actionShow = packageName + ACTION_SHOW_SUFFIX;
actionHide = packageName + ACTION_HIDE_SUFFIX;
Expand Down Expand Up @@ -156,8 +161,18 @@ public void updateNotification() {
showNotification();
}

private void createNotificationChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (notificationManager.getNotificationChannel(NOTIFICATION_CHANNEL_ID) == null) {
NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID,
getString(R.string.debugoverlay_notification_channel_name), NotificationManager.IMPORTANCE_LOW);
notificationManager.createNotificationChannel(channel);
}
}
}

private void showNotification() {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
.setStyle(new NotificationCompat.BigTextStyle().bigText(getString(R.string.debugoverlay_notification_big_text)))
.setSmallIcon(R.drawable.debugoverlay_ic_notification)
.setLargeIcon(getAppIcon(this))
Expand Down
Loading

0 comments on commit 0fec3e5

Please sign in to comment.