private browserParts getbrowserParts(final Context context,final String account,final PendingInvalidation invalidation,final SyncResult syncResult,final Semaphore semaphore) {
return new EmptybrowserParts() {
@Override
public void finishNativeInitialization() {
// Startup succeeded,so we can notify the invalidation.
notifyInvalidation(invalidation.mObjectSource,invalidation.mObjectId,invalidation.mVersion,invalidation.mPayload);
semaphore.release();
}
@Override
public void onStartupFailure() {
// The startup Failed,so we defer the invalidation.
DelayedInvalidationsController.getInstance().addPendingInvalidation(
context,account,invalidation);
// Using numIoExceptions so Android will treat this as a soft error.
syncResult.stats.numIoExceptions++;
semaphore.release();
}
};
}
private void getUserData(final OUser user) {
progressDialog.setMessage(getString(R.string.msg_setting_your_account));
new AsyncTask<Void,Void,Void>() {
@Override
protected Void doInBackground(Void... voids) {
registerForFCM(user);
ProjectTeams teams = new ProjectTeams(LoginActivity.this);
SyncAdapter adapter = teams.getSyncAdapter();
SyncResult result = adapter.syncModelData();
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
progressDialog.dismiss();
startSplashScreen();
}
}.execute();
}
private void deleteFromLocal(OModel model,HashSet<Integer> checkIds,SyncResult syncResult) {
odomain domain = new odomain();
domain.add("id","in",new ArrayList<>(checkIds));
odooResult result = odoo.searchRead(model.getModelName(),new odooFields("id"),domain,null);
if (result == null) {
Log.e(TAG,"FATAL : Request aborted.");
return;
}
if (result.containsKey("error")) {
Log.e(TAG,result.get("error") + "");
return;
}
HashSet<Integer> serverIds = new HashSet<>();
for (odooRecord record : result.getRecords()) {
serverIds.add(record.getDouble("id").intValue());
}
checkIds.removeAll(serverIds);
int deleted = model.deleteall(new ArrayList<>(checkIds));
if (syncResult != null) syncResult.stats.numDeletes += deleted;
}
private void deleteFromServer(OModel model,SyncResult syncResult) {
LocalRecordState recordState = new LocalRecordState(mContext);
List<Integer> ids = recordState.getServerIds(model.getModelName());
if (!ids.isEmpty()) {
odooResult result = odoo.unlinkRecord(model.getModelName(),ids);
if (result == null) {
Log.e(TAG,"FATAL : Request aborted.");
return;
}
if (result.containsKey("error")) {
Log.e(TAG,result.get("error") + "");
return;
}
if (result.getBoolean("result")) {
syncResult.stats.numSkippedEntries += ids.size();
recordState.delete("server_id in (" + TextUtils.join(",",ids) + ") and model = ?",model.getModelName());
}
}
}
@Override
public void run(final Context context,final Callback callback) {
ConferenceDataHandler.resetDataTimestamp(context);
final Bundle bundle = new Bundle();
bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL,true);
new AsyncTask<Context,Void>() {
@Override
protected Void doInBackground(Context... contexts) {
Account account = AccountUtils.getActiveAccount(context);
if (account == null) {
callback.done(false,"Cannot sync if there is no active account.");
} else {
new SyncHelper(contexts[0]).performSync(new SyncResult(),AccountUtils.getActiveAccount(context),bundle);
}
return null;
}
}.execute(context);
}
项目:TVGuide
文件:TvGuideSyncAdapter.java
@Override
public void onPerformSync(Account account,Bundle extras,String authority,ContentProviderClient provider,SyncResult syncResult) {
if ( Utility.isNotDuplicateSync(getContext())) {
if (BuildConfig.DEBUG) Log.d(LOG_TAG,"Start sync!");
sendSyncStatus(START_SYNC);
final TvService service = Tvapiclient.getClient().create(TvService.class);
syncCategories(service,provider,syncResult);
syncChannels(service,syncResult);
syncPrograms(service,syncResult);
notifyTvGuide(syncResult.stats.numInserts,syncResult.stats.numIoExceptions);
prefhelper.setLastSyncTime(getContext().getString(R.string.pref_last_sync_time_key),System.currentTimeMillis());
prefhelper.setFirstRun(getContext().getString(R.string.pref_fist_run_key),false);
sendSyncStatus(END_SYNC);
if (BuildConfig.DEBUG) Log.d(LOG_TAG,"End sync!");
}
}
项目:EasyAppleSyncAdapter
文件:BaseSyncAdapter.java
@Override
public void onPerformSync(Account account,SyncResult syncResult) {
// required for dav4android (ServiceLoader)
Thread.currentThread().setContextClassLoader(getContext().getClassLoader());
try {
syncLocalAndRemoteCollections(account,provider);
syncCalendarsEvents(account,extras);
// notify any registered caller that sync operation is finished
getContext().getContentResolver().notifyChange(GlobalConstant.CONTENT_URI,null,false);
} catch (InvalidAccountException | CalendarStorageException e) {
e.printstacktrace();
}
}
项目:simplest-sync-adapter
文件:SyncAdapter.java
/**
* Called by the Android system in response to a request to run the sync adapter. The work
* required to read data from the network,parse it,and store it in the content provider
* should be done here. Extending AbstractThreadedSyncAdapter ensures that all methods within SyncAdapter
* run on a background thread. For this reason,blocking I/O and other long-running tasks can be
* run <em>in situ</em>,and you don't have to set up a separate thread for them.
*
* <p>
* <p>This is where we actually perform any work required to perform a sync.
* {@link AbstractThreadedSyncAdapter} guarantees that this will be called on a non-UI thread,* so it is safe to perform blocking I/O here.
* <p>
*
* <p>The syncResult argument allows you to pass @R_726_4045@ion back to the method that triggered
* the sync.
*/
@Override
public void onPerformSync(Account account,SyncResult syncResult) {
// Your code to sync data
// between mobile database and
// the server goes here.
for (int i = 0; i < 15; i++) {
try {
Thread.sleep(1000);
Log.i(TAG,">>>> sleeping the thread: " + (i + 1));
} catch (InterruptedException e) {
e.printstacktrace();
}
} // end for
// write DB data sanity checks at the end.
}
@Override
public void run(final Context context,bundle);
}
return null;
}
}.execute(context);
}
private void deleteFromLocal(OModel model,result.get("error") + "");
return;
}
HashSet<Integer> serverIds = new HashSet<>();
for (odooRecord record : result.getRecords()) {
serverIds.add(record.getDouble("id").intValue());
}
checkIds.removeAll(serverIds);
int deleted = model.deleteall(new ArrayList<>(checkIds));
if (syncResult != null) syncResult.stats.numDeletes += deleted;
}
private void deleteFromServer(OModel model,model.getModelName());
}
}
}
项目:gito-github-client
文件:SyncAdapter.java
@Override
public void onPerformSync(Account account,SyncResult syncResult) {
String key = "onPerformSync";
final GithubRemoteDataSource githubRepository =
GithubRepository.Injection.provideRemoteDataSource(getContext());
githubRepository.getUserSync();
Cursor cursor = getContext().getContentResolver().query(RepositoryContract
.RepositoryEntry.CONTENT_URI_REPOSITORY_STARGAZERS,RepositoryContract.RepositoryEntry.REPOSITORY_COLUMNS_WITH_ADDITIONAL_INFO,null);
boolean forceSync = cursor == null || !cursor.movetoFirst();
if (cursor != null) {
cursor.close();
}
if (mSyncSettings.isSynced(key) && !forceSync) {
return;
} else {
mSyncSettings.synced(key);
}
List<Repository> repositories = githubRepository.getRepositoriesSync();
githubRepository.getRepositoriesWithAdditionalInfoSync(repositories);
githubRepository.getTrendingRepositoriesSync(githubRepository.getDefaultPeriodForTrending(),githubRepository.getDefaultLanguageForTrending(),false);
}
项目:TimesMunch
文件:SyncAdapter.java
@Override
public void onPerformSync(Account account,SyncResult syncResult) {
String data = "";
// try {
// URL url = new URL("http://api.nytimes.com/svc/news/v3/content/nyt/all/.json?limit=5&api-key=fd0457bbde566c4783e7643346b77859:5:74605174");
// HttpURLConnection connection = (HttpURLConnection) url.openConnection();
// connection.connect();
// InputStream inStream = connection.getInputStream();
// data = getInputData(inStream);
// } catch (Throwable e) {
// e.printstacktrace();
// }
//
//
// Gson gson = new Gson();
// NYTSearchResult result = gson.fromJson(data,NYTSearchResult.class);
// for (int i = 0; i < 5; i++) {
// String title = result.getResults().get(i).getTitle();
// Log.d(TAG,"THE TITLE OF THE " + (i + 1)
// + " ARTICLE IS: " + title);
// }
}
项目:OurVLE
文件:SyncAdapter.java
/**
* Perform a sync for this account. SyncAdapter-specific parameters may
* be specified in extras,which is guaranteed to not be null. Invocations
* of this method are guaranteed to be serialized.
*
* @param account the account that should be synced
* @param extras SyncAdapter-specific parameters
* @param authority the authority of this sync request
* @param provider a ContentProviderClient that points to the ContentProvider for this
* authority
* @param syncResult SyncAdapter-specific parameters
*/
@Override
public void onPerformSync(Account account,SyncResult syncResult) {
sharedPrefs = super.getContext().getSharedPreferences(MoodleConstants.PREFS_STRING,Context.MODE_PRIVATE);
first_update = sharedPrefs.getInt(MoodleConstants.FirsT_UPDATE,404); // flag to check whether this is the first update
mSites = new Select().all().from(SiteInfo.class).execute();
if(mSites==null)
return;
if(mSites.size()<=0)
return;
token = mSites.get(0).getToken(); // gets the url token
courses = new Select().all().from(Course.class).execute(); // gets all the courses
updateLatestEvents();
updateLatestForumPosts();
updateLatestdiscussionPots();
// updateLatestCourseContent();
updateMembers();
}
@Override
public void onPerformSync(Account account,SyncResult syncResult) {
Lesson[] oldLessons = TiMetableContentHelper.getTiMetable(getContext());
Lesson[] lessons = new SyncServerInterface(getContext()).getTiMetable();
lessons = ClassesUtils.filterLessons(getContext(),lessons);
if (lessons.length != oldLessons.length || !Utils.containsAll(lessons,oldLessons)) {
TiMetableNotification.notify(getContext());
}
TiMetableContentHelper.clearTiMetable(getContext());
if (lessons.length > 0) {
TiMetableContentHelper.addLessons(getContext(),lessons);
}
}
项目:android-wg-planer
文件:RepresentationsSyncAdapter.java
@Override
public void onPerformSync(Account account,SyncResult syncResult) {
Representation[] oldRepresentations = RepresentationsContentHelper.getRepresentations(getContext());
Representation[] representations = new SyncServerInterface(getContext()).getRepresentations();
representations = ClassesUtils.filterRepresentations(getContext(),representations);
if (representations.length != oldRepresentations.length || !Utils.containsAll(representations,oldRepresentations)) {
RepresentationsNotification.notify(getContext());
}
RepresentationsContentHelper.clearRepresentations(getContext());
if (representations.length > 0) {
RepresentationsContentHelper.addRepresentations(getContext(),representations);
}
}
项目:android-wg-planer
文件:UserSyncAdapter.java
@Override
public void onPerformSync(Account account,SyncResult syncResult) {
try {
String username = mAccountManager.blockingGetAuthToken(account,AccountGeneral.AUTHTOKEN_TYPE_FULL_ACCESS,true);
SyncServerInterface serverInterface = new SyncServerInterface(getContext());
User user = serverInterface.getUserInfo(username);
UserContentHelper.clearUsers(getContext());
if (user != null) {
UserContentHelper.addUser(getContext(),user);
}
} catch (OperationCanceledException | IOException | AuthenticatorException e) {
e.printstacktrace();
syncResult.stats.numParseExceptions++;
}
}
@Override
public void run(final Context context,bundle);
}
return null;
}
}.execute(context);
}
项目:Vafrinn
文件:ChromiumSyncAdapter.java
private browserStartupController.StartupCallback getStartupCallback(final Context context,final Semaphore semaphore) {
return new browserStartupController.StartupCallback() {
@Override
public void onSuccess(boolean alreadyStarted) {
// Startup succeeded,invalidation.mPayload);
semaphore.release();
}
@Override
public void onFailure() {
// The startup Failed,invalidation);
// Using numIoExceptions so Android will treat this as a soft error.
syncResult.stats.numIoExceptions++;
semaphore.release();
}
};
}
项目:BeAuthentic
文件:AuthenticSyncAdapter.java
@Override
public void onPerformSync(Account account,final SyncResult syncResult) {
final Account primaryAccount = Sessions.getPrimaryPhoneAccount(AccountManager.get(getContext()));
if (primaryAccount != null) {
retrieveMessageFromFirebase(primaryAccount,new ValueEventListenerAdapter() {
@Override
public void onDataChange(DataSnapshot snapshot) {
syncResult.stats.numUpdates++;
final Intent intent = new Intent(LoggedActivity.ACTION_REFRESH);
intent.putExtra(LoggedActivity.EXTRA_MESSAGE,TextUtils.isEmpty(snapshot.getValue().toString()) ? "" : snapshot.getValue().toString());
getContext().sendbroadcast(intent);
}
@Override
public void onCancelled(FirebaseError firebaseError) {
syncResult.stats.numIoExceptions++;
}
});
}
}
项目:FMTech
文件:bty.java
public bty(btl parambtl,Context paramContext,int paramInt,bup parambup,SyncResult paramSyncResult,ois paramois,long paramLong)
{
this.a = paramInt;
this.b = parambup;
this.c = paramSyncResult;
this.t = paramois;
this.v = ((AutoBackupEnvironment)mbb.a(paramContext,AutoBackupEnvironment.class));
this.u = paramLong;
this.s = System.currentTimeMillis();
if (System.currentTimeMillis() - parambtl.j > 900000L)
{
parambtl.i = ((ifj)mbb.a(parambtl.f,ifj.class)).f().d();
parambtl.j = System.currentTimeMillis();
}
this.d = parambtl.i;
this.j = btl.a(parambtl,paramContext);
this.f = ((iwb)mbb.a(paramContext,iwb.class)).a(paramInt);
int i1 = parambtl.a().size();
this.e = ((this.d - b()) / i1);
this.r = Math.min(104857600L,this.e);
this.l = this.r;
sqliteDatabase localsqliteDatabase = bqj.a(paramContext,paramInt).getReadableDatabase();
this.h = btl.a(localsqliteDatabase,1);
this.g = btl.a(localsqliteDatabase,10);
}
项目:FMTech
文件:auq.java
private final void a(int paramInt,boolean paramBoolean)
{
try
{
if (Log.isLoggable("PhotoSyncService",4)) {
new StringBuilder(66).append("----> Start highlights Metadata down sync for account: ").append(paramInt);
}
bsn localbsn = bsn.e;
bry.a(getContext(),paramInt,parambup,localbsn);
bgp.a(getContext(),dnn.b,System.currentTimeMillis());
return;
}
catch (Exception localException)
{
do
{
if (Log.isLoggable("PhotoSyncService",6)) {
Log.e("PhotoSyncService",65 + "----> doHighlightsMetadataDownSync error for account: " + paramInt);
}
} while (GooglePhotodownsyncService.a(localException));
SyncStats localSyncStats = paramSyncResult.stats;
localSyncStats.numIoExceptions = (1L + localSyncStats.numIoExceptions);
}
}
项目:FMTech
文件:auq.java
private final void a(List<Integer> paramList,SyncResult paramSyncResult)
{
hyi localhyi = (hyi)mbb.a(getContext(),hyi.class);
Iterator localIterator = paramList.iterator();
while (localIterator.hasNext())
{
int i = ((Integer)localIterator.next()).intValue();
if (localhyi.b(bwb.g,i))
{
try
{
a(i,paramSyncResult,false);
}
catch (Exception localException)
{
Log.e("PhotoSyncService",83 + "----> performUnconditionalHighlightsMetadataDownSync error for account: " + i,localException);
}
if (!GooglePhotodownsyncService.a(localException))
{
SyncStats localSyncStats = paramSyncResult.stats;
localSyncStats.numIoExceptions = (1L + localSyncStats.numIoExceptions);
}
}
}
}
@Override
public void run(final Context context,bundle);
}
return null;
}
}.execute(context);
}
项目:aelf-dailyreadings
文件:SyncAdapter.java
private void syncReading(LecturesController.WHAT what,AelfDate when,SyncResult syncResult) throws InterruptedException {
// Load from network,if not in cache and not outdated
if(!mController.isLecturesInCache(what,when,false)) {
try {
Log.i(TAG,what.urlName()+" for "+when.toIsoString()+" QUEUED");
pendingDownloads.add(mController.getLecturesFromNetwork(what,when));
} catch (IOException e) {
if (e.getCause() instanceof InterruptedException) {
throw (InterruptedException) e.getCause();
}
// Error already propagated to Sentry. Do not propagate twice !
Log.e(TAG,"I/O error while syncing");
syncResult.stats.numIoExceptions++;
}
} else {
Log.i(TAG,what.urlName()+" for "+when.toIsoString()+" SKIPPED");
}
}
项目:gma-android
文件:GmaSyncService.java
@Override
public void onHandleIntent(@NonNull final Intent intent) {
// short-circuit if we don't have a valid guid
final String guid = intent.getStringExtra(EXTRA_GUID);
if (guid == null) {
return;
}
// dispatch sync request
final int type = intent.getIntExtra(EXTRA_SYNCTYPE,SYNCTYPE_NONE);
final Bundle extras = intent.getExtras();
final SyncResult result = new SyncResult();
mSyncAdapter.dispatchSync(guid,type,extras,result);
// request a sync next time we are online if we had errors syncing
if (result.hasError()) {
final Account account = AccountUtils.getAccount(this,ACCOUNT_TYPE,guid);
if (account != null) {
ContentResolver.requestSync(account,SYNC_AUTHORITY,extras);
}
}
}
@Override
public void run(final Context context,final Callback callback) {
final Bundle bundle = new Bundle();
bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL,bundle);
}
return null;
}
}.execute(context);
}
@Override
public void run(final Context context,bundle);
}
return null;
}
}.execute(context);
}
@Override
public void run(final Context context,bundle);
}
return null;
}
}.execute(context);
}
项目:attendee-checkin
文件:SyncAdapter.java
@Override
public void onPerformSync(Account account,SyncResult syncResult) {
String authToken = extras.getString(EXTRA_AUTH_TOKEN);
if (TextUtils.isEmpty(authToken)) {
Log.d(TAG,"Not authorized. Cannot sync.");
return;
}
mapiclient.blockingConnect(5,TimeUnit.SECONDS);
try {
String cookie = getCookie(authToken);
syncCheckins(provider,cookie);
if (!extras.getBoolean(EXTRA_ONLY_CHECKINS,false)) {
syncEvents(provider,cookie);
}
} catch (IOException e) {
Log.e(TAG,"Error performing sync.",e);
}
}
项目:hr
文件:OSyncAdapter.java
@Override
public void onPerformSync(Account account,SyncResult syncResult) {
// Creating model Object
mModel = new OModel(mContext,odooAccountManager.getDetails(mContext,account.name))
.createInstance(mModelClass);
mUser = mModel.getUser();
if (odooAccountManager.isValidUserObj(mContext,mUser)) {
// Creating odoo instance
modoo = createodooInstance(mContext,mUser);
Log.i(TAG,"User : " + mModel.getUser().getAndroidName());
Log.i(TAG,"Model : " + mModel.getModelName());
Log.i(TAG,"Database : " + mModel.getDatabaseName());
Log.i(TAG,"odoo Version: " + mUser.getodooVersion().getServerSerie());
// Calling service callback
if (mService != null)
mService.performDataSync(this,mUser);
//Creating domain
odomain domain = (mDomain.containsKey(mModel.getModelName())) ?
mDomain.get(mModel.getModelName()) : null;
// Ready for sync data from server
syncData(mModel,mUser,syncResult,true,true);
}
}
项目:Popeens-DSub
文件:SubsonicSyncAdapter.java
@Override
public void onPerformSync(Account account,SyncResult syncResult) {
String invalidMessage = isNetworkValid();
if(invalidMessage != null) {
Log.w(TAG,"Not running sync: " + invalidMessage);
return;
}
// Make sure battery > x% or is charging
IntentFilter intentFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
Intent batteryStatus = context.registerReceiver(null,intentFilter);
int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS,-1);
if (status != BatteryManager.BATTERY_STATUS_CHARGING && status != BatteryManager.BATTERY_STATUS_FULL) {
int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL,-1);
int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE,-1);
if ((level / (float) scale) < 0.15) {
Log.w(TAG,"Not running sync,battery too low");
return;
}
}
executeSync(context);
}
项目:MarketAndroid
文件:MasterListSyncAdapter.java
@Override
public void onPerformSync(
Account account,SyncResult syncResult) {
/* Ln.v("Refreshing Data Stream");
m_accountUtils.refreshAuthToken(new AccountUtils.TokenRefreshListener() {
@Override
public void onTokenRefreshed() {
Ln.v("Synchronizing with Server");
m_smartListService.synchronizeSmartLists();
}
});*/
}
@Override
public void run(final Context context,bundle);
}
return null;
}
}.execute(context);
}
项目:androidclient
文件:Syncer.java
private void commit(ContentProviderClient usersProvider,SyncResult syncResult) {
// commit users table
Uri uri = Users.CONTENT_URI.buildUpon()
.appendQueryParameter(Users.RESYNC,"true")
.appendQueryParameter(Users.COMMIT,"true")
.build();
try {
usersProvider.update(uri,null);
Log.d(TAG,"users database committed");
Contact.invalidate();
}
catch (Exception e) {
Log.e(TAG,"error committing users database - aborting sync",e);
syncResult.databaseError = true;
}
}
项目:NewsReaders
文件:SyncAdapter.java
@Override
public void onPerformSync(Account account,SyncResult syncResult) {
Log.i(TAG,"Beginning network synchronization");
Long datetime = PrefUtils.getLastSync(mContext);
try {
List<Entry> entryList = api.newsList(datetime);
for (int i = 0; i < entryList.size(); i++) {
insertEntry(entryList.get(i));
}
PrefUtils.setLastSync(mContext,new Date().getTime());
} catch (RetrofitError retrofitError) {
Log.e(TAG,"Error syncing",retrofitError);
}
EventBus.getDefault().post(new SyncEndedEvent());
Log.i(TAG,"Network synchronization complete");
}
@Override
public void onPerformSync(Account account,SyncResult syncResult) {
Log.d(TAG,"onPerformSync");
try {
TaskApi api = new GoogleTaskApi(getGoogleAuthToken());
TaskDb db = new TaskDb(mContext);
db.open();
try {
TaskSyncLocalDatastore localDatastore = new TaskSyncLocalDatastore(db);
TaskSyncRemoteDatastore remoteDatastore = new TaskSyncRemoteDatastore(api);
SyncManager<Task,Task> syncManager = new SyncManager<Task,Task>(localDatastore,remoteDatastore);
syncManager.sync();
} finally {
db.close();
}
getContext().getContentResolver().notifyChange(TaskSyncContentProvider.CONTENT_URI,null);
} catch (Exception e) {
Log.e(TAG,"syncFailed:" + e.getMessage());
}
}
项目:github-v2
文件:SyncAdapter.java
@Override
public void onPerformSync(final Account account,final Bundle extras,final String authority,final ContentProviderClient provider,final SyncResult syncResult) {
accountScope.enterWith(account,AccountManager.get(getContext()));
try {
contextScope.enter(getContext());
try {
cancelCampaign();
campaign = campaignFactory.create(syncResult);
campaign.run();
} finally {
contextScope.exit(getContext());
}
} finally {
accountScope.exit();
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。