use of android.app.ActivityManager.ProcessErrorStateInfo in project android_frameworks_base by crdroidandroid.
the class ProcessErrorsTest method reportListContents.
/**
* This helper function will dump the actual error reports.
*
* @param errList The error report containing one or more error records.
* @return Returns a string containing all of the errors.
*/
private static String reportListContents(Collection<ProcessErrorStateInfo> errList) {
if (errList == null)
return null;
StringBuilder builder = new StringBuilder();
Iterator<ProcessErrorStateInfo> iter = errList.iterator();
while (iter.hasNext()) {
ProcessErrorStateInfo entry = iter.next();
String condition;
switch(entry.condition) {
case ActivityManager.ProcessErrorStateInfo.CRASHED:
condition = "a CRASH";
break;
case ActivityManager.ProcessErrorStateInfo.NOT_RESPONDING:
condition = "an ANR";
break;
default:
condition = "an unknown error";
break;
}
builder.append(String.format("Process %s encountered %s (%s)", entry.processName, condition, entry.shortMsg));
if (entry.condition == ActivityManager.ProcessErrorStateInfo.CRASHED) {
builder.append(String.format(" with stack trace:\n%s\n", entry.stackTrace));
}
builder.append("\n");
}
return builder.toString();
}
use of android.app.ActivityManager.ProcessErrorStateInfo in project android_frameworks_base by crdroidandroid.
the class AppCompatibility method launchActivity.
/**
* Launches and activity and queries for errors.
*
* @param packageName {@link String} the package name of the application to
* launch.
* @return {@link Collection} of {@link ProcessErrorStateInfo} detected
* during the app launch.
*/
private ProcessErrorStateInfo launchActivity(String packageName, Intent intent) {
Log.d(TAG, String.format("launching package \"%s\" with intent: %s", packageName, intent.toString()));
String processName = getProcessName(packageName);
// Launch Activity
mContext.startActivity(intent);
try {
Thread.sleep(mAppLaunchTimeout);
} catch (InterruptedException e) {
// ignore
}
// See if there are any errors. We wait until down here to give ANRs as much time as
// possible to occur.
final Collection<ProcessErrorStateInfo> postErr = mActivityManager.getProcessesInErrorState();
if (postErr == null) {
return null;
}
for (ProcessErrorStateInfo error : postErr) {
if (error.processName.equals(processName)) {
return error;
}
}
return null;
}
use of android.app.ActivityManager.ProcessErrorStateInfo in project android_frameworks_base by crdroidandroid.
the class AppCompatibility method testAppStability.
/**
* Actual test case that launches the package and throws an exception on the
* first error.
*
* @throws Exception
*/
public void testAppStability() throws Exception {
String packageName = mArgs.getString(PACKAGE_TO_LAUNCH);
if (packageName != null) {
Log.d(TAG, "Launching app " + packageName);
Intent intent = getLaunchIntentForPackage(packageName);
if (intent == null) {
Log.w(TAG, String.format("Skipping %s; no launch intent", packageName));
return;
}
ProcessErrorStateInfo err = launchActivity(packageName, intent);
// Make sure there are no errors when launching the application,
// otherwise raise an
// exception with the first error encountered.
assertNull(getStackTrace(err), err);
try {
assertTrue("App crashed after launch.", processStillUp(packageName));
} finally {
returnHome();
}
} else {
Log.d(TAG, "Missing argument, use " + PACKAGE_TO_LAUNCH + " to specify the package to launch");
}
}
use of android.app.ActivityManager.ProcessErrorStateInfo in project aware-client by denzilferreira.
the class Applications method onAccessibilityEvent.
/**
* Monitors for events of:
* {@link AccessibilityEvent#TYPE_WINDOW_STATE_CHANGED}
* {@link AccessibilityEvent#TYPE_NOTIFICATION_STATE_CHANGED}
*/
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
if (event.getPackageName() == null)
return;
if (Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_NOTIFICATIONS).equals("true") && event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {
Notification notificationDetails = (Notification) event.getParcelableData();
if (notificationDetails != null) {
ContentValues rowData = new ContentValues();
rowData.put(Applications_Notifications.DEVICE_ID, Aware.getSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID));
rowData.put(Applications_Notifications.TIMESTAMP, System.currentTimeMillis());
rowData.put(Applications_Notifications.PACKAGE_NAME, event.getPackageName().toString());
rowData.put(Applications_Notifications.APPLICATION_NAME, getApplicationName(event.getPackageName().toString()));
rowData.put(Applications_Notifications.TEXT, Encrypter.hash(getApplicationContext(), event.getText().toString()));
rowData.put(Applications_Notifications.SOUND, ((notificationDetails.sound != null) ? notificationDetails.sound.toString() : ""));
rowData.put(Applications_Notifications.VIBRATE, ((notificationDetails.vibrate != null) ? notificationDetails.vibrate.toString() : ""));
rowData.put(Applications_Notifications.DEFAULTS, notificationDetails.defaults);
rowData.put(Applications_Notifications.FLAGS, notificationDetails.flags);
if (DEBUG)
Log.d(TAG, "New notification:" + rowData.toString());
getContentResolver().insert(Applications_Notifications.CONTENT_URI, rowData);
if (awareSensor != null)
awareSensor.onNotification(rowData);
Intent notification = new Intent(ACTION_AWARE_APPLICATIONS_NOTIFICATIONS);
notification.putExtra(EXTRA_DATA, rowData);
sendBroadcast(notification);
}
}
if (Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_APPLICATIONS).equals("true") && event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
PackageManager packageManager = getPackageManager();
// Fixed: Window State Changed from the same application (showing keyboard within an app) should be ignored
boolean same_app = false;
Cursor last_foreground = getContentResolver().query(Applications_Foreground.CONTENT_URI, null, null, null, Applications_Foreground.TIMESTAMP + " DESC LIMIT 1");
if (last_foreground != null && last_foreground.moveToFirst()) {
if (last_foreground.getString(last_foreground.getColumnIndex(Applications_Foreground.PACKAGE_NAME)).equals(event.getPackageName())) {
same_app = true;
}
}
if (last_foreground != null && !last_foreground.isClosed())
last_foreground.close();
if (!same_app) {
ApplicationInfo appInfo;
try {
appInfo = packageManager.getApplicationInfo(event.getPackageName().toString(), PackageManager.GET_META_DATA);
} catch (NameNotFoundException | NullPointerException | Resources.NotFoundException e) {
appInfo = null;
}
PackageInfo pkgInfo;
try {
pkgInfo = packageManager.getPackageInfo(event.getPackageName().toString(), PackageManager.GET_META_DATA);
} catch (NameNotFoundException | NullPointerException | Resources.NotFoundException e) {
pkgInfo = null;
}
String appName = "";
try {
if (appInfo != null) {
appName = packageManager.getApplicationLabel(appInfo).toString();
}
} catch (Resources.NotFoundException | NullPointerException e) {
appName = "";
}
ContentValues rowData = new ContentValues();
rowData.put(Applications_Foreground.TIMESTAMP, System.currentTimeMillis());
rowData.put(Applications_Foreground.DEVICE_ID, Aware.getSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID));
rowData.put(Applications_Foreground.PACKAGE_NAME, event.getPackageName().toString());
rowData.put(Applications_Foreground.APPLICATION_NAME, appName);
rowData.put(Applications_Foreground.IS_SYSTEM_APP, pkgInfo != null && isSystemPackage(pkgInfo));
if (DEBUG)
Log.d(TAG, "FOREGROUND: " + rowData.toString());
try {
getContentResolver().insert(Applications_Foreground.CONTENT_URI, rowData);
if (awareSensor != null)
awareSensor.onForeground(rowData);
} catch (SQLException e) {
if (DEBUG)
Log.d(TAG, e.getMessage());
}
Intent newForeground = new Intent(ACTION_AWARE_APPLICATIONS_FOREGROUND);
newForeground.putExtra(EXTRA_DATA, rowData);
sendBroadcast(newForeground);
}
if (Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_CRASHES).equals("true")) {
// Check if there is a crashed application
ActivityManager activityMng = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
List<ProcessErrorStateInfo> errors = activityMng.getProcessesInErrorState();
if (errors != null) {
Iterator<ActivityManager.ProcessErrorStateInfo> iter = errors.iterator();
while (iter.hasNext()) {
ActivityManager.ProcessErrorStateInfo error = iter.next();
try {
PackageInfo pkgInfo = packageManager.getPackageInfo(error.processName, PackageManager.GET_META_DATA);
ApplicationInfo appInfo = packageManager.getApplicationInfo(event.getPackageName().toString(), PackageManager.GET_META_DATA);
String appName = (appInfo != null) ? (String) packageManager.getApplicationLabel(appInfo) : "";
ContentValues crashData = new ContentValues();
crashData.put(Applications_Crashes.TIMESTAMP, System.currentTimeMillis());
crashData.put(Applications_Crashes.DEVICE_ID, Aware.getSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID));
crashData.put(Applications_Crashes.PACKAGE_NAME, error.processName);
crashData.put(Applications_Crashes.APPLICATION_NAME, appName);
// some prepackages don't have version codes...
crashData.put(Applications_Crashes.APPLICATION_VERSION, (pkgInfo != null) ? pkgInfo.versionCode : -1);
crashData.put(Applications_Crashes.ERROR_SHORT, error.shortMsg);
String error_long = "";
error_long += error.longMsg + "\nStack:\n";
error_long += (error.stackTrace != null) ? error.stackTrace : "";
crashData.put(Applications_Crashes.ERROR_LONG, error_long);
crashData.put(Applications_Crashes.ERROR_CONDITION, error.condition);
crashData.put(Applications_Crashes.IS_SYSTEM_APP, pkgInfo != null && isSystemPackage(pkgInfo));
getContentResolver().insert(Applications_Crashes.CONTENT_URI, crashData);
if (awareSensor != null)
awareSensor.onCrash(crashData);
if (DEBUG)
Log.d(TAG, "Crashed: " + crashData.toString());
Intent crashed = new Intent(ACTION_AWARE_APPLICATIONS_CRASHES);
crashed.putExtra(EXTRA_DATA, crashData);
sendBroadcast(crashed);
} catch (NameNotFoundException e) {
e.printStackTrace();
}
}
}
}
}
if (Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_KEYBOARD).equals("true") && event.getEventType() == AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED) {
ContentValues keyboard = new ContentValues();
keyboard.put(Keyboard_Provider.Keyboard_Data.TIMESTAMP, System.currentTimeMillis());
keyboard.put(Keyboard_Provider.Keyboard_Data.DEVICE_ID, Aware.getSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID));
keyboard.put(Keyboard_Provider.Keyboard_Data.PACKAGE_NAME, (String) event.getPackageName());
keyboard.put(Keyboard_Provider.Keyboard_Data.BEFORE_TEXT, (String) event.getBeforeText());
keyboard.put(Keyboard_Provider.Keyboard_Data.CURRENT_TEXT, event.getText().toString());
keyboard.put(Keyboard_Provider.Keyboard_Data.IS_PASSWORD, event.isPassword());
if (awareSensor != null)
awareSensor.onKeyboard(keyboard);
getContentResolver().insert(Keyboard_Provider.Keyboard_Data.CONTENT_URI, keyboard);
if (DEBUG)
Log.d(TAG, "Keyboard: " + keyboard.toString());
Intent keyboard_data = new Intent(Keyboard.ACTION_AWARE_KEYBOARD);
sendBroadcast(keyboard_data);
}
if (Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_TOUCH).equals("true")) {
if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SCROLLED) {
if (event.getFromIndex() == 0)
last_scroll_index = 0;
if (last_scroll_index > 0) {
if (event.getFromIndex() < last_scroll_index) {
ContentValues touch = new ContentValues();
touch.put(Screen_Provider.Screen_Touch.TIMESTAMP, System.currentTimeMillis());
touch.put(Screen_Provider.Screen_Touch.DEVICE_ID, Aware.getSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID));
touch.put(Screen_Provider.Screen_Touch.TOUCH_APP, event.getPackageName().toString());
touch.put(Screen_Provider.Screen_Touch.TOUCH_ACTION, Screen.ACTION_AWARE_TOUCH_SCROLLED_UP);
touch.put(Screen_Provider.Screen_Touch.TOUCH_INDEX_ITEMS, event.getItemCount());
touch.put(Screen_Provider.Screen_Touch.TOUCH_FROM_INDEX, event.getFromIndex());
touch.put(Screen_Provider.Screen_Touch.TOUCH_TO_INDEX, event.getToIndex());
if (awareSensor != null)
awareSensor.onTouch(touch);
getContentResolver().insert(Screen_Provider.Screen_Touch.CONTENT_URI, touch);
if (DEBUG)
Log.d(TAG, "Touch: " + touch.toString());
Intent touch_data = new Intent(Screen.ACTION_AWARE_TOUCH_SCROLLED_UP);
sendBroadcast(touch_data);
} else if (event.getFromIndex() > last_scroll_index) {
ContentValues touch = new ContentValues();
touch.put(Screen_Provider.Screen_Touch.TIMESTAMP, System.currentTimeMillis());
touch.put(Screen_Provider.Screen_Touch.DEVICE_ID, Aware.getSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID));
touch.put(Screen_Provider.Screen_Touch.TOUCH_APP, event.getPackageName().toString());
touch.put(Screen_Provider.Screen_Touch.TOUCH_ACTION, Screen.ACTION_AWARE_TOUCH_SCROLLED_DOWN);
touch.put(Screen_Provider.Screen_Touch.TOUCH_INDEX_ITEMS, event.getItemCount());
touch.put(Screen_Provider.Screen_Touch.TOUCH_FROM_INDEX, event.getFromIndex());
touch.put(Screen_Provider.Screen_Touch.TOUCH_TO_INDEX, event.getToIndex());
if (awareSensor != null)
awareSensor.onTouch(touch);
getContentResolver().insert(Screen_Provider.Screen_Touch.CONTENT_URI, touch);
if (DEBUG)
Log.d(TAG, "Touch: " + touch.toString());
Intent touch_data = new Intent(Screen.ACTION_AWARE_TOUCH_SCROLLED_DOWN);
sendBroadcast(touch_data);
}
}
last_scroll_index = event.getFromIndex();
}
if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_CLICKED) {
ContentValues touch = new ContentValues();
touch.put(Screen_Provider.Screen_Touch.TIMESTAMP, System.currentTimeMillis());
touch.put(Screen_Provider.Screen_Touch.DEVICE_ID, Aware.getSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID));
touch.put(Screen_Provider.Screen_Touch.TOUCH_APP, event.getPackageName().toString());
touch.put(Screen_Provider.Screen_Touch.TOUCH_ACTION, Screen.ACTION_AWARE_TOUCH_CLICKED);
touch.put(Screen_Provider.Screen_Touch.TOUCH_ACTION_TEXT, event.getText().toString());
touch.put(Screen_Provider.Screen_Touch.TOUCH_INDEX_ITEMS, event.getItemCount());
touch.put(Screen_Provider.Screen_Touch.TOUCH_FROM_INDEX, event.getFromIndex());
touch.put(Screen_Provider.Screen_Touch.TOUCH_TO_INDEX, event.getToIndex());
if (awareSensor != null)
awareSensor.onTouch(touch);
getContentResolver().insert(Screen_Provider.Screen_Touch.CONTENT_URI, touch);
if (DEBUG)
Log.d(TAG, "Touch: " + touch.toString());
Intent touch_data = new Intent(Screen.ACTION_AWARE_TOUCH_CLICKED);
sendBroadcast(touch_data);
}
if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_LONG_CLICKED) {
ContentValues touch = new ContentValues();
touch.put(Screen_Provider.Screen_Touch.TIMESTAMP, System.currentTimeMillis());
touch.put(Screen_Provider.Screen_Touch.DEVICE_ID, Aware.getSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID));
touch.put(Screen_Provider.Screen_Touch.TOUCH_APP, event.getPackageName().toString());
touch.put(Screen_Provider.Screen_Touch.TOUCH_ACTION, Screen.ACTION_AWARE_TOUCH_LONG_CLICKED);
touch.put(Screen_Provider.Screen_Touch.TOUCH_ACTION_TEXT, event.getText().toString());
touch.put(Screen_Provider.Screen_Touch.TOUCH_INDEX_ITEMS, event.getItemCount());
touch.put(Screen_Provider.Screen_Touch.TOUCH_FROM_INDEX, event.getFromIndex());
touch.put(Screen_Provider.Screen_Touch.TOUCH_TO_INDEX, event.getToIndex());
if (awareSensor != null)
awareSensor.onTouch(touch);
getContentResolver().insert(Screen_Provider.Screen_Touch.CONTENT_URI, touch);
if (DEBUG)
Log.d(TAG, "Touch: " + touch.toString());
Intent touch_data = new Intent(Screen.ACTION_AWARE_TOUCH_LONG_CLICKED);
sendBroadcast(touch_data);
}
}
}
use of android.app.ActivityManager.ProcessErrorStateInfo in project android_frameworks_base by ParanoidAndroid.
the class AppCompatibility method launchActivity.
/**
* Launches and activity and queries for errors.
*
* @param packageName {@link String} the package name of the application to
* launch.
* @return {@link Collection} of {@link ProcessErrorStateInfo} detected
* during the app launch.
*/
private Collection<ProcessErrorStateInfo> launchActivity(String packageName) {
Intent homeIntent = new Intent(Intent.ACTION_MAIN);
homeIntent.addCategory(Intent.CATEGORY_HOME);
homeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Intent intent = mPackageManager.getLaunchIntentForPackage(packageName);
// Skip if the apk does not have a launch intent.
if (intent == null) {
Log.d(TAG, "Skipping " + packageName + "; missing launch intent");
return null;
}
// We check for any Crash or ANR dialogs that are already up, and we
// ignore them. This is
// so that we don't report crashes that were caused by prior apps (which
// those particular
// tests should have caught and reported already). Otherwise, test
// failures would cascade
// from the initial broken app to many/all of the tests following that
// app's launch.
final Collection<ProcessErrorStateInfo> preErr = mActivityManager.getProcessesInErrorState();
// Launch Activity
mContext.startActivity(intent);
try {
Thread.sleep(mAppLaunchTimeout);
} catch (InterruptedException e) {
// ignore
}
// Send the "home" intent and wait 2 seconds for us to get there
mContext.startActivity(homeIntent);
try {
Thread.sleep(mWorkspaceLaunchTimeout);
} catch (InterruptedException e) {
// ignore
}
// See if there are any errors. We wait until down here to give ANRs as
// much time as
// possible to occur.
final Collection<ProcessErrorStateInfo> postErr = mActivityManager.getProcessesInErrorState();
// present when we started
if (preErr != null && postErr != null) {
postErr.removeAll(preErr);
}
return postErr;
}
Aggregations