[RESTRICT AUTOMERGE] Protect Context#startService from BackgroundServiceStartNotAllowedException

We wrap the Context#startService calls in a try-catch block to avoid
the possibility of an exception due to background start. This can
happen if the activity is started when the screen is locked.

No need to add a try-catch block to Context#stopService, because
according to the documentation, if the service was not started,
nothing will happen (it won't throw anything).

Test: manually provisioned to work and device owner during and after
setup wizard with and without a background process limit
Fixes: 197412962

Change-Id: I5335b9f0e774fd950a091e98d144f546a7610dd8
(cherry picked from commit 233976ff2177a96f9e149a0d82ebc2e4d1bd5a92)
2 files changed