android新建用户删除app

一、android Q

1.创建用户
newUserInfo = userManager.createUser(addingUserName, 0);
为新用户添加app(app主用或其他户已安装)
iPackageManager.installExistingPackageAsUser(packageName, userHandle.getIdentifier(),0,PackageManager.INSTALL_REASON_UNKNOWN, null);
为新用户删除app(app主用或其他户已安装)
iPackageManager.deletePackageAsUser(packageName, PackageManager.VERSION_CODE_HIGHEST, null, userHandle.getIdentifier(),PackageManager.DELETE_SYSTEM_APP);
2.framework中为新用户屏蔽app
private UserInfo createUserInternalUnchecked(String name, int flags, int parentId,
String[] disallowedPackages) {
String restriction = ((flags & UserInfo.FLAG_MANAGED_PROFILE) != 0)
? UserManager.DISALLOW_ADD_MANAGED_PROFILE
: UserManager.DISALLOW_ADD_USER;
if (hasUserRestriction(restriction, UserHandle.getCallingUserId())) {
Log.w(LOG_TAG, “Cannot add user. " + restriction + " is enabled.”);
return null;
}
//Add by max start
int nums = 0;
if (null != disallowedPackages) {
nums == disallowedPackages.length;
}
String [] addDisableallowPackages = {"com.android.xxxx’};
String [] mDisableallowPackages = new String[nums + addDisableallowPackages.length];
if (nums > 0) {
int i = 0;
for (String s : disallowedPackages) {
mDisableallowPackages[i] = s;
}
for (String s : addDisableallowPackages ) {
mDisableallowPackages[i] = s;
}
disallowedPackages = mDisableallowPackages
} else {
disallowedPackages = addDisableallowPackages;
}
//Add by max end

}

二、android R

1.data/etc/preinstalled-packages-platform.xml

106 107 108 109 110 111 112 113 添加要在其它用户不安装的包名 114

详情https://source.android.google.cn/devices/tech/config/preinstalled-packages

2.在/frameworks/base/services/core/java/com/android/server/pm/UserManagerService.java
3365 private UserInfo createUserInternalUncheckedNoTracing(@Nullable String name,
3366 @NonNull String userType, @UserInfoFlag int flags, @UserIdInt int parentId,
3367 boolean preCreate, @Nullable String[] disallowedPackages,
3368 @NonNull TimingsTraceAndSlog t) throws UserManager.CheckedUserOperationException {

3528 final Set userTypeInstallablePackages =
3529 mSystemPackageInstaller.getInstallablePackagesForUserType(userType);
//添加
userTypeInstallablePackages .remove(“com.android.xxxx”);

你可能感兴趣的:(android,android)