Add flag guard and fix test

Bug: 317159160
Test: atest ApplicationsStateTest
Change-Id: If10300b88f9ef6c9f16d3dfdea870304327399a5
2 files changed