use of android.app.ActivityManager.RunningAppProcessInfo in project platform_frameworks_base by android.
the class FingerprintService method isForegroundActivity.
private boolean isForegroundActivity(int uid, int pid) {
try {
List<RunningAppProcessInfo> procs = ActivityManagerNative.getDefault().getRunningAppProcesses();
int N = procs.size();
for (int i = 0; i < N; i++) {
RunningAppProcessInfo proc = procs.get(i);
if (proc.pid == pid && proc.uid == uid && proc.importance == IMPORTANCE_FOREGROUND) {
return true;
}
}
} catch (RemoteException e) {
Slog.w(TAG, "am.getRunningAppProcesses() failed");
}
return false;
}
use of android.app.ActivityManager.RunningAppProcessInfo in project devbricks by dailystudio.
the class AndroidActivity method getTopActivityAboveL.
public static ComponentName getTopActivityAboveL(Context context) {
if (context == null) {
return null;
}
ActivityManager actmgr = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
if (actmgr == null) {
return null;
}
List<RunningTaskInfo> tasks = actmgr.getRunningTasks(1);
if (tasks == null || tasks.size() <= 0) {
return null;
}
List<RunningAppProcessInfo> processes = actmgr.getRunningAppProcesses();
if (processes == null) {
return null;
}
RunningAppProcessInfo p0 = processes.get(0);
if (p0 == null) {
return null;
}
String pkg = p0.processName;
String[] pkglist = p0.pkgList;
if (pkglist != null && pkglist.length > 0) {
pkg = pkglist[0];
}
Logger.debug("top app-pkg: %s", pkg);
if (TextUtils.isEmpty(pkg)) {
return null;
}
AndroidApplication app = new AndroidApplication(pkg);
Intent i = app.getLaunchIntent(context);
if (i == null) {
return null;
}
final ComponentName comp = i.getComponent();
Logger.debug("top app-comp: %s", comp);
return comp;
}
use of android.app.ActivityManager.RunningAppProcessInfo in project AppCenter-SDK-Android by Microsoft.
the class ErrorLogHelperTest method getErrorReportFromErrorLog.
@Test
public void getErrorReportFromErrorLog() throws java.lang.Exception {
/* Mock base. */
Context mockContext = mock(Context.class);
when(Process.myPid()).thenReturn(123);
/* Mock device. */
Device mockDevice = mock(Device.class);
when(DeviceInfoHelper.getDeviceInfo(any(Context.class))).thenReturn(mockDevice);
/* Mock process name. */
ActivityManager activityManager = mock(ActivityManager.class);
RunningAppProcessInfo runningAppProcessInfo = new RunningAppProcessInfo(null, 0, null);
runningAppProcessInfo.pid = 123;
runningAppProcessInfo.processName = "right.process";
when(mockContext.getSystemService(Context.ACTIVITY_SERVICE)).thenReturn(activityManager);
when(activityManager.getRunningAppProcesses()).thenReturn(Arrays.asList(mock(RunningAppProcessInfo.class), runningAppProcessInfo));
/* Mock architecture. */
TestUtils.setInternalState(Build.VERSION.class, "SDK_INT", 23);
TestUtils.setInternalState(Build.class, "SUPPORTED_ABIS", new String[] { "armeabi-v7a", "arm" });
/* Create an error log. */
ManagedErrorLog errorLog = ErrorLogHelper.createErrorLog(mockContext, java.lang.Thread.currentThread(), new RuntimeException(new TestCrashException()), java.lang.Thread.getAllStackTraces(), 900);
assertNotNull(errorLog);
/* Test. */
Throwable throwable = new RuntimeException();
ErrorReport report = ErrorLogHelper.getErrorReportFromErrorLog(errorLog, throwable);
assertNotNull(report);
assertEquals(errorLog.getId().toString(), report.getId());
assertEquals(errorLog.getErrorThreadName(), report.getThreadName());
assertEquals(throwable, report.getThrowable());
assertEquals(errorLog.getAppLaunchTimestamp(), report.getAppStartTime());
assertEquals(errorLog.getTimestamp(), report.getAppErrorTime());
assertEquals(errorLog.getDevice(), report.getDevice());
}
use of android.app.ActivityManager.RunningAppProcessInfo in project MVPFrames by RockyQu.
the class AppUtils method gc.
/**
* 清理后台进程与服务
*
* @param context 应用上下文对象context
* @return 被清理的数量
*/
public static int gc(Context context) {
long i = getDeviceUsableMemory(context);
// 清理掉的进程数
int count = 0;
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
// 获取正在运行的service列表
List<RunningServiceInfo> serviceList = am.getRunningServices(100);
if (serviceList != null) {
for (RunningServiceInfo service : serviceList) {
if (service.pid == android.os.Process.myPid())
continue;
try {
android.os.Process.killProcess(service.pid);
count++;
} catch (Exception e) {
e.getStackTrace();
}
}
}
// 获取正在运行的进程列表
List<RunningAppProcessInfo> processList = am.getRunningAppProcesses();
if (processList != null) {
for (RunningAppProcessInfo process : processList) {
// 一般数值大于RunningAppProcessInfo.IMPORTANCE_VISIBLE的进程都是非可见进程,也就是在后台运行着
if (process.importance > RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
// pkgList 得到该进程下运行的包名
String[] pkgList = process.pkgList;
for (String pkgName : pkgList) {
try {
am.killBackgroundProcesses(pkgName);
count++;
} catch (Exception e) {
// 防止意外发生
e.getStackTrace();
}
}
}
}
}
return count;
}
use of android.app.ActivityManager.RunningAppProcessInfo in project AnExplorer by 1hakr.
the class AppsProvider method queryChildDocuments.
@Override
public Cursor queryChildDocuments(String docId, String[] projection, String sortOrder) throws FileNotFoundException {
final MatrixCursor result = new DocumentCursor(resolveDocumentProjection(projection), docId);
// Delegate to real provider
final long token = Binder.clearCallingIdentity();
try {
if (docId.startsWith(ROOT_ID_USER_APP)) {
List<PackageInfo> allAppList = packageManager.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES);
for (PackageInfo packageInfo : allAppList) {
includeAppFromPackage(result, docId, packageInfo, false, null);
}
} else if (docId.startsWith(ROOT_ID_SYSTEM_APP)) {
List<PackageInfo> allAppList = packageManager.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES);
for (PackageInfo packageInfo : allAppList) {
includeAppFromPackage(result, docId, packageInfo, true, null);
}
} else if (docId.startsWith(ROOT_ID_PROCESS)) {
if (Utils.hasNougat()) {
List<RunningServiceInfo> runningServices = activityManager.getRunningServices(1000);
for (RunningServiceInfo process : runningServices) {
includeAppFromService(result, docId, process, null);
}
} else if (Utils.hasLollipopMR1()) {
List<AndroidAppProcess> runningAppProcesses = AndroidProcesses.getRunningAppProcesses();
for (AndroidAppProcess process : runningAppProcesses) {
includeAppFromProcess(result, docId, process, null);
}
} else {
List<RunningAppProcessInfo> runningProcessesList = activityManager.getRunningAppProcesses();
for (RunningAppProcessInfo processInfo : runningProcessesList) {
includeAppFromProcess(result, docId, processInfo, null);
}
}
}
} finally {
Binder.restoreCallingIdentity(token);
}
return result;
}
Aggregations