Save app toggle state as soon as possible

Delaying applying the states till onPause() sometimes results in the apps
disappearing slowly as the new user is booting up, causing failed queued up
broadcasts that result in crash dialogs. This happens mainly when the user
switch is initiated via QuickSettings->LockScreen->Switch while the App
restrictions screen is still showing. The onPause() gets called when
SetupWizard actually takes focus, which is quite late, as boot completed
and other events have already been queued.

Apply the initial toggles right away and apply any user changes when primary
is going to background, or onPause(), whichever comes first.

Bug: 8685927

Also ensure that apps with restrictions get a chance to persist their defaults
as soon as they are toggled on. The user may never actually click on the settings
icon for the app (which was the only way they were getting persisted before).

Some new strings for an upcoming change.

Change-Id: I96f453d066a91c6b15eafe9a6ce3f42d98bf5e33
2 files changed