2010-10-03 07:08:42 -04:00
|
|
|
package com.fsck.k9.helper;
|
|
|
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
|
|
|
|
import com.fsck.k9.K9;
|
|
|
|
|
|
|
|
import android.content.ContentResolver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.util.Log;
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public class AutoSyncSdk4 implements IAutoSync {
|
2010-10-03 07:08:42 -04:00
|
|
|
private Method mGetListenForNetworkTickles;
|
|
|
|
private Object mContentService;
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public void initialize(Context context) throws NoSuchMethodException {
|
2010-10-03 07:08:42 -04:00
|
|
|
/*
|
|
|
|
* There's no documented/official way to query the state of the
|
|
|
|
* auto-sync setting for a normal application in SDK 1.6/API 4.
|
2010-05-11 22:51:59 -04:00
|
|
|
*
|
2010-10-03 07:08:42 -04:00
|
|
|
* We use reflection to get an ContentService object, so we can call its
|
|
|
|
* getListenForNetworkTickles() method. This will return the current
|
|
|
|
* auto-sync state.
|
|
|
|
*/
|
2011-02-06 17:09:48 -05:00
|
|
|
try {
|
2010-10-03 07:08:42 -04:00
|
|
|
Method getContentService = ContentResolver.class.getMethod("getContentService");
|
|
|
|
mContentService = getContentService.invoke(null);
|
|
|
|
mGetListenForNetworkTickles = mContentService.getClass().getMethod("getListenForNetworkTickles");
|
2011-02-06 17:09:48 -05:00
|
|
|
} catch (Exception e) {
|
2010-10-03 07:08:42 -04:00
|
|
|
throw new NoSuchMethodException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public boolean getMasterSyncAutomatically() {
|
|
|
|
try {
|
2010-10-03 07:08:42 -04:00
|
|
|
return (Boolean) mGetListenForNetworkTickles.invoke(mContentService);
|
2011-02-06 17:09:48 -05:00
|
|
|
} catch (Exception e) {
|
2010-10-03 07:08:42 -04:00
|
|
|
Log.e(K9.LOG_TAG, "Could not query for network tickle", e);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|