[Settings] Code refactor

1. Adjust test case for improving testing performance
2. Some code refactor for avoiding from NullPointerException

Bug: 260540995
Test: auto and local
Change-Id: I18bd474304194137166c3c03ff828abdcd58473e
2 files changed