mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Use Android executor for background API calls Some Android API calls need to be made from a thread with a message queue, but to keep the UI responsive they shouldn't be made from the UI thread. This patch gives AndroidExecutor a captive thread with a message queue to execute tasks, and converts various background tasks from creating their own threads to using AndroidExecutor and IoExecutor. This allows us to upgrade the support library to 23.2.1. Fixes #332. See merge request !161
101 lines
2.6 KiB
Java
101 lines
2.6 KiB
Java
package org.briarproject.android;
|
|
|
|
import android.content.Intent;
|
|
import android.os.Bundle;
|
|
import android.os.Handler;
|
|
import android.os.StrictMode;
|
|
import android.os.StrictMode.ThreadPolicy;
|
|
import android.os.StrictMode.VmPolicy;
|
|
import android.support.v7.preference.PreferenceManager;
|
|
|
|
import org.briarproject.R;
|
|
import org.briarproject.android.api.AndroidExecutor;
|
|
import org.briarproject.android.util.AndroidUtils;
|
|
import org.briarproject.api.db.DatabaseConfig;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
import javax.inject.Inject;
|
|
|
|
import static org.briarproject.android.TestingConstants.DEFAULT_LOG_LEVEL;
|
|
import static org.briarproject.android.TestingConstants.TESTING;
|
|
|
|
public class SplashScreenActivity extends BaseActivity {
|
|
|
|
private static final Logger LOG =
|
|
Logger.getLogger(SplashScreenActivity.class.getName());
|
|
|
|
// This build expires on 1 June 2016
|
|
private static final long EXPIRY_DATE = 1464735600 * 1000L;
|
|
|
|
@Inject
|
|
protected DatabaseConfig dbConfig;
|
|
@Inject
|
|
protected AndroidExecutor androidExecutor;
|
|
|
|
public SplashScreenActivity() {
|
|
Logger.getLogger("").setLevel(DEFAULT_LOG_LEVEL);
|
|
enableStrictMode();
|
|
}
|
|
|
|
@Override
|
|
public void onCreate(Bundle state) {
|
|
super.onCreate(state);
|
|
|
|
setPreferencesDefaults();
|
|
|
|
setContentView(R.layout.splash);
|
|
|
|
new Handler().postDelayed(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
startNextActivity();
|
|
finish();
|
|
}
|
|
}, 500);
|
|
}
|
|
|
|
@Override
|
|
public void injectActivity(AndroidComponent component) {
|
|
component.inject(this);
|
|
}
|
|
|
|
protected void startNextActivity() {
|
|
if (System.currentTimeMillis() >= EXPIRY_DATE) {
|
|
LOG.info("Expired");
|
|
startActivity(new Intent(this, ExpiredActivity.class));
|
|
} else {
|
|
String hex = getEncryptedDatabaseKey();
|
|
if (hex != null && dbConfig.databaseExists()) {
|
|
startActivity(new Intent(this, NavDrawerActivity.class));
|
|
} else {
|
|
clearSharedPrefs();
|
|
AndroidUtils.deleteAppData(this);
|
|
startActivity(new Intent(this, SetupActivity.class));
|
|
}
|
|
}
|
|
}
|
|
|
|
private void enableStrictMode() {
|
|
if (TESTING) {
|
|
ThreadPolicy.Builder threadPolicy = new ThreadPolicy.Builder();
|
|
threadPolicy.detectAll();
|
|
threadPolicy.penaltyLog();
|
|
StrictMode.setThreadPolicy(threadPolicy.build());
|
|
VmPolicy.Builder vmPolicy = new VmPolicy.Builder();
|
|
vmPolicy.detectAll();
|
|
vmPolicy.penaltyLog();
|
|
StrictMode.setVmPolicy(vmPolicy.build());
|
|
}
|
|
}
|
|
|
|
private void setPreferencesDefaults() {
|
|
androidExecutor.execute(new Runnable() {
|
|
public void run() {
|
|
PreferenceManager.setDefaultValues(SplashScreenActivity.this,
|
|
R.xml.panic_preferences, false);
|
|
}
|
|
});
|
|
}
|
|
}
|