| /* |
| * Copyright (C) 2011 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| package android.database.sqlite; |
| |
| import android.os.StatFs; |
| |
| /** |
| * Provides access to SQLite functions that affect all database connection, |
| * such as memory management. |
| * |
| * The native code associated with SQLiteGlobal is also sets global configuration options |
| * using sqlite3_config() then calls sqlite3_initialize() to ensure that the SQLite |
| * library is properly initialized exactly once before any other framework or application |
| * code has a chance to run. |
| * |
| * Verbose SQLite logging is enabled if the "log.tag.SQLiteLog" property is set to "V". |
| * (per {@link SQLiteDebug#DEBUG_SQL_LOG}). |
| * |
| * @hide |
| */ |
| public final class SQLiteGlobal { |
| private static final String TAG = "SQLiteGlobal"; |
| |
| private static final Object sLock = new Object(); |
| private static int sDefaultPageSize; |
| |
| private static native int nativeReleaseMemory(); |
| |
| private SQLiteGlobal() { |
| } |
| |
| /** |
| * Attempts to release memory by pruning the SQLite page cache and other |
| * internal data structures. |
| * |
| * @return The number of bytes that were freed. |
| */ |
| public static int releaseMemory() { |
| return nativeReleaseMemory(); |
| } |
| |
| /** |
| * Gets the default page size to use when creating a database. |
| */ |
| public static int getDefaultPageSize() { |
| synchronized (sLock) { |
| if (sDefaultPageSize == 0) { |
| sDefaultPageSize = new StatFs("/data").getBlockSize(); |
| } |
| return sDefaultPageSize; |
| } |
| } |
| } |