当前位置: 首页>>代码示例>>Java>>正文


Java UserManager类代码示例

本文整理汇总了Java中android.os.UserManager的典型用法代码示例。如果您正苦于以下问题:Java UserManager类的具体用法?Java UserManager怎么用?Java UserManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


UserManager类属于android.os包,在下文中一共展示了UserManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCurrentState

import android.os.UserManager; //导入依赖的package包/类
private State getCurrentState() {
    ComponentName componentName = componentName();
    DevicePolicyManager policyManager =
            (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
    if (!policyManager.isAdminActive(componentName)) {
        return State.NEEDS_PERMISSIONS;
    }
    if (!policyManager.getCameraDisabled(componentName)) {
        return State.HAS_PERMISSIONS;
    }
    if (!policyManager.isDeviceOwnerApp(BuildConfig.APPLICATION_ID)) {
        return State.CAMERA_DISABLED;
    }
    // Apparently we can't query for user restrictions, so just always set them if they're not
    // already set. We know that we're allowed to because we're the device owner.
    policyManager.addUserRestriction(componentName, UserManager.DISALLOW_ADD_USER);
    policyManager.addUserRestriction(componentName, UserManager.DISALLOW_FACTORY_RESET);
    return State.IS_DEVICE_OWNER;
}
 
开发者ID:disablecamera,项目名称:disablecamera,代码行数:20,代码来源:DisableCameraActivity.java

示例2: onResume

import android.os.UserManager; //导入依赖的package包/类
@Override
public void onResume() {
    super.onResume();
    refreshNotificationListeners();
    lookupRingtoneNames();
    updateNotificationPreferenceState();
    mSettingsObserver.register(true);
    mReceiver.register(true);
    updateRingPreference();
    updateEffectsSuppressor();
    for (VolumeSeekBarPreference volumePref : mVolumePrefs) {
        volumePref.onActivityResume();
    }
    if (mIncreasingRingVolume != null) {
        mIncreasingRingVolume.onActivityResume();
    }
    boolean isRestricted = mUserManager.hasUserRestriction(UserManager.DISALLOW_ADJUST_VOLUME);
    for (String key : RESTRICTED_KEYS) {
        Preference pref = findPreference(key);
        if (pref != null) {
            pref.setEnabled(!isRestricted);
        }
    }
}
 
开发者ID:ric96,项目名称:lineagex86,代码行数:25,代码来源:SoundSettings.java

示例3: createWorkspaceLoaderFromAppRestriction

import android.os.UserManager; //导入依赖的package包/类
/**
 * Creates workspace loader from an XML resource listed in the app restrictions.
 *
 * @return the loader if the restrictions are set and the resource exists; null otherwise.
 */
private AutoInstallsLayout createWorkspaceLoaderFromAppRestriction(AppWidgetHost widgetHost) {
    Context ctx = getContext();
    UserManager um = (UserManager) ctx.getSystemService(Context.USER_SERVICE);
    Bundle bundle = um.getApplicationRestrictions(ctx.getPackageName());
    if (bundle == null) {
        return null;
    }

    String packageName = bundle.getString(RESTRICTION_PACKAGE_NAME);
    if (packageName != null) {
        try {
            Resources targetResources = ctx.getPackageManager()
                    .getResourcesForApplication(packageName);
            return AutoInstallsLayout.get(ctx, packageName, targetResources,
                    widgetHost, mOpenHelper);
        } catch (NameNotFoundException e) {
            e.printStackTrace();
            return null;
        }
    }
    return null;
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:28,代码来源:LauncherProvider.java

示例4: getLauncherShortcuts

import android.os.UserManager; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.N_MR1)
private int getLauncherShortcuts() {
    LauncherApps launcherApps = (LauncherApps) getSystemService(LAUNCHER_APPS_SERVICE);
    if(launcherApps.hasShortcutHostPermission()) {
        UserManager userManager = (UserManager) getSystemService(USER_SERVICE);

        LauncherApps.ShortcutQuery query = new LauncherApps.ShortcutQuery();
        query.setActivity(ComponentName.unflattenFromString(componentName));
        query.setQueryFlags(LauncherApps.ShortcutQuery.FLAG_MATCH_DYNAMIC
                | LauncherApps.ShortcutQuery.FLAG_MATCH_MANIFEST
                | LauncherApps.ShortcutQuery.FLAG_MATCH_PINNED);

        shortcuts = launcherApps.getShortcuts(query, userManager.getUserForSerialNumber(userId));
        if(shortcuts != null)
            return shortcuts.size();
    }

    return 0;
}
 
开发者ID:farmerbb,项目名称:Taskbar,代码行数:20,代码来源:ContextMenuActivity.java

示例5: isRestrictedProfile

import android.os.UserManager; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public static boolean isRestrictedProfile(Context context) {
    if (Versions.preJBMR2) {
        // Early versions don't support restrictions at all
        return false;
    }

    final UserManager mgr = (UserManager) context.getSystemService(Context.USER_SERVICE);
    final Bundle restrictions = new Bundle();
    restrictions.putAll(mgr.getApplicationRestrictions(context.getPackageName()));
    restrictions.putAll(mgr.getUserRestrictions());

    for (String key : restrictions.keySet()) {
        if (restrictions.getBoolean(key)) {
            // At least one restriction is enabled -> We are a restricted profile
            return true;
        }
    }

    return false;
}
 
开发者ID:jrconlin,项目名称:mc_backup,代码行数:22,代码来源:RestrictedProfiles.java

示例6: onStartCommand

import android.os.UserManager; //导入依赖的package包/类
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    createNotificationChannel();
    startForeground();

    if (getSystemService(UserManager.class).isUserUnlocked()
            || getActiveResetPasswordToken() == null) {
        stopSelf();
        mNm.cancel(NOTIFICATION_FOREGROUND);
        return START_NOT_STICKY;
    }
    IntentFilter filter = new IntentFilter();
    filter.addAction(ACTION_USER_UNLOCKED);
    filter.addAction(ACTION_RESET_PASSWORD);
    registerReceiver(receiver, filter);

    showNotification();
    return START_REDELIVER_INTENT;
}
 
开发者ID:googlesamples,项目名称:android-testdpc,代码行数:20,代码来源:ResetPasswordService.java

示例7: getCalendars

import android.os.UserManager; //导入依赖的package包/类
private static List<CalendarInfo> getCalendars(Context context) {
    final List<CalendarInfo> calendars = new ArrayList<>();
    for (UserHandle user : UserManager.get(context).getUserProfiles()) {
        final Context userContext = getContextForUser(context, user);
        if (userContext != null) {
            addCalendars(userContext, calendars);
        }
    }
    Collections.sort(calendars, CALENDAR_NAME);
    return calendars;
}
 
开发者ID:ric96,项目名称:lineagex86,代码行数:12,代码来源:ZenModeEventRuleSettings.java

示例8: supportsDrop

import android.os.UserManager; //导入依赖的package包/类
public static boolean supportsDrop(Context context, Object info) {
    UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
    Bundle restrictions = userManager.getUserRestrictions();
    if (restrictions.getBoolean(UserManager.DISALLOW_APPS_CONTROL, false)
            || restrictions.getBoolean(UserManager.DISALLOW_UNINSTALL_APPS, false)) {
        return false;
    }

    return getUninstallTarget(context, info) != null;
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:11,代码来源:UninstallDropTarget.java

示例9: getUserLockState

import android.os.UserManager; //导入依赖的package包/类
/**
 * Check if the calling user is running in an "unlocked" state. A user is unlocked only after
 * they've entered their credentials (such as a lock pattern or PIN), and credential-encrypted
 * private app data storage is available.
 * @param context context from which {@link UserManager} should be obtained.
 * @return One of {@link LockState}.
 */
@LockState
public static int getUserLockState(final Context context) {
    if (METHOD_isUserUnlocked == null) {
        return LOCK_STATE_UNKNOWN;
    }
    final UserManager userManager = context.getSystemService(UserManager.class);
    if (userManager == null) {
        return LOCK_STATE_UNKNOWN;
    }
    final Boolean result =
            (Boolean) CompatUtils.invoke(userManager, null, METHOD_isUserUnlocked);
    if (result == null) {
        return LOCK_STATE_UNKNOWN;
    }
    return result ? LOCK_STATE_UNLOCKED : LOCK_STATE_LOCKED;
}
 
开发者ID:rkkr,项目名称:simple-keyboard,代码行数:24,代码来源:UserManagerCompatUtils.java

示例10: updateEnabledState

import android.os.UserManager; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private void updateEnabledState() {
    // This method uses AppRestrictions directly, rather than using the Policy interface,
    // because it must be callable in contexts in which the native library hasn't been
    // loaded. It will always be called from a background thread (except possibly in tests)
    // so can get the App Restrictions synchronously.
    UserManager userManager = (UserManager) getContext().getSystemService(Context.USER_SERVICE);
    Bundle appRestrictions = userManager
            .getApplicationRestrictions(getContext().getPackageName());
    setEnabled(appRestrictions.getBoolean(SUPERVISED_USER_CONTENT_PROVIDER_ENABLED));
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:12,代码来源:SupervisedUserContentProvider.java

示例11: supportsDrop

import android.os.UserManager; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public static boolean supportsDrop(Context context, Object info) {
    if (Utilities.ATLEAST_JB_MR2) {
        UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
        Bundle restrictions = userManager.getUserRestrictions();
        if (restrictions.getBoolean(UserManager.DISALLOW_APPS_CONTROL, false)
                || restrictions.getBoolean(UserManager.DISALLOW_UNINSTALL_APPS, false)) {
            return false;
        }
    }

    Pair<ComponentName, Integer> componentInfo = getAppInfoFlags(info);
    return componentInfo != null && (componentInfo.second & AppInfo.DOWNLOADED_FLAG) != 0;
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:15,代码来源:UninstallDropTarget.java

示例12: createWorkspaceLoaderFromAppRestriction

import android.os.UserManager; //导入依赖的package包/类
/**
 * Creates workspace loader from an XML resource listed in the app restrictions.
 *
 * @return the loader if the restrictions are set and the resource exists; null otherwise.
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private AutoInstallsLayout createWorkspaceLoaderFromAppRestriction(AppWidgetHost widgetHost) {
    // UserManager.getApplicationRestrictions() requires minSdkVersion >= 18
    if (!Utilities.ATLEAST_JB_MR2) {
        return null;
    }

    Context ctx = getContext();
    UserManager um = (UserManager) ctx.getSystemService(Context.USER_SERVICE);
    Bundle bundle = um.getApplicationRestrictions(ctx.getPackageName());
    if (bundle == null) {
        return null;
    }

    String packageName = bundle.getString(RESTRICTION_PACKAGE_NAME);
    if (packageName != null) {
        try {
            Resources targetResources = ctx.getPackageManager()
                    .getResourcesForApplication(packageName);
            return AutoInstallsLayout.get(ctx, packageName, targetResources,
                    widgetHost, mOpenHelper);
        } catch (NameNotFoundException e) {
            Log.e(TAG, "Target package for restricted profile not found", e);
            return null;
        }
    }
    return null;
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:34,代码来源:LauncherProvider.java

示例13: getAppRestrictions

import android.os.UserManager; //导入依赖的package包/类
private void getAppRestrictions(){
  RestrictionsManager restrictionsManager =
          (RestrictionsManager) this
                  .getSystemService(Context.RESTRICTIONS_SERVICE);

  Bundle appRestrictions = restrictionsManager.getApplicationRestrictions();

  // Block user if KEY_RESTRICTIONS_PENDING is true, and save login hint if available
  if(!appRestrictions.isEmpty()){
    if(appRestrictions.getBoolean(UserManager.
            KEY_RESTRICTIONS_PENDING)!=true){
      mLoginHint = appRestrictions.getString(LOGIN_HINT);
    }
    else {
      Toast.makeText(this,R.string.restrictions_pending_block_user,
              Toast.LENGTH_LONG).show();
      finish();
    }
  }
}
 
开发者ID:googlecodelabs,项目名称:appauth-android-codelab,代码行数:21,代码来源:MainActivity.java

示例14: fixLeakInGetMethod

import android.os.UserManager; //导入依赖的package包/类
/**
 * Dirty fix, since the UserManager.get() method is marked as hidden and can't be
 * accessed directly, the current solution it's to use reflection to invoke the get method.
 *
 * @param app - the Application instance where UserManager.get() will be triggered
 */
@TargetApi(17)
public static void fixLeakInGetMethod(Application app) {
    try {
        final Method m = UserManager.class.getMethod(GET_METHOD, Context.class);
        m.setAccessible(true);
        m.invoke(null, app);

        //above is reflection for below...
        //UserManager.get();
    } catch (Throwable e) {
        Log.e(TAG, e.getLocalizedMessage(), e.getCause());
    }
}
 
开发者ID:BlackBoxVision,项目名称:mvp-helpers,代码行数:20,代码来源:UserManagerLeaks.java

示例15: launchAndroidForWork

import android.os.UserManager; //导入依赖的package包/类
private static void launchAndroidForWork(Context context, ComponentName componentName, Bundle bundle, long userId) {
    UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
    LauncherApps launcherApps = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE);

    try {
        launcherApps.startMainActivity(componentName, userManager.getUserForSerialNumber(userId), null, bundle);
    } catch (ActivityNotFoundException | NullPointerException e) { /* Gracefully fail */ }
}
 
开发者ID:farmerbb,项目名称:Taskbar,代码行数:9,代码来源:U.java


注:本文中的android.os.UserManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。