Search in sources :

Example 1 with SyncAdapterType

use of android.content.SyncAdapterType 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 SyncAdapterType

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

the class SyncManager method getIsSyncable.

private int getIsSyncable(Account account, int userId, String providerName) {
    int isSyncable = mSyncStorageEngine.getIsSyncable(account, userId, providerName);
    UserInfo userInfo = UserManager.get(mContext).getUserInfo(userId);
    // If it's not a restricted user, return isSyncable.
    if (userInfo == null || !userInfo.isRestricted())
        return isSyncable;
    // Else check if the sync adapter has opted-in or not.
    RegisteredServicesCache.ServiceInfo<SyncAdapterType> syncAdapterInfo = mSyncAdapters.getServiceInfo(SyncAdapterType.newKey(providerName, account.type), userId);
    if (syncAdapterInfo == null)
        return AuthorityInfo.NOT_SYNCABLE;
    PackageInfo pInfo = null;
    try {
        pInfo = AppGlobals.getPackageManager().getPackageInfo(syncAdapterInfo.componentName.getPackageName(), 0, userId);
        if (pInfo == null)
            return AuthorityInfo.NOT_SYNCABLE;
    } catch (RemoteException re) {
        // Shouldn't happen.
        return AuthorityInfo.NOT_SYNCABLE;
    }
    if (pInfo.restrictedAccountType != null && pInfo.restrictedAccountType.equals(account.type)) {
        return isSyncable;
    } else {
        return AuthorityInfo.NOT_SYNCABLE;
    }
}
Also used : PackageInfo(android.content.pm.PackageInfo) UserInfo(android.content.pm.UserInfo) SyncAdapterType(android.content.SyncAdapterType) RemoteException(android.os.RemoteException) EndPoint(com.android.server.content.SyncStorageEngine.EndPoint) RegisteredServicesCache(android.content.pm.RegisteredServicesCache)

Example 3 with SyncAdapterType

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

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);
    pw.print("device idle: ");
    pw.println(mDeviceIsIdle);
    pw.print("reported active: ");
    pw.println(mReportedSyncActive);
    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.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");
    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();
    }
    // 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(12);
        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");
        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();
            Pair<AuthorityInfo, SyncStatusInfo> syncAuthoritySyncStatus = mSyncStorageEngine.getCopyOfAuthorityWithSyncStatus(new SyncStorageEngine.EndPoint(account.account, syncAdapterType.type.authority, account.userId));
            SyncStorageEngine.AuthorityInfo settings = syncAuthoritySyncStatus.first;
            SyncStatusInfo status = syncAuthoritySyncStatus.second;
            String authority = settings.target.provider;
            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));
            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 : AuthorityInfo(com.android.server.content.SyncStorageEngine.AuthorityInfo) UserInfo(android.content.pm.UserInfo) SyncStatusInfo(android.content.SyncStatusInfo) SyncAdapterType(android.content.SyncAdapterType) EndPoint(com.android.server.content.SyncStorageEngine.EndPoint) EndPoint(com.android.server.content.SyncStorageEngine.EndPoint) PackageManager(android.content.pm.PackageManager) AccountAndUser(android.accounts.AccountAndUser) AuthorityInfo(com.android.server.content.SyncStorageEngine.AuthorityInfo) RegisteredServicesCache(android.content.pm.RegisteredServicesCache)

Example 4 with SyncAdapterType

use of android.content.SyncAdapterType in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ChooseAccountActivity method getAuthoritiesForAccountType.

public ArrayList<String> getAuthoritiesForAccountType(String type) {
    if (mAccountTypeToAuthorities == null) {
        mAccountTypeToAuthorities = Maps.newHashMap();
        SyncAdapterType[] syncAdapters = ContentResolver.getSyncAdapterTypesAsUser(mUserHandle.getIdentifier());
        for (int i = 0, n = syncAdapters.length; i < n; i++) {
            final SyncAdapterType sa = syncAdapters[i];
            ArrayList<String> authorities = mAccountTypeToAuthorities.get(sa.accountType);
            if (authorities == null) {
                authorities = new ArrayList<String>();
                mAccountTypeToAuthorities.put(sa.accountType, authorities);
            }
            if (Log.isLoggable(TAG, Log.VERBOSE)) {
                Log.d(TAG, "added authority " + sa.authority + " to accountType " + sa.accountType);
            }
            authorities.add(sa.authority);
        }
    }
    return mAccountTypeToAuthorities.get(type);
}
Also used : SyncAdapterType(android.content.SyncAdapterType)

Example 5 with SyncAdapterType

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

the class AccountSyncSettingsBackupHelper method serializeAccountSyncSettingsToJSON.

/**
     * Fetch and serialize Account and authority information as a JSON Array.
     */
private JSONObject serializeAccountSyncSettingsToJSON() throws JSONException {
    Account[] accounts = mAccountManager.getAccounts();
    SyncAdapterType[] syncAdapters = ContentResolver.getSyncAdapterTypesAsUser(mContext.getUserId());
    // Create a map of Account types to authorities. Later this will make it easier for us to
    // generate our JSON.
    HashMap<String, List<String>> accountTypeToAuthorities = new HashMap<String, List<String>>();
    for (SyncAdapterType syncAdapter : syncAdapters) {
        // Skip adapters that aren’t visible to the user.
        if (!syncAdapter.isUserVisible()) {
            continue;
        }
        if (!accountTypeToAuthorities.containsKey(syncAdapter.accountType)) {
            accountTypeToAuthorities.put(syncAdapter.accountType, new ArrayList<String>());
        }
        accountTypeToAuthorities.get(syncAdapter.accountType).add(syncAdapter.authority);
    }
    // Generate JSON.
    JSONObject backupJSON = new JSONObject();
    backupJSON.put(KEY_VERSION, JSON_FORMAT_VERSION);
    backupJSON.put(KEY_MASTER_SYNC_ENABLED, ContentResolver.getMasterSyncAutomatically());
    JSONArray accountJSONArray = new JSONArray();
    for (Account account : accounts) {
        List<String> authorities = accountTypeToAuthorities.get(account.type);
        // settings for us to restore.
        if (authorities == null || authorities.isEmpty()) {
            continue;
        }
        JSONObject accountJSON = new JSONObject();
        accountJSON.put(KEY_ACCOUNT_NAME, account.name);
        accountJSON.put(KEY_ACCOUNT_TYPE, account.type);
        // Add authorities for this Account type and check whether or not sync is enabled.
        JSONArray authoritiesJSONArray = new JSONArray();
        for (String authority : authorities) {
            int syncState = ContentResolver.getIsSyncable(account, authority);
            boolean syncEnabled = ContentResolver.getSyncAutomatically(account, authority);
            JSONObject authorityJSON = new JSONObject();
            authorityJSON.put(KEY_AUTHORITY_NAME, authority);
            authorityJSON.put(KEY_AUTHORITY_SYNC_STATE, syncState);
            authorityJSON.put(KEY_AUTHORITY_SYNC_ENABLED, syncEnabled);
            authoritiesJSONArray.put(authorityJSON);
        }
        accountJSON.put(KEY_ACCOUNT_AUTHORITIES, authoritiesJSONArray);
        accountJSONArray.put(accountJSON);
    }
    backupJSON.put(KEY_ACCOUNTS, accountJSONArray);
    return backupJSON;
}
Also used : Account(android.accounts.Account) HashMap(java.util.HashMap) JSONArray(org.json.JSONArray) SyncAdapterType(android.content.SyncAdapterType) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

SyncAdapterType (android.content.SyncAdapterType)127 Test (org.junit.Test)46 RegisteredServicesCache (android.content.pm.RegisteredServicesCache)33 EndPoint (com.android.server.content.SyncStorageEngine.EndPoint)30 UserInfo (android.content.pm.UserInfo)17 Account (android.accounts.Account)13 PackageManager (android.content.pm.PackageManager)13 ArrayList (java.util.ArrayList)13 AccountAndUser (android.accounts.AccountAndUser)12 RemoteException (android.os.RemoteException)11 UserHandle (android.os.UserHandle)9 Bundle (android.os.Bundle)8 Preference (android.support.v7.preference.Preference)8 HashSet (java.util.HashSet)8 SyncStatusInfo (android.content.SyncStatusInfo)7 PackageInfo (android.content.pm.PackageInfo)6 VisibleForTesting (android.support.annotation.VisibleForTesting)6 List (java.util.List)6 AuthenticatorDescription (android.accounts.AuthenticatorDescription)5 RemoteCallback (android.os.RemoteCallback)5