--- a/frameworks/base/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java+++ b/frameworks/base/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java@@ -16,24 +16,51 @@package com.android.systemui;+import android.app.ActivityManager;+import android.app.ActivityManager.RunningAppProcessInfo;import android.app.Application;import android.app.Instrumentation;import android.content.BroadcastReceiver;import android.content.Context;+import android.content.ComponentName;import android.content.Intent;import android.content.IntentFilter;import android.content.res.Configuration;+import android.database.ContentObserver;+import android.net.Uri;+import android.os.Build;+import android.os.Handler;import android.os.Process;import android.os.PowerManager;import android.os.SystemClock;import android.os.SystemProperties;import android.os.UserHandle;import android.util.Log;-+import java.util.List;+import java.util.Calendar;import com.android.systemui.stackdivider.Divider;import java.util.HashMap;import java.util.Map;+import java.util.Objects;+import java.io.BufferedReader;+import java.io.File;+import java.io.FileReader;+import java.io.FileWriter;+import java.io.IOException;+import java.text.SimpleDateFormat;+import java.util.Date;+import java.util.Locale;++import java.io.FileInputStream;+import java.io.FileNotFoundException;+import java.io.FileOutputStream;+import java.io.InputStream;+import java.io.PrintWriter;+import java.math.BigInteger;+import java.security.MessageDigest;+import java.security.NoSuchAlgorithmException;+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 appProcesses = activityManager.getRunningAppProcesses();+        +        for (RunningAppProcessInfo appProcess : appProcesses) {+            String[] pkgList = appProcess.pkgList;+            for (String pckName : pkgList) {+               if(packageName.equals(pckName)){+                       return true;+               }+                       +            }+        }*/+               ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);+               List recentTasks = am.getRecentTasks(30, ActivityManager.RECENT_IGNORE_UNAVAILABLE+                        | ActivityManager.RECENT_INCLUDE_PROFILES);+               +               for (ActivityManager.RecentTaskInfo recentInfo : recentTasks){+            //if (recentInfo.origActivity != null) {+                               String pckName = recentInfo.baseIntent.getComponent().getPackageName();+                               LDLog("isAppAlive.packageName=" + pckName);+                               if(packageName.equals(pckName)){+                                       return true;+                               }+                       //}+               }+        return false;+       }+}

更多相关文章

  1. android manifest.xml
  2. 【Android(安卓)系统开发】 Android(安卓)系统启动流程简介
  3. android 根据string 获取资源文件的id
  4. Android获取设备ID、型号及其它信息
  5. Android(安卓)音视频汇总
  6. 【Android(安卓)系统开发】 Android(安卓)系统启动流程简介
  7. Android(安卓)JSON,Gson,fastjson实现比较
  8. Android(安卓)查看本机外网IP
  9. Android(安卓)Property System | Android属性系统

随机推荐

  1. [Android]Android的常用adb命令
  2. Android(安卓)WebView加载H5音视频自动播
  3. Android中imageView图片放大缩小及旋转功
  4. Android(安卓)复习资料
  5. Android(安卓)Graphics - 3 BufferQueue
  6. Android(安卓)Google Map实例 - MD5 、Go
  7. 【android】Intent 和 Intent Filter
  8. 个人文章汇总
  9. Android(安卓)Studio:resource android:at
  10. Android(安卓)启动过程