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

Commit

Permalink
For #25311 - Set tokens used when communicating with Pocket
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugurell authored and mergify[bot] committed May 25, 2022
1 parent 98e3b8b commit 2343b75
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ gen-external-apklibs
.mls_token
.nimbus
.wallpaper_url
.pocket_consumer_key

# Python Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
15 changes: 15 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,21 @@ android.applicationVariants.all { variant ->
buildConfigField 'String', 'WALLPAPER_URL', '""'
println("--")
}

// -------------------------------------------------------------------------------------------------
// BuildConfig: Set the Pocket consumer key from a local file if it exists
// -------------------------------------------------------------------------------------------------

print("Pocket consumer key: ")

try {
def token = new File("${rootDir}/.pocket_consumer_key").text.trim()
buildConfigField 'String', 'POCKET_CONSUMER_KEY', '"' + token + '"'
println "(Added from .pocket_consumer_key file)"
} catch (FileNotFoundException ignored) {
buildConfigField 'String', 'POCKET_CONSUMER_KEY', '""'
println("--")
}
}

// Generate Kotlin code for the Fenix Glean metrics.
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/org/mozilla/fenix/components/Core.kt
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,10 @@ class Core(
PocketStoriesConfig(
client,
Frequency(4, TimeUnit.HOURS),
// These need to be updated. See https://mozilla-hub.atlassian.net/browse/FNXV2-20329.
Profile(UUID.randomUUID(), "fenix")
Profile(
profileId = UUID.fromString(context.settings().pocketSponsoredStoriesProfileId),
appId = BuildConfig.POCKET_CONSUMER_KEY
)
)
}
val pocketStoriesService by lazyMonitored { PocketStoriesService(context, pocketStoriesConfig) }
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/org/mozilla/fenix/utils/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import org.mozilla.fenix.settings.sitepermissions.AUTOPLAY_BLOCK_ALL
import org.mozilla.fenix.settings.sitepermissions.AUTOPLAY_BLOCK_AUDIBLE
import org.mozilla.fenix.wallpapers.WallpaperManager
import java.security.InvalidParameterException
import java.util.UUID

private const val AUTOPLAY_USER_SETTING = "AUTOPLAY_USER_SETTING"

Expand Down Expand Up @@ -1274,6 +1275,15 @@ class Settings(private val appContext: Context) : PreferencesHolder {
default = { homescreenSections[HomeScreenSection.POCKET] == true },
)

/**
* Get the profile id to use in the sponsored stories communications with the Pocket endpoint.
*/
val pocketSponsoredStoriesProfileId by stringPreference(
appContext.getPreferenceKey(R.string.pref_key_pocket_sponsored_stories_profile),
default = UUID.randomUUID().toString(),
persistDefaultIfNotExists = true
)

/**
* Indicates if the Contile functionality should be visible.
*/
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/res/values/preference_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,10 @@

<string name="pref_key_open_next_tab_desktop_mode" translatable="false">pref_key_open_next_tab_desktop_mode</string>

<!-- Pocket -->
<string name="pref_key_pocket_homescreen_recommendations" translatable="false">pref_key_pocket_homescreen_recommendations</string>
<string name="pref_key_pocket_sponsored_stories_profile" translatable="false">pref_key_pocket_sponsored_stories_profile</string>

<!-- Secret Info Setting Keys -->
<string name="pref_key_secret_debug_info" translatable="false">pref_key_secret_debug_info</string>

Expand All @@ -287,6 +291,5 @@
<string name="pref_key_nimbus_experiments" translatable="false">pref_key_nimbus_experiments</string>
<string name="pref_key_nimbus_use_preview" translatable="false">pref_key_nimbus_use_preview</string>
<string name="pref_key_history_metadata_feature" translatable="false">pref_key_history_metadata_feature</string>
<string name="pref_key_pocket_homescreen_recommendations" translatable="false">pref_key_pocket_homescreen_recommendations</string>
<string name="pref_key_show_unified_search" translatable="false">pref_key_show_unified_search</string>
</resources>
1 change: 1 addition & 0 deletions taskcluster/fenix_taskgraph/transforms/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def add_shippable_secrets(config, tasks):
("mls", ".mls_token"),
("nimbus_url", ".nimbus"),
("wallpaper_url", ".wallpaper_url"),
("pocket_consumer_key", ".pocket_consumer_key"),
)
]
)
Expand Down

0 comments on commit 2343b75

Please sign in to comment.