Fixed createAndManageUser() for headless system user mode.

It was refactored to split the "create" and "manage" parts so the
new user dialog is shown in the proper times, but such changed
broke the API when caller was passing initialExtras or a different
PO component.

To fix this issue, DPMS passes a token when the user is created,
and ignores the callback when the token matches.

This change also improved logging (which helped diagnose this issue).

Test: atest com.android.cts.devicepolicy.DeviceOwnerTest#testCreateAndManageUser_LowStorage,testCreateAndManageUser_MaxUsers,testCreateAndManageUser_GetSecondaryUsers,testCreateAndManageUser_SwitchUser,testCreateAndManageUser_CannotStopCurrentUser,testCreateAndManageUser_StartInBackground,testCreateAndManageUser_StartInBackground_MaxRunningUsers,testCreateAndManageUser_StopUser,testCreateAndManageUser_StopEphemeralUser_DisallowRemoveUser,testCreateAndManageUser_LogoutUser,testCreateAndManageUser_Affiliated,testCreateAndManageUser_Ephemeral,testCreateAndManageUser_LeaveAllSystemApps,testCreateAndManageUser_SkipSetupWizard,testCreateAndManageUser_AddRestrictionSet,testCreateAndManageUser_RemoveRestrictionSet,testUserAddedOrRemovedBroadcasts # on automotive and phone

Bug: 180515783

Change-Id: Ia6bddecd13fcdfc9604f40391ab7b2a5e98c146b
4 files changed