Fix some issues about AMS creation in tests.

In commit ce8db89ce529343262f7f4c669dd2d8976afcff6 we fixed a mem leak
issue caused by thread leak. That makes some tests using the constructor
in question crash. Therefore instead of trying to restore the original
state, convert these tests to use another constructor to avoid the mem
leak.

Also fixed another NPE when getting resources from null context and null
UiHandler for some of these tests.

Bug: 138840116
Test: atest FrameworksServicesTests:ActivityManagerServiceTest
Test: atest FrameworksServicesTests:ActivityManagerInternalTest
Test: atest FrameworksServicesTests:CoreSettingsObserverTest doesn't
fail for these reasons.
Test: atest FrameworksMockingServicesTests:AppCompactorTest
Test: atest FrameworksServicesTests:AppErrorDialogTest
Change-Id: Id349a3e1100faa5b4f5033d94c0f892d3f3745bf
7 files changed