mirror of
https://github.com/nextcloud/notes-android.git
synced 2024-11-22 04:46:04 +03:00
only synch if cert4android service is available.
This commit is contained in:
parent
4d2dfc6d77
commit
b3c2cc2f0e
3 changed files with 42 additions and 3 deletions
|
@ -1,10 +1,14 @@
|
|||
package it.niedermann.owncloud.notes.persistence;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
|
||||
import java.text.ParseException;
|
||||
|
@ -16,9 +20,10 @@ import java.util.List;
|
|||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import at.bitfire.cert4android.CustomCertService;
|
||||
import it.niedermann.owncloud.notes.model.CloudNote;
|
||||
import it.niedermann.owncloud.notes.model.DBNote;
|
||||
import it.niedermann.owncloud.notes.model.DBStatus;
|
||||
import it.niedermann.owncloud.notes.model.CloudNote;
|
||||
import it.niedermann.owncloud.notes.util.ICallback;
|
||||
import it.niedermann.owncloud.notes.util.NoteUtil;
|
||||
|
||||
|
@ -56,6 +61,7 @@ public class NoteSQLiteOpenHelper extends SQLiteOpenHelper {
|
|||
this.context = context.getApplicationContext();
|
||||
serverSyncHelper = NoteServerSyncHelper.getInstance(this);
|
||||
//recreateDatabase(getWritableDatabase());
|
||||
context.bindService(new Intent(context, CustomCertService.class), certService, Context.BIND_AUTO_CREATE);
|
||||
}
|
||||
|
||||
public static NoteSQLiteOpenHelper getInstance(Context context) {
|
||||
|
@ -69,6 +75,26 @@ public class NoteSQLiteOpenHelper extends SQLiteOpenHelper {
|
|||
return serverSyncHelper;
|
||||
}
|
||||
|
||||
private final ServiceConnection certService = new ServiceConnection() {
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
|
||||
getNoteServerSyncHelper().setCert4androidReady(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName componentName) {
|
||||
getNoteServerSyncHelper().setCert4androidReady(false);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
super.finalize();
|
||||
if (context != null && certService != null) {
|
||||
context.unbindService(certService);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates initial the Database
|
||||
*
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
package it.niedermann.owncloud.notes.persistence;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.ServiceConnection;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.IBinder;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
@ -22,6 +25,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import at.bitfire.cert4android.CustomCertManager;
|
||||
import it.niedermann.owncloud.notes.R;
|
||||
import it.niedermann.owncloud.notes.android.activity.SettingsActivity;
|
||||
import it.niedermann.owncloud.notes.model.CloudNote;
|
||||
|
@ -75,6 +79,16 @@ public class NoteServerSyncHelper {
|
|||
}
|
||||
};
|
||||
|
||||
private boolean cert4androidReady = false;
|
||||
|
||||
public boolean isCert4androidReady() {
|
||||
return cert4androidReady;
|
||||
}
|
||||
|
||||
public void setCert4androidReady(boolean cert4androidReady) {
|
||||
this.cert4androidReady = cert4androidReady;
|
||||
}
|
||||
|
||||
// current state of the synchronization
|
||||
private boolean syncActive = false;
|
||||
private boolean syncScheduled = false;
|
||||
|
@ -110,7 +124,7 @@ public class NoteServerSyncHelper {
|
|||
* @return true if sync is possible, otherwise false.
|
||||
*/
|
||||
public boolean isSyncPossible() {
|
||||
return networkConnected && isConfigured(appContext);
|
||||
return networkConnected && isConfigured(appContext) && isCert4androidReady();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ import java.net.URL;
|
|||
import java.security.KeyManagementException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManager;
|
||||
|
|
Loading…
Reference in a new issue