add preferences API and test code