blob: 3527eeead1d590cd7d9431566b4d44e3ae11510f [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006-2007 The Android Open Source Project
3 *
Mark Salyzyn00adb862014-03-19 11:00:06 -07004 * 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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007 *
Mark Salyzyn00adb862014-03-19 11:00:06 -07008 * http://www.apache.org/licenses/LICENSE-2.0
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009 *
Mark Salyzyn00adb862014-03-19 11:00:06 -070010 * 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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080014 * limitations under the License.
15 */
16
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080017#define LOG_TAG "CursorWindow"
18
Mathias Agopian49d2b182012-02-27 18:11:20 -080019#include <androidfw/CursorWindow.h>
Jeff Brown0cde89f2011-10-10 14:50:10 -070020
Jeff Brown0cde89f2011-10-10 14:50:10 -070021#include <sys/mman.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -060023#include "android-base/logging.h"
24#include "cutils/ashmem.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026namespace android {
27
Jeff Sharkey539fdff2020-09-23 21:43:23 -060028/**
29 * By default windows are lightweight inline allocations of this size;
30 * they're only inflated to ashmem regions when more space is needed.
31 */
32static constexpr const size_t kInlineSize = 16384;
33
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -060034static constexpr const size_t kSlotShift = 4;
35static constexpr const size_t kSlotSizeBytes = 1 << kSlotShift;
36
37CursorWindow::CursorWindow() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038}
39
Jeff Brown0cde89f2011-10-10 14:50:10 -070040CursorWindow::~CursorWindow() {
Jeff Sharkey539fdff2020-09-23 21:43:23 -060041 if (mAshmemFd != -1) {
42 ::munmap(mData, mSize);
43 ::close(mAshmemFd);
44 } else {
45 free(mData);
46 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047}
48
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -060049status_t CursorWindow::create(const String8 &name, size_t inflatedSize, CursorWindow **outWindow) {
50 *outWindow = nullptr;
Jeff Sharkey539fdff2020-09-23 21:43:23 -060051
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -060052 CursorWindow* window = new CursorWindow();
53 if (!window) goto fail;
Jeff Sharkey539fdff2020-09-23 21:43:23 -060054
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -060055 window->mName = name;
56 window->mSize = std::min(kInlineSize, inflatedSize);
57 window->mInflatedSize = inflatedSize;
58 window->mData = malloc(window->mSize);
59 if (!window->mData) goto fail;
60 window->mReadOnly = false;
61
62 window->clear();
63 window->updateSlotsData();
64
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -060065 *outWindow = window;
66 return OK;
67
68fail:
69 LOG(ERROR) << "Failed create";
70fail_silent:
Jeff Sharkey539fdff2020-09-23 21:43:23 -060071 delete window;
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -060072 return UNKNOWN_ERROR;
Jeff Sharkey539fdff2020-09-23 21:43:23 -060073}
74
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -060075status_t CursorWindow::maybeInflate() {
76 int ashmemFd = 0;
77 void* newData = nullptr;
78
79 // Bail early when we can't expand any further
80 if (mReadOnly || mSize == mInflatedSize) {
81 return INVALID_OPERATION;
82 }
Jeff Sharkey539fdff2020-09-23 21:43:23 -060083
Jeff Brown0cde89f2011-10-10 14:50:10 -070084 String8 ashmemName("CursorWindow: ");
Jeff Sharkey539fdff2020-09-23 21:43:23 -060085 ashmemName.append(mName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -060087 ashmemFd = ashmem_create_region(ashmemName.string(), mInflatedSize);
Jeff Brown0cde89f2011-10-10 14:50:10 -070088 if (ashmemFd < 0) {
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -060089 PLOG(ERROR) << "Failed ashmem_create_region";
90 goto fail_silent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091 }
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -060092
93 if (ashmem_set_prot_region(ashmemFd, PROT_READ | PROT_WRITE) < 0) {
94 PLOG(ERROR) << "Failed ashmem_set_prot_region";
95 goto fail_silent;
96 }
97
98 newData = ::mmap(nullptr, mInflatedSize, PROT_READ | PROT_WRITE, MAP_SHARED, ashmemFd, 0);
99 if (newData == MAP_FAILED) {
100 PLOG(ERROR) << "Failed mmap";
101 goto fail_silent;
102 }
103
104 if (ashmem_set_prot_region(ashmemFd, PROT_READ) < 0) {
105 PLOG(ERROR) << "Failed ashmem_set_prot_region";
106 goto fail_silent;
107 }
108
109 {
110 // Migrate existing contents into new ashmem region
111 uint32_t slotsSize = mSize - mSlotsOffset;
112 uint32_t newSlotsOffset = mInflatedSize - slotsSize;
113 memcpy(static_cast<uint8_t*>(newData),
114 static_cast<uint8_t*>(mData), mAllocOffset);
115 memcpy(static_cast<uint8_t*>(newData) + newSlotsOffset,
116 static_cast<uint8_t*>(mData) + mSlotsOffset, slotsSize);
117
118 free(mData);
119 mAshmemFd = ashmemFd;
120 mData = newData;
121 mSize = mInflatedSize;
122 mSlotsOffset = newSlotsOffset;
123
124 updateSlotsData();
125 }
126
127 LOG(DEBUG) << "Inflated: " << this->toString();
128 return OK;
129
130fail:
131 LOG(ERROR) << "Failed maybeInflate";
132fail_silent:
133 ::munmap(newData, mInflatedSize);
134 ::close(ashmemFd);
135 return UNKNOWN_ERROR;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136}
137
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -0600138status_t CursorWindow::createFromParcel(Parcel* parcel, CursorWindow** outWindow) {
139 *outWindow = nullptr;
Jeff Brown0cde89f2011-10-10 14:50:10 -0700140
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -0600141 CursorWindow* window = new CursorWindow();
142 if (!window) goto fail;
143
144 if (parcel->readString8(&window->mName)) goto fail;
145 if (parcel->readUint32(&window->mNumRows)) goto fail;
146 if (parcel->readUint32(&window->mNumColumns)) goto fail;
147 if (parcel->readUint32(&window->mSize)) goto fail;
148
149 if ((window->mNumRows * window->mNumColumns * kSlotSizeBytes) > window->mSize) {
150 LOG(ERROR) << "Unexpected size " << window->mSize << " for " << window->mNumRows
151 << " rows and " << window->mNumColumns << " columns";
152 goto fail_silent;
153 }
Jeff Sharkey539fdff2020-09-23 21:43:23 -0600154
155 bool isAshmem;
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -0600156 if (parcel->readBool(&isAshmem)) goto fail;
Jeff Sharkey539fdff2020-09-23 21:43:23 -0600157 if (isAshmem) {
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -0600158 window->mAshmemFd = parcel->readFileDescriptor();
159 if (window->mAshmemFd < 0) {
160 LOG(ERROR) << "Failed readFileDescriptor";
161 goto fail_silent;
Jeff Brown0cde89f2011-10-10 14:50:10 -0700162 }
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -0600163
164 window->mAshmemFd = ::fcntl(window->mAshmemFd, F_DUPFD_CLOEXEC, 0);
165 if (window->mAshmemFd < 0) {
166 PLOG(ERROR) << "Failed F_DUPFD_CLOEXEC";
167 goto fail_silent;
168 }
169
170 window->mData = ::mmap(nullptr, window->mSize, PROT_READ, MAP_SHARED, window->mAshmemFd, 0);
171 if (window->mData == MAP_FAILED) {
172 PLOG(ERROR) << "Failed mmap";
173 goto fail_silent;
174 }
175 } else {
176 window->mAshmemFd = -1;
177
178 if (window->mSize > kInlineSize) {
179 LOG(ERROR) << "Unexpected size " << window->mSize << " for inline window";
180 goto fail_silent;
181 }
182
183 window->mData = malloc(window->mSize);
184 if (!window->mData) goto fail;
185
186 if (parcel->read(window->mData, window->mSize)) goto fail;
Jeff Brown0cde89f2011-10-10 14:50:10 -0700187 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800188
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -0600189 // We just came from a remote source, so we're read-only
190 // and we can't inflate ourselves
191 window->mInflatedSize = window->mSize;
192 window->mReadOnly = true;
Jeff Sharkey539fdff2020-09-23 21:43:23 -0600193
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -0600194 window->updateSlotsData();
Jeff Sharkey539fdff2020-09-23 21:43:23 -0600195
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -0600196 LOG(DEBUG) << "Created from parcel: " << window->toString();
197 *outWindow = window;
Jeff Sharkey539fdff2020-09-23 21:43:23 -0600198 return OK;
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -0600199
200fail:
201 LOG(ERROR) << "Failed createFromParcel";
202fail_silent:
203 delete window;
204 return UNKNOWN_ERROR;
Jeff Sharkey539fdff2020-09-23 21:43:23 -0600205}
206
Jeff Brown0cde89f2011-10-10 14:50:10 -0700207status_t CursorWindow::writeToParcel(Parcel* parcel) {
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -0600208 LOG(DEBUG) << "Writing to parcel: " << this->toString();
Jeff Sharkey539fdff2020-09-23 21:43:23 -0600209
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -0600210 if (parcel->writeString8(mName)) goto fail;
211 if (parcel->writeUint32(mNumRows)) goto fail;
212 if (parcel->writeUint32(mNumColumns)) goto fail;
Jeff Sharkey539fdff2020-09-23 21:43:23 -0600213 if (mAshmemFd != -1) {
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -0600214 if (parcel->writeUint32(mSize)) goto fail;
215 if (parcel->writeBool(true)) goto fail;
216 if (parcel->writeDupFileDescriptor(mAshmemFd)) goto fail;
Jeff Sharkey539fdff2020-09-23 21:43:23 -0600217 } else {
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -0600218 // Since we know we're going to be read-only on the remote side,
219 // we can compact ourselves on the wire, with just enough padding
220 // to ensure our slots stay aligned
221 size_t slotsSize = mSize - mSlotsOffset;
222 size_t compactedSize = mAllocOffset + slotsSize;
223 compactedSize = (compactedSize + 3) & ~3;
224 if (parcel->writeUint32(compactedSize)) goto fail;
225 if (parcel->writeBool(false)) goto fail;
226 void* dest = parcel->writeInplace(compactedSize);
227 if (!dest) goto fail;
228 memcpy(static_cast<uint8_t*>(dest),
229 static_cast<uint8_t*>(mData), mAllocOffset);
230 memcpy(static_cast<uint8_t*>(dest) + compactedSize - slotsSize,
231 static_cast<uint8_t*>(mData) + mSlotsOffset, slotsSize);
Jeff Brown0cde89f2011-10-10 14:50:10 -0700232 }
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -0600233 return OK;
Jeff Sharkey539fdff2020-09-23 21:43:23 -0600234
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -0600235fail:
236 LOG(ERROR) << "Failed writeToParcel";
237fail_silent:
238 return UNKNOWN_ERROR;
Jeff Brown0cde89f2011-10-10 14:50:10 -0700239}
240
241status_t CursorWindow::clear() {
242 if (mReadOnly) {
243 return INVALID_OPERATION;
244 }
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -0600245 mAllocOffset = 0;
246 mSlotsOffset = mSize;
247 mNumRows = 0;
248 mNumColumns = 0;
Jeff Brown0cde89f2011-10-10 14:50:10 -0700249 return OK;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800250}
251
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -0600252void CursorWindow::updateSlotsData() {
Jeff Sharkey256da5a2020-10-13 09:40:52 -0600253 mSlotsStart = static_cast<uint8_t*>(mData) + mSize - kSlotSizeBytes;
254 mSlotsEnd = static_cast<uint8_t*>(mData) + mSlotsOffset;
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -0600255}
256
257void* CursorWindow::offsetToPtr(uint32_t offset, uint32_t bufferSize = 0) {
258 if (offset > mSize) {
259 LOG(ERROR) << "Offset " << offset
260 << " out of bounds, max value " << mSize;
261 return nullptr;
262 }
263 if (offset + bufferSize > mSize) {
264 LOG(ERROR) << "End offset " << (offset + bufferSize)
265 << " out of bounds, max value " << mSize;
266 return nullptr;
267 }
268 return static_cast<uint8_t*>(mData) + offset;
269}
270
271uint32_t CursorWindow::offsetFromPtr(void* ptr) {
272 return static_cast<uint8_t*>(ptr) - static_cast<uint8_t*>(mData);
273}
274
Jeff Brown0cde89f2011-10-10 14:50:10 -0700275status_t CursorWindow::setNumColumns(uint32_t numColumns) {
276 if (mReadOnly) {
277 return INVALID_OPERATION;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278 }
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -0600279 uint32_t cur = mNumColumns;
280 if ((cur > 0 || mNumRows > 0) && cur != numColumns) {
281 LOG(ERROR) << "Trying to go from " << cur << " columns to " << numColumns;
Jeff Brown0cde89f2011-10-10 14:50:10 -0700282 return INVALID_OPERATION;
283 }
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -0600284 mNumColumns = numColumns;
Jeff Brown0cde89f2011-10-10 14:50:10 -0700285 return OK;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286}
287
Jeff Brown0cde89f2011-10-10 14:50:10 -0700288status_t CursorWindow::allocRow() {
289 if (mReadOnly) {
290 return INVALID_OPERATION;
291 }
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -0600292 size_t size = mNumColumns * kSlotSizeBytes;
Jeff Sharkeyb2bbdaa2020-10-20 13:19:04 -0600293 int32_t newOffset = mSlotsOffset - size;
294 if (newOffset < (int32_t) mAllocOffset) {
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -0600295 maybeInflate();
296 newOffset = mSlotsOffset - size;
Jeff Sharkeyb2bbdaa2020-10-20 13:19:04 -0600297 if (newOffset < (int32_t) mAllocOffset) {
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -0600298 return NO_MEMORY;
299 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800300 }
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -0600301 memset(offsetToPtr(newOffset), 0, size);
302 mSlotsOffset = newOffset;
Jeff Sharkey256da5a2020-10-13 09:40:52 -0600303 updateSlotsData();
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -0600304 mNumRows++;
Jeff Brown0cde89f2011-10-10 14:50:10 -0700305 return OK;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800306}
307
Jeff Brown0cde89f2011-10-10 14:50:10 -0700308status_t CursorWindow::freeLastRow() {
309 if (mReadOnly) {
310 return INVALID_OPERATION;
311 }
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -0600312 size_t size = mNumColumns * kSlotSizeBytes;
Jeff Sharkeyb2bbdaa2020-10-20 13:19:04 -0600313 size_t newOffset = mSlotsOffset + size;
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -0600314 if (newOffset > mSize) {
315 return NO_MEMORY;
Jeff Brown0cde89f2011-10-10 14:50:10 -0700316 }
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -0600317 mSlotsOffset = newOffset;
Jeff Sharkey256da5a2020-10-13 09:40:52 -0600318 updateSlotsData();
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -0600319 mNumRows--;
Jeff Brown0cde89f2011-10-10 14:50:10 -0700320 return OK;
321}
322
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -0600323status_t CursorWindow::alloc(size_t size, uint32_t* outOffset) {
324 if (mReadOnly) {
325 return INVALID_OPERATION;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800326 }
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -0600327 size_t alignedSize = (size + 3) & ~3;
Jeff Sharkeyb2bbdaa2020-10-20 13:19:04 -0600328 size_t newOffset = mAllocOffset + alignedSize;
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -0600329 if (newOffset > mSlotsOffset) {
330 maybeInflate();
331 newOffset = mAllocOffset + alignedSize;
332 if (newOffset > mSlotsOffset) {
333 return NO_MEMORY;
Jeff Sharkey539fdff2020-09-23 21:43:23 -0600334 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800335 }
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -0600336 *outOffset = mAllocOffset;
337 mAllocOffset = newOffset;
338 return OK;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800339}
340
Jeff Brown0cde89f2011-10-10 14:50:10 -0700341CursorWindow::FieldSlot* CursorWindow::getFieldSlot(uint32_t row, uint32_t column) {
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -0600342 // This is carefully tuned to use as few cycles as
343 // possible, since this is an extremely hot code path;
344 // see CursorWindow_bench.cpp for more details
Jeff Sharkey256da5a2020-10-13 09:40:52 -0600345 void *result = static_cast<uint8_t*>(mSlotsStart)
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -0600346 - (((row * mNumColumns) + column) << kSlotShift);
Jeff Sharkeyb2bbdaa2020-10-20 13:19:04 -0600347 if (result < mSlotsEnd || result > mSlotsStart || column >= mNumColumns) {
Jeff Sharkey256da5a2020-10-13 09:40:52 -0600348 LOG(ERROR) << "Failed to read row " << row << ", column " << column
349 << " from a window with " << mNumRows << " rows, " << mNumColumns << " columns";
350 return nullptr;
351 } else {
352 return static_cast<FieldSlot*>(result);
353 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800354}
355
Jeff Brown0cde89f2011-10-10 14:50:10 -0700356status_t CursorWindow::putBlob(uint32_t row, uint32_t column, const void* value, size_t size) {
357 return putBlobOrString(row, column, value, size, FIELD_TYPE_BLOB);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800358}
359
Jeff Brown0cde89f2011-10-10 14:50:10 -0700360status_t CursorWindow::putString(uint32_t row, uint32_t column, const char* value,
361 size_t sizeIncludingNull) {
362 return putBlobOrString(row, column, value, sizeIncludingNull, FIELD_TYPE_STRING);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800363}
364
Jeff Brown0cde89f2011-10-10 14:50:10 -0700365status_t CursorWindow::putBlobOrString(uint32_t row, uint32_t column,
366 const void* value, size_t size, int32_t type) {
367 if (mReadOnly) {
368 return INVALID_OPERATION;
369 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800370
Jeff Brown0cde89f2011-10-10 14:50:10 -0700371 FieldSlot* fieldSlot = getFieldSlot(row, column);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800372 if (!fieldSlot) {
Jeff Brown0cde89f2011-10-10 14:50:10 -0700373 return BAD_VALUE;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 }
375
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -0600376 uint32_t offset;
377 if (alloc(size, &offset)) {
Jeff Brown0cde89f2011-10-10 14:50:10 -0700378 return NO_MEMORY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800379 }
380
Jeff Brown0cde89f2011-10-10 14:50:10 -0700381 memcpy(offsetToPtr(offset), value, size);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800382
Jeff Sharkeyae2d88a2020-09-26 18:57:32 -0600383 fieldSlot = getFieldSlot(row, column);
Jeff Brown0cde89f2011-10-10 14:50:10 -0700384 fieldSlot->type = type;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800385 fieldSlot->data.buffer.offset = offset;
Jeff Brown0cde89f2011-10-10 14:50:10 -0700386 fieldSlot->data.buffer.size = size;
387 return OK;
388}
389
390status_t CursorWindow::putLong(uint32_t row, uint32_t column, int64_t value) {
391 if (mReadOnly) {
392 return INVALID_OPERATION;
393 }
394
395 FieldSlot* fieldSlot = getFieldSlot(row, column);
396 if (!fieldSlot) {
397 return BAD_VALUE;
398 }
399
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800400 fieldSlot->type = FIELD_TYPE_INTEGER;
Jeff Brown0cde89f2011-10-10 14:50:10 -0700401 fieldSlot->data.l = value;
402 return OK;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800403}
404
Jeff Brown0cde89f2011-10-10 14:50:10 -0700405status_t CursorWindow::putDouble(uint32_t row, uint32_t column, double value) {
406 if (mReadOnly) {
407 return INVALID_OPERATION;
408 }
409
410 FieldSlot* fieldSlot = getFieldSlot(row, column);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800411 if (!fieldSlot) {
Jeff Brown0cde89f2011-10-10 14:50:10 -0700412 return BAD_VALUE;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800413 }
414
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800415 fieldSlot->type = FIELD_TYPE_FLOAT;
Jeff Brown0cde89f2011-10-10 14:50:10 -0700416 fieldSlot->data.d = value;
417 return OK;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800418}
419
Jeff Brown0cde89f2011-10-10 14:50:10 -0700420status_t CursorWindow::putNull(uint32_t row, uint32_t column) {
421 if (mReadOnly) {
422 return INVALID_OPERATION;
423 }
424
425 FieldSlot* fieldSlot = getFieldSlot(row, column);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800426 if (!fieldSlot) {
Jeff Brown0cde89f2011-10-10 14:50:10 -0700427 return BAD_VALUE;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800428 }
429
430 fieldSlot->type = FIELD_TYPE_NULL;
431 fieldSlot->data.buffer.offset = 0;
432 fieldSlot->data.buffer.size = 0;
Jeff Brown0cde89f2011-10-10 14:50:10 -0700433 return OK;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800434}
435
436}; // namespace android