android.content.SyncResult Java Examples

The following examples show how to use android.content.SyncResult. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ContactsSyncAdapter.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onPerformSync(Account account, Bundle extras, String authority,
                          ContentProviderClient provider, SyncResult syncResult)
{
  Log.i(TAG, "onPerformSync(" + authority +")");

  if (!KeyCachingService.isLocked() && TextSecurePreferences.isPushRegistered(getContext())) {
    try {
      DirectoryHelper.refreshDirectory(getContext(), true);
    } catch (IOException e) {
      Log.w(TAG, e);
    }
  } else {
    Log.i(TAG, "Scheduling directory refresh job at next startup...");
    TextSecurePreferences.removeDirectoryRefreshTime(getContext());
  }
}
 
Example #2
Source File: ChromiumSyncAdapter.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void startBrowserProcess(
        final BrowserStartupController.StartupCallback callback,
        final SyncResult syncResult, Semaphore semaphore) {
    try {
        ThreadUtils.runOnUiThreadBlocking(new Runnable() {
            @Override
            public void run() {
                initCommandLine();
                if (mAsyncStartup) {
                    BrowserStartupController.get(mApplication)
                            .startBrowserProcessesAsync(callback);
                } else {
                    startBrowserProcessesSync(callback);
                }
            }
        });
    } catch (RuntimeException e) {
        // It is still unknown why we ever experience this. See http://crbug.com/180044.
        Log.w(TAG, "Got exception when trying to request a sync. Informing Android system.", e);
        // Using numIoExceptions so Android will treat this as a soft error.
        syncResult.stats.numIoExceptions++;
        semaphore.release();
    }
}
 
Example #3
Source File: ChromiumSyncAdapter.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void onPerformSync(Account account, Bundle extras, String authority,
                          ContentProviderClient provider, SyncResult syncResult) {
    if (!DelayedSyncController.getInstance().shouldPerformSync(getContext(), extras, account)) {
        return;
    }

    // Browser startup is asynchronous, so we will need to wait for startup to finish.
    Semaphore semaphore = new Semaphore(0);

    // Configure the callback with all the data it needs.
    BrowserStartupController.StartupCallback callback =
            getStartupCallback(mApplication, account, extras, syncResult, semaphore);
    startBrowserProcess(callback, syncResult, semaphore);

    try {
        // Wait for startup to complete.
        semaphore.acquire();
    } catch (InterruptedException e) {
        Log.w(TAG, "Got InterruptedException when trying to request a sync.", e);
        // Using numIoExceptions so Android will treat this as a soft error.
        syncResult.stats.numIoExceptions++;
    }
}
 
Example #4
Source File: NGWVectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected boolean proceedAttach(JSONObject result, SyncResult syncResult) throws JSONException {
    // get attach info
    if (!result.has("upload_meta")) {
        if (Constants.DEBUG_MODE) {
            Log.d(Constants.TAG, "Problem sendAttachOnServer(), result has not upload_meta, result: " + result.toString());
        }
        syncResult.stats.numParseExceptions++;
        return false;
    }

    JSONArray uploadMetaArray = result.getJSONArray("upload_meta");
    if (uploadMetaArray.length() == 0) {
        if (Constants.DEBUG_MODE) {
            Log.d(Constants.TAG, "Problem sendAttachOnServer(), result upload_meta length() == 0");
        }
        syncResult.stats.numParseExceptions++;
        return false;
    }

    return true;
}
 
Example #5
Source File: ChromeBrowserSyncAdapter.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
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();
        }
    };
}
 
Example #6
Source File: SyncAdapter.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void sync(
        LayerGroup layerGroup,
        String authority,
        SyncResult syncResult)
{
    for (int i = 0; i < layerGroup.getLayerCount(); i++) {
        if (isCanceled()) {
            return;
        }
        ILayer layer = layerGroup.getLayer(i);
        if (layer instanceof LayerGroup) {
            sync((LayerGroup) layer, authority, syncResult);
        } else if (layer instanceof INGWLayer) {
            INGWLayer ngwLayer = (INGWLayer) layer;
            String accountName = ngwLayer.getAccountName();
            if (!mVersions.containsKey(accountName))
                mVersions.put(accountName, NGWUtil.getNgwVersion(getContext(), accountName));

            Pair<Integer, Integer> ver = mVersions.get(accountName);
            ngwLayer.sync(authority, ver, syncResult);
        } else if (layer instanceof TrackLayer) {
            ((TrackLayer) layer).sync();
        }
    }
}
 
Example #7
Source File: SyncAdapter.java    From gito-github-client with Apache License 2.0 6 votes vote down vote up
@Override
public void onPerformSync(Account account, Bundle extras, String authority,
                          ContentProviderClient provider, 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, null, 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);
}
 
Example #8
Source File: ChromeBrowserSyncAdapter.java    From delion with Apache License 2.0 6 votes vote down vote up
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();
        }
    };
}
 
Example #9
Source File: TaskSyncAdapter.java    From SyncManagerAndroid-DemoGoogleTasks with MIT License 6 votes vote down vote up
@Override
public void onPerformSync(Account account, Bundle extras, String authority,
		ContentProviderClient provider, 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());
	}	
}
 
Example #10
Source File: SyncAdapter.java    From attendee-checkin with Apache License 2.0 6 votes vote down vote up
@Override
public void onPerformSync(Account account, Bundle extras, String authority,
                          ContentProviderClient provider, 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);
    }
}
 
Example #11
Source File: PredatorSyncAdapter.java    From Capstone-Project with MIT License 6 votes vote down vote up
@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {
    Logger.d(TAG, "onPerformSync: account: " + account.name);
    try {
        // Check if internet is available. If not then don't perform any sync.
        if (!NetworkConnectionUtil.isNetworkAvailable(getContext())) {
            return;
        }

        // Get the auth token for the current account.
        String authToken = mAccountManager.blockingGetAuthToken(account,
                PredatorSharedPreferences.getAuthTokenType(getContext().getApplicationContext()),
                true);

        // Fetch latest posts.
        mPostsPresenter.getPosts(authToken,
                mPostsPresenter.getSortType(getContext()),
                true);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #12
Source File: EarthsSyncAdapter.java    From earth with GNU General Public License v3.0 6 votes vote down vote up
@Override
@SuppressWarnings("ConstantConditions")
public void onPerformSync(Account account, Bundle extras, String authority,
                          ContentProviderClient provider, SyncResult result) {
    final boolean manual = extras.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL);
    final Map<String, Long> synced = syncer.sync(provider, manual);

    if (synced.containsKey(RESULT_ERROR)) {
        final long error = synced.get(RESULT_ERROR);
        if (error == ERROR_DB) {
            result.databaseError = true;
        } else if (error == ERROR_IO) {
            result.stats.numIoExceptions++;
        }
        return;
    }

    if (synced.containsKey(RESULT_INSERTS) && synced.containsKey(RESULT_DELETES)) {
        result.stats.numInserts = synced.get(RESULT_INSERTS);
        result.stats.numDeletes = synced.get(RESULT_DELETES);
    }

    if (synced.containsKey(RESULT_DELAY_UNTIL)) {
        result.delayUntil = synced.get(RESULT_DELAY_UNTIL);
    }
}
 
Example #13
Source File: ChromeBrowserSyncAdapter.java    From 365browser with Apache License 2.0 6 votes vote down vote up
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();
        }
    };
}
 
Example #14
Source File: ChromiumSyncAdapter.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void startBrowserProcess(
        final BrowserStartupController.StartupCallback callback,
        final SyncResult syncResult, Semaphore semaphore) {
    try {
        ThreadUtils.runOnUiThreadBlocking(new Runnable() {
            @Override
            public void run() {
                initCommandLine();
                if (mAsyncStartup) {
                    BrowserStartupController.get(mApplication)
                            .startBrowserProcessesAsync(callback);
                } else {
                    startBrowserProcessesSync(callback);
                }
            }
        });
    } catch (RuntimeException e) {
        // It is still unknown why we ever experience this. See http://crbug.com/180044.
        Log.w(TAG, "Got exception when trying to request a sync. Informing Android system.", e);
        // Using numIoExceptions so Android will treat this as a soft error.
        syncResult.stats.numIoExceptions++;
        semaphore.release();
    }
}
 
Example #15
Source File: OSyncAdapter.java    From hr with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void onPerformSync(Account account, Bundle extras, String authority,
                          ContentProviderClient provider, SyncResult syncResult) {
    // Creating model Object
    mModel = new OModel(mContext, null, 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, extras, mUser);

        //Creating domain
        ODomain domain = (mDomain.containsKey(mModel.getModelName())) ?
                mDomain.get(mModel.getModelName()) : null;

        // Ready for sync data from server
        syncData(mModel, mUser, domain, syncResult, true, true);
    }
}
 
Example #16
Source File: SyncAdapter.java    From v2ex with Apache License 2.0 6 votes vote down vote up
@Override
public void onPerformSync(final Account account, Bundle extras, String authority,
        final ContentProviderClient provider, final SyncResult syncResult) {
    final boolean uploadOnly = extras.getBoolean(ContentResolver.SYNC_EXTRAS_UPLOAD, false);
    final boolean manualSync = extras.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, false);
    final boolean initialize = extras.getBoolean(ContentResolver.SYNC_EXTRAS_INITIALIZE, false);
    final boolean remoteSync = extras.getBoolean(EXTRA_SYNC_REMOTE, false);

    final String logSanitizedAccountName = sSanitizeAccountNamePattern
            .matcher(account.name).replaceAll("$1...$2@");

    if (uploadOnly) {
        return;
    }

    LOGI(TAG, "Beginning sync for account " + logSanitizedAccountName + "," +
            " uploadOnly=" + uploadOnly +
            " manualSync=" + manualSync +
            " remoteSync =" + remoteSync +
            " initialize=" + initialize);
    // Sync from bootstrap and remote data, as needed
    new SyncHelper(mContext).performSync(syncResult, account, extras);
}
 
Example #17
Source File: SyncManager.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Convert the error-containing SyncResult into the Sync.History error number. Since
 * the SyncResult may indicate multiple errors at once, this method just returns the
 * most "serious" error.
 * @param syncResult the SyncResult from which to read
 * @return the most "serious" error set in the SyncResult
 * @throws IllegalStateException if the SyncResult does not indicate any errors.
 *   If SyncResult.error() is true then it is safe to call this.
 */
private int syncResultToErrorNumber(SyncResult syncResult) {
    if (syncResult.syncAlreadyInProgress)
        return ContentResolver.SYNC_ERROR_SYNC_ALREADY_IN_PROGRESS;
    if (syncResult.stats.numAuthExceptions > 0)
        return ContentResolver.SYNC_ERROR_AUTHENTICATION;
    if (syncResult.stats.numIoExceptions > 0)
        return ContentResolver.SYNC_ERROR_IO;
    if (syncResult.stats.numParseExceptions > 0)
        return ContentResolver.SYNC_ERROR_PARSE;
    if (syncResult.stats.numConflictDetectedExceptions > 0)
        return ContentResolver.SYNC_ERROR_CONFLICT;
    if (syncResult.tooManyDeletions)
        return ContentResolver.SYNC_ERROR_TOO_MANY_DELETIONS;
    if (syncResult.tooManyRetries)
        return ContentResolver.SYNC_ERROR_TOO_MANY_RETRIES;
    if (syncResult.databaseError)
        return ContentResolver.SYNC_ERROR_INTERNAL;
    throw new IllegalStateException("we are not in an error state, " + syncResult);
}
 
Example #18
Source File: CocoSyncAdapter.java    From COCOFramework with Apache License 2.0 6 votes vote down vote up
@Override
public void onPerformSync(Account account, Bundle extras, String authority,
                          ContentProviderClient provider, SyncResult syncResult) {

    // Building a print of the extras we got
    StringBuilder sb = new StringBuilder();
    if (extras != null) {
        for (String key : extras.keySet()) {
            sb.append(key + "[" + extras.get(key) + "] ");
        }
    }

    Log.d("> onPerformSync for account[" + account.name + "]. Extras: " + sb.toString());

    try {
        run(account, extras, authority,
                provider, syncResult);
    } catch (Throwable e) {
        e.printStackTrace();
    }
}
 
Example #19
Source File: SubsonicSyncAdapter.java    From Popeens-DSub with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, 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);
}
 
Example #20
Source File: ChromiumSyncAdapter.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void onPerformSync(Account account, Bundle extras, String authority,
                          ContentProviderClient provider, SyncResult syncResult) {
    if (!DelayedSyncController.getInstance().shouldPerformSync(getContext(), extras, account)) {
        return;
    }

    // Browser startup is asynchronous, so we will need to wait for startup to finish.
    Semaphore semaphore = new Semaphore(0);

    // Configure the callback with all the data it needs.
    BrowserStartupController.StartupCallback callback =
            getStartupCallback(mApplication, account, extras, syncResult, semaphore);
    startBrowserProcess(callback, syncResult, semaphore);

    try {
        // Wait for startup to complete.
        semaphore.acquire();
    } catch (InterruptedException e) {
        Log.w(TAG, "Got InterruptedException when trying to request a sync.", e);
        // Using numIoExceptions so Android will treat this as a soft error.
        syncResult.stats.numIoExceptions++;
    }
}
 
Example #21
Source File: SyncManager.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void sendSyncFinishedOrCanceledMessage(ActiveSyncContext syncContext,
        SyncResult syncResult) {
    if (Log.isLoggable(TAG, Log.VERBOSE)) Slog.v(TAG, "sending MESSAGE_SYNC_FINISHED");
    Message msg = mSyncHandler.obtainMessage();
    msg.what = SyncHandler.MESSAGE_SYNC_FINISHED;
    msg.obj = new SyncFinishedOrCancelledMessagePayload(syncContext, syncResult);
    mSyncHandler.sendMessage(msg);
}
 
Example #22
Source File: ChromiumSyncAdapter.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private BrowserStartupController.StartupCallback getStartupCallback(
        final Context context, final Account acct, Bundle extras,
        final SyncResult syncResult, final Semaphore semaphore) {
    final boolean syncAllTypes = extras.getString(INVALIDATION_OBJECT_ID_KEY) == null;
    final int objectSource = syncAllTypes ? 0 : extras.getInt(INVALIDATION_OBJECT_SOURCE_KEY);
    final String objectId = syncAllTypes ? "" : extras.getString(INVALIDATION_OBJECT_ID_KEY);
    final long version = syncAllTypes ? 0 : extras.getLong(INVALIDATION_VERSION_KEY);
    final String payload = syncAllTypes ? "" : extras.getString(INVALIDATION_PAYLOAD_KEY);

    return new BrowserStartupController.StartupCallback() {
        @Override
        public void onSuccess(boolean alreadyStarted) {
            // Startup succeeded, so we can tickle the sync engine.
            if (syncAllTypes) {
                Log.v(TAG, "Received sync tickle for all types.");
                requestSyncForAllTypes();
            } else {
                // Invalidations persisted before objectSource was added should be assumed to be
                // for Sync objects. TODO(stepco): Remove this check once all persisted
                // invalidations can be expected to have the objectSource.
                int resolvedSource = objectSource;
                if (resolvedSource == 0) {
                  resolvedSource = Types.ObjectSource.Type.CHROME_SYNC.getNumber();
                }
                Log.v(TAG, "Received sync tickle for " + resolvedSource + " " + objectId + ".");
                requestSync(resolvedSource, objectId, version, payload);
            }
            semaphore.release();
        }

        @Override
        public void onFailure() {
            // The startup failed, so we reset the delayed sync state.
            DelayedSyncController.getInstance().setDelayedSync(context, acct.name);
            // Using numIoExceptions so Android will treat this as a soft error.
            syncResult.stats.numIoExceptions++;
            semaphore.release();
        }
    };
}
 
Example #23
Source File: ContactSyncService.java    From android_packages_apps_GmsCore with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public IBinder onBind(Intent intent) {
    return (new AbstractThreadedSyncAdapter(this, true) {
        @Override
        public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {
            Log.d(TAG, "unimplemented Method: onPerformSync");
        }
    }).getSyncAdapterBinder();
}
 
Example #24
Source File: CalendarSyncAdapterService.java    From haxsync with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onPerformSync(Account account, Bundle extras,
		String authority, ContentProviderClient provider,
		SyncResult syncResult) {
	try {
		CalendarSyncAdapterService.performSync(mContext, account,
				extras, authority, provider, syncResult);
	} catch (OperationCanceledException e) {
	}
}
 
Example #25
Source File: ContactsSyncAdapterService.java    From haxsync with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onPerformSync(Account account, Bundle extras,
		String authority, ContentProviderClient provider,
		SyncResult syncResult) {
	try {
		ContactsSyncAdapterService.performSync(mContext, account,
				extras, authority, provider, syncResult);
	} catch (OperationCanceledException e) {
	}
}
 
Example #26
Source File: ContactsSyncAdapterService.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {
    try {
        ContactsSyncAdapterService.performSync(mContext, account, extras, authority, provider, syncResult);
    } catch (OperationCanceledException e) {
        FileLog.e(e);
    }
}
 
Example #27
Source File: SyncHelper.java    From v2ex with Apache License 2.0 5 votes vote down vote up
/**
 * Attempts to perform data synchronization.
 *
 * @param syncResult (optional) the sync result object to update with statistics.
 * @param account    the account associated with this sync
 * @return Whether or not the synchronization made any changes to the data.
 */
public boolean performSync(SyncResult syncResult, Account account, Bundle extras) {

    final boolean remoteSync = extras.getBoolean(SyncAdapter.EXTRA_SYNC_REMOTE, true);

    // remote sync consists of these operations, which we try one by one (and tolerate
    // individual failures on each)
    String[] apisToPerform = remoteSync ?
            new String[] { Api.API_TOPICS_LATEST, Api.API_TOPICS_HOT} :
            new String[] { extras.getString(Api.ARG_API_NAME)};


    for (String api : apisToPerform) {
        try {
            sync(api, extras);
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            EventBus.getDefault().postSticky(new ExceptionEvent(mContext.getString(R.string.err_io)));
            LOGE(TAG, "Error performing remote sync.");
            increaseIoExceptions(syncResult);
        }
    }

    int operations = mDataHandler.getContentProviderOperationsDone();
    if (syncResult != null && syncResult.stats != null) {
        syncResult.stats.numEntries += operations;
        syncResult.stats.numUpdates += operations;
    }

    LOGD(TAG, "SYNC STATS:\n" +
            " *  Account synced: " + (account == null ? "null" : account.name) + "\n" +
            " *  Content provider operations: " + operations);

    return true;
}
 
Example #28
Source File: OModel.java    From hr with GNU Affero General Public License v3.0 5 votes vote down vote up
public void quickSyncRecords(ODomain domain) {
    OSyncAdapter syncAdapter = new OSyncAdapter(mContext, getClass(), null, true);
    syncAdapter.setModel(this);
    syncAdapter.setDomain(domain);
    syncAdapter.checkForWriteCreateDate(false);
    syncAdapter.onPerformSync(getUser().getAccount(), null, authority(), null, new SyncResult());
}
 
Example #29
Source File: OModel.java    From hr with GNU Affero General Public License v3.0 5 votes vote down vote up
public ODataRow quickCreateRecord(ODataRow record) {
    OSyncAdapter syncAdapter = new OSyncAdapter(mContext, getClass(), null, true);
    syncAdapter.setModel(this);
    ODomain domain = new ODomain();
    domain.add("id", "=", record.getFloat("id").intValue());
    syncAdapter.setDomain(domain);
    syncAdapter.checkForWriteCreateDate(false);
    syncAdapter.onPerformSync(getUser().getAccount(), null, authority(), null, new SyncResult());
    return browse(null, "id = ?", new String[]{record.getString("id")});
}
 
Example #30
Source File: SyncAdapter.java    From linphone-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onPerformSync(
        Account account,
        Bundle extras,
        String authority,
        ContentProviderClient provider,
        SyncResult syncResult) {}