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

Commit 158a12fe authored by Daisuke Miyakawa's avatar Daisuke Miyakawa Committed by Danny Baumann
Browse files

Do not allow intents to initiate special char sequence handling.

This is a squash of the following jellybean commits backported to GB:

- Prevent Intent from initiating special-char handling
  Ic5b042f620b10931fedcaf12bb58be2405bf7390

- Remember the flag suppressing special char handling
  Ie62a448675ac558ecdeea43da01082712edee35a

- Follow-up to Ie62a4486
  Idea7ae599e3a217ad656a304fbae26746d9f3284
parent a2c05eb0
Loading
Loading
Loading
Loading
+28 −1
Original line number Diff line number Diff line
@@ -211,6 +211,15 @@ public class TwelveKeyDialer extends Activity implements View.OnClickListener,
            }
        };

    /**
     * This field is set to true while processing an incoming DIAL intent, in order to make sure
     * that SpecialCharSequenceMgr actions can be triggered by user input but *not* by a
     * tel: URI passed by some other app. It will be set to false when all digits are cleared.
     */
    private boolean mDigitsFilledByIntent;

    private static final String PREF_DIGITS_FILLED_BY_INTENT = "pref_digits_filled_by_intent";

    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        // Do nothing
    }
@@ -222,7 +231,8 @@ public class TwelveKeyDialer extends Activity implements View.OnClickListener,
    }

    public void afterTextChanged(Editable input) {
        if (SpecialCharSequenceMgr.handleChars(this, input.toString(), mDigits)) {
        if (!mDigitsFilledByIntent &&
                SpecialCharSequenceMgr.handleChars(this, input.toString(), mDigits)) {
            // A special sequence was entered, clear the digits
            mDigits.getText().clear();
        }
@@ -230,6 +240,7 @@ public class TwelveKeyDialer extends Activity implements View.OnClickListener,
        if (!isDigitsEmpty()) {
            mDigits.setBackgroundDrawable(mDigitsBackground);
        } else {
            mDigitsFilledByIntent = false;
            mDigits.setCursorVisible(false);
            mDigits.setBackgroundDrawable(mDigitsEmptyBackground);
        }
@@ -316,6 +327,9 @@ public class TwelveKeyDialer extends Activity implements View.OnClickListener,
        //Wysi: Should remove this since it's also in onResume. To be tested.
        //updateDialer();

        if (icicle != null) {
            mDigitsFilledByIntent = icicle.getBoolean(PREF_DIGITS_FILLED_BY_INTENT);
        }
        if (!resolveIntent() && icicle != null) {
            super.onRestoreInstanceState(icicle);
        }
@@ -368,6 +382,8 @@ public class TwelveKeyDialer extends Activity implements View.OnClickListener,
                if ("tel".equals(uri.getScheme())) {
                    // Put the requested number into the input area
                    String data = uri.getSchemeSpecificPart();
                    // Remember it is filled via Intent.
                    mDigitsFilledByIntent = true;
                    setFormattedDigits(data);
                } else {
                    String type = intent.getType();
@@ -378,6 +394,8 @@ public class TwelveKeyDialer extends Activity implements View.OnClickListener,
                                new String[] {PhonesColumns.NUMBER}, null, null, null);
                        if (c != null) {
                            if (c.moveToFirst()) {
                                // Remember it is filled via Intent.
                                mDigitsFilledByIntent = true;
                                // Put the number into the input area
                                setFormattedDigits(c.getString(0));
                            }
@@ -419,6 +437,9 @@ public class TwelveKeyDialer extends Activity implements View.OnClickListener,
        return ignoreState;
    }

    /**
     * Sets formatted digits to digits field.
     */
    protected void setFormattedDigits(String data) {
        // strip the non-dialable numbers out of the data string.
        String dialString = PhoneNumberUtils.extractNetworkPortion(data);
@@ -750,6 +771,12 @@ public class TwelveKeyDialer extends Activity implements View.OnClickListener,
        mLastNumberDialed = EMPTY_NUMBER;  // Since we are going to query again, free stale number.
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putBoolean(PREF_DIGITS_FILLED_BY_INTENT, mDigitsFilledByIntent);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        m2SecPauseMenuItem = menu.add(0, MENU_2S_PAUSE, 0, R.string.add_2sec_pause)