Java Code Examples for android.app.ActivityManager#isUserAMonkey()

The following examples show how to use android.app.ActivityManager#isUserAMonkey() . 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: PersistentDataBlockService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public void setOemUnlockEnabled(boolean enabled) throws SecurityException {
    // do not allow monkey to flip the flag
    if (ActivityManager.isUserAMonkey()) {
        return;
    }

    enforceOemUnlockWritePermission();
    enforceIsAdmin();

    if (enabled) {
        // Do not allow oem unlock to be enabled if it's disallowed by a user restriction.
        enforceUserRestriction(UserManager.DISALLOW_OEM_UNLOCK);
        enforceUserRestriction(UserManager.DISALLOW_FACTORY_RESET);
    }
    synchronized (mLock) {
        doSetOemUnlockEnabledLocked(enabled);
        computeAndWriteDigestLocked();
    }
}
 
Example 2
Source File: LegacyGlobalActions.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public void onPress() {
    // don't actually trigger the bugreport if we are running stability
    // tests via monkey
    if (ActivityManager.isUserAMonkey()) {
        return;
    }
    // Add a little delay before executing, to give the
    // dialog a chance to go away before it takes a
    // screenshot.
    mHandler.postDelayed(new Runnable() {
        @Override
        public void run() {
            try {
                // Take an "interactive" bugreport.
                MetricsLogger.action(mContext,
                        MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_INTERACTIVE);
                ActivityManager.getService().requestBugReport(
                        ActivityManager.BUGREPORT_OPTION_INTERACTIVE);
            } catch (RemoteException e) {
            }
        }
    }, 500);
}
 
Example 3
Source File: LegacyGlobalActions.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onLongPress() {
    // don't actually trigger the bugreport if we are running stability
    // tests via monkey
    if (ActivityManager.isUserAMonkey()) {
        return false;
    }
    try {
        // Take a "full" bugreport.
        MetricsLogger.action(mContext, MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_FULL);
        ActivityManager.getService().requestBugReport(
                ActivityManager.BUGREPORT_OPTION_FULL);
    } catch (RemoteException e) {
    }
    return false;
}
 
Example 4
Source File: OemLockService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public void setOemUnlockAllowedByUser(boolean allowedByUser) {
    if (ActivityManager.isUserAMonkey()) {
        // Prevent a monkey from changing this
        return;
    }

    enforceManageUserOemUnlockPermission();
    enforceUserIsAdmin();

    final long token = Binder.clearCallingIdentity();
    try {
        if (!isOemUnlockAllowedByAdmin()) {
            throw new SecurityException("Admin does not allow OEM unlock");
        }

        if (!mOemLock.isOemUnlockAllowedByCarrier()) {
            throw new SecurityException("Carrier does not allow OEM unlock");
        }

        mOemLock.setOemUnlockAllowedByDevice(allowedByUser);
        setPersistentDataBlockOemUnlockAllowedBit(allowedByUser);
    } finally {
        Binder.restoreCallingIdentity(token);
    }
}
 
Example 5
Source File: DeviceAdminSample.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * If the "user" is a monkey, post an alert and notify the caller.  This prevents automated
 * test frameworks from stumbling into annoying or dangerous operations.
 */
private static boolean alertIfMonkey(Context context, int stringId) {
    if (ActivityManager.isUserAMonkey()) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setMessage(stringId);
        builder.setPositiveButton(R.string.monkey_ok, null);
        builder.show();
        return true;
    } else {
        return false;
    }
}
 
Example 6
Source File: MainActivity.java    From rebootmenu with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    new DebugLog("MainActivity.onCreate", DebugLog.LogLevel.V);
    //不支持旧版本的Android TV,理由:仅支持打开系统电源菜单意义不大
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P && SpecialSupport.isAndroidTV(this)) {
        UIUtils.visibleHint(this, R.string.hint_android_tv_error);
        startActivity(new Intent(Intent.ACTION_UNINSTALL_PACKAGE, Uri.parse("package:" + BuildConfig.APPLICATION_ID)).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
        finish();
        return;
    }
    //对于本应用的性质而言,Monkey Test没有必要,而且也容易造成测试机器电源状态改变
    if (ActivityManager.isUserAMonkey()) {
        new TextToast(this, true, getString(R.string.monkey_test_notice));
        ShellUtils.killShKillProcess("monkey");
        finish();
        return;
    }
    //配置选项
    String configView = getString(R.string.loading);
    final String PREFIX = "\n√ ";
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT)
        configView += getString(R.string.kitkat_compat);
    if (ConfigManager.get(ConfigManager.WHITE_THEME))
        configView += PREFIX + getString(R.string.r_whitetheme);
    if (ConfigManager.get(ConfigManager.CANCELABLE))
        configView += PREFIX + getString(R.string.r_cancelable);
    if (ConfigManager.get(ConfigManager.NO_NEED_TO_CONFIRM))
        configView += PREFIX + getString(R.string.r_normal_do);
    if (ConfigManager.get(ConfigManager.DO_NOT_CHECK_ROOT)) {
        configView += PREFIX + getString(R.string.r_no_root_check);
        if (ConfigManager.get(ConfigManager.UNROOT_MODE))
            configView += PREFIX + getString(R.string.r_unroot_mode);
    }
    cfgStat();
    new TextToast(this, configView);
    if (!ConfigManager.get(ConfigManager.DO_NOT_CHECK_ROOT))
        activitySwitch(ShellUtils.isRoot());
    else    //如果不检查root权限,则检查“手动免root模式”配置
        activitySwitch(!ConfigManager.get(ConfigManager.UNROOT_MODE));
}
 
Example 7
Source File: FindMonkey.java    From BlogDemo with Apache License 2.0 2 votes vote down vote up
/**
 * Check if the normal method of "isUserAMonkey"
 * returns a quick win of who the user is.
 *  
 * @return {@code true} if the user is a monkey
 * 		or {@code false} if not.
 */
public static boolean isUserAMonkey() {
	return ActivityManager.isUserAMonkey();
}