Skip to content

Commit

Permalink
1.0.2 ver: 耗电量优化, 修正参数提示.
Browse files Browse the repository at this point in the history
  • Loading branch information
Da Xing committed Mar 17, 2017
1 parent 1a9b436 commit 5c1bf0e
Show file tree
Hide file tree
Showing 8 changed files with 707 additions and 23 deletions.
684 changes: 684 additions & 0 deletions .idea/gradle_extensions.xml

Large diffs are not rendered by default.

Binary file removed HelloDaemon-1.0.1.jar
Binary file not shown.
Binary file removed hellodaemon-1.0.1-javadoc.jar
Binary file not shown.
Binary file removed hellodaemon-1.0.1-sources.jar
Binary file not shown.
16 changes: 3 additions & 13 deletions hellodaemon/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ext {
siteUrl = 'https://github.com/xingda920813/HelloDaemon'
gitUrl = 'https://github.com/xingda920813/HelloDaemon.git'

libraryVersion = '1.0.1'
libraryVersion = '1.0.2'

developerId = 'xingda920813'
developerName = 'Da Xing'
Expand All @@ -31,8 +31,8 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 25
versionCode 2
versionName "1.0.1"
versionCode 3
versionName "1.0.2"
}
buildTypes {
release {
Expand All @@ -50,16 +50,6 @@ dependencies {
compile 'com.android.support:support-annotations:+'
}

task makeJar(type: Copy) {
delete 'build/libs/HelloDaemon-1.0.1.jar'
from('build/intermediates/bundles/default/')
into('build/libs/')
include('classes.jar')
rename ('classes.jar', 'HelloDaemon-1.0.1.jar')
}

makeJar.dependsOn(build)

// Place it at the end of the file
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
apply from: 'bintrayv1.gradle'
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public abstract class AbsWorkService extends Service {

protected static final int HASH_CODE = 1;

protected boolean mFirstStarted = true;

/**
* 用于在不需要服务运行的时候取消 Job / Alarm / Subscription.
*/
Expand Down Expand Up @@ -41,12 +43,15 @@ public static void cancelJobAlarmSub() {
* 5.守护 Service 组件的启用状态, 使其不被 MAT 等工具禁用.
*/
protected int onStart(Intent intent, int flags, int startId) {
//启动前台服务而不显示通知的漏洞已在 API Level 25 修复,大快人心!
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.N) {
//利用漏洞在 API Level 17 及以下的 Android 系统中,启动前台服务而不显示通知
startForeground(HASH_CODE, new Notification());
//利用漏洞在 API Level 18 及以上的 Android 系统中,启动前台服务而不显示通知
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) startService(new Intent(getApplication(), WorkNotificationService.class));
if(mFirstStarted) {
mFirstStarted = false;
//启动前台服务而不显示通知的漏洞已在 API Level 25 修复,大快人心!
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.N) {
//利用漏洞在 API Level 17 及以下的 Android 系统中,启动前台服务而不显示通知
startForeground(HASH_CODE, new Notification());
//利用漏洞在 API Level 18 及以上的 Android 系统中,启动前台服务而不显示通知
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) startService(new Intent(getApplication(), WorkNotificationService.class));
}
}

//启动守护服务,运行在:watch子进程中
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private DaemonEnv() {}
* @param app Application Context.
* @param wakeUpInterval 定时唤醒的时间间隔(ms).
*/
public static void initialize(Context app, Class<? extends AbsWorkService> serviceClass, @Nullable Integer wakeUpInterval) {
public static void initialize(@NonNull Context app, @NonNull Class<? extends AbsWorkService> serviceClass, @Nullable Integer wakeUpInterval) {
sApp = app;
sServiceClass = serviceClass;
if (wakeUpInterval != null) sWakeUpInterval = wakeUpInterval;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,21 @@ public class WatchDogService extends Service {
protected static Subscription sSubscription;
protected static PendingIntent sPendingIntent;

protected boolean mFirstStarted = true;

/**
* 守护服务,运行在:watch子进程中
*/
protected final int onStart(Intent intent, int flags, int startId) {

if (!DaemonEnv.sInitialized) return START_STICKY;

if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.N) {
startForeground(HASH_CODE, new Notification());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) startService(new Intent(DaemonEnv.sApp, WatchDogNotificationService.class));
if(mFirstStarted) {
mFirstStarted = false;
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.N) {
startForeground(HASH_CODE, new Notification());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) startService(new Intent(DaemonEnv.sApp, WatchDogNotificationService.class));
}
}

if (sSubscription != null && !sSubscription.isUnsubscribed()) return START_STICKY;
Expand Down

0 comments on commit 5c1bf0e

Please sign in to comment.