org.chromium.chrome.browser.autofill.PersonalDataManager Java Examples

The following examples show how to use org.chromium.chrome.browser.autofill.PersonalDataManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SyncCustomizationFragment.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void onStop() {
    super.onStop();

    mProfileSyncService.removeSyncStateChangedListener(this);
    // If this activity is closing, apply configuration changes and tell sync that
    // the user is done configuring sync.
    if (!getActivity().isChangingConfigurations()) {
        // Only save state if the switch and external state match. If a stop and clear comes
        // while the dialog is open, this will be false and settings won't be saved.
        if (mSyncSwitchPreference.isChecked()
                && AndroidSyncSettings.isSyncEnabled(getActivity())) {
            // Save the new data type state.
            configureSyncDataTypes();
            // Inform sync that the user has finished setting up sync at least once.
            mProfileSyncService.setFirstSetupComplete();
        }
        PersonalDataManager.setPaymentsIntegrationEnabled(mPaymentsIntegration.isChecked());
        // Setup is done. This was preventing sync from turning on even if it was enabled.
        // TODO(crbug/557784): This needs to be set only when we think the user is done with
        // setting up. This means: 1) If the user leaves the Sync Settings screen (via back)
        // or, 2) If the user leaves the screen by tapping on "Manage Synced Data"
        mProfileSyncService.setSetupInProgress(false);
    }
}
 
Example #2
Source File: AutofillPreferences.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.autofill_preferences);
    getActivity().setTitle(R.string.prefs_autofill);

    ChromeSwitchPreference autofillSwitch =
            (ChromeSwitchPreference) findPreference(PREF_AUTOFILL_SWITCH);
    autofillSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            PersonalDataManager.setAutofillEnabled((boolean) newValue);
            return true;
        }
    });

    setPreferenceCategoryIcons();
}
 
Example #3
Source File: AutofillPreferences.java    From delion with Apache License 2.0 6 votes vote down vote up
private void rebuildProfileList() {
    // Add an edit preference for each current Chrome profile.
    PreferenceGroup profileCategory = (PreferenceGroup) findPreference(PREF_AUTOFILL_PROFILES);
    profileCategory.removeAll();
    for (AutofillProfile profile : PersonalDataManager.getInstance().getProfilesForSettings()) {
        // Add an item on the current page...
        Preference pref = new Preference(getActivity());
        pref.setTitle(profile.getFullName());
        pref.setSummary(profile.getLabel());

        if (profile.getIsLocal()) {
            pref.setFragment(AutofillProfileEditor.class.getName());
        } else {
            pref.setWidgetLayoutResource(R.layout.autofill_server_data_label);
            pref.setFragment(AutofillServerProfilePreferences.class.getName());
        }

        Bundle args = pref.getExtras();
        args.putString(AUTOFILL_GUID, profile.getGUID());
        profileCategory.addPreference(pref);
    }
}
 
Example #4
Source File: AutofillPreferences.java    From delion with Apache License 2.0 6 votes vote down vote up
private void rebuildCreditCardList() {
    PreferenceGroup profileCategory =
            (PreferenceGroup) findPreference(PREF_AUTOFILL_CREDIT_CARDS);
    profileCategory.removeAll();
    for (CreditCard card : PersonalDataManager.getInstance().getCreditCardsForSettings()) {
        // Add an item on the current page...
        Preference pref = new Preference(getActivity());
        pref.setTitle(card.getObfuscatedNumber());
        pref.setSummary(card.getFormattedExpirationDate(getActivity()));

        if (card.getIsLocal()) {
            pref.setFragment(AutofillLocalCardEditor.class.getName());
        } else {
            pref.setFragment(AutofillServerCardEditor.class.getName());
            pref.setWidgetLayoutResource(R.layout.autofill_server_data_label);
        }

        Bundle args = pref.getExtras();
        args.putString(AUTOFILL_GUID, card.getGUID());
        profileCategory.addPreference(pref);
    }
}
 
Example #5
Source File: AutofillPaymentApp.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void getInstruments(JSONObject unusedDetails, final InstrumentsCallback callback) {
    PersonalDataManager pdm = PersonalDataManager.getInstance();
    List<CreditCard> cards = pdm.getCreditCardsToSuggest();
    final List<PaymentInstrument> instruments = new ArrayList<>(cards.size());

    for (int i = 0; i < cards.size(); i++) {
        CreditCard card = cards.get(i);
        AutofillProfile billingAddress = TextUtils.isEmpty(card.getBillingAddressId())
                ? null : pdm.getProfile(card.getBillingAddressId());
        instruments.add(new AutofillPaymentInstrument(mWebContents, card, billingAddress));
    }

    new Handler().post(new Runnable() {
        @Override
        public void run() {
            callback.onInstrumentsReady(AutofillPaymentApp.this, instruments);
        }
    });
}
 
Example #6
Source File: SyncCustomizationFragment.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void onStop() {
    super.onStop();

    mProfileSyncService.removeSyncStateChangedListener(this);
    // If this activity is closing, apply configuration changes and tell sync that
    // the user is done configuring sync.
    if (!getActivity().isChangingConfigurations()) {
        // Only save state if the switch and external state match. If a stop and clear comes
        // while the dialog is open, this will be false and settings won't be saved.
        if (mSyncSwitchPreference.isChecked()
                && AndroidSyncSettings.isSyncEnabled(getActivity())) {
            // Save the new data type state.
            configureSyncDataTypes();
            // Inform sync that the user has finished setting up sync at least once.
            mProfileSyncService.setFirstSetupComplete();
        }
        PersonalDataManager.setPaymentsIntegrationEnabled(mPaymentsIntegration.isChecked());
        // Setup is done. This was preventing sync from turning on even if it was enabled.
        // TODO(crbug/557784): This needs to be set only when we think the user is done with
        // setting up. This means: 1) If the user leaves the Sync Settings screen (via back)
        // or, 2) If the user leaves the screen by tapping on "Manage Synced Data"
        mProfileSyncService.setSetupInProgress(false);
    }
}
 
Example #7
Source File: AutofillPreferences.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.autofill_preferences);
    getActivity().setTitle(R.string.prefs_autofill);

    ChromeSwitchPreference autofillSwitch =
            (ChromeSwitchPreference) findPreference(PREF_AUTOFILL_SWITCH);
    autofillSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            PersonalDataManager.setAutofillEnabled((boolean) newValue);
            return true;
        }
    });

    setPreferenceCategoryIcons();
}
 
Example #8
Source File: AutofillPreferences.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private void rebuildProfileList() {
    // Add an edit preference for each current Chrome profile.
    PreferenceGroup profileCategory = (PreferenceGroup) findPreference(PREF_AUTOFILL_PROFILES);
    profileCategory.removeAll();
    for (AutofillProfile profile : PersonalDataManager.getInstance().getProfilesForSettings()) {
        // Add an item on the current page...
        Preference pref = new Preference(getActivity());
        pref.setTitle(profile.getFullName());
        pref.setSummary(profile.getLabel());

        if (profile.getIsLocal()) {
            pref.setFragment(AutofillProfileEditor.class.getName());
        } else {
            pref.setWidgetLayoutResource(R.layout.autofill_server_data_label);
            pref.setFragment(AutofillServerProfilePreferences.class.getName());
        }

        Bundle args = pref.getExtras();
        args.putString(AUTOFILL_GUID, profile.getGUID());
        profileCategory.addPreference(pref);
    }
}
 
Example #9
Source File: AutofillPreferences.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private void rebuildCreditCardList() {
    PreferenceGroup profileCategory =
            (PreferenceGroup) findPreference(PREF_AUTOFILL_CREDIT_CARDS);
    profileCategory.removeAll();
    for (CreditCard card : PersonalDataManager.getInstance().getCreditCardsForSettings()) {
        // Add an item on the current page...
        Preference pref = new Preference(getActivity());
        pref.setTitle(card.getObfuscatedNumber());
        pref.setSummary(card.getFormattedExpirationDate(getActivity()));

        if (card.getIsLocal()) {
            pref.setFragment(AutofillLocalCardEditor.class.getName());
        } else {
            pref.setFragment(AutofillServerCardEditor.class.getName());
            pref.setWidgetLayoutResource(R.layout.autofill_server_data_label);
        }

        Bundle args = pref.getExtras();
        args.putString(AUTOFILL_GUID, card.getGUID());
        profileCategory.addPreference(pref);
    }
}
 
Example #10
Source File: AutofillLocalCardEditor.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean saveEntry() {
    // Remove all spaces in editText.
    String cardNumber = mNumberText.getText().toString().replaceAll("\\s+", "");
    PersonalDataManager personalDataManager = PersonalDataManager.getInstance();
    // Card Payment Type will be empty if credit card number is not valid.
    if (TextUtils.isEmpty(personalDataManager.getBasicCardPaymentType(cardNumber,
            true /* emptyIfInvalid */))) {
        mNumberLabel.setError(mContext.getString(
                R.string.payments_card_number_invalid_validation_message));
        return false;
    }
    CreditCard card = new CreditCard(mGUID, AutofillPreferences.SETTINGS_ORIGIN,
            true /* isLocal */, false /* isCached */, mNameText.getText().toString().trim(),
            cardNumber, "" /* obfuscatedNumber */,
            String.valueOf(mExpirationMonth.getSelectedItemPosition() + 1),
            (String) mExpirationYear.getSelectedItem(), "" /* basicCardPaymentType */,
            0 /* issuerIconDrawableId */,
            ((AutofillProfile) mBillingAddress.getSelectedItem()).getGUID() /* billing */,
            "" /* serverId */);
    personalDataManager.setCreditCard(card);
    return true;
}
 
Example #11
Source File: SyncCustomizationFragment.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void onStop() {
    super.onStop();

    mProfileSyncService.removeSyncStateChangedListener(this);
    // If this activity is closing, apply configuration changes and tell sync that
    // the user is done configuring sync.
    if (!getActivity().isChangingConfigurations()) {
        // Only save state if the switch and external state match. If a stop and clear comes
        // while the dialog is open, this will be false and settings won't be saved.
        if (mSyncSwitchPreference.isChecked()
                && AndroidSyncSettings.isSyncEnabled(getActivity())) {
            // Save the new data type state.
            configureSyncDataTypes();
            // Inform sync that the user has finished setting up sync at least once.
            mProfileSyncService.setFirstSetupComplete();
        }
        PersonalDataManager.setPaymentsIntegrationEnabled(mPaymentsIntegration.isChecked());
        // Setup is done. This was preventing sync from turning on even if it was enabled.
        // TODO(crbug/557784): This needs to be set only when we think the user is done with
        // setting up. This means: 1) If the user leaves the Sync Settings screen (via back)
        // or, 2) If the user leaves the screen by tapping on "Manage Synced Data"
        mProfileSyncService.setSetupInProgress(false);
    }
}
 
Example #12
Source File: CardEditor.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private boolean isCardNumberLengthMaximum(@Nullable CharSequence value) {
    if (TextUtils.isEmpty(value)) return false;
    String cardType = PersonalDataManager.getInstance().getBasicCardIssuerNetwork(
            value.toString(), false);
    if (TextUtils.isEmpty(cardType)) return false;

    // Below maximum values are consistent with the values used to check the validity of the
    // credit card number in autofill::IsValidCreditCardNumber.
    String cardNumber = removeSpaceAndBar(value);
    switch (cardType) {
        case AMEX:
            return cardNumber.length() == 15;
        case DINERS:
            return cardNumber.length() == 14;
        case UNIONPAY:
            return cardNumber.length() == 19;
        default:
            // Valid DISCOVER, JCB, MASTERCARD, MIR and VISA cards have at most 16 digits.
            return cardNumber.length() == 16;
    }
}
 
Example #13
Source File: AddressEditor.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/** Requests the list of admin areas. */
private void loadAdminAreasForCountry(String countryCode) {
    // Used to check if the callback is called (for the cancellation).
    mAdminAreasLoaded = false;

    // For tests, the time-out is set to 0. In this case, we should not
    // fetch the admin-areas, and show a text-field instead.
    // This is to have the tests independent of the network status.
    if (PersonalDataManager.getInstance().getRequestTimeoutMS() == 0) {
        onSubKeysReceived(null);
        return;
    }

    // In each rule, admin area keys are saved under sub-keys of country.
    PersonalDataManager.getInstance().loadRulesForSubKeys(countryCode);
    PersonalDataManager.getInstance().getRegionSubKeys(countryCode, this);
}
 
Example #14
Source File: AutofillAndPaymentsPreferences.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    PreferenceUtils.addPreferencesFromResource(this, R.xml.autofill_and_payments_preferences);
    getActivity().setTitle(R.string.prefs_autofill_and_payments);

    ChromeSwitchPreference autofillSwitch =
            (ChromeSwitchPreference) findPreference(PREF_AUTOFILL_SWITCH);
    autofillSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            PersonalDataManager.setAutofillEnabled((boolean) newValue);
            return true;
        }
    });

    if (ChromeFeatureList.isEnabled(ChromeFeatureList.ANDROID_PAYMENT_APPS)) {
        Preference pref = new Preference(getActivity());
        pref.setTitle(getActivity().getString(R.string.payment_apps_title));
        pref.setFragment(AndroidPaymentAppsFragment.class.getCanonicalName());
        pref.setShouldDisableView(true);
        pref.setKey(PREF_ANDROID_PAYMENT_APPS);
        getPreferenceScreen().addPreference(pref);
    }
}
 
Example #15
Source File: CreditCardNumberFormattingTextWatcher.java    From 365browser with Apache License 2.0 6 votes vote down vote up
public static void insertSeparators(Editable s) {
    int[] positions;
    if (PersonalDataManager.getInstance()
                    .getBasicCardIssuerNetwork(s.toString(), false)
                    .equals("amex")) {
        positions = new int[2];
        positions[0] = 4;
        positions[1] = 11;
    } else {
        positions = new int[3];
        positions[0] = 4;
        positions[1] = 9;
        positions[2] = 14;
    }
    for (int i : positions) {
        if (s.length() > i) {
            s.insert(i, SEPARATOR);
        }
    }
}
 
Example #16
Source File: AutofillLocalCardEditor.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean saveEntry() {
    // Remove all spaces in editText.
    String cardNumber = mNumberText.getText().toString().replaceAll("\\s+", "");
    PersonalDataManager personalDataManager = PersonalDataManager.getInstance();
    // Issuer network will be empty if credit card number is not valid.
    if (TextUtils.isEmpty(personalDataManager.getBasicCardIssuerNetwork(
                cardNumber, true /* emptyIfInvalid */))) {
        mNumberLabel.setError(mContext.getString(
                R.string.payments_card_number_invalid_validation_message));
        return false;
    }
    CreditCard card = new CreditCard(mGUID, AutofillAndPaymentsPreferences.SETTINGS_ORIGIN,
            true /* isLocal */, false /* isCached */, mNameText.getText().toString().trim(),
            cardNumber, "" /* obfuscatedNumber */,
            String.valueOf(mExpirationMonth.getSelectedItemPosition() + 1),
            (String) mExpirationYear.getSelectedItem(), "" /* basicCardPaymentType */,
            0 /* issuerIconDrawableId */,
            ((AutofillProfile) mBillingAddress.getSelectedItem()).getGUID() /* billing */,
            "" /* serverId */);
    personalDataManager.setCreditCard(card);
    return true;
}
 
Example #17
Source File: SyncCustomizationFragment.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Update the data type switch state.
 *
 * If sync is on, load the prefs from native. Otherwise, all data types are disabled and
 * checked. Note that the Password data type will be shown as disabled and unchecked between
 * sync being turned on and the backend initialization completing.
 */
private void updateDataTypeState() {
    boolean isSyncEnabled = mSyncSwitchPreference.isChecked();
    boolean syncEverything = mSyncEverything.isChecked();
    boolean passwordSyncConfigurable = mProfileSyncService.isBackendInitialized()
            && mProfileSyncService.isCryptographerReady();
    Set<Integer> syncTypes = mProfileSyncService.getPreferredDataTypes();
    boolean syncAutofill = syncTypes.contains(ModelType.AUTOFILL);
    for (CheckBoxPreference pref : mAllTypes) {
        boolean canSyncType = true;
        if (pref == mSyncPasswords) canSyncType = passwordSyncConfigurable;
        if (pref == mPaymentsIntegration) {
            canSyncType = syncAutofill || syncEverything;
        }

        if (!isSyncEnabled) {
            pref.setChecked(true);
        } else if (syncEverything) {
            pref.setChecked(canSyncType);
        }

        pref.setEnabled(isSyncEnabled && !syncEverything && canSyncType);
    }
    if (isSyncEnabled && !syncEverything) {
        mSyncAutofill.setChecked(syncAutofill);
        mSyncBookmarks.setChecked(syncTypes.contains(ModelType.BOOKMARKS));
        mSyncOmnibox.setChecked(syncTypes.contains(ModelType.TYPED_URLS));
        mSyncPasswords.setChecked(passwordSyncConfigurable
                && syncTypes.contains(ModelType.PASSWORDS));
        mSyncRecentTabs.setChecked(syncTypes.contains(ModelType.PROXY_TABS));
        // TODO(zea): Switch this to PREFERENCE once that datatype is
        // supported on Android.
        mSyncSettings.setChecked(syncTypes.contains(ModelType.PRIORITY_PREFERENCES));
        mPaymentsIntegration.setChecked(
                syncAutofill && PersonalDataManager.isPaymentsIntegrationEnabled());
    }
}
 
Example #18
Source File: SyncCustomizationFragment.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Update the data type switch state.
 *
 * If sync is on, load the prefs from native. Otherwise, all data types are disabled and
 * checked. Note that the Password data type will be shown as disabled and unchecked between
 * sync being turned on and the backend initialization completing.
 */
private void updateDataTypeState() {
    boolean isSyncEnabled = mSyncSwitchPreference.isChecked();
    boolean syncEverything = mSyncEverything.isChecked();
    boolean passwordSyncConfigurable = mProfileSyncService.isBackendInitialized()
            && mProfileSyncService.isCryptographerReady();
    Set<Integer> syncTypes = mProfileSyncService.getPreferredDataTypes();
    boolean syncAutofill = syncTypes.contains(ModelType.AUTOFILL);
    for (CheckBoxPreference pref : mAllTypes) {
        boolean canSyncType = true;
        if (pref == mSyncPasswords) canSyncType = passwordSyncConfigurable;
        if (pref == mPaymentsIntegration) {
            canSyncType = syncAutofill || syncEverything;
        }

        if (!isSyncEnabled) {
            pref.setChecked(true);
        } else if (syncEverything) {
            pref.setChecked(canSyncType);
        }

        pref.setEnabled(isSyncEnabled && !syncEverything && canSyncType);
    }
    if (isSyncEnabled && !syncEverything) {
        mSyncAutofill.setChecked(syncAutofill);
        mSyncBookmarks.setChecked(syncTypes.contains(ModelType.BOOKMARKS));
        mSyncOmnibox.setChecked(syncTypes.contains(ModelType.TYPED_URLS));
        mSyncPasswords.setChecked(passwordSyncConfigurable
                && syncTypes.contains(ModelType.PASSWORDS));
        mSyncRecentTabs.setChecked(syncTypes.contains(ModelType.PROXY_TABS));
        // TODO(zea): Switch this to PREFERENCE once that datatype is
        // supported on Android.
        mSyncSettings.setChecked(syncTypes.contains(ModelType.PRIORITY_PREFERENCES));
        mPaymentsIntegration.setChecked(
                syncAutofill && PersonalDataManager.isPaymentsIntegrationEnabled());
    }
}
 
Example #19
Source File: AutofillProfileEditor.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
protected void saveEntry() {
    AutofillProfile profile = new PersonalDataManager.AutofillProfile(mGUID,
            AutofillPreferences.SETTINGS_ORIGIN, true /* isLocal */,
            getFieldText(AddressField.RECIPIENT), getFieldText(AddressField.ORGANIZATION),
            getFieldText(AddressField.STREET_ADDRESS), getFieldText(AddressField.ADMIN_AREA),
            getFieldText(AddressField.LOCALITY), getFieldText(AddressField.DEPENDENT_LOCALITY),
            getFieldText(AddressField.POSTAL_CODE), getFieldText(AddressField.SORTING_CODE),
            mCountryCodes.get(mCurrentCountryPos), mPhoneText.getText().toString(),
            mEmailText.getText().toString(), mLanguageCodeString);
    PersonalDataManager.getInstance().setProfile(profile);
}
 
Example #20
Source File: CardEditor.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Saves the edited credit card.
 *
 * If this is a server card, then only its billing address identifier is updated.
 *
 * If this is a new local card, then it's saved on this device only if the user has checked the
 * "save this card" checkbox.
 */
private void commitChanges(CreditCard card, boolean isNewCard) {
    card.setBillingAddressId(mBillingAddressField.getValue().toString());

    PersonalDataManager pdm = PersonalDataManager.getInstance();
    if (!card.getIsLocal()) {
        pdm.updateServerCardBillingAddress(card);
        return;
    }

    card.setNumber(removeSpaceAndBar(mNumberField.getValue()));
    card.setName(mNameField.getValue().toString());
    card.setMonth(mMonthField.getValue().toString());
    card.setYear(mYearField.getValue().toString());

    // Calculate the basic card issuer network, obfuscated number, and the icon for this card.
    // All of these depend on the card number. The issuer network is sent to the merchant
    // website. The obfuscated number and the icon are displayed in the user interface.
    CreditCard displayableCard = pdm.getCreditCardForNumber(card.getNumber());
    card.setBasicCardIssuerNetwork(displayableCard.getBasicCardIssuerNetwork());
    card.setObfuscatedNumber(displayableCard.getObfuscatedNumber());
    card.setIssuerIconDrawableId(displayableCard.getIssuerIconDrawableId());

    if (!isNewCard) {
        pdm.setCreditCard(card);
        return;
    }

    if (mSaveCardCheckbox != null && mSaveCardCheckbox.isChecked()) {
        card.setGUID(pdm.setCreditCard(card));
    }
}
 
Example #21
Source File: AutofillPaymentInstrument.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Checks whether card is complete, i.e., can be sent to the merchant as-is without editing
 * first. And updates edit message, edit title and complete status.
 *
 * For both local and server cards, verifies that the billing address is present. For local
 * cards also verifies that the card number is valid and the name on card is not empty.
 *
 * Does not check that the billing address has all of the required fields. This is done
 * elsewhere to filter out such billing addresses entirely.
 *
 * Does not check the expiration date. If the card is expired, the user has the opportunity
 * update the expiration date when providing their CVC in the card unmask dialog.
 *
 * Does not check that the card type is accepted by the merchant. This is done elsewhere to
 * filter out such cards from view entirely.
 */
private void checkAndUpateCardCompleteness(Context context) {
    int editMessageResId = 0; // Zero is the invalid resource Id.
    int editTitleResId = R.string.payments_edit_card;
    int invalidFieldsCount = 0;

    if (mBillingAddress == null) {
        editMessageResId = R.string.payments_billing_address_required;
        editTitleResId = R.string.payments_add_billing_address;
        invalidFieldsCount++;
    }

    mHasValidNumberAndName = true;
    if (mCard.getIsLocal()) {
        if (TextUtils.isEmpty(mCard.getName())) {
            mHasValidNumberAndName = false;
            editMessageResId = R.string.payments_name_on_card_required;
            editTitleResId = R.string.payments_add_name_on_card;
            invalidFieldsCount++;
        }

        if (PersonalDataManager.getInstance().getBasicCardIssuerNetwork(
                    mCard.getNumber().toString(), true)
                == null) {
            mHasValidNumberAndName = false;
            editMessageResId = R.string.payments_card_number_invalid_validation_message;
            editTitleResId = R.string.payments_add_valid_card_number;
            invalidFieldsCount++;
        }
    }

    if (invalidFieldsCount > 1) {
        editMessageResId = R.string.payments_more_information_required;
        editTitleResId = R.string.payments_add_more_information;
    }

    mEditMessage = editMessageResId == 0 ? null : context.getString(editMessageResId);
    mEditTitle = context.getString(editTitleResId);
    mIsComplete = mEditMessage == null;
}
 
Example #22
Source File: PaymentRequestImpl.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Called after retrieving instrument details.
 */
@Override
public void onInstrumentDetailsReady(String methodName, String stringifiedDetails) {
    if (mClient == null || mPaymentResponseHelper == null) return;

    // Record the payment method used to complete the transaction. If the payment method was an
    // Autofill credit card with an identifier, record its use.
    PaymentOption selectedPaymentMethod = mPaymentMethodsSection.getSelectedItem();
    if (selectedPaymentMethod instanceof AutofillPaymentInstrument) {
        if (!selectedPaymentMethod.getIdentifier().isEmpty()) {
            PersonalDataManager.getInstance().recordAndLogCreditCardUse(
                    selectedPaymentMethod.getIdentifier());
        }
        mJourneyLogger.setSelectedPaymentMethod(SelectedPaymentMethod.CREDIT_CARD);
    } else if (methodName.equals(ANDROID_PAY_METHOD_NAME)
            || methodName.equals(PAY_WITH_GOOGLE_METHOD_NAME)) {
        mJourneyLogger.setSelectedPaymentMethod(SelectedPaymentMethod.ANDROID_PAY);
    } else {
        mJourneyLogger.setSelectedPaymentMethod(SelectedPaymentMethod.OTHER_PAYMENT_APP);
    }

    // Showing the payment request UI if we were previously skipping it so the loading
    // spinner shows up until the merchant notifies that payment was completed.
    if (mShouldSkipShowingPaymentRequestUi) mUI.showProcessingMessageAfterUiSkip();

    mJourneyLogger.setEventOccurred(Event.RECEIVED_INSTRUMENT_DETAILS);

    mPaymentResponseHelper.onInstrumentDetailsReceived(methodName, stringifiedDetails);
}
 
Example #23
Source File: AddressEditor.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/** Saves the edited profile on disk. */
private void commitChanges(AutofillProfile profile) {
    // Country code and phone number are always required and are always collected from the
    // editor model.
    profile.setCountryCode(mCountryField.getValue().toString());
    profile.setPhoneNumber(mPhoneField.getValue().toString());

    // Autofill profile bridge normalizes the language code for the autofill profile.
    profile.setLanguageCode(mAutofillProfileBridge.getCurrentBestLanguageCode());

    // Collect data from all visible fields and store it in the autofill profile.
    Set<Integer> visibleFields = new HashSet<>();
    for (int i = 0; i < mAddressUiComponents.size(); i++) {
        AddressUiComponent component = mAddressUiComponents.get(i);
        visibleFields.add(component.id);
        if (component.id != AddressField.COUNTRY) {
            setProfileField(profile, component.id, mAddressFields.get(component.id).getValue());
        }
    }

    // Clear the fields that are hidden from the user interface, so
    // AutofillAddress.toPaymentAddress() will send them to the renderer as empty strings.
    for (Map.Entry<Integer, EditorFieldModel> entry : mAddressFields.entrySet()) {
        if (!visibleFields.contains(entry.getKey())) {
            setProfileField(profile, entry.getKey(), "");
        }
    }

    // Save the edited autofill profile locally.
    profile.setGUID(PersonalDataManager.getInstance().setProfileToLocal(mProfile));
    profile.setIsLocal(true);
}
 
Example #24
Source File: AutofillAndPaymentsPreferences.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    ((ChromeSwitchPreference) findPreference(PREF_AUTOFILL_SWITCH))
            .setChecked(PersonalDataManager.isAutofillEnabled());
    refreshPaymentAppsPref();
}
 
Example #25
Source File: MainPreferences.java    From delion with Apache License 2.0 5 votes vote down vote up
private void updatePreferences() {
    if (getPreferenceScreen() != null) getPreferenceScreen().removeAll();
    addPreferencesFromResource(R.xml.main_preferences);

    ChromeBasePreference autofillPref =
            (ChromeBasePreference) findPreference(PREF_AUTOFILL_SETTINGS);
    setOnOffSummary(autofillPref, PersonalDataManager.isAutofillEnabled());
    autofillPref.setManagedPreferenceDelegate(mManagedPreferenceDelegate);

    ChromeBasePreference passwordsPref =
            (ChromeBasePreference) findPreference(PREF_SAVED_PASSWORDS);
    if (PasswordUIView.shouldUseSmartLockBranding()) {
        passwordsPref.setTitle(getResources().getString(
                R.string.prefs_smart_lock_for_passwords));
    }
    setOnOffSummary(passwordsPref,
            PrefServiceBridge.getInstance().isRememberPasswordsEnabled());
    passwordsPref.setManagedPreferenceDelegate(mManagedPreferenceDelegate);

    Preference homepagePref = findPreference(PREF_HOMEPAGE);
    if (HomepageManager.shouldShowHomepageSetting()) {
        setOnOffSummary(homepagePref,
                HomepageManager.getInstance(getActivity()).getPrefHomepageEnabled());
    } else {
        getPreferenceScreen().removePreference(homepagePref);
    }

    ChromeBasePreference dataReduction =
            (ChromeBasePreference) findPreference(PREF_DATA_REDUCTION);
    if (DataReductionProxySettings.getInstance().isDataReductionProxyAllowed()) {
        dataReduction.setSummary(
                DataReductionPreferences.generateSummary(getResources()));
        dataReduction.setManagedPreferenceDelegate(mManagedPreferenceDelegate);
    } else {
        getPreferenceScreen().removePreference(dataReduction);
    }
}
 
Example #26
Source File: AutofillServerCardEditor.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean saveEntry() {
    if (mBillingAddress.getSelectedItem() != null
            && mBillingAddress.getSelectedItem() instanceof AutofillProfile) {
        mCard.setBillingAddressId(
                ((AutofillProfile) mBillingAddress.getSelectedItem()).getGUID());
        PersonalDataManager.getInstance().updateServerCardBillingAddress(mCard);
    }
    return true;
}
 
Example #27
Source File: AutofillProfileEditor.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean saveEntry() {
    AutofillProfile profile = new PersonalDataManager.AutofillProfile(mGUID,
            AutofillAndPaymentsPreferences.SETTINGS_ORIGIN, true /* isLocal */,
            getFieldText(AddressField.RECIPIENT), getFieldText(AddressField.ORGANIZATION),
            getFieldText(AddressField.STREET_ADDRESS), getFieldText(AddressField.ADMIN_AREA),
            getFieldText(AddressField.LOCALITY), getFieldText(AddressField.DEPENDENT_LOCALITY),
            getFieldText(AddressField.POSTAL_CODE), getFieldText(AddressField.SORTING_CODE),
            mCountryCodes.get(mCurrentCountryPos), mPhoneText.getText().toString(),
            mEmailText.getText().toString(), mLanguageCodeString);
    PersonalDataManager.getInstance().setProfile(profile);
    return true;
}
 
Example #28
Source File: AddressEditor.java    From delion with Apache License 2.0 5 votes vote down vote up
/** Saves the edited profile on disk. */
private void commitChanges(AutofillProfile profile) {
    // Country code and phone number are always required and are always collected from the
    // editor model.
    profile.setCountryCode(mCountryField.getValue().toString());
    profile.setPhoneNumber(mPhoneField.getValue().toString());

    // Autofill profile bridge normalizes the language code for the autofill profile.
    profile.setLanguageCode(mAutofillProfileBridge.getCurrentBestLanguageCode());

    // Collect data from all visible fields and store it in the autofill profile.
    Set<Integer> visibleFields = new HashSet<>();
    for (int i = 0; i < mAddressUiComponents.size(); i++) {
        AddressUiComponent component = mAddressUiComponents.get(i);
        visibleFields.add(component.id);
        if (component.id != AddressField.COUNTRY) {
            setProfileField(profile, component.id, mAddressFields.get(component.id).getValue());
        }
    }

    // Clear the fields that are hidden from the user interface, so
    // AutofillAddress.toPaymentAddress() will send them to the renderer as empty strings.
    for (Map.Entry<Integer, EditorFieldModel> entry : mAddressFields.entrySet()) {
        if (!visibleFields.contains(entry.getKey())) {
            setProfileField(profile, entry.getKey(), "");
        }
    }

    // Calculate the label for this profile. The label's format depends on the country and
    // language code for the profile.
    PersonalDataManager pmd = PersonalDataManager.getInstance();
    profile.setLabel(pmd.getGetAddressLabelForPaymentRequest(profile));

    // Save the edited autofill profile.
    pmd.setProfile(profile);
}
 
Example #29
Source File: SyncCustomizationFragment.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Update the data type switch state.
 *
 * If sync is on, load the prefs from native. Otherwise, all data types are disabled and
 * checked. Note that the Password data type will be shown as disabled and unchecked between
 * sync being turned on and the engine initialization completing.
 */
private void updateDataTypeState() {
    boolean isSyncEnabled = mSyncSwitchPreference.isChecked();
    boolean syncEverything = mSyncEverything.isChecked();
    boolean passwordSyncConfigurable = mProfileSyncService.isEngineInitialized()
            && mProfileSyncService.isCryptographerReady();
    Set<Integer> syncTypes = mProfileSyncService.getPreferredDataTypes();
    boolean syncAutofill = syncTypes.contains(ModelType.AUTOFILL);
    for (CheckBoxPreference pref : mAllTypes) {
        boolean canSyncType = true;
        if (pref == mSyncPasswords) canSyncType = passwordSyncConfigurable;
        if (pref == mPaymentsIntegration) {
            canSyncType = syncAutofill || syncEverything;
        }

        if (!isSyncEnabled) {
            pref.setChecked(true);
        } else if (syncEverything) {
            pref.setChecked(canSyncType);
        }

        pref.setEnabled(isSyncEnabled && !syncEverything && canSyncType);
    }
    if (isSyncEnabled && !syncEverything) {
        mSyncAutofill.setChecked(syncAutofill);
        mSyncBookmarks.setChecked(syncTypes.contains(ModelType.BOOKMARKS));
        mSyncOmnibox.setChecked(syncTypes.contains(ModelType.TYPED_URLS));
        mSyncPasswords.setChecked(passwordSyncConfigurable
                && syncTypes.contains(ModelType.PASSWORDS));
        mSyncRecentTabs.setChecked(syncTypes.contains(ModelType.PROXY_TABS));
        mSyncSettings.setChecked(syncTypes.contains(ModelType.PREFERENCES));
        mPaymentsIntegration.setChecked(
                syncAutofill && PersonalDataManager.isPaymentsIntegrationEnabled());
    }
}
 
Example #30
Source File: AutofillLocalCardEditor.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
protected void saveEntry() {
    // Remove all spaces in editText.
    String cardNumber = mNumberText.getText().toString().replaceAll("\\s+", "");
    CreditCard card = new CreditCard(mGUID, AutofillPreferences.SETTINGS_ORIGIN,
            true /* isLocal */, false /* isCached */, mNameText.getText().toString().trim(),
            cardNumber, "" /* obfuscatedNumber */,
            String.valueOf(mExpirationMonth.getSelectedItemPosition() + 1),
            (String) mExpirationYear.getSelectedItem(), "" /* basicCardPaymentType */,
            0 /* issuerIconDrawableId */,
            ((AutofillProfile) mBillingAddress.getSelectedItem()).getGUID() /* billing */);
    PersonalDataManager.getInstance().setCreditCard(card);
}