Merge pull request #1281 from kiwix/feature/macgills/#1258-leakcanary-ci

#1258 upgrade leakcanary to 2.0 and fix strict mode issues
This commit is contained in:
macgills 2019-07-15 11:17:18 +01:00 committed by GitHub
commit 5641a54176
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 28 additions and 21 deletions

View File

@ -63,10 +63,11 @@ after_success:
- ./gradlew kiwixtestUploadKiwix
after_failure:
- export LOG_DIR = ${TRAVIS_HOME}/build/kiwix/kiwix-android/app/build/outputs/reports/androidTests/connected/flavors/KIWIX/
- lynx --dump ${LOG_DIR}com.android.builder.testing.ConnectedDevice.html
- lynx --dump ${LOG_DIR}com.android.builder.testing.html
- lynx --dump ${LOG_DIR}org.kiwix.kiwixmobile.tests.BasicTest.html;
- export REPORT_DIR=${TRAVIS_HOME}/build/kiwix/kiwix-android/app/build/outputs/reports/
- export LOG_DIR=${REPORT_DIR}androidTests/connected/flavors/KIWIX/
- lynx -dump ${LOG_DIR}index.html
- lynx -dump ${REPORT_DIR}lint-results-kiwixDebug.html
before_deploy:
# - export APP_CHANGELOG=$(cat app/src/kiwix/play/release-notes/en-US/default.txt)

View File

@ -122,9 +122,8 @@ dependencies {
implementation "io.reactivex.rxjava2:rxjava:$rxJavaVersion"
// Leak canary
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.3'
androidTestImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.3'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.6.3'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.0-alpha-2'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
implementation "android.arch.lifecycle:extensions:1.1.1"

View File

@ -26,7 +26,6 @@ import android.util.Log;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.multidex.MultiDexApplication;
import com.jakewharton.threetenabp.AndroidThreeTen;
import com.squareup.leakcanary.LeakCanary;
import dagger.android.AndroidInjector;
import dagger.android.DispatchingAndroidInjector;
import dagger.android.HasActivityInjector;
@ -73,11 +72,6 @@ public class KiwixApplication extends MultiDexApplication implements HasActivity
@Override
public void onCreate() {
super.onCreate();
if (LeakCanary.isInAnalyzerProcess(this)) {
// This process is dedicated to LeakCanary for heap analysis.
// You should not init your app in this process.
return;
}
AndroidThreeTen.init(this);
if (isExternalStorageWritable()) {
File appDirectory = new File(Environment.getExternalStorageDirectory() + "/Kiwix");
@ -110,7 +104,6 @@ public class KiwixApplication extends MultiDexApplication implements HasActivity
Log.d("KIWIX", "Started KiwixApplication");
applicationComponent.inject(this);
LeakCanary.install(this);
if (BuildConfig.DEBUG) {
StrictMode.setThreadPolicy(buildThreadPolicy(new StrictMode.ThreadPolicy.Builder()));
StrictMode.setVmPolicy(buildVmPolicy(new StrictMode.VmPolicy.Builder()));

View File

@ -36,7 +36,7 @@ import org.kiwix.kiwixmobile.data.remote.UserAgentInterceptor;
@Provides @Singleton OkHttpClient provideOkHttpClient() {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(BuildConfig.DEBUG ? Level.BODY : Level.BASIC);
logging.setLevel(BuildConfig.DEBUG ? Level.BASIC : Level.NONE);
return new OkHttpClient().newBuilder().followRedirects(true).followSslRedirects(true)
.connectTimeout(10, TimeUnit.SECONDS)

View File

@ -4,7 +4,9 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.os.Environment;
import android.preference.PreferenceManager;
import io.reactivex.Flowable;
import io.reactivex.processors.BehaviorProcessor;
import io.reactivex.processors.PublishProcessor;
import java.util.Calendar;
import javax.inject.Inject;
import javax.inject.Singleton;
@ -35,12 +37,11 @@ public class SharedPreferenceUtil {
private static final String PREF_SHOW_BOOKMARKS_CURRENT_BOOK = "show_bookmarks_current_book";
private static final String PREF_SHOW_HISTORY_CURRENT_BOOK = "show_history_current_book";
private SharedPreferences sharedPreferences;
public final BehaviorProcessor<String> prefStorages;
private final PublishProcessor<String> prefStorages = PublishProcessor.create();
@Inject
public SharedPreferenceUtil(Context context) {
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
prefStorages = BehaviorProcessor.createDefault(getPrefStorage());
}
public boolean getPrefWifiOnly() {
@ -130,6 +131,10 @@ public class SharedPreferenceUtil {
prefStorages.onNext(storage);
}
public Flowable<String> getPrefStorages(){
return prefStorages.startWith(getPrefStorage());
}
public void putPrefFullScreen(boolean fullScreen) {
sharedPreferences.edit().putBoolean(PREF_FULLSCREEN, fullScreen).apply();
}

View File

@ -26,6 +26,7 @@ import android.provider.MediaStore.MediaColumns
import eu.mhutti1.utils.storage.StorageDeviceUtils
import io.reactivex.Flowable
import io.reactivex.functions.BiFunction
import io.reactivex.schedulers.Schedulers
import org.kiwix.kiwixmobile.extensions.forEachRow
import org.kiwix.kiwixmobile.extensions.get
import java.io.File
@ -37,8 +38,8 @@ class FileSearch @Inject constructor(private val context: Context) {
fun scan(defaultPath: String) =
Flowable.combineLatest(
Flowable.fromCallable { scanFileSystem(defaultPath) },
Flowable.fromCallable(this::scanMediaStore),
Flowable.fromCallable { scanFileSystem(defaultPath) }.subscribeOn(Schedulers.io()),
Flowable.fromCallable(this::scanMediaStore).subscribeOn(Schedulers.io()),
BiFunction<List<File>, List<File>, List<File>> { filesSystemFiles, mediaStoreFiles ->
filesSystemFiles + mediaStoreFiles
}

View File

@ -14,11 +14,11 @@ import javax.inject.Inject
class StorageObserver @Inject constructor(
private val sharedPreferenceUtil: SharedPreferenceUtil,
downloadDao: NewDownloadDao,
private val downloadDao: NewDownloadDao,
private val fileSearch: FileSearch
) {
val booksOnFileSystem = scanFiles()
val booksOnFileSystem get() = scanFiles()
.withLatestFrom(
downloadDao.downloads(),
BiFunction(this::toFilesThatAreNotDownloading)

View File

@ -29,11 +29,14 @@ import io.mockk.clearMocks
import io.mockk.every
import io.mockk.mockk
import io.mockk.mockkStatic
import io.reactivex.schedulers.Schedulers
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import org.kiwix.kiwixmobile.resetSchedulers
import org.kiwix.kiwixmobile.setScheduler
import java.io.File
class FileSearchTest {
@ -47,6 +50,10 @@ class FileSearchTest {
private val unitTestTempDirectoryPath = "unittest${File.separator}"
init {
setScheduler(Schedulers.trampoline())
}
@BeforeEach
fun init() {
clearMocks(context, externalStorageDirectory, contentResolver, storageDevice)
@ -66,6 +73,7 @@ class FileSearchTest {
@AfterAll
fun teardown() {
deleteTempDirectory()
resetSchedulers()
}
@Nested