mirror of
https://github.com/etesync/android
synced 2025-01-11 00:01:12 +00:00
lint: don't keep references to Context in static fields
This commit is contained in:
parent
1354afebf7
commit
d2d7ce8fe3
@ -42,7 +42,7 @@ public class CollectionInfoTest extends TestCase {
|
||||
"</response>" +
|
||||
"</multistatus>"));
|
||||
|
||||
DavResource dav = new DavResource(HttpClient.create(), server.url("/"));
|
||||
DavResource dav = new DavResource(HttpClient.create(null), server.url("/"));
|
||||
dav.propfind(0, ResourceType.NAME);
|
||||
CollectionInfo info = CollectionInfo.fromDavResource(dav);
|
||||
assertEquals(CollectionInfo.Type.ADDRESS_BOOK, info.type);
|
||||
@ -66,7 +66,7 @@ public class CollectionInfoTest extends TestCase {
|
||||
"</response>" +
|
||||
"</multistatus>"));
|
||||
|
||||
dav = new DavResource(HttpClient.create(), server.url("/"));
|
||||
dav = new DavResource(HttpClient.create(null), server.url("/"));
|
||||
dav.propfind(0, ResourceType.NAME);
|
||||
info = CollectionInfo.fromDavResource(dav);
|
||||
assertEquals(CollectionInfo.Type.CALENDAR, info.type);
|
||||
|
@ -54,9 +54,9 @@ public class DavResourceFinderTest extends InstrumentationTestCase {
|
||||
server.start();
|
||||
|
||||
credentials = new LoginCredentials(URI.create("/"), "mock", "12345");
|
||||
finder = new DavResourceFinder(getInstrumentation().getContext(), credentials);
|
||||
finder = new DavResourceFinder(getInstrumentation().getTargetContext(), credentials);
|
||||
|
||||
client = HttpClient.create();
|
||||
client = HttpClient.create(null);
|
||||
client = HttpClient.addAuthentication(client, credentials.userName, credentials.password);
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@ public class App extends Application {
|
||||
LOG_TO_EXTERNAL_STORAGE = "logToExternalStorage";
|
||||
|
||||
@Getter
|
||||
private static CustomCertManager certManager;
|
||||
private CustomCertManager certManager;
|
||||
|
||||
@Getter
|
||||
private static SSLSocketFactoryCompat sslSocketFactoryCompat;
|
||||
|
@ -42,8 +42,8 @@ public class HttpClient {
|
||||
private HttpClient() {
|
||||
}
|
||||
|
||||
public static OkHttpClient create(@NonNull Context context, @NonNull Account account, @NonNull final Logger logger) throws InvalidAccountException {
|
||||
OkHttpClient.Builder builder = defaultBuilder(logger);
|
||||
public static OkHttpClient create(@Nullable Context context, @NonNull Account account, @NonNull final Logger logger) throws InvalidAccountException {
|
||||
OkHttpClient.Builder builder = defaultBuilder(context, logger);
|
||||
|
||||
// use account settings for authentication
|
||||
AccountSettings settings = new AccountSettings(context, account);
|
||||
@ -52,27 +52,30 @@ public class HttpClient {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public static OkHttpClient create(@NonNull Logger logger) {
|
||||
return defaultBuilder(logger).build();
|
||||
public static OkHttpClient create(@NonNull Context context, @NonNull Logger logger) {
|
||||
return defaultBuilder(context, logger).build();
|
||||
}
|
||||
|
||||
public static OkHttpClient create(@NonNull Context context, @NonNull Account account) throws InvalidAccountException {
|
||||
return create(context, account, App.log);
|
||||
}
|
||||
|
||||
public static OkHttpClient create() {
|
||||
return create(App.log);
|
||||
public static OkHttpClient create(@Nullable Context context) {
|
||||
return create(context, App.log);
|
||||
}
|
||||
|
||||
|
||||
private static OkHttpClient.Builder defaultBuilder(@NonNull final Logger logger) {
|
||||
private static OkHttpClient.Builder defaultBuilder(@Nullable Context context, @NonNull final Logger logger) {
|
||||
OkHttpClient.Builder builder = client.newBuilder();
|
||||
|
||||
// use MemorizingTrustManager to manage self-signed certificates
|
||||
if (App.getSslSocketFactoryCompat() != null && App.getCertManager() != null)
|
||||
builder.sslSocketFactory(App.getSslSocketFactoryCompat(), App.getCertManager());
|
||||
if (App.getHostnameVerifier() != null)
|
||||
builder.hostnameVerifier(App.getHostnameVerifier());
|
||||
if (context != null) {
|
||||
App app = (App)context.getApplicationContext();
|
||||
if (App.getSslSocketFactoryCompat() != null && app.getCertManager() != null)
|
||||
builder.sslSocketFactory(App.getSslSocketFactoryCompat(), app.getCertManager());
|
||||
if (App.getHostnameVerifier() != null)
|
||||
builder.hostnameVerifier(App.getHostnameVerifier());
|
||||
}
|
||||
|
||||
// set timeouts
|
||||
builder.connectTimeout(30, TimeUnit.SECONDS);
|
||||
|
@ -484,7 +484,7 @@ public class ContactsSyncManager extends SyncManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
OkHttpClient resourceClient = HttpClient.create();
|
||||
OkHttpClient resourceClient = HttpClient.create(context);
|
||||
|
||||
// authenticate only against a certain host, and only upon request
|
||||
resourceClient = HttpClient.addAuthentication(resourceClient, baseUrl.host(), settings.username(), settings.password());
|
||||
|
@ -114,7 +114,7 @@ public class AccountActivity extends AppCompatActivity implements Toolbar.OnMenu
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
CustomCertManager certManager = App.getCertManager();
|
||||
CustomCertManager certManager = ((App)getApplicationContext()).getCertManager();
|
||||
if (certManager != null)
|
||||
certManager.appInForeground = false;
|
||||
}
|
||||
@ -122,7 +122,7 @@ public class AccountActivity extends AppCompatActivity implements Toolbar.OnMenu
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
CustomCertManager certManager = App.getCertManager();
|
||||
CustomCertManager certManager = ((App)getApplicationContext()).getCertManager();
|
||||
if (certManager != null)
|
||||
certManager.appInForeground = true;
|
||||
}
|
||||
|
@ -71,8 +71,6 @@ public class AppSettingsActivity extends AppCompatActivity {
|
||||
prefDistrustSystemCerts.setChecked(settings.getBoolean(App.DISTRUST_SYSTEM_CERTIFICATES, false));
|
||||
|
||||
prefResetCertificates = findPreference("reset_certificates");
|
||||
if (App.getCertManager() == null)
|
||||
prefResetCertificates.setVisible(false);
|
||||
|
||||
prefLogToExternalStorage = (SwitchPreferenceCompat)findPreference("log_to_external_storage");
|
||||
prefLogToExternalStorage.setChecked(settings.getBoolean(App.LOG_TO_EXTERNAL_STORAGE, false));
|
||||
@ -108,7 +106,7 @@ public class AppSettingsActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void resetCertificates() {
|
||||
App.getCertManager().resetCertificates();
|
||||
((App)getContext().getApplicationContext()).getCertManager().resetCertificates();
|
||||
Snackbar.make(getView(), getString(R.string.app_settings_reset_certificates_success), Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ public class DavResourceFinder {
|
||||
log.setLevel(Level.FINEST);
|
||||
log.addHandler(logBuffer);
|
||||
|
||||
httpClient = HttpClient.create(log);
|
||||
httpClient = HttpClient.create(context, log);
|
||||
httpClient = HttpClient.addAuthentication(httpClient, credentials.userName, credentials.password);
|
||||
}
|
||||
|
||||
|
@ -57,15 +57,19 @@ public class LoginActivity extends AppCompatActivity {
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (App.getCertManager() != null)
|
||||
App.getCertManager().appInForeground = true;
|
||||
|
||||
App app = (App)getApplicationContext();
|
||||
if (app.getCertManager() != null)
|
||||
app.getCertManager().appInForeground = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
if (App.getCertManager() != null)
|
||||
App.getCertManager().appInForeground = false;
|
||||
|
||||
App app = (App)getApplicationContext();
|
||||
if (app.getCertManager() != null)
|
||||
app.getCertManager().appInForeground = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -26,7 +26,7 @@ public class HttpClientTest extends TestCase {
|
||||
|
||||
@Override
|
||||
public void setUp() throws IOException {
|
||||
httpClient = HttpClient.create();
|
||||
httpClient = HttpClient.create(null);
|
||||
|
||||
server = new MockWebServer();
|
||||
server.start(30000);
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 0b0405a95dda7a0435e4b2562c90c0b7311e171f
|
||||
Subproject commit e70f7a4135b124af9fd696f6863c50ea4c91562f
|
@ -1 +1 @@
|
||||
Subproject commit c075d3803ae0b0b0b008f96e541cded183d1dd2b
|
||||
Subproject commit f6535874a9f1f399913dcb51bda1aa9affbb4c5a
|
@ -1 +1 @@
|
||||
Subproject commit 499901fc285c1bb3356feb7446a85db268d57a1d
|
||||
Subproject commit 8c4776a6be83b641611c12e1a0e524b6435bcf9a
|
Loading…
Reference in New Issue
Block a user