• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of 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,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.dialer.calllog.ui;
18 
19 import android.content.Context;
20 import android.database.Cursor;
21 import android.support.v4.content.CursorLoader;
22 import com.android.dialer.CoalescedIds;
23 import com.android.dialer.DialerPhoneNumber;
24 import com.android.dialer.NumberAttributes;
25 import com.android.dialer.calllog.database.contract.AnnotatedCallLogContract.CoalescedAnnotatedCallLog;
26 import com.android.dialer.calllog.model.CoalescedRow;
27 import com.google.protobuf.InvalidProtocolBufferException;
28 
29 /** CursorLoader for the coalesced annotated call log. */
30 final class CoalescedAnnotatedCallLogCursorLoader extends CursorLoader {
31 
32   // Indexes for CoalescedAnnotatedCallLog.ALL_COLUMNS
33   private static final int ID = 0;
34   private static final int TIMESTAMP = 1;
35   private static final int NUMBER = 2;
36   private static final int FORMATTED_NUMBER = 3;
37   private static final int NUMBER_PRESENTATION = 4;
38   private static final int IS_READ = 5;
39   private static final int NEW = 6;
40   private static final int GEOCODED_LOCATION = 7;
41   private static final int PHONE_ACCOUNT_COMPONENT_NAME = 8;
42   private static final int PHONE_ACCOUNT_ID = 9;
43   private static final int PHONE_ACCOUNT_LABEL = 10;
44   private static final int PHONE_ACCOUNT_COLOR = 11;
45   private static final int FEATURES = 12;
46   private static final int NUMBER_ATTRIBUTES = 13;
47   private static final int CALL_TYPE = 14;
48   private static final int COALESCED_IDS = 15;
49 
CoalescedAnnotatedCallLogCursorLoader(Context context)50   CoalescedAnnotatedCallLogCursorLoader(Context context) {
51     // CoalescedAnnotatedCallLog requires that PROJECTION be ALL_COLUMNS and the following params be
52     // null.
53     super(
54         context,
55         CoalescedAnnotatedCallLog.CONTENT_URI,
56         CoalescedAnnotatedCallLog.ALL_COLUMNS,
57         null,
58         null,
59         null);
60   }
61 
62   /** Creates a new {@link CoalescedRow} from the provided cursor using the current position. */
toRow(Cursor cursor)63   static CoalescedRow toRow(Cursor cursor) {
64     DialerPhoneNumber number;
65     try {
66       number = DialerPhoneNumber.parseFrom(cursor.getBlob(NUMBER));
67     } catch (InvalidProtocolBufferException e) {
68       throw new IllegalStateException("Couldn't parse DialerPhoneNumber bytes");
69     }
70 
71     CoalescedIds coalescedIds;
72     try {
73       coalescedIds = CoalescedIds.parseFrom(cursor.getBlob(COALESCED_IDS));
74     } catch (InvalidProtocolBufferException e) {
75       throw new IllegalStateException("Couldn't parse CoalescedIds bytes");
76     }
77 
78     NumberAttributes numberAttributes;
79     try {
80       numberAttributes = NumberAttributes.parseFrom(cursor.getBlob(NUMBER_ATTRIBUTES));
81     } catch (InvalidProtocolBufferException e) {
82       throw new IllegalStateException("Couldn't parse NumberAttributes bytes");
83     }
84 
85     return CoalescedRow.builder()
86         .setId(cursor.getInt(ID))
87         .setTimestamp(cursor.getLong(TIMESTAMP))
88         .setNumber(number)
89         .setFormattedNumber(cursor.getString(FORMATTED_NUMBER))
90         .setNumberPresentation(cursor.getInt(NUMBER_PRESENTATION))
91         .setIsRead(cursor.getInt(IS_READ) == 1)
92         .setIsNew(cursor.getInt(NEW) == 1)
93         .setGeocodedLocation(cursor.getString(GEOCODED_LOCATION))
94         .setPhoneAccountComponentName(cursor.getString(PHONE_ACCOUNT_COMPONENT_NAME))
95         .setPhoneAccountId(cursor.getString(PHONE_ACCOUNT_ID))
96         .setPhoneAccountLabel(cursor.getString(PHONE_ACCOUNT_LABEL))
97         .setPhoneAccountColor(cursor.getInt(PHONE_ACCOUNT_COLOR))
98         .setFeatures(cursor.getInt(FEATURES))
99         .setCallType(cursor.getInt(CALL_TYPE))
100         .setNumberAttributes(numberAttributes)
101         .setCoalescedIds(coalescedIds)
102         .build();
103   }
104 
getTimestamp(Cursor cursor)105   static long getTimestamp(Cursor cursor) {
106     return cursor.getLong(TIMESTAMP);
107   }
108 }
109