Search in sources :

Example 1 with OnCheckBlockedListener

use of com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnCheckBlockedListener in project android_packages_apps_Dialer by MoKee.

the class BlockedListSearchFragment method blockNumber.

private void blockNumber(final String number) {
    final String countryIso = GeoUtil.getCurrentCountryIso(getContext());
    final OnCheckBlockedListener onCheckListener = new OnCheckBlockedListener() {

        @Override
        public void onCheckComplete(Integer id) {
            if (id == null) {
                BlockNumberDialogFragment.show(id, number, countryIso, PhoneNumberUtils.formatNumber(number, countryIso), R.id.blocked_numbers_activity_container, getFragmentManager(), BlockedListSearchFragment.this);
            } else {
                Toast.makeText(getContext(), ContactDisplayUtils.getTtsSpannedPhoneNumber(getResources(), R.string.alreadyBlocked, number), Toast.LENGTH_SHORT).show();
            }
        }
    };
    final boolean success = mFilteredNumberAsyncQueryHandler.isBlockedNumber(onCheckListener, number, countryIso);
    if (!success) {
        Toast.makeText(getContext(), ContactDisplayUtils.getTtsSpannedPhoneNumber(getResources(), R.string.invalidNumber, number), Toast.LENGTH_SHORT).show();
    }
}
Also used : OnCheckBlockedListener(com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnCheckBlockedListener)

Example 2 with OnCheckBlockedListener

use of com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnCheckBlockedListener in project android_packages_apps_Dialer by MoKee.

the class FilteredNumberCompat method newMigrationListener.

private static BlockedNumbersMigrator.Listener newMigrationListener(final ContentResolver contentResolver, final String number, final String countryIso, final String displayNumber, final Integer parentViewId, final FragmentManager fragmentManager, @Nullable final Callback callback) {
    return new BlockedNumbersMigrator.Listener() {

        @Override
        public void onComplete() {
            Log.i(TAG, "showBlockNumberDialogFlow - listener showing block number dialog");
            if (!hasMigratedToNewBlocking()) {
                Log.i(TAG, "showBlockNumberDialogFlow - migration failed");
                return;
            }
            /*
                 * Edge case to cover here: if the user initiated the migration workflow with a
                 * number that's already blocked in the framework, don't show the block number
                 * dialog. Doing so would allow them to block the same number twice, causing a
                 * crash.
                 */
            new FilteredNumberAsyncQueryHandler(contentResolver).isBlockedNumber(new OnCheckBlockedListener() {

                @Override
                public void onCheckComplete(Integer id) {
                    if (id != null) {
                        Log.i(TAG, "showBlockNumberDialogFlow - number already blocked");
                        return;
                    }
                    Log.i(TAG, "showBlockNumberDialogFlow - need to block number");
                    BlockNumberDialogFragment.show(null, number, countryIso, displayNumber, parentViewId, fragmentManager, callback);
                }
            }, number, countryIso);
        }
    };
}
Also used : OnCheckBlockedListener(com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnCheckBlockedListener) FilteredNumberAsyncQueryHandler(com.android.dialer.database.FilteredNumberAsyncQueryHandler) OnCheckBlockedListener(com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnCheckBlockedListener)

Example 3 with OnCheckBlockedListener

use of com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnCheckBlockedListener in project android_packages_apps_Dialer by MoKee.

the class InCallPresenter method maybeBlockCall.

/**
 * Checks whether a call should be blocked, and blocks it if so. Otherwise, it adds the call
 * to the CallList so it can proceed as normal. There is a timeout, so if the function for
 * checking whether a function is blocked does not return in a reasonable time, we proceed
 * with adding the call anyways.
 */
private void maybeBlockCall(final android.telecom.Call call) {
    final String countryIso = GeoUtil.getCurrentCountryIso(mContext);
    final String number = TelecomCallUtil.getNumber(call);
    final long timeAdded = System.currentTimeMillis();
    // Though AtomicBoolean's can be scary, don't fear, as in this case it is only used on the
    // main UI thread. It is needed so we can change its value within different scopes, since
    // that cannot be done with a final boolean.
    final AtomicBoolean hasTimedOut = new AtomicBoolean(false);
    final Handler handler = new Handler();
    // Proceed if the query is slow; the call may still be blocked after the query returns.
    final Runnable runnable = new Runnable() {

        public void run() {
            hasTimedOut.set(true);
            mCallList.onCallAdded(call);
        }
    };
    handler.postDelayed(runnable, BLOCK_QUERY_TIMEOUT_MS);
    OnCheckBlockedListener onCheckBlockedListener = new OnCheckBlockedListener() {

        @Override
        public void onCheckComplete(final Integer id) {
            if (!hasTimedOut.get()) {
                handler.removeCallbacks(runnable);
            }
            if (id == null) {
                if (!hasTimedOut.get()) {
                    mCallList.onCallAdded(call);
                }
            } else {
                Log.i(this, "Rejecting incoming call from blocked number");
                call.reject(false, null);
                Logger.logInteraction(InteractionEvent.CALL_BLOCKED);
                mFilteredQueryHandler.incrementFilteredCount(id);
                // Register observer to update the call log.
                // BlockedNumberContentObserver will unregister after successful log or timeout.
                BlockedNumberContentObserver contentObserver = new BlockedNumberContentObserver(new Handler(), number, timeAdded);
                contentObserver.register();
            }
        }
    };
    final boolean success = mFilteredQueryHandler.isBlockedNumber(onCheckBlockedListener, number, countryIso);
    if (!success) {
        Log.d(this, "checkForBlockedCall: invalid number, skipping block checking");
        if (!hasTimedOut.get()) {
            handler.removeCallbacks(runnable);
            mCallList.onCallAdded(call);
        }
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) OnCheckBlockedListener(com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnCheckBlockedListener) Handler(android.os.Handler) FilteredNumberAsyncQueryHandler(com.android.dialer.database.FilteredNumberAsyncQueryHandler)

Aggregations

OnCheckBlockedListener (com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnCheckBlockedListener)3 FilteredNumberAsyncQueryHandler (com.android.dialer.database.FilteredNumberAsyncQueryHandler)2 Handler (android.os.Handler)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1