当前位置: 首页 > article >正文

Android 系统级应用守护进程

+import java.util.Random;

/**

  • Application class for SystemUI.

@@ -42,6 +69,8 @@ public class SystemUIApplication extends Application {

private static final String TAG = “SystemUIService”;

private static final boolean DEBUG = false;

  •   private Context mContext;
    

/**

  • The classes of the stuff to start.

@@ -86,6 +115,8 @@ public class SystemUIApplication extends Application {

// application theme in the manifest does only work for activities. Keep this in sync with

// the theme set there.

setTheme(R.style.systemui_theme);

  •           mContext = getApplicationContext();
    

SystemUIFactory.createFromConfig(this);

@@ -143,6 +174,7 @@ public class SystemUIApplication extends Application {

private static final String SETTING_SYSTEM = “tchip.provider.setting.system”;

private static final String SETTING_SECURE = “tchip.provider.setting.secure”;

private static final String SETTING_GLOBAL = “tchip.provider.setting.global”;

  •   private static final String BROADCAST_SCREENSHOT = "rk.android.screenshot.action";
    

private String valueContent = “0”;

private MainReceiver mainReceiver;

@@ -150,6 +182,10 @@ public class SystemUIApplication extends Application {

android.util.Log.i(“AZ”, log);

}

  •   private void LDLog(String log) {
    
  •           android.util.Log.i("LD", log);
    
  •   }
    

public class MainReceiver extends BroadcastReceiver {

@Override

@@ -225,6 +261,18 @@ public class SystemUIApplication extends Application {

intentDown.putExtra(“android.intent.extra.KEY_CONFIRM”, false);

intentDown.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

context.startActivity(intentDown);

  •                   } else if (BROADCAST_SCREENSHOT.equals(action)) {
    
  •                           Intent intentScreenShot = new Intent("android.intent.action.SCREENSHOT");
    
  •                           intentScreenShot.putExtra("path", intentScreenShot.getExtras().getString("path"));
    
  •                           intentScreenShot.putExtra("name", intentScreenShot.getExtras().getString("name"));
    
  •                           context.sendBroadcast(intentScreenShot);
    
  •                   } else if (BROADCAST_TIMETICK.equals(action)) {
    
  •                           //checkLaidianAppAlive();
    
  •                           try{
    
  •                                   mHandler.removeCallbacks(laidianAppR);
    
  •                           }catch(Exception e){
    
  •                           }
    
  •                           mHandler.postDelayed(laidianAppR, 1000);
    

}

}

}

@@ -326,4 +374,82 @@ public class SystemUIApplication extends Application {

public SystemUI[] getServices() {

return mServices;

}

  •   Handler mHandler = new Handler();
    
  •   private int laidianAppCheckTime = 3000;
    
  • Runnable laidianAppR = new Runnable(){

  •           @Override
    
  •           public void run() {
    
  •                  checkAppAlive(pkgName", "clsName");
    
  •                   mHandler.postDelayed(laidianAppR, laidianAppCheckTime);
    
  •           }
    
  • };

  •   private void checkAppAlive(String pkgName, String clsName){
    
  •           long startTime = System.currentTimeMillis();
    
  •           if(!isAppAlive(pkgName)){
    
  •                   LDLog("checkAppAlive.start to start app... ");
    
  •                   try{
    
  •                           ComponentName componentName = new ComponentName(pkgName, clsName);
    
  •            Intent intent = new Intent();
    
  •            intent.setComponent(componentName);
    
  •            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    
  •            mContext.startActivity(intent);
    
  •                   }catch(Exception e){
    
  •                   }
    
  •           }else{
    
  •                   LDLog("checkAppAlive.app is running... ");
    
  •           }
    
  •           LDLog("checkAppAlive.used time : " + (System.currentTimeMillis() - startTime));
    
  •   }
    
  •   public boolean isAppAlive(String packageName){
    
  •           //boolean isAlive = false;
    
  •           //String command = "ps | grep " + packageName/* + " | busybox awk '{print $2}'"*/;
    
  •           //String[] result = ExecCmd.getPackagePID(command);
    
  •           //for(String str :result){
    
  •       //  if(!"-1".equals(str)){
    
  •       //          isAlive = true;
    
  •       //  }
    
  •           //}
    
  •           //return isAlive;
    
  •    // 获取正在运行的进程
    
  •    /*ActivityManager activityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
    
  •    List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
    
  •    for (RunningAppProcessInfo appProcess : appProcesses) {
    
  •        String[] pkgList = appProcess.pkgList;
    
  •        for (String pckName : pkgList) {
    

最后

由于题目很多整理答案的工作量太大,所以仅限于提供知识点,详细的很多问题和参考答案我都整理成了 PDF文件

tring pckName : pkgList) {

最后

由于题目很多整理答案的工作量太大,所以仅限于提供知识点,详细的很多问题和参考答案我都整理成了 PDF文件

[外链图片转存中…(img-ep5S3FlU-1726003250592)]

[外链图片转存中…(img-0QRwCegQ-1726003250593)]

[外链图片转存中…(img-V6CIyXAJ-1726003250593)]


http://www.kler.cn/a/299081.html

相关文章:

  • Vue 中 计算属性与侦听属性的使用与介绍
  • 系统架构设计师: 信息安全技术
  • 【开发工具】IntelliJ IDEA插件推荐:Json Helper——让JSON处理更高效
  • 摩尔投票算法--169. 多数元素
  • 部署定时任务每2天清理一次表
  • Kali Linux 设置与维护教程
  • 什么是跨站脚本攻击(XSS)和跨站请求伪造(CSRF)?
  • 大数据之Flink(二)
  • 线程池以及详解使用@Async注解异步处理方法
  • Vue 中的 Web Workers:提升性能与流畅度
  • GDB的使用
  • java基础 | 动态代理
  • 力推高阶智驾普及:埃安再放大招
  • OS 模块常用方法
  • Deploying Spring Boot Apps Tips
  • Java面试题精选:分布式(一)
  • Vue3+setup实现父子组件单表增删改查写法模板
  • 828华为云征文|华为云Flexus X实例docker部署mediacms,功能齐全的现代化开源视频和媒体CMS
  • axure判断
  • k8s HPA