Kaynağa Gözat

[监控][添加]:增加监控服务进程

tags/jenkins-front-end-screenad-240-v138
hupeng 5 yıl önce
ebeveyn
işleme
998d25ac6f
15 değiştirilmiş dosya ile 181 ekleme ve 75 silme
  1. +9
    -0
      .gitignore
  2. +0
    -17
      android/.project
  3. +0
    -2
      android/.settings/org.eclipse.buildship.core.prefs
  4. +0
    -6
      android/app/.classpath
  5. +0
    -23
      android/app/.project
  6. +0
    -2
      android/app/.settings/org.eclipse.buildship.core.prefs
  7. BIN
      android/app/libs/cron4j-2.2.5.jar
  8. +5
    -1
      android/app/src/main/AndroidManifest.xml
  9. +0
    -8
      android/app/src/main/gen/com/screenad/BuildConfig.java
  10. +0
    -7
      android/app/src/main/gen/com/screenad/Manifest.java
  11. +0
    -7
      android/app/src/main/gen/com/screenad/R.java
  12. +153
    -0
      android/app/src/main/java/com/screenad/DaemonService.java
  13. +14
    -2
      android/app/src/main/java/com/screenad/MainApplication.java
  14. BIN
      image/ad1.jpg
  15. BIN
      image/ad2.jpg

+ 9
- 0
.gitignore Dosyayı Görüntüle

@@ -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/*



+ 0
- 17
android/.project Dosyayı Görüntüle

@@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>screenAd</name>
<comment>Project android created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>

+ 0
- 2
android/.settings/org.eclipse.buildship.core.prefs Dosyayı Görüntüle

@@ -1,2 +0,0 @@
connection.project.dir=
eclipse.preferences.version=1

+ 0
- 6
android/app/.classpath Dosyayı Görüntüle

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin/default"/>
</classpath>

+ 0
- 23
android/app/.project Dosyayı Görüntüle

@@ -1,23 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>app</name>
<comment>Project app created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>

+ 0
- 2
android/app/.settings/org.eclipse.buildship.core.prefs Dosyayı Görüntüle

@@ -1,2 +0,0 @@
connection.project.dir=..
eclipse.preferences.version=1

BIN
android/app/libs/cron4j-2.2.5.jar Dosyayı Görüntüle


+ 5
- 1
android/app/src/main/AndroidManifest.xml Dosyayı Görüntüle

@@ -5,7 +5,7 @@
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<application
android:name=".MainApplication"
android:label="@string/app_name"
@@ -27,6 +27,10 @@
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
<service
android:name=".DaemonService"
android:exported="true"
android:launchMode="singleInstance" />
<receiver android:name=".AutoStartBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />


+ 0
- 8
android/app/src/main/gen/com/screenad/BuildConfig.java Dosyayı Görüntüle

@@ -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);
}

+ 0
- 7
android/app/src/main/gen/com/screenad/Manifest.java Dosyayı Görüntüle

@@ -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 {
}

+ 0
- 7
android/app/src/main/gen/com/screenad/R.java Dosyayı Görüntüle

@@ -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 {
}

+ 153
- 0
android/app/src/main/java/com/screenad/DaemonService.java Dosyayı Görüntüle

@@ -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<ActivityManager.RunningAppProcessInfo> 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<ActivityManager.RunningAppProcessInfo> 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();
}
}

+ 14
- 2
android/app/src/main/java/com/screenad/MainApplication.java Dosyayı Görüntüle

@@ -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");
}
}

BIN
image/ad1.jpg Dosyayı Görüntüle

Önce Sonra
Genişlik: 1080  |  Yükseklik: 1920  |  Boyut: 224 KiB

BIN
image/ad2.jpg Dosyayı Görüntüle

Önce Sonra
Genişlik: 1080  |  Yükseklik: 1920  |  Boyut: 243 KiB

Yükleniyor…
İptal
Kaydet