diff --git a/.gitignore b/.gitignore
index 562c430..9e4b45e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -55,3 +55,12 @@ buck-out/
# Bundle artifact
*.jsbundle
/yarn.lock
+
+android/app/.classpath
+android/app/.project
+android/.project
+android/.settings/*
+android/app/.settings/*
+android/app/src/main/gen/*
+
+
diff --git a/android/.project b/android/.project
deleted file mode 100644
index f031723..0000000
--- a/android/.project
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
- screenAd
- Project android created by Buildship.
-
-
-
-
- org.eclipse.buildship.core.gradleprojectbuilder
-
-
-
-
-
- org.eclipse.buildship.core.gradleprojectnature
-
-
diff --git a/android/.settings/org.eclipse.buildship.core.prefs b/android/.settings/org.eclipse.buildship.core.prefs
deleted file mode 100644
index e889521..0000000
--- a/android/.settings/org.eclipse.buildship.core.prefs
+++ /dev/null
@@ -1,2 +0,0 @@
-connection.project.dir=
-eclipse.preferences.version=1
diff --git a/android/app/.classpath b/android/app/.classpath
deleted file mode 100644
index eb19361..0000000
--- a/android/app/.classpath
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
diff --git a/android/app/.project b/android/app/.project
deleted file mode 100644
index ac485d7..0000000
--- a/android/app/.project
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
- app
- Project app created by Buildship.
-
-
-
-
- org.eclipse.jdt.core.javabuilder
-
-
-
-
- org.eclipse.buildship.core.gradleprojectbuilder
-
-
-
-
-
- org.eclipse.jdt.core.javanature
- org.eclipse.buildship.core.gradleprojectnature
-
-
diff --git a/android/app/.settings/org.eclipse.buildship.core.prefs b/android/app/.settings/org.eclipse.buildship.core.prefs
deleted file mode 100644
index b1886ad..0000000
--- a/android/app/.settings/org.eclipse.buildship.core.prefs
+++ /dev/null
@@ -1,2 +0,0 @@
-connection.project.dir=..
-eclipse.preferences.version=1
diff --git a/android/app/libs/cron4j-2.2.5.jar b/android/app/libs/cron4j-2.2.5.jar
new file mode 100644
index 0000000..90fc173
Binary files /dev/null and b/android/app/libs/cron4j-2.2.5.jar differ
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index 73e42bf..965bec9 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -5,7 +5,7 @@
-
+
+
diff --git a/android/app/src/main/gen/com/screenad/BuildConfig.java b/android/app/src/main/gen/com/screenad/BuildConfig.java
deleted file mode 100644
index 9ad7088..0000000
--- a/android/app/src/main/gen/com/screenad/BuildConfig.java
+++ /dev/null
@@ -1,8 +0,0 @@
-/*___Generated_by_IDEA___*/
-
-package com.screenad;
-
-/* This stub is only used by the IDE. It is NOT the BuildConfig class actually packed into the APK */
-public final class BuildConfig {
- public final static boolean DEBUG = Boolean.parseBoolean(null);
-}
\ No newline at end of file
diff --git a/android/app/src/main/gen/com/screenad/Manifest.java b/android/app/src/main/gen/com/screenad/Manifest.java
deleted file mode 100644
index 0588432..0000000
--- a/android/app/src/main/gen/com/screenad/Manifest.java
+++ /dev/null
@@ -1,7 +0,0 @@
-/*___Generated_by_IDEA___*/
-
-package com.screenad;
-
-/* This stub is only used by the IDE. It is NOT the Manifest class actually packed into the APK */
-public final class Manifest {
-}
\ No newline at end of file
diff --git a/android/app/src/main/gen/com/screenad/R.java b/android/app/src/main/gen/com/screenad/R.java
deleted file mode 100644
index 162fc32..0000000
--- a/android/app/src/main/gen/com/screenad/R.java
+++ /dev/null
@@ -1,7 +0,0 @@
-/*___Generated_by_IDEA___*/
-
-package com.screenad;
-
-/* This stub is only used by the IDE. It is NOT the R class actually packed into the APK */
-public final class R {
-}
\ No newline at end of file
diff --git a/android/app/src/main/java/com/screenad/DaemonService.java b/android/app/src/main/java/com/screenad/DaemonService.java
new file mode 100644
index 0000000..a362611
--- /dev/null
+++ b/android/app/src/main/java/com/screenad/DaemonService.java
@@ -0,0 +1,153 @@
+package com.screenad;
+
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.NotificationChannel;
+import android.app.Service;
+import android.content.Intent;
+import android.os.Build;
+import android.os.IBinder;
+import android.app.ActivityManager;
+import android.content.Context;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+
+import android.util.Log;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.screenad.MainApplication;
+
+import it.sauronsoftware.cron4j.Scheduler;
+
+
+/**
+ * 守护进程,同时用来升级程序
+ */
+public class DaemonService extends Service {
+ // 核心进程 Service ID
+ private final static int CORE_SERVICE_ID = -5122;
+ private ExecutorService executorService = Executors.newSingleThreadExecutor();
+ Scheduler scheduler;
+
+ public DaemonService() {
+ }
+
+ private static void log(String text) {
+ Log.i("DaemonService",text);
+ }
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ log("created");
+ //利用 Android 漏洞提高进程优先级, 前台进程
+ String CHANNEL_ONE_ID = "CHANNEL_ONE_ID";
+ String CHANNEL_ONE_NAME= "CHANNEL_ONE_ID";
+ NotificationChannel notificationChannel= null;
+ //进行8.0的判断
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
+ notificationChannel= new NotificationChannel(CHANNEL_ONE_ID,
+ CHANNEL_ONE_NAME, NotificationManager.IMPORTANCE_HIGH);
+ notificationChannel.setShowBadge(true);
+ notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
+ NotificationManager manager= (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
+ manager.createNotificationChannel(notificationChannel);
+ }
+
+ Notification notification= new Notification.Builder(this).setChannelId(CHANNEL_ONE_ID)
+ .setContentTitle("DaemonService")
+ .build();
+ notification.flags|= Notification.FLAG_NO_CLEAR;
+
+ startForeground(CORE_SERVICE_ID, notification);
+ }
+
+ @Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ log("started");
+ executorService.submit(new Runnable() {
+ @Override
+ public void run() {
+ startCronTabTask();
+ }
+ });
+ return START_STICKY;
+ }
+
+ private boolean isProcessWork(Context context, String processName) {
+ ActivityManager myAM = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
+ List processInfos = myAM.getRunningAppProcesses();
+ if (processInfos == null) {
+ return false;
+ }
+ for (ActivityManager.RunningAppProcessInfo processInfo : processInfos) {
+ if (processInfo.processName.equals(processName)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private boolean isBackground(Context context, String packageName) {
+ ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
+ List appProcesses = activityManager.getRunningAppProcesses();
+ for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {
+ if (appProcess.processName.equals(packageName)) {
+ /* BACKGROUND=400 EMPTY=500 FOREGROUND=100 GONE=1000 PERCEPTIBLE=130 SERVICE=300 ISIBLE=200 */
+ log(ppProcess.processName + " appimportace =" + appProcess.importance);
+ if (appProcess.importance != ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
+ log("处于后台" + appProcess.processName);
+ return true;
+ } else {
+ log("处于前台" + appProcess.processName);
+ return false;
+ }
+ }
+ }
+ return false;
+ }
+
+
+ /**
+ * 开启cron4jtab定时任务
+ */
+ private void startCronTabTask() {
+ if (scheduler != null) {
+ scheduler.stop();
+ }
+ scheduler = new Scheduler();
+ scheduler.isDaemon();
+ scheduler.schedule("* * * * *", new Runnable() {
+ public void run() {
+ try {
+ if (!isProcessWork(MainApplication.getContext(), "com.screenad") ||
+ isBackground(MainApplication.getContext(), "com.screenad")) {
+ log("正在重启 com.screenad...");
+ Intent newIntent = MainApplication.getContext().getPackageManager().getLaunchIntentForPackage("com.screenad");
+ MainApplication.getContext().startActivity(newIntent);
+ }else{
+ log("运行良好 com.screenad...");
+ }
+ } catch (Exception e) {
+ log(e.getMessage());
+ }
+ }
+ });
+ scheduler.start();
+ }
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ }
+
+}
diff --git a/android/app/src/main/java/com/screenad/MainApplication.java b/android/app/src/main/java/com/screenad/MainApplication.java
index 22ae962..ff1876f 100644
--- a/android/app/src/main/java/com/screenad/MainApplication.java
+++ b/android/app/src/main/java/com/screenad/MainApplication.java
@@ -1,7 +1,9 @@
package com.screenad;
+import com.screenad.DaemonService;
import android.app.Application;
-
+import android.content.Context;
+import android.content.Intent;
import com.facebook.react.ReactApplication;
import com.horcrux.svg.SvgPackage;
import org.reactnative.camera.RNCameraPackage;
@@ -18,7 +20,7 @@ import com.facebook.soloader.SoLoader;
import java.util.Arrays;
import java.util.List;
-
+import android.util.Log;
public class MainApplication extends Application implements ReactApplication {
@@ -57,6 +59,13 @@ public class MainApplication extends Application implements ReactApplication {
}
};
+ private static void log(String text) {
+ Log.i("MainApplication",text);
+ }
+ private static Context context;
+ public static Context getContext() {
+ return context;
+ }
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
@@ -65,6 +74,9 @@ public class MainApplication extends Application implements ReactApplication {
@Override
public void onCreate() {
super.onCreate();
+ context = this;
SoLoader.init(this, /* native exopackage */ false);
+ context.startForegroundService(new Intent(getContext(), DaemonService.class));
+ log("started");
}
}
diff --git a/image/ad1.jpg b/image/ad1.jpg
deleted file mode 100644
index 95ce77a..0000000
Binary files a/image/ad1.jpg and /dev/null differ
diff --git a/image/ad2.jpg b/image/ad2.jpg
deleted file mode 100644
index fb35e40..0000000
Binary files a/image/ad2.jpg and /dev/null differ