Search in sources :

Example 6 with StopWatch

use of com.android.contacts.common.util.StopWatch in project android_packages_apps_Dialer by MoKee.

the class DialpadFragment method onResume.

@Override
public void onResume() {
    Trace.beginSection(TAG + " onResume");
    super.onResume();
    final DialtactsActivity activity = (DialtactsActivity) getActivity();
    mDialpadQueryListener = activity;
    final StopWatch stopWatch = StopWatch.start("Dialpad.onResume");
    // Query the last dialed number. Do it first because hitting
    mHasReadAndWriteCallLogPermission = PermissionsUtil.hasPermission(getActivity(), READ_CALL_LOG) && PermissionsUtil.hasPermission(getActivity(), WRITE_CALL_LOG);
    // the DB is 'slow'. This call is asynchronous.
    if (mHasReadAndWriteCallLogPermission) {
        queryLastOutgoingCall();
    } else {
        ActivityCompat.requestPermissions(getActivity(), new String[] { READ_CALL_LOG, WRITE_CALL_LOG }, READ_WRITE_CALL_LOG_PERMISSION_REQUEST_CODE);
    }
    stopWatch.lap("qloc");
    final ContentResolver contentResolver = activity.getContentResolver();
    // retrieve the DTMF tone play back setting.
    mDTMFToneEnabled = Settings.System.getInt(contentResolver, Settings.System.DTMF_TONE_WHEN_DIALING, 1) == 1;
    stopWatch.lap("dtwd");
    stopWatch.lap("hptc");
    mPressedDialpadKeys.clear();
    configureScreenFromIntent(getActivity());
    stopWatch.lap("fdin");
    if (!isPhoneInUse()) {
        // A sanity-check: the "dialpad chooser" UI should not be visible if the phone is idle.
        showDialpadChooser(false);
    }
    stopWatch.lap("hnt");
    updateDeleteButtonEnabledState();
    stopWatch.lap("bes");
    stopWatch.stopAndLog(TAG, 50);
    // Populate the overflow menu in onResume instead of onCreate, so that if the SMS activity
    // is disabled while Dialer is paused, the "Send a text message" option can be correctly
    // removed when resumed.
    mOverflowMenuButton = mDialpadView.getOverflowMenuButton();
    mOverflowPopupMenu = buildOptionsMenu(mOverflowMenuButton);
    mOverflowMenuButton.setOnTouchListener(mOverflowPopupMenu.getDragToOpenListener());
    mOverflowMenuButton.setOnClickListener(this);
    mOverflowMenuButton.setVisibility(isDigitsEmpty() ? View.INVISIBLE : View.VISIBLE);
    if (mFirstLaunch) {
        // The onHiddenChanged callback does not get called the first time the fragment is
        // attached, so call it ourselves here.
        onHiddenChanged(false);
    }
    mFirstLaunch = false;
    if (MoreContactUtils.shouldShowOperator(getContext())) {
        mOperator.setVisibility(View.VISIBLE);
        mOperator.setText(MoreContactUtils.getNetworkSpnName(getContext(), SubscriptionManager.getDefaultVoiceSubscriptionId()));
    } else {
        mOperator.setVisibility(View.GONE);
    }
    if (isConfigAvailableNetwork) {
        Context context = getActivity();
        mWifiCallReadyReceiver = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                changeDialpadButton(intent.getBooleanExtra(ACTION_WIFI_CALL_READY_EXTRA, false));
            }
        };
        IntentFilter filter = new IntentFilter(ACTION_WIFI_CALL_READY_STATUS_CHANGE);
        context.registerReceiver(mWifiCallReadyReceiver, filter);
        changeDialpadButton(WifiCallUtils.isWifiCallReadyEnabled(context));
    }
    Trace.endSection();
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) DialtactsActivity(com.android.dialer.DialtactsActivity) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) StopWatch(com.android.contacts.common.util.StopWatch) ContentResolver(android.content.ContentResolver)

Example 7 with StopWatch

use of com.android.contacts.common.util.StopWatch in project android_packages_apps_Dialer by MoKee.

the class DialerDatabaseHelper method updateSmartDialDatabase.

/**
 * Updates the smart dial and prefix database. This method queries the Delta API to get changed
 * contacts since last update, and updates the records in smartdial database and prefix database
 * accordingly. It also queries the deleted contact database to remove newly deleted contacts
 * since last update.
 *
 * @param forceUpdate If set to true, update the database by reloading all contacts.
 */
@WorkerThread
public synchronized void updateSmartDialDatabase(boolean forceUpdate) {
    LogUtil.enterBlock("DialerDatabaseHelper.updateSmartDialDatabase");
    final SQLiteDatabase db = getWritableDatabase();
    LogUtil.v("DialerDatabaseHelper.updateSmartDialDatabase", "starting to update database");
    final StopWatch stopWatch = DEBUG ? StopWatch.start("Updating databases") : null;
    /**
     * Gets the last update time on the database.
     */
    final SharedPreferences databaseLastUpdateSharedPref = context.getSharedPreferences(DATABASE_LAST_CREATED_SHARED_PREF, Context.MODE_PRIVATE);
    long defaultLastUpdateMillis = ConfigProviderBindings.get(context).getLong(DEFAULT_LAST_UPDATED_CONFIG_KEY, 0);
    long sharedPrefLastUpdateMillis = databaseLastUpdateSharedPref.getLong(LAST_UPDATED_MILLIS, defaultLastUpdateMillis);
    final String lastUpdateMillis = String.valueOf(forceUpdate ? 0 : sharedPrefLastUpdateMillis);
    LogUtil.i("DialerDatabaseHelper.updateSmartDialDatabase", "last updated at %s", lastUpdateMillis);
    /**
     * Sets the time after querying the database as the current update time.
     */
    final Long currentMillis = System.currentTimeMillis();
    if (DEBUG) {
        stopWatch.lap("Queried the Contacts database");
    }
    /**
     * Removes contacts that have been deleted.
     */
    removeDeletedContacts(db, lastUpdateMillis);
    removePotentiallyCorruptedContacts(db, lastUpdateMillis);
    if (DEBUG) {
        stopWatch.lap("Finished deleting deleted entries");
    }
    /**
     * If the database did not exist before, jump through deletion as there is nothing to delete.
     */
    if (!lastUpdateMillis.equals("0")) {
        /**
         * Removes contacts that have been updated. Updated contact information will be inserted
         * later. Note that this has to use a separate result set from updatePhoneCursor, since it is
         * possible for a contact to be updated (e.g. phone number deleted), but have no results show
         * up in updatedPhoneCursor (since all of its phone numbers have been deleted).
         */
        final Cursor updatedContactCursor = context.getContentResolver().query(UpdatedContactQuery.URI, UpdatedContactQuery.PROJECTION, UpdatedContactQuery.SELECT_UPDATED_CLAUSE, new String[] { lastUpdateMillis }, null);
        if (updatedContactCursor == null) {
            LogUtil.e("DialerDatabaseHelper.updateSmartDialDatabase", "smartDial query received null for cursor");
            return;
        }
        try {
            removeUpdatedContacts(db, updatedContactCursor);
        } finally {
            updatedContactCursor.close();
        }
        if (DEBUG) {
            stopWatch.lap("Finished deleting entries belonging to updated contacts");
        }
    }
    /**
     * Queries the contact database to get all phone numbers that have been updated since the last
     * update time.
     */
    final Cursor updatedPhoneCursor = context.getContentResolver().query(PhoneQuery.URI, PhoneQuery.PROJECTION, PhoneQuery.SELECTION, new String[] { lastUpdateMillis }, null);
    if (updatedPhoneCursor == null) {
        LogUtil.e("DialerDatabaseHelper.updateSmartDialDatabase", "smartDial query received null for cursor");
        return;
    }
    try {
        /**
         * Inserts recently updated phone numbers to the smartdial database.
         */
        insertUpdatedContactsAndNumberPrefix(db, updatedPhoneCursor, currentMillis);
        if (DEBUG) {
            stopWatch.lap("Finished building the smart dial table");
        }
    } finally {
        updatedPhoneCursor.close();
    }
    /**
     * Gets a list of distinct contacts which have been updated, and adds the name prefixes of these
     * contacts to the prefix table.
     */
    final Cursor nameCursor = db.rawQuery("SELECT DISTINCT " + SmartDialDbColumns.DISPLAY_NAME_PRIMARY + ", " + SmartDialDbColumns.CONTACT_ID + " FROM " + Tables.SMARTDIAL_TABLE + " WHERE " + SmartDialDbColumns.LAST_SMARTDIAL_UPDATE_TIME + " = " + currentMillis, new String[] {});
    if (nameCursor != null) {
        try {
            if (DEBUG) {
                stopWatch.lap("Queried the smart dial table for contact names");
            }
            /**
             * Inserts prefixes of names into the prefix table.
             */
            insertNamePrefixes(db, nameCursor);
            if (DEBUG) {
                stopWatch.lap("Finished building the name prefix table");
            }
        } finally {
            nameCursor.close();
        }
    }
    /**
     * Creates index on contact_id for fast JOIN operation.
     */
    db.execSQL("CREATE INDEX IF NOT EXISTS smartdial_contact_id_index ON " + Tables.SMARTDIAL_TABLE + " (" + SmartDialDbColumns.CONTACT_ID + ");");
    /**
     * Creates index on last_smartdial_update_time for fast SELECT operation.
     */
    db.execSQL("CREATE INDEX IF NOT EXISTS smartdial_last_update_index ON " + Tables.SMARTDIAL_TABLE + " (" + SmartDialDbColumns.LAST_SMARTDIAL_UPDATE_TIME + ");");
    /**
     * Creates index on sorting fields for fast sort operation.
     */
    db.execSQL("CREATE INDEX IF NOT EXISTS smartdial_sort_index ON " + Tables.SMARTDIAL_TABLE + " (" + SmartDialDbColumns.STARRED + ", " + SmartDialDbColumns.IS_SUPER_PRIMARY + ", " + SmartDialDbColumns.LAST_TIME_USED + ", " + SmartDialDbColumns.TIMES_USED + ", " + SmartDialDbColumns.IN_VISIBLE_GROUP + ", " + SmartDialDbColumns.DISPLAY_NAME_PRIMARY + ", " + SmartDialDbColumns.CONTACT_ID + ", " + SmartDialDbColumns.IS_PRIMARY + ");");
    /**
     * Creates index on prefix for fast SELECT operation.
     */
    db.execSQL("CREATE INDEX IF NOT EXISTS nameprefix_index ON " + Tables.PREFIX_TABLE + " (" + PrefixColumns.PREFIX + ");");
    /**
     * Creates index on contact_id for fast JOIN operation.
     */
    db.execSQL("CREATE INDEX IF NOT EXISTS nameprefix_contact_id_index ON " + Tables.PREFIX_TABLE + " (" + PrefixColumns.CONTACT_ID + ");");
    if (DEBUG) {
        stopWatch.lap(TAG + "Finished recreating index");
    }
    /**
     * Updates the database index statistics.
     */
    db.execSQL("ANALYZE " + Tables.SMARTDIAL_TABLE);
    db.execSQL("ANALYZE " + Tables.PREFIX_TABLE);
    db.execSQL("ANALYZE smartdial_contact_id_index");
    db.execSQL("ANALYZE smartdial_last_update_index");
    db.execSQL("ANALYZE nameprefix_index");
    db.execSQL("ANALYZE nameprefix_contact_id_index");
    if (DEBUG) {
        stopWatch.stopAndLog(TAG + "Finished updating index stats", 0);
    }
    final SharedPreferences.Editor editor = databaseLastUpdateSharedPref.edit();
    editor.putLong(LAST_UPDATED_MILLIS, currentMillis);
    editor.apply();
    LogUtil.i("DialerDatabaseHelper.updateSmartDialDatabase", "broadcasting smart dial update");
    // Notify content observers that smart dial database has been updated.
    Intent intent = new Intent(ACTION_SMART_DIAL_UPDATED);
    intent.setPackage(context.getPackageName());
    context.sendBroadcast(intent);
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SharedPreferences(android.content.SharedPreferences) Intent(android.content.Intent) Cursor(android.database.Cursor) StopWatch(com.android.contacts.common.util.StopWatch) WorkerThread(android.support.annotation.WorkerThread)

Example 8 with StopWatch

use of com.android.contacts.common.util.StopWatch in project android_packages_apps_Dialer by MoKee.

the class DialpadFragment method onResume.

@Override
public void onResume() {
    LogUtil.enterBlock("DialpadFragment.onResume");
    Trace.beginSection(TAG + " onResume");
    super.onResume();
    Resources res = getResources();
    int iconId = R.drawable.quantum_ic_call_vd_theme_24;
    if (MotorolaUtils.isWifiCallingAvailable(getContext())) {
        iconId = R.drawable.ic_wifi_calling;
    }
    floatingActionButtonController.changeIcon(getContext(), iconId, res.getString(R.string.description_dial_button));
    dialpadQueryListener = FragmentUtils.getParentUnsafe(this, OnDialpadQueryChangedListener.class);
    final StopWatch stopWatch = StopWatch.start("Dialpad.onResume");
    // Query the last dialed number. Do it first because hitting
    // the DB is 'slow'. This call is asynchronous.
    queryLastOutgoingCall();
    stopWatch.lap("qloc");
    final ContentResolver contentResolver = getActivity().getContentResolver();
    // retrieve the DTMF tone play back setting.
    dTMFToneEnabled = Settings.System.getInt(contentResolver, Settings.System.DTMF_TONE_WHEN_DIALING, 1) == 1;
    stopWatch.lap("dtwd");
    stopWatch.lap("hptc");
    pressedDialpadKeys.clear();
    configureScreenFromIntent(getActivity().getIntent());
    stopWatch.lap("fdin");
    if (!isPhoneInUse()) {
        LogUtil.i("DialpadFragment.onResume", "phone not in use");
        // A sanity-check: the "dialpad chooser" UI should not be visible if the phone is idle.
        showDialpadChooser(false);
    }
    stopWatch.lap("hnt");
    updateDeleteButtonEnabledState();
    stopWatch.lap("bes");
    stopWatch.stopAndLog(TAG, 50);
    // Populate the overflow menu in onResume instead of onCreate, so that if the SMS activity
    // is disabled while Dialer is paused, the "Send a text message" option can be correctly
    // removed when resumed.
    overflowMenuButton = dialpadView.getOverflowMenuButton();
    overflowPopupMenu = buildOptionsMenu(overflowMenuButton);
    overflowMenuButton.setOnTouchListener(overflowPopupMenu.getDragToOpenListener());
    overflowMenuButton.setOnClickListener(this);
    overflowMenuButton.setVisibility(isDigitsEmpty() ? View.INVISIBLE : View.VISIBLE);
    if (firstLaunch) {
        // The onHiddenChanged callback does not get called the first time the fragment is
        // attached, so call it ourselves here.
        onHiddenChanged(false);
    }
    firstLaunch = false;
    Trace.endSection();
}
Also used : Resources(android.content.res.Resources) StopWatch(com.android.contacts.common.util.StopWatch) ContentResolver(android.content.ContentResolver)

Example 9 with StopWatch

use of com.android.contacts.common.util.StopWatch in project android_packages_apps_Dialer by MoKee.

the class DialerDatabaseHelper method getLooseMatches.

/**
 * Returns a list of candidate contacts where the query is a prefix of the dialpad index of the
 * contact's name or phone number.
 *
 * @param query The prefix of a contact's dialpad index.
 * @return A list of top candidate contacts that will be suggested to user to match their input.
 */
@WorkerThread
public synchronized ArrayList<ContactNumber> getLooseMatches(String query, SmartDialNameMatcher nameMatcher) {
    if (query.length() == 0) {
        return Lists.newArrayList();
    }
    final SQLiteDatabase db = getReadableDatabase();
    /**
     * Uses SQL query wildcard '%' to represent prefix matching.
     */
    StringBuilder looseQuery = new StringBuilder(query);
    for (int i = 0; i < looseQuery.toString().length(); ) {
        looseQuery.insert(i, "%");
        i = i + 2;
    }
    looseQuery.append("%");
    final ArrayList<ContactNumber> result = new ArrayList<>();
    final StopWatch stopWatch = DEBUG ? StopWatch.start(":Name Prefix query") : null;
    final String currentTimeStamp = Long.toString(System.currentTimeMillis());
    /**
     * Queries the database to find contacts that have an index matching the query prefix.
     */
    final Cursor cursor = db.rawQuery("SELECT " + SmartDialDbColumns.DATA_ID + ", " + SmartDialDbColumns.DISPLAY_NAME_PRIMARY + ", " + SmartDialDbColumns.PHOTO_ID + ", " + SmartDialDbColumns.NUMBER + ", " + SmartDialDbColumns.CONTACT_ID + ", " + SmartDialDbColumns.LOOKUP_KEY + ", " + SmartDialDbColumns.CARRIER_PRESENCE + " FROM " + Tables.SMARTDIAL_TABLE + " WHERE " + SmartDialDbColumns.CONTACT_ID + " IN " + " (SELECT " + PrefixColumns.CONTACT_ID + " FROM " + Tables.PREFIX_TABLE + " WHERE " + Tables.PREFIX_TABLE + "." + PrefixColumns.PREFIX + " LIKE '" + looseQuery + "')" + " ORDER BY " + SmartDialSortingOrder.SORT_ORDER, new String[] { currentTimeStamp });
    if (cursor == null) {
        return result;
    }
    try {
        if (DEBUG) {
            stopWatch.lap("Prefix query completed");
        }
        /**
         * Gets the column ID from the cursor.
         */
        final int columnDataId = 0;
        final int columnDisplayNamePrimary = 1;
        final int columnPhotoId = 2;
        final int columnNumber = 3;
        final int columnId = 4;
        final int columnLookupKey = 5;
        final int columnCarrierPresence = 6;
        if (DEBUG) {
            stopWatch.lap("Found column IDs");
        }
        final Set<ContactMatch> duplicates = new HashSet<>();
        int counter = 0;
        if (DEBUG) {
            stopWatch.lap("Moved cursor to start");
        }
        /**
         * Iterates the cursor to find top contact suggestions without duplication.
         */
        while ((cursor.moveToNext()) && (counter < MAX_ENTRIES)) {
            final long dataID = cursor.getLong(columnDataId);
            final String displayName = cursor.getString(columnDisplayNamePrimary);
            final String phoneNumber = cursor.getString(columnNumber);
            final long id = cursor.getLong(columnId);
            final long photoId = cursor.getLong(columnPhotoId);
            final String lookupKey = cursor.getString(columnLookupKey);
            final int carrierPresence = cursor.getInt(columnCarrierPresence);
            /**
             * If a contact already exists and another phone number of the contact is being processed,
             * skip the second instance.
             */
            final ContactMatch contactMatch = new ContactMatch(lookupKey, id);
            if (duplicates.contains(contactMatch)) {
                continue;
            }
            /**
             * If the contact has either the name or number that matches the query, add to the result.
             */
            final boolean nameMatches = nameMatcher.matches(context, displayName);
            final boolean numberMatches = (nameMatcher.matchesNumber(context, phoneNumber, query) != null);
            if (nameMatches || numberMatches) {
                /**
                 * If a contact has not been added, add it to the result and the hash set.
                 */
                duplicates.add(contactMatch);
                result.add(new ContactNumber(id, dataID, displayName, phoneNumber, lookupKey, photoId, carrierPresence));
                counter++;
                if (DEBUG) {
                    stopWatch.lap("Added one result: Name: " + displayName);
                }
            }
        }
        if (DEBUG) {
            stopWatch.stopAndLog(TAG + "Finished loading cursor", 0);
        }
    } finally {
        cursor.close();
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) StopWatch(com.android.contacts.common.util.StopWatch) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) HashSet(java.util.HashSet) WorkerThread(android.support.annotation.WorkerThread)

Example 10 with StopWatch

use of com.android.contacts.common.util.StopWatch in project android_packages_apps_Dialer by LineageOS.

the class DialpadFragment method onResume.

@Override
public void onResume() {
    LogUtil.enterBlock("DialpadFragment.onResume");
    Trace.beginSection(TAG + " onResume");
    super.onResume();
    dialpadQueryListener = FragmentUtils.getParentUnsafe(this, OnDialpadQueryChangedListener.class);
    final StopWatch stopWatch = StopWatch.start("Dialpad.onResume");
    // Query the last dialed number. Do it first because hitting
    // the DB is 'slow'. This call is asynchronous.
    queryLastOutgoingCall();
    stopWatch.lap("qloc");
    final ContentResolver contentResolver = getActivity().getContentResolver();
    // retrieve the DTMF tone play back setting.
    dTMFToneEnabled = Settings.System.getInt(contentResolver, Settings.System.DTMF_TONE_WHEN_DIALING, 1) == 1;
    stopWatch.lap("dtwd");
    stopWatch.lap("hptc");
    pressedDialpadKeys.clear();
    configureScreenFromIntent(getActivity().getIntent());
    stopWatch.lap("fdin");
    if (!isPhoneInUse()) {
        LogUtil.i("DialpadFragment.onResume", "phone not in use");
        // A sanity-check: the "dialpad chooser" UI should not be visible if the phone is idle.
        showDialpadChooser(false);
    }
    stopWatch.lap("hnt");
    updateDeleteButtonEnabledState();
    stopWatch.lap("bes");
    stopWatch.stopAndLog(TAG, 50);
    // Populate the overflow menu in onResume instead of onCreate, so that if the SMS activity
    // is disabled while Dialer is paused, the "Send a text message" option can be correctly
    // removed when resumed.
    overflowMenuButton = dialpadView.getOverflowMenuButton();
    overflowPopupMenu = buildOptionsMenu(overflowMenuButton);
    overflowMenuButton.setOnTouchListener(overflowPopupMenu.getDragToOpenListener());
    overflowMenuButton.setOnClickListener(this);
    overflowMenuButton.setVisibility(isDigitsEmpty() ? View.INVISIBLE : View.VISIBLE);
    updateDialpadHint();
    if (firstLaunch) {
        // The onHiddenChanged callback does not get called the first time the fragment is
        // attached, so call it ourselves here.
        onHiddenChanged(false);
    }
    firstLaunch = false;
    Trace.endSection();
}
Also used : StopWatch(com.android.contacts.common.util.StopWatch) ContentResolver(android.content.ContentResolver)

Aggregations

StopWatch (com.android.contacts.common.util.StopWatch)10 Cursor (android.database.Cursor)6 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)6 WorkerThread (android.support.annotation.WorkerThread)5 ContentResolver (android.content.ContentResolver)4 Intent (android.content.Intent)4 SharedPreferences (android.content.SharedPreferences)4 Resources (android.content.res.Resources)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 IntentFilter (android.content.IntentFilter)1 DialtactsActivity (com.android.dialer.DialtactsActivity)1 DialtactsActivity (com.android.dialer.app.DialtactsActivity)1