MtpDatabaseConstants.java revision 9e8a4fa78f5b9e3964dca84ad4047210d35c4013
1/* 2 * Copyright (C) 2015 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 17package com.android.mtp; 18 19import android.provider.DocumentsContract.Document; 20import android.provider.DocumentsContract.Root; 21 22/** 23 * Class containing MtpDatabase constants. 24 */ 25class MtpDatabaseConstants { 26 static final int DATABASE_VERSION = 1; 27 static final String DATABASE_NAME = null; 28 29 static final int FLAG_DATABASE_IN_MEMORY = 1; 30 static final int FLAG_DATABASE_IN_FILE = 0; 31 32 /** 33 * Table representing documents including root documents. 34 */ 35 static final String TABLE_DOCUMENTS = "Documents"; 36 37 /** 38 * Table containing additional information only available for root documents. 39 * The table uses same primary keys with corresponding documents. 40 */ 41 static final String TABLE_ROOT_EXTRA = "RootExtra"; 42 43 /** 44 * View to join Documents and RootExtra tables to provide roots information. 45 */ 46 static final String VIEW_ROOTS = "Roots"; 47 48 static final String COLUMN_DEVICE_ID = "device_id"; 49 static final String COLUMN_STORAGE_ID = "storage_id"; 50 static final String COLUMN_OBJECT_HANDLE = "object_handle"; 51 static final String COLUMN_PARENT_DOCUMENT_ID = "parent_document_id"; 52 static final String COLUMN_ROW_STATE = "row_state"; 53 54 /** 55 * The state represents that the row has a valid object handle. 56 */ 57 static final int ROW_STATE_VALID = 0; 58 59 /** 60 * The state represents that the rows added at the previous cycle and need to be updated with 61 * fresh values. 62 * The row may not have valid object handle. External application can still fetch the documents. 63 * If the external application tries to fetch object handle, the provider resolves pending 64 * documents with invalidated documents ahead. 65 */ 66 static final int ROW_STATE_INVALIDATED = 1; 67 68 /** 69 * The state represents the raw has a valid object handle but it may be going to be mapped with 70 * another rows invalidated. After fetching all documents under the parent, the database tries 71 * to map the pending documents and the invalidated documents in order to keep old document ID 72 * alive. 73 */ 74 static final int ROW_STATE_PENDING = 2; 75 76 /** 77 * Mapping mode that uses MTP identifier to find corresponding rows. 78 */ 79 static final int MAP_BY_MTP_IDENTIFIER = 0; 80 81 /** 82 * Mapping mode that uses name to find corresponding rows. 83 */ 84 static final int MAP_BY_NAME = 1; 85 86 static final String SELECTION_DOCUMENT_ID = Document.COLUMN_DOCUMENT_ID + " = ?"; 87 static final String SELECTION_ROOT_ID = Root.COLUMN_ROOT_ID + " = ?"; 88 static final String SELECTION_ROOT_DOCUMENTS = 89 COLUMN_DEVICE_ID + " = ? AND " + COLUMN_PARENT_DOCUMENT_ID + " IS NULL"; 90 static final String SELECTION_CHILD_DOCUMENTS = COLUMN_PARENT_DOCUMENT_ID + " = ?"; 91 92 static final String QUERY_CREATE_DOCUMENTS = 93 "CREATE TABLE " + TABLE_DOCUMENTS + " (" + 94 Document.COLUMN_DOCUMENT_ID + 95 " INTEGER PRIMARY KEY AUTOINCREMENT," + 96 COLUMN_DEVICE_ID + " INTEGER NOT NULL," + 97 COLUMN_STORAGE_ID + " INTEGER," + 98 COLUMN_OBJECT_HANDLE + " INTEGER," + 99 COLUMN_PARENT_DOCUMENT_ID + " INTEGER," + 100 COLUMN_ROW_STATE + " INTEGER NOT NULL," + 101 Document.COLUMN_MIME_TYPE + " TEXT," + 102 Document.COLUMN_DISPLAY_NAME + " TEXT NOT NULL," + 103 Document.COLUMN_SUMMARY + " TEXT," + 104 Document.COLUMN_LAST_MODIFIED + " INTEGER," + 105 Document.COLUMN_ICON + " INTEGER," + 106 Document.COLUMN_FLAGS + " INTEGER NOT NULL," + 107 Document.COLUMN_SIZE + " INTEGER NOT NULL);"; 108 109 static final String QUERY_CREATE_ROOT_EXTRA = 110 "CREATE TABLE " + TABLE_ROOT_EXTRA + " (" + 111 Root.COLUMN_ROOT_ID + " INTEGER PRIMARY KEY," + 112 Root.COLUMN_FLAGS + " INTEGER NOT NULL," + 113 Root.COLUMN_AVAILABLE_BYTES + " INTEGER NOT NULL," + 114 Root.COLUMN_CAPACITY_BYTES + " INTEGER NOT NULL," + 115 Root.COLUMN_MIME_TYPES + " TEXT NOT NULL);"; 116 117 /** 118 * Creates a view to join Documents table and RootExtra table on their primary keys to 119 * provide DocumentContract.Root equivalent information. 120 */ 121 static final String QUERY_CREATE_VIEW_ROOTS = 122 "CREATE VIEW " + VIEW_ROOTS + " AS SELECT " + 123 TABLE_DOCUMENTS + "." + Document.COLUMN_DOCUMENT_ID + " AS " + 124 Root.COLUMN_ROOT_ID + "," + 125 TABLE_ROOT_EXTRA + "." + Root.COLUMN_FLAGS + "," + 126 TABLE_DOCUMENTS + "." + Document.COLUMN_ICON + " AS " + 127 Root.COLUMN_ICON + "," + 128 TABLE_DOCUMENTS + "." + Document.COLUMN_DISPLAY_NAME + " AS " + 129 Root.COLUMN_TITLE + "," + 130 TABLE_DOCUMENTS + "." + Document.COLUMN_SUMMARY + " AS " + 131 Root.COLUMN_SUMMARY + "," + 132 TABLE_DOCUMENTS + "." + Document.COLUMN_DOCUMENT_ID + " AS " + 133 Root.COLUMN_DOCUMENT_ID + "," + 134 TABLE_ROOT_EXTRA + "." + Root.COLUMN_AVAILABLE_BYTES + "," + 135 TABLE_ROOT_EXTRA + "." + Root.COLUMN_CAPACITY_BYTES + "," + 136 TABLE_ROOT_EXTRA + "." + Root.COLUMN_MIME_TYPES + "," + 137 TABLE_DOCUMENTS + "." + COLUMN_ROW_STATE + 138 " FROM " + TABLE_DOCUMENTS + " INNER JOIN " + TABLE_ROOT_EXTRA + 139 " ON " + 140 COLUMN_PARENT_DOCUMENT_ID + " IS NULL AND " + 141 TABLE_DOCUMENTS + "." + Document.COLUMN_DOCUMENT_ID + 142 "=" + 143 TABLE_ROOT_EXTRA + "." + Root.COLUMN_ROOT_ID; 144} 145