use of android.app.IActivityManager in project platform_frameworks_base by android.
the class PackageManagerService method startCleaningPackages.
void startCleaningPackages() {
// reader
if (!isExternalMediaAvailable()) {
return;
}
synchronized (mPackages) {
if (mSettings.mPackagesToBeCleaned.isEmpty()) {
return;
}
}
Intent intent = new Intent(PackageManager.ACTION_CLEAN_EXTERNAL_STORAGE);
intent.setComponent(DEFAULT_CONTAINER_COMPONENT);
IActivityManager am = ActivityManagerNative.getDefault();
if (am != null) {
try {
am.startService(null, intent, null, mContext.getOpPackageName(), UserHandle.USER_SYSTEM);
} catch (RemoteException e) {
}
}
}
use of android.app.IActivityManager in project platform_frameworks_base by android.
the class PackageManagerService method setPermissionEnforced.
@Override
public void setPermissionEnforced(String permission, boolean enforced) {
// TODO: Now that we no longer change GID for storage, this should to away.
mContext.enforceCallingOrSelfPermission(Manifest.permission.GRANT_RUNTIME_PERMISSIONS, "setPermissionEnforced");
if (READ_EXTERNAL_STORAGE.equals(permission)) {
synchronized (mPackages) {
if (mSettings.mReadExternalStorageEnforced == null || mSettings.mReadExternalStorageEnforced != enforced) {
mSettings.mReadExternalStorageEnforced = enforced;
mSettings.writeLPr();
}
}
// kill any non-foreground processes so we restart them and
// grant/revoke the GID.
final IActivityManager am = ActivityManagerNative.getDefault();
if (am != null) {
final long token = Binder.clearCallingIdentity();
try {
am.killProcessesBelowForeground("setPermissionEnforcement");
} catch (RemoteException e) {
} finally {
Binder.restoreCallingIdentity(token);
}
}
} else {
throw new IllegalArgumentException("No selective enforcement for " + permission);
}
}
use of android.app.IActivityManager in project android_frameworks_base by ParanoidAndroid.
the class SettingsCmd method run.
public void run() {
boolean valid = false;
String arg;
try {
while ((arg = nextArg()) != null) {
if ("--user".equals(arg)) {
if (mUser != -1) {
// --user specified more than once; invalid
break;
}
mUser = Integer.parseInt(nextArg());
} else if (mVerb == CommandVerb.UNSPECIFIED) {
if ("get".equalsIgnoreCase(arg)) {
mVerb = CommandVerb.GET;
} else if ("put".equalsIgnoreCase(arg)) {
mVerb = CommandVerb.PUT;
} else {
// invalid
System.err.println("Invalid command: " + arg);
break;
}
} else if (mTable == null) {
if (!"system".equalsIgnoreCase(arg) && !"secure".equalsIgnoreCase(arg) && !"global".equalsIgnoreCase(arg)) {
System.err.println("Invalid namespace '" + arg + "'");
// invalid
break;
}
mTable = arg.toLowerCase();
} else if (mVerb == CommandVerb.GET) {
mKey = arg;
if (mNextArg >= mArgs.length) {
valid = true;
} else {
System.err.println("Too many arguments");
}
break;
} else if (mKey == null) {
mKey = arg;
// keep going; there's another PUT arg
} else {
// PUT, final arg
mValue = arg;
if (mNextArg >= mArgs.length) {
valid = true;
} else {
System.err.println("Too many arguments");
}
break;
}
}
} catch (Exception e) {
valid = false;
}
if (valid) {
if (mUser < 0) {
mUser = UserHandle.USER_OWNER;
}
try {
IActivityManager activityManager = ActivityManagerNative.getDefault();
IContentProvider provider = null;
IBinder token = new Binder();
try {
ContentProviderHolder holder = activityManager.getContentProviderExternal("settings", UserHandle.USER_OWNER, token);
if (holder == null) {
throw new IllegalStateException("Could not find settings provider");
}
provider = holder.provider;
switch(mVerb) {
case GET:
System.out.println(getForUser(provider, mUser, mTable, mKey));
break;
case PUT:
putForUser(provider, mUser, mTable, mKey, mValue);
break;
default:
System.err.println("Unspecified command");
break;
}
} finally {
if (provider != null) {
activityManager.removeContentProviderExternal("settings", token);
}
}
} catch (Exception e) {
System.err.println("Error while accessing settings provider");
e.printStackTrace();
}
} else {
printUsage();
}
}
use of android.app.IActivityManager in project android_frameworks_base by ParanoidAndroid.
the class SettingsHelper method setLocaleData.
/**
* Sets the locale specified. Input data is the equivalent of "ll_cc".getBytes(), where
* "ll" is the language code and "cc" is the country code.
* @param data the locale string in bytes.
*/
void setLocaleData(byte[] data, int size) {
// Check if locale was set by the user:
Configuration conf = mContext.getResources().getConfiguration();
Locale loc = conf.locale;
// Don't change if user set it in the SetupWizard
if (conf.userSetLocale)
return;
final String[] availableLocales = mContext.getAssets().getLocales();
String localeCode = new String(data, 0, size);
String language = new String(data, 0, 2);
String country = size > 4 ? new String(data, 3, 2) : "";
loc = null;
for (int i = 0; i < availableLocales.length; i++) {
if (availableLocales[i].equals(localeCode)) {
loc = new Locale(language, country);
break;
}
}
// Couldn't find the saved locale in this version of the software
if (loc == null)
return;
try {
IActivityManager am = ActivityManagerNative.getDefault();
Configuration config = am.getConfiguration();
config.locale = loc;
// indicate this isn't some passing default - the user wants this remembered
config.userSetLocale = true;
am.updateConfiguration(config);
} catch (RemoteException e) {
// Intentionally left blank
}
}
use of android.app.IActivityManager in project android_frameworks_base by ParanoidAndroid.
the class PackageManagerService method sendPackageBroadcast.
static final void sendPackageBroadcast(String action, String pkg, String intentCategory, Bundle extras, String targetPkg, IIntentReceiver finishedReceiver, int[] userIds) {
IActivityManager am = ActivityManagerNative.getDefault();
if (am != null) {
try {
if (userIds == null) {
userIds = am.getRunningUserIds();
}
for (int id : userIds) {
final Intent intent = new Intent(action, pkg != null ? Uri.fromParts("package", pkg, null) : null);
if (extras != null) {
intent.putExtras(extras);
}
if (targetPkg != null) {
intent.setPackage(targetPkg);
}
// Modify the UID when posting to other users
int uid = intent.getIntExtra(Intent.EXTRA_UID, -1);
if (uid > 0 && UserHandle.getUserId(uid) != id) {
uid = UserHandle.getUid(id, UserHandle.getAppId(uid));
intent.putExtra(Intent.EXTRA_UID, uid);
}
intent.putExtra(Intent.EXTRA_USER_HANDLE, id);
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
if (DEBUG_BROADCASTS) {
RuntimeException here = new RuntimeException("here");
here.fillInStackTrace();
Slog.d(TAG, "Sending to user " + id + ": " + intent.toShortString(false, true, false, false) + " " + intent.getExtras(), here);
}
if (intentCategory != null) {
intent.addCategory(intentCategory);
}
am.broadcastIntent(null, intent, null, finishedReceiver, 0, null, null, null, android.app.AppOpsManager.OP_NONE, finishedReceiver != null, false, id);
}
} catch (RemoteException ex) {
}
}
}
Aggregations