Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when switching between LPMs. #4921

Merged
merged 12 commits into from
May 2, 2022
Merged

Conversation

michelleb-stripe
Copy link
Contributor

@michelleb-stripe michelleb-stripe commented Apr 27, 2022

Summary

When switching between LPMs the form view model was reported collected fields for the new LPM even though all fields were not filled out. This resulted in the PaymentMethodCreateParameters to be wrongly created (it should not be created until all fields on the new LPM are complete), and causing the access of the last 4 of the card number to cause a crash.

Testing

  • Added tests
  • Modified tests
  • Manually verified

Changelog

  • [Fixed] Fixed a crash that could happen when switching between LPMs.

@github-actions
Copy link
Contributor

github-actions bot commented Apr 27, 2022

Diffuse output:

OLD: paymentsheet-example-release-master.apk (signature: none)
NEW: paymentsheet-example-release-pr.apk (signature: none)

          │          compressed          │          uncompressed          
          ├──────────┬──────────┬────────┼──────────┬──────────┬──────────
 APK      │ old      │ new      │ diff   │ old      │ new      │ diff     
──────────┼──────────┼──────────┼────────┼──────────┼──────────┼──────────
      dex │ 13.5 MiB │ 13.5 MiB │ +636 B │ 45.2 MiB │ 45.2 MiB │ +1.3 KiB 
     arsc │  1.7 MiB │  1.7 MiB │    0 B │  1.7 MiB │  1.7 MiB │      0 B 
 manifest │  3.1 KiB │  3.1 KiB │    0 B │ 13.7 KiB │ 13.7 KiB │      0 B 
      res │  711 KiB │  711 KiB │    0 B │  1.1 MiB │  1.1 MiB │      0 B 
   native │  5.4 MiB │  5.4 MiB │    0 B │ 13.4 MiB │ 13.4 MiB │      0 B 
    asset │    3 MiB │    3 MiB │   +4 B │    3 MiB │    3 MiB │     +4 B 
    other │   80 KiB │   80 KiB │    0 B │  155 KiB │  155 KiB │      0 B 
──────────┼──────────┼──────────┼────────┼──────────┼──────────┼──────────
    total │ 24.3 MiB │ 24.3 MiB │ +640 B │ 64.6 MiB │ 64.6 MiB │ +1.3 KiB 

         │          raw           │             unique              
         ├────────┬────────┬──────┼────────┬────────┬───────────────
 DEX     │ old    │ new    │ diff │ old    │ new    │ diff          
─────────┼────────┼────────┼──────┼────────┼────────┼───────────────
   files │      3 │      3 │    0 │        │        │               
 strings │ 218890 │ 218892 │   +2 │ 192536 │ 192536 │   0 (+20 -20) 
   types │  38011 │  38016 │   +5 │  35154 │  35158 │  +4 (+7 -3)   
 classes │  32524 │  32528 │   +4 │  32524 │  32528 │  +4 (+7 -3)   
 methods │ 195574 │ 195589 │  +15 │ 189066 │ 189081 │ +15 (+35 -20) 
  fields │ 139571 │ 139576 │   +5 │ 138652 │ 138656 │  +4 (+12 -8)  

 ARSC    │ old  │ new  │ diff 
─────────┼──────┼──────┼──────
 configs │  292 │  292 │  0   
 entries │ 5766 │ 5766 │  0
APK
    compressed    │    uncompressed     │                               
─────────┬────────┼──────────┬──────────┤                               
 size    │ diff   │ size     │ diff     │ path                          
─────────┼────────┼──────────┼──────────┼───────────────────────────────
 3.9 MiB │ +636 B │ 11.2 MiB │ +1.3 KiB │ ∆ classes3.dex                
 7.3 KiB │   +4 B │  7.2 KiB │     +4 B │ ∆ assets/dexopt/baseline.prof 
─────────┼────────┼──────────┼──────────┼───────────────────────────────
 3.9 MiB │ +640 B │ 11.2 MiB │ +1.3 KiB │ (total)
DEX
STRINGS:

   old    │ new    │ diff        
  ────────┼────────┼─────────────
   192536 │ 192536 │ 0 (+20 -20) 
  + 8
  ���
  ��
  ���
  ���
  
  ���
  
  ���
  
  ���
  
  ���
  
  ���
  ���
  ���
  ����2�0�B���¢����JJ����0�2�����0�2�����0�2��	����0
  2�����02
  ���
  ����0�2�������02�������0�H�¨��
  + V
  ���
  ���
  ���
  ���
  ���
  ���
  ���
  ���
  
  ���
  
  ���
  
  ���
  
  ���
  
  ���
  ���
  ���
  
  ���
  
  ���
  ����� 2�0�:�B�¢����J_����0�2�����0�2�������0�2�������0�H�J�����0�2�����0�2�������0�H�J!������0�2�������0�2�����0 H�¢���!R�����0�8BX���¢�
  �����������R��	��0
  8FX���¢�
  ��
  �������R�����0�X��¢��
  ¨�#
  + \
  ���
  ���
  ���
  ���
  ���
  ���
  ���
  ���
  ���
  
  ���
  ���
  ���
  
  ���
  
  ���
  
  ���
  
  ���
  ���
  ���
  
  �� 
  ���� � %2�0�:�%B�¢����J���������0
  02�����0�H�J
  ������0�H�J&������0�2�����0�2�������0�2�������0�H�J�����0�2�����0�H�¢����J�����0�2�����0�2�������0�H�J�����0�2�����0�H�J&����0�2�� ��0!2�������0�0#2��_��0�H�R���������0�X¦�¢��������R�����0�X¦�¢�����	�
  ¨�&
  + _r8_lambda_1-ZGFCvTCgeOQrFxqPfloI-S64Q
  + _r8_lambda_ZPME4QZS_C82ZIBUGgLrTkV1EZM
  + _sheetViewModel_delegate
  + Lcom/stripe/android/paymentsheet/paymentdatacollection/ComposeFormDataCollectionFragment__ExternalSyntheticLambda0;
  + Lcom/stripe/android/paymentsheet/paymentdatacollection/ComposeFormDataCollectionFragment_onViewCreated__inlined_activityViewModels_default_1;
  + Lcom/stripe/android/paymentsheet/paymentdatacollection/ComposeFormDataCollectionFragment_onViewCreated__inlined_activityViewModels_default_2;
  + Lcom/stripe/android/paymentsheet/paymentdatacollection/ComposeFormDataCollectionFragment_onViewCreated__inlined_activityViewModels_default_3;
  + Lcom/stripe/android/paymentsheet/paymentdatacollection/ComposeFormDataCollectionFragment_onViewCreated__inlined_activityViewModels_default_4;
  + Lcom/stripe/android/paymentsheet/paymentdatacollection/ComposeFormDataCollectionFragment_onViewCreated_1_1;
  + Lcom/stripe/android/paymentsheet/paymentdatacollection/ComposeFormDataCollectionFragment_onViewCreated_1;
  + SMAP
  BaseAddPaymentMethodFragment.kt
  Kotlin
  *S Kotlin
  *F
  + 1 BaseAddPaymentMethodFragment.kt
  com/stripe/android/paymentsheet/BaseAddPaymentMethodFragment
  + 2 fake.kt
  kotlin/jvm/internal/FakeKt
  + 3 View.kt
  androidx/core/view/ViewKt
  + 4 FragmentManager.kt
  androidx/fragment/app/FragmentManagerKt
  *L
  1#1,234:1
  1#2:235
  254#3,2:236
  26#4,12:238
  *S KotlinDebug
  *F
  + 1 BaseAddPaymentMethodFragment.kt
  com/stripe/android/paymentsheet/BaseAddPaymentMethodFragment
  *L
  110#1:236,2
  158#1:238,12
  *E
  
  + SMAP
  BaseAddPaymentMethodFragment.kt
  Kotlin
  *S Kotlin
  *F
  + 1 BaseAddPaymentMethodFragment.kt
  com/stripe/android/paymentsheet/BaseAddPaymentMethodFragment_onViewCreated_4_1_1
  + 2 View.kt
  androidx/core/view/ViewKt
  *L
  1#1,234:1
  254#2,2:235
  *S KotlinDebug
  *F
  + 1 BaseAddPaymentMethodFragment.kt
  com/stripe/android/paymentsheet/BaseAddPaymentMethodFragment_onViewCreated_4_1_1
  *L
  96#1:235,2
  *E
  
  + SMAP
  BaseAddPaymentMethodFragment.kt
  Kotlin
  *S Kotlin
  *F
  + 1 BaseAddPaymentMethodFragment.kt
  com/stripe/android/paymentsheet/BaseAddPaymentMethodFragment_setupRecyclerView_1_1
  + 2 Composables.kt
  androidx/compose/runtime/ComposablesKt
  + 3 Composer.kt
  androidx/compose/runtime/ComposerKt
  + 4 SnapshotState.kt
  androidx/compose/runtime/SnapshotStateKt__SnapshotStateKt
  *L
  1#1,234:1
  36#2:235
  957#3,6:236
  76#4:242
  76#4:243
  *S KotlinDebug
  *F
  + 1 BaseAddPaymentMethodFragment.kt
  com/stripe/android/paymentsheet/BaseAddPaymentMethodFragment_setupRecyclerView_1_1
  *L
  124#1:235
  124#1:236,6
  114#1:242
  117#1:243
  *E
  
  + SMAP
  ComposeFormDataCollectionFragment.kt
  Kotlin
  *S Kotlin
  *F
  + 1 ComposeFormDataCollectionFragment.kt
  com/stripe/android/paymentsheet/paymentdatacollection/ComposeFormDataCollectionFragment
  + 2 FragmentViewModelLazy.kt
  androidx/fragment/app/FragmentViewModelLazyKt
  + 3 Maps.kt
  kotlin/collections/MapsKt__MapsKt
  *L
  1#1,164:1
  56#2,10:165
  84#2,6:175
  84#2,6:181
  536#3:187
  521#3,6:188
  *S KotlinDebug
  *F
  + 1 ComposeFormDataCollectionFragment.kt
  com/stripe/android/paymentsheet/paymentdatacollection/ComposeFormDataCollectionFragment
  *L
  49#1:165,10
  87#1:175,6
  90#1:181,6
  133#1:187
  133#1:188,6
  *E
  
  + SMAP
  ComposeFormDataCollectionFragment.kt
  Kotlin
  *S Kotlin
  *F
  + 1 ComposeFormData
...✂

@jameswoo-stripe
Copy link
Contributor

Is it possible to add a test for this?

skyler-stripe
skyler-stripe previously approved these changes Apr 27, 2022
@@ -101,11 +105,18 @@ internal abstract class BaseAddPaymentMethodFragment : Fragment() {
sheetViewModel.eventReporter.onShowNewPaymentOptionForm()
}

override fun onStop() {
super.onStop()
composeFragmentFieldValues?.cancel()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like we may not be scoping the job correctly. Is it possible to scope the lifecycle of the job to this fragment rather than manually canceling the job?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@awush-stripe I moved the BaseSheetViewModel so it is accessible from the ComposeFormDataCollectionFragment. It was slightly akward as the VIewModel could be a PaymentSheetActivityViewModel or a PaymentOptionsActivityViewModel. It seems to work calling activityViewModels from onViewCreated, but would be curious to hear if there was a better way to handle this.

jameswoo-stripe
jameswoo-stripe previously approved these changes May 2, 2022
Copy link
Contributor

@jameswoo-stripe jameswoo-stripe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally, just one comment

@michelleb-stripe michelleb-stripe merged commit 98e3d70 into master May 2, 2022
@michelleb-stripe michelleb-stripe deleted the michelleb/fix-crash branch May 2, 2022 23:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants