Search in sources :

Example 26 with SyncStatusInfo

use of android.content.SyncStatusInfo in project android_frameworks_base by ResurrectionRemix.

the class SyncStorageEngine method markPending.

public void markPending(EndPoint info, boolean pendingValue) {
    synchronized (mAuthorities) {
        AuthorityInfo authority = getOrCreateAuthorityLocked(info, -1, /* desired identifier */
        true);
        if (authority == null) {
            return;
        }
        SyncStatusInfo status = getOrCreateSyncStatusLocked(authority.ident);
        status.pending = pendingValue;
    }
    reportChange(ContentResolver.SYNC_OBSERVER_TYPE_PENDING);
}
Also used : SyncStatusInfo(android.content.SyncStatusInfo)

Example 27 with SyncStatusInfo

use of android.content.SyncStatusInfo in project android_frameworks_base by crdroidandroid.

the class SyncStorageEngine method markPending.

public void markPending(EndPoint info, boolean pendingValue) {
    synchronized (mAuthorities) {
        AuthorityInfo authority = getOrCreateAuthorityLocked(info, -1, /* desired identifier */
        true);
        if (authority == null) {
            return;
        }
        SyncStatusInfo status = getOrCreateSyncStatusLocked(authority.ident);
        status.pending = pendingValue;
    }
    reportChange(ContentResolver.SYNC_OBSERVER_TYPE_PENDING);
}
Also used : SyncStatusInfo(android.content.SyncStatusInfo)

Example 28 with SyncStatusInfo

use of android.content.SyncStatusInfo in project android_frameworks_base by crdroidandroid.

the class SyncStorageEngine method readAndDeleteLegacyAccountInfoLocked.

/**
     * Load sync engine state from the old syncmanager database, and then
     * erase it.  Note that we don't deal with pending operations, active
     * sync, or history.
     */
private void readAndDeleteLegacyAccountInfoLocked() {
    // Look for old database to initialize from.
    File file = mContext.getDatabasePath("syncmanager.db");
    if (!file.exists()) {
        return;
    }
    String path = file.getPath();
    SQLiteDatabase db = null;
    try {
        db = SQLiteDatabase.openDatabase(path, null, SQLiteDatabase.OPEN_READONLY);
    } catch (SQLiteException e) {
    }
    if (db != null) {
        final boolean hasType = db.getVersion() >= 11;
        // Copy in all of the status information, as well as accounts.
        if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
            Slog.v(TAG_FILE, "Reading legacy sync accounts db");
        }
        SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
        qb.setTables("stats, status");
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("_id", "status._id as _id");
        map.put("account", "stats.account as account");
        if (hasType) {
            map.put("account_type", "stats.account_type as account_type");
        }
        map.put("authority", "stats.authority as authority");
        map.put("totalElapsedTime", "totalElapsedTime");
        map.put("numSyncs", "numSyncs");
        map.put("numSourceLocal", "numSourceLocal");
        map.put("numSourcePoll", "numSourcePoll");
        map.put("numSourceServer", "numSourceServer");
        map.put("numSourceUser", "numSourceUser");
        map.put("lastSuccessSource", "lastSuccessSource");
        map.put("lastSuccessTime", "lastSuccessTime");
        map.put("lastFailureSource", "lastFailureSource");
        map.put("lastFailureTime", "lastFailureTime");
        map.put("lastFailureMesg", "lastFailureMesg");
        map.put("pending", "pending");
        qb.setProjectionMap(map);
        qb.appendWhere("stats._id = status.stats_id");
        Cursor c = qb.query(db, null, null, null, null, null, null);
        while (c.moveToNext()) {
            String accountName = c.getString(c.getColumnIndex("account"));
            String accountType = hasType ? c.getString(c.getColumnIndex("account_type")) : null;
            if (accountType == null) {
                accountType = "com.google";
            }
            String authorityName = c.getString(c.getColumnIndex("authority"));
            AuthorityInfo authority = this.getOrCreateAuthorityLocked(new EndPoint(new Account(accountName, accountType), authorityName, 0), -1, false);
            if (authority != null) {
                int i = mSyncStatus.size();
                boolean found = false;
                SyncStatusInfo st = null;
                while (i > 0) {
                    i--;
                    st = mSyncStatus.valueAt(i);
                    if (st.authorityId == authority.ident) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    st = new SyncStatusInfo(authority.ident);
                    mSyncStatus.put(authority.ident, st);
                }
                st.totalElapsedTime = getLongColumn(c, "totalElapsedTime");
                st.numSyncs = getIntColumn(c, "numSyncs");
                st.numSourceLocal = getIntColumn(c, "numSourceLocal");
                st.numSourcePoll = getIntColumn(c, "numSourcePoll");
                st.numSourceServer = getIntColumn(c, "numSourceServer");
                st.numSourceUser = getIntColumn(c, "numSourceUser");
                st.numSourcePeriodic = 0;
                st.lastSuccessSource = getIntColumn(c, "lastSuccessSource");
                st.lastSuccessTime = getLongColumn(c, "lastSuccessTime");
                st.lastFailureSource = getIntColumn(c, "lastFailureSource");
                st.lastFailureTime = getLongColumn(c, "lastFailureTime");
                st.lastFailureMesg = c.getString(c.getColumnIndex("lastFailureMesg"));
                st.pending = getIntColumn(c, "pending") != 0;
            }
        }
        c.close();
        // Retrieve the settings.
        qb = new SQLiteQueryBuilder();
        qb.setTables("settings");
        c = qb.query(db, null, null, null, null, null, null);
        while (c.moveToNext()) {
            String name = c.getString(c.getColumnIndex("name"));
            String value = c.getString(c.getColumnIndex("value"));
            if (name == null)
                continue;
            if (name.equals("listen_for_tickles")) {
                setMasterSyncAutomatically(value == null || Boolean.parseBoolean(value), 0);
            } else if (name.startsWith("sync_provider_")) {
                String provider = name.substring("sync_provider_".length(), name.length());
                int i = mAuthorities.size();
                while (i > 0) {
                    i--;
                    AuthorityInfo authority = mAuthorities.valueAt(i);
                    if (authority.target.provider.equals(provider)) {
                        authority.enabled = value == null || Boolean.parseBoolean(value);
                        authority.syncable = 1;
                    }
                }
            }
        }
        c.close();
        db.close();
        (new File(path)).delete();
    }
}
Also used : Account(android.accounts.Account) HashMap(java.util.HashMap) SyncStatusInfo(android.content.SyncStatusInfo) SQLiteException(android.database.sqlite.SQLiteException) Cursor(android.database.Cursor) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) File(java.io.File) SQLiteQueryBuilder(android.database.sqlite.SQLiteQueryBuilder)

Example 29 with SyncStatusInfo

use of android.content.SyncStatusInfo in project android_frameworks_base by crdroidandroid.

the class SyncStorageEngine method isSyncPending.

/** Return true if the pending status is true of any matching authorities. */
public boolean isSyncPending(EndPoint info) {
    synchronized (mAuthorities) {
        final int N = mSyncStatus.size();
        for (int i = 0; i < N; i++) {
            SyncStatusInfo cur = mSyncStatus.valueAt(i);
            AuthorityInfo ainfo = mAuthorities.get(cur.authorityId);
            if (ainfo == null) {
                continue;
            }
            if (!ainfo.target.matchesSpec(info)) {
                continue;
            }
            if (cur.pending) {
                return true;
            }
        }
        return false;
    }
}
Also used : SyncStatusInfo(android.content.SyncStatusInfo)

Example 30 with SyncStatusInfo

use of android.content.SyncStatusInfo in project android_frameworks_base by crdroidandroid.

the class SyncStorageEngine method stopSyncEvent.

public void stopSyncEvent(long historyId, long elapsedTime, String resultMessage, long downstreamActivity, long upstreamActivity) {
    synchronized (mAuthorities) {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Slog.v(TAG, "stopSyncEvent: historyId=" + historyId);
        }
        SyncHistoryItem item = null;
        int i = mSyncHistory.size();
        while (i > 0) {
            i--;
            item = mSyncHistory.get(i);
            if (item.historyId == historyId) {
                break;
            }
            item = null;
        }
        if (item == null) {
            Slog.w(TAG, "stopSyncEvent: no history for id " + historyId);
            return;
        }
        item.elapsedTime = elapsedTime;
        item.event = EVENT_STOP;
        item.mesg = resultMessage;
        item.downstreamActivity = downstreamActivity;
        item.upstreamActivity = upstreamActivity;
        SyncStatusInfo status = getOrCreateSyncStatusLocked(item.authorityId);
        status.numSyncs++;
        status.totalElapsedTime += elapsedTime;
        switch(item.source) {
            case SOURCE_LOCAL:
                status.numSourceLocal++;
                break;
            case SOURCE_POLL:
                status.numSourcePoll++;
                break;
            case SOURCE_USER:
                status.numSourceUser++;
                break;
            case SOURCE_SERVER:
                status.numSourceServer++;
                break;
            case SOURCE_PERIODIC:
                status.numSourcePeriodic++;
                break;
        }
        boolean writeStatisticsNow = false;
        int day = getCurrentDayLocked();
        if (mDayStats[0] == null) {
            mDayStats[0] = new DayStats(day);
        } else if (day != mDayStats[0].day) {
            System.arraycopy(mDayStats, 0, mDayStats, 1, mDayStats.length - 1);
            mDayStats[0] = new DayStats(day);
            writeStatisticsNow = true;
        } else if (mDayStats[0] == null) {
        }
        final DayStats ds = mDayStats[0];
        final long lastSyncTime = (item.eventTime + elapsedTime);
        boolean writeStatusNow = false;
        if (MESG_SUCCESS.equals(resultMessage)) {
            // - if successful, update the successful columns
            if (status.lastSuccessTime == 0 || status.lastFailureTime != 0) {
                writeStatusNow = true;
            }
            status.lastSuccessTime = lastSyncTime;
            status.lastSuccessSource = item.source;
            status.lastFailureTime = 0;
            status.lastFailureSource = -1;
            status.lastFailureMesg = null;
            status.initialFailureTime = 0;
            ds.successCount++;
            ds.successTime += elapsedTime;
        } else if (!MESG_CANCELED.equals(resultMessage)) {
            if (status.lastFailureTime == 0) {
                writeStatusNow = true;
            }
            status.lastFailureTime = lastSyncTime;
            status.lastFailureSource = item.source;
            status.lastFailureMesg = resultMessage;
            if (status.initialFailureTime == 0) {
                status.initialFailureTime = lastSyncTime;
            }
            ds.failureCount++;
            ds.failureTime += elapsedTime;
        }
        if (writeStatusNow) {
            writeStatusLocked();
        } else if (!hasMessages(MSG_WRITE_STATUS)) {
            sendMessageDelayed(obtainMessage(MSG_WRITE_STATUS), WRITE_STATUS_DELAY);
        }
        if (writeStatisticsNow) {
            writeStatisticsLocked();
        } else if (!hasMessages(MSG_WRITE_STATISTICS)) {
            sendMessageDelayed(obtainMessage(MSG_WRITE_STATISTICS), WRITE_STATISTICS_DELAY);
        }
    }
    reportChange(ContentResolver.SYNC_OBSERVER_TYPE_STATUS);
}
Also used : SyncStatusInfo(android.content.SyncStatusInfo)

Aggregations

SyncStatusInfo (android.content.SyncStatusInfo)58 Parcel (android.os.Parcel)12 Account (android.accounts.Account)8 SyncAdapterType (android.content.SyncAdapterType)7 AccountAndUser (android.accounts.AccountAndUser)6 PackageManager (android.content.pm.PackageManager)6 RegisteredServicesCache (android.content.pm.RegisteredServicesCache)6 UserInfo (android.content.pm.UserInfo)6 Cursor (android.database.Cursor)6 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)6 SQLiteException (android.database.sqlite.SQLiteException)6 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)6 File (java.io.File)6 FileOutputStream (java.io.FileOutputStream)6 HashMap (java.util.HashMap)6 AuthorityInfo (com.android.server.content.SyncStorageEngine.AuthorityInfo)5 EndPoint (com.android.server.content.SyncStorageEngine.EndPoint)5 SyncInfo (android.content.SyncInfo)2 Bundle (android.os.Bundle)2 Preference (android.support.v7.preference.Preference)2