Skip to content

Commit

Permalink
Fix for android screenshots generation with okhttp (#3200)
Browse files Browse the repository at this point in the history
* Update screenshots test to newer AndroidJUnit4 class.

* Make okhttp client fallback to compatible tls.
Should fix #3198.
  • Loading branch information
VaiTon committed May 31, 2020
1 parent 7a44eb3 commit 84ee601
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,29 @@
import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import androidx.test.rule.GrantPermissionRule;
import android.util.Log;
import openfoodfacts.github.scrachx.openfood.fragments.PreferencesFragment;
import openfoodfacts.github.scrachx.openfood.test.ScreenshotActivityTestRule;
import openfoodfacts.github.scrachx.openfood.test.ScreenshotParameter;
import openfoodfacts.github.scrachx.openfood.test.ScreenshotsLocaleProvider;
import openfoodfacts.github.scrachx.openfood.utils.LocaleHelper;
import openfoodfacts.github.scrachx.openfood.views.OFFApplication;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.rule.GrantPermissionRule;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.util.Collection;
import java.util.Locale;

import openfoodfacts.github.scrachx.openfood.test.ScreenshotActivityTestRule;
import openfoodfacts.github.scrachx.openfood.test.ScreenshotParameter;
import openfoodfacts.github.scrachx.openfood.test.ScreenshotsLocaleProvider;
import openfoodfacts.github.scrachx.openfood.utils.LocaleHelper;
import openfoodfacts.github.scrachx.openfood.views.OFFApplication;

/**
* Take screenshots...
*/
@RunWith(JUnit4.class)
@RunWith(AndroidJUnit4.class)
public abstract class AbstractScreenshotTest {
public static final String ACTION_NAME = "actionName";
private static final String LOG_TAG = AbstractScreenshotTest.class.getSimpleName();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package openfoodfacts.github.scrachx.openfood;

import android.content.Intent;
import androidx.test.runner.AndroidJUnit4;

import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import openfoodfacts.github.scrachx.openfood.test.ScreenshotActivityTestRule;
import openfoodfacts.github.scrachx.openfood.utils.SearchInfo;
import openfoodfacts.github.scrachx.openfood.views.OFFApplication;
import openfoodfacts.github.scrachx.openfood.views.ProductBrowsingListActivity;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
* Take screenshots...
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package openfoodfacts.github.scrachx.openfood;

import androidx.test.runner.AndroidJUnit4;
import openfoodfacts.github.scrachx.openfood.test.ScreenshotActivityTestRule;
import openfoodfacts.github.scrachx.openfood.views.MainActivity;
import openfoodfacts.github.scrachx.openfood.views.WelcomeActivity;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import openfoodfacts.github.scrachx.openfood.test.ScreenshotActivityTestRule;
import openfoodfacts.github.scrachx.openfood.views.MainActivity;
import openfoodfacts.github.scrachx.openfood.views.WelcomeActivity;

/**
* Take screenshots...
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package openfoodfacts.github.scrachx.openfood;

import androidx.test.runner.AndroidJUnit4;
import openfoodfacts.github.scrachx.openfood.test.ScreenshotActivityTestRule;
import openfoodfacts.github.scrachx.openfood.views.ContinuousScanActivity;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import openfoodfacts.github.scrachx.openfood.test.ScreenshotActivityTestRule;
import openfoodfacts.github.scrachx.openfood.views.ContinuousScanActivity;

/**
* Take screenshots...
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
package openfoodfacts.github.scrachx.openfood;

import android.content.Intent;
import androidx.test.runner.AndroidJUnit4;

import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.ArrayList;
import java.util.List;

import openfoodfacts.github.scrachx.openfood.models.Product;
import openfoodfacts.github.scrachx.openfood.models.State;
import openfoodfacts.github.scrachx.openfood.test.ScreenshotActivityTestRule;
import openfoodfacts.github.scrachx.openfood.test.ScreenshotParameter;
import openfoodfacts.github.scrachx.openfood.views.HistoryScanActivity;
import openfoodfacts.github.scrachx.openfood.views.OFFApplication;
import openfoodfacts.github.scrachx.openfood.views.product.ProductActivity;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.ArrayList;
import java.util.List;

/**
* Take screenshots...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,13 @@
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.TimeUnit;

import okhttp3.CipherSuite;
import okhttp3.ConnectionSpec;
import okhttp3.OkHttpClient;
import okhttp3.TlsVersion;
import okhttp3.logging.HttpLoggingInterceptor;
import openfoodfacts.github.scrachx.openfood.BuildConfig;
import openfoodfacts.github.scrachx.openfood.R;
Expand Down Expand Up @@ -455,16 +453,8 @@ public static OkHttpClient httpClientBuilder() {
OkHttpClient.Builder builder = new OkHttpClient.Builder()
.connectTimeout(5000, TimeUnit.MILLISECONDS)
.readTimeout(30000, TimeUnit.MILLISECONDS)
.writeTimeout(30000, TimeUnit.MILLISECONDS);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
ConnectionSpec spec = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
.tlsVersions(TlsVersion.TLS_1_2)
.cipherSuites(CipherSuite.TLS_DHE_RSA_WITH_AES_128_GCM_SHA256)
.build();

builder.connectionSpecs(Collections.singletonList(spec));
}
.writeTimeout(30000, TimeUnit.MILLISECONDS)
.connectionSpecs(Arrays.asList(ConnectionSpec.MODERN_TLS, ConnectionSpec.COMPATIBLE_TLS));

if (BuildConfig.DEBUG) {
builder.addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY));
Expand All @@ -491,10 +481,7 @@ public static boolean isAirplaneModeActive(Context context) {
}
}

public static boolean isUserLoggedIn(Context context) {
if (context == null) {
return false;
}
public static boolean isUserLoggedIn(@NonNull Context context) {
final SharedPreferences settings = context.getSharedPreferences("login", 0);
final String login = settings.getString("user", "");
return StringUtils.isNotEmpty(login);
Expand Down

0 comments on commit 84ee601

Please sign in to comment.