1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.content.pm; 18 19 import android.Manifest; 20 import android.annotation.IntDef; 21 import android.annotation.NonNull; 22 import android.annotation.Nullable; 23 import android.annotation.RequiresPermission; 24 import android.annotation.SuppressLint; 25 import android.annotation.SystemApi; 26 import android.annotation.TestApi; 27 import android.os.Parcel; 28 import android.os.Parcelable; 29 import android.util.Slog; 30 31 import com.android.internal.annotations.VisibleForTesting; 32 import com.android.modules.utils.TypedXmlPullParser; 33 import com.android.modules.utils.TypedXmlSerializer; 34 35 import org.xmlpull.v1.XmlPullParserException; 36 37 import java.io.IOException; 38 import java.io.PrintWriter; 39 import java.lang.annotation.Retention; 40 import java.lang.annotation.RetentionPolicy; 41 42 /** 43 * Class holding the properties of a user that derive mostly from its user type. 44 * 45 * @hide 46 */ 47 @SystemApi 48 public final class UserProperties implements Parcelable { 49 private static final String LOG_TAG = UserProperties.class.getSimpleName(); 50 51 // Attribute strings for reading/writing properties to/from XML. 52 private static final String ATTR_SHOW_IN_LAUNCHER = "showInLauncher"; 53 private static final String ATTR_START_WITH_PARENT = "startWithParent"; 54 private static final String ATTR_SHOW_IN_SETTINGS = "showInSettings"; 55 private static final String ATTR_SHOW_IN_QUIET_MODE = "showInQuietMode"; 56 private static final String ATTR_SHOW_IN_SHARING_SURFACES = "showInSharingSurfaces"; 57 private static final String ATTR_INHERIT_DEVICE_POLICY = "inheritDevicePolicy"; 58 private static final String ATTR_USE_PARENTS_CONTACTS = "useParentsContacts"; 59 private static final String ATTR_UPDATE_CROSS_PROFILE_INTENT_FILTERS_ON_OTA = 60 "updateCrossProfileIntentFiltersOnOTA"; 61 private static final String ATTR_CROSS_PROFILE_INTENT_FILTER_ACCESS_CONTROL = 62 "crossProfileIntentFilterAccessControl"; 63 private static final String ATTR_CROSS_PROFILE_INTENT_RESOLUTION_STRATEGY = 64 "crossProfileIntentResolutionStrategy"; 65 private static final String ATTR_MEDIA_SHARED_WITH_PARENT = 66 "mediaSharedWithParent"; 67 private static final String ATTR_CREDENTIAL_SHAREABLE_WITH_PARENT = 68 "credentialShareableWithParent"; 69 private static final String ATTR_AUTH_ALWAYS_REQUIRED_TO_DISABLE_QUIET_MODE = 70 "authAlwaysRequiredToDisableQuietMode"; 71 private static final String ATTR_DELETE_APP_WITH_PARENT = "deleteAppWithParent"; 72 private static final String ATTR_ALWAYS_VISIBLE = "alwaysVisible"; 73 private static final String ATTR_ALLOW_STOPPING_USER_WITH_DELAYED_LOCKING = 74 "allowStoppingUserWithDelayedLocking"; 75 76 private static final String ATTR_CROSS_PROFILE_CONTENT_SHARING_STRATEGY = 77 "crossProfileContentSharingStrategy"; 78 private static final String ATTR_PROFILE_API_VISIBILITY = "profileApiVisibility"; 79 private static final String ITEMS_RESTRICTED_ON_HOME_SCREEN = 80 "itemsRestrictedOnHomeScreen"; 81 /** Index values of each property (to indicate whether they are present in this object). */ 82 @IntDef(prefix = "INDEX_", value = { 83 INDEX_SHOW_IN_LAUNCHER, 84 INDEX_START_WITH_PARENT, 85 INDEX_SHOW_IN_SETTINGS, 86 INDEX_INHERIT_DEVICE_POLICY, 87 INDEX_USE_PARENTS_CONTACTS, 88 INDEX_UPDATE_CROSS_PROFILE_INTENT_FILTERS_ON_OTA, 89 INDEX_CROSS_PROFILE_INTENT_FILTER_ACCESS_CONTROL, 90 INDEX_CROSS_PROFILE_INTENT_RESOLUTION_STRATEGY, 91 INDEX_MEDIA_SHARED_WITH_PARENT, 92 INDEX_CREDENTIAL_SHAREABLE_WITH_PARENT, 93 INDEX_DELETE_APP_WITH_PARENT, 94 INDEX_ALWAYS_VISIBLE, 95 INDEX_SHOW_IN_QUIET_MODE, 96 INDEX_SHOW_IN_SHARING_SURFACES, 97 INDEX_AUTH_ALWAYS_REQUIRED_TO_DISABLE_QUIET_MODE, 98 INDEX_CROSS_PROFILE_CONTENT_SHARING_STRATEGY, 99 INDEX_ALLOW_STOPPING_USER_WITH_DELAYED_LOCKING, 100 INDEX_PROFILE_API_VISIBILITY, 101 INDEX_ITEMS_RESTRICTED_ON_HOME_SCREEN 102 }) 103 @Retention(RetentionPolicy.SOURCE) 104 private @interface PropertyIndex { 105 } 106 private static final int INDEX_SHOW_IN_LAUNCHER = 0; 107 private static final int INDEX_START_WITH_PARENT = 1; 108 private static final int INDEX_SHOW_IN_SETTINGS = 2; 109 private static final int INDEX_INHERIT_DEVICE_POLICY = 3; 110 private static final int INDEX_USE_PARENTS_CONTACTS = 4; 111 private static final int INDEX_UPDATE_CROSS_PROFILE_INTENT_FILTERS_ON_OTA = 5; 112 private static final int INDEX_CROSS_PROFILE_INTENT_FILTER_ACCESS_CONTROL = 6; 113 private static final int INDEX_CROSS_PROFILE_INTENT_RESOLUTION_STRATEGY = 7; 114 private static final int INDEX_MEDIA_SHARED_WITH_PARENT = 8; 115 private static final int INDEX_CREDENTIAL_SHAREABLE_WITH_PARENT = 9; 116 private static final int INDEX_DELETE_APP_WITH_PARENT = 10; 117 private static final int INDEX_ALWAYS_VISIBLE = 11; 118 private static final int INDEX_SHOW_IN_QUIET_MODE = 12; 119 private static final int INDEX_AUTH_ALWAYS_REQUIRED_TO_DISABLE_QUIET_MODE = 13; 120 private static final int INDEX_SHOW_IN_SHARING_SURFACES = 14; 121 private static final int INDEX_CROSS_PROFILE_CONTENT_SHARING_STRATEGY = 15; 122 private static final int INDEX_ALLOW_STOPPING_USER_WITH_DELAYED_LOCKING = 16; 123 private static final int INDEX_PROFILE_API_VISIBILITY = 17; 124 private static final int INDEX_ITEMS_RESTRICTED_ON_HOME_SCREEN = 18; 125 /** A bit set, mapping each PropertyIndex to whether it is present (1) or absent (0). */ 126 private long mPropertiesPresent = 0; 127 128 129 /** 130 * Possible values for whether or how to show this user in the Launcher. 131 * @hide 132 */ 133 @IntDef(prefix = "SHOW_IN_LAUNCHER_", value = { 134 SHOW_IN_LAUNCHER_UNKNOWN, 135 SHOW_IN_LAUNCHER_WITH_PARENT, 136 SHOW_IN_LAUNCHER_SEPARATE, 137 SHOW_IN_LAUNCHER_NO, 138 }) 139 @Retention(RetentionPolicy.SOURCE) 140 public @interface ShowInLauncher { 141 } 142 /** 143 * Indicates that the show in launcher value for this profile is unknown or unsupported. 144 * @hide 145 */ 146 @TestApi 147 @SuppressLint("UnflaggedApi") // b/306636213 148 public static final int SHOW_IN_LAUNCHER_UNKNOWN = -1; 149 /** 150 * Suggests that the launcher should show this user's apps in the main tab. 151 * That is, either this user is a full user, so its apps should be presented accordingly, or, if 152 * this user is a profile, then its apps should be shown alongside its parent's apps. 153 * @hide 154 */ 155 @TestApi 156 public static final int SHOW_IN_LAUNCHER_WITH_PARENT = 0; 157 /** 158 * Suggests that the launcher should show this user's apps, but separately from the apps of this 159 * user's parent. 160 * @hide 161 */ 162 @TestApi 163 public static final int SHOW_IN_LAUNCHER_SEPARATE = 1; 164 /** 165 * Suggests that the launcher should not show this user. 166 * @hide 167 */ 168 @TestApi 169 public static final int SHOW_IN_LAUNCHER_NO = 2; 170 171 /** 172 * Possible values for whether or how to show this user in the Settings app. 173 * @hide 174 */ 175 @IntDef(prefix = "SHOW_IN_SETTINGS_", value = { 176 SHOW_IN_SETTINGS_UNKNOWN, 177 SHOW_IN_SETTINGS_WITH_PARENT, 178 SHOW_IN_SETTINGS_SEPARATE, 179 SHOW_IN_SETTINGS_NO, 180 }) 181 @Retention(RetentionPolicy.SOURCE) 182 public @interface ShowInSettings { 183 } 184 /** 185 * Indicates that the show in settings value for this profile is unknown or unsupported. 186 * @hide 187 */ 188 @SuppressLint("UnflaggedApi") // b/306636213 189 public static final int SHOW_IN_SETTINGS_UNKNOWN = -1; 190 /** 191 * Suggests that the Settings app should show this user's apps in the main tab. 192 * That is, either this user is a full user, so its apps should be presented accordingly, or, if 193 * this user is a profile, then its apps should be shown alongside its parent's apps. 194 * @hide 195 */ 196 public static final int SHOW_IN_SETTINGS_WITH_PARENT = 0; 197 /** 198 * Suggests that the Settings app should show this user's apps, but separately from the apps of 199 * this user's parent. 200 * @hide 201 */ 202 public static final int SHOW_IN_SETTINGS_SEPARATE = 1; 203 /** 204 * Suggests that the Settings app should not show this user. 205 * @hide 206 */ 207 public static final int SHOW_IN_SETTINGS_NO = 2; 208 209 /** 210 * Possible values for whether (and from whom) to inherit select user restrictions 211 * or device policies. 212 * 213 * @hide 214 */ 215 @IntDef(prefix = "INHERIT_DEVICE_POLICY", value = { 216 INHERIT_DEVICE_POLICY_NO, 217 INHERIT_DEVICE_POLICY_FROM_PARENT, 218 }) 219 @Retention(RetentionPolicy.SOURCE) 220 public @interface InheritDevicePolicy { 221 } 222 /** 223 * Suggests that the given user profile should not inherit user restriction or device policy 224 * from any other user. This is the default value for any new user type. 225 * @hide 226 */ 227 public static final int INHERIT_DEVICE_POLICY_NO = 0; 228 /** 229 * Suggests that the given user profile should inherit select user restrictions or 230 * device policies from its parent profile. 231 * 232 *<p> All the user restrictions and device policies would be not propagated to the profile 233 * with this property value. The {@link com.android.server.devicepolicy.DevicePolicyEngine} 234 * uses this property to determine and propagate only select ones to the given profile. 235 * 236 * @hide 237 */ 238 public static final int INHERIT_DEVICE_POLICY_FROM_PARENT = 1; 239 240 /** 241 * Reference to the default user properties for this user's user type. 242 * <li>If non-null, then any absent property will use the default property from here instead. 243 * <li>If null, then any absent property indicates that the caller lacks permission to see it, 244 * so attempting to get that property will trigger a SecurityException. 245 */ 246 private final @Nullable UserProperties mDefaultProperties; 247 248 /** 249 * CrossProfileIntentFilterAccessControlLevel provides level of access for user to create/modify 250 * {@link CrossProfileIntentFilter}. Each level have value assigned, the higher the value 251 * implies higher restriction for creation/modification. 252 * CrossProfileIntentFilterAccessControlLevel allows us to protect against malicious changes in 253 * user's {@link CrossProfileIntentFilter}s, which might add/remove 254 * {@link CrossProfileIntentFilter} leading to unprecedented results. 255 * 256 * @hide 257 */ 258 @IntDef(prefix = {"CROSS_PROFILE_INTENT_FILTER_ACCESS_LEVEL_"}, value = { 259 CROSS_PROFILE_INTENT_FILTER_ACCESS_LEVEL_ALL, 260 CROSS_PROFILE_INTENT_FILTER_ACCESS_LEVEL_SYSTEM, 261 CROSS_PROFILE_INTENT_FILTER_ACCESS_LEVEL_SYSTEM_ADD_ONLY, 262 }) 263 @Retention(RetentionPolicy.SOURCE) 264 public @interface CrossProfileIntentFilterAccessControlLevel { 265 } 266 267 /** 268 * CROSS_PROFILE_INTENT_FILTER_ACCESS_LEVEL_ALL signifies that irrespective of user we would 269 * allow access (addition/modification/removal) for CrossProfileIntentFilter. 270 * This is the default access control level. 271 * 272 * @hide 273 */ 274 public static final int CROSS_PROFILE_INTENT_FILTER_ACCESS_LEVEL_ALL = 0; 275 276 /** 277 * CROSS_PROFILE_INTENT_FILTER_ACCESS_LEVEL_SYSTEM signifies that only system/root user would 278 * be able to access (addition/modification/removal) CrossProfileIntentFilter. 279 * 280 * @hide 281 */ 282 public static final int CROSS_PROFILE_INTENT_FILTER_ACCESS_LEVEL_SYSTEM = 10; 283 284 /** 285 * CROSS_PROFILE_INTENT_FILTER_ACCESS_LEVEL_SYSTEM_ADD_ONLY signifies that only system/root 286 * user would be able to add CrossProfileIntentFilter but not modify/remove. Once added, it 287 * cannot be modified or removed. 288 * 289 * @hide 290 */ 291 public static final int CROSS_PROFILE_INTENT_FILTER_ACCESS_LEVEL_SYSTEM_ADD_ONLY = 20; 292 293 /** 294 * Possible values for cross profile intent resolution strategy. 295 * 296 * @hide 297 */ 298 @IntDef(prefix = {"CROSS_PROFILE_INTENT_RESOLUTION_STRATEGY_"}, value = { 299 CROSS_PROFILE_INTENT_RESOLUTION_STRATEGY_DEFAULT, 300 CROSS_PROFILE_INTENT_RESOLUTION_STRATEGY_NO_FILTERING 301 }) 302 @Retention(RetentionPolicy.SOURCE) 303 public @interface CrossProfileIntentResolutionStrategy { 304 } 305 306 /** 307 * Signifies to use {@link DefaultCrossProfileResolver} strategy, which 308 * check if it needs to skip the initiating profile, resolves intent in target profile. 309 * {@link DefaultCrossProfileResolver} also filters the {@link ResolveInfo} after intent 310 * resolution based on their domain approval level 311 * 312 * @hide 313 */ 314 public static final int CROSS_PROFILE_INTENT_RESOLUTION_STRATEGY_DEFAULT = 0; 315 316 /** 317 * Signifies that there is no need to filter {@link ResolveInfo} after cross profile intent 318 * resolution across. This strategy is for profile acting transparent to end-user and resolves 319 * all allowed intent without giving any profile priority. 320 * 321 * @hide 322 */ 323 public static final int CROSS_PROFILE_INTENT_RESOLUTION_STRATEGY_NO_FILTERING = 1; 324 325 /** 326 * Possible values for the profile visibility when in quiet mode. This affects the profile data 327 * and apps surfacing in Settings, sharing surfaces, and file picker surfaces. It signifies 328 * whether the profile data and apps will be shown or not. 329 * 330 * @hide 331 */ 332 @Retention(RetentionPolicy.SOURCE) 333 @IntDef(prefix = "SHOW_IN_QUIET_MODE_", 334 value = { 335 SHOW_IN_QUIET_MODE_UNKNOWN, 336 SHOW_IN_QUIET_MODE_PAUSED, 337 SHOW_IN_QUIET_MODE_HIDDEN, 338 SHOW_IN_QUIET_MODE_DEFAULT, 339 } 340 ) 341 public @interface ShowInQuietMode { 342 } 343 344 /** 345 * Indicates that the show in quiet mode value for this profile is unknown. 346 */ 347 @SuppressLint("UnflaggedApi") // b/306636213 348 public static final int SHOW_IN_QUIET_MODE_UNKNOWN = -1; 349 350 /** 351 * Indicates that the profile should still be visible in quiet mode but should be shown as 352 * paused (e.g. by greying out its icons). 353 */ 354 @SuppressLint("UnflaggedApi") // b/306636213 355 public static final int SHOW_IN_QUIET_MODE_PAUSED = 0; 356 /** 357 * Indicates that the profile should not be visible when the profile is in quiet mode. 358 * For example, the profile should not be shown in tabbed views in Settings, files sharing 359 * surfaces etc when in quiet mode. 360 */ 361 @SuppressLint("UnflaggedApi") // b/306636213 362 public static final int SHOW_IN_QUIET_MODE_HIDDEN = 1; 363 /** 364 * Indicates that quiet mode should not have any effect on the profile visibility. If the 365 * profile is meant to be visible, it will remain visible and vice versa. 366 */ 367 @SuppressLint("UnflaggedApi") // b/306636213 368 public static final int SHOW_IN_QUIET_MODE_DEFAULT = 2; 369 370 /** 371 * Possible values for the profile apps visibility in sharing surfaces. This indicates the 372 * profile data and apps should be shown in separate tabs or mixed with its parent user's data 373 * and apps in sharing surfaces and file picker surfaces. 374 * 375 * @hide 376 */ 377 @Retention(RetentionPolicy.SOURCE) 378 @IntDef(prefix = "SHOW_IN_SHARING_SURFACES_", 379 value = { 380 SHOW_IN_SHARING_SURFACES_UNKNOWN, 381 SHOW_IN_SHARING_SURFACES_SEPARATE, 382 SHOW_IN_SHARING_SURFACES_WITH_PARENT, 383 SHOW_IN_SHARING_SURFACES_NO, 384 } 385 ) 386 public @interface ShowInSharingSurfaces { 387 } 388 389 /** 390 * Indicates that the show in launcher value for this profile is unknown or unsupported. 391 */ 392 @SuppressLint("UnflaggedApi") // b/306636213 393 public static final int SHOW_IN_SHARING_SURFACES_UNKNOWN = SHOW_IN_LAUNCHER_UNKNOWN; 394 395 /** 396 * Indicates that the profile data and apps should be shown in sharing surfaces intermixed with 397 * parent user's data and apps. 398 */ 399 @SuppressLint("UnflaggedApi") // b/306636213 400 public static final int SHOW_IN_SHARING_SURFACES_WITH_PARENT = SHOW_IN_LAUNCHER_WITH_PARENT; 401 402 /** 403 * Indicates that the profile data and apps should be shown in sharing surfaces separate from 404 * parent user's data and apps. 405 */ 406 @SuppressLint("UnflaggedApi") // b/306636213 407 public static final int SHOW_IN_SHARING_SURFACES_SEPARATE = SHOW_IN_LAUNCHER_SEPARATE; 408 409 /** 410 * Indicates that the profile data and apps should not be shown in sharing surfaces at all. 411 */ 412 @SuppressLint("UnflaggedApi") // b/306636213 413 public static final int SHOW_IN_SHARING_SURFACES_NO = SHOW_IN_LAUNCHER_NO; 414 /** 415 * Possible values for cross profile content sharing strategy for this profile. 416 * 417 * @hide 418 */ 419 @IntDef(prefix = {"CROSS_PROFILE_CONTENT_SHARING_"}, value = { 420 CROSS_PROFILE_CONTENT_SHARING_UNKNOWN, 421 CROSS_PROFILE_CONTENT_SHARING_NO_DELEGATION, 422 CROSS_PROFILE_CONTENT_SHARING_DELEGATE_FROM_PARENT 423 }) 424 @Retention(RetentionPolicy.SOURCE) 425 public @interface CrossProfileContentSharingStrategy { 426 } 427 428 /** 429 * Signifies that cross-profile content sharing strategy, both to and from this profile, is 430 * unknown/unsupported. 431 */ 432 @SuppressLint("UnflaggedApi") // b/306636213 433 public static final int CROSS_PROFILE_CONTENT_SHARING_UNKNOWN = -1; 434 435 /** 436 * Signifies that cross-profile content sharing strategy, both to and from this profile, should 437 * not be delegated to any other user/profile. 438 * For ex: 439 * If this property is set for a profile, content sharing applications (such as Android 440 * Sharesheet), should not delegate the decision to share content between that profile and 441 * another profile to whether content sharing is allowed between any other profile/user related 442 * to those profiles. They should instead decide, based upon whether content sharing is 443 * specifically allowed between the two profiles in question. 444 */ 445 @SuppressLint("UnflaggedApi") // b/306636213 446 public static final int CROSS_PROFILE_CONTENT_SHARING_NO_DELEGATION = 0; 447 448 /** 449 * Signifies that cross-profile content sharing strategy, both to and from this profile, should 450 * be based upon the strategy used by the parent user of the profile. 451 * For ex: 452 * If this property is set for a profile A, content sharing applications (such as Android 453 * Sharesheet), should share content between profile A and profile B, based upon whether content 454 * sharing is allowed between the parent of profile A and profile B. 455 * If it's also set for profile B, then decision should, in turn be made by considering content 456 * sharing strategy between the parents of both profiles. 457 */ 458 @SuppressLint("UnflaggedApi") // b/306636213 459 public static final int CROSS_PROFILE_CONTENT_SHARING_DELEGATE_FROM_PARENT = 1; 460 461 /** 462 * Possible values for the profile visibility in public API surfaces. This indicates whether or 463 * not the information linked to the profile (userId, package names) should not be returned in 464 * API surfaces if a user is marked as hidden. 465 * 466 * @hide 467 */ 468 @Retention(RetentionPolicy.SOURCE) 469 @IntDef(prefix = "PROFILE_API_VISIBILITY_", 470 value = { 471 PROFILE_API_VISIBILITY_UNKNOWN, 472 PROFILE_API_VISIBILITY_VISIBLE, 473 PROFILE_API_VISIBILITY_HIDDEN, 474 } 475 ) 476 public @interface ProfileApiVisibility { 477 } 478 479 /** 480 * The api visibility value for this profile user is undefined or unknown. 481 * 482 * @hide 483 */ 484 public static final int PROFILE_API_VISIBILITY_UNKNOWN = -1; 485 486 /** 487 * Indicates that information about this profile user should be shown in API surfaces. 488 * 489 * @hide 490 */ 491 public static final int PROFILE_API_VISIBILITY_VISIBLE = 0; 492 493 /** 494 * Indicates that information about this profile should be not be visible in API surfaces. 495 * 496 * @hide 497 */ 498 public static final int PROFILE_API_VISIBILITY_HIDDEN = 1; 499 500 501 /** 502 * Creates a UserProperties (intended for the SystemServer) that stores a reference to the given 503 * default properties, which it uses for any property not subsequently set. 504 * @hide 505 */ UserProperties(@onNull UserProperties defaultProperties)506 public UserProperties(@NonNull UserProperties defaultProperties) { 507 mDefaultProperties = defaultProperties; 508 mPropertiesPresent = 0; 509 } 510 511 /** 512 * Copies the given UserProperties, excluding any information that doesn't satisfy the specified 513 * permissions. 514 * Can only be used on the original version (one that won't throw on permission errors). 515 * Note that, internally, this does not perform an exact copy. 516 * @hide 517 */ 518 @SuppressLint("MissingPermission") UserProperties(UserProperties orig, boolean exposeAllFields, boolean hasManagePermission, boolean hasQueryOrManagePermission)519 public UserProperties(UserProperties orig, 520 boolean exposeAllFields, 521 boolean hasManagePermission, 522 boolean hasQueryOrManagePermission) { 523 524 if (orig.mDefaultProperties == null) { 525 throw new IllegalArgumentException("Attempting to copy a non-original UserProperties."); 526 } 527 528 this.mDefaultProperties = null; 529 530 // Insert each setter into the following hierarchy based on its permission requirements. 531 // NOTE: Copy each property using getters to ensure default values are copied if needed. 532 if (exposeAllFields) { 533 // Add items that require exposeAllFields to be true (strictest permission level). 534 setStartWithParent(orig.getStartWithParent()); 535 setInheritDevicePolicy(orig.getInheritDevicePolicy()); 536 setUpdateCrossProfileIntentFiltersOnOTA(orig.getUpdateCrossProfileIntentFiltersOnOTA()); 537 setCrossProfileIntentFilterAccessControl( 538 orig.getCrossProfileIntentFilterAccessControl()); 539 setCrossProfileIntentResolutionStrategy(orig.getCrossProfileIntentResolutionStrategy()); 540 setDeleteAppWithParent(orig.getDeleteAppWithParent()); 541 setAlwaysVisible(orig.getAlwaysVisible()); 542 setAllowStoppingUserWithDelayedLocking(orig.getAllowStoppingUserWithDelayedLocking()); 543 } 544 if (hasManagePermission) { 545 // Add items that require MANAGE_USERS or stronger. 546 setShowInSettings(orig.getShowInSettings()); 547 setUseParentsContacts(orig.getUseParentsContacts()); 548 setAuthAlwaysRequiredToDisableQuietMode( 549 orig.isAuthAlwaysRequiredToDisableQuietMode()); 550 } 551 if (hasQueryOrManagePermission) { 552 // Add items that require QUERY_USERS or stronger. 553 } 554 // Add items that have no permission requirements at all. 555 setShowInLauncher(orig.getShowInLauncher()); 556 setMediaSharedWithParent(orig.isMediaSharedWithParent()); 557 setCredentialShareableWithParent(orig.isCredentialShareableWithParent()); 558 setShowInQuietMode(orig.getShowInQuietMode()); 559 setShowInSharingSurfaces(orig.getShowInSharingSurfaces()); 560 setCrossProfileContentSharingStrategy(orig.getCrossProfileContentSharingStrategy()); 561 setProfileApiVisibility(orig.getProfileApiVisibility()); 562 setItemsRestrictedOnHomeScreen(orig.areItemsRestrictedOnHomeScreen()); 563 } 564 565 /** 566 * Indicates that the given property is being stored explicitly in this object. 567 * If false, it means that either 568 * <li>the default property for the user type should be used instead (for SystemServer callers) 569 * <li>the caller lacks permission to see this property (for all other callers) 570 */ isPresent(@ropertyIndex long index)571 private boolean isPresent(@PropertyIndex long index) { 572 return (mPropertiesPresent & (1L << index)) != 0; 573 } 574 575 /** Indicates that the given property is henceforth being explicitly stored in this object. */ setPresent(@ropertyIndex long index)576 private void setPresent(@PropertyIndex long index) { 577 mPropertiesPresent |= (1L << index); 578 } 579 580 /** @hide Returns the internal mPropertiesPresent value. Only for testing purposes. */ 581 @VisibleForTesting getPropertiesPresent()582 public long getPropertiesPresent() { 583 return mPropertiesPresent; 584 } 585 586 /** 587 * Returns whether, and how, a user should be shown in the Launcher. 588 * This is generally inapplicable for non-profile users. 589 * 590 * Possible return values include 591 * {@link #SHOW_IN_LAUNCHER_WITH_PARENT}}, 592 * {@link #SHOW_IN_LAUNCHER_SEPARATE}, 593 * and {@link #SHOW_IN_LAUNCHER_NO}. 594 * 595 * @return whether, and how, a profile should be shown in the Launcher. 596 * @hide 597 */ 598 @TestApi getShowInLauncher()599 public @ShowInLauncher int getShowInLauncher() { 600 if (isPresent(INDEX_SHOW_IN_LAUNCHER)) return mShowInLauncher; 601 if (mDefaultProperties != null) return mDefaultProperties.mShowInLauncher; 602 throw new SecurityException("You don't have permission to query showInLauncher"); 603 } 604 /** @hide */ setShowInLauncher(@howInLauncher int val)605 public void setShowInLauncher(@ShowInLauncher int val) { 606 this.mShowInLauncher = val; 607 setPresent(INDEX_SHOW_IN_LAUNCHER); 608 } 609 private @ShowInLauncher int mShowInLauncher; 610 611 /** 612 * Returns whether, and how, a user should be shown in the Settings app. 613 * This is generally inapplicable for non-profile users. 614 * 615 * Possible return values include 616 * {@link #SHOW_IN_SETTINGS_WITH_PARENT}}, 617 * {@link #SHOW_IN_SETTINGS_SEPARATE}, 618 * and {@link #SHOW_IN_SETTINGS_NO}. 619 * 620 * @return whether, and how, a profile should be shown in the Settings. 621 * @hide 622 */ 623 @RequiresPermission(Manifest.permission.MANAGE_USERS) getShowInSettings()624 public @ShowInSettings int getShowInSettings() { 625 if (isPresent(INDEX_SHOW_IN_SETTINGS)) return mShowInSettings; 626 if (mDefaultProperties != null) return mDefaultProperties.mShowInSettings; 627 throw new SecurityException("You don't have permission to query mShowInSettings"); 628 } 629 /** @hide */ setShowInSettings(@howInSettings int val)630 public void setShowInSettings(@ShowInSettings int val) { 631 this.mShowInSettings = val; 632 setPresent(INDEX_SHOW_IN_SETTINGS); 633 } 634 private @ShowInSettings int mShowInSettings; 635 636 /** 637 * Returns whether a user should be shown in the Settings and sharing surfaces depending on the 638 * {@link android.os.UserManager#requestQuietModeEnabled(boolean, android.os.UserHandle) 639 * quiet mode}. This is only applicable to profile users since the quiet mode concept is only 640 * applicable to profile users. 641 * 642 * <p> Please note that, in Settings, this property takes effect only if 643 * {@link #getShowInSettings()} does not return {@link #SHOW_IN_SETTINGS_NO}. 644 * Also note that in Sharing surfaces this property takes effect only if 645 * {@link #getShowInSharingSurfaces()} does not return {@link #SHOW_IN_SHARING_SURFACES_NO}. 646 * 647 * @return One of {@link #SHOW_IN_QUIET_MODE_HIDDEN}, 648 * {@link #SHOW_IN_QUIET_MODE_PAUSED}, or 649 * {@link #SHOW_IN_QUIET_MODE_DEFAULT} depending on whether the profile should be 650 * shown in quiet mode or not. 651 */ 652 @SuppressLint("UnflaggedApi") // b/306636213 getShowInQuietMode()653 public @ShowInQuietMode int getShowInQuietMode() { 654 // NOTE: Launcher currently does not make use of this property. 655 if (isPresent(INDEX_SHOW_IN_QUIET_MODE)) return mShowInQuietMode; 656 if (mDefaultProperties != null) return mDefaultProperties.mShowInQuietMode; 657 throw new SecurityException( 658 "You don't have permission to query ShowInQuietMode"); 659 } 660 /** @hide */ setShowInQuietMode(@howInQuietMode int showInQuietMode)661 public void setShowInQuietMode(@ShowInQuietMode int showInQuietMode) { 662 this.mShowInQuietMode = showInQuietMode; 663 setPresent(INDEX_SHOW_IN_QUIET_MODE); 664 } 665 private int mShowInQuietMode; 666 667 /** 668 * Returns whether a user's data and apps should be shown in sharing surfaces in a separate tab 669 * or mixed with the parent user's data/apps. This is only applicable to profile users. 670 * 671 * @return One of {@link #SHOW_IN_SHARING_SURFACES_NO}, 672 * {@link #SHOW_IN_SHARING_SURFACES_SEPARATE}, or 673 * {@link #SHOW_IN_SHARING_SURFACES_WITH_PARENT} depending on whether the profile 674 * should be shown separate from its parent's data, mixed with the parent's data, or 675 * not shown at all. 676 */ 677 @SuppressLint("UnflaggedApi") // b/306636213 getShowInSharingSurfaces()678 public @ShowInSharingSurfaces int getShowInSharingSurfaces() { 679 if (isPresent(INDEX_SHOW_IN_SHARING_SURFACES)) return mShowInSharingSurfaces; 680 if (mDefaultProperties != null) return mDefaultProperties.mShowInSharingSurfaces; 681 throw new SecurityException( 682 "You don't have permission to query ShowInSharingSurfaces"); 683 } 684 /** @hide */ setShowInSharingSurfaces(@howInSharingSurfaces int showInSharingSurfaces)685 public void setShowInSharingSurfaces(@ShowInSharingSurfaces int showInSharingSurfaces) { 686 this.mShowInSharingSurfaces = showInSharingSurfaces; 687 setPresent(INDEX_SHOW_IN_SHARING_SURFACES); 688 } 689 private int mShowInSharingSurfaces; 690 691 /** 692 * Returns whether a profile should be started when its parent starts (unless in quiet mode). 693 * This only applies for users that have parents (i.e. for profiles). 694 * 695 * Only available to the SYSTEM uid. 696 * @hide 697 */ getStartWithParent()698 public boolean getStartWithParent() { 699 if (isPresent(INDEX_START_WITH_PARENT)) return mStartWithParent; 700 if (mDefaultProperties != null) return mDefaultProperties.mStartWithParent; 701 throw new SecurityException("You don't have permission to query startWithParent"); 702 } 703 /** @hide */ setStartWithParent(boolean val)704 public void setStartWithParent(boolean val) { 705 this.mStartWithParent = val; 706 setPresent(INDEX_START_WITH_PARENT); 707 } 708 private boolean mStartWithParent; 709 710 /** 711 * Returns whether an app in the profile should be deleted when the same package in 712 * the parent user is being deleted. 713 * This only applies for users that have parents (i.e. for profiles). 714 * 715 * Only available to the SYSTEM uid. 716 * @hide 717 */ getDeleteAppWithParent()718 public boolean getDeleteAppWithParent() { 719 if (isPresent(INDEX_DELETE_APP_WITH_PARENT)) return mDeleteAppWithParent; 720 if (mDefaultProperties != null) return mDefaultProperties.mDeleteAppWithParent; 721 throw new SecurityException("You don't have permission to query deleteAppWithParent"); 722 } 723 /** @hide */ setDeleteAppWithParent(boolean val)724 public void setDeleteAppWithParent(boolean val) { 725 this.mDeleteAppWithParent = val; 726 setPresent(INDEX_DELETE_APP_WITH_PARENT); 727 } 728 private boolean mDeleteAppWithParent; 729 730 /** 731 * Returns whether the user should always 732 * be {@link android.os.UserManager#isUserVisible() visible}. 733 * The intended usage is for the Communal Profile, which is running and accessible at all times. 734 * 735 * Only available to the SYSTEM uid. 736 * @hide 737 */ getAlwaysVisible()738 public boolean getAlwaysVisible() { 739 if (isPresent(INDEX_ALWAYS_VISIBLE)) return mAlwaysVisible; 740 if (mDefaultProperties != null) return mDefaultProperties.mAlwaysVisible; 741 throw new SecurityException("You don't have permission to query alwaysVisible"); 742 } 743 /** @hide */ setAlwaysVisible(boolean val)744 public void setAlwaysVisible(boolean val) { 745 this.mAlwaysVisible = val; 746 setPresent(INDEX_ALWAYS_VISIBLE); 747 } 748 private boolean mAlwaysVisible; 749 750 /** 751 * Return whether, and how, select user restrictions or device policies should be inherited 752 * from other user. 753 * 754 * Possible return values include 755 * {@link #INHERIT_DEVICE_POLICY_FROM_PARENT} or {@link #INHERIT_DEVICE_POLICY_NO} 756 * 757 * Only available to the SYSTEM uid. 758 * @hide 759 */ getInheritDevicePolicy()760 public @InheritDevicePolicy int getInheritDevicePolicy() { 761 if (isPresent(INDEX_INHERIT_DEVICE_POLICY)) return mInheritDevicePolicy; 762 if (mDefaultProperties != null) return mDefaultProperties.mInheritDevicePolicy; 763 throw new SecurityException("You don't have permission to query inheritDevicePolicy"); 764 } 765 /** @hide */ setInheritDevicePolicy(@nheritDevicePolicy int val)766 public void setInheritDevicePolicy(@InheritDevicePolicy int val) { 767 this.mInheritDevicePolicy = val; 768 setPresent(INDEX_INHERIT_DEVICE_POLICY); 769 } 770 private @InheritDevicePolicy int mInheritDevicePolicy; 771 772 /** 773 * Returns whether the current user must use parent user's contacts. If true, writes to the 774 * ContactsProvider corresponding to the current user will be disabled and reads will be 775 * redirected to the parent. 776 * 777 * This only applies to users that have parents (i.e. profiles) and is used to ensure 778 * they can access contacts from the parent profile. This will be generally inapplicable for 779 * non-profile users. 780 * 781 * Please note that in case of the clone profiles, only the allow-listed apps would be allowed 782 * to access contacts across profiles and other apps will not see any contacts. 783 * TODO(b/256126819) Add link to the method returning apps allow-listed for app-cloning 784 * 785 * @return whether contacts access from an associated profile is enabled for the user 786 * @hide 787 */ 788 @RequiresPermission(Manifest.permission.MANAGE_USERS) getUseParentsContacts()789 public boolean getUseParentsContacts() { 790 if (isPresent(INDEX_USE_PARENTS_CONTACTS)) return mUseParentsContacts; 791 if (mDefaultProperties != null) return mDefaultProperties.mUseParentsContacts; 792 throw new SecurityException("You don't have permission to query useParentsContacts"); 793 } 794 /** @hide */ setUseParentsContacts(boolean val)795 public void setUseParentsContacts(boolean val) { 796 this.mUseParentsContacts = val; 797 setPresent(INDEX_USE_PARENTS_CONTACTS); 798 } 799 /** 800 * Indicates whether the current user should use parent user's contacts. 801 * If this property is set true, the user will be blocked from storing any contacts in its 802 * own contacts database and will serve all read contacts calls through the parent's contacts. 803 */ 804 private boolean mUseParentsContacts; 805 806 /** 807 * Returns true if user needs to update default 808 * {@link com.android.server.pm.CrossProfileIntentFilter} with its parents during an OTA update. 809 * 810 * Only available to the SYSTEM uid. 811 * @hide 812 */ getUpdateCrossProfileIntentFiltersOnOTA()813 public boolean getUpdateCrossProfileIntentFiltersOnOTA() { 814 if (isPresent(INDEX_UPDATE_CROSS_PROFILE_INTENT_FILTERS_ON_OTA)) { 815 return mUpdateCrossProfileIntentFiltersOnOTA; 816 } 817 if (mDefaultProperties != null) { 818 return mDefaultProperties.mUpdateCrossProfileIntentFiltersOnOTA; 819 } 820 throw new SecurityException("You don't have permission to query " 821 + "updateCrossProfileIntentFiltersOnOTA"); 822 } 823 /** @hide */ setUpdateCrossProfileIntentFiltersOnOTA(boolean val)824 public void setUpdateCrossProfileIntentFiltersOnOTA(boolean val) { 825 this.mUpdateCrossProfileIntentFiltersOnOTA = val; 826 setPresent(INDEX_UPDATE_CROSS_PROFILE_INTENT_FILTERS_ON_OTA); 827 } 828 /** 829 Indicate if {@link com.android.server.pm.CrossProfileIntentFilter}s need to be updated during 830 OTA update between user-parent 831 */ 832 private boolean mUpdateCrossProfileIntentFiltersOnOTA; 833 834 /** 835 * Returns whether a profile shares media with its parent user. 836 * This only applies for users that have parents (i.e. for profiles). 837 */ isMediaSharedWithParent()838 public boolean isMediaSharedWithParent() { 839 if (isPresent(INDEX_MEDIA_SHARED_WITH_PARENT)) return mMediaSharedWithParent; 840 if (mDefaultProperties != null) return mDefaultProperties.mMediaSharedWithParent; 841 throw new SecurityException("You don't have permission to query mediaSharedWithParent"); 842 } 843 /** @hide */ setMediaSharedWithParent(boolean val)844 public void setMediaSharedWithParent(boolean val) { 845 this.mMediaSharedWithParent = val; 846 setPresent(INDEX_MEDIA_SHARED_WITH_PARENT); 847 } 848 private boolean mMediaSharedWithParent; 849 850 /** 851 * Returns whether a profile can have shared lockscreen credential with its parent user. 852 * This only applies for users that have parents (i.e. for profiles). 853 */ isCredentialShareableWithParent()854 public boolean isCredentialShareableWithParent() { 855 if (isPresent(INDEX_CREDENTIAL_SHAREABLE_WITH_PARENT)) { 856 return mCredentialShareableWithParent; 857 } 858 if (mDefaultProperties != null) return mDefaultProperties.mCredentialShareableWithParent; 859 throw new SecurityException( 860 "You don't have permission to query credentialShareableWithParent"); 861 } 862 /** @hide */ setCredentialShareableWithParent(boolean val)863 public void setCredentialShareableWithParent(boolean val) { 864 this.mCredentialShareableWithParent = val; 865 setPresent(INDEX_CREDENTIAL_SHAREABLE_WITH_PARENT); 866 } 867 private boolean mCredentialShareableWithParent; 868 869 /** 870 * Returns whether the profile always requires user authentication to disable from quiet mode. 871 * 872 * <p> Settings this field to true will ensure that the credential confirmation activity is 873 * always shown whenever the user requests to disable quiet mode. The behavior of credential 874 * checks is not guaranteed when the property is false and may vary depending on user types. 875 * @hide 876 */ 877 @RequiresPermission(Manifest.permission.MANAGE_USERS) isAuthAlwaysRequiredToDisableQuietMode()878 public boolean isAuthAlwaysRequiredToDisableQuietMode() { 879 if (isPresent(INDEX_AUTH_ALWAYS_REQUIRED_TO_DISABLE_QUIET_MODE)) { 880 return mAuthAlwaysRequiredToDisableQuietMode; 881 } 882 if (mDefaultProperties != null) { 883 return mDefaultProperties.mAuthAlwaysRequiredToDisableQuietMode; 884 } 885 throw new SecurityException( 886 "You don't have permission to query authAlwaysRequiredToDisableQuietMode"); 887 } 888 /** @hide */ setAuthAlwaysRequiredToDisableQuietMode(boolean val)889 public void setAuthAlwaysRequiredToDisableQuietMode(boolean val) { 890 this.mAuthAlwaysRequiredToDisableQuietMode = val; 891 setPresent(INDEX_AUTH_ALWAYS_REQUIRED_TO_DISABLE_QUIET_MODE); 892 } 893 private boolean mAuthAlwaysRequiredToDisableQuietMode; 894 895 /** 896 * Returns whether a user (usually a profile) is allowed to leave the CE storage unlocked when 897 * stopped. 898 * 899 * <p> Setting this property to true will enable the user's CE storage to remain unlocked when 900 * the user is stopped using 901 * {@link com.android.server.am.ActivityManagerService#stopUserWithDelayedLocking(int, 902 * IStopUserCallback)}. 903 * 904 * <p> When this property is false, delayed locking may still be applicable at a global 905 * level for all users via the {@code config_multiuserDelayUserDataLocking}. That is, delayed 906 * locking for a user can happen if either the device configuration is set or if this property 907 * is set. When both, the config and the property value is false, the user storage is always 908 * locked when the user is stopped. 909 * 910 * Only available to the SYSTEM uid. 911 * @hide 912 */ getAllowStoppingUserWithDelayedLocking()913 public boolean getAllowStoppingUserWithDelayedLocking() { 914 if (isPresent(INDEX_ALLOW_STOPPING_USER_WITH_DELAYED_LOCKING)) { 915 return mAllowStoppingUserWithDelayedLocking; 916 } 917 if (mDefaultProperties != null) { 918 return mDefaultProperties.mAllowStoppingUserWithDelayedLocking; 919 } 920 throw new SecurityException( 921 "You don't have permission to query allowStoppingUserWithDelayedLocking"); 922 } 923 /** @hide */ setAllowStoppingUserWithDelayedLocking(boolean val)924 public void setAllowStoppingUserWithDelayedLocking(boolean val) { 925 this.mAllowStoppingUserWithDelayedLocking = val; 926 setPresent(INDEX_ALLOW_STOPPING_USER_WITH_DELAYED_LOCKING); 927 } 928 private boolean mAllowStoppingUserWithDelayedLocking; 929 930 /** 931 * Returns the user's {@link CrossProfileIntentFilterAccessControlLevel}. 932 * 933 * Only available to the SYSTEM uid. 934 * @hide 935 */ 936 public @CrossProfileIntentFilterAccessControlLevel int getCrossProfileIntentFilterAccessControl()937 getCrossProfileIntentFilterAccessControl() { 938 if (isPresent(INDEX_CROSS_PROFILE_INTENT_FILTER_ACCESS_CONTROL)) { 939 return mCrossProfileIntentFilterAccessControl; 940 } 941 if (mDefaultProperties != null) { 942 return mDefaultProperties.mCrossProfileIntentFilterAccessControl; 943 } 944 throw new SecurityException("You don't have permission to query " 945 + "crossProfileIntentFilterAccessControl"); 946 } 947 /** 948 * Sets {@link CrossProfileIntentFilterAccessControlLevel} for the user. 949 * @param val access control for user 950 * @hide 951 */ setCrossProfileIntentFilterAccessControl( @rossProfileIntentFilterAccessControlLevel int val)952 public void setCrossProfileIntentFilterAccessControl( 953 @CrossProfileIntentFilterAccessControlLevel int val) { 954 this.mCrossProfileIntentFilterAccessControl = val; 955 setPresent(INDEX_CROSS_PROFILE_INTENT_FILTER_ACCESS_CONTROL); 956 } 957 private @CrossProfileIntentFilterAccessControlLevel int mCrossProfileIntentFilterAccessControl; 958 959 /** 960 * Returns the user's {@link CrossProfileIntentResolutionStrategy}. 961 * @return user's {@link CrossProfileIntentResolutionStrategy}. 962 * 963 * Only available to the SYSTEM uid. 964 * @hide 965 */ getCrossProfileIntentResolutionStrategy()966 public @CrossProfileIntentResolutionStrategy int getCrossProfileIntentResolutionStrategy() { 967 if (isPresent(INDEX_CROSS_PROFILE_INTENT_RESOLUTION_STRATEGY)) { 968 return mCrossProfileIntentResolutionStrategy; 969 } 970 if (mDefaultProperties != null) { 971 return mDefaultProperties.mCrossProfileIntentResolutionStrategy; 972 } 973 throw new SecurityException("You don't have permission to query " 974 + "crossProfileIntentResolutionStrategy"); 975 } 976 977 /** @hide */ setCrossProfileIntentResolutionStrategy( @rossProfileIntentResolutionStrategy int val)978 public void setCrossProfileIntentResolutionStrategy( 979 @CrossProfileIntentResolutionStrategy int val) { 980 this.mCrossProfileIntentResolutionStrategy = val; 981 setPresent(INDEX_CROSS_PROFILE_INTENT_RESOLUTION_STRATEGY); 982 } 983 private @CrossProfileIntentResolutionStrategy int mCrossProfileIntentResolutionStrategy; 984 985 /** 986 * Returns the user's {@link CrossProfileContentSharingStrategy}. 987 * 988 * Content sharing applications, such as Android Sharesheet allow sharing of content 989 * (an image, for ex.) between profiles, based upon cross-profile access checks between the 990 * originating and destined profile. 991 * In some cases however, we may want another user (such as profile parent) to serve as the 992 * delegated user to be used for such checks. 993 * To effect the same, clients can fetch this property and accordingly replace the 994 * originating/destined profile by another user for cross-profile access checks. 995 * 996 * @return user's {@link CrossProfileContentSharingStrategy}. 997 */ 998 @SuppressLint("UnflaggedApi") // b/306636213 getCrossProfileContentSharingStrategy()999 public @CrossProfileContentSharingStrategy int getCrossProfileContentSharingStrategy() { 1000 if (isPresent(INDEX_CROSS_PROFILE_CONTENT_SHARING_STRATEGY)) { 1001 return mCrossProfileContentSharingStrategy; 1002 } 1003 if (mDefaultProperties != null) { 1004 return mDefaultProperties.mCrossProfileContentSharingStrategy; 1005 } 1006 throw new SecurityException("You don't have permission to query " 1007 + "crossProfileContentSharingStrategy"); 1008 } 1009 1010 /** @hide */ setCrossProfileContentSharingStrategy( @rossProfileContentSharingStrategy int val)1011 public void setCrossProfileContentSharingStrategy( 1012 @CrossProfileContentSharingStrategy int val) { 1013 this.mCrossProfileContentSharingStrategy = val; 1014 setPresent(INDEX_CROSS_PROFILE_CONTENT_SHARING_STRATEGY); 1015 } 1016 private @CrossProfileContentSharingStrategy int mCrossProfileContentSharingStrategy; 1017 1018 /** 1019 * Returns the visibility of the profile user in API surfaces. Any information linked to the 1020 * profile (userId, package names) should be hidden API surfaces if a user is marked as hidden. 1021 * 1022 * @hide 1023 */ 1024 @NonNull getProfileApiVisibility()1025 public @ProfileApiVisibility int getProfileApiVisibility() { 1026 if (isPresent(INDEX_PROFILE_API_VISIBILITY)) return mProfileApiVisibility; 1027 if (mDefaultProperties != null) return mDefaultProperties.mProfileApiVisibility; 1028 throw new SecurityException("You don't have permission to query profileApiVisibility"); 1029 } 1030 /** @hide */ 1031 @NonNull setProfileApiVisibility(@rofileApiVisibility int profileApiVisibility)1032 public void setProfileApiVisibility(@ProfileApiVisibility int profileApiVisibility) { 1033 this.mProfileApiVisibility = profileApiVisibility; 1034 setPresent(INDEX_PROFILE_API_VISIBILITY); 1035 } 1036 private @ProfileApiVisibility int mProfileApiVisibility; 1037 1038 /** 1039 * Returns whether a user (usually a profile) is allowed to have items such as Apps Pending 1040 * Installation, Widgets, Custom App Shortcuts, etc. on Launcher home screen. 1041 * 1042 * <p> For a typical user/profile, this property will be false, allowing framework APIs to 1043 * provide information about such items to Launcher(s). When set true, framework APIs will 1044 * restrict the same. 1045 * 1046 * <p> This property only restricts information about items that are accessed solely via the 1047 * Launcher home screen. Information about items such as App Icons, Deep Links, which can also 1048 * be accessed via other launcher components, such as All Apps Drawer is not restricted by this 1049 * property. 1050 * 1051 * @hide 1052 */ areItemsRestrictedOnHomeScreen()1053 public boolean areItemsRestrictedOnHomeScreen() { 1054 if (isPresent(INDEX_ITEMS_RESTRICTED_ON_HOME_SCREEN)) { 1055 return mItemsRestrictedOnHomeScreen; 1056 } 1057 if (mDefaultProperties != null) { 1058 return mDefaultProperties.mItemsRestrictedOnHomeScreen; 1059 } 1060 throw new SecurityException( 1061 "You don't have permission to query mItemsRestrictedOnHomeScreen"); 1062 } 1063 /** @hide */ setItemsRestrictedOnHomeScreen(boolean val)1064 public void setItemsRestrictedOnHomeScreen(boolean val) { 1065 this.mItemsRestrictedOnHomeScreen = val; 1066 setPresent(INDEX_ITEMS_RESTRICTED_ON_HOME_SCREEN); 1067 } 1068 private boolean mItemsRestrictedOnHomeScreen; 1069 1070 @Override toString()1071 public String toString() { 1072 StringBuilder s = new StringBuilder(); 1073 s.append("UserProperties{"); 1074 s.append("mPropertiesPresent="); s.append(Long.toBinaryString(mPropertiesPresent)); 1075 try { 1076 s.append(listPropertiesAsStringBuilder()); 1077 } catch (SecurityException e) { 1078 // Caller doesn't have permission to see all the properties. Just don't share them. 1079 } 1080 s.append("}"); 1081 return s.toString(); 1082 } 1083 listPropertiesAsStringBuilder()1084 private StringBuilder listPropertiesAsStringBuilder() { 1085 final StringBuilder s = new StringBuilder(); 1086 1087 // Please print in increasing order of PropertyIndex. 1088 s.append(", mShowInLauncher="); s.append(getShowInLauncher()); 1089 s.append(", mStartWithParent="); s.append(getStartWithParent()); 1090 s.append(", mShowInSettings="); s.append(getShowInSettings()); 1091 s.append(", mInheritDevicePolicy="); s.append(getInheritDevicePolicy()); 1092 s.append(", mUseParentsContacts="); s.append(getUseParentsContacts()); 1093 s.append(", mUpdateCrossProfileIntentFiltersOnOTA="); 1094 s.append(getUpdateCrossProfileIntentFiltersOnOTA()); 1095 s.append(", mCrossProfileIntentFilterAccessControl="); 1096 s.append(getCrossProfileIntentFilterAccessControl()); 1097 s.append(", mCrossProfileIntentResolutionStrategy="); 1098 s.append(getCrossProfileIntentResolutionStrategy()); 1099 s.append(", mMediaSharedWithParent="); s.append(isMediaSharedWithParent()); 1100 s.append(", mCredentialShareableWithParent="); s.append(isCredentialShareableWithParent()); 1101 s.append(", mAuthAlwaysRequiredToDisableQuietMode="); 1102 s.append(isAuthAlwaysRequiredToDisableQuietMode()); 1103 s.append(", mAllowStoppingUserWithDelayedLocking="); 1104 s.append(getAllowStoppingUserWithDelayedLocking()); 1105 s.append(", mDeleteAppWithParent="); s.append(getDeleteAppWithParent()); 1106 s.append(", mAlwaysVisible="); s.append(getAlwaysVisible()); 1107 s.append(", mCrossProfileContentSharingStrategy="); 1108 s.append(getCrossProfileContentSharingStrategy()); 1109 s.append(", mProfileApiVisibility="); s.append(getProfileApiVisibility()); 1110 s.append(", mItemsRestrictedOnHomeScreen="); s.append(areItemsRestrictedOnHomeScreen()); 1111 1112 return s; 1113 } 1114 1115 /** 1116 * Print the UserProperties to the given PrintWriter. 1117 * @hide 1118 */ println(PrintWriter pw, String prefix)1119 public void println(PrintWriter pw, String prefix) { 1120 // Please print in increasing order of PropertyIndex. 1121 pw.println(prefix + "UserProperties:"); 1122 pw.println(prefix + " mPropertiesPresent=" + Long.toBinaryString(mPropertiesPresent)); 1123 pw.println(prefix + " mShowInLauncher=" + getShowInLauncher()); 1124 pw.println(prefix + " mStartWithParent=" + getStartWithParent()); 1125 pw.println(prefix + " mShowInSettings=" + getShowInSettings()); 1126 pw.println(prefix + " mInheritDevicePolicy=" + getInheritDevicePolicy()); 1127 pw.println(prefix + " mUseParentsContacts=" + getUseParentsContacts()); 1128 pw.println(prefix + " mUpdateCrossProfileIntentFiltersOnOTA=" 1129 + getUpdateCrossProfileIntentFiltersOnOTA()); 1130 pw.println(prefix + " mCrossProfileIntentFilterAccessControl=" 1131 + getCrossProfileIntentFilterAccessControl()); 1132 pw.println(prefix + " mCrossProfileIntentResolutionStrategy=" 1133 + getCrossProfileIntentResolutionStrategy()); 1134 pw.println(prefix + " mMediaSharedWithParent=" + isMediaSharedWithParent()); 1135 pw.println(prefix + " mCredentialShareableWithParent=" 1136 + isCredentialShareableWithParent()); 1137 pw.println(prefix + " mAuthAlwaysRequiredToDisableQuietMode=" 1138 + isAuthAlwaysRequiredToDisableQuietMode()); 1139 pw.println(prefix + " mAllowStoppingUserWithDelayedLocking=" 1140 + getAllowStoppingUserWithDelayedLocking()); 1141 pw.println(prefix + " mDeleteAppWithParent=" + getDeleteAppWithParent()); 1142 pw.println(prefix + " mAlwaysVisible=" + getAlwaysVisible()); 1143 pw.println(prefix + " mCrossProfileContentSharingStrategy=" 1144 + getCrossProfileContentSharingStrategy()); 1145 pw.println(prefix + " mProfileApiVisibility=" + getProfileApiVisibility()); 1146 pw.println(prefix + " mItemsRestrictedOnHomeScreen=" + areItemsRestrictedOnHomeScreen()); 1147 } 1148 1149 /** 1150 * Reads in a UserProperties from an xml file, for use by the SystemServer. 1151 * 1152 * The serializer should already be inside a tag from which to read the user properties. 1153 * 1154 * @param defaultUserPropertiesReference the default UserProperties to use for this user type. 1155 * @see #writeToXml 1156 * @hide 1157 */ UserProperties( TypedXmlPullParser parser, @NonNull UserProperties defaultUserPropertiesReference)1158 public UserProperties( 1159 TypedXmlPullParser parser, 1160 @NonNull UserProperties defaultUserPropertiesReference) 1161 throws IOException, XmlPullParserException { 1162 1163 this(defaultUserPropertiesReference); 1164 updateFromXml(parser); 1165 } 1166 1167 /** 1168 * Parses the given xml file and updates this UserProperties with its data. 1169 * I.e., if a piece of data is present in the xml, it will overwrite whatever was 1170 * previously stored in this UserProperties. 1171 * @hide 1172 */ updateFromXml(TypedXmlPullParser parser)1173 public void updateFromXml(TypedXmlPullParser parser) 1174 throws IOException, XmlPullParserException { 1175 1176 final int attributeCount = parser.getAttributeCount(); 1177 for (int i = 0; i < attributeCount; i++) { 1178 final String attributeName = parser.getAttributeName(i); 1179 switch(attributeName) { 1180 case ATTR_SHOW_IN_LAUNCHER: 1181 setShowInLauncher(parser.getAttributeInt(i)); 1182 break; 1183 case ATTR_START_WITH_PARENT: 1184 setStartWithParent(parser.getAttributeBoolean(i)); 1185 break; 1186 case ATTR_SHOW_IN_SETTINGS: 1187 setShowInSettings(parser.getAttributeInt(i)); 1188 break; 1189 case ATTR_SHOW_IN_QUIET_MODE: 1190 setShowInQuietMode(parser.getAttributeInt(i)); 1191 break; 1192 case ATTR_SHOW_IN_SHARING_SURFACES: 1193 setShowInSharingSurfaces(parser.getAttributeInt(i)); 1194 break; 1195 case ATTR_INHERIT_DEVICE_POLICY: 1196 setInheritDevicePolicy(parser.getAttributeInt(i)); 1197 break; 1198 case ATTR_USE_PARENTS_CONTACTS: 1199 setUseParentsContacts(parser.getAttributeBoolean(i)); 1200 break; 1201 case ATTR_UPDATE_CROSS_PROFILE_INTENT_FILTERS_ON_OTA: 1202 setUpdateCrossProfileIntentFiltersOnOTA(parser.getAttributeBoolean(i)); 1203 break; 1204 case ATTR_CROSS_PROFILE_INTENT_FILTER_ACCESS_CONTROL: 1205 setCrossProfileIntentFilterAccessControl(parser.getAttributeInt(i)); 1206 break; 1207 case ATTR_CROSS_PROFILE_INTENT_RESOLUTION_STRATEGY: 1208 setCrossProfileIntentResolutionStrategy(parser.getAttributeInt(i)); 1209 break; 1210 case ATTR_MEDIA_SHARED_WITH_PARENT: 1211 setMediaSharedWithParent(parser.getAttributeBoolean(i)); 1212 break; 1213 case ATTR_CREDENTIAL_SHAREABLE_WITH_PARENT: 1214 setCredentialShareableWithParent(parser.getAttributeBoolean(i)); 1215 break; 1216 case ATTR_AUTH_ALWAYS_REQUIRED_TO_DISABLE_QUIET_MODE: 1217 setAuthAlwaysRequiredToDisableQuietMode(parser.getAttributeBoolean(i)); 1218 break; 1219 case ATTR_ALLOW_STOPPING_USER_WITH_DELAYED_LOCKING: 1220 setAllowStoppingUserWithDelayedLocking(parser.getAttributeBoolean(i)); 1221 break; 1222 case ATTR_DELETE_APP_WITH_PARENT: 1223 setDeleteAppWithParent(parser.getAttributeBoolean(i)); 1224 break; 1225 case ATTR_ALWAYS_VISIBLE: 1226 setAlwaysVisible(parser.getAttributeBoolean(i)); 1227 break; 1228 case ATTR_CROSS_PROFILE_CONTENT_SHARING_STRATEGY: 1229 setCrossProfileContentSharingStrategy(parser.getAttributeInt(i)); 1230 break; 1231 case ATTR_PROFILE_API_VISIBILITY: 1232 setProfileApiVisibility(parser.getAttributeInt(i)); 1233 break; 1234 case ITEMS_RESTRICTED_ON_HOME_SCREEN: 1235 setItemsRestrictedOnHomeScreen(parser.getAttributeBoolean(i)); 1236 break; 1237 default: 1238 Slog.w(LOG_TAG, "Skipping unknown property " + attributeName); 1239 } 1240 } 1241 } 1242 1243 /** 1244 * Writes the UserProperties, as used by the SystemServer, to the xml file. 1245 * 1246 * The serializer should already be inside a tag in which to write the user properties. 1247 * 1248 * @see #UserProperties(TypedXmlPullParser, UserProperties) 1249 * @hide 1250 */ writeToXml(TypedXmlSerializer serializer)1251 public void writeToXml(TypedXmlSerializer serializer) 1252 throws IOException, XmlPullParserException { 1253 1254 if (isPresent(INDEX_SHOW_IN_LAUNCHER)) { 1255 serializer.attributeInt(null, ATTR_SHOW_IN_LAUNCHER, mShowInLauncher); 1256 } 1257 if (isPresent(INDEX_START_WITH_PARENT)) { 1258 serializer.attributeBoolean(null, ATTR_START_WITH_PARENT, mStartWithParent); 1259 } 1260 if (isPresent(INDEX_SHOW_IN_SETTINGS)) { 1261 serializer.attributeInt(null, ATTR_SHOW_IN_SETTINGS, mShowInSettings); 1262 } 1263 if (isPresent(INDEX_SHOW_IN_QUIET_MODE)) { 1264 serializer.attributeInt(null, ATTR_SHOW_IN_QUIET_MODE, 1265 mShowInQuietMode); 1266 } 1267 if (isPresent(INDEX_SHOW_IN_SHARING_SURFACES)) { 1268 serializer.attributeInt(null, ATTR_SHOW_IN_SHARING_SURFACES, mShowInSharingSurfaces); 1269 } 1270 if (isPresent(INDEX_INHERIT_DEVICE_POLICY)) { 1271 serializer.attributeInt(null, ATTR_INHERIT_DEVICE_POLICY, 1272 mInheritDevicePolicy); 1273 } 1274 if (isPresent(INDEX_USE_PARENTS_CONTACTS)) { 1275 serializer.attributeBoolean(null, ATTR_USE_PARENTS_CONTACTS, 1276 mUseParentsContacts); 1277 } 1278 if (isPresent(INDEX_UPDATE_CROSS_PROFILE_INTENT_FILTERS_ON_OTA)) { 1279 serializer.attributeBoolean(null, 1280 ATTR_UPDATE_CROSS_PROFILE_INTENT_FILTERS_ON_OTA, 1281 mUpdateCrossProfileIntentFiltersOnOTA); 1282 } 1283 if (isPresent(INDEX_CROSS_PROFILE_INTENT_FILTER_ACCESS_CONTROL)) { 1284 serializer.attributeInt(null, ATTR_CROSS_PROFILE_INTENT_FILTER_ACCESS_CONTROL, 1285 mCrossProfileIntentFilterAccessControl); 1286 } 1287 if (isPresent(INDEX_CROSS_PROFILE_INTENT_RESOLUTION_STRATEGY)) { 1288 serializer.attributeInt(null, ATTR_CROSS_PROFILE_INTENT_RESOLUTION_STRATEGY, 1289 mCrossProfileIntentResolutionStrategy); 1290 } 1291 if (isPresent(INDEX_MEDIA_SHARED_WITH_PARENT)) { 1292 serializer.attributeBoolean(null, ATTR_MEDIA_SHARED_WITH_PARENT, 1293 mMediaSharedWithParent); 1294 } 1295 if (isPresent(INDEX_CREDENTIAL_SHAREABLE_WITH_PARENT)) { 1296 serializer.attributeBoolean(null, ATTR_CREDENTIAL_SHAREABLE_WITH_PARENT, 1297 mCredentialShareableWithParent); 1298 } 1299 if (isPresent(INDEX_AUTH_ALWAYS_REQUIRED_TO_DISABLE_QUIET_MODE)) { 1300 serializer.attributeBoolean(null, ATTR_AUTH_ALWAYS_REQUIRED_TO_DISABLE_QUIET_MODE, 1301 mAuthAlwaysRequiredToDisableQuietMode); 1302 } 1303 if (isPresent(INDEX_ALLOW_STOPPING_USER_WITH_DELAYED_LOCKING)) { 1304 serializer.attributeBoolean(null, ATTR_ALLOW_STOPPING_USER_WITH_DELAYED_LOCKING, 1305 mAllowStoppingUserWithDelayedLocking); 1306 } 1307 if (isPresent(INDEX_DELETE_APP_WITH_PARENT)) { 1308 serializer.attributeBoolean(null, ATTR_DELETE_APP_WITH_PARENT, 1309 mDeleteAppWithParent); 1310 } 1311 if (isPresent(INDEX_ALWAYS_VISIBLE)) { 1312 serializer.attributeBoolean(null, ATTR_ALWAYS_VISIBLE, 1313 mAlwaysVisible); 1314 } 1315 if (isPresent(INDEX_CROSS_PROFILE_CONTENT_SHARING_STRATEGY)) { 1316 serializer.attributeInt(null, ATTR_CROSS_PROFILE_CONTENT_SHARING_STRATEGY, 1317 mCrossProfileContentSharingStrategy); 1318 } 1319 if (isPresent(INDEX_PROFILE_API_VISIBILITY)) { 1320 serializer.attributeInt(null, ATTR_PROFILE_API_VISIBILITY, 1321 mProfileApiVisibility); 1322 } 1323 if (isPresent(INDEX_ITEMS_RESTRICTED_ON_HOME_SCREEN)) { 1324 serializer.attributeBoolean(null, ITEMS_RESTRICTED_ON_HOME_SCREEN, 1325 mItemsRestrictedOnHomeScreen); 1326 } 1327 } 1328 1329 // For use only with an object that has already had any permission-lacking fields stripped out. 1330 @Override writeToParcel(@onNull Parcel dest, int parcelableFlags)1331 public void writeToParcel(@NonNull Parcel dest, int parcelableFlags) { 1332 dest.writeLong(mPropertiesPresent); 1333 dest.writeInt(mShowInLauncher); 1334 dest.writeBoolean(mStartWithParent); 1335 dest.writeInt(mShowInSettings); 1336 dest.writeInt(mShowInQuietMode); 1337 dest.writeInt(mShowInSharingSurfaces); 1338 dest.writeInt(mInheritDevicePolicy); 1339 dest.writeBoolean(mUseParentsContacts); 1340 dest.writeBoolean(mUpdateCrossProfileIntentFiltersOnOTA); 1341 dest.writeInt(mCrossProfileIntentFilterAccessControl); 1342 dest.writeInt(mCrossProfileIntentResolutionStrategy); 1343 dest.writeBoolean(mMediaSharedWithParent); 1344 dest.writeBoolean(mCredentialShareableWithParent); 1345 dest.writeBoolean(mAuthAlwaysRequiredToDisableQuietMode); 1346 dest.writeBoolean(mAllowStoppingUserWithDelayedLocking); 1347 dest.writeBoolean(mDeleteAppWithParent); 1348 dest.writeBoolean(mAlwaysVisible); 1349 dest.writeInt(mCrossProfileContentSharingStrategy); 1350 dest.writeInt(mProfileApiVisibility); 1351 dest.writeBoolean(mItemsRestrictedOnHomeScreen); 1352 } 1353 1354 /** 1355 * Reads a UserProperties object from the parcel. 1356 * Not suitable for the canonical SystemServer version since it lacks mDefaultProperties. 1357 */ UserProperties(@onNull Parcel source)1358 private UserProperties(@NonNull Parcel source) { 1359 mDefaultProperties = null; 1360 1361 mPropertiesPresent = source.readLong(); 1362 mShowInLauncher = source.readInt(); 1363 mStartWithParent = source.readBoolean(); 1364 mShowInSettings = source.readInt(); 1365 mShowInQuietMode = source.readInt(); 1366 mShowInSharingSurfaces = source.readInt(); 1367 mInheritDevicePolicy = source.readInt(); 1368 mUseParentsContacts = source.readBoolean(); 1369 mUpdateCrossProfileIntentFiltersOnOTA = source.readBoolean(); 1370 mCrossProfileIntentFilterAccessControl = source.readInt(); 1371 mCrossProfileIntentResolutionStrategy = source.readInt(); 1372 mMediaSharedWithParent = source.readBoolean(); 1373 mCredentialShareableWithParent = source.readBoolean(); 1374 mAuthAlwaysRequiredToDisableQuietMode = source.readBoolean(); 1375 mAllowStoppingUserWithDelayedLocking = source.readBoolean(); 1376 mDeleteAppWithParent = source.readBoolean(); 1377 mAlwaysVisible = source.readBoolean(); 1378 mCrossProfileContentSharingStrategy = source.readInt(); 1379 mProfileApiVisibility = source.readInt(); 1380 mItemsRestrictedOnHomeScreen = source.readBoolean(); 1381 } 1382 1383 @Override describeContents()1384 public int describeContents() { 1385 return 0; 1386 } 1387 1388 public static final @android.annotation.NonNull Parcelable.Creator<UserProperties> CREATOR 1389 = new Parcelable.Creator<UserProperties>() { 1390 public UserProperties createFromParcel(Parcel source) { 1391 return new UserProperties(source); 1392 } 1393 public UserProperties[] newArray(int size) { 1394 return new UserProperties[size]; 1395 } 1396 }; 1397 1398 /** 1399 * Builder for the SystemServer's {@link UserProperties}; see that class for documentation. 1400 * Intended for building default values (and so all properties are present in the built object). 1401 * @hide 1402 */ 1403 @TestApi 1404 @SuppressLint("UnflaggedApi") // b/306636213 1405 public static final class Builder { 1406 // UserProperties fields and their default values. 1407 private @ShowInLauncher int mShowInLauncher = SHOW_IN_LAUNCHER_WITH_PARENT; 1408 private boolean mStartWithParent = false; 1409 private @ShowInSettings int mShowInSettings = SHOW_IN_SETTINGS_WITH_PARENT; 1410 private @ShowInQuietMode int mShowInQuietMode = 1411 SHOW_IN_QUIET_MODE_PAUSED; 1412 private @ShowInSharingSurfaces int mShowInSharingSurfaces = 1413 SHOW_IN_SHARING_SURFACES_SEPARATE; 1414 private @InheritDevicePolicy int mInheritDevicePolicy = INHERIT_DEVICE_POLICY_NO; 1415 private boolean mUseParentsContacts = false; 1416 private boolean mUpdateCrossProfileIntentFiltersOnOTA = false; 1417 private @CrossProfileIntentFilterAccessControlLevel int 1418 mCrossProfileIntentFilterAccessControl = 1419 CROSS_PROFILE_INTENT_FILTER_ACCESS_LEVEL_ALL; 1420 private @CrossProfileIntentResolutionStrategy int mCrossProfileIntentResolutionStrategy = 1421 CROSS_PROFILE_INTENT_RESOLUTION_STRATEGY_DEFAULT; 1422 private boolean mMediaSharedWithParent = false; 1423 private boolean mCredentialShareableWithParent = false; 1424 private boolean mAuthAlwaysRequiredToDisableQuietMode = false; 1425 private boolean mAllowStoppingUserWithDelayedLocking = false; 1426 private boolean mDeleteAppWithParent = false; 1427 private boolean mAlwaysVisible = false; 1428 private @CrossProfileContentSharingStrategy int mCrossProfileContentSharingStrategy = 1429 CROSS_PROFILE_CONTENT_SHARING_NO_DELEGATION; 1430 private @ProfileApiVisibility int mProfileApiVisibility = 0; 1431 private boolean mItemsRestrictedOnHomeScreen = false; 1432 1433 /** 1434 * @hide 1435 */ 1436 @SuppressLint("UnflaggedApi") // b/306636213 1437 @TestApi Builder()1438 public Builder() {} 1439 1440 /** @hide */ setShowInLauncher(@howInLauncher int showInLauncher)1441 public Builder setShowInLauncher(@ShowInLauncher int showInLauncher) { 1442 mShowInLauncher = showInLauncher; 1443 return this; 1444 } 1445 1446 /** @hide */ setStartWithParent(boolean startWithParent)1447 public Builder setStartWithParent(boolean startWithParent) { 1448 mStartWithParent = startWithParent; 1449 return this; 1450 } 1451 1452 /** Sets the value for {@link #mShowInSettings} 1453 * @hide 1454 */ setShowInSettings(@howInSettings int showInSettings)1455 public Builder setShowInSettings(@ShowInSettings int showInSettings) { 1456 mShowInSettings = showInSettings; 1457 return this; 1458 } 1459 1460 /** Sets the value for {@link #mShowInQuietMode} 1461 * @hide 1462 */ 1463 @TestApi 1464 @SuppressLint("UnflaggedApi") // b/306636213 1465 @NonNull setShowInQuietMode(@howInQuietMode int showInQuietMode)1466 public Builder setShowInQuietMode(@ShowInQuietMode int showInQuietMode) { 1467 mShowInQuietMode = showInQuietMode; 1468 return this; 1469 } 1470 1471 /** Sets the value for {@link #mShowInSharingSurfaces}. 1472 * @hide 1473 */ 1474 @TestApi 1475 @SuppressLint("UnflaggedApi") // b/306636213 1476 @NonNull setShowInSharingSurfaces(@howInSharingSurfaces int showInSharingSurfaces)1477 public Builder setShowInSharingSurfaces(@ShowInSharingSurfaces int showInSharingSurfaces) { 1478 mShowInSharingSurfaces = showInSharingSurfaces; 1479 return this; 1480 } 1481 1482 /** Sets the value for {@link #mInheritDevicePolicy} 1483 * @hide 1484 */ setInheritDevicePolicy( @nheritDevicePolicy int inheritRestrictionsDevicePolicy)1485 public Builder setInheritDevicePolicy( 1486 @InheritDevicePolicy int inheritRestrictionsDevicePolicy) { 1487 mInheritDevicePolicy = inheritRestrictionsDevicePolicy; 1488 return this; 1489 } 1490 1491 /** @hide */ setUseParentsContacts(boolean useParentsContacts)1492 public Builder setUseParentsContacts(boolean useParentsContacts) { 1493 mUseParentsContacts = useParentsContacts; 1494 return this; 1495 } 1496 1497 /** Sets the value for {@link #mUpdateCrossProfileIntentFiltersOnOTA} 1498 * @hide 1499 */ setUpdateCrossProfileIntentFiltersOnOTA(boolean updateCrossProfileIntentFiltersOnOTA)1500 public Builder setUpdateCrossProfileIntentFiltersOnOTA(boolean 1501 updateCrossProfileIntentFiltersOnOTA) { 1502 mUpdateCrossProfileIntentFiltersOnOTA = updateCrossProfileIntentFiltersOnOTA; 1503 return this; 1504 } 1505 1506 /** Sets the value for {@link #mCrossProfileIntentFilterAccessControl} 1507 * @hide 1508 */ setCrossProfileIntentFilterAccessControl( @rossProfileIntentFilterAccessControlLevel int crossProfileIntentFilterAccessControl)1509 public Builder setCrossProfileIntentFilterAccessControl( 1510 @CrossProfileIntentFilterAccessControlLevel int 1511 crossProfileIntentFilterAccessControl) { 1512 mCrossProfileIntentFilterAccessControl = crossProfileIntentFilterAccessControl; 1513 return this; 1514 } 1515 1516 /** Sets the value for {@link #mCrossProfileIntentResolutionStrategy} 1517 * @hide 1518 */ setCrossProfileIntentResolutionStrategy(@rossProfileIntentResolutionStrategy int crossProfileIntentResolutionStrategy)1519 public Builder setCrossProfileIntentResolutionStrategy(@CrossProfileIntentResolutionStrategy 1520 int crossProfileIntentResolutionStrategy) { 1521 mCrossProfileIntentResolutionStrategy = crossProfileIntentResolutionStrategy; 1522 return this; 1523 } 1524 1525 /** @hide */ setMediaSharedWithParent(boolean mediaSharedWithParent)1526 public Builder setMediaSharedWithParent(boolean mediaSharedWithParent) { 1527 mMediaSharedWithParent = mediaSharedWithParent; 1528 return this; 1529 } 1530 1531 /** @hide */ setCredentialShareableWithParent(boolean credentialShareableWithParent)1532 public Builder setCredentialShareableWithParent(boolean credentialShareableWithParent) { 1533 mCredentialShareableWithParent = credentialShareableWithParent; 1534 return this; 1535 } 1536 1537 /** Sets the value for {@link #mAuthAlwaysRequiredToDisableQuietMode} 1538 * @hide 1539 */ setAuthAlwaysRequiredToDisableQuietMode( boolean authAlwaysRequiredToDisableQuietMode)1540 public Builder setAuthAlwaysRequiredToDisableQuietMode( 1541 boolean authAlwaysRequiredToDisableQuietMode) { 1542 mAuthAlwaysRequiredToDisableQuietMode = 1543 authAlwaysRequiredToDisableQuietMode; 1544 return this; 1545 } 1546 1547 /** Sets the value for {@link #mAllowStoppingUserWithDelayedLocking} 1548 * @hide 1549 */ setAllowStoppingUserWithDelayedLocking( boolean allowStoppingUserWithDelayedLocking)1550 public Builder setAllowStoppingUserWithDelayedLocking( 1551 boolean allowStoppingUserWithDelayedLocking) { 1552 mAllowStoppingUserWithDelayedLocking = 1553 allowStoppingUserWithDelayedLocking; 1554 return this; 1555 } 1556 1557 /** Sets the value for {@link #mDeleteAppWithParent} 1558 * @hide 1559 */ setDeleteAppWithParent(boolean deleteAppWithParent)1560 public Builder setDeleteAppWithParent(boolean deleteAppWithParent) { 1561 mDeleteAppWithParent = deleteAppWithParent; 1562 return this; 1563 } 1564 1565 /** Sets the value for {@link #mAlwaysVisible} 1566 * @hide 1567 */ setAlwaysVisible(boolean alwaysVisible)1568 public Builder setAlwaysVisible(boolean alwaysVisible) { 1569 mAlwaysVisible = alwaysVisible; 1570 return this; 1571 } 1572 1573 /** Sets the value for {@link #mCrossProfileContentSharingStrategy} 1574 * @hide 1575 */ 1576 1577 @TestApi 1578 @SuppressLint("UnflaggedApi") // b/306636213 1579 @NonNull setCrossProfileContentSharingStrategy(@rossProfileContentSharingStrategy int crossProfileContentSharingStrategy)1580 public Builder setCrossProfileContentSharingStrategy(@CrossProfileContentSharingStrategy 1581 int crossProfileContentSharingStrategy) { 1582 mCrossProfileContentSharingStrategy = crossProfileContentSharingStrategy; 1583 return this; 1584 } 1585 1586 /** 1587 * Sets the value for {@link #mProfileApiVisibility} 1588 * @hide 1589 */ 1590 @NonNull setProfileApiVisibility(@rofileApiVisibility int profileApiVisibility)1591 public Builder setProfileApiVisibility(@ProfileApiVisibility int profileApiVisibility){ 1592 mProfileApiVisibility = profileApiVisibility; 1593 return this; 1594 } 1595 1596 /** Sets the value for {@link #mItemsRestrictedOnHomeScreen} 1597 * @hide 1598 */ setItemsRestrictedOnHomeScreen( boolean itemsRestrictedOnHomeScreen)1599 public Builder setItemsRestrictedOnHomeScreen( 1600 boolean itemsRestrictedOnHomeScreen) { 1601 mItemsRestrictedOnHomeScreen = itemsRestrictedOnHomeScreen; 1602 return this; 1603 } 1604 1605 /** Builds a UserProperties object with *all* values populated. 1606 * @hide 1607 */ 1608 @TestApi 1609 @SuppressLint("UnflaggedApi") // b/306636213 1610 @NonNull build()1611 public UserProperties build() { 1612 return new UserProperties( 1613 mShowInLauncher, 1614 mStartWithParent, 1615 mShowInSettings, 1616 mShowInQuietMode, 1617 mShowInSharingSurfaces, 1618 mInheritDevicePolicy, 1619 mUseParentsContacts, 1620 mUpdateCrossProfileIntentFiltersOnOTA, 1621 mCrossProfileIntentFilterAccessControl, 1622 mCrossProfileIntentResolutionStrategy, 1623 mMediaSharedWithParent, 1624 mCredentialShareableWithParent, 1625 mAuthAlwaysRequiredToDisableQuietMode, 1626 mAllowStoppingUserWithDelayedLocking, 1627 mDeleteAppWithParent, 1628 mAlwaysVisible, 1629 mCrossProfileContentSharingStrategy, 1630 mProfileApiVisibility, 1631 mItemsRestrictedOnHomeScreen); 1632 } 1633 } // end Builder 1634 1635 /** Creates a UserProperties with the given properties. Intended for building default values. */ UserProperties( @howInLauncher int showInLauncher, boolean startWithParent, @ShowInSettings int showInSettings, @ShowInQuietMode int showInQuietMode, @ShowInSharingSurfaces int showInSharingSurfaces, @InheritDevicePolicy int inheritDevicePolicy, boolean useParentsContacts, boolean updateCrossProfileIntentFiltersOnOTA, @CrossProfileIntentFilterAccessControlLevel int crossProfileIntentFilterAccessControl, @CrossProfileIntentResolutionStrategy int crossProfileIntentResolutionStrategy, boolean mediaSharedWithParent, boolean credentialShareableWithParent, boolean authAlwaysRequiredToDisableQuietMode, boolean allowStoppingUserWithDelayedLocking, boolean deleteAppWithParent, boolean alwaysVisible, @CrossProfileContentSharingStrategy int crossProfileContentSharingStrategy, @ProfileApiVisibility int profileApiVisibility, boolean itemsRestrictedOnHomeScreen)1636 private UserProperties( 1637 @ShowInLauncher int showInLauncher, 1638 boolean startWithParent, 1639 @ShowInSettings int showInSettings, 1640 @ShowInQuietMode int showInQuietMode, 1641 @ShowInSharingSurfaces int showInSharingSurfaces, 1642 @InheritDevicePolicy int inheritDevicePolicy, 1643 boolean useParentsContacts, boolean updateCrossProfileIntentFiltersOnOTA, 1644 @CrossProfileIntentFilterAccessControlLevel int crossProfileIntentFilterAccessControl, 1645 @CrossProfileIntentResolutionStrategy int crossProfileIntentResolutionStrategy, 1646 boolean mediaSharedWithParent, 1647 boolean credentialShareableWithParent, 1648 boolean authAlwaysRequiredToDisableQuietMode, 1649 boolean allowStoppingUserWithDelayedLocking, 1650 boolean deleteAppWithParent, 1651 boolean alwaysVisible, 1652 @CrossProfileContentSharingStrategy int crossProfileContentSharingStrategy, 1653 @ProfileApiVisibility int profileApiVisibility, 1654 boolean itemsRestrictedOnHomeScreen) { 1655 mDefaultProperties = null; 1656 setShowInLauncher(showInLauncher); 1657 setStartWithParent(startWithParent); 1658 setShowInSettings(showInSettings); 1659 setShowInQuietMode(showInQuietMode); 1660 setShowInSharingSurfaces(showInSharingSurfaces); 1661 setInheritDevicePolicy(inheritDevicePolicy); 1662 setUseParentsContacts(useParentsContacts); 1663 setUpdateCrossProfileIntentFiltersOnOTA(updateCrossProfileIntentFiltersOnOTA); 1664 setCrossProfileIntentFilterAccessControl(crossProfileIntentFilterAccessControl); 1665 setCrossProfileIntentResolutionStrategy(crossProfileIntentResolutionStrategy); 1666 setMediaSharedWithParent(mediaSharedWithParent); 1667 setCredentialShareableWithParent(credentialShareableWithParent); 1668 setAuthAlwaysRequiredToDisableQuietMode( 1669 authAlwaysRequiredToDisableQuietMode); 1670 setAllowStoppingUserWithDelayedLocking(allowStoppingUserWithDelayedLocking); 1671 setDeleteAppWithParent(deleteAppWithParent); 1672 setAlwaysVisible(alwaysVisible); 1673 setCrossProfileContentSharingStrategy(crossProfileContentSharingStrategy); 1674 setProfileApiVisibility(profileApiVisibility); 1675 setItemsRestrictedOnHomeScreen(itemsRestrictedOnHomeScreen); 1676 } 1677 } 1678