• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2015, Motorola Mobility LLC
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *     - Redistributions of source code must retain the above copyright
8  *       notice, this list of conditions and the following disclaimer.
9  *     - Redistributions in binary form must reproduce the above copyright
10  *       notice, this list of conditions and the following disclaimer in the
11  *       documentation and/or other materials provided with the distribution.
12  *     - Neither the name of Motorola Mobility nor the
13  *       names of its contributors may be used to endorse or promote products
14  *       derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MOTOROLA MOBILITY LLC BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
26  * DAMAGE.
27  */
28 
29 package com.android.service.ims.presence;
30 
31 import android.accounts.Account;
32 import android.content.ContentResolver;
33 import android.content.ContentUris;
34 import android.content.ContentValues;
35 import android.content.Context;
36 import android.database.Cursor;
37 import android.net.Uri;
38 import android.provider.ContactsContract.Groups;
39 
40 import android.provider.ContactsContract;
41 import android.provider.ContactsContract.CommonDataKinds.Phone;
42 
43 import com.android.ims.internal.EABContract;
44 import com.android.ims.internal.Logger;
45 
46 public class ContactDbUtil {
47     private static Logger logger = Logger.getLogger("ContactDbUtil");
48 
resetVtCapability(ContentResolver resolver)49     public static int resetVtCapability(ContentResolver resolver) {
50         if(resolver == null) {
51             logger.error("resetVtCapability, resolver = null");
52             return 0;
53         }
54 
55         String selection = ContactsContract.Data.MIMETYPE + " = '" + Phone.CONTENT_ITEM_TYPE + "'";
56 
57         ContentValues values = new ContentValues();
58         values.put(ContactsContract.Data.CARRIER_PRESENCE, 0); // reset all.
59         int count = resolver.update(ContactsContract.Data.CONTENT_URI, values, selection, null);
60         logger.debug("resetVtCapability count=" + count);
61         return count;
62     }
63 
updateVtCapability(ContentResolver resolver, long dataId, boolean enable)64     public static int updateVtCapability(ContentResolver resolver, long dataId, boolean enable) {
65         if(resolver == null) {
66             logger.error("resetVtCapability, resolver = null");
67             return 0;
68         }
69 
70         String selection = ContactsContract.Data.MIMETYPE + " = '" + Phone.CONTENT_ITEM_TYPE
71                 + "' and " + ContactsContract.Data._ID + "= '" + dataId + "'";
72 
73         int oldValue = 0;
74         final Cursor cursor = resolver.query(ContactsContract.Data.CONTENT_URI,
75                 new String[] { ContactsContract.Data._ID, ContactsContract.Data.CARRIER_PRESENCE },
76                 selection, null, null);
77         if (cursor != null) {
78             try {
79                 if (cursor.moveToFirst()) {
80                     oldValue = cursor.getInt(1);
81                 }
82             } finally {
83                 cursor.close();
84             }
85         }
86 
87 
88         ContentValues values = new ContentValues();
89         values.put(ContactsContract.Data.CARRIER_PRESENCE,
90                 enable?(oldValue | ContactsContract.Data.CARRIER_PRESENCE_VT_CAPABLE):
91                 (oldValue & ~ContactsContract.Data.CARRIER_PRESENCE_VT_CAPABLE));
92         int count = resolver.update(ContactsContract.Data.CONTENT_URI, values, selection, null);
93         logger.debug("resetVtCapability count=" + count);
94         return count;
95     }
96 }
97