summaryrefslogtreecommitdiffstats
path: root/src/com/android/messaging/util/BlacklistSync.java
diff options
context:
space:
mode:
authorgkipnis <gkipnis@cyngn.com>2015-11-13 15:03:34 -0800
committerGerrit Code Review <gerrit@cyanogenmod.org>2015-12-08 14:52:47 -0800
commitdbcecc682dcde13911e8373056d933762e8aefca (patch)
tree87e17b44fb5d868ffffb43b7a0cc454eab5907da /src/com/android/messaging/util/BlacklistSync.java
parent3d4deaf5320efb43600e2f5fff783f07b9f244b4 (diff)
downloadandroid_packages_apps_Messaging-dbcecc682dcde13911e8373056d933762e8aefca.tar.gz
android_packages_apps_Messaging-dbcecc682dcde13911e8373056d933762e8aefca.tar.bz2
android_packages_apps_Messaging-dbcecc682dcde13911e8373056d933762e8aefca.zip
Added local blacklist and framework blacklist database synchronization
Local blacklist DB acts as a WriteThrough cache of the FW blacklist DB. 1. At the App startup time, the local DB is initialized with FW DB values. 2. A ContentObserver is registered to monitor FW Blacklist DB 3. Updates to local DB are also passed to the FW DB Change-Id: I56e1965884c383782710c90563940d75a17a7264
Diffstat (limited to 'src/com/android/messaging/util/BlacklistSync.java')
-rw-r--r--src/com/android/messaging/util/BlacklistSync.java90
1 files changed, 90 insertions, 0 deletions
diff --git a/src/com/android/messaging/util/BlacklistSync.java b/src/com/android/messaging/util/BlacklistSync.java
new file mode 100644
index 0000000..9cc611e
--- /dev/null
+++ b/src/com/android/messaging/util/BlacklistSync.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2015 The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.messaging.util;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.database.Cursor;
+import android.net.Uri;
+import android.os.AsyncTask;
+import android.telephony.PhoneNumberUtils;
+import android.telephony.TelephonyManager;
+import android.text.format.Time;
+import android.util.Log;
+import com.android.messaging.datamodel.BugleDatabaseOperations;
+import com.android.messaging.datamodel.DataModel;
+import com.android.messaging.datamodel.DatabaseWrapper;
+import com.android.messaging.datamodel.data.ParticipantData;
+import com.android.messaging.util.LogUtil;
+
+public class BlacklistSync extends AsyncTask<Void, Void, Void> {
+ private Context mContext;
+
+ private static final String TAG = BlacklistSync.class.getSimpleName();
+
+ public BlacklistSync(Context context) {
+ mContext = context;
+
+ }
+
+ @Override
+ protected Void doInBackground(Void... params) {
+ // TODO - need to extract URI from TelephonyProvider
+ Uri CONTENT_URI = Uri.parse("content://blacklist");
+ Cursor cursor;
+
+ // need to update local blacklist database - we are simply overwriting the
+ // local database with the framework database - the local database is used
+ // as a WriteThrough Cache of the Framework Database
+ cursor = mContext.getContentResolver().query(CONTENT_URI, null, null, null, null);
+ if (cursor != null && cursor.getCount() > 0) {
+ int normalizedNumberIndex = cursor.getColumnIndex("normalized_number");
+ int blockedIndex = cursor.getColumnIndex("message");
+ int updateCount;
+ if (normalizedNumberIndex < 0 || blockedIndex < 0) {
+ cursor.close();
+ return null;
+ }
+
+ DatabaseWrapper db = DataModel.get().getDatabase();
+
+ while(cursor.moveToNext()) {
+ String number = cursor.getString(normalizedNumberIndex);
+ String blocked = cursor.getString(blockedIndex);
+ boolean isBlocked = blocked.compareTo("1") == 0;
+ updateCount = BugleDatabaseOperations.updateDestination(db, number, isBlocked,
+ false);
+ if (updateCount == 0) {
+ // there was no phone number in the local participants database that was
+ // blacklisted in the framework blacklist database, create a new participant
+ // and insert him into the local participants database
+ ParticipantData participant = ParticipantData
+ .getFromRawPhoneBySystemLocale(number);
+ BugleDatabaseOperations.getOrCreateParticipantInTransaction(db,
+ participant);
+ BugleDatabaseOperations.updateDestination(db, number,
+ isBlocked, false);
+ }
+ }
+ }
+ if (cursor != null) {
+ cursor.close();
+ }
+
+ return null;
+ }
+}