Search in sources :

Example 1 with TimingLogger

use of android.util.TimingLogger in project android_packages_apps_Dialer by LineageOS.

the class AccountTypeManagerImpl method loadAccountsInBackground.

/**
 * Loads account list and corresponding account types (potentially with data sets). Always called
 * on a background thread.
 */
protected void loadAccountsInBackground() {
    if (Log.isLoggable(Constants.PERFORMANCE_TAG, Log.DEBUG)) {
        Log.d(Constants.PERFORMANCE_TAG, "AccountTypeManager.loadAccountsInBackground start");
    }
    TimingLogger timings = new TimingLogger(TAG, "loadAccountsInBackground");
    final long startTime = SystemClock.currentThreadTimeMillis();
    final long startTimeWall = SystemClock.elapsedRealtime();
    // Account types, keyed off the account type and data set concatenation.
    final Map<AccountTypeWithDataSet, AccountType> accountTypesByTypeAndDataSet = new ArrayMap<>();
    // The same AccountTypes, but keyed off {@link RawContacts#ACCOUNT_TYPE}.  Since there can
    // be multiple account types (with different data sets) for the same type of account, each
    // type string may have multiple AccountType entries.
    final Map<String, List<AccountType>> accountTypesByType = new ArrayMap<>();
    final List<AccountWithDataSet> allAccounts = new ArrayList<>();
    final List<AccountWithDataSet> contactWritableAccounts = new ArrayList<>();
    final List<AccountWithDataSet> groupWritableAccounts = new ArrayList<>();
    final Set<String> extensionPackages = new HashSet<>();
    final AccountManager am = mAccountManager;
    final SyncAdapterType[] syncs = ContentResolver.getSyncAdapterTypes();
    final AuthenticatorDescription[] auths = am.getAuthenticatorTypes();
    // First process sync adapters to find any that provide contact data.
    for (SyncAdapterType sync : syncs) {
        if (!ContactsContract.AUTHORITY.equals(sync.authority)) {
            // Skip sync adapters that don't provide contact data.
            continue;
        }
        // Look for the formatting details provided by each sync
        // adapter, using the authenticator to find general resources.
        final String type = sync.accountType;
        final AuthenticatorDescription auth = findAuthenticator(auths, type);
        if (auth == null) {
            Log.w(TAG, "No authenticator found for type=" + type + ", ignoring it.");
            continue;
        }
        AccountType accountType;
        if (GoogleAccountType.ACCOUNT_TYPE.equals(type)) {
            accountType = new GoogleAccountType(mContext, auth.packageName);
        } else if (ExchangeAccountType.isExchangeType(type)) {
            accountType = new ExchangeAccountType(mContext, auth.packageName, type);
        } else if (SamsungAccountType.isSamsungAccountType(mContext, type, auth.packageName)) {
            accountType = new SamsungAccountType(mContext, auth.packageName, type);
        } else {
            Log.d(TAG, "Registering external account type=" + type + ", packageName=" + auth.packageName);
            accountType = new ExternalAccountType(mContext, auth.packageName, false);
        }
        if (!accountType.isInitialized()) {
            if (accountType.isEmbedded()) {
                throw new IllegalStateException("Problem initializing embedded type " + accountType.getClass().getCanonicalName());
            } else {
                // Skip external account types that couldn't be initialized.
                continue;
            }
        }
        accountType.accountType = auth.type;
        accountType.titleRes = auth.labelId;
        accountType.iconRes = auth.iconId;
        addAccountType(accountType, accountTypesByTypeAndDataSet, accountTypesByType);
        // Check to see if the account type knows of any other non-sync-adapter packages
        // that may provide other data sets of contact data.
        extensionPackages.addAll(accountType.getExtensionPackageNames());
    }
    // If any extension packages were specified, process them as well.
    if (!extensionPackages.isEmpty()) {
        Log.d(TAG, "Registering " + extensionPackages.size() + " extension packages");
        for (String extensionPackage : extensionPackages) {
            ExternalAccountType accountType = new ExternalAccountType(mContext, extensionPackage, true);
            if (!accountType.isInitialized()) {
                // Skip external account types that couldn't be initialized.
                continue;
            }
            if (!accountType.hasContactsMetadata()) {
                Log.w(TAG, "Skipping extension package " + extensionPackage + " because" + " it doesn't have the CONTACTS_STRUCTURE metadata");
                continue;
            }
            if (TextUtils.isEmpty(accountType.accountType)) {
                Log.w(TAG, "Skipping extension package " + extensionPackage + " because" + " the CONTACTS_STRUCTURE metadata doesn't have the accountType" + " attribute");
                continue;
            }
            Log.d(TAG, "Registering extension package account type=" + accountType.accountType + ", dataSet=" + accountType.dataSet + ", packageName=" + extensionPackage);
            addAccountType(accountType, accountTypesByTypeAndDataSet, accountTypesByType);
        }
    }
    timings.addSplit("Loaded account types");
    // Map in accounts to associate the account names with each account type entry.
    Account[] accounts = mAccountManager.getAccounts();
    for (Account account : accounts) {
        boolean syncable = ContentResolver.getIsSyncable(account, ContactsContract.AUTHORITY) > 0;
        if (syncable) {
            List<AccountType> accountTypes = accountTypesByType.get(account.type);
            if (accountTypes != null) {
                // authenticated by this account.
                for (AccountType accountType : accountTypes) {
                    AccountWithDataSet accountWithDataSet = new AccountWithDataSet(account.name, account.type, accountType.dataSet);
                    allAccounts.add(accountWithDataSet);
                    if (accountType.areContactsWritable()) {
                        contactWritableAccounts.add(accountWithDataSet);
                    }
                    if (accountType.isGroupMembershipEditable()) {
                        groupWritableAccounts.add(accountWithDataSet);
                    }
                }
            }
        }
    }
    Collections.sort(allAccounts, ACCOUNT_COMPARATOR);
    Collections.sort(contactWritableAccounts, ACCOUNT_COMPARATOR);
    Collections.sort(groupWritableAccounts, ACCOUNT_COMPARATOR);
    timings.addSplit("Loaded accounts");
    synchronized (this) {
        mAccountTypesWithDataSets = accountTypesByTypeAndDataSet;
        mAccounts = allAccounts;
        mContactWritableAccounts = contactWritableAccounts;
        mGroupWritableAccounts = groupWritableAccounts;
        mInvitableAccountTypes = findAllInvitableAccountTypes(mContext, allAccounts, accountTypesByTypeAndDataSet);
    }
    timings.dumpToLog();
    final long endTimeWall = SystemClock.elapsedRealtime();
    final long endTime = SystemClock.currentThreadTimeMillis();
    Log.i(TAG, "Loaded meta-data for " + mAccountTypesWithDataSets.size() + " account types, " + mAccounts.size() + " accounts in " + (endTimeWall - startTimeWall) + "ms(wall) " + (endTime - startTime) + "ms(cpu)");
    if (mInitializationLatch != null) {
        mInitializationLatch.countDown();
        mInitializationLatch = null;
    }
    if (Log.isLoggable(Constants.PERFORMANCE_TAG, Log.DEBUG)) {
        Log.d(Constants.PERFORMANCE_TAG, "AccountTypeManager.loadAccountsInBackground finish");
    }
    // Check filter validity since filter may become obsolete after account update. It must be
    // done from UI thread.
    mMainThreadHandler.post(mCheckFilterValidityRunnable);
}
Also used : Account(android.accounts.Account) ArrayList(java.util.ArrayList) GoogleAccountType(com.android.contacts.common.model.account.GoogleAccountType) ExchangeAccountType(com.android.contacts.common.model.account.ExchangeAccountType) SamsungAccountType(com.android.contacts.common.model.account.SamsungAccountType) AuthenticatorDescription(android.accounts.AuthenticatorDescription) TimingLogger(android.util.TimingLogger) List(java.util.List) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AccountWithDataSet(com.android.contacts.common.model.account.AccountWithDataSet) AccountTypeWithDataSet(com.android.contacts.common.model.account.AccountTypeWithDataSet) ArrayMap(android.util.ArrayMap) ExternalAccountType(com.android.contacts.common.model.account.ExternalAccountType) SyncAdapterType(android.content.SyncAdapterType) AccountType(com.android.contacts.common.model.account.AccountType) FallbackAccountType(com.android.contacts.common.model.account.FallbackAccountType) ExchangeAccountType(com.android.contacts.common.model.account.ExchangeAccountType) SamsungAccountType(com.android.contacts.common.model.account.SamsungAccountType) ExternalAccountType(com.android.contacts.common.model.account.ExternalAccountType) GoogleAccountType(com.android.contacts.common.model.account.GoogleAccountType) AccountManager(android.accounts.AccountManager)

Example 2 with TimingLogger

use of android.util.TimingLogger in project Auto.js by hyb1996.

the class TemplateMatching method fastTemplateMatching.

/**
 * 采用图像金字塔算法快速找图
 *
 * @param img             图片
 * @param template        模板图片
 * @param matchMethod     匹配算法
 * @param weakThreshold   弱阈值。该值用于在每一轮模板匹配中检验是否继续匹配。如果相似度小于该值,则不再继续匹配。
 * @param strictThreshold 强阈值。该值用于检验最终匹配结果,以及在每一轮匹配中如果相似度大于该值则直接返回匹配结果。
 * @param maxLevel        图像金字塔的层数
 * @return
 */
public static Point fastTemplateMatching(Mat img, Mat template, int matchMethod, float weakThreshold, float strictThreshold, int maxLevel) {
    TimingLogger logger = new TimingLogger(LOG_TAG, "fast_tm");
    if (maxLevel == MAX_LEVEL_AUTO) {
        // 自动选取金字塔层数
        maxLevel = selectPyramidLevel(img, template);
        logger.addSplit("selectPyramidLevel:" + maxLevel);
    }
    // 保存每一轮匹配到模板图片在原图片的位置
    Point p = null;
    Mat matchResult;
    double similarity = 0;
    boolean isFirstMatching = true;
    for (int level = maxLevel; level >= 0; level--) {
        // 放缩图片
        Mat src = getPyramidDownAtLevel(img, level);
        Mat currentTemplate = getPyramidDownAtLevel(template, level);
        // 如果在上一轮中没有匹配到图片,则考虑是否退出匹配
        if (p == null) {
            // 如果不是第一次匹配,并且不满足shouldContinueMatching的条件,则直接退出匹配(返回null)
            if (!isFirstMatching && !shouldContinueMatching(level, maxLevel)) {
                break;
            }
            matchResult = matchTemplate(src, currentTemplate, matchMethod);
            Pair<Point, Double> bestMatched = getBestMatched(matchResult, matchMethod, weakThreshold);
            p = bestMatched.first;
            similarity = bestMatched.second;
        } else {
            // 根据上一轮的匹配点,计算本次匹配的区域
            Rect r = getROI(p, src, currentTemplate);
            matchResult = matchTemplate(new Mat(src, r), currentTemplate, matchMethod);
            Pair<Point, Double> bestMatched = getBestMatched(matchResult, matchMethod, weakThreshold);
            // 不满足弱阈值,返回null
            if (bestMatched.second < weakThreshold) {
            // p = null;
            // break;
            }
            p = bestMatched.first;
            similarity = bestMatched.second;
            p.x += r.x;
            p.y += r.y;
        }
        // 满足强阈值,返回当前结果
        if (similarity >= strictThreshold) {
            pyrUp(p, level);
            break;
        }
        logger.addSplit("level:" + level + " point:" + p);
        isFirstMatching = false;
    }
    logger.addSplit("result:" + p);
    logger.dumpToLog();
    if (similarity < strictThreshold) {
        return null;
    }
    return p;
}
Also used : Mat(org.opencv.core.Mat) Rect(org.opencv.core.Rect) TimingLogger(android.util.TimingLogger) Point(org.opencv.core.Point) Point(org.opencv.core.Point)

Example 3 with TimingLogger

use of android.util.TimingLogger in project Auto.js by hyb1996.

the class TemplateMatching method getBestMatched.

public static Pair<Point, Double> getBestMatched(Mat tmResult, int matchMethod, float threshold) {
    TimingLogger logger = new TimingLogger(LOG_TAG, "best_matched_point");
    // FIXME: 2017/11/26 正交化?
    // Core.normalize(tmResult, tmResult, 0, 1, Core.NORM_MINMAX, -1, new Mat());
    Core.MinMaxLocResult mmr = Core.minMaxLoc(tmResult);
    logger.addSplit("minMaxLoc");
    double value;
    Point pos;
    if (matchMethod == Imgproc.TM_SQDIFF || matchMethod == Imgproc.TM_SQDIFF_NORMED) {
        pos = mmr.minLoc;
        value = -mmr.minVal;
    } else {
        pos = mmr.maxLoc;
        value = mmr.maxVal;
    }
    logger.addSplit("value:" + value);
    logger.dumpToLog();
    return new Pair<>(pos, value);
}
Also used : TimingLogger(android.util.TimingLogger) Point(org.opencv.core.Point) Core(org.opencv.core.Core) Pair(android.util.Pair)

Aggregations

TimingLogger (android.util.TimingLogger)3 Point (org.opencv.core.Point)2 Account (android.accounts.Account)1 AccountManager (android.accounts.AccountManager)1 AuthenticatorDescription (android.accounts.AuthenticatorDescription)1 SyncAdapterType (android.content.SyncAdapterType)1 ArrayMap (android.util.ArrayMap)1 Pair (android.util.Pair)1 AccountType (com.android.contacts.common.model.account.AccountType)1 AccountTypeWithDataSet (com.android.contacts.common.model.account.AccountTypeWithDataSet)1 AccountWithDataSet (com.android.contacts.common.model.account.AccountWithDataSet)1 ExchangeAccountType (com.android.contacts.common.model.account.ExchangeAccountType)1 ExternalAccountType (com.android.contacts.common.model.account.ExternalAccountType)1 FallbackAccountType (com.android.contacts.common.model.account.FallbackAccountType)1 GoogleAccountType (com.android.contacts.common.model.account.GoogleAccountType)1 SamsungAccountType (com.android.contacts.common.model.account.SamsungAccountType)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Core (org.opencv.core.Core)1