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