Refactor Preferences code to allow better reuse.

Break up getPreferences into smaller subfunctions to
allow for reuse.

Change-Id: Idd33bab61b3ef5a262fee9361105f1c5d8024044
Merge "Refactor Preferences code to allow better reuse."