Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d42fc1db authored by Adnan's avatar Adnan Committed by Adnan Begovic
Browse files

Settings: Alert user when they attempt to add an invalid number to BL.

  - BlacklistProvider will reject numbers that aren't valid, silently. So instead of
  resuming to a blank screen, we should alert the user that the number they attempted to
  add is invalid by utilizing BlacklistUtils#addOrUpdate method.

Change-Id: I1ca32427baad41c1c9379e18046e6ca7937b6d32
parent 6bb06dab
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -702,6 +702,7 @@ two in order to insert additional control points. \'Remove\' deletes the selecte
    <string name="blacklist_regex_summary">Use . as a wildcard and * for repetition. E.g. 123.* blocks numbers starting with 123 and .*123.* blocks numbers containing 123</string>
    <string name="blacklist_policy_block_calls">Block incoming calls</string>
    <string name="blacklist_policy_block_messages">Block incoming messages</string>
    <string name="blacklist_bad_number_add">Unable to add invalid number to blacklist</string>

    <!-- Blacklist management -->
    <string name="add_blacklist_number">Add number</string>
+13 −16
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageButton;

import android.widget.Toast;
import com.android.internal.telephony.util.BlacklistUtils;
import com.android.settings.R;

@@ -196,24 +197,20 @@ public class EntryEditDialogFragment extends DialogFragment
    }

    private void updateBlacklistEntry() {
        ContentValues cv = new ContentValues();
        String number = mEditText.getText().toString();

        cv.put(Blacklist.NUMBER, number);
        cv.put(Blacklist.PHONE_MODE, mBlockCalls.isChecked() ? 1 : 0);
        cv.put(Blacklist.MESSAGE_MODE, mBlockMessages.isChecked() ? 1 : 0);

        long id = getEntryId();
        Uri uri;

        if (id < 0) {
            uri = Blacklist.CONTENT_FILTER_BYNUMBER_URI.buildUpon()
                    .appendPath(number)
                    .build();
        } else {
            uri = ContentUris.withAppendedId(Blacklist.CONTENT_URI, id);
        int flags = 0;
        if (mBlockCalls.isChecked()) {
            flags = flags | BlacklistUtils.BLOCK_CALLS;
        }
        if (mBlockMessages.isChecked()) {
            flags = flags | BlacklistUtils.BLOCK_MESSAGES;
        }
        // Since BlacklistProvider enforces validity for a number to be added
        // we should alert the user if and when it gets rejected
        if (!BlacklistUtils.addOrUpdate(getActivity(), number, flags, flags)) {
            Toast.makeText(getActivity(), getString(R.string.blacklist_bad_number_add),
                    Toast.LENGTH_LONG).show();
        }
        getActivity().getContentResolver().update(uri, cv, null, null);
    }

    private void updateOkButtonState() {