Search in sources :

Example 1 with SyncStatusInfo

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

the class SyncManager method dumpSyncState.

protected void dumpSyncState(PrintWriter pw) {
    pw.print("data connected: ");
    pw.println(mDataConnectionIsConnected);
    pw.print("auto sync: ");
    List<UserInfo> users = getAllUsers();
    if (users != null) {
        for (UserInfo user : users) {
            pw.print("u" + user.id + "=" + mSyncStorageEngine.getMasterSyncAutomatically(user.id) + " ");
        }
        pw.println();
    }
    pw.print("memory low: ");
    pw.println(mStorageIsLow);
    final AccountAndUser[] accounts = AccountManagerService.getSingleton().getAllAccounts();
    pw.print("accounts: ");
    if (accounts != INITIAL_ACCOUNTS_ARRAY) {
        pw.println(accounts.length);
    } else {
        pw.println("not known yet");
    }
    final long now = SystemClock.elapsedRealtime();
    pw.print("now: ");
    pw.print(now);
    pw.println(" (" + formatTime(System.currentTimeMillis()) + ")");
    pw.print("offset: ");
    pw.print(DateUtils.formatElapsedTime(mSyncRandomOffsetMillis / 1000));
    pw.println(" (HH:MM:SS)");
    pw.print("uptime: ");
    pw.print(DateUtils.formatElapsedTime(now / 1000));
    pw.println(" (HH:MM:SS)");
    pw.print("time spent syncing: ");
    pw.print(DateUtils.formatElapsedTime(mSyncHandler.mSyncTimeTracker.timeSpentSyncing() / 1000));
    pw.print(" (HH:MM:SS), sync ");
    pw.print(mSyncHandler.mSyncTimeTracker.mLastWasSyncing ? "" : "not ");
    pw.println("in progress");
    if (mSyncHandler.mAlarmScheduleTime != null) {
        pw.print("next alarm time: ");
        pw.print(mSyncHandler.mAlarmScheduleTime);
        pw.print(" (");
        pw.print(DateUtils.formatElapsedTime((mSyncHandler.mAlarmScheduleTime - now) / 1000));
        pw.println(" (HH:MM:SS) from now)");
    } else {
        pw.println("no alarm is scheduled (there had better not be any pending syncs)");
    }
    pw.print("notification info: ");
    final StringBuilder sb = new StringBuilder();
    mSyncHandler.mSyncNotificationInfo.toString(sb);
    pw.println(sb.toString());
    pw.println();
    pw.println("Active Syncs: " + mActiveSyncContexts.size());
    final PackageManager pm = mContext.getPackageManager();
    for (SyncManager.ActiveSyncContext activeSyncContext : mActiveSyncContexts) {
        final long durationInSeconds = (now - activeSyncContext.mStartTime) / 1000;
        pw.print("  ");
        pw.print(DateUtils.formatElapsedTime(durationInSeconds));
        pw.print(" - ");
        pw.print(activeSyncContext.mSyncOperation.dump(pm, false));
        pw.println();
    }
    synchronized (mSyncQueue) {
        sb.setLength(0);
        mSyncQueue.dump(sb);
    }
    pw.println();
    pw.print(sb.toString());
    // join the installed sync adapter with the accounts list and emit for everything
    pw.println();
    pw.println("Sync Status");
    for (AccountAndUser account : accounts) {
        pw.printf("Account %s u%d %s\n", account.account.name, account.userId, account.account.type);
        pw.println("=======================================================================");
        final PrintTable table = new PrintTable(13);
        table.set(0, 0, // 0
        "Authority", // 1
        "Syncable", // 2
        "Enabled", // 3
        "Delay", // 4
        "Loc", // 5
        "Poll", // 6
        "Per", // 7
        "Serv", // 8
        "User", // 9
        "Tot", // 10
        "Time", // 11
        "Last Sync", // 12
        "Periodic");
        final List<RegisteredServicesCache.ServiceInfo<SyncAdapterType>> sorted = Lists.newArrayList();
        sorted.addAll(mSyncAdapters.getAllServices(account.userId));
        Collections.sort(sorted, new Comparator<RegisteredServicesCache.ServiceInfo<SyncAdapterType>>() {

            @Override
            public int compare(RegisteredServicesCache.ServiceInfo<SyncAdapterType> lhs, RegisteredServicesCache.ServiceInfo<SyncAdapterType> rhs) {
                return lhs.type.authority.compareTo(rhs.type.authority);
            }
        });
        for (RegisteredServicesCache.ServiceInfo<SyncAdapterType> syncAdapterType : sorted) {
            if (!syncAdapterType.type.accountType.equals(account.account.type)) {
                continue;
            }
            int row = table.getNumRows();
            SyncStorageEngine.AuthorityInfo settings = mSyncStorageEngine.getOrCreateAuthority(account.account, account.userId, syncAdapterType.type.authority);
            SyncStatusInfo status = mSyncStorageEngine.getOrCreateSyncStatus(settings);
            String authority = settings.authority;
            if (authority.length() > 50) {
                authority = authority.substring(authority.length() - 50);
            }
            table.set(row, 0, authority, settings.syncable, settings.enabled);
            table.set(row, 4, status.numSourceLocal, status.numSourcePoll, status.numSourcePeriodic, status.numSourceServer, status.numSourceUser, status.numSyncs, DateUtils.formatElapsedTime(status.totalElapsedTime / 1000));
            for (int i = 0; i < settings.periodicSyncs.size(); i++) {
                final Pair<Bundle, Long> pair = settings.periodicSyncs.get(0);
                final String period = String.valueOf(pair.second);
                final String extras = pair.first.size() > 0 ? pair.first.toString() : "";
                final String next = formatTime(status.getPeriodicSyncTime(0) + pair.second * 1000);
                table.set(row + i * 2, 12, period + extras);
                table.set(row + i * 2 + 1, 12, next);
            }
            int row1 = row;
            if (settings.delayUntil > now) {
                table.set(row1++, 12, "D: " + (settings.delayUntil - now) / 1000);
                if (settings.backoffTime > now) {
                    table.set(row1++, 12, "B: " + (settings.backoffTime - now) / 1000);
                    table.set(row1++, 12, settings.backoffDelay / 1000);
                }
            }
            if (status.lastSuccessTime != 0) {
                table.set(row1++, 11, SyncStorageEngine.SOURCES[status.lastSuccessSource] + " " + "SUCCESS");
                table.set(row1++, 11, formatTime(status.lastSuccessTime));
            }
            if (status.lastFailureTime != 0) {
                table.set(row1++, 11, SyncStorageEngine.SOURCES[status.lastFailureSource] + " " + "FAILURE");
                table.set(row1++, 11, formatTime(status.lastFailureTime));
                //noinspection UnusedAssignment
                table.set(row1++, 11, status.lastFailureMesg);
            }
        }
        table.writeTo(pw);
    }
}
Also used : UserInfo(android.content.pm.UserInfo) PackageManager(android.content.pm.PackageManager) AccountAndUser(android.accounts.AccountAndUser) Bundle(android.os.Bundle) SyncStatusInfo(android.content.SyncStatusInfo) SyncAdapterType(android.content.SyncAdapterType) RegisteredServicesCache(android.content.pm.RegisteredServicesCache)

Example 2 with SyncStatusInfo

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

the class SyncStorageEngine method updateOrRemovePeriodicSync.

private void updateOrRemovePeriodicSync(Account account, int userId, String providerName, Bundle extras, long period, boolean add) {
    if (period <= 0) {
        period = 0;
    }
    if (extras == null) {
        extras = new Bundle();
    }
    if (DEBUG) {
        Log.v(TAG, "addOrRemovePeriodicSync: " + account + ", user " + userId + ", provider " + providerName + " -> period " + period + ", extras " + extras);
    }
    synchronized (mAuthorities) {
        try {
            AuthorityInfo authority = getOrCreateAuthorityLocked(account, userId, providerName, -1, false);
            if (add) {
                // add this periodic sync if one with the same extras doesn't already
                // exist in the periodicSyncs array
                boolean alreadyPresent = false;
                for (int i = 0, N = authority.periodicSyncs.size(); i < N; i++) {
                    Pair<Bundle, Long> syncInfo = authority.periodicSyncs.get(i);
                    final Bundle existingExtras = syncInfo.first;
                    if (PeriodicSync.syncExtrasEquals(existingExtras, extras)) {
                        if (syncInfo.second == period) {
                            return;
                        }
                        authority.periodicSyncs.set(i, Pair.create(extras, period));
                        alreadyPresent = true;
                        break;
                    }
                }
                // the periodic syncs status to correspond to it
                if (!alreadyPresent) {
                    authority.periodicSyncs.add(Pair.create(extras, period));
                    SyncStatusInfo status = getOrCreateSyncStatusLocked(authority.ident);
                    status.setPeriodicSyncTime(authority.periodicSyncs.size() - 1, 0);
                }
            } else {
                // remove any periodic syncs that match the authority and extras
                SyncStatusInfo status = mSyncStatus.get(authority.ident);
                boolean changed = false;
                Iterator<Pair<Bundle, Long>> iterator = authority.periodicSyncs.iterator();
                int i = 0;
                while (iterator.hasNext()) {
                    Pair<Bundle, Long> syncInfo = iterator.next();
                    if (PeriodicSync.syncExtrasEquals(syncInfo.first, extras)) {
                        iterator.remove();
                        changed = true;
                        // remove the corresponding entry from the status
                        if (status != null) {
                            status.removePeriodicSyncTime(i);
                        }
                    } else {
                        i++;
                    }
                }
                if (!changed) {
                    return;
                }
            }
        } finally {
            writeAccountInfoLocked();
            writeStatusLocked();
        }
    }
    reportChange(ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS);
}
Also used : Bundle(android.os.Bundle) SyncStatusInfo(android.content.SyncStatusInfo) Pair(android.util.Pair)

Example 3 with SyncStatusInfo

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

the class SyncStorageEngine method isSyncPending.

/**
     * Return true if the pending status is true of any matching authorities.
     */
public boolean isSyncPending(Account account, int userId, String authority) {
    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 (userId != ainfo.userId) {
                continue;
            }
            if (account != null && !ainfo.account.equals(account)) {
                continue;
            }
            if (ainfo.authority.equals(authority) && cur.pending) {
                return true;
            }
        }
        return false;
    }
}
Also used : SyncStatusInfo(android.content.SyncStatusInfo)

Example 4 with SyncStatusInfo

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

the class SyncStorageEngine method getOrCreateSyncStatusLocked.

private SyncStatusInfo getOrCreateSyncStatusLocked(int authorityId) {
    SyncStatusInfo status = mSyncStatus.get(authorityId);
    if (status == null) {
        status = new SyncStatusInfo(authorityId);
        mSyncStatus.put(authorityId, status);
    }
    return status;
}
Also used : SyncStatusInfo(android.content.SyncStatusInfo)

Example 5 with SyncStatusInfo

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

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 (DEBUG_FILE)
            Log.v(TAG, "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 Account(accountName, accountType), 0, /* legacy is single-user */
            authorityName, -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.authority.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) AtomicFile(android.util.AtomicFile) File(java.io.File) SQLiteQueryBuilder(android.database.sqlite.SQLiteQueryBuilder)

Aggregations

SyncStatusInfo (android.content.SyncStatusInfo)64 Account (android.accounts.Account)14 Parcel (android.os.Parcel)12 SyncInfo (android.content.SyncInfo)8 Date (java.util.Date)8 SyncAdapterType (android.content.SyncAdapterType)7 Preference (android.support.v7.preference.Preference)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