当前位置: 首页 > news >正文

【笔记】Android 多用户模式和用户类型

简介

用户界面:System =》Multiple Users =》 开关多用户模式。

一般是不同用户模式下,有修改Settings应用配置的权限差异,因此需要通过用户类型对功能进行判断限制。

代码

通过UserManager可以获取当前用户的信息。

frameworks/base/core/java/android/os/UserManager.java

提供多种判断当前用户类型的接口

UserManager功能接口
APIComment
getUserType()

获取当前用户类型

@return the user type of the context user.

getUserName()

获取当前用户名

Returns the user name of the context user. This call is only available to applications on the system image.

isSystemUser()

判断是否为系统用户

Used to check if the context user is the system user. The system user is the initial user that is implicitly created on first boot and hosts most of the system services.

isGuestUser()

基于上下文,判断是否为访客用户

Used to check if the context user is a guest user. A guest user may be transient.

@return whether the context user is a guest user.

isGuestUser(@UserIdInt int userId)

判断指定ID是否为访客用户

Checks if a user is a guest user.

@return whether user is a guest user.

isUserAdmin(@UserIdInt int userId)

判断指定指定id的用户是否为admin(admin可以不唯一)

返回user.isAdmin()

@hide Returns whether the provided user is an admin user. There can be more than one admin user.

源码

/*** Manages users and user details on a multi-user system. There are two major categories of* users: fully customizable users with their own login, and profiles that share a workspace* with a related user.* <p>* Users are different from accounts, which are managed by* {@link AccountManager}. Each user can have their own set of accounts.* <p>* See {@link DevicePolicyManager#ACTION_PROVISION_MANAGED_PROFILE} for more on managed profiles.*/
@SystemService(Context.USER_SERVICE)
@android.ravenwood.annotation.RavenwoodKeepPartialClass
public class UserManager {/*** @return the user type of the context user.* @hide*/@TestApi@RequiresPermission(anyOf = {android.Manifest.permission.MANAGE_USERS,android.Manifest.permission.CREATE_USERS,android.Manifest.permission.QUERY_USERS})@UserHandleAwarepublic @NonNull String getUserType() {UserInfo userInfo = getUserInfo(mUserId);return userInfo == null ? "" : userInfo.userType;}

获取用户信息的方法

代码案例:

通过系统服务获取UserManager对象,然后根据需求get信息。

   //判断是否为Owner机主  private static boolean isAdminUser(Context context) {if (context == null) return false;final UserManager userManager = context.getSystemService(UserManager.class);if (userManager == null) return false;//获取当前用户类型 Log.d(TAG, "isAdminUser: Now user is " + userManager.getUserType());return userManager.isAdminUser();}

常见用户类型

常见类型是Owner,User和Guest。

多用户模式用户类型映射关系
StringUSER_TYPE用户场景说明
USER_TYPE_FULL_SYSTEMandroid.os.usertype.full.SYSTEM

Owner,即机主,adminUser。

 User type representing a {@link UserHandle#USER_SYSTEM system} user that is a human user.
 This type of user cannot be created; it can only pre-exist on first boot.
USER_TYPE_FULL_SECONDARYandroid.os.usertype.full.SECONDARYUser,非Owner(机主)用户。User type representing a regular non-profile non-{@link UserHandle#USER_SYSTEM system} human
user.
This is sometimes called an ordinary 'secondary user'.
USER_TYPE_FULL_GUESTandroid.os.usertype.full.GUESTGuset,访客模式User type representing a guest user that may be transient.
USER_TYPE_FULL_DEMOandroid.os.usertype.full.DEMO怎么变成demo?User type representing a user for demo purposes only, which can be removed at any time.
USER_TYPE_FULL_RESTRICTEDandroid.os.usertype.full.RESTRICTED受限用户,profile是什么?User type representing a "restricted profile" user, which is a full user that is subject to
certain restrictions from a parent user. Note, however, that it is NOT technically a profile.
USER_TYPE_PROFILE_MANAGEDandroid.os.usertype.profile.MANAGEDDPC是啥?APN里面有查询

User type representing a managed profile, which is a profile that is to be managed by a
device policy controller (DPC).
The intended purpose is for work profiles, which are managed by a corporate entity.

 @FlaggedApi(android.os.Flags.FLAG_ALLOW_PRIVATE_PROFILE)

USER_TYPE_PROFILE_CLONEandroid.os.usertype.profile.CLONE克隆某用户

User type representing a clone profile. Clone profile is a user profile type used to run
second instance of an otherwise single user App (eg, messengers). Currently only the
{@link android.content.pm.UserInfo#isMain()} user can have a clone profile.

@FlaggedApi(android.os.Flags.FLAG_ALLOW_PRIVATE_PROFILE)

USER_TYPE_PROFILE_PRIVATEandroid.os.usertype.profile.PRIVATE

User type representing a private profile. Private profile is a user profile that can be used
as an alternative user-space to install and use sensitive apps.
UI surfaces can adopt an alternative strategy to show apps belonging to this profile, in line
with their sensitive nature.
 

@FlaggedApi(android.os.Flags.FLAG_ALLOW_PRIVATE_PROFILE)

USER_TYPE_PROFILE_TESTandroid.os.usertype.profile.TEST测试User type representing a generic profile for testing purposes. Only on debuggable builds.
USER_TYPE_PROFILE_COMMUNALandroid.os.usertype.profile.COMMUNAL多个用户共享一些资源而不共享敏感信息。User type representing a communal profile, which is shared by all users of the device.
public static final String USER_TYPE_FULL_SYSTEM = "android.os.usertype.full.SYSTEM";
public static final String USER_TYPE_FULL_SECONDARY = "android.os.usertype.full.SECONDARY";
public static final String USER_TYPE_FULL_GUEST = "android.os.usertype.full.GUEST";
public static final String USER_TYPE_FULL_DEMO = "android.os.usertype.full.DEMO";
public static final String USER_TYPE_FULL_RESTRICTED = "android.os.usertype.full.RESTRICTED";
public static final String USER_TYPE_PROFILE_MANAGED = "android.os.usertype.profile.MANAGED";
public static final String USER_TYPE_PROFILE_CLONE = "android.os.usertype.profile.CLONE";
public static final String USER_TYPE_PROFILE_PRIVATE = "android.os.usertype.profile.PRIVATE";
public static final String USER_TYPE_PROFILE_TEST = "android.os.usertype.profile.TEST";
public static final String USER_TYPE_PROFILE_COMMUNAL = "android.os.usertype.profile.COMMUNAL";
public static final String USER_TYPE_FULL_SYSTEM = "android.os.usertype.full.SYSTEM";
public static final String USER_TYPE_FULL_SECONDARY = "android.os.usertype.full.SECONDARY";
public static final String USER_TYPE_FULL_GUEST = "android.os.usertype.full.GUEST";
public static final String USER_TYPE_FULL_DEMO = "android.os.usertype.full.DEMO";
public static final String USER_TYPE_FULL_RESTRICTED = "android.os.usertype.full.RESTRICTED";
public static final String USER_TYPE_PROFILE_MANAGED = "android.os.usertype.profile.MANAGED";
public static final String USER_TYPE_PROFILE_CLONE = "android.os.usertype.profile.CLONE";
public static final String USER_TYPE_PROFILE_PRIVATE = "android.os.usertype.profile.PRIVATE";
public static final String USER_TYPE_PROFILE_TEST = "android.os.usertype.profile.TEST";
public static final String USER_TYPE_PROFILE_COMMUNAL = "android.os.usertype.profile.COMMUNAL";
public static final String USER_TYPE_SYSTEM_HEADLESS = "android.os.usertype.system.HEADLESS";

相关文章:

【笔记】Android 多用户模式和用户类型

简介 用户界面&#xff1a;System 》Multiple Users 》 开关多用户模式。 一般是不同用户模式下&#xff0c;有修改Settings应用配置的权限差异&#xff0c;因此需要通过用户类型对功能进行判断限制。 代码 通过UserManager可以获取当前用户的信息。 frameworks/base/core/…...

SQL基础——MySQL的索引

简介&#xff1a;个人学习分享&#xff0c;如有错误&#xff0c;欢迎批评指正。 一、概述 介绍 索引是通过某种算法&#xff0c;构建出一个数据模型&#xff0c;用于快速找出在某个列中有一特定值的行&#xff0c;不使用索引&#xff0c;MySQL必须从第一条记录开始读完整个表&…...

【开发语言】面向对象和面向过程开发思路的区别

引入&#xff1a; 我总结了 面向过程的开发语言思路&#xff1a;1.我要干啥&#xff1f;2.怎么才能实现 面向对象的开发语言思路&#xff1a;1.我要研究谁&#xff1f;2.他能干啥 详解&#xff1a; 面向过程的开发语言思路 我要干啥&#xff1f; 在面向过程的开发中&a…...

谷歌账号登录的时候提示被停用,原因是什么,账号还有救吗?该如何处理?

今日早上&#xff0c;有个久违的朋友找到我说&#xff0c;要恢复账号。 他的情况是这样的&#xff1a;7月21日的时候&#xff0c;他发现自己的谷歌账号登录的时候提示活动异常先&#xff0c;需要输入手机号码验证才能恢复账号。但是输入了自己和亲友们的多个手机号码都无法验证…...

数据库复习笔记

写在最前&#xff0c; 写文章的初衷只是为了复习与记录自己的成长&#xff0c;笔者目前水平还有待提高&#xff0c;文章中难免会出现许多问题与错误&#xff0c;文章内容仅供参考&#xff0c;有不足的地方还请大家多多包涵并指正&#xff0c;谢谢~ 第八章 T-SQL程序结构 8.…...

学习STM32(6)-- STM32单片机ADCDAC的应用

1 引 言 深入了解并掌握STM32F103单片机在模拟数字转换&#xff08;ADC&#xff09;和数字模拟转换&#xff08;DAC&#xff09;应用方面的功能和操作。学习如何配置STM32F103的ADC模块&#xff0c;实现模拟信号到数字信号的精确转换&#xff1b;同时&#xff0c;探索DAC模块…...

学习记录第二十五天

wait函数 wait函数是一个系统调用&#xff0c;用于等待一个子进程结束并回收其资源。当父进程调用wait函数时&#xff0c;它会暂停执行&#xff0c;直到至少有一个子进程结束。wait函数的原型如下&#xff1a; #include <sys/types.h> #include <sys/wait.h>pid_…...

C语言:字符串函数strcmp

该函数用于比较两个字符串是否一样。 使用方法如下&#xff1a; #include<stdio.h> #include<string.h>int main() {//strcmp函数返回值有三种情况&#xff0c;小于零时返回-1&#xff0c;等于零&#xff0c;大于零时返回1printf("%d\n", strcmp("…...

【数据分析---偏企业】 Excel操作

各位大佬好 &#xff0c;这里是阿川的博客&#xff0c;祝您变得更强 个人主页&#xff1a;在线OJ的阿川 大佬的支持和鼓励&#xff0c;将是我成长路上最大的动力 阿川水平有限&#xff0c;如有错误&#xff0c;欢迎大佬指正 Excel操作前 必看 Python 初阶 Python—语言基础与…...

Ajax-01.原生方式

<!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><title>Ajax-原生方式</title> </head> <!-…...

OpenAI GPT-2 model use with TensorFlow JS

题意&#xff1a;使用 TensorFlow JS 应用 OpenAI GPT-2 模型 问题背景&#xff1a; Is that possible to generate texts from OpenAI GPT-2 using TensorFlowJS? 是否可以使用 TensorFlowJS 生成 OpenAI GPT-2 的文本&#xff1f; If not what is the limitation, like mo…...

JVM-运行数据区(堆、栈、元空间)

文章声明&#xff1a;文章图片均来自互联网&#xff0c;因为本人画的图不够生动。 运行数据区是JVM最重要的一个区域。 运行数据区由栈、堆、元空间构成。 栈&#xff1a;程序计数器、JVM虚拟机栈&#xff0c;本地方法栈 本地方法栈&#xff1a;加载native修饰的方法&#…...

超详细!!! LVS(Linux virual server)负载均衡知识及其NAT模式、DR模式、火墙标记实验

目录 前言系统性能扩展方式集群Cluster分布式集群与分布式 四层转发与七层转发的区别 LVS&#xff08;Linux virual server&#xff09;一、LVS介绍LVS相关概念 二、LVS集群结构体系1. 负载均衡层&#xff08;Load Balancer&#xff09;2. 服务器群组层&#xff08;Server Pool…...

信息学奥赛一本通1259:【例9.3】求最长不下降序列

题目&#xff1a; 1259&#xff1a;【例9.3】求最长不下降序列 时间限制: 1000 ms 内存限制: 65536 KB 提交数:51218 通过数: 20928 Special Judge 【题目描述】 设有由n(1≤n≤200)n(1≤n≤200)个不相同的整数组成的数列&#xff0c;记为:b(1)、b(2)、……、…...

星露谷模组开发教程#3 事件

首发于Enaium的个人博客 SMAPI提供了一些事件&#xff0c;比如游戏的内容、显示、输入等事件。这些事件可以让我们在游戏中添加自己的逻辑。这一节我们就来看看如何使用这些事件。 注册一个事件 在SMAPI中&#xff0c;我们可以通过IModHelper的Events属性来注册事件。比如我们…...

C语言程序设计(初识C语言后部分)

愿天下无Bug&#xff0c;秀发常驻。 3&#xff09;函数的参数 1.实际参数&#xff08;实参&#xff09;&#xff1a; 真实传给函数的参数&#xff0c;叫实参。 实参可以是&#xff1a;常量、变量、表达式、函数等。 无论实参是何类型的量&#xff0c;在进行函数调用时&#…...

驱动基础开发

1、字符设备传统开发模板 字符设备驱动框架&#xff0c;首先我们需要去用module_init这个宏去修饰整个驱动的入口函数&#xff0c;用module_exit去修饰整个驱动的出口函数&#xff0c;然后还需要用MODULE_LICENSE用于声明模块的许可证类型。 在入口函数里面我们需要注册字符设…...

从苹果AppStore看AI开发者生态

从苹果 App Store 看 AI 开发者生态 在人工智能迅速发展的今天&#xff0c;我们不禁要问&#xff1a;未来的 AI 开发者生态将会是什么样子&#xff1f;为了回答这个问题&#xff0c;我们不妨回顾一下移动互联网时代最成功的开发者生态之一——苹果的 App Store。 通过分析 App …...

【Python学习-UI界面】PyQt5 小部件1-Label

QLabel 对象可用作显示不可编辑的文本、图像或动态GIF影片的占位符。 它还可以用作其他小部件的助记键。 标签可以显示普通文本、超链接或富文本。 1、普通文本 直接双击输入即可 2、添加超链接 选中对应Label&#xff0c;右键选择多信息文本&#xff0c;添加链接&#xff0c…...

【Linux详解】进度条实现 Linux下git 的远程上传

&#x1f4c3;个人主页&#xff1a;island1314 &#x1f525;个人专栏&#xff1a;Linux—登神长阶 ⛺️ 欢迎关注&#xff1a;&#x1f44d;点赞 &#x1f442;&#x1f3fd;留言 &#x1f60d;收藏 &#x1f49e; &#x1f49e; &#x1f49e; &#x1f680;前言 &#x…...

变量 varablie 声明- Rust 变量 let mut 声明与 C/C++ 变量声明对比分析

一、变量声明设计&#xff1a;let 与 mut 的哲学解析 Rust 采用 let 声明变量并通过 mut 显式标记可变性&#xff0c;这种设计体现了语言的核心哲学。以下是深度解析&#xff1a; 1.1 设计理念剖析 安全优先原则&#xff1a;默认不可变强制开发者明确声明意图 let x 5; …...

日语AI面试高效通关秘籍:专业解读与青柚面试智能助攻

在如今就业市场竞争日益激烈的背景下&#xff0c;越来越多的求职者将目光投向了日本及中日双语岗位。但是&#xff0c;一场日语面试往往让许多人感到步履维艰。你是否也曾因为面试官抛出的“刁钻问题”而心生畏惧&#xff1f;面对生疏的日语交流环境&#xff0c;即便提前恶补了…...

基于大模型的 UI 自动化系统

基于大模型的 UI 自动化系统 下面是一个完整的 Python 系统,利用大模型实现智能 UI 自动化,结合计算机视觉和自然语言处理技术,实现"看屏操作"的能力。 系统架构设计 #mermaid-svg-2gn2GRvh5WCP2ktF {font-family:"trebuchet ms",verdana,arial,sans-…...

C++初阶-list的底层

目录 1.std::list实现的所有代码 2.list的简单介绍 2.1实现list的类 2.2_list_iterator的实现 2.2.1_list_iterator实现的原因和好处 2.2.2_list_iterator实现 2.3_list_node的实现 2.3.1. 避免递归的模板依赖 2.3.2. 内存布局一致性 2.3.3. 类型安全的替代方案 2.3.…...

模型参数、模型存储精度、参数与显存

模型参数量衡量单位 M&#xff1a;百万&#xff08;Million&#xff09; B&#xff1a;十亿&#xff08;Billion&#xff09; 1 B 1000 M 1B 1000M 1B1000M 参数存储精度 模型参数是固定的&#xff0c;但是一个参数所表示多少字节不一定&#xff0c;需要看这个参数以什么…...

AI Agent与Agentic AI:原理、应用、挑战与未来展望

文章目录 一、引言二、AI Agent与Agentic AI的兴起2.1 技术契机与生态成熟2.2 Agent的定义与特征2.3 Agent的发展历程 三、AI Agent的核心技术栈解密3.1 感知模块代码示例&#xff1a;使用Python和OpenCV进行图像识别 3.2 认知与决策模块代码示例&#xff1a;使用OpenAI GPT-3进…...

SCAU期末笔记 - 数据分析与数据挖掘题库解析

这门怎么题库答案不全啊日 来简单学一下子来 一、选择题&#xff08;可多选&#xff09; 将原始数据进行集成、变换、维度规约、数值规约是在以下哪个步骤的任务?(C) A. 频繁模式挖掘 B.分类和预测 C.数据预处理 D.数据流挖掘 A. 频繁模式挖掘&#xff1a;专注于发现数据中…...

基于Uniapp开发HarmonyOS 5.0旅游应用技术实践

一、技术选型背景 1.跨平台优势 Uniapp采用Vue.js框架&#xff0c;支持"一次开发&#xff0c;多端部署"&#xff0c;可同步生成HarmonyOS、iOS、Android等多平台应用。 2.鸿蒙特性融合 HarmonyOS 5.0的分布式能力与原子化服务&#xff0c;为旅游应用带来&#xf…...

高等数学(下)题型笔记(八)空间解析几何与向量代数

目录 0 前言 1 向量的点乘 1.1 基本公式 1.2 例题 2 向量的叉乘 2.1 基础知识 2.2 例题 3 空间平面方程 3.1 基础知识 3.2 例题 4 空间直线方程 4.1 基础知识 4.2 例题 5 旋转曲面及其方程 5.1 基础知识 5.2 例题 6 空间曲面的法线与切平面 6.1 基础知识 6.2…...

根据万维钢·精英日课6的内容,使用AI(2025)可以参考以下方法:

根据万维钢精英日课6的内容&#xff0c;使用AI&#xff08;2025&#xff09;可以参考以下方法&#xff1a; 四个洞见 模型已经比人聪明&#xff1a;以ChatGPT o3为代表的AI非常强大&#xff0c;能运用高级理论解释道理、引用最新学术论文&#xff0c;生成对顶尖科学家都有用的…...