use of android.app.IActivityManager in project platform_frameworks_base by android.
the class SettingsHelper method setLocaleData.
/**
* Sets the locale specified. Input data is the byte representation of a
* BCP-47 language tag. For backwards compatibility, strings of the form
* {@code ll_CC} are also accepted, where {@code ll} is a two letter language
* code and {@code CC} is a two letter 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();
// Don't change if user set it in the SetupWizard
if (conf.userSetLocale)
return;
final String[] availableLocales = mContext.getAssets().getLocales();
// Replace "_" with "-" to deal with older backups.
String localeCode = new String(data, 0, size).replace('_', '-');
Locale loc = null;
for (int i = 0; i < availableLocales.length; i++) {
if (availableLocales[i].equals(localeCode)) {
loc = Locale.forLanguageTag(localeCode);
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 platform_frameworks_base by android.
the class PhoneStatusBar method handleLongPressBack.
/**
* Handles long press for back button. This exits screen pinning.
*/
private boolean handleLongPressBack() {
try {
IActivityManager activityManager = ActivityManagerNative.getDefault();
if (activityManager.isInLockTaskMode()) {
activityManager.stopSystemLockTaskMode();
// When exiting refresh disabled flags.
mNavigationBarView.setDisabledFlags(mDisabled1, true);
return true;
}
} catch (RemoteException e) {
Log.d(TAG, "Unable to reach activity manager", e);
}
return false;
}
use of android.app.IActivityManager in project platform_frameworks_base by android.
the class SearchManagerService method launchLegacyAssist.
@Override
public boolean launchLegacyAssist(String hint, int userHandle, Bundle args) {
ComponentName comp = getLegacyAssistComponent(userHandle);
if (comp == null) {
return false;
}
long ident = Binder.clearCallingIdentity();
try {
Intent intent = new Intent(Intent.ACTION_ASSIST);
intent.setComponent(comp);
IActivityManager am = ActivityManagerNative.getDefault();
return am.launchAssistIntent(intent, ActivityManager.ASSIST_CONTEXT_BASIC, hint, userHandle, args);
} catch (RemoteException e) {
} finally {
Binder.restoreCallingIdentity(ident);
}
return true;
}
use of android.app.IActivityManager in project XobotOS by xamarin.
the class PhoneBase method setSystemLocale.
/**
* Utility code to set the system locale if it's not set already
* @param language Two character language code desired
* @param country Two character country code desired
* @param fromMcc Indicating whether the locale is set according to MCC table.
* This flag wil be ignored by default implementation.
* TODO: Use a source enumeration so that source of the locale
* can be prioritized.
*
* {@hide}
*/
public void setSystemLocale(String language, String country, boolean fromMcc) {
String l = SystemProperties.get("persist.sys.language");
String c = SystemProperties.get("persist.sys.country");
if (null == language) {
// no match possible
return;
}
language = language.toLowerCase();
if (null == country) {
country = "";
}
country = country.toUpperCase();
if ((null == l || 0 == l.length()) && (null == c || 0 == c.length())) {
try {
// try to find a good match
String[] locales = mContext.getAssets().getLocales();
final int N = locales.length;
String bestMatch = null;
for (int i = 0; i < N; i++) {
// only match full (lang + country) locales
if (locales[i] != null && locales[i].length() >= 5 && locales[i].substring(0, 2).equals(language)) {
if (locales[i].substring(3, 5).equals(country)) {
bestMatch = locales[i];
break;
} else if (null == bestMatch) {
bestMatch = locales[i];
}
}
}
if (null != bestMatch) {
IActivityManager am = ActivityManagerNative.getDefault();
Configuration config = am.getConfiguration();
config.locale = new Locale(bestMatch.substring(0, 2), bestMatch.substring(3, 5));
config.userSetLocale = true;
am.updateConfiguration(config);
}
} catch (Exception e) {
// Intentionally left blank
}
}
}
use of android.app.IActivityManager in project XobotOS by xamarin.
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() {
boolean bluetoothOff;
boolean radioOff;
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);
}
Log.i(TAG, "Sending shutdown broadcast...");
// First send the high-level shut down broadcast.
mActionDone = false;
mContext.sendOrderedBroadcast(new Intent(Intent.ACTION_SHUTDOWN), 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) {
}
}
final ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.checkService("phone"));
final IBluetooth bluetooth = IBluetooth.Stub.asInterface(ServiceManager.checkService(BluetoothAdapter.BLUETOOTH_SERVICE));
final IMountService mount = IMountService.Stub.asInterface(ServiceManager.checkService("mount"));
try {
bluetoothOff = bluetooth == null || bluetooth.getBluetoothState() == BluetoothAdapter.STATE_OFF;
if (!bluetoothOff) {
Log.w(TAG, "Disabling Bluetooth...");
// disable but don't persist new state
bluetooth.disable(false);
}
} catch (RemoteException ex) {
Log.e(TAG, "RemoteException during bluetooth shutdown", ex);
bluetoothOff = true;
}
try {
radioOff = phone == null || !phone.isRadioOn();
if (!radioOff) {
Log.w(TAG, "Turning off radio...");
phone.setRadio(false);
}
} catch (RemoteException ex) {
Log.e(TAG, "RemoteException during radio shutdown", ex);
radioOff = true;
}
Log.i(TAG, "Waiting for Bluetooth and Radio...");
// Wait a max of 32 seconds for clean shutdown
for (int i = 0; i < MAX_NUM_PHONE_STATE_READS; i++) {
if (!bluetoothOff) {
try {
bluetoothOff = bluetooth.getBluetoothState() == BluetoothAdapter.STATE_OFF;
} catch (RemoteException ex) {
Log.e(TAG, "RemoteException during bluetooth shutdown", ex);
bluetoothOff = true;
}
}
if (!radioOff) {
try {
radioOff = !phone.isRadioOn();
} catch (RemoteException ex) {
Log.e(TAG, "RemoteException during radio shutdown", ex);
radioOff = true;
}
}
if (radioOff && bluetoothOff) {
Log.i(TAG, "Radio and Bluetooth shutdown complete.");
break;
}
SystemClock.sleep(PHONE_STATE_POLL_SLEEP_MSEC);
}
// 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 {
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);
}
Aggregations