• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.android.providers.telephony;
2 
3 import android.content.ContentValues;
4 import android.database.Cursor;
5 import android.database.MatrixCursor;
6 import android.database.sqlite.SQLiteDatabase;
7 import android.database.sqlite.SQLiteOpenHelper;
8 import android.provider.BaseColumns;
9 import android.provider.Telephony;
10 
11 public class RcsProviderCanonicalAddressHelper {
12     SQLiteOpenHelper mSQLiteOpenHelper;
13 
RcsProviderCanonicalAddressHelper(SQLiteOpenHelper sqLiteOpenHelper)14     RcsProviderCanonicalAddressHelper(SQLiteOpenHelper sqLiteOpenHelper) {
15         mSQLiteOpenHelper = sqLiteOpenHelper;
16     }
17 
getOrCreateCanonicalAddress(String canonicalAddress)18     Cursor getOrCreateCanonicalAddress(String canonicalAddress) {
19         SQLiteDatabase db = mSQLiteOpenHelper.getReadableDatabase();
20 
21         Cursor cursor = db.query(
22                 MmsSmsProvider.TABLE_CANONICAL_ADDRESSES,
23                 new String[]{BaseColumns._ID}, Telephony.CanonicalAddressesColumns.ADDRESS + "=?",
24                 new String[]{canonicalAddress}, null, null, null);
25 
26         if (cursor != null && cursor.getCount() > 0) {
27             return cursor;
28         }
29 
30         if (cursor != null) {
31             cursor.close();
32         }
33 
34         return insertCanonicalAddress(canonicalAddress);
35     }
36 
insertCanonicalAddress(String canonicalAddress)37     private Cursor insertCanonicalAddress(String canonicalAddress) {
38         ContentValues contentValues = new ContentValues();
39         contentValues.put(Telephony.CanonicalAddressesColumns.ADDRESS, canonicalAddress);
40 
41         SQLiteDatabase db = mSQLiteOpenHelper.getWritableDatabase();
42 
43         long id = db.insert(MmsSmsProvider.TABLE_CANONICAL_ADDRESSES, null, contentValues);
44 
45         if (id == -1) {
46             return null;
47         }
48 
49         MatrixCursor matrixCursor = new MatrixCursor(new String[]{BaseColumns._ID}, 1);
50         matrixCursor.addRow(new Object[]{id});
51 
52         return matrixCursor;
53     }
54 }
55