• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License
15  */
16 package com.android.providers.contacts;
17 
18 import android.content.ContentValues;
19 import android.content.Context;
20 import android.database.Cursor;
21 import android.database.sqlite.SQLiteDatabase;
22 import android.provider.ContactsContract.CommonDataKinds.Identity;
23 import com.android.providers.contacts.aggregation.AbstractContactAggregator;
24 
25 /**
26  * Handler for Identity data rows.
27  */
28 public class DataRowHandlerForIdentity extends DataRowHandler {
DataRowHandlerForIdentity(Context context, ContactsDatabaseHelper dbHelper, AbstractContactAggregator aggregator)29     public DataRowHandlerForIdentity(Context context, ContactsDatabaseHelper dbHelper,
30             AbstractContactAggregator aggregator) {
31         super(context, dbHelper, aggregator, Identity.CONTENT_ITEM_TYPE);
32     }
33 
34     @Override
insert(SQLiteDatabase db, TransactionContext txContext, long rawContactId, ContentValues values)35     public long insert(SQLiteDatabase db, TransactionContext txContext, long rawContactId,
36             ContentValues values) {
37         final long dataId = super.insert(db, txContext, rawContactId, values);
38 
39         // Identity affects aggregation.
40         if (values.containsKey(Identity.IDENTITY) || values.containsKey(Identity.NAMESPACE)) {
41             triggerAggregation(txContext, rawContactId);
42         }
43 
44         return dataId;
45     }
46 
47     @Override
update(SQLiteDatabase db, TransactionContext txContext, ContentValues values, Cursor c, boolean callerIsSyncAdapter, boolean callerIsMetadataSyncAdapter)48     public boolean update(SQLiteDatabase db, TransactionContext txContext, ContentValues values,
49             Cursor c, boolean callerIsSyncAdapter, boolean callerIsMetadataSyncAdapter) {
50 
51         super.update(db, txContext, values, c, callerIsSyncAdapter, callerIsMetadataSyncAdapter);
52 
53         // Identity affects aggregation.
54         final long rawContactId = c.getLong(DataUpdateQuery.RAW_CONTACT_ID);
55         if (values.containsKey(Identity.IDENTITY) || values.containsKey(Identity.NAMESPACE)) {
56             triggerAggregation(txContext, rawContactId);
57         }
58 
59         return true;
60     }
61 
62     @Override
delete(SQLiteDatabase db, TransactionContext txContext, Cursor c)63     public int delete(SQLiteDatabase db, TransactionContext txContext, Cursor c) {
64         final int count = super.delete(db, txContext, c);
65 
66         // Identity affects aggregation.
67         final long rawContactId = c.getLong(DataUpdateQuery.RAW_CONTACT_ID);
68         triggerAggregation(txContext, rawContactId);
69 
70         return count;
71     }
72 }
73