Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[android] Add support for external SDK clients tokens management #14631

Merged
merged 1 commit into from
May 30, 2019

Conversation

Guardiola31337
Copy link
Contributor

This PR builds on top of #14404 and adds support for external SDK clients to be able to manage the tokens on their side disabling the default implementation and returning the token from SharedPreferences i.e. the external SDK is responsible for managing the state, rotating and storing (using the proper keys defined in AccountsManager) the tokens.

This is an initial proposal, please let me know what you think.

cc @akitchen @frederoni

@Guardiola31337 Guardiola31337 added the Android Mapbox Maps SDK for Android label May 9, 2019
@Guardiola31337 Guardiola31337 self-assigned this May 9, 2019
@zugaldia
Copy link
Member

zugaldia commented May 9, 2019

cc: @tobrun or @LukasPaczos for a first round of comments.

@zugaldia zugaldia removed their request for review May 9, 2019 23:53
@Guardiola31337 Guardiola31337 requested review from zugaldia and removed request for zugaldia May 10, 2019 03:14
Copy link
Member

@LukasPaczos LukasPaczos left a comment

Choose a reason for hiding this comment

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

Initially LGTM 👍

One note that AccountsManager#PREFERENCE_SKU_TOKEN constant should be exposed so that it can be used downstream, without hardcoding the value.

@Guardiola31337 Guardiola31337 force-pushed the pg-external-sku-handling branch 2 times, most recently from 08ce07c to 3110363 Compare May 23, 2019 13:32
@tobrun
Copy link
Member

tobrun commented May 28, 2019

@Guardiola31337 any progress on this PR? if we want to hit the deadline for release-oolong, we need to start moving on this.

@Guardiola31337
Copy link
Contributor Author

@tobrun

any progress on this PR? if we want to hit the deadline for release-oolong, we need to start moving on this.

Sure thing! This is updated and ready for another round of 👀

cc @LukasPaczos

@Guardiola31337 Guardiola31337 marked this pull request as ready for review May 28, 2019 14:18
Copy link
Member

@LukasPaczos LukasPaczos left a comment

Choose a reason for hiding this comment

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

Looks good, minor comments below. Also, it'd be great if you could add some unit tests to the AccountsManagerTest

public static final String KEY_PREFERENCE_SKU_TOKEN = "com.mapbox.mapboxsdk.accounts.skutoken";

/**
* Key used to switch SKU token management on/off in AndroidManifest.xml
Copy link
Member

Choose a reason for hiding this comment

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

NIT: I don't think we need this javadoc.

public static final String KEY_META_DATA_MANAGE_SKU_TOKEN = "com.mapbox.ManageSkuToken";

/**
* Default value for KEY_META_DATA_MANAGE_SKU_TOKEN (default is on)
Copy link
Member

Choose a reason for hiding this comment

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

Same as above.


private long timestamp;
@Nullable
Copy link
Member

Choose a reason for hiding this comment

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

Let's ensure that the token is actually not null by fetching it from preferences in the constructor as well.

@Guardiola31337
Copy link
Contributor Author

@LukasPaczos updated and ready for another round of 👀

public void checksSkuTokenExternalManagement() {
SharedPreferences mockedSharedPreferences = mock(SharedPreferences.class);
when(mockedSharedPreferences.getString(KEY_PREFERENCE_SKU_TOKEN, "")).thenReturn("external-sku-token");
boolean isNotManaged = false;
Copy link
Member

Choose a reason for hiding this comment

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

NIT: should be called isManaged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

🤔 now the variable is called isNotManaged, and has value false, so that should mean that it is managed. Idk, just seems a little bit off to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👀 Working Effectively with Unit Tests

when writing tests you should prefer DAMP (Descriptive And Maintainable Procedures)

That includes a bunch of procedures Moving Towards Readability 😅

I highly recommend you reading that book (if you haven't already). It's 🔝 💯

Copy link
Member

Choose a reason for hiding this comment

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

Thanks! It had a reverse effect on me though haha 🤷‍♂️

@Guardiola31337
Copy link
Contributor Author

@LukasPaczos I've answered back / addressed all your comments, this is ready for a final round of 👀

@Guardiola31337 Guardiola31337 merged commit 0181ef8 into master May 30, 2019
@Guardiola31337 Guardiola31337 deleted the pg-external-sku-handling branch May 30, 2019 15:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Android Mapbox Maps SDK for Android
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants