├── .firebaserc ├── .github ├── FUNDING.yml ├── dependabot.yml └── workflows │ ├── build-pr.yml │ └── publish.yml ├── .gitignore ├── .opensource └── project.json ├── LICENSE ├── README.md ├── build.gradle.kts ├── firebase.json ├── gradle.properties ├── gradle ├── libs.versions.toml └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src ├── main └── java │ ├── android │ ├── app │ │ ├── Activity.kt │ │ ├── AlertDialog.java │ │ ├── Application.kt │ │ ├── Dialog.java │ │ ├── Fragment.kt │ │ └── Service.java │ ├── content │ │ ├── BroadcastReceiver.java │ │ ├── ComponentCallbacks.java │ │ ├── ComponentCallbacks2.java │ │ ├── ComponentName.java │ │ ├── ContentProvider.java │ │ ├── ContentResolver.java │ │ ├── ContentValues.java │ │ ├── Context.kt │ │ ├── DialogInterface.java │ │ ├── Intent.java │ │ ├── IntentFilter.java │ │ ├── SharedPreferences.java │ │ ├── pm │ │ │ ├── ApplicationInfo.java │ │ │ ├── PackageInfo.java │ │ │ ├── PackageManager.java │ │ │ ├── ResolveInfo.java │ │ │ └── ServiceInfo.java │ │ └── res │ │ │ └── Resources.java │ ├── database │ │ ├── AbstractCursor.java │ │ ├── AbstractWindowedCursor.java │ │ ├── ContentObservable.java │ │ ├── CrossProcessCursor.java │ │ ├── Cursor.java │ │ ├── CursorIndexOutOfBoundsException.java │ │ ├── CursorWindow.java │ │ ├── DataSetObservable.java │ │ ├── DatabaseErrorHandler.java │ │ ├── DatabaseUtils.java │ │ ├── DefaultDatabaseErrorHandler.java │ │ ├── Observable.java │ │ ├── SQLException.java │ │ ├── StaleDataException.java │ │ └── sqlite │ │ │ ├── CloseGuard.java │ │ │ ├── DatabaseObjectNotClosedException.java │ │ │ ├── SQLiteAbortException.java │ │ │ ├── SQLiteAccessPermException.java │ │ │ ├── SQLiteBindOrColumnIndexOutOfRangeException.java │ │ │ ├── SQLiteBlobTooBigException.java │ │ │ ├── SQLiteCantOpenDatabaseException.java │ │ │ ├── SQLiteClosable.java │ │ │ ├── SQLiteConnection.java │ │ │ ├── SQLiteConnectionPool.java │ │ │ ├── SQLiteConstraintException.java │ │ │ ├── SQLiteCursor.java │ │ │ ├── SQLiteCursorDriver.java │ │ │ ├── SQLiteCustomFunction.java │ │ │ ├── SQLiteDatabase.java │ │ │ ├── SQLiteDatabaseConfiguration.java │ │ │ ├── SQLiteDatabaseCorruptException.java │ │ │ ├── SQLiteDatabaseLockedException.java │ │ │ ├── SQLiteDatatypeMismatchException.java │ │ │ ├── SQLiteDebug.java │ │ │ ├── SQLiteDirectCursorDriver.java │ │ │ ├── SQLiteDiskIOException.java │ │ │ ├── SQLiteDoneException.java │ │ │ ├── SQLiteException.java │ │ │ ├── SQLiteFullException.java │ │ │ ├── SQLiteGlobal.java │ │ │ ├── SQLiteMisuseException.java │ │ │ ├── SQLiteOpenHelper.java │ │ │ ├── SQLiteOutOfMemoryException.java │ │ │ ├── SQLiteProgram.java │ │ │ ├── SQLiteQuery.java │ │ │ ├── SQLiteQueryBuilder.java │ │ │ ├── SQLiteReadOnlyDatabaseException.java │ │ │ ├── SQLiteSession.java │ │ │ ├── SQLiteStatement.java │ │ │ ├── SQLiteStatementInfo.java │ │ │ ├── SQLiteTableLockedException.java │ │ │ └── SQLiteTransactionListener.java │ ├── net │ │ ├── ConnectivityManager.kt │ │ ├── SSLCertificateSocketFactory.kt │ │ ├── SSLSessionCache.java │ │ └── Uri.kt │ ├── os │ │ ├── AsyncTask.kt │ │ ├── Binder.java │ │ ├── Build.java │ │ ├── Bundle.java │ │ ├── CancellationSignal.java │ │ ├── DeadObjectException.java │ │ ├── Handler.kt │ │ ├── HandlerThread.java │ │ ├── IBinder.java │ │ ├── IInterface.java │ │ ├── IMessenger.kt │ │ ├── Looper.java │ │ ├── Message.java │ │ ├── Messenger.java │ │ ├── OperationCanceledException.kt │ │ ├── Parcelable.java │ │ ├── PowerManager.java │ │ ├── Process.java │ │ ├── RemoteException.java │ │ ├── StatFs.java │ │ ├── StrictMode.java │ │ ├── SystemClock.java │ │ ├── Trace.java │ │ └── UserManager.java │ ├── text │ │ ├── Spannable.java │ │ ├── Spanned.java │ │ └── TextUtils.java │ ├── util │ │ ├── AndroidException.java │ │ ├── ArrayMap.java │ │ ├── Base64.java │ │ ├── Base64OutputStream.java │ │ ├── ContainerHelpers.java │ │ ├── Log.java │ │ ├── LruCache.java │ │ ├── MapCollections.java │ │ ├── Pair.java │ │ ├── SparseArray.java │ │ └── SparseIntArray.java │ ├── view │ │ └── View.java │ └── widget │ │ └── ProgressBar.java │ ├── com │ ├── android │ │ └── internal │ │ │ └── util │ │ │ ├── ArrayUtils.java │ │ │ └── GrowingArrayUtils.java │ └── google │ │ ├── android │ │ └── collect │ │ │ └── Lists.java │ │ └── firebase │ │ ├── FirebasePlatform.kt │ │ ├── annotations │ │ └── concurrent │ │ │ ├── Background.java │ │ │ ├── Blocking.java │ │ │ ├── Lightweight.java │ │ │ └── UiThread.java │ │ └── auth │ │ ├── ActionCodeEmailInfo.java │ │ ├── ActionCodeInfo.java │ │ ├── ActionCodeMultiFactorInfo.java │ │ ├── ActionCodeResult.java │ │ ├── AuthCredential.java │ │ ├── AuthResult.java │ │ ├── EmailAuthProvider.java │ │ ├── FacebookAuthProvider.java │ │ ├── FirebaseAuth.kt │ │ ├── FirebaseAuthActionCodeException.kt │ │ ├── FirebaseAuthEmailException.kt │ │ ├── FirebaseAuthInvalidCredentialsException.kt │ │ ├── FirebaseAuthInvalidUserException.kt │ │ ├── FirebaseAuthRecentLoginRequiredException.kt │ │ ├── FirebaseAuthRegistrar.java │ │ ├── FirebaseAuthUserCollisionException.kt │ │ ├── FirebaseAuthWeakPasswordException.kt │ │ ├── FirebaseAuthWebException.kt │ │ ├── FirebaseUser.kt │ │ ├── GithubAuthProvider.java │ │ ├── GoogleAuthProvider.java │ │ ├── OAuthProvider.java │ │ ├── PhoneAuthProvider.java │ │ ├── Stubs.kt │ │ ├── TwitterAuthProvider.java │ │ └── UserProfileChangeRequest.java │ ├── dalvik │ └── system │ │ ├── PathClassLoader.java │ │ └── VMRuntime.java │ ├── libcore │ └── util │ │ └── EmptyArray.java │ └── org │ ├── json │ ├── JSON.java │ ├── JSONArray.java │ ├── JSONException.java │ ├── JSONObject.java │ ├── JSONStringer.java │ └── JSONTokener.java │ └── sqlite │ └── core │ └── Native.kt └── test ├── kotlin ├── AppTest.kt ├── AuthTest.kt ├── FirebaseTest.kt └── FirestoreTest.kt └── resources └── firebase_data ├── auth_export ├── accounts.json └── config.json └── firebase-export-metadata.json /.firebaserc: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [GitLiveApp] 2 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "gradle" 4 | directory: "/" 5 | schedule: 6 | interval: "weekly" 7 | - package-ecosystem: "github-actions" 8 | directory: "/" 9 | schedule: 10 | interval: "weekly" 11 | -------------------------------------------------------------------------------- /.github/workflows/build-pr.yml: -------------------------------------------------------------------------------- 1 | name: Build and test on PRs 2 | on: pull_request 3 | 4 | jobs: 5 | gradle: 6 | name: Build and Test 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v4 10 | - uses: actions/setup-java@v4 11 | with: 12 | distribution: 'zulu' 13 | java-version: 17 14 | - name: Set up Node.js 20 15 | uses: actions/setup-node@v4 16 | with: 17 | node-version: 20 18 | - name: Install Firebase CLI 19 | run: npm install -g firebase-tools 20 | - name: Build 21 | run: firebase emulators:exec --project my-firebase-project --import=src/test/resources/firebase_data './gradlew build' 22 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Gradle 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle 3 | 4 | name: Publish 5 | 6 | on: 7 | release: 8 | types: [ prereleased, released ] 9 | 10 | env: 11 | sonatypeUsername: ${{ secrets.SONATYPEUSERNAME }} 12 | sonatypePassword: ${{ secrets.SONATYPEPASSWORD }} 13 | ORG_GRADLE_PROJECT_signingKey: ${{ secrets.GPG_PRIVATE_KEY }} 14 | ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.PASSPHRASE }} 15 | 16 | jobs: 17 | build: 18 | runs-on: ubuntu-latest 19 | steps: 20 | - uses: actions/checkout@v4 21 | - name: Set up JDK 22 | uses: actions/setup-java@v4 23 | with: 24 | distribution: 'zulu' 25 | java-version: '17' 26 | - name: CopyAars 27 | uses: eskatos/gradle-command-action@v3 28 | with: 29 | arguments: copyAars 30 | - name: Grant execute permission for gradlew 31 | run: chmod +x gradlew 32 | - name: Publish 33 | run: ./gradlew publish 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .gradle/ 3 | .kotlin/ 4 | build/ 5 | *.iml 6 | /local.properties 7 | /.DS_Store 8 | 9 | -------------------------------------------------------------------------------- /.opensource/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Firebase Java SDK (unofficial)", 3 | "platforms": ["Desktop"], 4 | "content": "README.md", 5 | "related": [ 6 | "GitLive/firebase-kotlin-sdk", 7 | "firebase/firebase-android-sdk", 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | import java.util.Locale 2 | 3 | buildscript { 4 | repositories { 5 | google() 6 | mavenCentral() 7 | } 8 | } 9 | 10 | repositories { 11 | mavenLocal() 12 | mavenCentral() 13 | google() 14 | } 15 | 16 | plugins { 17 | `java-library` 18 | `maven-publish` 19 | signing 20 | alias(libs.plugins.kotlin.jvm) 21 | alias(libs.plugins.kotlinx.serialization) 22 | alias(libs.plugins.jlleitschuh.ktlint) 23 | alias(libs.plugins.ben.manes.versions) 24 | } 25 | 26 | group = "dev.gitlive" 27 | version = project.property("version") as String 28 | 29 | java { 30 | withSourcesJar() 31 | withJavadocJar() 32 | sourceCompatibility = JavaVersion.VERSION_17 33 | } 34 | 35 | val aar by configurations.creating 36 | 37 | val copyAars by tasks.registering(Copy::class) { 38 | mkdir("build/aar") 39 | from(configurations["aar"]) { 40 | include("*.aar") 41 | } 42 | into("build/aar") 43 | } 44 | 45 | val extractClasses by tasks.registering(Copy::class) { 46 | dependsOn(copyAars) 47 | configurations["aar"].forEach { aarFile -> 48 | copy { 49 | from(zipTree(aarFile)) 50 | include("classes.jar") 51 | fileMode = 0b01110110000 52 | rename("classes.jar", aarFile.nameWithoutExtension + ".jar") 53 | into("build/jar") 54 | } 55 | } 56 | } 57 | 58 | tasks { 59 | compileKotlin { 60 | dependsOn(extractClasses) 61 | kotlinOptions { 62 | jvmTarget = JavaVersion.VERSION_17.toString() 63 | } 64 | } 65 | compileTestKotlin { 66 | kotlinOptions { 67 | jvmTarget = JavaVersion.VERSION_17.toString() 68 | } 69 | } 70 | withType().configureEach { 71 | onlyIf { !project.gradle.startParameter.taskNames.any { "MavenLocal" in it } } 72 | } 73 | javadoc { 74 | exclude("android/**", "libcore/util/**") 75 | } 76 | } 77 | 78 | val jar by tasks.getting(Jar::class) { 79 | dependsOn(configurations.runtimeClasspath) 80 | from({ 81 | configurations.runtimeClasspath.get().filter { 82 | it.path.startsWith("${projectDir.path}${File.separator}build${File.separator}jar") 83 | }.map { zipTree(it) } 84 | }) 85 | } 86 | 87 | val sourceSets = project.the() 88 | 89 | val cleanLibs by tasks.creating(Delete::class) { 90 | delete("$${layout.buildDirectory.asFile.get().path}/libs") 91 | } 92 | 93 | publishing { 94 | 95 | repositories { 96 | maven { 97 | url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2") 98 | credentials { 99 | username = project.findProperty("sonatypeUsername") as String? ?: System.getenv("sonatypeUsername") 100 | password = project.findProperty("sonatypePassword") as String? ?: System.getenv("sonatypePassword") 101 | } 102 | } 103 | } 104 | 105 | publications { 106 | create("library") { 107 | from(components["java"]) 108 | 109 | pom { 110 | name.set("firebase-java-sdk") 111 | description.set("The Firebase Java SDK is a pure java port of the Firebase Android SDK to run in clientside java environments such as the desktop.") 112 | url.set("https://github.com/GitLiveApp/firebase-java-sdk") 113 | inceptionYear.set("2023") 114 | 115 | scm { 116 | url.set("https://github.com/GitLiveApp/firebase-java-sdk") 117 | connection.set("scm:git:https://github.com/GitLiveApp/firebase-java-sdk.git") 118 | developerConnection.set("scm:git:https://github.com/GitLiveApp/firebase-java-sdk.git") 119 | tag.set("HEAD") 120 | } 121 | 122 | issueManagement { 123 | system.set("GitHub Issues") 124 | url.set("https://github.com/GitLiveApp/firebase-java-sdk/issues") 125 | } 126 | 127 | developers { 128 | developer { 129 | name.set("Nicholas Bransby-Williams") 130 | email.set("nbransby@gmail.com") 131 | } 132 | } 133 | 134 | licenses { 135 | license { 136 | name.set("The Apache Software License, Version 2.0") 137 | url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") 138 | distribution.set("repo") 139 | comments.set("A business-friendly OSS license") 140 | } 141 | } 142 | } 143 | } 144 | } 145 | } 146 | 147 | dependencies { 148 | compileOnly(libs.robolectric.android.all) 149 | testImplementation(libs.junit) 150 | testImplementation(libs.kotlinx.coroutines.play.services) 151 | testImplementation(libs.kotlinx.coroutines.swing) 152 | testImplementation(libs.kotlinx.coroutines.test) 153 | // firebase aars 154 | aar(platform(libs.google.firebase.bom)) 155 | aar(libs.google.firebase.firestore) 156 | aar(libs.google.firebase.functions) 157 | aar(libs.google.firebase.database) 158 | aar(libs.google.firebase.config) 159 | aar(libs.google.firebase.installations) 160 | // extracted aar dependencies 161 | // exclude lifecycle libs due to https://github.com/GitLiveApp/firebase-java-sdk/pull/15 - remove the exclude once the dependencies in the aars are updated to the required version 162 | api(fileTree(mapOf("dir" to "build/jar", "include" to listOf("*.jar"), "exclude" to listOf("lifecycle-*")))) 163 | // polyfill dependencies 164 | implementation(libs.kotlinx.coroutines.core) 165 | implementation(libs.kotlinx.serialization.core) 166 | implementation(libs.kotlinx.serialization.json) 167 | implementation(libs.xerial.sqlite.jdbc) 168 | // firebase dependencies 169 | implementation(libs.javax.inject) 170 | implementation(libs.okhttp) 171 | implementation(libs.io.grpc.protobuf.lite) 172 | implementation(libs.io.grpc.stub) 173 | implementation(libs.androidx.collection) 174 | implementation(libs.io.grpc.okhttp) 175 | implementation(libs.androidx.lifecycle.common) 176 | implementation(libs.androidx.lifecycle.viewmodel) 177 | } 178 | 179 | tasks.named("publishToMavenLocal").configure { 180 | dependsOn(cleanLibs, jar) 181 | } 182 | 183 | tasks.named("publish").configure { 184 | dependsOn(cleanLibs) 185 | } 186 | 187 | ktlint { 188 | version.set(libs.versions.ktlint.get()) 189 | } 190 | 191 | signing { 192 | val signingKey: String? by project 193 | val signingPassword: String? by project 194 | useInMemoryPgpKeys(signingKey, signingPassword) 195 | sign(publishing.publications) 196 | } 197 | 198 | tasks.withType { 199 | 200 | fun isNonStable(version: String): Boolean { 201 | val stableKeyword = listOf("RELEASE", "FINAL", "GA") 202 | .any { version.uppercase(Locale.ROOT).contains(it) } 203 | val versionMatch = "^[0-9,.v-]+(-r)?$".toRegex().matches(version) 204 | 205 | return (stableKeyword || versionMatch).not() 206 | } 207 | 208 | rejectVersionIf { 209 | isNonStable(candidate.version) 210 | } 211 | 212 | checkForGradleUpdate = true 213 | outputFormatter = "plain,html" 214 | outputDir = "build/dependency-reports" 215 | reportfileName = "dependency-updates" 216 | } 217 | -------------------------------------------------------------------------------- /firebase.json: -------------------------------------------------------------------------------- 1 | { 2 | "emulators": { 3 | "auth": { 4 | "port": 9099 5 | }, 6 | "ui": { 7 | "enabled": true 8 | }, 9 | "singleProjectMode": true 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | version=0.4.8 2 | -------------------------------------------------------------------------------- /gradle/libs.versions.toml: -------------------------------------------------------------------------------- 1 | [versions] 2 | androidx-lifecycle = "2.9.0-alpha01" 3 | ben-manes-versions = "0.51.0" 4 | google-firebase-bom = "32.7.0" 5 | io-grpc = "1.66.0" 6 | jlleitschuh-ktlint = "12.1.1" 7 | kotlin = "2.0.20" 8 | kotlinx-coroutines = "1.8.1" 9 | kotlinx-serialization = "1.7.2" 10 | ktlint = "0.47.1" 11 | 12 | [libraries] 13 | androidx-collection = { module = "androidx.collection:collection", version = "1.4.3" } 14 | androidx-lifecycle-common = { module = "androidx.lifecycle:lifecycle-common", version.ref = "androidx-lifecycle" } 15 | androidx-lifecycle-viewmodel = { module = "androidx.lifecycle:lifecycle-viewmodel", version.ref = "androidx-lifecycle" } 16 | google-firebase-bom = { module = "com.google.firebase:firebase-bom", version.ref = "google-firebase-bom" } 17 | google-firebase-config = { module = "com.google.firebase:firebase-config" } 18 | google-firebase-database = { module = "com.google.firebase:firebase-database" } 19 | google-firebase-firestore = { module = "com.google.firebase:firebase-firestore" } 20 | google-firebase-functions = { module = "com.google.firebase:firebase-functions" } 21 | google-firebase-installations = { module = "com.google.firebase:firebase-installations" } 22 | io-grpc-okhttp = { module = "io.grpc:grpc-okhttp", version.ref = "io-grpc" } 23 | io-grpc-protobuf-lite = { module = "io.grpc:grpc-protobuf-lite", version.ref = "io-grpc" } 24 | io-grpc-stub = { module = "io.grpc:grpc-stub", version.ref = "io-grpc" } 25 | javax-inject = { module = "javax.inject:javax.inject", version = "1" } 26 | junit = { module = "junit:junit", version = "4.13.2" } 27 | kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" } 28 | kotlinx-coroutines-play-services = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-play-services", version.ref = "kotlinx-coroutines" } 29 | kotlinx-coroutines-swing = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-swing", version.ref = "kotlinx-coroutines" } 30 | kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinx-coroutines" } 31 | kotlinx-serialization-core = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core", version.ref = "kotlinx-serialization" } 32 | kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization" } 33 | okhttp = { module = "com.squareup.okhttp3:okhttp", version = "3.12.13" } 34 | robolectric-android-all = { module = "org.robolectric:android-all", version = "14-robolectric-10818077" } 35 | xerial-sqlite-jdbc = { module = "org.xerial:sqlite-jdbc", version = "3.46.1.0" } 36 | 37 | [plugins] 38 | ben-manes-versions = { id = "com.github.ben-manes.versions", version.ref = "ben-manes-versions" } 39 | jlleitschuh-ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "jlleitschuh-ktlint" } 40 | kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } 41 | kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } 42 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GitLiveApp/firebase-java-sdk/07a7140a1d225c88b39a317e017d8476ec44a3cb/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | @rem SPDX-License-Identifier: Apache-2.0 17 | @rem 18 | 19 | @if "%DEBUG%"=="" @echo off 20 | @rem ########################################################################## 21 | @rem 22 | @rem Gradle startup script for Windows 23 | @rem 24 | @rem ########################################################################## 25 | 26 | @rem Set local scope for the variables with windows NT shell 27 | if "%OS%"=="Windows_NT" setlocal 28 | 29 | set DIRNAME=%~dp0 30 | if "%DIRNAME%"=="" set DIRNAME=. 31 | @rem This is normally unused 32 | set APP_BASE_NAME=%~n0 33 | set APP_HOME=%DIRNAME% 34 | 35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 37 | 38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 40 | 41 | @rem Find java.exe 42 | if defined JAVA_HOME goto findJavaFromJavaHome 43 | 44 | set JAVA_EXE=java.exe 45 | %JAVA_EXE% -version >NUL 2>&1 46 | if %ERRORLEVEL% equ 0 goto execute 47 | 48 | echo. 1>&2 49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 50 | echo. 1>&2 51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 52 | echo location of your Java installation. 1>&2 53 | 54 | goto fail 55 | 56 | :findJavaFromJavaHome 57 | set JAVA_HOME=%JAVA_HOME:"=% 58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 59 | 60 | if exist "%JAVA_EXE%" goto execute 61 | 62 | echo. 1>&2 63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 64 | echo. 1>&2 65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 66 | echo location of your Java installation. 1>&2 67 | 68 | goto fail 69 | 70 | :execute 71 | @rem Setup the command line 72 | 73 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 74 | 75 | 76 | @rem Execute Gradle 77 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 78 | 79 | :end 80 | @rem End local scope for the variables with windows NT shell 81 | if %ERRORLEVEL% equ 0 goto mainEnd 82 | 83 | :fail 84 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 85 | rem the _cmd.exe /c_ return code! 86 | set EXIT_CODE=%ERRORLEVEL% 87 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 88 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 89 | exit /b %EXIT_CODE% 90 | 91 | :mainEnd 92 | if "%OS%"=="Windows_NT" endlocal 93 | 94 | :omega 95 | -------------------------------------------------------------------------------- /src/main/java/android/app/Activity.kt: -------------------------------------------------------------------------------- 1 | package android.app 2 | 3 | import android.content.Context 4 | 5 | class Activity : Context() 6 | -------------------------------------------------------------------------------- /src/main/java/android/app/AlertDialog.java: -------------------------------------------------------------------------------- 1 | package android.app; 2 | 3 | public class AlertDialog extends Dialog { 4 | } 5 | -------------------------------------------------------------------------------- /src/main/java/android/app/Application.kt: -------------------------------------------------------------------------------- 1 | package android.app 2 | 3 | import android.content.ComponentCallbacks 4 | import android.content.Context 5 | 6 | class Application : Context() { 7 | var minSdkVersion: Int = 0 8 | var targetSdkVersion: Int = 0 9 | 10 | fun registerActivityLifecycleCallbacks(callbacks: ActivityLifecycleCallbacks) { 11 | } 12 | 13 | fun registerComponentCallbacks(callbacks: ComponentCallbacks) { 14 | } 15 | 16 | interface ActivityLifecycleCallbacks 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/android/app/Dialog.java: -------------------------------------------------------------------------------- 1 | package android.app; 2 | 3 | public class Dialog { 4 | } 5 | -------------------------------------------------------------------------------- /src/main/java/android/app/Fragment.kt: -------------------------------------------------------------------------------- 1 | package android.app 2 | 3 | open class Fragment 4 | -------------------------------------------------------------------------------- /src/main/java/android/app/Service.java: -------------------------------------------------------------------------------- 1 | package android.app; 2 | 3 | public class Service { 4 | } 5 | -------------------------------------------------------------------------------- /src/main/java/android/content/BroadcastReceiver.java: -------------------------------------------------------------------------------- 1 | package android.content; 2 | 3 | public class BroadcastReceiver { 4 | } 5 | -------------------------------------------------------------------------------- /src/main/java/android/content/ComponentCallbacks.java: -------------------------------------------------------------------------------- 1 | package android.content; 2 | 3 | public interface ComponentCallbacks { 4 | } 5 | -------------------------------------------------------------------------------- /src/main/java/android/content/ComponentCallbacks2.java: -------------------------------------------------------------------------------- 1 | package android.content; 2 | 3 | public interface ComponentCallbacks2 { 4 | } 5 | -------------------------------------------------------------------------------- /src/main/java/android/content/ComponentName.java: -------------------------------------------------------------------------------- 1 | package android.content; 2 | 3 | public class ComponentName { 4 | 5 | public final String pkg; 6 | public final String cls; 7 | 8 | public ComponentName(String pkg, String cls) { 9 | this.pkg = pkg; 10 | this.cls = cls; 11 | } 12 | 13 | public ComponentName(Context context, Class cls) { 14 | this.pkg = null; 15 | this.cls = cls.getName(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/android/content/ContentProvider.java: -------------------------------------------------------------------------------- 1 | package android.content; 2 | 3 | public abstract class ContentProvider { 4 | } 5 | -------------------------------------------------------------------------------- /src/main/java/android/content/ContentResolver.java: -------------------------------------------------------------------------------- 1 | package android.content; 2 | 3 | public class ContentResolver { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/android/content/Context.kt: -------------------------------------------------------------------------------- 1 | package android.content 2 | 3 | import android.content.SharedPreferences.Editor 4 | import android.content.pm.ApplicationInfo 5 | import android.content.pm.PackageManager 6 | import android.content.res.Resources 7 | import android.net.ConnectivityManager 8 | import android.os.Looper 9 | import android.os.PowerManager 10 | import android.os.UserManager 11 | import com.google.firebase.FirebasePlatform 12 | import java.io.File 13 | 14 | open class Context { 15 | 16 | val applicationContext: Context 17 | get() = this 18 | 19 | val mainLooper: Looper 20 | get() = Looper.getMainLooper() 21 | 22 | val packageName: String 23 | get() = "app.teamhub.TeamHub" 24 | 25 | val resources: Resources 26 | get() = Resources() 27 | 28 | val packageManager: PackageManager 29 | get() = PackageManager() 30 | 31 | val isDeviceProtectedStorage: Boolean 32 | get() = false 33 | 34 | val noBackupFilesDir: File 35 | get() = File(System.getProperty("java.io.tmpdir")) 36 | 37 | val classLoader: ClassLoader 38 | get() = ClassLoader.getSystemClassLoader() 39 | 40 | val contentResolver: ContentResolver 41 | get() = ContentResolver() 42 | 43 | val applicationInfo: ApplicationInfo = ApplicationInfo() 44 | 45 | fun getSharedPreferences(name: String, mode: Int): SharedPreferences { 46 | return object : SharedPreferences { 47 | override fun contains(key: String): Boolean { 48 | when (key) { 49 | "firebase_data_collection_default_enabled" -> return false 50 | "auto_init" -> return false 51 | "firebase_messaging_auto_init_enabled" -> return false 52 | "fire-fst" -> return false 53 | "fire-global" -> return !FirebasePlatform.firebasePlatform.retrieve(key).isNullOrEmpty() 54 | } 55 | throw IllegalArgumentException(key) 56 | } 57 | 58 | override fun getString(key: String, defaultValue: String?): String? { 59 | return when { 60 | key == "last-used-date" -> FirebasePlatform.firebasePlatform.retrieve(key) ?: defaultValue 61 | key.contains("|T|") -> null 62 | key.startsWith("com.google.firebase.auth.FIREBASE_USER") -> 63 | FirebasePlatform.firebasePlatform.retrieve(key) ?: defaultValue 64 | else -> throw IllegalArgumentException(key) 65 | } 66 | } 67 | 68 | override fun getLong(key: String?, defaultValue: Long): Long { 69 | when (key) { 70 | "fire-global" -> return FirebasePlatform.firebasePlatform.retrieve(key)?.toLong() ?: defaultValue 71 | } 72 | throw IllegalArgumentException(key) 73 | } 74 | 75 | override fun getAll(): Map { 76 | return emptyMap() 77 | } 78 | 79 | override fun edit(): Editor { 80 | return object : Editor { 81 | override fun putLong(key: String?, value: Long): Editor { 82 | when (key) { 83 | "fire-global" -> FirebasePlatform.firebasePlatform.store(key, value.toString()) 84 | else -> throw IllegalArgumentException(key) 85 | } 86 | return this 87 | } 88 | 89 | override fun putString(key: String?, value: String?): Editor { 90 | when (key) { 91 | "last-used-date" -> FirebasePlatform.firebasePlatform.store(key, value.toString()) 92 | else -> if (key?.startsWith("com.google.firebase.auth.FIREBASE_USER") == true) { 93 | FirebasePlatform.firebasePlatform.store(key, value.toString()) 94 | } else { 95 | throw IllegalArgumentException(key) 96 | } 97 | } 98 | return this 99 | } 100 | 101 | override fun commit(): Boolean { 102 | // Don't need to commit as changes are committed in the put method 103 | return true 104 | } 105 | 106 | override fun apply() { 107 | // Don't need to apply as changes are applied in the put method 108 | } 109 | } 110 | } 111 | } 112 | } 113 | 114 | fun getSystemService(name: String): Any { 115 | when (name) { 116 | "power" -> return PowerManager() 117 | CONNECTIVITY_SERVICE -> return ConnectivityManager.instance 118 | } 119 | throw IllegalArgumentException(name) 120 | } 121 | 122 | fun getSystemService(clazz: Class<*>): Any { 123 | when (clazz) { 124 | UserManager::class.java -> return UserManager() 125 | } 126 | throw IllegalArgumentException(clazz.toString()) 127 | } 128 | 129 | fun getDir(path: String, flags: Int): File { 130 | return File(System.getProperty("java.io.tmpdir")) 131 | } 132 | 133 | fun getDatabasePath(name: String): File = FirebasePlatform.firebasePlatform.getDatabasePath(name) 134 | 135 | companion object { 136 | @JvmStatic 137 | val CONNECTIVITY_SERVICE = "connectivity" 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /src/main/java/android/content/DialogInterface.java: -------------------------------------------------------------------------------- 1 | package android.content; 2 | 3 | public interface DialogInterface { 4 | interface OnCancelListener { 5 | 6 | } 7 | interface OnClickListener { 8 | 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/android/content/Intent.java: -------------------------------------------------------------------------------- 1 | package android.content; 2 | 3 | public class Intent { 4 | private final String action; 5 | private String _package; 6 | 7 | public Intent(String action) { 8 | this.action = action; 9 | } 10 | 11 | public Intent setPackage(String p) { 12 | this._package = p; 13 | return this; 14 | } 15 | 16 | public String getAction() { 17 | return action; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/android/content/IntentFilter.java: -------------------------------------------------------------------------------- 1 | package android.content; 2 | 3 | public class IntentFilter { 4 | public IntentFilter(String name) { 5 | 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/android/content/SharedPreferences.java: -------------------------------------------------------------------------------- 1 | package android.content; 2 | 3 | import java.util.Map; 4 | 5 | public interface SharedPreferences { 6 | 7 | boolean contains(String key); 8 | String getString(String key, String defaultValue); 9 | Map getAll(); 10 | long getLong(String key, long defValue); 11 | 12 | Editor edit(); 13 | 14 | interface Editor { 15 | Editor putLong(String key, long value); 16 | Editor putString(String key, String value); 17 | boolean commit(); 18 | void apply(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/android/content/pm/ApplicationInfo.java: -------------------------------------------------------------------------------- 1 | package android.content.pm; 2 | 3 | import java.util.Collections; 4 | import java.util.Map; 5 | 6 | public class ApplicationInfo extends ServiceInfo { 7 | public ApplicationInfo() { super(Collections.emptyMap()); } 8 | public ApplicationInfo(Map data) { 9 | super(data); 10 | } 11 | 12 | public int minSdkVersion; 13 | public int targetSdkVersion; 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/android/content/pm/PackageInfo.java: -------------------------------------------------------------------------------- 1 | package android.content.pm; 2 | 3 | public class PackageInfo { 4 | public String PackageItemInfo; 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/android/content/pm/PackageManager.java: -------------------------------------------------------------------------------- 1 | package android.content.pm; 2 | 3 | import android.content.ComponentName; 4 | import android.content.Intent; 5 | import android.util.AndroidException; 6 | 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | 10 | public class PackageManager { 11 | 12 | public ApplicationInfo getApplicationInfo(String packageName, int flags) throws NameNotFoundException { 13 | Map data = new HashMap<>(); 14 | data.put("com.google.app.id", "app.teamhub.TeamHub"); 15 | data.put("packageName", "app.teamhub.TeamHub"); 16 | data.put("com.google.android.gms.version", 12451000); 17 | data.put("firebase_data_collection_default_enabled", false); 18 | data.put("firebase_messaging_auto_init_enabled", false); 19 | return new ApplicationInfo(data); 20 | } 21 | 22 | public static class NameNotFoundException extends AndroidException { 23 | public NameNotFoundException() { 24 | } 25 | 26 | public NameNotFoundException(String name) { 27 | super(name); 28 | } 29 | } 30 | 31 | public ServiceInfo getServiceInfo(ComponentName component, int flags) throws NameNotFoundException { 32 | switch(component.cls) { 33 | case "com.google.firebase.components.ComponentDiscoveryService": 34 | Map data = new HashMap<>(); 35 | data.put("com.google.firebase.components.ComponentRegistrar", Boolean.TRUE); 36 | data.put("com.google.firebase.components:com.google.firebase.database.DatabaseRegistrar", "com.google.firebase.components.ComponentRegistrar"); 37 | data.put("com.google.firebase.components:com.google.firebase.firestore.FirestoreRegistrar", "com.google.firebase.components.ComponentRegistrar"); 38 | data.put("com.google.firebase.components:com.google.firebase.auth.FirebaseAuthRegistrar", "com.google.firebase.components.ComponentRegistrar"); 39 | data.put("com.google.firebase.components:com.google.firebase.functions.FunctionsRegistrar", "com.google.firebase.components.ComponentRegistrar"); 40 | data.put("com.google.firebase.components:com.google.firebase.installations.FirebaseInstallationsRegistrar", "com.google.firebase.components.ComponentRegistrar"); 41 | data.put("com.google.firebase.components:com.google.firebase.iid.Registrar", "com.google.firebase.components.ComponentRegistrar"); 42 | return new ServiceInfo(data); 43 | } 44 | throw new IllegalArgumentException(component.cls); 45 | } 46 | 47 | public ResolveInfo resolveService(Intent intent, int flags) { 48 | switch (intent.getAction()) { 49 | case "com.google.firebase.MESSAGING_EVENT": 50 | return null; //new ResolveInfo(); 51 | 52 | } 53 | throw new IllegalArgumentException(intent.getAction()); 54 | } 55 | 56 | public PackageInfo getPackageInfo(String name, int flags) throws NameNotFoundException { 57 | throw new NameNotFoundException(); 58 | } 59 | 60 | public String getInstallerPackageName(String var1) throws NameNotFoundException { 61 | return (String) getApplicationInfo("", 0).metaData.get("packageName"); 62 | } 63 | 64 | public boolean hasSystemFeature(String name) { 65 | switch(name) { 66 | case "android.hardware.type.watch": 67 | case "android.hardware.type.iot": 68 | case "android.hardware.type.embedded": 69 | case "android.hardware.type.television": 70 | case "android.hardware.type.automotive": 71 | case "cn.google": 72 | return false; 73 | } 74 | throw new IllegalArgumentException(name); 75 | 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/android/content/pm/ResolveInfo.java: -------------------------------------------------------------------------------- 1 | package android.content.pm; 2 | 3 | public class ResolveInfo { 4 | } 5 | -------------------------------------------------------------------------------- /src/main/java/android/content/pm/ServiceInfo.java: -------------------------------------------------------------------------------- 1 | package android.content.pm; 2 | 3 | import android.os.Bundle; 4 | 5 | import java.util.Map; 6 | 7 | public class ServiceInfo { 8 | 9 | public ServiceInfo(Map data) { 10 | metaData = new Bundle(data); 11 | } 12 | 13 | public Bundle metaData; 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/android/content/res/Resources.java: -------------------------------------------------------------------------------- 1 | package android.content.res; 2 | 3 | public class Resources { 4 | public static class NotFoundException extends RuntimeException { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/android/database/AbstractWindowedCursor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 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 android.database; 18 | 19 | /** 20 | * A base class for Cursors that store their data in {@link CursorWindow}s. 21 | *

22 | * The cursor owns the cursor window it uses. When the cursor is closed, 23 | * its window is also closed. Likewise, when the window used by the cursor is 24 | * changed, its old window is closed. This policy of strict ownership ensures 25 | * that cursor windows are not leaked. 26 | *

27 | * Subclasses are responsible for filling the cursor window with data during 28 | * {@link #onMove(int, int)}, allocating a new cursor window if necessary. 29 | * During {@link #requery()}, the existing cursor window should be cleared and 30 | * filled with new data. 31 | *

32 | * If the contents of the cursor change or become invalid, the old window must be closed 33 | * (because it is owned by the cursor) and set to null. 34 | *

35 | */ 36 | public abstract class AbstractWindowedCursor extends AbstractCursor { 37 | /** 38 | * The cursor window owned by this cursor. 39 | */ 40 | protected CursorWindow mWindow; 41 | 42 | @Override 43 | public byte[] getBlob(int columnIndex) { 44 | checkPosition(); 45 | return mWindow.getBlob(mPos, columnIndex); 46 | } 47 | 48 | @Override 49 | public String getString(int columnIndex) { 50 | checkPosition(); 51 | return mWindow.getString(mPos, columnIndex); 52 | } 53 | 54 | @Override 55 | public short getShort(int columnIndex) { 56 | checkPosition(); 57 | return mWindow.getShort(mPos, columnIndex); 58 | } 59 | 60 | @Override 61 | public int getInt(int columnIndex) { 62 | checkPosition(); 63 | return mWindow.getInt(mPos, columnIndex); 64 | } 65 | 66 | @Override 67 | public long getLong(int columnIndex) { 68 | checkPosition(); 69 | return mWindow.getLong(mPos, columnIndex); 70 | } 71 | 72 | @Override 73 | public float getFloat(int columnIndex) { 74 | checkPosition(); 75 | return mWindow.getFloat(mPos, columnIndex); 76 | } 77 | 78 | @Override 79 | public double getDouble(int columnIndex) { 80 | checkPosition(); 81 | return mWindow.getDouble(mPos, columnIndex); 82 | } 83 | 84 | @Override 85 | public boolean isNull(int columnIndex) { 86 | checkPosition(); 87 | return mWindow.getType(mPos, columnIndex) == Cursor.FIELD_TYPE_NULL; 88 | } 89 | 90 | /** 91 | * @deprecated Use {@link #getType} 92 | */ 93 | @Deprecated 94 | public boolean isBlob(int columnIndex) { 95 | return getType(columnIndex) == Cursor.FIELD_TYPE_BLOB; 96 | } 97 | 98 | /** 99 | * @deprecated Use {@link #getType} 100 | */ 101 | @Deprecated 102 | public boolean isString(int columnIndex) { 103 | return getType(columnIndex) == Cursor.FIELD_TYPE_STRING; 104 | } 105 | 106 | /** 107 | * @deprecated Use {@link #getType} 108 | */ 109 | @Deprecated 110 | public boolean isLong(int columnIndex) { 111 | return getType(columnIndex) == Cursor.FIELD_TYPE_INTEGER; 112 | } 113 | 114 | /** 115 | * @deprecated Use {@link #getType} 116 | */ 117 | @Deprecated 118 | public boolean isFloat(int columnIndex) { 119 | return getType(columnIndex) == Cursor.FIELD_TYPE_FLOAT; 120 | } 121 | 122 | @Override 123 | public int getType(int columnIndex) { 124 | checkPosition(); 125 | return mWindow.getType(mPos, columnIndex); 126 | } 127 | 128 | @Override 129 | protected void checkPosition() { 130 | super.checkPosition(); 131 | 132 | if (mWindow == null) { 133 | throw new StaleDataException("Attempting to access a closed CursorWindow." + 134 | "Most probable cause: cursor is deactivated prior to calling this method."); 135 | } 136 | } 137 | 138 | @Override 139 | public CursorWindow getWindow() { 140 | return mWindow; 141 | } 142 | 143 | /** 144 | * Sets a new cursor window for the cursor to use. 145 | *

146 | * The cursor takes ownership of the provided cursor window; the cursor window 147 | * will be closed when the cursor is closed or when the cursor adopts a new 148 | * cursor window. 149 | *

150 | * If the cursor previously had a cursor window, then it is closed when the 151 | * new cursor window is assigned. 152 | *

153 | * 154 | * @param window The new cursor window, typically a remote cursor window. 155 | */ 156 | public void setWindow(CursorWindow window) { 157 | if (window != mWindow) { 158 | closeWindow(); 159 | mWindow = window; 160 | } 161 | } 162 | 163 | /** 164 | * Returns true if the cursor has an associated cursor window. 165 | * 166 | * @return True if the cursor has an associated cursor window. 167 | */ 168 | public boolean hasWindow() { 169 | return mWindow != null; 170 | } 171 | 172 | /** 173 | * Closes the cursor window and sets {@link #mWindow} to null. 174 | * @hide 175 | */ 176 | protected void closeWindow() { 177 | if (mWindow != null) { 178 | mWindow.close(); 179 | mWindow = null; 180 | } 181 | } 182 | 183 | /** 184 | * If there is a window, clear it. 185 | * Otherwise, creates a new window. 186 | * 187 | * @param name The window name. 188 | * @hide 189 | */ 190 | protected void clearOrCreateWindow(String name) { 191 | if (mWindow == null) { 192 | mWindow = new CursorWindow(name); 193 | } else { 194 | mWindow.clear(); 195 | } 196 | } 197 | 198 | /** @hide */ 199 | @Override 200 | protected void onDeactivateOrClose() { 201 | super.onDeactivateOrClose(); 202 | closeWindow(); 203 | } 204 | } -------------------------------------------------------------------------------- /src/main/java/android/database/ContentObservable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 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 android.database; 18 | 19 | import android.net.Uri; 20 | 21 | /** 22 | * A specialization of {@link Observable} for {@link ContentObserver} 23 | * that provides methods for sending notifications to a list of 24 | * {@link ContentObserver} objects. 25 | */ 26 | public class ContentObservable extends Observable { 27 | // Even though the generic method defined in Observable would be perfectly 28 | // fine on its own, we can't delete this overridden method because it would 29 | // potentially break binary compatibility with existing applications. 30 | @Override 31 | public void registerObserver(ContentObserver observer) { 32 | super.registerObserver(observer); 33 | } 34 | 35 | /** 36 | * Invokes {@link ContentObserver#dispatchChange(boolean)} on each observer. 37 | *

38 | * If selfChange is true, only delivers the notification 39 | * to the observer if it has indicated that it wants to receive self-change 40 | * notifications by implementing {@link ContentObserver#deliverSelfNotifications} 41 | * to return true. 42 | *

43 | * 44 | * @param selfChange True if this is a self-change notification. 45 | * 46 | * @deprecated Use {@link #dispatchChange(boolean, Uri)} instead. 47 | */ 48 | @Deprecated 49 | public void dispatchChange(boolean selfChange) { 50 | dispatchChange(selfChange, null); 51 | } 52 | 53 | /** 54 | * Invokes {@link ContentObserver#dispatchChange(boolean, Uri)} on each observer. 55 | * Includes the changed content Uri when available. 56 | *

57 | * If selfChange is true, only delivers the notification 58 | * to the observer if it has indicated that it wants to receive self-change 59 | * notifications by implementing {@link ContentObserver#deliverSelfNotifications} 60 | * to return true. 61 | *

62 | * 63 | * @param selfChange True if this is a self-change notification. 64 | * @param uri The Uri of the changed content, or null if unknown. 65 | */ 66 | public void dispatchChange(boolean selfChange, Uri uri) { 67 | synchronized(mObservers) { 68 | for (ContentObserver observer : mObservers) { 69 | if (!selfChange || observer.deliverSelfNotifications()) { 70 | observer.dispatchChange(selfChange, uri); 71 | } 72 | } 73 | } 74 | } 75 | 76 | /** 77 | * Invokes {@link ContentObserver#onChange} on each observer. 78 | * 79 | * @param selfChange True if this is a self-change notification. 80 | * 81 | * @deprecated Use {@link #dispatchChange} instead. 82 | */ 83 | @Deprecated 84 | public void notifyChange(boolean selfChange) { 85 | synchronized(mObservers) { 86 | for (ContentObserver observer : mObservers) { 87 | observer.onChange(selfChange, null); 88 | } 89 | } 90 | } 91 | } -------------------------------------------------------------------------------- /src/main/java/android/database/CrossProcessCursor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 android.database; 18 | 19 | /** 20 | * A cross process cursor is an extension of a {@link Cursor} that also supports 21 | * usage from remote processes. 22 | *

23 | * The contents of a cross process cursor are marshalled to the remote process by 24 | * filling {@link CursorWindow} objects using {@link #fillWindow}. As an optimization, 25 | * the cursor can provide a pre-filled window to use via {@link #getWindow} thereby 26 | * obviating the need to copy the data to yet another cursor window. 27 | */ 28 | public interface CrossProcessCursor extends Cursor { 29 | /** 30 | * Returns a pre-filled window that contains the data within this cursor. 31 | *

32 | * In particular, the window contains the row indicated by {@link Cursor#getPosition}. 33 | * The window's contents are automatically scrolled whenever the current 34 | * row moved outside the range covered by the window. 35 | *

36 | * 37 | * @return The pre-filled window, or null if none. 38 | */ 39 | CursorWindow getWindow(); 40 | 41 | /** 42 | * Copies cursor data into the window. 43 | *

44 | * Clears the window and fills it with data beginning at the requested 45 | * row position until all of the data in the cursor is exhausted 46 | * or the window runs out of space. 47 | *

48 | * The filled window uses the same row indices as the original cursor. 49 | * For example, if you fill a window starting from row 5 from the cursor, 50 | * you can query the contents of row 5 from the window just by asking it 51 | * for row 5 because there is a direct correspondence between the row indices 52 | * used by the cursor and the window. 53 | *

54 | * The current position of the cursor, as returned by {@link #getPosition}, 55 | * is not changed by this method. 56 | *

57 | * 58 | * @param position The zero-based index of the first row to copy into the window. 59 | * @param window The window to fill. 60 | */ 61 | void fillWindow(int position, CursorWindow window); 62 | 63 | /** 64 | * This function is called every time the cursor is successfully scrolled 65 | * to a new position, giving the subclass a chance to update any state it 66 | * may have. If it returns false the move function will also do so and the 67 | * cursor will scroll to the beforeFirst position. 68 | *

69 | * This function should be called by methods such as {@link #moveToPosition(int)}, 70 | * so it will typically not be called from outside of the cursor class itself. 71 | *

72 | * 73 | * @param oldPosition The position that we're moving from. 74 | * @param newPosition The position that we're moving to. 75 | * @return True if the move is successful, false otherwise. 76 | */ 77 | boolean onMove(int oldPosition, int newPosition); 78 | } -------------------------------------------------------------------------------- /src/main/java/android/database/CursorIndexOutOfBoundsException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 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 android.database; 18 | 19 | /** 20 | * An exception indicating that a cursor is out of bounds. 21 | */ 22 | public class CursorIndexOutOfBoundsException extends IndexOutOfBoundsException { 23 | 24 | public CursorIndexOutOfBoundsException(int index, int size) { 25 | super("Index " + index + " requested, with a size of " + size); 26 | } 27 | 28 | public CursorIndexOutOfBoundsException(String message) { 29 | super(message); 30 | } 31 | } -------------------------------------------------------------------------------- /src/main/java/android/database/DataSetObservable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 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 android.database; 18 | 19 | /** 20 | * A specialization of {@link Observable} for {@link DataSetObserver} 21 | * that provides methods for sending notifications to a list of 22 | * {@link DataSetObserver} objects. 23 | */ 24 | public class DataSetObservable extends Observable { 25 | /** 26 | * Invokes {@link DataSetObserver#onChanged} on each observer. 27 | * Called when the contents of the data set have changed. The recipient 28 | * will obtain the new contents the next time it queries the data set. 29 | */ 30 | public void notifyChanged() { 31 | synchronized(mObservers) { 32 | // since onChanged() is implemented by the app, it could do anything, including 33 | // removing itself from {@link mObservers} - and that could cause problems if 34 | // an iterator is used on the ArrayList {@link mObservers}. 35 | // to avoid such problems, just march thru the list in the reverse order. 36 | for (int i = mObservers.size() - 1; i >= 0; i--) { 37 | mObservers.get(i).onChanged(); 38 | } 39 | } 40 | } 41 | 42 | /** 43 | * Invokes {@link DataSetObserver#onInvalidated} on each observer. 44 | * Called when the data set is no longer valid and cannot be queried again, 45 | * such as when the data set has been closed. 46 | */ 47 | public void notifyInvalidated() { 48 | synchronized (mObservers) { 49 | for (int i = mObservers.size() - 1; i >= 0; i--) { 50 | mObservers.get(i).onInvalidated(); 51 | } 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /src/main/java/android/database/DatabaseErrorHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 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 | ** Modified to support SQLite extensions by the SQLite developers: 18 | ** sqlite-dev@sqlite.org. 19 | */ 20 | 21 | 22 | package android.database; 23 | 24 | import android.database.sqlite.SQLiteDatabase; 25 | 26 | /** 27 | * An interface to let apps define an action to take when database corruption is detected. 28 | */ 29 | public interface DatabaseErrorHandler { 30 | 31 | /** 32 | * The method invoked when database corruption is detected. 33 | * @param dbObj the {@link SQLiteDatabase} object representing the database on which corruption 34 | * is detected. 35 | */ 36 | void onCorruption(SQLiteDatabase dbObj); 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/android/database/DefaultDatabaseErrorHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 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 | ** Modified to support SQLite extensions by the SQLite developers: 18 | ** sqlite-dev@sqlite.org. 19 | */ 20 | 21 | package android.database; 22 | 23 | import java.io.File; 24 | import java.util.List; 25 | 26 | import android.database.sqlite.SQLiteDatabase; 27 | import android.database.sqlite.SQLiteException; 28 | import android.util.Log; 29 | import android.util.Pair; 30 | 31 | /** 32 | * Default class used to define the action to take when database corruption is reported 33 | * by sqlite. 34 | *

35 | * An application can specify an implementation of {@link DatabaseErrorHandler} on the 36 | * following: 37 | *

    38 | *
  • {@link SQLiteDatabase#openOrCreateDatabase(String, 39 | * android.database.sqlite.SQLiteDatabase.CursorFactory, DatabaseErrorHandler)}
  • 40 | *
  • {@link SQLiteDatabase#openDatabase(String, 41 | * android.database.sqlite.SQLiteDatabase.CursorFactory, int, DatabaseErrorHandler)}
  • 42 | *
43 | * The specified {@link DatabaseErrorHandler} is used to handle database corruption errors, if they 44 | * occur. 45 | *

46 | * If null is specified for the DatabaseErrorHandler param in the above calls, this class is used 47 | * as the default {@link DatabaseErrorHandler}. 48 | */ 49 | public final class DefaultDatabaseErrorHandler implements DatabaseErrorHandler { 50 | 51 | private static final String TAG = "DefaultDatabaseErrorHandler"; 52 | 53 | /** 54 | * defines the default method to be invoked when database corruption is detected. 55 | * @param dbObj the {@link SQLiteDatabase} object representing the database on which corruption 56 | * is detected. 57 | */ 58 | public void onCorruption(SQLiteDatabase dbObj) { 59 | Log.e(TAG, "Corruption reported by sqlite on database: " + dbObj.getPath()); 60 | 61 | // If this is a SEE build, do not delete any database files. 62 | // It may be that the user has specified an incorrect password. 63 | if( SQLiteDatabase.hasCodec() ) return; 64 | 65 | // is the corruption detected even before database could be 'opened'? 66 | if (!dbObj.isOpen()) { 67 | // database files are not even openable. delete this database file. 68 | // NOTE if the database has attached databases, then any of them could be corrupt. 69 | // and not deleting all of them could cause corrupted database file to remain and 70 | // make the application crash on database open operation. To avoid this problem, 71 | // the application should provide its own {@link DatabaseErrorHandler} impl class 72 | // to delete ALL files of the database (including the attached databases). 73 | deleteDatabaseFile(dbObj.getPath()); 74 | return; 75 | } 76 | 77 | List> attachedDbs = null; 78 | try { 79 | // Close the database, which will cause subsequent operations to fail. 80 | // before that, get the attached database list first. 81 | try { 82 | attachedDbs = dbObj.getAttachedDbs(); 83 | } catch (SQLiteException e) { 84 | /* ignore */ 85 | } 86 | try { 87 | dbObj.close(); 88 | } catch (SQLiteException e) { 89 | /* ignore */ 90 | } 91 | } finally { 92 | // Delete all files of this corrupt database and/or attached databases 93 | if (attachedDbs != null) { 94 | for (Pair p : attachedDbs) { 95 | deleteDatabaseFile(p.second); 96 | } 97 | } else { 98 | // attachedDbs = null is possible when the database is so corrupt that even 99 | // "PRAGMA database_list;" also fails. delete the main database file 100 | deleteDatabaseFile(dbObj.getPath()); 101 | } 102 | } 103 | } 104 | 105 | private void deleteDatabaseFile(String fileName) { 106 | if (fileName.equalsIgnoreCase(":memory:") || fileName.trim().length() == 0) { 107 | return; 108 | } 109 | Log.e(TAG, "deleting the database file: " + fileName); 110 | try { 111 | SQLiteDatabase.deleteDatabase(new File(fileName)); 112 | } catch (Exception e) { 113 | /* print warning and ignore exception */ 114 | Log.w(TAG, "delete failed: " + e.getMessage()); 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/main/java/android/database/Observable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 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 android.database; 18 | 19 | import java.util.ArrayList; 20 | 21 | /** 22 | * Provides methods for registering or unregistering arbitrary observers in an {@link ArrayList}. 23 | * 24 | * This abstract class is intended to be subclassed and specialized to maintain 25 | * a registry of observers of specific types and dispatch notifications to them. 26 | * 27 | * @param T The observer type. 28 | */ 29 | public abstract class Observable { 30 | /** 31 | * The list of observers. An observer can be in the list at most 32 | * once and will never be null. 33 | */ 34 | protected final ArrayList mObservers = new ArrayList(); 35 | 36 | /** 37 | * Adds an observer to the list. The observer cannot be null and it must not already 38 | * be registered. 39 | * @param observer the observer to register 40 | * @throws IllegalArgumentException the observer is null 41 | * @throws IllegalStateException the observer is already registered 42 | */ 43 | public void registerObserver(T observer) { 44 | if (observer == null) { 45 | throw new IllegalArgumentException("The observer is null."); 46 | } 47 | synchronized(mObservers) { 48 | if (mObservers.contains(observer)) { 49 | throw new IllegalStateException("Observer " + observer + " is already registered."); 50 | } 51 | mObservers.add(observer); 52 | } 53 | } 54 | 55 | /** 56 | * Removes a previously registered observer. The observer must not be null and it 57 | * must already have been registered. 58 | * @param observer the observer to unregister 59 | * @throws IllegalArgumentException the observer is null 60 | * @throws IllegalStateException the observer is not yet registered 61 | */ 62 | public void unregisterObserver(T observer) { 63 | if (observer == null) { 64 | throw new IllegalArgumentException("The observer is null."); 65 | } 66 | synchronized(mObservers) { 67 | int index = mObservers.indexOf(observer); 68 | if (index == -1) { 69 | throw new IllegalStateException("Observer " + observer + " was not registered."); 70 | } 71 | mObservers.remove(index); 72 | } 73 | } 74 | 75 | /** 76 | * Remove all registered observers. 77 | */ 78 | public void unregisterAll() { 79 | synchronized(mObservers) { 80 | mObservers.clear(); 81 | } 82 | } 83 | } -------------------------------------------------------------------------------- /src/main/java/android/database/SQLException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 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 | ** Modified to support SQLite extensions by the SQLite developers: 18 | ** sqlite-dev@sqlite.org. 19 | */ 20 | 21 | package android.database; 22 | 23 | /** 24 | * An exception that indicates there was an error with SQL parsing or execution. 25 | */ 26 | public class SQLException extends RuntimeException { 27 | public SQLException() { 28 | } 29 | 30 | public SQLException(String error) { 31 | super(error); 32 | } 33 | 34 | public SQLException(String error, Throwable cause) { 35 | super(error, cause); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/android/database/StaleDataException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 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 android.database; 18 | 19 | /** 20 | * This exception is thrown when a Cursor contains stale data and must be 21 | * requeried before being used again. 22 | */ 23 | public class StaleDataException extends java.lang.RuntimeException 24 | { 25 | public StaleDataException() 26 | { 27 | super(); 28 | } 29 | 30 | public StaleDataException(String description) 31 | { 32 | super(description); 33 | } 34 | } -------------------------------------------------------------------------------- /src/main/java/android/database/sqlite/DatabaseObjectNotClosedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 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 | ** Modified to support SQLite extensions by the SQLite developers: 18 | ** sqlite-dev@sqlite.org. 19 | */ 20 | 21 | package android.database.sqlite; 22 | 23 | /** 24 | * An exception that indicates that garbage-collector is finalizing a database object 25 | * that is not explicitly closed 26 | * @hide 27 | */ 28 | public class DatabaseObjectNotClosedException extends RuntimeException { 29 | private static final String s = "Application did not close the cursor or database object " + 30 | "that was opened here"; 31 | 32 | public DatabaseObjectNotClosedException() { 33 | super(s); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/android/database/sqlite/SQLiteAbortException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | ** Modified to support SQLite extensions by the SQLite developers: 18 | ** sqlite-dev@sqlite.org. 19 | */ 20 | 21 | package android.database.sqlite; 22 | 23 | /** 24 | * An exception that indicates that the SQLite program was aborted. 25 | * This can happen either through a call to ABORT in a trigger, 26 | * or as the result of using the ABORT conflict clause. 27 | */ 28 | public class SQLiteAbortException extends SQLiteException { 29 | public SQLiteAbortException() {} 30 | 31 | public SQLiteAbortException(String error) { 32 | super(error); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/android/database/sqlite/SQLiteAccessPermException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 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 | ** Modified to support SQLite extensions by the SQLite developers: 18 | ** sqlite-dev@sqlite.org. 19 | */ 20 | 21 | package android.database.sqlite; 22 | 23 | /** 24 | * This exception class is used when sqlite can't access the database file 25 | * due to lack of permissions on the file. 26 | */ 27 | public class SQLiteAccessPermException extends SQLiteException { 28 | public SQLiteAccessPermException() {} 29 | 30 | public SQLiteAccessPermException(String error) { 31 | super(error); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/android/database/sqlite/SQLiteBindOrColumnIndexOutOfRangeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 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 | ** Modified to support SQLite extensions by the SQLite developers: 18 | ** sqlite-dev@sqlite.org. 19 | */ 20 | 21 | package android.database.sqlite; 22 | 23 | /** 24 | * Thrown if the the bind or column parameter index is out of range 25 | */ 26 | public class SQLiteBindOrColumnIndexOutOfRangeException extends SQLiteException { 27 | public SQLiteBindOrColumnIndexOutOfRangeException() {} 28 | 29 | public SQLiteBindOrColumnIndexOutOfRangeException(String error) { 30 | super(error); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/android/database/sqlite/SQLiteBlobTooBigException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 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 | ** Modified to support SQLite extensions by the SQLite developers: 18 | ** sqlite-dev@sqlite.org. 19 | */ 20 | 21 | package android.database.sqlite; 22 | 23 | public class SQLiteBlobTooBigException extends SQLiteException { 24 | public SQLiteBlobTooBigException() {} 25 | 26 | public SQLiteBlobTooBigException(String error) { 27 | super(error); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/android/database/sqlite/SQLiteCantOpenDatabaseException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 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 | ** Modified to support SQLite extensions by the SQLite developers: 18 | ** sqlite-dev@sqlite.org. 19 | */ 20 | 21 | package android.database.sqlite; 22 | 23 | public class SQLiteCantOpenDatabaseException extends SQLiteException { 24 | public SQLiteCantOpenDatabaseException() {} 25 | 26 | public SQLiteCantOpenDatabaseException(String error) { 27 | super(error); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/android/database/sqlite/SQLiteClosable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 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 | ** Modified to support SQLite extensions by the SQLite developers: 18 | ** sqlite-dev@sqlite.org. 19 | */ 20 | 21 | package android.database.sqlite; 22 | 23 | import java.io.Closeable; 24 | 25 | /** 26 | * An object created from a SQLiteDatabase that can be closed. 27 | * 28 | * This class implements a primitive reference counting scheme for database objects. 29 | */ 30 | public abstract class SQLiteClosable implements Closeable { 31 | private int mReferenceCount = 1; 32 | 33 | /** 34 | * Called when the last reference to the object was released by 35 | * a call to {@link #releaseReference()} or {@link #close()}. 36 | */ 37 | protected abstract void onAllReferencesReleased(); 38 | 39 | /** 40 | * Called when the last reference to the object was released by 41 | * a call to {@link #releaseReferenceFromContainer()}. 42 | * 43 | * @deprecated Do not use. 44 | */ 45 | @Deprecated 46 | protected void onAllReferencesReleasedFromContainer() { 47 | onAllReferencesReleased(); 48 | } 49 | 50 | /** 51 | * Acquires a reference to the object. 52 | * 53 | * @throws IllegalStateException if the last reference to the object has already 54 | * been released. 55 | */ 56 | public void acquireReference() { 57 | synchronized(this) { 58 | if (mReferenceCount <= 0) { 59 | throw new IllegalStateException( 60 | "attempt to re-open an already-closed object: " + this); 61 | } 62 | mReferenceCount++; 63 | } 64 | } 65 | 66 | /** 67 | * Releases a reference to the object, closing the object if the last reference 68 | * was released. 69 | * 70 | * @see #onAllReferencesReleased() 71 | */ 72 | public void releaseReference() { 73 | boolean refCountIsZero = false; 74 | synchronized(this) { 75 | refCountIsZero = --mReferenceCount == 0; 76 | } 77 | if (refCountIsZero) { 78 | onAllReferencesReleased(); 79 | } 80 | } 81 | 82 | /** 83 | * Releases a reference to the object that was owned by the container of the object, 84 | * closing the object if the last reference was released. 85 | * 86 | * @see #onAllReferencesReleasedFromContainer() 87 | * @deprecated Do not use. 88 | */ 89 | @Deprecated 90 | public void releaseReferenceFromContainer() { 91 | boolean refCountIsZero = false; 92 | synchronized(this) { 93 | refCountIsZero = --mReferenceCount == 0; 94 | } 95 | if (refCountIsZero) { 96 | onAllReferencesReleasedFromContainer(); 97 | } 98 | } 99 | 100 | /** 101 | * Releases a reference to the object, closing the object if the last reference 102 | * was released. 103 | * 104 | * Calling this method is equivalent to calling {@link #releaseReference}. 105 | * 106 | * @see #releaseReference() 107 | * @see #onAllReferencesReleased() 108 | */ 109 | public void close() { 110 | releaseReference(); 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/main/java/android/database/sqlite/SQLiteConstraintException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | ** Modified to support SQLite extensions by the SQLite developers: 18 | ** sqlite-dev@sqlite.org. 19 | */ 20 | 21 | package android.database.sqlite; 22 | 23 | /** 24 | * An exception that indicates that an integrity constraint was violated. 25 | */ 26 | public class SQLiteConstraintException extends SQLiteException { 27 | public SQLiteConstraintException() {} 28 | 29 | public SQLiteConstraintException(String error) { 30 | super(error); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/android/database/sqlite/SQLiteCursorDriver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 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 | ** Modified to support SQLite extensions by the SQLite developers: 18 | ** sqlite-dev@sqlite.org. 19 | */ 20 | 21 | package android.database.sqlite; 22 | 23 | import android.database.Cursor; 24 | import android.database.sqlite.SQLiteDatabase.CursorFactory; 25 | 26 | /** 27 | * A driver for SQLiteCursors that is used to create them and gets notified 28 | * by the cursors it creates on significant events in their lifetimes. 29 | */ 30 | public interface SQLiteCursorDriver { 31 | /** 32 | * Executes the query returning a Cursor over the result set. 33 | * 34 | * @param factory The CursorFactory to use when creating the Cursors, or 35 | * null if standard SQLiteCursors should be returned. 36 | * @return a Cursor over the result set 37 | */ 38 | Cursor query(CursorFactory factory, String[] bindArgs); 39 | 40 | /** 41 | * Called by a SQLiteCursor when it is released. 42 | */ 43 | void cursorDeactivated(); 44 | 45 | /** 46 | * Called by a SQLiteCursor when it is requeried. 47 | */ 48 | void cursorRequeried(Cursor cursor); 49 | 50 | /** 51 | * Called by a SQLiteCursor when it it closed to destroy this object as well. 52 | */ 53 | void cursorClosed(); 54 | 55 | /** 56 | * Set new bind arguments. These will take effect in cursorRequeried(). 57 | * @param bindArgs the new arguments 58 | */ 59 | public void setBindArguments(String[] bindArgs); 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/android/database/sqlite/SQLiteCustomFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 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 | ** Modified to support SQLite extensions by the SQLite developers: 18 | ** sqlite-dev@sqlite.org. 19 | */ 20 | 21 | package android.database.sqlite; 22 | 23 | /** 24 | * Describes a custom SQL function. 25 | * 26 | * @hide 27 | */ 28 | public final class SQLiteCustomFunction { 29 | public final String name; 30 | public final int numArgs; 31 | public final SQLiteDatabase.CustomFunction callback; 32 | 33 | /** 34 | * Create custom function. 35 | * 36 | * @param name The name of the sqlite3 function. 37 | * @param numArgs The number of arguments for the function, or -1 to 38 | * support any number of arguments. 39 | * @param callback The callback to invoke when the function is executed. 40 | */ 41 | public SQLiteCustomFunction(String name, int numArgs, 42 | SQLiteDatabase.CustomFunction callback) { 43 | if (name == null) { 44 | throw new IllegalArgumentException("name must not be null."); 45 | } 46 | 47 | this.name = name; 48 | this.numArgs = numArgs; 49 | this.callback = callback; 50 | } 51 | 52 | // Called from native. 53 | @SuppressWarnings("unused") 54 | private void dispatchCallback(String[] args) { 55 | callback.callback(args); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/android/database/sqlite/SQLiteDatabaseConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 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 | ** Modified to support SQLite extensions by the SQLite developers: 18 | ** sqlite-dev@sqlite.org. 19 | */ 20 | 21 | package android.database.sqlite; 22 | 23 | import java.util.ArrayList; 24 | import java.util.Locale; 25 | import java.util.regex.Pattern; 26 | 27 | /** 28 | * Describes how to configure a database. 29 | *

30 | * The purpose of this object is to keep track of all of the little 31 | * configuration settings that are applied to a database after it 32 | * is opened so that they can be applied to all connections in the 33 | * connection pool uniformly. 34 | *

35 | * Each connection maintains its own copy of this object so it can 36 | * keep track of which settings have already been applied. 37 | *

38 | * 39 | * @hide 40 | */ 41 | public final class SQLiteDatabaseConfiguration { 42 | // The pattern we use to strip email addresses from database paths 43 | // when constructing a label to use in log messages. 44 | private static final Pattern EMAIL_IN_DB_PATTERN = 45 | Pattern.compile("[\\w\\.\\-]+@[\\w\\.\\-]+"); 46 | 47 | /** 48 | * Special path used by in-memory databases. 49 | */ 50 | public static final String MEMORY_DB_PATH = ":memory:"; 51 | 52 | /** 53 | * The database path. 54 | */ 55 | public final String path; 56 | 57 | /** 58 | * The label to use to describe the database when it appears in logs. 59 | * This is derived from the path but is stripped to remove PII. 60 | */ 61 | public final String label; 62 | 63 | /** 64 | * The flags used to open the database. 65 | */ 66 | public int openFlags; 67 | 68 | /** 69 | * The maximum size of the prepared statement cache for each database connection. 70 | * Must be non-negative. 71 | * 72 | * Default is 25. 73 | */ 74 | public int maxSqlCacheSize; 75 | 76 | /** 77 | * The database locale. 78 | * 79 | * Default is the value returned by {@link Locale#getDefault()}. 80 | */ 81 | public Locale locale; 82 | 83 | /** 84 | * True if foreign key constraints are enabled. 85 | * 86 | * Default is false. 87 | */ 88 | public boolean foreignKeyConstraintsEnabled; 89 | 90 | /** 91 | * The custom functions to register. 92 | */ 93 | public final ArrayList customFunctions = 94 | new ArrayList(); 95 | 96 | /** 97 | * Creates a database configuration with the required parameters for opening a 98 | * database and default values for all other parameters. 99 | * 100 | * @param path The database path. 101 | * @param openFlags Open flags for the database, such as {@link SQLiteDatabase#OPEN_READWRITE}. 102 | */ 103 | public SQLiteDatabaseConfiguration(String path, int openFlags) { 104 | if (path == null) { 105 | throw new IllegalArgumentException("path must not be null."); 106 | } 107 | 108 | this.path = path; 109 | label = stripPathForLogs(path); 110 | this.openFlags = openFlags; 111 | 112 | // Set default values for optional parameters. 113 | maxSqlCacheSize = 25; 114 | locale = Locale.getDefault(); 115 | } 116 | 117 | /** 118 | * Creates a database configuration as a copy of another configuration. 119 | * 120 | * @param other The other configuration. 121 | */ 122 | public SQLiteDatabaseConfiguration(SQLiteDatabaseConfiguration other) { 123 | if (other == null) { 124 | throw new IllegalArgumentException("other must not be null."); 125 | } 126 | 127 | this.path = other.path; 128 | this.label = other.label; 129 | updateParametersFrom(other); 130 | } 131 | 132 | /** 133 | * Updates the non-immutable parameters of this configuration object 134 | * from the other configuration object. 135 | * 136 | * @param other The object from which to copy the parameters. 137 | */ 138 | public void updateParametersFrom(SQLiteDatabaseConfiguration other) { 139 | if (other == null) { 140 | throw new IllegalArgumentException("other must not be null."); 141 | } 142 | if (!path.equals(other.path)) { 143 | throw new IllegalArgumentException("other configuration must refer to " 144 | + "the same database."); 145 | } 146 | 147 | openFlags = other.openFlags; 148 | maxSqlCacheSize = other.maxSqlCacheSize; 149 | locale = other.locale; 150 | foreignKeyConstraintsEnabled = other.foreignKeyConstraintsEnabled; 151 | customFunctions.clear(); 152 | customFunctions.addAll(other.customFunctions); 153 | } 154 | 155 | /** 156 | * Returns true if the database is in-memory. 157 | * @return True if the database is in-memory. 158 | */ 159 | public boolean isInMemoryDb() { 160 | return path.equalsIgnoreCase(MEMORY_DB_PATH); 161 | } 162 | 163 | private static String stripPathForLogs(String path) { 164 | /* Strip off all URI parameters. This is in case a SEE database is 165 | * opened with the password specified as a URI parameter. We do not 166 | * want the password to appear in any log files. */ 167 | int iIdx = path.indexOf('?'); 168 | if( iIdx>=0 ){ 169 | path = (String) path.subSequence(0, iIdx); 170 | } 171 | 172 | if (path.indexOf('@') == -1) { 173 | return path; 174 | } 175 | return EMAIL_IN_DB_PATTERN.matcher(path).replaceAll("XX@YY"); 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /src/main/java/android/database/sqlite/SQLiteDatabaseCorruptException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 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 | ** Modified to support SQLite extensions by the SQLite developers: 18 | ** sqlite-dev@sqlite.org. 19 | */ 20 | 21 | package android.database.sqlite; 22 | 23 | /** 24 | * An exception that indicates that the SQLite database file is corrupt. 25 | */ 26 | public class SQLiteDatabaseCorruptException extends SQLiteException { 27 | public SQLiteDatabaseCorruptException() {} 28 | 29 | public SQLiteDatabaseCorruptException(String error) { 30 | super(error); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/android/database/sqlite/SQLiteDatabaseLockedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 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 | ** Modified to support SQLite extensions by the SQLite developers: 18 | ** sqlite-dev@sqlite.org. 19 | */ 20 | 21 | package android.database.sqlite; 22 | 23 | /** 24 | * Thrown if the database engine was unable to acquire the 25 | * database locks it needs to do its job. If the statement is a [COMMIT] 26 | * or occurs outside of an explicit transaction, then you can retry the 27 | * statement. If the statement is not a [COMMIT] and occurs within a 28 | * explicit transaction then you should rollback the transaction before 29 | * continuing. 30 | */ 31 | public class SQLiteDatabaseLockedException extends SQLiteException { 32 | public SQLiteDatabaseLockedException() {} 33 | 34 | public SQLiteDatabaseLockedException(String error) { 35 | super(error); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/android/database/sqlite/SQLiteDatatypeMismatchException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | ** Modified to support SQLite extensions by the SQLite developers: 18 | ** sqlite-dev@sqlite.org. 19 | */ 20 | 21 | package android.database.sqlite; 22 | 23 | public class SQLiteDatatypeMismatchException extends SQLiteException { 24 | public SQLiteDatatypeMismatchException() {} 25 | 26 | public SQLiteDatatypeMismatchException(String error) { 27 | super(error); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/android/database/sqlite/SQLiteDebug.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 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 | ** Modified to support SQLite extensions by the SQLite developers: 18 | ** sqlite-dev@sqlite.org. 19 | */ 20 | 21 | package android.database.sqlite; 22 | 23 | import java.util.ArrayList; 24 | 25 | import android.os.Build; 26 | /* import android.os.SystemProperties; */ 27 | import android.util.Log; 28 | import android.util.Printer; 29 | 30 | /** 31 | * Provides debugging info about all SQLite databases running in the current process. 32 | * 33 | * {@hide} 34 | */ 35 | public final class SQLiteDebug { 36 | private static native void nativeGetPagerStats(PagerStats stats); 37 | 38 | /** 39 | * Controls the printing of informational SQL log messages. 40 | * 41 | * Enable using "adb shell setprop log.tag.SQLiteLog VERBOSE". 42 | */ 43 | public static final boolean DEBUG_SQL_LOG = 44 | Log.isLoggable("SQLiteLog", Log.VERBOSE); 45 | 46 | /** 47 | * Controls the printing of SQL statements as they are executed. 48 | * 49 | * Enable using "adb shell setprop log.tag.SQLiteStatements VERBOSE". 50 | */ 51 | public static final boolean DEBUG_SQL_STATEMENTS = 52 | Log.isLoggable("SQLiteStatements", Log.VERBOSE); 53 | 54 | /** 55 | * Controls the printing of wall-clock time taken to execute SQL statements 56 | * as they are executed. 57 | * 58 | * Enable using "adb shell setprop log.tag.SQLiteTime VERBOSE". 59 | */ 60 | public static final boolean DEBUG_SQL_TIME = 61 | Log.isLoggable("SQLiteTime", Log.VERBOSE); 62 | 63 | /** 64 | * True to enable database performance testing instrumentation. 65 | * @hide 66 | */ 67 | public static final boolean DEBUG_LOG_SLOW_QUERIES = false; 68 | 69 | private SQLiteDebug() { 70 | } 71 | 72 | /** 73 | * Determines whether a query should be logged. 74 | * 75 | * Reads the "db.log.slow_query_threshold" system property, which can be changed 76 | * by the user at any time. If the value is zero, then all queries will 77 | * be considered slow. If the value does not exist or is negative, then no queries will 78 | * be considered slow. 79 | * 80 | * This value can be changed dynamically while the system is running. 81 | * For example, "adb shell setprop db.log.slow_query_threshold 200" will 82 | * log all queries that take 200ms or longer to run. 83 | * @hide 84 | */ 85 | public static final boolean shouldLogSlowQuery(long elapsedTimeMillis) { 86 | int slowQueryMillis = Integer.parseInt( 87 | System.getProperty("db.log.slow_query_threshold", "10000") 88 | ); 89 | return slowQueryMillis >= 0 && elapsedTimeMillis >= slowQueryMillis; 90 | } 91 | 92 | /** 93 | * Contains statistics about the active pagers in the current process. 94 | * 95 | * @see #nativeGetPagerStats(PagerStats) 96 | */ 97 | public static class PagerStats { 98 | /** the current amount of memory checked out by sqlite using sqlite3_malloc(). 99 | * documented at http://www.sqlite.org/c3ref/c_status_malloc_size.html 100 | */ 101 | public int memoryUsed; 102 | 103 | /** the number of bytes of page cache allocation which could not be sattisfied by the 104 | * SQLITE_CONFIG_PAGECACHE buffer and where forced to overflow to sqlite3_malloc(). 105 | * The returned value includes allocations that overflowed because they where too large 106 | * (they were larger than the "sz" parameter to SQLITE_CONFIG_PAGECACHE) and allocations 107 | * that overflowed because no space was left in the page cache. 108 | * documented at http://www.sqlite.org/c3ref/c_status_malloc_size.html 109 | */ 110 | public int pageCacheOverflow; 111 | 112 | /** records the largest memory allocation request handed to sqlite3. 113 | * documented at http://www.sqlite.org/c3ref/c_status_malloc_size.html 114 | */ 115 | public int largestMemAlloc; 116 | 117 | /** a list of {@link DbStats} - one for each main database opened by the applications 118 | * running on the android device 119 | */ 120 | public ArrayList dbStats; 121 | } 122 | 123 | /** 124 | * contains statistics about a database 125 | */ 126 | public static class DbStats { 127 | /** name of the database */ 128 | public String dbName; 129 | 130 | /** the page size for the database */ 131 | public long pageSize; 132 | 133 | /** the database size */ 134 | public long dbSize; 135 | 136 | /** documented here http://www.sqlite.org/c3ref/c_dbstatus_lookaside_used.html */ 137 | public int lookaside; 138 | 139 | /** statement cache stats: hits/misses/cachesize */ 140 | public String cache; 141 | 142 | public DbStats(String dbName, long pageCount, long pageSize, int lookaside, 143 | int hits, int misses, int cachesize) { 144 | this.dbName = dbName; 145 | this.pageSize = pageSize / 1024; 146 | dbSize = (pageCount * pageSize) / 1024; 147 | this.lookaside = lookaside; 148 | this.cache = hits + "/" + misses + "/" + cachesize; 149 | } 150 | } 151 | 152 | /** 153 | * return all pager and database stats for the current process. 154 | * @return {@link PagerStats} 155 | */ 156 | public static PagerStats getDatabaseInfo() { 157 | PagerStats stats = new PagerStats(); 158 | nativeGetPagerStats(stats); 159 | stats.dbStats = SQLiteDatabase.getDbStats(); 160 | return stats; 161 | } 162 | 163 | /** 164 | * Dumps detailed information about all databases used by the process. 165 | * @param printer The printer for dumping database state. 166 | * @param args Command-line arguments supplied to dumpsys dbinfo 167 | */ 168 | public static void dump(Printer printer, String[] args) { 169 | boolean verbose = false; 170 | for (String arg : args) { 171 | if (arg.equals("-v")) { 172 | verbose = true; 173 | } 174 | } 175 | 176 | SQLiteDatabase.dumpAll(printer, verbose); 177 | } 178 | } 179 | -------------------------------------------------------------------------------- /src/main/java/android/database/sqlite/SQLiteDirectCursorDriver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 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 | ** Modified to support SQLite extensions by the SQLite developers: 18 | ** sqlite-dev@sqlite.org. 19 | */ 20 | 21 | package android.database.sqlite; 22 | 23 | import android.database.Cursor; 24 | import android.database.sqlite.SQLiteDatabase.CursorFactory; 25 | import android.os.CancellationSignal; 26 | 27 | /** 28 | * A cursor driver that uses the given query directly. 29 | * 30 | * @hide 31 | */ 32 | public final class SQLiteDirectCursorDriver implements SQLiteCursorDriver { 33 | private final SQLiteDatabase mDatabase; 34 | private final String mEditTable; 35 | private final String mSql; 36 | private final CancellationSignal mCancellationSignal; 37 | private SQLiteQuery mQuery; 38 | 39 | public SQLiteDirectCursorDriver(SQLiteDatabase db, String sql, String editTable, 40 | CancellationSignal cancellationSignal) { 41 | mDatabase = db; 42 | mEditTable = editTable; 43 | mSql = sql; 44 | mCancellationSignal = cancellationSignal; 45 | } 46 | 47 | public Cursor query(CursorFactory factory, String[] selectionArgs) { 48 | final SQLiteQuery query = new SQLiteQuery(mDatabase, mSql, mCancellationSignal); 49 | final Cursor cursor; 50 | try { 51 | query.bindAllArgsAsStrings(selectionArgs); 52 | 53 | if (factory == null) { 54 | cursor = new SQLiteCursor(this, mEditTable, query); 55 | } else { 56 | cursor = factory.newCursor(mDatabase, this, mEditTable, query); 57 | } 58 | } catch (RuntimeException ex) { 59 | query.close(); 60 | throw ex; 61 | } 62 | 63 | mQuery = query; 64 | return cursor; 65 | } 66 | 67 | public void cursorClosed() { 68 | // Do nothing 69 | } 70 | 71 | public void setBindArguments(String[] bindArgs) { 72 | mQuery.bindAllArgsAsStrings(bindArgs); 73 | } 74 | 75 | public void cursorDeactivated() { 76 | // Do nothing 77 | } 78 | 79 | public void cursorRequeried(Cursor cursor) { 80 | // Do nothing 81 | } 82 | 83 | @Override 84 | public String toString() { 85 | return "SQLiteDirectCursorDriver: " + mSql; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/android/database/sqlite/SQLiteDiskIOException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 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 | ** Modified to support SQLite extensions by the SQLite developers: 18 | ** sqlite-dev@sqlite.org. 19 | */ 20 | 21 | package android.database.sqlite; 22 | 23 | /** 24 | * An exception that indicates that an IO error occured while accessing the 25 | * SQLite database file. 26 | */ 27 | public class SQLiteDiskIOException extends SQLiteException { 28 | public SQLiteDiskIOException() {} 29 | 30 | public SQLiteDiskIOException(String error) { 31 | super(error); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/android/database/sqlite/SQLiteDoneException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | ** Modified to support SQLite extensions by the SQLite developers: 18 | ** sqlite-dev@sqlite.org. 19 | */ 20 | 21 | package android.database.sqlite; 22 | 23 | /** 24 | * An exception that indicates that the SQLite program is done. 25 | * Thrown when an operation that expects a row (such as {@link 26 | * SQLiteStatement#simpleQueryForString} or {@link 27 | * SQLiteStatement#simpleQueryForLong}) does not get one. 28 | */ 29 | public class SQLiteDoneException extends SQLiteException { 30 | public SQLiteDoneException() {} 31 | 32 | public SQLiteDoneException(String error) { 33 | super(error); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/android/database/sqlite/SQLiteException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 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 | ** Modified to support SQLite extensions by the SQLite developers: 18 | ** sqlite-dev@sqlite.org. 19 | */ 20 | 21 | package android.database.sqlite; 22 | 23 | import android.database.SQLException; 24 | 25 | /** 26 | * A SQLite exception that indicates there was an error with SQL parsing or execution. 27 | */ 28 | public class SQLiteException extends SQLException { 29 | public SQLiteException() { 30 | } 31 | 32 | public SQLiteException(String error) { 33 | super(error); 34 | } 35 | 36 | public SQLiteException(String error, Throwable cause) { 37 | super(error, cause); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/android/database/sqlite/SQLiteFullException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | ** Modified to support SQLite extensions by the SQLite developers: 18 | ** sqlite-dev@sqlite.org. 19 | */ 20 | 21 | package android.database.sqlite; 22 | 23 | /** 24 | * An exception that indicates that the SQLite database is full. 25 | */ 26 | public class SQLiteFullException extends SQLiteException { 27 | public SQLiteFullException() {} 28 | 29 | public SQLiteFullException(String error) { 30 | super(error); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/android/database/sqlite/SQLiteGlobal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 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 | ** Modified to support SQLite extensions by the SQLite developers: 18 | ** sqlite-dev@sqlite.org. 19 | */ 20 | 21 | package android.database.sqlite; 22 | 23 | import android.content.res.Resources; 24 | import android.os.StatFs; 25 | 26 | /** 27 | * Provides access to SQLite functions that affect all database connection, 28 | * such as memory management. 29 | * 30 | * The native code associated with SQLiteGlobal is also sets global configuration options 31 | * using sqlite3_config() then calls sqlite3_initialize() to ensure that the SQLite 32 | * library is properly initialized exactly once before any other framework or application 33 | * code has a chance to run. 34 | * 35 | * Verbose SQLite logging is enabled if the "log.tag.SQLiteLog" property is set to "V". 36 | * (per {@link SQLiteDebug#DEBUG_SQL_LOG}). 37 | * 38 | * @hide 39 | */ 40 | public final class SQLiteGlobal { 41 | private static final String TAG = "SQLiteGlobal"; 42 | 43 | private static final Object sLock = new Object(); 44 | private static int sDefaultPageSize; 45 | 46 | private static native int nativeReleaseMemory(); 47 | 48 | private SQLiteGlobal() { 49 | } 50 | 51 | /** 52 | * Attempts to release memory by pruning the SQLite page cache and other 53 | * internal data structures. 54 | * 55 | * @return The number of bytes that were freed. 56 | */ 57 | public static int releaseMemory() { 58 | return nativeReleaseMemory(); 59 | } 60 | 61 | /** 62 | * Gets the default page size to use when creating a database. 63 | */ 64 | public static int getDefaultPageSize() { 65 | synchronized (sLock) { 66 | if (sDefaultPageSize == 0) { 67 | // If there is an issue accessing /data, something is so seriously 68 | // wrong that we just let the IllegalArgumentException propagate. 69 | sDefaultPageSize = new StatFs("/data").getBlockSize(); 70 | } 71 | return 1024; 72 | } 73 | } 74 | 75 | /** 76 | * Gets the default journal mode when WAL is not in use. 77 | */ 78 | public static String getDefaultJournalMode() { 79 | return "delete"; 80 | } 81 | 82 | /** 83 | * Gets the journal size limit in bytes. 84 | */ 85 | public static int getJournalSizeLimit() { 86 | return 10000; 87 | } 88 | 89 | /** 90 | * Gets the default database synchronization mode when WAL is not in use. 91 | */ 92 | public static String getDefaultSyncMode() { 93 | return "normal"; 94 | } 95 | 96 | /** 97 | * Gets the database synchronization mode when in WAL mode. 98 | */ 99 | public static String getWALSyncMode() { 100 | return "normal"; 101 | } 102 | 103 | /** 104 | * Gets the WAL auto-checkpoint integer in database pages. 105 | */ 106 | public static int getWALAutoCheckpoint() { 107 | int value = 1000; 108 | return Math.max(1, value); 109 | } 110 | 111 | /** 112 | * Gets the connection pool size when in WAL mode. 113 | */ 114 | public static int getWALConnectionPoolSize() { 115 | int value = 10; 116 | return Math.max(2, value); 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /src/main/java/android/database/sqlite/SQLiteMisuseException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | ** Modified to support SQLite extensions by the SQLite developers: 18 | ** sqlite-dev@sqlite.org. 19 | */ 20 | 21 | package android.database.sqlite; 22 | 23 | /** 24 | * This error can occur if the application creates a SQLiteStatement object and allows multiple 25 | * threads in the application use it at the same time. 26 | * Sqlite returns this error if bind and execute methods on this object occur at the same time 27 | * from multiple threads, like so: 28 | * thread # 1: in execute() method of the SQLiteStatement object 29 | * while thread # 2: is in bind..() on the same object. 30 | *

31 | * FIX this by NEVER sharing the same SQLiteStatement object between threads. 32 | * Create a local instance of the SQLiteStatement whenever it is needed, use it and close it ASAP. 33 | * NEVER make it globally available. 34 | */ 35 | public class SQLiteMisuseException extends SQLiteException { 36 | public SQLiteMisuseException() {} 37 | 38 | public SQLiteMisuseException(String error) { 39 | super(error); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/android/database/sqlite/SQLiteOutOfMemoryException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 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 | ** Modified to support SQLite extensions by the SQLite developers: 18 | ** sqlite-dev@sqlite.org. 19 | */ 20 | 21 | package android.database.sqlite; 22 | 23 | public class SQLiteOutOfMemoryException extends SQLiteException { 24 | public SQLiteOutOfMemoryException() {} 25 | 26 | public SQLiteOutOfMemoryException(String error) { 27 | super(error); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/android/database/sqlite/SQLiteQuery.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 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 | ** Modified to support SQLite extensions by the SQLite developers: 18 | ** sqlite-dev@sqlite.org. 19 | */ 20 | 21 | package android.database.sqlite; 22 | 23 | import android.database.CursorWindow; 24 | import android.os.CancellationSignal; 25 | import android.os.OperationCanceledException; 26 | import android.util.Log; 27 | 28 | /** 29 | * Represents a query that reads the resulting rows into a {@link SQLiteQuery}. 30 | * This class is used by {@link SQLiteCursor} and isn't useful itself. 31 | *

32 | * This class is not thread-safe. 33 | *

34 | */ 35 | public final class SQLiteQuery extends SQLiteProgram { 36 | private static final String TAG = "SQLiteQuery"; 37 | 38 | private final CancellationSignal mCancellationSignal; 39 | 40 | SQLiteQuery(SQLiteDatabase db, String query, CancellationSignal cancellationSignal) { 41 | super(db, query, null, cancellationSignal); 42 | 43 | mCancellationSignal = cancellationSignal; 44 | } 45 | 46 | /** 47 | * Reads rows into a buffer. 48 | * 49 | * @param window The window to fill into 50 | * @param startPos The start position for filling the window. 51 | * @param requiredPos The position of a row that MUST be in the window. 52 | * If it won't fit, then the query should discard part of what it filled. 53 | * @param countAllRows True to count all rows that the query would 54 | * return regardless of whether they fit in the window. 55 | * @return Number of rows that were enumerated. Might not be all rows 56 | * unless countAllRows is true. 57 | * 58 | * @throws SQLiteException if an error occurs. 59 | * @throws OperationCanceledException if the operation was canceled. 60 | */ 61 | int fillWindow(CursorWindow window, int startPos, int requiredPos, boolean countAllRows) { 62 | acquireReference(); 63 | try { 64 | window.acquireReference(); 65 | try { 66 | int numRows = getSession().executeForCursorWindow(getSql(), getBindArgs(), 67 | window, startPos, requiredPos, countAllRows, getConnectionFlags(), 68 | mCancellationSignal); 69 | return numRows; 70 | } catch (SQLiteDatabaseCorruptException ex) { 71 | onCorruption(); 72 | throw ex; 73 | } catch (SQLiteException ex) { 74 | Log.e(TAG, "exception: " + ex.getMessage() + "; query: " + getSql()); 75 | throw ex; 76 | } finally { 77 | window.releaseReference(); 78 | } 79 | } finally { 80 | releaseReference(); 81 | } 82 | } 83 | 84 | @Override 85 | public String toString() { 86 | return "SQLiteQuery: " + getSql(); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/main/java/android/database/sqlite/SQLiteReadOnlyDatabaseException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 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 | ** Modified to support SQLite extensions by the SQLite developers: 18 | ** sqlite-dev@sqlite.org. 19 | */ 20 | 21 | package android.database.sqlite; 22 | 23 | public class SQLiteReadOnlyDatabaseException extends SQLiteException { 24 | public SQLiteReadOnlyDatabaseException() {} 25 | 26 | public SQLiteReadOnlyDatabaseException(String error) { 27 | super(error); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/android/database/sqlite/SQLiteStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 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 | ** Modified to support SQLite extensions by the SQLite developers: 18 | ** sqlite-dev@sqlite.org. 19 | */ 20 | 21 | package android.database.sqlite; 22 | 23 | import android.os.ParcelFileDescriptor; 24 | 25 | /** 26 | * Represents a statement that can be executed against a database. The statement 27 | * cannot return multiple rows or columns, but single value (1 x 1) result sets 28 | * are supported. 29 | *

30 | * This class is not thread-safe. 31 | *

32 | */ 33 | public final class SQLiteStatement extends SQLiteProgram { 34 | SQLiteStatement(SQLiteDatabase db, String sql, Object[] bindArgs) { 35 | super(db, sql, bindArgs, null); 36 | } 37 | 38 | /** 39 | * Execute this SQL statement, if it is not a SELECT / INSERT / DELETE / UPDATE, for example 40 | * CREATE / DROP table, view, trigger, index etc. 41 | * 42 | * @throws android.database.SQLException If the SQL string is invalid for 43 | * some reason 44 | */ 45 | public void execute() { 46 | acquireReference(); 47 | try { 48 | getSession().execute(getSql(), getBindArgs(), getConnectionFlags(), null); 49 | } catch (SQLiteDatabaseCorruptException ex) { 50 | onCorruption(); 51 | throw ex; 52 | } finally { 53 | releaseReference(); 54 | } 55 | } 56 | 57 | /** 58 | * Execute this SQL statement, if the the number of rows affected by execution of this SQL 59 | * statement is of any importance to the caller - for example, UPDATE / DELETE SQL statements. 60 | * 61 | * @return the number of rows affected by this SQL statement execution. 62 | * @throws android.database.SQLException If the SQL string is invalid for 63 | * some reason 64 | */ 65 | public int executeUpdateDelete() { 66 | acquireReference(); 67 | try { 68 | return getSession().executeForChangedRowCount( 69 | getSql(), getBindArgs(), getConnectionFlags(), null); 70 | } catch (SQLiteDatabaseCorruptException ex) { 71 | onCorruption(); 72 | throw ex; 73 | } finally { 74 | releaseReference(); 75 | } 76 | } 77 | 78 | /** 79 | * Execute this SQL statement and return the ID of the row inserted due to this call. 80 | * The SQL statement should be an INSERT for this to be a useful call. 81 | * 82 | * @return the row ID of the last row inserted, if this insert is successful. -1 otherwise. 83 | * 84 | * @throws android.database.SQLException If the SQL string is invalid for 85 | * some reason 86 | */ 87 | public long executeInsert() { 88 | acquireReference(); 89 | try { 90 | return getSession().executeForLastInsertedRowId( 91 | getSql(), getBindArgs(), getConnectionFlags(), null); 92 | } catch (SQLiteDatabaseCorruptException ex) { 93 | onCorruption(); 94 | throw ex; 95 | } finally { 96 | releaseReference(); 97 | } 98 | } 99 | 100 | /** 101 | * Execute a statement that returns a 1 by 1 table with a numeric value. 102 | * For example, SELECT COUNT(*) FROM table; 103 | * 104 | * @return The result of the query. 105 | * 106 | * @throws android.database.sqlite.SQLiteDoneException if the query returns zero rows 107 | */ 108 | public long simpleQueryForLong() { 109 | acquireReference(); 110 | try { 111 | return getSession().executeForLong( 112 | getSql(), getBindArgs(), getConnectionFlags(), null); 113 | } catch (SQLiteDatabaseCorruptException ex) { 114 | onCorruption(); 115 | throw ex; 116 | } finally { 117 | releaseReference(); 118 | } 119 | } 120 | 121 | /** 122 | * Execute a statement that returns a 1 by 1 table with a text value. 123 | * For example, SELECT COUNT(*) FROM table; 124 | * 125 | * @return The result of the query. 126 | * 127 | * @throws android.database.sqlite.SQLiteDoneException if the query returns zero rows 128 | */ 129 | public String simpleQueryForString() { 130 | acquireReference(); 131 | try { 132 | return getSession().executeForString( 133 | getSql(), getBindArgs(), getConnectionFlags(), null); 134 | } catch (SQLiteDatabaseCorruptException ex) { 135 | onCorruption(); 136 | throw ex; 137 | } finally { 138 | releaseReference(); 139 | } 140 | } 141 | 142 | /** 143 | * Executes a statement that returns a 1 by 1 table with a blob value. 144 | * 145 | * @return A read-only file descriptor for a copy of the blob value, or {@code null} 146 | * if the value is null or could not be read for some reason. 147 | * 148 | * @throws android.database.sqlite.SQLiteDoneException if the query returns zero rows 149 | */ 150 | public ParcelFileDescriptor simpleQueryForBlobFileDescriptor() { 151 | acquireReference(); 152 | try { 153 | return getSession().executeForBlobFileDescriptor( 154 | getSql(), getBindArgs(), getConnectionFlags(), null); 155 | } catch (SQLiteDatabaseCorruptException ex) { 156 | onCorruption(); 157 | throw ex; 158 | } finally { 159 | releaseReference(); 160 | } 161 | } 162 | 163 | @Override 164 | public String toString() { 165 | return "SQLiteProgram: " + getSql(); 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /src/main/java/android/database/sqlite/SQLiteStatementInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 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 | ** Modified to support SQLite extensions by the SQLite developers: 18 | ** sqlite-dev@sqlite.org. 19 | */ 20 | 21 | package android.database.sqlite; 22 | 23 | /** 24 | * Describes a SQLite statement. 25 | * 26 | * @hide 27 | */ 28 | public final class SQLiteStatementInfo { 29 | /** 30 | * The number of parameters that the statement has. 31 | */ 32 | public int numParameters; 33 | 34 | /** 35 | * The names of all columns in the result set of the statement. 36 | */ 37 | public String[] columnNames; 38 | 39 | /** 40 | * True if the statement is read-only. 41 | */ 42 | public boolean readOnly; 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/android/database/sqlite/SQLiteTableLockedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 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 | ** Modified to support SQLite extensions by the SQLite developers: 18 | ** sqlite-dev@sqlite.org. 19 | */ 20 | 21 | package android.database.sqlite; 22 | 23 | public class SQLiteTableLockedException extends SQLiteException { 24 | public SQLiteTableLockedException() {} 25 | 26 | public SQLiteTableLockedException(String error) { 27 | super(error); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/android/database/sqlite/SQLiteTransactionListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 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 | ** Modified to support SQLite extensions by the SQLite developers: 18 | ** sqlite-dev@sqlite.org. 19 | */ 20 | 21 | package android.database.sqlite; 22 | 23 | /** 24 | * A listener for transaction events. 25 | */ 26 | public interface SQLiteTransactionListener { 27 | /** 28 | * Called immediately after the transaction begins. 29 | */ 30 | void onBegin(); 31 | 32 | /** 33 | * Called immediately before commiting the transaction. 34 | */ 35 | void onCommit(); 36 | 37 | /** 38 | * Called if the transaction is about to be rolled back. 39 | */ 40 | void onRollback(); 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/android/net/ConnectivityManager.kt: -------------------------------------------------------------------------------- 1 | package android.net 2 | 3 | import com.google.firebase.database.DataSnapshot 4 | import com.google.firebase.database.DatabaseError 5 | import com.google.firebase.database.FirebaseDatabase 6 | import com.google.firebase.database.ValueEventListener 7 | 8 | class ConnectivityManager private constructor() { 9 | 10 | companion object { 11 | val instance = ConnectivityManager() 12 | } 13 | 14 | private val connected = FirebaseDatabase.getInstance().getReference(".info/connected") 15 | 16 | fun registerDefaultNetworkCallback(networkCallback: NetworkCallback) { 17 | connected.addValueEventListener(networkCallback) 18 | } 19 | 20 | fun unregisterNetworkCallback(networkCallback: NetworkCallback) { 21 | connected.removeEventListener(networkCallback) 22 | } 23 | 24 | open class NetworkCallback : ValueEventListener { 25 | override fun onDataChange(data: DataSnapshot) { 26 | when (data.getValue(Boolean::class.java)) { 27 | true -> onAvailable(null) 28 | else -> onLost(null) 29 | } 30 | } 31 | 32 | override fun onCancelled(error: DatabaseError) { 33 | throw error.toException() 34 | } 35 | 36 | open fun onAvailable(network: Network?) {} 37 | open fun onLost(network: Network?) {} 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/android/net/SSLCertificateSocketFactory.kt: -------------------------------------------------------------------------------- 1 | package android.net 2 | 3 | import java.net.InetAddress 4 | import java.net.Socket 5 | import javax.net.ssl.HttpsURLConnection 6 | import javax.net.ssl.SSLSocketFactory 7 | 8 | class SSLCertificateSocketFactory() : SSLSocketFactory() { 9 | 10 | companion object { 11 | 12 | init { 13 | HttpsURLConnection.setDefaultHostnameVerifier { _, _ -> true } 14 | } 15 | 16 | @JvmStatic 17 | fun getDefault(timeout: Int, cache: SSLSessionCache): SSLSocketFactory = SSLCertificateSocketFactory() 18 | } 19 | 20 | private val instance = SSLSocketFactory.getDefault() as SSLSocketFactory 21 | 22 | override fun getDefaultCipherSuites(): Array = instance.defaultCipherSuites 23 | 24 | override fun createSocket(p0: Socket?, p1: String?, p2: Int, p3: Boolean): Socket = instance.createSocket(p0, p1, p2, p3) 25 | 26 | override fun createSocket(p0: String?, p1: Int): Socket = instance.createSocket(p0, p1) 27 | 28 | override fun createSocket(p0: String?, p1: Int, p2: InetAddress?, p3: Int): Socket = instance.createSocket(p0, p1) 29 | 30 | override fun createSocket(p0: InetAddress?, p1: Int): Socket = instance.createSocket(p0, p1) 31 | 32 | override fun createSocket(p0: InetAddress?, p1: Int, p2: InetAddress?, p3: Int): Socket = instance.createSocket(p0, p1, p2, p3) 33 | 34 | override fun getSupportedCipherSuites(): Array = instance.supportedCipherSuites 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/android/net/SSLSessionCache.java: -------------------------------------------------------------------------------- 1 | package android.net; 2 | 3 | import java.io.File; 4 | 5 | public class SSLSessionCache { 6 | public SSLSessionCache(File dir) { 7 | 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/android/net/Uri.kt: -------------------------------------------------------------------------------- 1 | package android.net 2 | 3 | import java.net.URI 4 | import java.util.Collections 5 | 6 | class Uri(private val uri: URI) { 7 | 8 | companion object { 9 | @JvmStatic 10 | fun parse(uriString: String) = Uri(URI.create(uriString)) 11 | } 12 | 13 | val scheme get() = uri.scheme 14 | val port get() = uri.port 15 | val host get() = uri.host 16 | 17 | fun getQueryParameterNames(): Set { 18 | val query: String = uri.query ?: return emptySet() 19 | val names: MutableSet = LinkedHashSet() 20 | var start = 0 21 | do { 22 | val next = query.indexOf('&', start) 23 | val end = if ((next == -1)) query.length else next 24 | var separator = query.indexOf('=', start) 25 | if (separator > end || separator == -1) { 26 | separator = end 27 | } 28 | val name = query.substring(start, separator) 29 | names.add(name) 30 | // Move start to end of name. 31 | start = end + 1 32 | } while (start < query.length) 33 | return Collections.unmodifiableSet(names) 34 | } 35 | 36 | fun getQueryParameter(key: String?): String? { 37 | if (key == null) { 38 | throw NullPointerException("key") 39 | } 40 | val query: String = uri.query ?: return null 41 | val length = query.length 42 | var start = 0 43 | do { 44 | val nextAmpersand = query.indexOf('&', start) 45 | val end = if (nextAmpersand != -1) nextAmpersand else length 46 | var separator = query.indexOf('=', start) 47 | if (separator > end || separator == -1) { 48 | separator = end 49 | } 50 | if (separator - start == key.length && 51 | query.regionMatches(start, key, 0, key.length) 52 | ) { 53 | if (separator == end) { 54 | return "" 55 | } else { 56 | return query.substring(separator + 1, end) 57 | } 58 | } 59 | // Move start to end of name. 60 | if (nextAmpersand != -1) { 61 | start = nextAmpersand + 1 62 | } else { 63 | break 64 | } 65 | } while (true) 66 | return null 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/android/os/AsyncTask.kt: -------------------------------------------------------------------------------- 1 | package android.os 2 | 3 | import kotlinx.coroutines.Dispatchers 4 | import kotlinx.coroutines.GlobalScope 5 | import kotlinx.coroutines.launch 6 | import kotlinx.coroutines.withContext 7 | import java.util.concurrent.Executor 8 | 9 | abstract class AsyncTask { 10 | 11 | companion object { 12 | @JvmField 13 | val THREAD_POOL_EXECUTOR = Executor { 14 | GlobalScope.launch { 15 | it.run() 16 | } 17 | } 18 | } 19 | 20 | fun execute(vararg params: Any): AsyncTask { 21 | GlobalScope.launch { 22 | withContext(Dispatchers.Main) { onPreExecute() } 23 | val result = doInBackground(*params) 24 | withContext(Dispatchers.Main) { onPostExecute(result) } 25 | } 26 | return this 27 | } 28 | 29 | protected abstract fun doInBackground(vararg params: Any): Any 30 | 31 | protected open fun onPreExecute() {} 32 | 33 | protected open fun onPostExecute(result: Any) {} 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/android/os/Binder.java: -------------------------------------------------------------------------------- 1 | package android.os; 2 | 3 | public class Binder { 4 | public void attachInterface (IInterface owner, 5 | String descriptor) { 6 | 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/android/os/Build.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 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 android.os; 18 | 19 | /** 20 | * Information about the current build, extracted from system properties. 21 | */ 22 | public class Build { 23 | 24 | // /** Various version strings. */ 25 | public static class VERSION { 26 | 27 | public static final int SDK_INT = 28; 28 | 29 | } 30 | 31 | public static final String PRODUCT = "unknown"; 32 | public static final String DEVICE = "unknown"; 33 | public static final String BRAND = "unknown"; 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/android/os/Bundle.java: -------------------------------------------------------------------------------- 1 | package android.os; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | import java.util.Set; 6 | 7 | public class Bundle { 8 | 9 | private final Map data; 10 | 11 | public Bundle(Map data) { 12 | this.data = data; 13 | } 14 | 15 | public Bundle(Bundle bundle) { 16 | this.data = new HashMap<>(bundle.data); 17 | } 18 | 19 | public boolean containsKey(String key) { 20 | if(data.containsKey(key)) return true; 21 | throw new IllegalArgumentException(key); 22 | } 23 | 24 | public Set keySet() { 25 | return data.keySet(); 26 | } 27 | 28 | public boolean getBoolean(String key) { 29 | 30 | return (Boolean)data.get(key); 31 | } 32 | 33 | public Object get(String key) { 34 | containsKey(key); 35 | return data.get(key); 36 | } 37 | 38 | public String getString(String key) { 39 | containsKey(key); 40 | return (String)data.get(key); 41 | } 42 | 43 | public int getInt(String key) { 44 | return (Integer)data.get(key); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/android/os/CancellationSignal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 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 | package android.os; 17 | 18 | /** 19 | * Provides the ability to cancel an operation in progress. 20 | */ 21 | public final class CancellationSignal { 22 | private boolean mIsCanceled; 23 | private OnCancelListener mOnCancelListener; 24 | private ICancellationSignal mRemote; 25 | private boolean mCancelInProgress; 26 | /** 27 | * Creates a cancellation signal, initially not canceled. 28 | */ 29 | public CancellationSignal() { 30 | } 31 | /** 32 | * Returns true if the operation has been canceled. 33 | * 34 | * @return True if the operation has been canceled. 35 | */ 36 | public boolean isCanceled() { 37 | synchronized (this) { 38 | return mIsCanceled; 39 | } 40 | } 41 | /** 42 | * Throws {@link OperationCanceledException} if the operation has been canceled. 43 | * 44 | * @throws OperationCanceledException if the operation has been canceled. 45 | */ 46 | public void throwIfCanceled() { 47 | if (isCanceled()) { 48 | throw new OperationCanceledException(); 49 | } 50 | } 51 | /** 52 | * Cancels the operation and signals the cancellation listener. 53 | * If the operation has not yet started, then it will be canceled as soon as it does. 54 | */ 55 | public void cancel() { 56 | final OnCancelListener listener; 57 | final ICancellationSignal remote; 58 | synchronized (this) { 59 | if (mIsCanceled) { 60 | return; 61 | } 62 | mIsCanceled = true; 63 | mCancelInProgress = true; 64 | listener = mOnCancelListener; 65 | remote = mRemote; 66 | } 67 | try { 68 | if (listener != null) { 69 | listener.onCancel(); 70 | } 71 | if (remote != null) { 72 | try { 73 | remote.cancel(); 74 | } catch (RemoteException ex) { 75 | } 76 | } 77 | } finally { 78 | synchronized (this) { 79 | mCancelInProgress = false; 80 | notifyAll(); 81 | } 82 | } 83 | } 84 | /** 85 | * Sets the cancellation listener to be called when canceled. 86 | * 87 | * This method is intended to be used by the recipient of a cancellation signal 88 | * such as a database or a content provider to handle cancellation requests 89 | * while performing a long-running operation. This method is not intended to be 90 | * used by applications themselves. 91 | * 92 | * If {@link CancellationSignal#cancel} has already been called, then the provided 93 | * listener is invoked immediately. 94 | * 95 | * This method is guaranteed that the listener will not be called after it 96 | * has been removed. 97 | * 98 | * @param listener The cancellation listener, or null to remove the current listener. 99 | */ 100 | public void setOnCancelListener(OnCancelListener listener) { 101 | synchronized (this) { 102 | waitForCancelFinishedLocked(); 103 | if (mOnCancelListener == listener) { 104 | return; 105 | } 106 | mOnCancelListener = listener; 107 | if (!mIsCanceled || listener == null) { 108 | return; 109 | } 110 | } 111 | listener.onCancel(); 112 | } 113 | /** 114 | * Sets the remote transport. 115 | * 116 | * If {@link CancellationSignal#cancel} has already been called, then the provided 117 | * remote transport is canceled immediately. 118 | * 119 | * This method is guaranteed that the remote transport will not be called after it 120 | * has been removed. 121 | * 122 | * @param remote The remote transport, or null to remove. 123 | * 124 | * @hide 125 | */ 126 | public void setRemote(ICancellationSignal remote) { 127 | synchronized (this) { 128 | waitForCancelFinishedLocked(); 129 | if (mRemote == remote) { 130 | return; 131 | } 132 | mRemote = remote; 133 | if (!mIsCanceled || remote == null) { 134 | return; 135 | } 136 | } 137 | try { 138 | remote.cancel(); 139 | } catch (RemoteException ex) { 140 | } 141 | } 142 | 143 | private void waitForCancelFinishedLocked() { 144 | while (mCancelInProgress) { 145 | try { 146 | wait(); 147 | } catch (InterruptedException ex) { 148 | } 149 | } 150 | } 151 | /** 152 | * Creates a transport that can be returned back to the caller of 153 | * a Binder function and subsequently used to dispatch a cancellation signal. 154 | * 155 | * @return The new cancellation signal transport. 156 | * 157 | * @hide 158 | */ 159 | public static ICancellationSignal createTransport() { 160 | return new Transport(); 161 | } 162 | /** 163 | * Given a locally created transport, returns its associated cancellation signal. 164 | * 165 | * @param transport The locally created transport, or null if none. 166 | * @return The associated cancellation signal, or null if none. 167 | * 168 | * @hide 169 | */ 170 | public static CancellationSignal fromTransport(ICancellationSignal transport) { 171 | if (transport instanceof Transport) { 172 | return ((Transport)transport).mCancellationSignal; 173 | } 174 | return null; 175 | } 176 | /** 177 | * Listens for cancellation. 178 | */ 179 | public interface OnCancelListener { 180 | /** 181 | * Called when {@link CancellationSignal#cancel} is invoked. 182 | */ 183 | void onCancel(); 184 | } 185 | private static final class Transport extends ICancellationSignal.Stub { 186 | final CancellationSignal mCancellationSignal = new CancellationSignal(); 187 | @Override 188 | public void cancel() throws RemoteException { 189 | mCancellationSignal.cancel(); 190 | } 191 | } 192 | } -------------------------------------------------------------------------------- /src/main/java/android/os/DeadObjectException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 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 android.os; 18 | 19 | /** 20 | * The object you are calling has died, because its hosting process 21 | * no longer exists. 22 | */ 23 | public class DeadObjectException extends RemoteException { 24 | public DeadObjectException() { 25 | super(); 26 | } 27 | 28 | public DeadObjectException(String message) { 29 | super(message); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/android/os/Handler.kt: -------------------------------------------------------------------------------- 1 | package android.os 2 | 3 | import kotlinx.coroutines.Dispatchers 4 | import kotlinx.coroutines.GlobalScope 5 | import kotlinx.coroutines.delay 6 | import kotlinx.coroutines.launch 7 | 8 | open class Handler(looper: Looper?, callback: Handler.Callback?) { 9 | 10 | constructor(looper: Looper) : this(looper, null) 11 | 12 | fun post(runnable: Runnable): Boolean { 13 | GlobalScope.launch(Dispatchers.Main) { 14 | runnable.run() 15 | } 16 | return true 17 | } 18 | 19 | fun postDelayed(runnable: Runnable, time: Long): Boolean { 20 | GlobalScope.launch(Dispatchers.Main) { 21 | delay(time) 22 | runnable.run() 23 | } 24 | return true 25 | } 26 | 27 | fun getIMessenger(): IMessenger { 28 | return object : IMessenger { 29 | override fun send(p0: Message?) { 30 | TODO("not implemented") 31 | } 32 | 33 | override fun asBinder(): IBinder { 34 | TODO("not implemented") 35 | } 36 | } 37 | } 38 | 39 | fun obtainMessage(id: Int): Message? { 40 | return Message(id, null) 41 | } 42 | 43 | fun obtainMessage(id: Int, params: Any): Message? { 44 | return Message(id, params) 45 | } 46 | 47 | fun sendMessage(message: Message): Boolean { 48 | return when (message.id) { 49 | 6 -> false 50 | 7 -> false 51 | else -> { // Note the block 52 | throw IllegalArgumentException("${message.id}") 53 | } 54 | } 55 | } 56 | 57 | companion object { 58 | @JvmStatic 59 | fun createAsync(looper: Looper) = Handler(looper) 60 | } 61 | 62 | fun removeCallbacks(r: Runnable) { 63 | } 64 | 65 | interface Callback 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/android/os/HandlerThread.java: -------------------------------------------------------------------------------- 1 | package android.os; 2 | 3 | public class HandlerThread { 4 | public HandlerThread(String name, int flags) { 5 | 6 | } 7 | 8 | public void start() { 9 | 10 | } 11 | 12 | public Looper getLooper() { 13 | return new Looper(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/android/os/IBinder.java: -------------------------------------------------------------------------------- 1 | package android.os; 2 | 3 | public interface IBinder { 4 | } 5 | -------------------------------------------------------------------------------- /src/main/java/android/os/IInterface.java: -------------------------------------------------------------------------------- 1 | package android.os; 2 | 3 | public interface IInterface { 4 | IBinder asBinder(); 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/android/os/IMessenger.kt: -------------------------------------------------------------------------------- 1 | package android.os 2 | 3 | interface IMessenger : IBinder { 4 | 5 | fun send(p0: Message?) 6 | fun asBinder(): IBinder 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/android/os/Looper.java: -------------------------------------------------------------------------------- 1 | package android.os; 2 | 3 | import javax.swing.*; 4 | 5 | public class Looper { 6 | private static final Looper main = new Looper(); 7 | 8 | public Thread getThread() { 9 | return Thread.currentThread(); 10 | } 11 | 12 | public static Looper getMainLooper() { 13 | return main; 14 | } 15 | 16 | public static Looper myLooper() { 17 | return SwingUtilities.isEventDispatchThread() ? main : new Looper(); 18 | } 19 | 20 | static void prepare() { 21 | 22 | } 23 | 24 | static void loop() { 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/android/os/Message.java: -------------------------------------------------------------------------------- 1 | package android.os; 2 | 3 | public class Message { 4 | final int id; 5 | final Object params; 6 | 7 | public Message(int id, Object params) { 8 | this.id = id; 9 | this.params = params; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/android/os/Messenger.java: -------------------------------------------------------------------------------- 1 | package android.os; 2 | 3 | public class Messenger { 4 | public Messenger(Handler handler) { 5 | 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/android/os/OperationCanceledException.kt: -------------------------------------------------------------------------------- 1 | package android.os 2 | 3 | class OperationCanceledException : RuntimeException() 4 | -------------------------------------------------------------------------------- /src/main/java/android/os/Parcelable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 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 android.os; 18 | 19 | import android.annotation.IntDef; 20 | 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | 24 | /** 25 | * Interface for classes whose instances can be written to 26 | * and restored from a {@link Parcel}. Classes implementing the Parcelable 27 | * interface must also have a non-null static field called CREATOR 28 | * of a type that implements the {@link Creator} interface. 29 | * 30 | *

A typical implementation of Parcelable is:

31 | * 32 | *
 33 |  * public class MyParcelable implements Parcelable {
 34 |  *     private int mData;
 35 |  *
 36 |  *     public int describeContents() {
 37 |  *         return 0;
 38 |  *     }
 39 |  *
 40 |  *     public void writeToParcel(Parcel out, int flags) {
 41 |  *         out.writeInt(mData);
 42 |  *     }
 43 |  *
 44 |  *     public static final Parcelable.Creator<MyParcelable> CREATOR
 45 |  *             = new Parcelable.Creator<MyParcelable>() {
 46 |  *         public MyParcelable createFromParcel(Parcel in) {
 47 |  *             return new MyParcelable(in);
 48 |  *         }
 49 |  *
 50 |  *         public MyParcelable[] newArray(int size) {
 51 |  *             return new MyParcelable[size];
 52 |  *         }
 53 |  *     };
 54 |  *     
 55 |  *     private MyParcelable(Parcel in) {
 56 |  *         mData = in.readInt();
 57 |  *     }
 58 |  * }
59 | */ 60 | public interface Parcelable { 61 | @IntDef(flag = true, prefix = { "PARCELABLE_" }, value = { 62 | PARCELABLE_WRITE_RETURN_VALUE, 63 | PARCELABLE_ELIDE_DUPLICATES, 64 | }) 65 | @Retention(RetentionPolicy.SOURCE) 66 | public @interface WriteFlags {} 67 | 68 | /** 69 | * Flag for use with {@link #writeToParcel}: the object being written 70 | * is a return value, that is the result of a function such as 71 | * "Parcelable someFunction()", 72 | * "void someFunction(out Parcelable)", or 73 | * "void someFunction(inout Parcelable)". Some implementations 74 | * may want to release resources at this point. 75 | */ 76 | public static final int PARCELABLE_WRITE_RETURN_VALUE = 0x0001; 77 | 78 | /** 79 | * Flag for use with {@link #writeToParcel}: a parent object will take 80 | * care of managing duplicate state/data that is nominally replicated 81 | * across its inner data members. This flag instructs the inner data 82 | * types to omit that data during marshaling. Exact behavior may vary 83 | * on a case by case basis. 84 | */ 85 | public static final int PARCELABLE_ELIDE_DUPLICATES = 0x0002; 86 | 87 | /* 88 | * Bit masks for use with {@link #describeContents}: each bit represents a 89 | * kind of object considered to have potential special significance when 90 | * marshalled. 91 | */ 92 | 93 | @IntDef(flag = true, prefix = { "CONTENTS_" }, value = { 94 | CONTENTS_FILE_DESCRIPTOR, 95 | }) 96 | @Retention(RetentionPolicy.SOURCE) 97 | public @interface ContentsFlags {} 98 | 99 | /** 100 | * Descriptor bit used with {@link #describeContents()}: indicates that 101 | * the Parcelable object's flattened representation includes a file descriptor. 102 | * 103 | * @see #describeContents() 104 | */ 105 | public static final int CONTENTS_FILE_DESCRIPTOR = 0x0001; 106 | 107 | /** 108 | * Describe the kinds of special objects contained in this Parcelable 109 | * instance's marshaled representation. For example, if the object will 110 | * include a file descriptor in the output of {@link #writeToParcel(Parcel, int)}, 111 | * the return value of this method must include the 112 | * {@link #CONTENTS_FILE_DESCRIPTOR} bit. 113 | * 114 | * @return a bitmask indicating the set of special object types marshaled 115 | * by this Parcelable object instance. 116 | */ 117 | public @ContentsFlags int describeContents(); 118 | 119 | /** 120 | * Flatten this object in to a Parcel. 121 | * 122 | * @param dest The Parcel in which the object should be written. 123 | * @param flags Additional flags about how the object should be written. 124 | * May be 0 or {@link #PARCELABLE_WRITE_RETURN_VALUE}. 125 | */ 126 | public void writeToParcel(Parcel dest, @WriteFlags int flags); 127 | 128 | /** 129 | * Interface that must be implemented and provided as a public CREATOR 130 | * field that generates instances of your Parcelable class from a Parcel. 131 | */ 132 | public interface Creator { 133 | /** 134 | * Create a new instance of the Parcelable class, instantiating it 135 | * from the given Parcel whose data had previously been written by 136 | * {@link Parcelable#writeToParcel Parcelable.writeToParcel()}. 137 | * 138 | * @param source The Parcel to read the object's data from. 139 | * @return Returns a new instance of the Parcelable class. 140 | */ 141 | public T createFromParcel(Parcel source); 142 | 143 | /** 144 | * Create a new array of the Parcelable class. 145 | * 146 | * @param size Size of the array. 147 | * @return Returns an array of the Parcelable class, with every entry 148 | * initialized to null. 149 | */ 150 | public T[] newArray(int size); 151 | } 152 | 153 | /** 154 | * Specialization of {@link Creator} that allows you to receive the 155 | * ClassLoader the object is being created in. 156 | */ 157 | public interface ClassLoaderCreator extends Creator { 158 | /** 159 | * Create a new instance of the Parcelable class, instantiating it 160 | * from the given Parcel whose data had previously been written by 161 | * {@link Parcelable#writeToParcel Parcelable.writeToParcel()} and 162 | * using the given ClassLoader. 163 | * 164 | * @param source The Parcel to read the object's data from. 165 | * @param loader The ClassLoader that this object is being created in. 166 | * @return Returns a new instance of the Parcelable class. 167 | */ 168 | public T createFromParcel(Parcel source, ClassLoader loader); 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /src/main/java/android/os/PowerManager.java: -------------------------------------------------------------------------------- 1 | package android.os; 2 | 3 | public class PowerManager { 4 | 5 | public WakeLock newWakeLock(int flags, String name) { 6 | return new WakeLock(); 7 | } 8 | 9 | public class WakeLock { 10 | 11 | public void setReferenceCounted(boolean a) {} 12 | 13 | public void acquire() {} 14 | 15 | public void release() {} 16 | } 17 | 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/android/os/Process.java: -------------------------------------------------------------------------------- 1 | package android.os; 2 | 3 | public class Process { 4 | public static void setThreadPriority(int p) {} 5 | 6 | public static int myTid() { 7 | return 0; 8 | } 9 | 10 | public static int myPid() { 11 | return 0; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/android/os/RemoteException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 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 android.os; 18 | 19 | import android.util.AndroidException; 20 | 21 | /** 22 | * Parent exception for all Binder remote-invocation errors 23 | */ 24 | public class RemoteException extends AndroidException { 25 | public RemoteException() { 26 | super(); 27 | } 28 | 29 | public RemoteException(String message) { 30 | super(message); 31 | } 32 | 33 | /** */ 34 | public RemoteException(String message, Throwable cause, boolean enableSuppression, 35 | boolean writableStackTrace) { 36 | super(message, cause, enableSuppression, writableStackTrace); 37 | } 38 | 39 | /** {} */ 40 | public RuntimeException rethrowAsRuntimeException() { 41 | throw new RuntimeException(this); 42 | } 43 | 44 | /** 45 | * Rethrow this exception when we know it came from the system server. This 46 | * gives us an opportunity to throw a nice clean 47 | * {@link DeadSystemException} signal to avoid spamming logs with 48 | * misleading stack traces. 49 | *

50 | * Apps making calls into the system server may end up persisting internal 51 | * state or making security decisions based on the perceived success or 52 | * failure of a call, or any default values returned. For this reason, we 53 | * want to strongly throw when there was trouble with the transaction. 54 | * 55 | * 56 | */ 57 | public RuntimeException rethrowFromSystemServer() { 58 | if (this instanceof DeadObjectException) { 59 | throw new RuntimeException(new DeadSystemException()); 60 | } else { 61 | throw new RuntimeException(this); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/android/os/StatFs.java: -------------------------------------------------------------------------------- 1 | package android.os; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | public class StatFs { 7 | 8 | File file; 9 | 10 | public StatFs(String path) { 11 | file = new File(path); 12 | } 13 | 14 | public int getBlockSize() { 15 | try { 16 | return (int)file.toPath().getFileSystem().getFileStores().iterator().next().getBlockSize(); 17 | } catch (IOException e) { 18 | throw new RuntimeException(e); 19 | } 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/android/os/StrictMode.java: -------------------------------------------------------------------------------- 1 | package android.os; 2 | 3 | public class StrictMode { 4 | 5 | public static void setThreadPolicy(ThreadPolicy policy) { 6 | 7 | } 8 | 9 | public static final class ThreadPolicy { 10 | public static final class Builder { 11 | public Builder detectAll() { 12 | return this; 13 | } 14 | public Builder detectNetwork() { 15 | return this; 16 | } 17 | public Builder detectResourceMismatches() { 18 | return this; 19 | } 20 | public Builder detectUnbufferedIo() { 21 | return this; 22 | } 23 | public Builder penaltyLog() { 24 | return this; 25 | } 26 | public ThreadPolicy build() { 27 | return new ThreadPolicy(); 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/android/os/SystemClock.java: -------------------------------------------------------------------------------- 1 | package android.os; 2 | 3 | import java.lang.management.ManagementFactory; 4 | 5 | public final class SystemClock { 6 | public static long elapsedRealtime() { 7 | return ManagementFactory.getRuntimeMXBean().getUptime(); 8 | } 9 | public static long uptimeMillis() { 10 | return ManagementFactory.getRuntimeMXBean().getUptime(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/android/os/Trace.java: -------------------------------------------------------------------------------- 1 | package android.os; 2 | 3 | public final class Trace { 4 | public static void beginSection(String sectionName) {} 5 | public static void endSection() {} 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/android/os/UserManager.java: -------------------------------------------------------------------------------- 1 | package android.os; 2 | 3 | public class UserManager { 4 | 5 | public boolean isUserUnlocked() { 6 | return true; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/android/text/Spannable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 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 android.text; 18 | 19 | /** 20 | * This is the interface for text to which markup objects can be 21 | * attached and detached. Not all Spannable classes have mutable text; 22 | * see {@link Editable} for that. 23 | */ 24 | public interface Spannable 25 | extends Spanned 26 | { 27 | /** 28 | * Attach the specified markup object to the range start…end 29 | * of the text, or move the object to that range if it was already 30 | * attached elsewhere. See {@link Spanned} for an explanation of 31 | * what the flags mean. The object can be one that has meaning only 32 | * within your application, or it can be one that the text system will 33 | * use to affect text display or behavior. Some noteworthy ones are 34 | * the subclasses of {@link android.text.style.CharacterStyle} and 35 | * {@link android.text.style.ParagraphStyle}, and 36 | * {@link TextWatcher} and 37 | * {@link SpanWatcher}. 38 | */ 39 | public void setSpan(Object what, int start, int end, int flags); 40 | 41 | /** 42 | * Remove the specified object from the range of text to which it 43 | * was attached, if any. It is OK to remove an object that was never 44 | * attached in the first place. 45 | */ 46 | public void removeSpan(Object what); 47 | 48 | /** 49 | * Remove the specified object from the range of text to which it 50 | * was attached, if any. It is OK to remove an object that was never 51 | * attached in the first place. 52 | * 53 | * See {@link Spanned} for an explanation of what the flags mean. 54 | * 55 | * 56 | */ 57 | default void removeSpan(Object what, int flags) { 58 | removeSpan(what); 59 | } 60 | 61 | /** 62 | * Factory used by TextView to create new {@link Spannable Spannables}. You can subclass 63 | * it to provide something other than {@link SpannableString}. 64 | * 65 | * @see android.widget.TextView#setSpannableFactory(Factory) 66 | */ 67 | public static class Factory { 68 | private static Factory sInstance = new Factory(); 69 | 70 | /** 71 | * Returns the standard Spannable Factory. 72 | */ 73 | public static Factory getInstance() { 74 | return sInstance; 75 | } 76 | 77 | /** 78 | * Returns a new SpannableString from the specified CharSequence. 79 | * You can override this to provide a different kind of Spannable. 80 | */ 81 | public Spannable newSpannable(CharSequence source) { 82 | return new SpannableString(source); 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/android/util/AndroidException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 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 android.util; 18 | 19 | /** 20 | * Base class for all checked exceptions thrown by the Android frameworks. 21 | */ 22 | public class AndroidException extends Exception { 23 | public AndroidException() { 24 | } 25 | 26 | public AndroidException(String name) { 27 | super(name); 28 | } 29 | 30 | public AndroidException(String name, Throwable cause) { 31 | super(name, cause); 32 | } 33 | 34 | public AndroidException(Exception cause) { 35 | super(cause); 36 | } 37 | 38 | /** */ 39 | protected AndroidException(String message, Throwable cause, boolean enableSuppression, 40 | boolean writableStackTrace) { 41 | super(message, cause, enableSuppression, writableStackTrace); 42 | } 43 | }; 44 | 45 | -------------------------------------------------------------------------------- /src/main/java/android/util/Base64OutputStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 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 android.util; 18 | 19 | import java.io.FilterOutputStream; 20 | import java.io.IOException; 21 | import java.io.OutputStream; 22 | 23 | /** 24 | * An OutputStream that does Base64 encoding on the data written to 25 | * it, writing the resulting data to another OutputStream. 26 | */ 27 | public class Base64OutputStream extends FilterOutputStream { 28 | private final Base64.Coder coder; 29 | private final int flags; 30 | 31 | private byte[] buffer = null; 32 | private int bpos = 0; 33 | 34 | private static byte[] EMPTY = new byte[0]; 35 | 36 | /** 37 | * Performs Base64 encoding on the data written to the stream, 38 | * writing the encoded data to another OutputStream. 39 | * 40 | * @param out the OutputStream to write the encoded data to 41 | * @param flags bit flags for controlling the encoder; see the 42 | * constants in {@link Base64} 43 | */ 44 | public Base64OutputStream(OutputStream out, int flags) { 45 | this(out, flags, true); 46 | } 47 | 48 | /** 49 | * Performs Base64 encoding or decoding on the data written to the 50 | * stream, writing the encoded/decoded data to another 51 | * OutputStream. 52 | * 53 | * @param out the OutputStream to write the encoded data to 54 | * @param flags bit flags for controlling the encoder; see the 55 | * constants in {@link Base64} 56 | * @param encode true to encode, false to decode 57 | * 58 | * 59 | */ 60 | public Base64OutputStream(OutputStream out, int flags, boolean encode) { 61 | super(out); 62 | this.flags = flags; 63 | if (encode) { 64 | coder = new Base64.Encoder(flags, null); 65 | } else { 66 | coder = new Base64.Decoder(flags, null); 67 | } 68 | } 69 | 70 | public void write(int b) throws IOException { 71 | // To avoid invoking the encoder/decoder routines for single 72 | // bytes, we buffer up calls to write(int) in an internal 73 | // byte array to transform them into writes of decently-sized 74 | // arrays. 75 | 76 | if (buffer == null) { 77 | buffer = new byte[1024]; 78 | } 79 | if (bpos >= buffer.length) { 80 | // internal buffer full; write it out. 81 | internalWrite(buffer, 0, bpos, false); 82 | bpos = 0; 83 | } 84 | buffer[bpos++] = (byte) b; 85 | } 86 | 87 | /** 88 | * Flush any buffered data from calls to write(int). Needed 89 | * before doing a write(byte[], int, int) or a close(). 90 | */ 91 | private void flushBuffer() throws IOException { 92 | if (bpos > 0) { 93 | internalWrite(buffer, 0, bpos, false); 94 | bpos = 0; 95 | } 96 | } 97 | 98 | public void write(byte[] b, int off, int len) throws IOException { 99 | if (len <= 0) return; 100 | flushBuffer(); 101 | internalWrite(b, off, len, false); 102 | } 103 | 104 | public void close() throws IOException { 105 | IOException thrown = null; 106 | try { 107 | flushBuffer(); 108 | internalWrite(EMPTY, 0, 0, true); 109 | } catch (IOException e) { 110 | thrown = e; 111 | } 112 | 113 | try { 114 | if ((flags & Base64.NO_CLOSE) == 0) { 115 | out.close(); 116 | } else { 117 | out.flush(); 118 | } 119 | } catch (IOException e) { 120 | if (thrown != null) { 121 | thrown = e; 122 | } 123 | } 124 | 125 | if (thrown != null) { 126 | throw thrown; 127 | } 128 | } 129 | 130 | /** 131 | * Write the given bytes to the encoder/decoder. 132 | * 133 | * @param finish true if this is the last batch of input, to cause 134 | * encoder/decoder state to be finalized. 135 | */ 136 | private void internalWrite(byte[] b, int off, int len, boolean finish) throws IOException { 137 | coder.output = embiggen(coder.output, coder.maxOutputSize(len)); 138 | if (!coder.process(b, off, len, finish)) { 139 | throw new Base64DataException("bad base-64"); 140 | } 141 | out.write(coder.output, 0, coder.op); 142 | } 143 | 144 | /** 145 | * If b.length is at least len, return b. Otherwise return a new 146 | * byte array of length len. 147 | */ 148 | private byte[] embiggen(byte[] b, int len) { 149 | if (b == null || b.length < len) { 150 | return new byte[len]; 151 | } else { 152 | return b; 153 | } 154 | } 155 | } -------------------------------------------------------------------------------- /src/main/java/android/util/ContainerHelpers.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 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 android.util; 18 | 19 | class ContainerHelpers { 20 | 21 | // This is Arrays.binarySearch(), but doesn't do any argument validation. 22 | static int binarySearch(int[] array, int size, int value) { 23 | int lo = 0; 24 | int hi = size - 1; 25 | 26 | while (lo <= hi) { 27 | final int mid = (lo + hi) >>> 1; 28 | final int midVal = array[mid]; 29 | 30 | if (midVal < value) { 31 | lo = mid + 1; 32 | } else if (midVal > value) { 33 | hi = mid - 1; 34 | } else { 35 | return mid; // value found 36 | } 37 | } 38 | return ~lo; // value not present 39 | } 40 | 41 | static int binarySearch(long[] array, int size, long value) { 42 | int lo = 0; 43 | int hi = size - 1; 44 | 45 | while (lo <= hi) { 46 | final int mid = (lo + hi) >>> 1; 47 | final long midVal = array[mid]; 48 | 49 | if (midVal < value) { 50 | lo = mid + 1; 51 | } else if (midVal > value) { 52 | hi = mid - 1; 53 | } else { 54 | return mid; // value found 55 | } 56 | } 57 | return ~lo; // value not present 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/android/util/Pair.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 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 android.util; 18 | 19 | import java.util.Objects; 20 | 21 | /** 22 | * Container to ease passing around a tuple of two objects. This object provides a sensible 23 | * implementation of equals(), returning true if equals() is true on each of the contained 24 | * objects. 25 | */ 26 | public class Pair { 27 | public final F first; 28 | public final S second; 29 | 30 | /** 31 | * Constructor for a Pair. 32 | * 33 | * @param first the first object in the Pair 34 | * @param second the second object in the pair 35 | */ 36 | public Pair(F first, S second) { 37 | this.first = first; 38 | this.second = second; 39 | } 40 | 41 | /** 42 | * Checks the two objects for equality by delegating to their respective 43 | * {@link Object#equals(Object)} methods. 44 | * 45 | * @param o the {@link Pair} to which this one is to be checked for equality 46 | * @return true if the underlying objects of the Pair are both considered 47 | * equal 48 | */ 49 | @Override 50 | public boolean equals(Object o) { 51 | if (!(o instanceof Pair)) { 52 | return false; 53 | } 54 | Pair p = (Pair) o; 55 | return Objects.equals(p.first, first) && Objects.equals(p.second, second); 56 | } 57 | 58 | /** 59 | * Compute a hash code using the hash codes of the underlying objects 60 | * 61 | * @return a hashcode of the Pair 62 | */ 63 | @Override 64 | public int hashCode() { 65 | return (first == null ? 0 : first.hashCode()) ^ (second == null ? 0 : second.hashCode()); 66 | } 67 | 68 | @Override 69 | public String toString() { 70 | return "Pair{" + String.valueOf(first) + " " + String.valueOf(second) + "}"; 71 | } 72 | 73 | /** 74 | * Convenience method for creating an appropriately typed pair. 75 | * @param a the first object in the Pair 76 | * @param b the second object in the pair 77 | * @return a Pair that is templatized with the types of a and b 78 | */ 79 | public static Pair create(A a, B b) { 80 | return new Pair(a, b); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/android/view/View.java: -------------------------------------------------------------------------------- 1 | package android.view; 2 | 3 | public class View { 4 | public static interface OnCreateContextMenuListener { 5 | void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/android/widget/ProgressBar.java: -------------------------------------------------------------------------------- 1 | package android.widget; 2 | 3 | import android.view.View; 4 | 5 | public class ProgressBar extends View { 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/com/google/android/collect/Lists.java: -------------------------------------------------------------------------------- 1 | package com.google.android.collect; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | 6 | public class Lists { 7 | public Lists() { 8 | } 9 | 10 | public static ArrayList newArrayList() { 11 | return new ArrayList(); 12 | } 13 | 14 | public static ArrayList newArrayList(E... elements) { 15 | int capacity = elements.length * 110 / 100 + 5; 16 | ArrayList list = new ArrayList(capacity); 17 | Collections.addAll(list, elements); 18 | return list; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/google/firebase/FirebasePlatform.kt: -------------------------------------------------------------------------------- 1 | package com.google.firebase 2 | 3 | import java.io.File 4 | 5 | abstract class FirebasePlatform { 6 | 7 | companion object { 8 | 9 | internal lateinit var firebasePlatform: FirebasePlatform 10 | 11 | fun initializeFirebasePlatform(platform: FirebasePlatform) { 12 | firebasePlatform = platform 13 | // prevent coroutines from thinking its on android 14 | System.setProperty("kotlinx.coroutines.fast.service.loader", "false") 15 | } 16 | } 17 | 18 | abstract fun store(key: String, value: String) 19 | 20 | abstract fun retrieve(key: String): String? 21 | 22 | abstract fun clear(key: String) 23 | 24 | abstract fun log(msg: String) 25 | 26 | open fun getDatabasePath(name: String): File = File("${System.getProperty("java.io.tmpdir")}${File.separatorChar}$name") 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/google/firebase/annotations/concurrent/Background.java: -------------------------------------------------------------------------------- 1 | package com.google.firebase.annotations.concurrent; 2 | 3 | public @interface Background { 4 | } 5 | -------------------------------------------------------------------------------- /src/main/java/com/google/firebase/annotations/concurrent/Blocking.java: -------------------------------------------------------------------------------- 1 | package com.google.firebase.annotations.concurrent; 2 | 3 | public @interface Blocking { 4 | } 5 | -------------------------------------------------------------------------------- /src/main/java/com/google/firebase/annotations/concurrent/Lightweight.java: -------------------------------------------------------------------------------- 1 | package com.google.firebase.annotations.concurrent; 2 | 3 | public @interface Lightweight { 4 | } 5 | -------------------------------------------------------------------------------- /src/main/java/com/google/firebase/annotations/concurrent/UiThread.java: -------------------------------------------------------------------------------- 1 | package com.google.firebase.annotations.concurrent; 2 | 3 | public @interface UiThread { 4 | } 5 | -------------------------------------------------------------------------------- /src/main/java/com/google/firebase/auth/ActionCodeEmailInfo.java: -------------------------------------------------------------------------------- 1 | package com.google.firebase.auth; 2 | 3 | public interface ActionCodeEmailInfo extends ActionCodeInfo { 4 | String getPreviousEmail(); 5 | 6 | } -------------------------------------------------------------------------------- /src/main/java/com/google/firebase/auth/ActionCodeInfo.java: -------------------------------------------------------------------------------- 1 | package com.google.firebase.auth; 2 | 3 | import androidx.annotation.NonNull; 4 | 5 | public interface ActionCodeInfo { 6 | @NonNull 7 | String getEmail(); 8 | } -------------------------------------------------------------------------------- /src/main/java/com/google/firebase/auth/ActionCodeMultiFactorInfo.java: -------------------------------------------------------------------------------- 1 | package com.google.firebase.auth; 2 | 3 | public interface ActionCodeMultiFactorInfo extends ActionCodeInfo { 4 | MultiFactorInfo getMultiFactorInfo(); 5 | } -------------------------------------------------------------------------------- /src/main/java/com/google/firebase/auth/ActionCodeResult.java: -------------------------------------------------------------------------------- 1 | package com.google.firebase.auth; 2 | 3 | public interface ActionCodeResult { 4 | int PASSWORD_RESET = 0; 5 | int VERIFY_EMAIL = 1; 6 | int RECOVER_EMAIL = 2; 7 | int ERROR = 3; 8 | int SIGN_IN_WITH_EMAIL_LINK = 4; 9 | int VERIFY_BEFORE_CHANGE_EMAIL = 5; 10 | int REVERT_SECOND_FACTOR_ADDITION = 6; 11 | int EMAIL = 0; 12 | int FROM_EMAIL = 1; 13 | 14 | int getOperation(); 15 | 16 | ActionCodeInfo getInfo(); 17 | } -------------------------------------------------------------------------------- /src/main/java/com/google/firebase/auth/AuthCredential.java: -------------------------------------------------------------------------------- 1 | package com.google.firebase.auth; 2 | 3 | import kotlin.NotImplementedError; 4 | 5 | public class AuthCredential { 6 | public String getProvider() { 7 | throw new NotImplementedError(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/google/firebase/auth/AuthResult.java: -------------------------------------------------------------------------------- 1 | package com.google.firebase.auth; 2 | 3 | public interface AuthResult { 4 | FirebaseUser getUser(); 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/com/google/firebase/auth/EmailAuthProvider.java: -------------------------------------------------------------------------------- 1 | package com.google.firebase.auth; 2 | 3 | import kotlin.NotImplementedError; 4 | 5 | public class EmailAuthProvider { 6 | public static AuthCredential getCredential(String email, String password) { 7 | throw new NotImplementedError(); 8 | } 9 | public static AuthCredential getCredentialWithLink(String email, String emailLink) { 10 | throw new NotImplementedError(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/google/firebase/auth/FacebookAuthProvider.java: -------------------------------------------------------------------------------- 1 | package com.google.firebase.auth; 2 | 3 | import kotlin.NotImplementedError; 4 | 5 | public class FacebookAuthProvider { 6 | public static AuthCredential getCredential(String accessToken) { 7 | throw new NotImplementedError(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/google/firebase/auth/FirebaseAuthActionCodeException.kt: -------------------------------------------------------------------------------- 1 | package com.google.firebase.auth 2 | 3 | class FirebaseAuthActionCodeException(errorCode: String, detailMessage: String) : FirebaseAuthException(errorCode, detailMessage) 4 | -------------------------------------------------------------------------------- /src/main/java/com/google/firebase/auth/FirebaseAuthEmailException.kt: -------------------------------------------------------------------------------- 1 | package com.google.firebase.auth 2 | 3 | class FirebaseAuthEmailException(errorCode: String, detailMessage: String) : FirebaseAuthException(errorCode, detailMessage) 4 | -------------------------------------------------------------------------------- /src/main/java/com/google/firebase/auth/FirebaseAuthInvalidCredentialsException.kt: -------------------------------------------------------------------------------- 1 | package com.google.firebase.auth 2 | 3 | open class FirebaseAuthInvalidCredentialsException(errorCode: String, detailMessage: String) : FirebaseAuthException(errorCode, detailMessage) 4 | -------------------------------------------------------------------------------- /src/main/java/com/google/firebase/auth/FirebaseAuthInvalidUserException.kt: -------------------------------------------------------------------------------- 1 | package com.google.firebase.auth 2 | 3 | class FirebaseAuthInvalidUserException(errorCode: String, detailMessage: String) : FirebaseAuthException(errorCode, detailMessage) 4 | -------------------------------------------------------------------------------- /src/main/java/com/google/firebase/auth/FirebaseAuthRecentLoginRequiredException.kt: -------------------------------------------------------------------------------- 1 | package com.google.firebase.auth 2 | 3 | class FirebaseAuthRecentLoginRequiredException(errorCode: String, detailMessage: String) : FirebaseAuthException(errorCode, detailMessage) 4 | -------------------------------------------------------------------------------- /src/main/java/com/google/firebase/auth/FirebaseAuthRegistrar.java: -------------------------------------------------------------------------------- 1 | package com.google.firebase.auth; 2 | 3 | import androidx.annotation.Keep; 4 | import com.google.firebase.FirebaseApp; 5 | import com.google.firebase.auth.internal.InternalAuthProvider; 6 | import com.google.firebase.components.*; 7 | 8 | import java.util.Arrays; 9 | import java.util.Collections; 10 | import java.util.List; 11 | 12 | @Keep 13 | public class FirebaseAuthRegistrar implements ComponentRegistrar { 14 | @Keep 15 | public List> getComponents() { 16 | return Arrays.asList(new Component[]{ 17 | Component.builder(FirebaseAuth.class, new Class[]{ InternalAuthProvider.class }) 18 | .add(Dependency.required(FirebaseApp.class)) 19 | .factory(componentContainer -> { 20 | FirebaseApp app = componentContainer.get(FirebaseApp.class); 21 | FirebaseAuth auth = new FirebaseAuth(app); 22 | return auth; 23 | }).alwaysEager().build() 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/google/firebase/auth/FirebaseAuthUserCollisionException.kt: -------------------------------------------------------------------------------- 1 | package com.google.firebase.auth 2 | 3 | class FirebaseAuthUserCollisionException(errorCode: String, detailMessage: String) : FirebaseAuthException(errorCode, detailMessage) 4 | -------------------------------------------------------------------------------- /src/main/java/com/google/firebase/auth/FirebaseAuthWeakPasswordException.kt: -------------------------------------------------------------------------------- 1 | package com.google.firebase.auth 2 | 3 | class FirebaseAuthWeakPasswordException(errorCode: String, detailMessage: String) : FirebaseAuthInvalidCredentialsException(errorCode, detailMessage) 4 | -------------------------------------------------------------------------------- /src/main/java/com/google/firebase/auth/FirebaseAuthWebException.kt: -------------------------------------------------------------------------------- 1 | package com.google.firebase.auth 2 | 3 | class FirebaseAuthWebException(errorCode: String, detailMessage: String) : FirebaseAuthException(errorCode, detailMessage) 4 | -------------------------------------------------------------------------------- /src/main/java/com/google/firebase/auth/FirebaseUser.kt: -------------------------------------------------------------------------------- 1 | package com.google.firebase.auth 2 | 3 | import com.google.android.gms.tasks.Task 4 | 5 | abstract class FirebaseUser { 6 | abstract val uid: String 7 | abstract val isAnonymous: Boolean 8 | abstract fun delete(): Task 9 | abstract fun reload(): Task 10 | 11 | val email: String get() = TODO() 12 | val displayName: String get() = TODO() 13 | val phoneNumber: String get() = TODO() 14 | val photoUrl: String? get() = TODO() 15 | val isEmailVerified: Boolean get() = TODO() 16 | val metadata: FirebaseUserMetadata get() = TODO() 17 | val multiFactor: MultiFactor get() = TODO() 18 | val providerData: List get() = TODO() 19 | val providerId: String get() = TODO() 20 | abstract fun getIdToken(forceRefresh: Boolean): Task 21 | fun linkWithCredential(credential: AuthCredential): Task = TODO() 22 | fun sendEmailVerification(): Task = TODO() 23 | fun sendEmailVerification(actionCodeSettings: ActionCodeSettings): Task = TODO() 24 | fun unlink(provider: String): Task = TODO() 25 | fun updateEmail(email: String): Task = TODO() 26 | fun updatePassword(password: String): Task = TODO() 27 | fun updatePhoneNumber(credential: AuthCredential): Task = TODO() 28 | fun updateProfile(request: UserProfileChangeRequest): Task = TODO() 29 | fun verifyBeforeUpdateEmail(newEmail: String, actionCodeSettings: ActionCodeSettings?): Task = TODO() 30 | fun reauthenticate(credential: AuthCredential): Task = TODO() 31 | fun reauthenticateAndRetrieveData(credential: AuthCredential): Task = TODO() 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/google/firebase/auth/GithubAuthProvider.java: -------------------------------------------------------------------------------- 1 | package com.google.firebase.auth; 2 | 3 | import kotlin.NotImplementedError; 4 | 5 | public class GithubAuthProvider { 6 | public static AuthCredential getCredential(String token) { 7 | throw new NotImplementedError(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/google/firebase/auth/GoogleAuthProvider.java: -------------------------------------------------------------------------------- 1 | package com.google.firebase.auth; 2 | 3 | import kotlin.NotImplementedError; 4 | 5 | public class GoogleAuthProvider { 6 | public static AuthCredential getCredential(String email, String password) { 7 | throw new NotImplementedError(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/google/firebase/auth/OAuthProvider.java: -------------------------------------------------------------------------------- 1 | package com.google.firebase.auth; 2 | 3 | import kotlin.NotImplementedError; 4 | 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | public class OAuthProvider { 9 | 10 | public OAuthProvider(Builder builder) { 11 | throw new NotImplementedError(); 12 | } 13 | 14 | public static AuthCredential getCredential(String email, String password) { 15 | throw new NotImplementedError(); 16 | } 17 | 18 | public static class Builder { 19 | public Builder setScopes(List scopes) { 20 | throw new NotImplementedError(); 21 | } 22 | public Builder addCustomParameters(Map customParameters) { 23 | throw new NotImplementedError(); 24 | } 25 | public OAuthProvider build() { 26 | throw new NotImplementedError(); 27 | } 28 | } 29 | 30 | public static class CredentialBuilder { 31 | public Builder setAccessToken(String accessToken) { 32 | throw new NotImplementedError(); 33 | } 34 | public Builder setIdToken(String idToken) { 35 | throw new NotImplementedError(); 36 | } 37 | public Builder setIdTokenWithRawNonce(String idToken, String rawNonce) { 38 | throw new NotImplementedError(); 39 | } 40 | public void build() { 41 | throw new NotImplementedError(); 42 | } 43 | } 44 | 45 | public static Builder newBuilder(String provider, FirebaseAuth auth) { 46 | throw new NotImplementedError(); 47 | } 48 | 49 | public static CredentialBuilder newCredentialBuilder(String provider) { 50 | throw new NotImplementedError(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/google/firebase/auth/PhoneAuthProvider.java: -------------------------------------------------------------------------------- 1 | package com.google.firebase.auth; 2 | 3 | import android.app.Activity; 4 | import com.google.firebase.FirebaseException; 5 | import kotlin.NotImplementedError; 6 | 7 | import java.util.concurrent.TimeUnit; 8 | 9 | public class PhoneAuthProvider { 10 | public static PhoneAuthCredential getCredential(String email, String password) { 11 | throw new NotImplementedError(); 12 | } 13 | public static PhoneAuthProvider getInstance(FirebaseAuth auth) { 14 | throw new NotImplementedError(); 15 | } 16 | 17 | public void verifyPhoneNumber(String phoneNumber, long timeout, TimeUnit unit, Activity activity, PhoneAuthProvider.OnVerificationStateChangedCallbacks callbacks) { 18 | throw new NotImplementedError(); 19 | } 20 | 21 | public void verifyPhoneNumber(String phoneNumber, long timeout, TimeUnit unit, Activity activity, PhoneAuthProvider.OnVerificationStateChangedCallbacks callbacks, ForceResendingToken forceResending) { 22 | throw new NotImplementedError(); 23 | } 24 | 25 | public static abstract class OnVerificationStateChangedCallbacks { 26 | public void onCodeAutoRetrievalTimeOut(String verificationId) { 27 | throw new NotImplementedError(); 28 | } 29 | public void onCodeSent(String verificationId, PhoneAuthProvider.ForceResendingToken forceResendingToken) { 30 | throw new NotImplementedError(); 31 | } 32 | public abstract void onVerificationCompleted(PhoneAuthCredential credential); 33 | public abstract void onVerificationFailed(FirebaseException exception); 34 | } 35 | 36 | public static class ForceResendingToken { 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/google/firebase/auth/Stubs.kt: -------------------------------------------------------------------------------- 1 | package com.google.firebase.auth 2 | 3 | import android.net.Uri 4 | import com.google.android.gms.tasks.Task 5 | 6 | class ActionCodeSettings { 7 | companion object { 8 | fun newBuilder(): Builder = TODO() 9 | } 10 | 11 | class Builder { 12 | fun setAndroidPackageName(packageName: String, installIfNotAvailable: Boolean, minimumVersion: String?): Builder = TODO() 13 | fun setDynamicLinkDomain(dynamicLinkDomain: String): Builder = TODO() 14 | fun setIOSBundleId(iOSBundleId: String): Builder = TODO() 15 | fun setUrl(url: String): Builder = TODO() 16 | fun setHandleCodeInApp(canHandleCodeInApp: Boolean): Builder = TODO() 17 | fun build(): ActionCodeSettings = TODO() 18 | } 19 | } 20 | 21 | class FirebaseAuthMultiFactorException(errorCode: String, detailMessage: String) : FirebaseAuthException(errorCode, detailMessage) 22 | 23 | class UserInfo { 24 | val displayName: String? get() = TODO() 25 | val email: String get() = TODO() 26 | val phoneNumber: String get() = TODO() 27 | val photoUrl: Uri? get() = TODO() 28 | val providerId: String get() = TODO() 29 | val uid: String get() = TODO() 30 | } 31 | 32 | class FirebaseUserMetadata { 33 | val creationTimestamp: Long get() = TODO() 34 | val lastSignInTimestamp: Long get() = TODO() 35 | } 36 | 37 | class MultiFactor { 38 | val uid: String get() = TODO() 39 | val enrolledFactors: List get() = TODO() 40 | val session: Task get() = TODO() 41 | fun enroll(multiFactorAssertion: MultiFactorAssertion, displayName: String?): Task = TODO() 42 | fun unenroll(multiFactorInfo: MultiFactorInfo): Task = TODO() 43 | fun unenroll(factorUid: String): Task = TODO() 44 | } 45 | class MultiFactorInfo { 46 | val displayName: String? get() = TODO() 47 | val enrollmentTimestamp: Long get() = TODO() 48 | val factorId: String get() = TODO() 49 | val uid: String get() = TODO() 50 | } 51 | class MultiFactorAssertion { 52 | val factorId: String get() = TODO() 53 | } 54 | class MultiFactorSession 55 | class MultiFactorResolver { 56 | val firebaseAuth: FirebaseAuth get() = TODO() 57 | val hints: List get() = TODO() 58 | val session: MultiFactorSession get() = TODO() 59 | fun resolveSignIn(assertion: MultiFactorAssertion): Task = TODO() 60 | } 61 | 62 | class PhoneAuthCredential : AuthCredential() 63 | class OAuthCredential : AuthCredential() 64 | 65 | interface SignInMethodQueryResult { 66 | val signInMethods: List 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/com/google/firebase/auth/TwitterAuthProvider.java: -------------------------------------------------------------------------------- 1 | package com.google.firebase.auth; 2 | 3 | import kotlin.NotImplementedError; 4 | 5 | public class TwitterAuthProvider { 6 | public static AuthCredential getCredential(String email, String password) { 7 | throw new NotImplementedError(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/google/firebase/auth/UserProfileChangeRequest.java: -------------------------------------------------------------------------------- 1 | package com.google.firebase.auth; 2 | 3 | import android.net.Uri; 4 | import kotlin.NotImplementedError; 5 | 6 | public class UserProfileChangeRequest { 7 | public static class Builder { 8 | public Builder setDisplayName(String name) { 9 | throw new NotImplementedError(); 10 | } 11 | public Builder setPhotoUri(Uri uri) { 12 | throw new NotImplementedError(); 13 | } 14 | public UserProfileChangeRequest build() { 15 | throw new NotImplementedError(); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /src/main/java/dalvik/system/PathClassLoader.java: -------------------------------------------------------------------------------- 1 | package dalvik.system; 2 | 3 | public class PathClassLoader extends ClassLoader { 4 | } 5 | -------------------------------------------------------------------------------- /src/main/java/dalvik/system/VMRuntime.java: -------------------------------------------------------------------------------- 1 | package dalvik.system; 2 | 3 | import com.android.internal.util.ArrayUtils; 4 | 5 | import java.util.Arrays; 6 | 7 | public class VMRuntime { 8 | public static VMRuntime getRuntime() { 9 | return new VMRuntime(); 10 | } 11 | 12 | public Object newUnpaddedArray(Class clazz, int minLen) { 13 | if(clazz == int.class) return new int[minLen]; 14 | return new Object[minLen]; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/libcore/util/EmptyArray.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 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 libcore.util; 18 | 19 | import android.annotation.SystemApi; 20 | 21 | import java.lang.annotation.Annotation; 22 | 23 | import static android.annotation.SystemApi.Client.MODULE_LIBRARIES; 24 | 25 | /** 26 | * Empty array is immutable. Use a shared empty array to avoid allocation. 27 | * 28 | * @hide 29 | */ 30 | @SystemApi(client = MODULE_LIBRARIES) 31 | public final class EmptyArray { 32 | private EmptyArray() {} 33 | 34 | /** @hide */ 35 | @SystemApi(client = MODULE_LIBRARIES) 36 | public static final @NonNull boolean[] BOOLEAN = new boolean[0]; 37 | 38 | /** @hide */ 39 | @SystemApi(client = MODULE_LIBRARIES) 40 | public static final @NonNull byte[] BYTE = new byte[0]; 41 | 42 | /** @hide */ 43 | public static final char[] CHAR = new char[0]; 44 | 45 | /** @hide */ 46 | public static final double[] DOUBLE = new double[0]; 47 | 48 | /** @hide */ 49 | @SystemApi(client = MODULE_LIBRARIES) 50 | public static final @NonNull float[] FLOAT = new float[0]; 51 | 52 | /** @hide */ 53 | @SystemApi(client = MODULE_LIBRARIES) 54 | public static final @NonNull int[] INT = new int[0]; 55 | 56 | /** @hide */ 57 | @SystemApi(client = MODULE_LIBRARIES) 58 | public static final @NonNull long[] LONG = new long[0]; 59 | 60 | /** @hide */ 61 | public static final Class[] CLASS = new Class[0]; 62 | 63 | /** @hide */ 64 | @SystemApi(client = MODULE_LIBRARIES) 65 | public static final @NonNull Object[] OBJECT = new Object[0]; 66 | 67 | /** @hide */ 68 | @SystemApi(client = MODULE_LIBRARIES) 69 | public static final @NonNull String[] STRING = new String[0]; 70 | 71 | /** @hide */ 72 | public static final Throwable[] THROWABLE = new Throwable[0]; 73 | 74 | /** @hide */ 75 | public static final StackTraceElement[] STACK_TRACE_ELEMENT = new StackTraceElement[0]; 76 | 77 | /** @hide */ 78 | public static final java.lang.reflect.Type[] TYPE = new java.lang.reflect.Type[0]; 79 | 80 | /** @hide */ 81 | public static final java.lang.reflect.TypeVariable[] TYPE_VARIABLE = 82 | new java.lang.reflect.TypeVariable[0]; 83 | /** @hide */ 84 | public static final Annotation[] ANNOTATION = new Annotation[0]; 85 | } -------------------------------------------------------------------------------- /src/main/java/org/json/JSON.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 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 org.json; 18 | 19 | class JSON { 20 | /** 21 | * Returns the input if it is a JSON-permissible value; throws otherwise. 22 | */ 23 | static double checkDouble(double d) throws JSONException { 24 | if (Double.isInfinite(d) || Double.isNaN(d)) { 25 | throw new JSONException("Forbidden numeric value: " + d); 26 | } 27 | return d; 28 | } 29 | 30 | static Boolean toBoolean(Object value) { 31 | if (value instanceof Boolean) { 32 | return (Boolean) value; 33 | } else if (value instanceof String) { 34 | String stringValue = (String) value; 35 | if ("true".equalsIgnoreCase(stringValue)) { 36 | return true; 37 | } else if ("false".equalsIgnoreCase(stringValue)) { 38 | return false; 39 | } 40 | } 41 | return null; 42 | } 43 | 44 | static Double toDouble(Object value) { 45 | if (value instanceof Double) { 46 | return (Double) value; 47 | } else if (value instanceof Number) { 48 | return ((Number) value).doubleValue(); 49 | } else if (value instanceof String) { 50 | try { 51 | return Double.valueOf((String) value); 52 | } catch (NumberFormatException ignored) { 53 | } 54 | } 55 | return null; 56 | } 57 | 58 | static Integer toInteger(Object value) { 59 | if (value instanceof Integer) { 60 | return (Integer) value; 61 | } else if (value instanceof Number) { 62 | return ((Number) value).intValue(); 63 | } else if (value instanceof String) { 64 | try { 65 | return (int) Double.parseDouble((String) value); 66 | } catch (NumberFormatException ignored) { 67 | } 68 | } 69 | return null; 70 | } 71 | 72 | static Long toLong(Object value) { 73 | if (value instanceof Long) { 74 | return (Long) value; 75 | } else if (value instanceof Number) { 76 | return ((Number) value).longValue(); 77 | } else if (value instanceof String) { 78 | try { 79 | return (long) Double.parseDouble((String) value); 80 | } catch (NumberFormatException ignored) { 81 | } 82 | } 83 | return null; 84 | } 85 | 86 | static String toString(Object value) { 87 | if (value instanceof String) { 88 | return (String) value; 89 | } else if (value != null) { 90 | return String.valueOf(value); 91 | } 92 | return null; 93 | } 94 | 95 | public static JSONException typeMismatch(Object indexOrName, Object actual, 96 | String requiredType) throws JSONException { 97 | if (actual == null) { 98 | throw new JSONException("Value at " + indexOrName + " is null."); 99 | } else { 100 | throw new JSONException("Value " + actual + " at " + indexOrName 101 | + " of type " + actual.getClass().getName() 102 | + " cannot be converted to " + requiredType); 103 | } 104 | } 105 | 106 | public static JSONException typeMismatch(Object actual, String requiredType) 107 | throws JSONException { 108 | if (actual == null) { 109 | throw new JSONException("Value is null."); 110 | } else { 111 | throw new JSONException("Value " + actual 112 | + " of type " + actual.getClass().getName() 113 | + " cannot be converted to " + requiredType); 114 | } 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /src/main/java/org/json/JSONException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 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 org.json; 18 | 19 | // Note: this class was written without inspecting the non-free org.json sourcecode. 20 | 21 | /** 22 | * Thrown to indicate a problem with the JSON API. Such problems include: 23 | *

    24 | *
  • Attempts to parse or construct malformed documents 25 | *
  • Use of null as a name 26 | *
  • Use of numeric types not available to JSON, such as {@link 27 | * Double#isNaN() NaNs} or {@link Double#isInfinite() infinities}. 28 | *
  • Lookups using an out of range index or nonexistent name 29 | *
  • Type mismatches on lookups 30 | *
31 | * 32 | *

Although this is a checked exception, it is rarely recoverable. Most 33 | * callers should simply wrap this exception in an unchecked exception and 34 | * rethrow: 35 | *

  public JSONArray toJSONObject() {
36 |  *     try {
37 |  *         JSONObject result = new JSONObject();
38 |  *         ...
39 |  *     } catch (JSONException e) {
40 |  *         throw new RuntimeException(e);
41 |  *     }
42 |  * }
43 | */ 44 | public class JSONException extends Exception { 45 | 46 | public JSONException(String s) { 47 | super(s); 48 | } 49 | 50 | public JSONException(String message, Throwable cause) { 51 | super(message, cause); 52 | } 53 | 54 | public JSONException(Throwable cause) { 55 | super(cause); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/test/kotlin/AppTest.kt: -------------------------------------------------------------------------------- 1 | import android.app.Application 2 | import com.google.firebase.Firebase 3 | import com.google.firebase.FirebaseOptions 4 | import com.google.firebase.FirebasePlatform 5 | import com.google.firebase.initialize 6 | import org.junit.Test 7 | 8 | class AppTest : FirebaseTest() { 9 | @Test 10 | fun testInitialize() { 11 | FirebasePlatform.initializeFirebasePlatform(object : FirebasePlatform() { 12 | val storage = mutableMapOf() 13 | override fun store(key: String, value: String) = storage.set(key, value) 14 | override fun retrieve(key: String) = storage[key] 15 | override fun clear(key: String) { storage.remove(key) } 16 | override fun log(msg: String) = println(msg) 17 | }) 18 | val options = FirebaseOptions.Builder() 19 | .setProjectId("my-firebase-project") 20 | .setApplicationId("1:27992087142:android:ce3b6448250083d1") 21 | .setApiKey("AIzaSyADUe90ULnQDuGShD9W23RDP0xmeDc6Mvw") 22 | // setDatabaseURL(...) 23 | // setStorageBucket(...) 24 | .build() 25 | val app = Firebase.initialize(Application(), options) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/test/kotlin/AuthTest.kt: -------------------------------------------------------------------------------- 1 | import com.google.firebase.auth.FirebaseAuth 2 | import com.google.firebase.auth.FirebaseAuthInvalidUserException 3 | import kotlinx.coroutines.runBlocking 4 | import kotlinx.coroutines.tasks.await 5 | import kotlinx.coroutines.test.runTest 6 | import org.junit.Assert.assertEquals 7 | import org.junit.Assert.assertThrows 8 | import org.junit.Test 9 | 10 | class AuthTest : FirebaseTest() { 11 | private fun createAuth(): FirebaseAuth { 12 | return FirebaseAuth(app).apply { 13 | useEmulator("localhost", 9099) 14 | } 15 | } 16 | 17 | @Test 18 | fun `should authenticate via anonymous auth`() = runTest { 19 | val auth = createAuth() 20 | 21 | auth.signInAnonymously().await() 22 | 23 | assertEquals(true, auth.currentUser?.isAnonymous) 24 | } 25 | 26 | @Test 27 | fun `should authenticate via email and password`() = runTest { 28 | val auth = createAuth() 29 | 30 | auth.signInWithEmailAndPassword("email@example.com", "securepassword").await() 31 | 32 | assertEquals(false, auth.currentUser?.isAnonymous) 33 | } 34 | 35 | @Test 36 | fun `should throw exception on invalid password`() { 37 | val auth = createAuth() 38 | 39 | val exception = assertThrows(FirebaseAuthInvalidUserException::class.java) { 40 | runBlocking { 41 | auth.signInWithEmailAndPassword("email@example.com", "wrongpassword").await() 42 | } 43 | } 44 | 45 | assertEquals("INVALID_PASSWORD", exception.errorCode) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/kotlin/FirebaseTest.kt: -------------------------------------------------------------------------------- 1 | import android.app.Application 2 | import com.google.firebase.Firebase 3 | import com.google.firebase.FirebaseApp 4 | import com.google.firebase.FirebaseOptions 5 | import com.google.firebase.FirebasePlatform 6 | import com.google.firebase.initialize 7 | import org.junit.Before 8 | import java.io.File 9 | 10 | abstract class FirebaseTest { 11 | protected val app: FirebaseApp get() { 12 | val options = FirebaseOptions.Builder() 13 | .setProjectId("my-firebase-project") 14 | .setApplicationId("1:27992087142:android:ce3b6448250083d1") 15 | .setApiKey("AIzaSyADUe90ULnQDuGShD9W23RDP0xmeDc6Mvw") 16 | .build() 17 | 18 | return Firebase.initialize(Application(), options) 19 | } 20 | 21 | @Before 22 | fun beforeEach() { 23 | FirebasePlatform.initializeFirebasePlatform(object : FirebasePlatform() { 24 | val storage = mutableMapOf() 25 | override fun store(key: String, value: String) = storage.set(key, value) 26 | override fun retrieve(key: String) = storage[key] 27 | override fun clear(key: String) { storage.remove(key) } 28 | override fun log(msg: String) = println(msg) 29 | override fun getDatabasePath(name: String) = File("./build/$name") 30 | }) 31 | FirebaseApp.clearInstancesForTest() 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/kotlin/FirestoreTest.kt: -------------------------------------------------------------------------------- 1 | import com.google.firebase.Firebase 2 | import com.google.firebase.firestore.firestore 3 | import kotlinx.coroutines.tasks.await 4 | import kotlinx.coroutines.test.runTest 5 | import org.junit.Assert.assertEquals 6 | import org.junit.Test 7 | 8 | class FirestoreTest : FirebaseTest() { 9 | 10 | @Test 11 | fun testFirestore(): Unit = runTest { 12 | val firestore = Firebase.firestore(app) 13 | firestore.disableNetwork().await() 14 | 15 | val data = Data("jim") 16 | val doc = firestore.document("sally/jim") 17 | doc.set(data) 18 | assertEquals(data, doc.get().await().toObject(Data::class.java)) 19 | } 20 | 21 | data class Data(val name: String = "none") 22 | } 23 | -------------------------------------------------------------------------------- /src/test/resources/firebase_data/auth_export/accounts.json: -------------------------------------------------------------------------------- 1 | { 2 | "kind": "identitytoolkit#DownloadAccountResponse", 3 | "users": [ 4 | { 5 | "localId": "Ijat10t0F1gvH1VrClkkSqEcId1p", 6 | "lastLoginAt": "1728509249920", 7 | "displayName": "", 8 | "photoUrl": "", 9 | "emailVerified": true, 10 | "email": "email@example.com", 11 | "salt": "fakeSaltHsRxYqy9iKVQRLwz8975", 12 | "passwordHash": "fakeHash:salt=fakeSaltHsRxYqy9iKVQRLwz8975:password=securepassword", 13 | "passwordUpdatedAt": 1728509249921, 14 | "validSince": "1728509249", 15 | "mfaInfo": [], 16 | "createdAt": "1728509249920", 17 | "providerUserInfo": [ 18 | { 19 | "providerId": "password", 20 | "email": "email@example.com", 21 | "federatedId": "email@example.com", 22 | "rawId": "email@example.com", 23 | "displayName": "", 24 | "photoUrl": "" 25 | } 26 | ] 27 | } 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /src/test/resources/firebase_data/auth_export/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "signIn": { 3 | "allowDuplicateEmails": false 4 | }, 5 | "emailPrivacyConfig": { 6 | "enableImprovedEmailPrivacy": false 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/test/resources/firebase_data/firebase-export-metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "13.3.1", 3 | "auth": { 4 | "version": "13.3.1", 5 | "path": "auth_export" 6 | } 7 | } --------------------------------------------------------------------------------