Search in sources :

Example 1 with FilteredNumberAsyncQueryHandler

use of com.android.dialer.database.FilteredNumberAsyncQueryHandler 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 2 with FilteredNumberAsyncQueryHandler

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

the class CallDetailActivity method onCreate.

@Override
protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    mContext = this;
    mResources = getResources();
    mContactInfoHelper = new ContactInfoHelper(this, GeoUtil.getCurrentCountryIso(this));
    mContactsPreferences = new ContactsPreferences(mContext);
    mCallTypeHelper = new CallTypeHelper(getResources());
    mFilteredNumberAsyncQueryHandler = new FilteredNumberAsyncQueryHandler(getContentResolver());
    mVoicemailUri = getIntent().getParcelableExtra(EXTRA_VOICEMAIL_URI);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    setContentView(R.layout.call_detail);
    mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
    mHistoryList = (ListView) findViewById(R.id.history);
    mHistoryList.addHeaderView(mInflater.inflate(R.layout.call_detail_header, null));
    mHistoryList.addFooterView(mInflater.inflate(R.layout.call_detail_footer, null), null, false);
    mQuickContactBadge = (QuickContactBadge) findViewById(R.id.quick_contact_photo);
    mQuickContactBadge.setOverlay(null);
    if (CompatUtils.hasPrioritizedMimeType()) {
        mQuickContactBadge.setPrioritizedMimeType(Phone.CONTENT_ITEM_TYPE);
    }
    mCallerName = (TextView) findViewById(R.id.caller_name);
    mCallerNumber = (TextView) findViewById(R.id.caller_number);
    mAccountLabel = (TextView) findViewById(R.id.phone_account_label);
    mContactPhotoManager = ContactPhotoManager.getInstance(this);
    mCallButton = findViewById(R.id.call_back_button);
    mCallButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (TextUtils.isEmpty(mNumber)) {
                return;
            }
            Intent dialIntent = new CallIntentBuilder(getDialableNumber()).setCallInitiationType(LogState.INITIATION_CALL_DETAILS).build();
            if (DialerUtils.isConferenceURICallLog(mNumber, mPostDialDigits)) {
                dialIntent.putExtra("org.codeaurora.extra.DIAL_CONFERENCE_URI", true);
            }
            mContext.startActivity(dialIntent);
        }
    });
    mBlockNumberActionItem = (TextView) findViewById(R.id.call_detail_action_block);
    updateBlockActionItemVisibility(View.VISIBLE);
    mBlockNumberActionItem.setOnClickListener(this);
    mEditBeforeCallActionItem = findViewById(R.id.call_detail_action_edit_before_call);
    mEditBeforeCallActionItem.setOnClickListener(this);
    mReportActionItem = findViewById(R.id.call_detail_action_report);
    mReportActionItem.setOnClickListener(this);
    mCopyNumberActionItem = findViewById(R.id.call_detail_action_copy);
    mCopyNumberActionItem.setOnClickListener(this);
    if (getIntent().getBooleanExtra(EXTRA_FROM_NOTIFICATION, false)) {
        closeSystemDialogs();
    }
}
Also used : CallTypeHelper(com.android.dialer.calllog.CallTypeHelper) ContactsPreferences(com.android.contacts.common.preference.ContactsPreferences) ContactInfoHelper(com.android.dialer.calllog.ContactInfoHelper) CallIntentBuilder(com.android.dialer.util.IntentUtil.CallIntentBuilder) FilteredNumberAsyncQueryHandler(com.android.dialer.database.FilteredNumberAsyncQueryHandler) Intent(android.content.Intent) View(android.view.View) TextView(android.widget.TextView) ListView(android.widget.ListView)

Example 3 with FilteredNumberAsyncQueryHandler

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

the class BlockNumberDialogFragment method onCreateDialog.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    super.onCreateDialog(savedInstanceState);
    final boolean isBlocked = getArguments().containsKey(ARG_BLOCK_ID);
    mNumber = getArguments().getString(ARG_NUMBER);
    mDisplayNumber = getArguments().getString(ARG_DISPLAY_NUMBER);
    mCountryIso = getArguments().getString(ARG_COUNTRY_ISO);
    if (TextUtils.isEmpty(mDisplayNumber)) {
        mDisplayNumber = mNumber;
    }
    mHandler = new FilteredNumberAsyncQueryHandler(getContext().getContentResolver());
    mVoicemailEnabledChecker = new VisualVoicemailEnabledChecker(getActivity(), null);
    /**
     * Choose not to update VoicemailEnabledChecker, as checks should already been done in
     * all current use cases.
     */
    mParentView = getActivity().findViewById(getArguments().getInt(ARG_PARENT_VIEW_ID));
    CharSequence title;
    String okText;
    String message;
    if (isBlocked) {
        title = null;
        okText = getString(R.string.unblock_number_ok);
        message = ContactDisplayUtils.getTtsSpannedPhoneNumber(getResources(), R.string.unblock_number_confirmation_title, mDisplayNumber).toString();
    } else {
        title = ContactDisplayUtils.getTtsSpannedPhoneNumber(getResources(), R.string.block_number_confirmation_title, mDisplayNumber);
        okText = getString(R.string.block_number_ok);
        if (FilteredNumberCompat.useNewFiltering()) {
            message = getString(R.string.block_number_confirmation_message_new_filtering);
        } else if (mVoicemailEnabledChecker.isVisualVoicemailEnabled()) {
            message = getString(R.string.block_number_confirmation_message_vvm);
        } else {
            message = getString(R.string.block_number_confirmation_message_no_vvm);
        }
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setTitle(title).setMessage(message).setPositiveButton(okText, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int id) {
            if (isBlocked) {
                unblockNumber();
            } else {
                blockNumber();
            }
        }
    }).setNegativeButton(android.R.string.cancel, null);
    return builder.create();
}
Also used : AlertDialog(android.app.AlertDialog) VisualVoicemailEnabledChecker(com.android.dialer.voicemail.VisualVoicemailEnabledChecker) DialogInterface(android.content.DialogInterface) FilteredNumberAsyncQueryHandler(com.android.dialer.database.FilteredNumberAsyncQueryHandler)

Example 4 with FilteredNumberAsyncQueryHandler

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

the class FilteredNumbersUtil method maybeNotifyCallBlockingDisabled.

public static void maybeNotifyCallBlockingDisabled(final Context context) {
    // The Dialer is not responsible for this notification after migrating
    if (FilteredNumberCompat.useNewFiltering()) {
        return;
    }
    // Skip if the user has already received a notification for the most recent emergency call.
    if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(NOTIFIED_CALL_BLOCKING_DISABLED_BY_EMERGENCY_CALL_PREF_KEY, false)) {
        return;
    }
    // If the user has blocked numbers, notify that call blocking is temporarily disabled.
    FilteredNumberAsyncQueryHandler queryHandler = new FilteredNumberAsyncQueryHandler(context.getContentResolver());
    queryHandler.hasBlockedNumbers(new OnHasBlockedNumbersListener() {

        @Override
        public void onHasBlockedNumbers(boolean hasBlockedNumbers) {
            if (context == null || !hasBlockedNumbers) {
                return;
            }
            NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            Notification.Builder builder = new Notification.Builder(context).setSmallIcon(R.drawable.ic_block_24dp).setContentTitle(context.getString(R.string.call_blocking_disabled_notification_title)).setContentText(context.getString(R.string.call_blocking_disabled_notification_text)).setAutoCancel(true);
            final Intent contentIntent = new Intent(context, BlockedNumbersSettingsActivity.class);
            builder.setContentIntent(PendingIntent.getActivity(context, 0, contentIntent, PendingIntent.FLAG_UPDATE_CURRENT));
            notificationManager.notify(CALL_BLOCKING_NOTIFICATION_TAG, CALL_BLOCKING_DISABLED_BY_EMERGENCY_CALL_NOTIFICATION_ID, builder.build());
            // Record that the user has been notified for this emergency call.
            PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean(NOTIFIED_CALL_BLOCKING_DISABLED_BY_EMERGENCY_CALL_PREF_KEY, true).apply();
        }
    });
}
Also used : NotificationManager(android.app.NotificationManager) OnHasBlockedNumbersListener(com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnHasBlockedNumbersListener) FilteredNumberAsyncQueryHandler(com.android.dialer.database.FilteredNumberAsyncQueryHandler) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification)

Example 5 with FilteredNumberAsyncQueryHandler

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

the class FilteredNumbersUtil method importSendToVoicemailContacts.

/**
 * Blocks all the phone numbers of any contacts marked as SEND_TO_VOICEMAIL, then clears the
 * SEND_TO_VOICEMAIL flag on those contacts.
 */
public static void importSendToVoicemailContacts(final Context context, final ImportSendToVoicemailContactsListener listener) {
    Logger.logInteraction(InteractionEvent.IMPORT_SEND_TO_VOICEMAIL);
    final FilteredNumberAsyncQueryHandler mFilteredNumberAsyncQueryHandler = new FilteredNumberAsyncQueryHandler(context.getContentResolver());
    final AsyncTask<Object, Void, Boolean> task = new AsyncTask<Object, Void, Boolean>() {

        @Override
        public Boolean doInBackground(Object[] params) {
            if (context == null) {
                return false;
            }
            // Get the phone number of contacts marked as SEND_TO_VOICEMAIL.
            final Cursor phoneCursor = context.getContentResolver().query(Phone.CONTENT_URI, PhoneQuery.PROJECTION, PhoneQuery.SELECT_SEND_TO_VOICEMAIL_TRUE, null, null);
            if (phoneCursor == null) {
                return false;
            }
            try {
                while (phoneCursor.moveToNext()) {
                    final String normalizedNumber = phoneCursor.getString(PhoneQuery.NORMALIZED_NUMBER_COLUMN_INDEX);
                    final String number = phoneCursor.getString(PhoneQuery.NUMBER_COLUMN_INDEX);
                    if (normalizedNumber != null) {
                        // Block the phone number of the contact.
                        mFilteredNumberAsyncQueryHandler.blockNumber(null, normalizedNumber, number, null);
                    }
                }
            } finally {
                phoneCursor.close();
            }
            // Clear SEND_TO_VOICEMAIL on all contacts. The setting has been imported to Dialer.
            ContentValues newValues = new ContentValues();
            newValues.put(Contacts.SEND_TO_VOICEMAIL, 0);
            context.getContentResolver().update(Contacts.CONTENT_URI, newValues, ContactsQuery.SELECT_SEND_TO_VOICEMAIL_TRUE, null);
            return true;
        }

        @Override
        public void onPostExecute(Boolean success) {
            if (success) {
                if (listener != null) {
                    listener.onImportComplete();
                }
            } else if (context != null) {
                String toastStr = context.getString(R.string.send_to_voicemail_import_failed);
                Toast.makeText(context, toastStr, Toast.LENGTH_SHORT).show();
            }
        }
    };
    task.execute();
}
Also used : ContentValues(android.content.ContentValues) FilteredNumberAsyncQueryHandler(com.android.dialer.database.FilteredNumberAsyncQueryHandler) AsyncTask(android.os.AsyncTask) Cursor(android.database.Cursor)

Aggregations

FilteredNumberAsyncQueryHandler (com.android.dialer.database.FilteredNumberAsyncQueryHandler)9 Intent (android.content.Intent)3 View (android.view.View)2 TextView (android.widget.TextView)2 ContactInfoHelper (com.android.dialer.calllog.ContactInfoHelper)2 AlertDialog (android.app.AlertDialog)1 Notification (android.app.Notification)1 NotificationManager (android.app.NotificationManager)1 PendingIntent (android.app.PendingIntent)1 ContentValues (android.content.ContentValues)1 DialogInterface (android.content.DialogInterface)1 Cursor (android.database.Cursor)1 AsyncTask (android.os.AsyncTask)1 ListView (android.widget.ListView)1 ContactsPreferences (com.android.contacts.common.preference.ContactsPreferences)1 CallTypeHelper (com.android.dialer.calllog.CallTypeHelper)1 CallTypeIconsView (com.android.dialer.calllog.CallTypeIconsView)1 OnCheckBlockedListener (com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnCheckBlockedListener)1 OnHasBlockedNumbersListener (com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnHasBlockedNumbersListener)1 BlockedNumbersAutoMigrator (com.android.dialer.filterednumber.BlockedNumbersAutoMigrator)1