• 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.net.Uri;
32 import android.provider.BaseColumns;
33 import android.text.format.Time;
34 import com.android.ims.internal.EABContract;
35 
36 import com.android.ims.internal.ContactNumberUtils;
37 import com.android.ims.internal.Logger;
38 
39 public final class Contacts {
Contacts()40     private Contacts() {}
41 
42     /**
43      * Intent that a new contact is inserted in EAB Provider.
44      * This intent will have a extra parameter with key NEW_PHONE_NUMBER.
45      */
46     public static final String ACTION_NEW_CONTACT_INSERTED =
47             "android.provider.rcs.eab.EAB_NEW_CONTACT_INSERTED";
48 
49     /**
50      * Intent that EAB database is reset.
51      */
52     public static final String ACTION_EAB_DATABASE_RESET =
53             "android.provider.rcs.eab.EAB_DATABASE_RESET";
54 
55     /**
56      * Key to bundle the new phone number inserted in EAB Provider.
57      */
58     public static final String NEW_PHONE_NUMBER = "newPhoneNumber";
59 
60 
61     public static final String AUTHORITY = EABContract.AUTHORITY;
62 
63     public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY);
64 
65     public static final class Impl implements BaseColumns {
Impl()66         private Impl() {}
67 
68         public static final String TABLE_NAME =
69                 EABContract.EABColumns.TABLE_NAME;
70 
71         /**
72          * CONTENT_URI
73          * <P>
74          * "content://com.android.vt.eab/EABPresence"
75          * </P>
76          */
77         public static final Uri CONTENT_URI =
78                 Uri.withAppendedPath(Contacts.CONTENT_URI, TABLE_NAME);
79 
80         /**
81          * Key defining the contact number.
82          * <P>
83          * Type: TEXT
84          * </P>
85          */
86         public static final String FORMATTED_NUMBER =
87                 EABContract.EABColumns.FORMATTED_NUMBER;
88 
89         /**
90          * Key defining the contact number.
91          * <P>
92          * Type: TEXT
93          * </P>
94          */
95         public static final String CONTACT_NUMBER =
96                 EABContract.EABColumns.CONTACT_NUMBER;
97 
98         /**
99          * Key defining the contact name.
100          * <P>
101          * Type: TEXT
102          * </P>
103          */
104         public static final String CONTACT_NAME =
105                 EABContract.EABColumns.CONTACT_NAME;
106 
107         /**
108          * <p>
109          * Type: INT
110          * </p>
111          */
112         public static final String VOLTE_STATUS =
113                 EABContract.EABColumns.VOLTE_STATUS;
114 
115         /**
116          * Key defining the last updated timestamp.
117          * <P>
118          * Type: LONG
119          * </P>
120          */
121         public static final String CONTACT_LAST_UPDATED_TIMESTAMP =
122                 EABContract.EABColumns.CONTACT_LAST_UPDATED_TIMESTAMP;
123 
124         /**
125          * Key defining the VoLTE call service contact address.
126          * <P>
127          * Type: TEXT
128          * </P>
129          */
130         public static final String VOLTE_CALL_SERVICE_CONTACT_ADDRESS =
131                 EABContract.EABColumns.VOLTE_CALL_SERVICE_CONTACT_ADDRESS;
132 
133         /**
134          * Key defining the VoLTE call capability.
135          * <P>
136          * Type: TEXT
137          * </P>
138          */
139         public static final String VOLTE_CALL_CAPABILITY =
140                 EABContract.EABColumns.VOLTE_CALL_CAPABILITY;
141 
142         /**
143          * Key defining the VoLTE call capability timestamp.
144          * <P>
145          * Type: LONG
146          * </P>
147          */
148         public static final String VOLTE_CALL_CAPABILITY_TIMESTAMP =
149                 EABContract.EABColumns.VOLTE_CALL_CAPABILITY_TIMESTAMP;
150 
151         /**
152          * Key defining the VoLTE call availability.
153          * <P>
154          * Type: TEXT
155          * </P>
156          */
157         public static final String VOLTE_CALL_AVAILABILITY =
158                 EABContract.EABColumns.VOLTE_CALL_AVAILABILITY;
159 
160         /**
161          * Key defining the VoLTE call availability timestamp.
162          * <P>
163          * Type: LONG
164          * </P>
165          */
166         public static final String VOLTE_CALL_AVAILABILITY_TIMESTAMP =
167                 EABContract.EABColumns.VOLTE_CALL_AVAILABILITY_TIMESTAMP;
168 
169         /**
170          * Key defining the Video call service contact address.
171          * <P>
172          * Type: TEXT
173          * </P>
174          */
175         public static final String VIDEO_CALL_SERVICE_CONTACT_ADDRESS =
176                 EABContract.EABColumns.VIDEO_CALL_SERVICE_CONTACT_ADDRESS;
177 
178         /**
179          * Key defining the Video call capability.
180          * <P>
181          * Type: TEXT
182          * </P>
183          */
184         public static final String VIDEO_CALL_CAPABILITY =
185                 EABContract.EABColumns.VIDEO_CALL_CAPABILITY;
186 
187         /**
188          * Key defining the Video call capability timestamp.
189          * <P>
190          * Type: LONG
191          * </P>
192          */
193         public static final String VIDEO_CALL_CAPABILITY_TIMESTAMP =
194                 EABContract.EABColumns.VIDEO_CALL_CAPABILITY_TIMESTAMP;
195 
196         /**
197          * Key defining the Video call availability.
198          * <P>
199          * Type: TEXT
200          * </P>
201          */
202         public static final String VIDEO_CALL_AVAILABILITY =
203                 EABContract.EABColumns.VIDEO_CALL_AVAILABILITY;
204 
205         /**
206          * Key defining the Video call availability timestamp.
207          * <P>
208          * Type: LONG
209          * </P>
210          */
211         public static final String VIDEO_CALL_AVAILABILITY_TIMESTAMP =
212                 EABContract.EABColumns.VIDEO_CALL_AVAILABILITY_TIMESTAMP;
213     }
214 
215     public static class Item {
Item(long id)216         public Item(long id) {
217             mId = id;
218         }
219 
id()220         public long id() {
221             return mId;
222         }
223 
number()224         public String number() {
225             return mNumber;
226         }
227 
setNumber(String number)228         public void setNumber(String number) {
229             mNumber = ContactNumberUtils.getDefault().format(number);
230         }
231 
isValid()232         public boolean isValid() {
233             int res = ContactNumberUtils.getDefault().validate(mNumber);
234             return (res == ContactNumberUtils.NUMBER_VALID);
235         }
236 
name()237         public String name() {
238             return mName;
239         }
240 
setName(String name)241         public void setName(String name) {
242             mName = name;
243         }
244 
lastUpdateTime()245         public long lastUpdateTime() {
246             return mLastUpdateTime;
247         }
248 
setLastUpdateTime(long time)249         public void setLastUpdateTime(long time) {
250             mLastUpdateTime = time;
251         }
252 
volteTimestamp()253         public long volteTimestamp() {
254             return mVolteTimeStamp;
255         }
256 
setVolteTimestamp(long time)257         public void setVolteTimestamp(long time) {
258             mVolteTimeStamp = time;
259         }
260 
videoTimestamp()261         public long videoTimestamp() {
262             return mVideoTimeStamp;
263         }
264 
setVideoTimestamp(long time)265         public void setVideoTimestamp(long time) {
266             mVideoTimeStamp = time;
267         }
268 
269         @Override
equals(Object o)270         public boolean equals(Object o) {
271             if (this == o) return true;
272             if (!(o instanceof Contacts.Item)) return false;
273 
274             Contacts.Item that = (Contacts.Item) o;
275             return this.number().equalsIgnoreCase(that.number());
276         }
277 
278         @Override
toString()279         public String toString() {
280             return new StringBuilder(256)
281                 .append("Contacts.Item { ")
282                 .append("\nId: " + mId)
283                 .append("\nNumber: " + Logger.hidePhoneNumberPii(mNumber))
284                 .append("\nLast update time: " + mLastUpdateTime + "(" +
285                         getTimeString(mLastUpdateTime) + ")")
286                 .append("\nVolte capability timestamp: " + mVolteTimeStamp + "(" +
287                         getTimeString(mVolteTimeStamp) + ")")
288                 .append("\nVideo capability timestamp: " + mVideoTimeStamp + "(" +
289                         getTimeString(mVideoTimeStamp) + ")")
290                 .append("\nisValid: " + isValid())
291                 .append(" }")
292                 .toString();
293         }
294 
getTimeString(long time)295         private String getTimeString(long time) {
296             if (time <= 0) {
297                 time = System.currentTimeMillis();
298             }
299 
300             Time tobj = new Time();
301             tobj.set(time);
302             return String.format("%s.%s", tobj.format("%m-%d %H:%M:%S"), time % 1000);
303         }
304 
305         private long mId;
306         private String mNumber;
307         private String mName;
308         private long mLastUpdateTime;
309         private long mVolteTimeStamp;
310         private long mVideoTimeStamp;
311     }
312 }
313