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 24 import com.android.providers.contacts.aggregation.ContactAggregator; 25 26 /** 27 * Handler for Identity data rows. 28 */ 29 public class DataRowHandlerForIdentity extends DataRowHandler { 30 public DataRowHandlerForIdentity( 31 Context context, ContactsDatabaseHelper dbHelper, ContactAggregator aggregator) { 32 super(context, dbHelper, aggregator, Identity.CONTENT_ITEM_TYPE); 33 } 34 35 @Override 36 public long insert(SQLiteDatabase db, TransactionContext txContext, long rawContactId, 37 ContentValues values) { 38 final long dataId = super.insert(db, txContext, rawContactId, values); 39 40 // Identity affects aggregation. 41 if (values.containsKey(Identity.IDENTITY) || values.containsKey(Identity.NAMESPACE)) { 42 triggerAggregation(txContext, rawContactId); 43 } 44 45 return dataId; 46 } 47 48 @Override 49 public boolean update(SQLiteDatabase db, TransactionContext txContext, ContentValues values, 50 Cursor c, boolean callerIsSyncAdapter) { 51 52 super.update(db, txContext, values, c, callerIsSyncAdapter); 53 54 // Identity affects aggregation. 55 final long rawContactId = c.getLong(DataUpdateQuery.RAW_CONTACT_ID); 56 if (values.containsKey(Identity.IDENTITY) || values.containsKey(Identity.NAMESPACE)) { 57 triggerAggregation(txContext, rawContactId); 58 } 59 60 return true; 61 } 62 63 @Override 64 public int delete(SQLiteDatabase db, TransactionContext txContext, Cursor c) { 65 final int count = super.delete(db, txContext, c); 66 67 // Identity affects aggregation. 68 final long rawContactId = c.getLong(DataUpdateQuery.RAW_CONTACT_ID); 69 triggerAggregation(txContext, rawContactId); 70 71 return count; 72 } 73 } 74