use of android.app.IActivityManager in project android_frameworks_base by crdroidandroid.
the class BroadcastReceiver method peekService.
/**
* Provide a binder to an already-bound service. This method is synchronous
* and will not start the target service if it is not present, so it is safe
* to call from {@link #onReceive}.
*
* For peekService() to return a non null {@link android.os.IBinder} interface
* the service must have published it before. In other words some component
* must have called {@link android.content.Context#bindService(Intent, ServiceConnection, int)} on it.
*
* @param myContext The Context that had been passed to {@link #onReceive(Context, Intent)}
* @param service Identifies the already-bound service you wish to use. See
* {@link android.content.Context#bindService(Intent, ServiceConnection, int)}
* for more information.
*/
public IBinder peekService(Context myContext, Intent service) {
IActivityManager am = ActivityManagerNative.getDefault();
IBinder binder = null;
try {
service.prepareToLeaveProcess(myContext);
binder = am.peekService(service, service.resolveTypeIfNeeded(myContext.getContentResolver()), myContext.getOpPackageName());
} catch (RemoteException e) {
}
return binder;
}
use of android.app.IActivityManager in project android_frameworks_base by crdroidandroid.
the class ShellUiAutomatorBridge method getSystemLongPressTime.
public long getSystemLongPressTime() {
// Read the long press timeout setting.
long longPressTimeout = 0;
try {
IContentProvider provider = null;
Cursor cursor = null;
IActivityManager activityManager = ActivityManagerNative.getDefault();
String providerName = Settings.Secure.CONTENT_URI.getAuthority();
IBinder token = new Binder();
try {
ContentProviderHolder holder = activityManager.getContentProviderExternal(providerName, UserHandle.USER_SYSTEM, token);
if (holder == null) {
throw new IllegalStateException("Could not find provider: " + providerName);
}
provider = holder.provider;
cursor = provider.query(null, Settings.Secure.CONTENT_URI, new String[] { Settings.Secure.VALUE }, "name=?", new String[] { Settings.Secure.LONG_PRESS_TIMEOUT }, null, null);
if (cursor.moveToFirst()) {
longPressTimeout = cursor.getInt(0);
}
} finally {
if (cursor != null) {
cursor.close();
}
if (provider != null) {
activityManager.removeContentProviderExternal(providerName, token);
}
}
} catch (RemoteException e) {
String message = "Error reading long press timeout setting.";
Log.e(LOG_TAG, message, e);
throw new RuntimeException(message, e);
}
return longPressTimeout;
}
use of android.app.IActivityManager in project android_frameworks_base by crdroidandroid.
the class StrictMode method dropboxViolationAsync.
/**
* In the common case, as set by conditionallyEnableDebugLogging,
* we're just dropboxing any violations but not showing a dialog,
* not loggging, and not killing the process. In these cases we
* don't need to do a synchronous call to the ActivityManager.
* This is used by both per-thread and vm-wide violations when
* applicable.
*/
private static void dropboxViolationAsync(final int violationMaskSubset, final ViolationInfo info) {
int outstanding = sDropboxCallsInFlight.incrementAndGet();
if (outstanding > 20) {
// What's going on? Let's not make make the situation
// worse and just not log.
sDropboxCallsInFlight.decrementAndGet();
return;
}
if (LOG_V)
Log.d(TAG, "Dropboxing async; in-flight=" + outstanding);
new Thread("callActivityManagerForStrictModeDropbox") {
public void run() {
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
try {
IActivityManager am = ActivityManagerNative.getDefault();
if (am == null) {
Log.d(TAG, "No activity manager; failed to Dropbox violation.");
} else {
am.handleApplicationStrictModeViolation(RuntimeInit.getApplicationObject(), violationMaskSubset, info);
}
} catch (RemoteException e) {
if (e instanceof DeadObjectException) {
// System process is dead; ignore
} else {
Log.e(TAG, "RemoteException handling StrictMode violation", e);
}
}
int outstanding = sDropboxCallsInFlight.decrementAndGet();
if (LOG_V)
Log.d(TAG, "Dropbox complete; in-flight=" + outstanding);
}
}.start();
}
use of android.app.IActivityManager in project android_frameworks_base by crdroidandroid.
the class ActionUtils method killForegroundAppInternal.
private static boolean killForegroundAppInternal(Context context, int userId) throws RemoteException {
try {
final Intent intent = new Intent(Intent.ACTION_MAIN);
String defaultHomePackage = "com.android.launcher";
intent.addCategory(Intent.CATEGORY_HOME);
final ResolveInfo res = context.getPackageManager().resolveActivity(intent, 0);
if (res.activityInfo != null && !res.activityInfo.packageName.equals("android")) {
defaultHomePackage = res.activityInfo.packageName;
}
IActivityManager am = ActivityManagerNative.getDefault();
List<ActivityManager.RunningAppProcessInfo> apps = am.getRunningAppProcesses();
for (ActivityManager.RunningAppProcessInfo appInfo : apps) {
int uid = appInfo.uid;
// root, phone, etc.)
if (uid >= Process.FIRST_APPLICATION_UID && uid <= Process.LAST_APPLICATION_UID && appInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
if (appInfo.pkgList != null && (appInfo.pkgList.length > 0)) {
for (String pkg : appInfo.pkgList) {
if (!pkg.equals("com.android.systemui") && !pkg.equals(defaultHomePackage)) {
am.forceStopPackage(pkg, UserHandle.USER_CURRENT);
return true;
}
}
} else {
Process.killProcess(appInfo.pid);
return true;
}
}
}
} catch (RemoteException remoteException) {
// Do nothing; just let it go.
}
return false;
}
use of android.app.IActivityManager in project android_packages_apps_Settings by LineageOS.
the class Utils method getSecureTargetUser.
/**
* Returns the target user for a Settings activity.
* <p>
* User would be retrieved in this order:
* <ul>
* <li> If this activity is launched from other user, return that user id.
* <li> If this is launched from the Settings app in same user, return the user contained as an
* extra in the arguments or intent extras.
* <li> Otherwise, return UserHandle.myUserId().
* </ul>
* <p>
* Note: This is secure in the sense that it only returns a target user different to the current
* one if the app launching this activity is the Settings app itself, running in the same user
* or in one that is in the same profile group, or if the user id is provided by the system.
*/
public static UserHandle getSecureTargetUser(IBinder activityToken, UserManager um, @Nullable Bundle arguments, @Nullable Bundle intentExtras) {
UserHandle currentUser = new UserHandle(UserHandle.myUserId());
IActivityManager am = ActivityManager.getService();
try {
String launchedFromPackage = am.getLaunchedFromPackage(activityToken);
boolean launchedFromSettingsApp = SETTINGS_PACKAGE_NAME.equals(launchedFromPackage);
UserHandle launchedFromUser = new UserHandle(UserHandle.getUserId(am.getLaunchedFromUid(activityToken)));
if (launchedFromUser != null && !launchedFromUser.equals(currentUser)) {
// Check it's secure
if (isProfileOf(um, launchedFromUser)) {
return launchedFromUser;
}
}
UserHandle extrasUser = getUserHandleFromBundle(intentExtras);
if (extrasUser != null && !extrasUser.equals(currentUser)) {
// Check it's secure
if (launchedFromSettingsApp && isProfileOf(um, extrasUser)) {
return extrasUser;
}
}
UserHandle argumentsUser = getUserHandleFromBundle(arguments);
if (argumentsUser != null && !argumentsUser.equals(currentUser)) {
// Check it's secure
if (launchedFromSettingsApp && isProfileOf(um, argumentsUser)) {
return argumentsUser;
}
}
} catch (RemoteException e) {
// Should not happen
Log.v(TAG, "Could not talk to activity manager.", e);
}
return currentUser;
}
Aggregations