1 /* 2 * Copyright (C) 2016 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.database; 18 19 import android.os.Build.VERSION; 20 import android.os.Build.VERSION_CODES; 21 import android.provider.VoicemailContract.Status; 22 import android.support.annotation.RequiresApi; 23 import java.util.ArrayList; 24 import java.util.Arrays; 25 import java.util.List; 26 27 /** The query for the call voicemail status table. */ 28 public class VoicemailStatusQuery { 29 30 // TODO: Column indices should be removed in favor of Cursor#getColumnIndex 31 public static final int SOURCE_PACKAGE_INDEX = 0; 32 public static final int SETTINGS_URI_INDEX = 1; 33 public static final int VOICEMAIL_ACCESS_URI_INDEX = 2; 34 public static final int CONFIGURATION_STATE_INDEX = 3; 35 public static final int DATA_CHANNEL_STATE_INDEX = 4; 36 public static final int NOTIFICATION_CHANNEL_STATE_INDEX = 5; 37 38 @RequiresApi(VERSION_CODES.N) 39 public static final int QUOTA_OCCUPIED_INDEX = 6; 40 41 @RequiresApi(VERSION_CODES.N) 42 public static final int QUOTA_TOTAL_INDEX = 7; 43 44 @RequiresApi(VERSION_CODES.N_MR1) 45 // The PHONE_ACCOUNT columns were added in M, but aren't queryable until N MR1 46 public static final int PHONE_ACCOUNT_COMPONENT_NAME = 8; 47 48 @RequiresApi(VERSION_CODES.N_MR1) 49 public static final int PHONE_ACCOUNT_ID = 9; 50 51 @RequiresApi(VERSION_CODES.N_MR1) 52 public static final int SOURCE_TYPE_INDEX = 10; 53 54 private static final String[] PROJECTION_M = 55 new String[] { 56 Status.SOURCE_PACKAGE, // 0 57 Status.SETTINGS_URI, // 1 58 Status.VOICEMAIL_ACCESS_URI, // 2 59 Status.CONFIGURATION_STATE, // 3 60 Status.DATA_CHANNEL_STATE, // 4 61 Status.NOTIFICATION_CHANNEL_STATE // 5 62 }; 63 64 @RequiresApi(VERSION_CODES.N) 65 private static final String[] PROJECTION_N; 66 67 @RequiresApi(VERSION_CODES.N_MR1) 68 private static final String[] PROJECTION_NMR1; 69 70 static { 71 List<String> projectionList = new ArrayList<>(Arrays.asList(PROJECTION_M)); 72 projectionList.add(Status.QUOTA_OCCUPIED); // 6 73 projectionList.add(Status.QUOTA_TOTAL); // 7 74 PROJECTION_N = projectionList.toArray(new String[projectionList.size()]); 75 76 projectionList.add(Status.PHONE_ACCOUNT_COMPONENT_NAME); // 8 77 projectionList.add(Status.PHONE_ACCOUNT_ID); // 9 78 projectionList.add(Status.SOURCE_TYPE); // 10 79 PROJECTION_NMR1 = projectionList.toArray(new String[projectionList.size()]); 80 } 81 82 public static String[] getProjection() { 83 if (VERSION.SDK_INT >= VERSION_CODES.N_MR1) { 84 return PROJECTION_NMR1; 85 } 86 if (VERSION.SDK_INT >= VERSION_CODES.N) { 87 return PROJECTION_N; 88 } 89 return PROJECTION_M; 90 } 91 } 92