Home | History | Annotate | Download | only in contract
      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.os.Build;
     21 import android.provider.BaseColumns;
     22 import com.android.dialer.compat.android.provider.VoicemailCompat;
     23 import com.android.dialer.constants.Constants;
     24 import java.util.Arrays;
     25 
     26 /** Contract for the AnnotatedCallLog content provider. */
     27 public class AnnotatedCallLogContract {
     28   public static final String AUTHORITY = Constants.get().getAnnotatedCallLogProviderAuthority();
     29 
     30   public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY);
     31 
     32   /**
     33    * Columns shared by {@link AnnotatedCallLog} and {@link CoalescedAnnotatedCallLog}.
     34    *
     35    * <p>When adding columns be sure to update {@link #ALL_COMMON_COLUMNS}.
     36    */
     37   interface CommonColumns extends BaseColumns {
     38 
     39     /**
     40      * Timestamp of the entry, in milliseconds.
     41      *
     42      * <p>Type: INTEGER (long)
     43      */
     44     String TIMESTAMP = "timestamp";
     45 
     46     /**
     47      * The phone number called or number the call came from, encoded as a {@link
     48      * com.android.dialer.DialerPhoneNumber} proto. The number may be empty if it was an incoming
     49      * call and the number was unknown.
     50      *
     51      * <p>Type: BLOB
     52      */
     53     String NUMBER = "number";
     54 
     55     /**
     56      * The number formatted as it should be displayed to the user. Note that it may not always be
     57      * displayed, for example if the number has a corresponding person or business name.
     58      *
     59      * <p>Type: TEXT
     60      */
     61     String FORMATTED_NUMBER = "formatted_number";
     62 
     63     /**
     64      * See {@link android.provider.CallLog.Calls#NUMBER_PRESENTATION}.
     65      *
     66      * <p>Type: INTEGER (int)
     67      */
     68     String NUMBER_PRESENTATION = "presentation";
     69 
     70     /**
     71      * See {@link android.provider.CallLog.Calls#IS_READ}.
     72      *
     73      * <p>TYPE: INTEGER (boolean)
     74      */
     75     String IS_READ = "is_read";
     76 
     77     /**
     78      * See {@link android.provider.CallLog.Calls#NEW}.
     79      *
     80      * <p>Type: INTEGER (boolean)
     81      */
     82     String NEW = "new";
     83 
     84     /**
     85      * See {@link android.provider.CallLog.Calls#GEOCODED_LOCATION}.
     86      *
     87      * <p>TYPE: TEXT
     88      */
     89     String GEOCODED_LOCATION = "geocoded_location";
     90 
     91     /**
     92      * See {@link android.provider.CallLog.Calls#PHONE_ACCOUNT_COMPONENT_NAME}.
     93      *
     94      * <p>TYPE: TEXT
     95      */
     96     String PHONE_ACCOUNT_COMPONENT_NAME = "phone_account_component_name";
     97 
     98     /**
     99      * See {@link android.provider.CallLog.Calls#PHONE_ACCOUNT_ID}.
    100      *
    101      * <p>TYPE: TEXT
    102      */
    103     String PHONE_ACCOUNT_ID = "phone_account_id";
    104 
    105     /**
    106      * String suitable for display which indicates the phone account used to make the call.
    107      *
    108      * <p>TYPE: TEXT
    109      */
    110     String PHONE_ACCOUNT_LABEL = "phone_account_label";
    111 
    112     /**
    113      * The color int for the phone account.
    114      *
    115      * <p>TYPE: INTEGER (int)
    116      */
    117     String PHONE_ACCOUNT_COLOR = "phone_account_color";
    118 
    119     /**
    120      * See {@link android.provider.CallLog.Calls#FEATURES}.
    121      *
    122      * <p>TYPE: INTEGER (int)
    123      */
    124     String FEATURES = "features";
    125 
    126     /**
    127      * Additional attributes about the number.
    128      *
    129      * <p>TYPE: BLOB
    130      *
    131      * @see com.android.dialer.NumberAttributes
    132      */
    133     String NUMBER_ATTRIBUTES = "number_attributes";
    134 
    135     /**
    136      * Copied from {@link android.provider.CallLog.Calls#TYPE}.
    137      *
    138      * <p>Type: INTEGER (int)
    139      */
    140     String CALL_TYPE = "call_type";
    141 
    142     String[] ALL_COMMON_COLUMNS =
    143         new String[] {
    144           _ID,
    145           TIMESTAMP,
    146           NUMBER,
    147           FORMATTED_NUMBER,
    148           NUMBER_PRESENTATION,
    149           IS_READ,
    150           NEW,
    151           GEOCODED_LOCATION,
    152           PHONE_ACCOUNT_COMPONENT_NAME,
    153           PHONE_ACCOUNT_ID,
    154           PHONE_ACCOUNT_LABEL,
    155           PHONE_ACCOUNT_COLOR,
    156           FEATURES,
    157           NUMBER_ATTRIBUTES,
    158           CALL_TYPE
    159         };
    160   }
    161 
    162   /**
    163    * AnnotatedCallLog table.
    164    *
    165    * <p>This contains all of the non-coalesced call log entries.
    166    */
    167   public static final class AnnotatedCallLog implements CommonColumns {
    168 
    169     public static final String TABLE = "AnnotatedCallLog";
    170     public static final String DISTINCT_PHONE_NUMBERS = "DistinctPhoneNumbers";
    171 
    172     /** The content URI for this table. */
    173     public static final Uri CONTENT_URI =
    174         Uri.withAppendedPath(AnnotatedCallLogContract.CONTENT_URI, TABLE);
    175 
    176     /** Content URI for selecting the distinct phone numbers from the AnnotatedCallLog. */
    177     public static final Uri DISTINCT_NUMBERS_CONTENT_URI =
    178         Uri.withAppendedPath(AnnotatedCallLogContract.CONTENT_URI, DISTINCT_PHONE_NUMBERS);
    179 
    180     /** The MIME type of a {@link android.content.ContentProvider#getType(Uri)} single entry. */
    181     public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/annotated_call_log";
    182 
    183     /**
    184      * See {@link android.provider.CallLog.Calls#DATA_USAGE}.
    185      *
    186      * <p>Type: INTEGER (long)
    187      */
    188     public static final String DATA_USAGE = "data_usage";
    189 
    190     /**
    191      * See {@link android.provider.CallLog.Calls#DURATION}.
    192      *
    193      * <p>TYPE: INTEGER (long)
    194      */
    195     public static final String DURATION = "duration";
    196 
    197     /**
    198      * See {@link android.provider.CallLog.Calls#TRANSCRIPTION}.
    199      *
    200      * <p>TYPE: TEXT
    201      */
    202     public static final String TRANSCRIPTION = "transcription";
    203 
    204     /**
    205      * See {@link VoicemailCompat.TRANSCRIPTION_STATE}
    206      *
    207      * <p>Only populated in {@link Build.VERSION_CODES.O} and above
    208      *
    209      * <p>TYPE: INTEGER
    210      */
    211     public static final String TRANSCRIPTION_STATE = "transcription_state";
    212 
    213     /**
    214      * See {@link android.provider.CallLog.Calls#VOICEMAIL_URI}.
    215      *
    216      * <p>TYPE: TEXT
    217      */
    218     public static final String VOICEMAIL_URI = "voicemail_uri";
    219   }
    220 
    221   /**
    222    * Coalesced view of the AnnotatedCallLog table.
    223    *
    224    * <p>This is an in-memory view of the {@link AnnotatedCallLog} with some adjacent entries
    225    * collapsed.
    226    *
    227    * <p>When adding columns be sure to update {@link #COLUMNS_ONLY_IN_COALESCED_CALL_LOG}.
    228    */
    229   public static final class CoalescedAnnotatedCallLog implements CommonColumns {
    230 
    231     public static final String TABLE = "CoalescedAnnotatedCallLog";
    232 
    233     /** The content URI for this table. */
    234     public static final Uri CONTENT_URI =
    235         Uri.withAppendedPath(AnnotatedCallLogContract.CONTENT_URI, TABLE);
    236 
    237     /** The MIME type of a {@link android.content.ContentProvider#getType(Uri)} single entry. */
    238     public static final String CONTENT_ITEM_TYPE =
    239         "vnd.android.cursor.item/coalesced_annotated_call_log";
    240 
    241     /**
    242      * IDs of rows in {@link AnnotatedCallLog} that are coalesced into one row in {@link
    243      * CoalescedAnnotatedCallLog}, encoded as a {@link com.android.dialer.CoalescedIds} proto.
    244      *
    245      * <p>Type: BLOB
    246      */
    247     public static final String COALESCED_IDS = "coalesced_ids";
    248 
    249     /**
    250      * Columns that are only in the {@link CoalescedAnnotatedCallLog} but not the {@link
    251      * AnnotatedCallLog}.
    252      */
    253     private static final String[] COLUMNS_ONLY_IN_COALESCED_CALL_LOG = new String[] {COALESCED_IDS};
    254 
    255     /** All columns in the {@link CoalescedAnnotatedCallLog}. */
    256     public static final String[] ALL_COLUMNS =
    257         concat(ALL_COMMON_COLUMNS, COLUMNS_ONLY_IN_COALESCED_CALL_LOG);
    258   }
    259 
    260   private static String[] concat(String[] first, String[] second) {
    261     String[] result = Arrays.copyOf(first, first.length + second.length);
    262     System.arraycopy(second, 0, result, first.length, second.length);
    263     return result;
    264   }
    265 }
    266