Java Code Examples for android.app.ActivityManagerNative#getDefault()

The following examples show how to use android.app.ActivityManagerNative#getDefault() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UiAutomationShellWrapper.java    From JsDroidCmd with Mozilla Public License 2.0 6 votes vote down vote up
public void setRunAsMonkey(boolean isSet) {
	IActivityManager am = ActivityManagerNative.getDefault();
	if (am == null) {
		throw new RuntimeException(
				"Can't manage monkey status; is the system running?");
	}
	try {
		if (isSet) {
			am.setActivityController(new DummyActivityController());
		} else {
			am.setActivityController(null);
		}
	} catch (RemoteException e) {
		throw new RuntimeException(e);
	}
}
 
Example 2
Source File: UiDevice.java    From JsDroidCmd with Mozilla Public License 2.0 6 votes vote down vote up
public void initialize(ShellUiAutomatorBridge uiAutomatorBridge) {
	mUiAutomationBridge = uiAutomatorBridge;
	// 监听activity变化,用于getAct
	try {
		IActivityManager am = ActivityManagerNative.getDefault();
		am.setActivityController(new DummyActivityController());
	} catch (RemoteException e) {
	}
	UiAutomation uiAutomation = uiAutomatorBridge.getUiAutomation();
	uiAutomation
			.setOnAccessibilityEventListener(new OnAccessibilityEventListener() {
				public void onAccessibilityEvent(AccessibilityEvent event) {
					synchronized (onAccessibilityEventListeners) {
						for (OnAccessibilityEventListener listener : onAccessibilityEventListeners) {
							listener.onAccessibilityEvent(event);
						}
					}
				}
			});
}
 
Example 3
Source File: UserManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Evicts a user's CE key by stopping and restarting the user.
 *
 * The key is evicted automatically by the user controller when the user has stopped.
 */
@Override
public void evictCredentialEncryptionKey(@UserIdInt int userId) {
    checkManageUsersPermission("evict CE key");
    final IActivityManager am = ActivityManagerNative.getDefault();
    final long identity = Binder.clearCallingIdentity();
    try {
        am.restartUserInBackground(userId);
    } catch (RemoteException re) {
        throw re.rethrowAsRuntimeException();
    } finally {
        Binder.restoreCallingIdentity(identity);
    }
}
 
Example 4
Source File: ShellUiAutomatorBridge.java    From JsDroidCmd with Mozilla Public License 2.0 5 votes vote down vote up
public long getSystemLongPressTime() {
	long longPressTimeout = 2000;
	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_OWNER, 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 (Throwable e) {
	}
	return longPressTimeout;
}
 
Example 5
Source File: SettingsHelper.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
    // TODO: The following is not working as intended because the network is forcing a locale
    // change after registering. Need to find some other way to detect if the user manually
    // changed the locale
    if (conf.userSetLocale) return; // Don't change if user set it in the SetupWizard

    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;
        }
    }
    if (loc == null) return; // Couldn't find the saved locale in this version of the software

    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
    }
}
 
Example 6
Source File: ActivityManagerPatch.java    From DeepInVirtualApp with MIT License 4 votes vote down vote up
public static IActivityManager getAMN() {
    return ActivityManagerNative.getDefault();
}
 
Example 7
Source File: ToolConnection.java    From android-test with Apache License 2.0 4 votes vote down vote up
@Override
protected Object getActivityManager() {
  Log.i(TAG, "Invoking ActivityManagerNative.getDefault");
  return ActivityManagerNative.getDefault();
}