Implement UPSERT for VoicemailStatusTable#insert

When putting data into the voicemail status table we used to have 2
separate database operations:
1) check if the index exists
2) insert into the database if not exist, or update if exists.
This is a potential race condition if 2 threads try to write at the
same time, pointed out in ag/838999

This CL solve it by changing the semantic of INSERT to "UPSERT",
"Update or insert", which is a single database operation of
"insert into the database if not exist, or update if exists"

SQLite does not directly support UPSERT, and doing so in a single
query is complicated. Instead insert, query, update, and delete in
VoicemailStatusTable is changed to be synchronized with a singleton, so there can only
be one thread doing a set of operations on the table at once.

Large traffic on VoicemailStatusTable is unlikely so the synchronization
cost is acceptable.

Bug:26451384
Change-Id: I6c03bd2720cbb05738cb3059fd19d65156244e20
2 files changed