diff --git a/.travis.yml b/.travis.yml index bed811fd8..4272ce452 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,40 +1,28 @@ -language: java -jdk: oraclejdk7 env: ANDROID_SDK=android-16 ANDROID_ABI=armeabi-v7a +language: android +android: + components: + # The SDK version used to compile your project + - $ANDROID_SDK -before_install: - # Install ia32-libs (necessary for Android SDK to run on 64-bit linux) - # - sudo apt-get clean && sudo apt-get update - - sudo apt-get update -qq - - sudo apt-get install -qq --force-yes libgd2-xpm ia32-libs ia32-libs-multiarch + # Additional components + - extra-google-m2repository + - extra-android-m2repository + - extra-android-support - # Install Android SDK - - wget http://dl.google.com/android/android-sdk_r22.6.2-linux.tgz - - tar -zxf android-sdk_r22.6.2-linux.tgz - - ls - - export ANDROID_HOME=`pwd`/android-sdk-linux - - export PATH=${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools + # Specify at least one system image, + # if you need to run emulator(s) during your tests + - sys-img-$ANDROID_ABI-$ANDROID_SDK - # Install build-tools - - wget https://dl-ssl.google.com/android/repository/build-tools_r19.0.3-linux.zip - - unzip build-tools_r19.0.3-linux.zip -d $ANDROID_HOME - - mkdir -p $ANDROID_HOME/build-tools/ - - mv $ANDROID_HOME/android-4.4.2 $ANDROID_HOME/build-tools/19.0.1 + licenses: + - 'android-sdk-license-.+' - # Install required Android components - - android list sdk --extended - # Do you accept the license 'android-sdk-license-bcbbd656' [y/n]: - - echo -ne "y\n" | android update sdk --filter system-image,platform-tools,extra-android-support,$ANDROID_SDK --no-ui --force - - # Create and start emulator +before_script: - echo no | android create avd --force -n test -t $ANDROID_SDK --abi $ANDROID_ABI - android list avds - emulator -avd test -no-skin -no-audio -no-window & + - android-wait-for-emulator + - adb shell input keyevent 82 & + - mvn --version -before_script: - # Make sure the emulator has started before running tests - - chmod +x ./wait_for_emulator - - ./wait_for_emulator - -script: - - mvn clean install -e +script: mvn clean install diff --git a/android-wait-for-emulator b/android-wait-for-emulator new file mode 100755 index 000000000..aa6345d8b --- /dev/null +++ b/android-wait-for-emulator @@ -0,0 +1,25 @@ +#!/bin/bash + +# Originally written by Ralf Kistner , but placed in the public domain + +set +e + +bootanim="" +failcounter=0 +timeout_in_sec=360 + +until [[ "$bootanim" =~ "stopped" ]]; do + bootanim=`adb -e shell getprop init.svc.bootanim 2>&1 &` + if [[ "$bootanim" =~ "device not found" || "$bootanim" =~ "device offline" + || "$bootanim" =~ "running" ]]; then + let "failcounter += 1" + echo "Waiting for emulator to start" + if [[ $failcounter -gt timeout_in_sec ]]; then + echo "Timeout ($timeout_in_sec seconds) reached; failed to start emulator" + exit 1 + fi + fi + sleep 1 +done + +echo "Emulator is ready" diff --git a/src/com/activeandroid/ActiveAndroid.java b/src/com/activeandroid/ActiveAndroid.java index c58c8efd8..60237c8f8 100644 --- a/src/com/activeandroid/ActiveAndroid.java +++ b/src/com/activeandroid/ActiveAndroid.java @@ -20,6 +20,7 @@ import android.database.sqlite.SQLiteDatabase; import com.activeandroid.util.Log; +import android.os.Build; public final class ActiveAndroid { ////////////////////////////////////////////////////////////////////////////////////// @@ -60,8 +61,16 @@ public static SQLiteDatabase getDatabase() { return Cache.openDatabase(); } + /** + * Non-exclusive transactions allows BEGIN IMMEDIATE + * blocks, allowing better read concurrency. + */ public static void beginTransaction() { - Cache.openDatabase().beginTransaction(); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { + Cache.openDatabase().beginTransaction(); + } else { + Cache.openDatabase().beginTransactionNonExclusive(); + } } public static void endTransaction() { diff --git a/src/com/activeandroid/DatabaseHelper.java b/src/com/activeandroid/DatabaseHelper.java index 7158c5bb6..c2b30e9c4 100644 --- a/src/com/activeandroid/DatabaseHelper.java +++ b/src/com/activeandroid/DatabaseHelper.java @@ -37,6 +37,7 @@ import com.activeandroid.util.NaturalOrderComparator; import com.activeandroid.util.SQLiteUtils; import com.activeandroid.util.SqlParser; +import android.os.Build; public final class DatabaseHelper extends SQLiteOpenHelper { ////////////////////////////////////////////////////////////////////////////////////// @@ -65,6 +66,25 @@ public DatabaseHelper(Configuration configuration) { // OVERRIDEN METHODS ////////////////////////////////////////////////////////////////////////////////////// + /** + * onConfigure is called when the db connection + * is being configured. It's the right place + * to enable write-ahead logging or foreign + * key support. + * + * Available for API level 16 (JellyBean) and above. + */ + @Override + public void onConfigure(SQLiteDatabase db) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + db.enableWriteAheadLogging(); + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + db.setForeignKeyConstraintsEnabled(true); + } + executePragmas(db); + } + @Override public void onOpen(SQLiteDatabase db) { executePragmas(db); diff --git a/wait_for_emulator b/wait_for_emulator deleted file mode 100644 index b30bc35c9..000000000 --- a/wait_for_emulator +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -bootanim="" -failcounter=0 -until [[ "$bootanim" =~ "stopped" ]]; do - bootanim=`adb -e shell getprop init.svc.bootanim 2>&1` - echo "$bootanim" - if [[ "$bootanim" =~ "not found" ]]; then - let "failcounter += 1" - if [[ $failcounter -gt 3 ]]; then - echo "Failed to start emulator" - exit 1 - fi - fi - sleep 1 -done - -echo "Done"