| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.database.sqlite; |
| 18 |
|
| 19 |
import android.annotation.TestApi; |
| 20 |
import android.content.res.Resources; |
| 21 |
import android.os.StatFs; |
| 22 |
import android.os.SystemProperties; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
@TestApi |
| 39 |
public final class SQLiteGlobal { |
| 40 |
private static final String TAG = "SQLiteGlobal"; |
| 41 |
|
| 42 |
|
| 43 |
public static final String SYNC_MODE_FULL = "FULL"; |
| 44 |
|
| 45 |
|
| 46 |
static final String WIPE_CHECK_FILE_SUFFIX = "-wipecheck"; |
| 47 |
|
| 48 |
private static final Object sLock = new Object(); |
| 49 |
|
| 50 |
private static int sDefaultPageSize; |
| 51 |
|
| 52 |
private static native int nativeReleaseMemory(); |
| 53 |
|
| 54 |
|
| 55 |
public static volatile String sDefaultSyncMode; |
| 56 |
|
| 57 |
private SQLiteGlobal() { |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
public static int releaseMemory() { |
| 67 |
return nativeReleaseMemory(); |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
public static int getDefaultPageSize() { |
| 74 |
synchronized (sLock) { |
| 75 |
if (sDefaultPageSize == 0) { |
| 76 |
|
| 77 |
|
| 78 |
sDefaultPageSize = new StatFs("/data").getBlockSize(); |
| 79 |
} |
| 80 |
return SystemProperties.getInt("debug.sqlite.pagesize", sDefaultPageSize); |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
public static @SQLiteDatabase.JournalMode String getDefaultJournalMode() { |
| 88 |
return SystemProperties.get("debug.sqlite.journalmode", |
| 89 |
Resources.getSystem().getString( |
| 90 |
com.android.internal.R.string.db_default_journal_mode)); |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
public static int getJournalSizeLimit() { |
| 97 |
return SystemProperties.getInt("debug.sqlite.journalsizelimit", |
| 98 |
Resources.getSystem().getInteger( |
| 99 |
com.android.internal.R.integer.db_journal_size_limit)); |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
public static @SQLiteDatabase.SyncMode String getDefaultSyncMode() { |
| 106 |
|
| 107 |
String defaultMode = sDefaultSyncMode; |
| 108 |
if (defaultMode != null) { |
| 109 |
return defaultMode; |
| 110 |
} |
| 111 |
return SystemProperties.get("debug.sqlite.syncmode", |
| 112 |
Resources.getSystem().getString( |
| 113 |
com.android.internal.R.string.db_default_sync_mode)); |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
public static @SQLiteDatabase.SyncMode String getWALSyncMode() { |
| 120 |
|
| 121 |
String defaultMode = sDefaultSyncMode; |
| 122 |
if (defaultMode != null) { |
| 123 |
return defaultMode; |
| 124 |
} |
| 125 |
return SystemProperties.get("debug.sqlite.wal.syncmode", |
| 126 |
Resources.getSystem().getString( |
| 127 |
com.android.internal.R.string.db_wal_sync_mode)); |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
public static int getWALAutoCheckpoint() { |
| 134 |
int value = SystemProperties.getInt("debug.sqlite.wal.autocheckpoint", |
| 135 |
Resources.getSystem().getInteger( |
| 136 |
com.android.internal.R.integer.db_wal_autocheckpoint)); |
| 137 |
return Math.max(1, value); |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
public static int getWALConnectionPoolSize() { |
| 144 |
int value = SystemProperties.getInt("debug.sqlite.wal.poolsize", |
| 145 |
Resources.getSystem().getInteger( |
| 146 |
com.android.internal.R.integer.db_connection_pool_size)); |
| 147 |
return Math.max(2, value); |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
public static int getIdleConnectionTimeout() { |
| 155 |
return SystemProperties.getInt("debug.sqlite.idle_connection_timeout", |
| 156 |
Resources.getSystem().getInteger( |
| 157 |
com.android.internal.R.integer.db_default_idle_connection_timeout)); |
| 158 |
} |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
public static long getWALTruncateSize() { |
| 168 |
final long setting = SQLiteCompatibilityWalFlags.getTruncateSize(); |
| 169 |
if (setting >= 0) { |
| 170 |
return setting; |
| 171 |
} |
| 172 |
return SystemProperties.getInt("debug.sqlite.wal.truncatesize", |
| 173 |
Resources.getSystem().getInteger( |
| 174 |
com.android.internal.R.integer.db_wal_truncate_size)); |
| 175 |
} |
| 176 |
|
| 177 |
|
| 178 |
public static boolean checkDbWipe() { |
| 179 |
return false; |
| 180 |
} |
| 181 |
} |