Skip to content

Commit a34c1e0

Browse files
committed
fixies
1 parent b0b6b8a commit a34c1e0

File tree

73 files changed

+1171
-521
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1171
-521
lines changed

README.md

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# strictmode-notifier
2+
An Android library that shows a notification of StrictMode violation.
3+
4+
<img src="assets/notification.png" width="25%" hspace="10" vspace="10"/>
5+
<img src="assets/detail.png" width="25%" hspace="10" vspace="10"/>
6+
<img src="assets/list.png" width="25%" hspace="10" vspace="10"/>
7+
8+
## About StrictMode
9+
- [StrictMode for Runtime Analysis on Android](https://medium.com/google-developers/strictmode-for-runtime-analysis-on-android-f8d0a2c5667e#.elffd4gi1)
10+
- [StrictMode for enforcing best practices at runtime](https://www.youtube.com/watch?v=BxTfwT7mkB4)
11+
12+
## Getting started
13+
14+
In your `build.gradle`:
15+
16+
```gradle
17+
dependencies {
18+
debugCompile 'com.nshmura:strictmode-notifer:0.1.0'
19+
releaseCompile 'com.nshmura:strictmode-notifer-no-op:0.1.0'
20+
}
21+
```
22+
23+
In your `Application` class:
24+
25+
```java
26+
public class ExampleApplication extends Application {
27+
28+
@Override public void onCreate() {
29+
super.onCreate();
30+
31+
//setup this library
32+
StrictModeNotifier.install(this);
33+
34+
//setup StrictMode. penaltyLog() should be call.
35+
new Handler().post(new Runnable() {
36+
@Override public void run() {
37+
StrictMode.ThreadPolicy threadPolicy = new StrictMode.ThreadPolicy.Builder()
38+
.detectAll()
39+
.permitDiskReads()
40+
.permitDiskWrites()
41+
.penaltyLog() // Must!
42+
.build();
43+
StrictMode.setThreadPolicy(threadPolicy);
44+
45+
StrictMode.VmPolicy vmPolicy = new StrictMode.VmPolicy.Builder()
46+
.detectAll()
47+
.penaltyLog() // Must!
48+
.build();
49+
StrictMode.setVmPolicy(vmPolicy);
50+
}
51+
});
52+
}
53+
}
54+
```
55+
56+
## How does it work?
57+
1. StrictModeNotifier starts `logcat -v time -s StrictMode:*` command, and infinitely reads the output.
58+
2. If StrictMode violation is happend, logcat outputs logs.
59+
3. StrictModeNotifier reads that log, and shows a notification of the violation.
60+
61+
## Thanks
62+
Inspired by [square/leakcanary](https://github.com/square/leakcanary)
63+
64+
## License
65+
```
66+
Copyright (C) 2016 nshmura
67+
68+
Licensed under the Apache License, Version 2.0 (the "License");
69+
you may not use this file except in compliance with the License.
70+
You may obtain a copy of the License at
71+
72+
http://www.apache.org/licenses/LICENSE-2.0
73+
74+
Unless required by applicable law or agreed to in writing, software
75+
distributed under the License is distributed on an "AS IS" BASIS,
76+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
77+
See the License for the specific language governing permissions and
78+
limitations under the License.
79+
```

assets/detail.png

197 KB
Loading

assets/list.png

48.3 KB
Loading

assets/notification.png

109 KB
Loading

build.gradle

+25
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ buildscript {
66
}
77
dependencies {
88
classpath 'com.android.tools.build:gradle:2.1.0-alpha3'
9+
classpath 'com.novoda:bintray-release:0.3.4'
910

1011
// NOTE: Do not place your application dependencies here; they belong
1112
// in the individual module build.gradle files
@@ -21,3 +22,27 @@ allprojects {
2122
task clean(type: Delete) {
2223
delete rootProject.buildDir
2324
}
25+
26+
ext {
27+
minSdkVersion = 9
28+
compileSdkVersion = 23
29+
targetSdkVersion = compileSdkVersion
30+
buildToolsVersion = '23.0.2'
31+
javaVersion = JavaVersion.VERSION_1_7
32+
supportLibraryVersion = '23.2.1'
33+
versionCode = 1
34+
versionName = "0.1.1"
35+
36+
POM_DEVELOPER_ID = "nshmura"
37+
POM_GROUP = "com.nshmura"
38+
POM_VERSION_NAME = versionName
39+
POM_URL = "https://github.com/nshmura/strictmode-notifier"
40+
41+
POM_ARTIFACT_ID = "strictmode-notifier"
42+
POM_ARTIFACT_NAME = "strictmode-notifier"
43+
POM_DESCRIPTION = "An Android library that report notification of StrictMode violation."
44+
45+
POM_ARTIFACT_ID_NO_OP = "strictmode-notifier-no-op"
46+
POM_ARTIFACT_NAME_NO_OP = "strictmode-notifier-no-op"
47+
POM_DESCRIPTION_NO_OP = "No op strictmode-notifier"
48+
}

demo/build.gradle

+22-17
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 23
5-
buildToolsVersion "23.0.2"
4+
compileSdkVersion rootProject.ext.compileSdkVersion
5+
buildToolsVersion rootProject.ext.buildToolsVersion
66

7-
defaultConfig {
8-
applicationId "com.nshmura.strictmodenotifier.demo"
9-
minSdkVersion 9
10-
targetSdkVersion 23
11-
versionCode 1
12-
versionName "1.0"
13-
}
14-
buildTypes {
15-
release {
16-
minifyEnabled false
17-
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18-
}
7+
defaultConfig {
8+
applicationId "com.nshmura.strictmodenotifier.demo"
9+
minSdkVersion 11
10+
targetSdkVersion rootProject.ext.targetSdkVersion
11+
versionCode rootProject.ext.versionCode
12+
versionName rootProject.ext.versionName
13+
}
14+
buildTypes {
15+
release {
16+
minifyEnabled false
17+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
1918
}
19+
}
2020
}
2121

2222
dependencies {
23-
testCompile 'junit:junit:4.12'
24-
compile 'com.android.support:appcompat-v7:23.2.1'
25-
compile project(":library")
23+
compile fileTree(dir: 'libs', include: ['*.jar'])
24+
testCompile 'junit:junit:4.12'
25+
compile "com.android.support:appcompat-v7:$rootProject.ext.supportLibraryVersion"
26+
27+
//debugCompile project(":library")
28+
//releaseCompile project(":library-no-op")
29+
debugCompile "com.nshmura:strictmode-notifier:$rootProject.ext.versionName"
30+
releaseCompile "com.nshmura:strictmode-notifier-no-op:$rootProject.ext.versionName"
2631
}

demo/src/androidTest/java/com/nshmura/strictmodenotifier/demo/ApplicationTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
88
*/
99
public class ApplicationTest extends ApplicationTestCase<Application> {
10-
1110
public ApplicationTest() {
1211
super(Application.class);
1312
}

demo/src/main/AndroidManifest.xml

+2-18
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,20 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.nshmura.strictmodenotifier.demo">
44

5-
<uses-permission android:name="android.permission.READ_LOGS"/>
6-
<uses-permission android:name="android.permission.INTERNET"/>
7-
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
8-
95
<application
106
android:allowBackup="true"
117
android:icon="@mipmap/ic_launcher"
128
android:label="@string/app_name"
139
android:supportsRtl="true"
1410
android:theme="@style/AppTheme"
1511
android:name=".MainApplication">
16-
1712
<activity android:name=".MainActivity">
1813
<intent-filter>
1914
<action android:name="android.intent.action.MAIN"/>
15+
2016
<category android:name="android.intent.category.LAUNCHER"/>
21-
<category android:name="android.intent.category.DEFAULT"/>
2217
</intent-filter>
2318
</activity>
24-
25-
<activity android:name=".ClassInstanceLimitActivity"/>
26-
<activity android:name=".LeakedClosableObjectsActivity"/>
27-
28-
<receiver
29-
android:name=".LeakedBroadcastReceiver">
30-
<intent-filter>
31-
<action android:name="LeakAction"/>
32-
</intent-filter>
33-
</receiver>
34-
3519
</application>
3620

37-
</manifest>
21+
</manifest>

0 commit comments

Comments
 (0)