use of android.app.IActivityManager in project android_frameworks_base by ParanoidAndroid.
the class PackageManagerService method installExistingPackageAsUser.
/**
* @hide
*/
@Override
public int installExistingPackageAsUser(String packageName, int userId) {
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.INSTALL_PACKAGES, null);
PackageSetting pkgSetting;
final int uid = Binder.getCallingUid();
if (UserHandle.getUserId(uid) != userId) {
mContext.enforceCallingPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, "installExistingPackage for user " + userId);
}
if (isUserRestricted(userId, UserManager.DISALLOW_INSTALL_APPS)) {
return PackageManager.INSTALL_FAILED_USER_RESTRICTED;
}
long callingId = Binder.clearCallingIdentity();
try {
boolean sendAdded = false;
Bundle extras = new Bundle(1);
// writer
synchronized (mPackages) {
pkgSetting = mSettings.mPackages.get(packageName);
if (pkgSetting == null) {
return PackageManager.INSTALL_FAILED_INVALID_URI;
}
if (!pkgSetting.getInstalled(userId)) {
pkgSetting.setInstalled(true, userId);
mSettings.writePackageRestrictionsLPr(userId);
extras.putInt(Intent.EXTRA_UID, UserHandle.getUid(userId, pkgSetting.appId));
sendAdded = true;
}
}
if (sendAdded) {
sendPackageBroadcast(Intent.ACTION_PACKAGE_ADDED, null, packageName, extras, null, null, new int[] { userId });
try {
IActivityManager am = ActivityManagerNative.getDefault();
final boolean isSystem = isSystemApp(pkgSetting) || isUpdatedSystemApp(pkgSetting);
if (isSystem && am.isUserRunning(userId, false)) {
// The just-installed/enabled app is bundled on the system, so presumed
// to be able to run automatically without needing an explicit launch.
// Send it a BOOT_COMPLETED if it would ordinarily have gotten one.
Intent bcIntent = new Intent(Intent.ACTION_BOOT_COMPLETED).addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES).setPackage(packageName);
am.broadcastIntent(null, bcIntent, null, null, 0, null, null, null, android.app.AppOpsManager.OP_NONE, false, false, userId);
}
} catch (RemoteException e) {
// shouldn't happen
Slog.w(TAG, "Unable to bootstrap installed package", e);
}
}
} finally {
Binder.restoreCallingIdentity(callingId);
}
return PackageManager.INSTALL_SUCCEEDED;
}
use of android.app.IActivityManager in project android_frameworks_base by ParanoidAndroid.
the class PackageManagerService method revokePermission.
public void revokePermission(String packageName, String permissionName) {
int changedAppId = -1;
synchronized (mPackages) {
final PackageParser.Package pkg = mPackages.get(packageName);
if (pkg == null) {
throw new IllegalArgumentException("Unknown package: " + packageName);
}
if (pkg.applicationInfo.uid != Binder.getCallingUid()) {
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.GRANT_REVOKE_PERMISSIONS, null);
}
final BasePermission bp = mSettings.mPermissions.get(permissionName);
if (bp == null) {
throw new IllegalArgumentException("Unknown permission: " + permissionName);
}
checkGrantRevokePermissions(pkg, bp);
final PackageSetting ps = (PackageSetting) pkg.mExtras;
if (ps == null) {
return;
}
final GrantedPermissions gp = (ps.sharedUser != null) ? ps.sharedUser : ps;
if (gp.grantedPermissions.remove(permissionName)) {
gp.grantedPermissions.remove(permissionName);
if (ps.haveGids) {
gp.gids = removeInts(gp.gids, bp.gids);
}
mSettings.writeLPr();
changedAppId = ps.appId;
}
}
if (changedAppId >= 0) {
// We changed the perm on someone, kill its processes.
IActivityManager am = ActivityManagerNative.getDefault();
if (am != null) {
final int callingUserId = UserHandle.getCallingUserId();
final long ident = Binder.clearCallingIdentity();
try {
//XXX we should only revoke for the calling user's app permissions,
// but for now we impact all users.
//am.killUid(UserHandle.getUid(callingUserId, changedAppId),
// "revoke " + permissionName);
int[] users = sUserManager.getUserIds();
for (int user : users) {
am.killUid(UserHandle.getUid(user, changedAppId), "revoke " + permissionName);
}
} catch (RemoteException e) {
} finally {
Binder.restoreCallingIdentity(ident);
}
}
}
}
use of android.app.IActivityManager in project android_frameworks_base by ParanoidAndroid.
the class ShutdownThread method run.
/**
* Makes sure we handle the shutdown gracefully.
* Shuts off power regardless of radio and bluetooth state if the alloted time has passed.
*/
public void run() {
BroadcastReceiver br = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// We don't allow apps to cancel this, so ignore the result.
actionDone();
}
};
/*
* Write a system property in case the system_server reboots before we
* get to the actual hardware restart. If that happens, we'll retry at
* the beginning of the SystemServer startup.
*/
{
String reason = (mReboot ? "1" : "0") + (mRebootReason != null ? mRebootReason : "");
SystemProperties.set(SHUTDOWN_ACTION_PROPERTY, reason);
}
/*
* If we are rebooting into safe mode, write a system property
* indicating so.
*/
if (mRebootSafeMode) {
SystemProperties.set(REBOOT_SAFEMODE_PROPERTY, "1");
}
Log.i(TAG, "Sending shutdown broadcast...");
// First send the high-level shut down broadcast.
mActionDone = false;
Intent intent = new Intent(Intent.ACTION_SHUTDOWN);
intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
mContext.sendOrderedBroadcastAsUser(intent, UserHandle.ALL, null, br, mHandler, 0, null, null);
final long endTime = SystemClock.elapsedRealtime() + MAX_BROADCAST_TIME;
synchronized (mActionDoneSync) {
while (!mActionDone) {
long delay = endTime - SystemClock.elapsedRealtime();
if (delay <= 0) {
Log.w(TAG, "Shutdown broadcast timed out");
break;
}
try {
mActionDoneSync.wait(delay);
} catch (InterruptedException e) {
}
}
}
Log.i(TAG, "Shutting down activity manager...");
final IActivityManager am = ActivityManagerNative.asInterface(ServiceManager.checkService("activity"));
if (am != null) {
try {
am.shutdown(MAX_BROADCAST_TIME);
} catch (RemoteException e) {
}
}
// Shutdown radios.
shutdownRadios(MAX_RADIO_WAIT_TIME);
// Shutdown MountService to ensure media is in a safe state
IMountShutdownObserver observer = new IMountShutdownObserver.Stub() {
public void onShutDownComplete(int statusCode) throws RemoteException {
Log.w(TAG, "Result code " + statusCode + " from MountService.shutdown");
actionDone();
}
};
Log.i(TAG, "Shutting down MountService");
// Set initial variables and time out time.
mActionDone = false;
final long endShutTime = SystemClock.elapsedRealtime() + MAX_SHUTDOWN_WAIT_TIME;
synchronized (mActionDoneSync) {
try {
final IMountService mount = IMountService.Stub.asInterface(ServiceManager.checkService("mount"));
if (mount != null) {
mount.shutdown(observer);
} else {
Log.w(TAG, "MountService unavailable for shutdown");
}
} catch (Exception e) {
Log.e(TAG, "Exception during MountService shutdown", e);
}
while (!mActionDone) {
long delay = endShutTime - SystemClock.elapsedRealtime();
if (delay <= 0) {
Log.w(TAG, "Shutdown wait timed out");
break;
}
try {
mActionDoneSync.wait(delay);
} catch (InterruptedException e) {
}
}
}
rebootOrShutdown(mReboot, mRebootReason);
}
use of android.app.IActivityManager in project android_frameworks_base by ParanoidAndroid.
the class BroadcastReceiver method peekService.
/**
* Provide a binder to an already-running 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}.
*
* @param myContext The Context that had been passed to {@link #onReceive(Context, Intent)}
* @param service The Intent indicating the service you wish to use. See {@link
* Context#startService(Intent)} for more information.
*/
public IBinder peekService(Context myContext, Intent service) {
IActivityManager am = ActivityManagerNative.getDefault();
IBinder binder = null;
try {
service.prepareToLeaveProcess();
binder = am.peekService(service, service.resolveTypeIfNeeded(myContext.getContentResolver()));
} catch (RemoteException e) {
}
return binder;
}
use of android.app.IActivityManager in project android_frameworks_base by ParanoidAndroid.
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) {
Log.e(TAG, "RemoteException handling StrictMode violation", e);
}
int outstanding = sDropboxCallsInFlight.decrementAndGet();
if (LOG_V)
Log.d(TAG, "Dropbox complete; in-flight=" + outstanding);
}
}.start();
}
Aggregations