<commit_before>/*
 * Copyright 2012 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.funkyandroid.droidcon.uk.iosched.sync;

import android.app.IntentService;
import android.content.ContentResolver;
import android.content.Intent;
import android.content.SyncResult;
import android.os.Bundle;
import com.funkyandroid.droidcon.uk.iosched.Config;

import java.io.IOException;

import static com.funkyandroid.droidcon.uk.iosched.util.LogUtils.LOGE;
import static com.funkyandroid.droidcon.uk.iosched.util.LogUtils.LOGI;

/**
 * Service that handles sync. We're not requiring users to have any kind of account, so this needs to perform
 * the sync rather than just be a front end to a SyncAdapter.
 */
public class SyncService extends IntentService {

    private SyncHelper mSyncHelper;

    public SyncService() {
        super("SyncService");
    }

    @Override
    public void onHandleIntent(Intent intent) {
        Bundle extras = intent.getExtras();
        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);

        if (uploadOnly) {
            return;
        }

        LOGI(Config.LOG_TAG, "Beginning sync ," +
                " uploadOnly=" + uploadOnly +
                " manualSync=" + manualSync +
                " initialize=" + initialize);

        /*
            TODO: Look at non-G+ dependant way of doing this
        String chosenAccountName = AccountUtils.getChosenAccountName(mContext);
        boolean isAccountSet = !TextUtils.isEmpty(chosenAccountName);
        boolean isChosenAccount = isAccountSet && chosenAccountName.equals(account.name);
        if (isAccountSet) {
            ContentResolver.setIsSyncable(account, authority, isChosenAccount ? 1 : 0);
        }
        if (!isChosenAccount) {
            LOGW(TAG, "Tried to sync account " + logSanitizedAccountName + " but the chosen " +
                    "account is actually " + chosenAccountName);
            ++syncResult.stats.numAuthExceptions;
            return;
        }
        */

        // Perform a sync using SyncHelper
        if (mSyncHelper == null) {
            mSyncHelper = new SyncHelper(this);
        }

        // Dummy SyncResult object, we can use this for detecting issues
        // at some point.
        SyncResult syncResult = new SyncResult();
        try {
            mSyncHelper.performSync(syncResult,
                    SyncHelper.FLAG_SYNC_LOCAL | SyncHelper.FLAG_SYNC_REMOTE);

        } catch (IOException e) {
            ++syncResult.stats.numIoExceptions;
            LOGE(Config.LOG_TAG, "Error syncing data for I/O 2013.", e);
        }
    }
}<commit_msg>Removed dead code and made error more relevant<commit_after>/*
 * Copyright 2012 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.funkyandroid.droidcon.uk.iosched.sync;

import android.app.IntentService;
import android.content.ContentResolver;
import android.content.Intent;
import android.content.SyncResult;
import android.os.Bundle;
import com.funkyandroid.droidcon.uk.iosched.Config;

import java.io.IOException;

import static com.funkyandroid.droidcon.uk.iosched.util.LogUtils.LOGE;
import static com.funkyandroid.droidcon.uk.iosched.util.LogUtils.LOGI;

/**
 * Service that handles sync. We're not requiring users to have any kind of account, so this needs to perform
 * the sync rather than just be a front end to a SyncAdapter.
 */
public class SyncService extends IntentService {

    private SyncHelper mSyncHelper;

    public SyncService() {
        super("SyncService");
    }

    @Override
    public void onHandleIntent(Intent intent) {
        Bundle extras = intent.getExtras();
        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);

        if (uploadOnly) {
            return;
        }

        LOGI(Config.LOG_TAG, "Beginning sync ," +
                " uploadOnly=" + uploadOnly +
                " manualSync=" + manualSync +
                " initialize=" + initialize);

        // Perform a sync using SyncHelper
        if (mSyncHelper == null) {
            mSyncHelper = new SyncHelper(this);
        }

        // Dummy SyncResult object, we can use this for detecting issues
        // at some point.
        SyncResult syncResult = new SyncResult();
        try {
            mSyncHelper.performSync(syncResult,
                    SyncHelper.FLAG_SYNC_LOCAL | SyncHelper.FLAG_SYNC_REMOTE);

        } catch (IOException e) {
            ++syncResult.stats.numIoExceptions;
            LOGE(Config.LOG_TAG, "Error syncing data for Droidcon London 2013.", e);
        }
    }
}
{'fraction_non_alphanumeric': 0.08415841584158416, 'fraction_numerical': 0.0042904290429042905, 'mean_word_length': 2.8071608040201004, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4267294', 'n_tokens_mistral': 1686, 'n_tokens_neox': 1627, 'n_words': 503}