• 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.database.contract;
18 
19 import android.net.Uri;
20 import android.provider.BaseColumns;
21 import com.android.dialer.constants.Constants;
22 import java.util.Arrays;
23 
24 /** Contract for the AnnotatedCallLog content provider. */
25 public class AnnotatedCallLogContract {
26   public static final String AUTHORITY = Constants.get().getAnnotatedCallLogProviderAuthority();
27 
28   public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY);
29 
30   /**
31    * Columns shared by {@link AnnotatedCallLog} and {@link CoalescedAnnotatedCallLog}.
32    *
33    * <p>When adding columns be sure to update {@link #ALL_COMMON_COLUMNS}.
34    */
35   interface CommonColumns extends BaseColumns {
36 
37     /**
38      * Timestamp of the entry, in milliseconds.
39      *
40      * <p>Type: INTEGER (long)
41      */
42     String TIMESTAMP = "timestamp";
43 
44     /**
45      * Name to display for the entry.
46      *
47      * <p>Type: TEXT
48      */
49     String CONTACT_NAME = "contact_name";
50 
51     String[] ALL_COMMON_COLUMNS = new String[] {_ID, TIMESTAMP, CONTACT_NAME};
52   }
53 
54   /**
55    * AnnotatedCallLog table.
56    *
57    * <p>This contains all of the non-coalesced call log entries.
58    */
59   public static final class AnnotatedCallLog implements CommonColumns {
60 
61     public static final String TABLE = "AnnotatedCallLog";
62 
63     /** The content URI for this table. */
64     public static final Uri CONTENT_URI =
65         Uri.withAppendedPath(AnnotatedCallLogContract.CONTENT_URI, TABLE);
66 
67     /** The MIME type of a {@link android.content.ContentProvider#getType(Uri)} single entry. */
68     public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/annotated_call_log";
69 
70     /**
71      * The phone number called or number the call came from, encoded as a {@link
72      * com.android.dialer.DialerPhoneNumber} proto. The number may be empty if it was an incoming
73      * call and the number was unknown.
74      *
75      * <p>This column is only present in the annotated call log, and not the coalesced annotated
76      * call log. The coalesced version uses a formatted number string rather than proto bytes.
77      *
78      * <p>Type: BLOB
79      */
80     public static final String NUMBER = "number";
81   }
82 
83   /**
84    * Coalesced view of the AnnotatedCallLog table.
85    *
86    * <p>This is an in-memory view of the {@link AnnotatedCallLog} with some adjacent entries
87    * collapsed.
88    *
89    * <p>When adding columns be sure to update {@link #COLUMNS_ONLY_IN_COALESCED_CALL_LOG}.
90    */
91   public static final class CoalescedAnnotatedCallLog implements CommonColumns {
92 
93     public static final String TABLE = "CoalescedAnnotatedCallLog";
94 
95     /** The content URI for this table. */
96     public static final Uri CONTENT_URI =
97         Uri.withAppendedPath(AnnotatedCallLogContract.CONTENT_URI, TABLE);
98 
99     /** The MIME type of a {@link android.content.ContentProvider#getType(Uri)} single entry. */
100     public static final String CONTENT_ITEM_TYPE =
101         "vnd.android.cursor.item/coalesced_annotated_call_log";
102 
103     /**
104      * Number of AnnotatedCallLog rows represented by this CoalescedAnnotatedCallLog row.
105      *
106      * <p>Type: INTEGER
107      */
108     public static final String NUMBER_CALLS = "number_calls";
109 
110     /**
111      * The phone number formatted in a way suitable for display to the user. This value is generated
112      * on the fly when the {@link CoalescedAnnotatedCallLog} is generated.
113      *
114      * <p>Type: TEXT
115      */
116     public static final String FORMATTED_NUMBER = "formatted_number";
117 
118     /**
119      * Columns that are only in the {@link CoalescedAnnotatedCallLog} but not the {@link
120      * AnnotatedCallLog}.
121      */
122     private static final String[] COLUMNS_ONLY_IN_COALESCED_CALL_LOG =
123         new String[] {NUMBER_CALLS, FORMATTED_NUMBER};
124 
125     /** All columns in the {@link CoalescedAnnotatedCallLog}. */
126     public static final String[] ALL_COLUMNS =
127         concat(ALL_COMMON_COLUMNS, COLUMNS_ONLY_IN_COALESCED_CALL_LOG);
128   }
129 
concat(String[] first, String[] second)130   private static String[] concat(String[] first, String[] second) {
131     String[] result = Arrays.copyOf(first, first.length + second.length);
132     System.arraycopy(second, 0, result, first.length, second.length);
133     return result;
134   }
135 }
136