Bug 1386906 - Add Pocket keys to build system. r?chmanchester
MozReview-Commit-ID: 8fjcSkn1P7P
--- a/mobile/android/base/AppConstants.java.in
+++ b/mobile/android/base/AppConstants.java.in
@@ -332,9 +332,16 @@ public class AppConstants {
* MozillaOnline (Mozilla China) version of Fennec.
*/
public static final boolean MOZ_ANDROID_MOZILLA_ONLINE =
//#ifdef MOZ_ANDROID_MOZILLA_ONLINE
true;
//#else
false;
//#endif
+
+ public static final String MOZ_POCKET_API_KEY =
+//#ifdef MOZ_ANDROID_POCKET
+ "@MOZ_POCKET_API_KEY@";
+//#else
+ null;
+//#endif
}
--- a/mobile/android/base/generate_build_config.py
+++ b/mobile/android/base/generate_build_config.py
@@ -45,16 +45,17 @@ def _defines():
'MOZ_ANDROID_EXCLUDE_FONTS',
'MOZ_ANDROID_GCM',
'MOZ_ANDROID_MLS_STUMBLER',
'MOZ_ANDROID_MMA',
'MOZ_ANDROID_MOZILLA_ONLINE',
'MOZ_ANDROID_PWA',
'MOZ_LEANPLUM_SDK_KEY',
'MOZ_LEANPLUM_SDK_CLIENTID',
+ 'MOZ_ANDROID_POCKET',
'MOZ_ANDROID_SEARCH_ACTIVITY',
'MOZ_CRASHREPORTER',
'MOZ_DEBUG',
'MOZ_INSTALL_TRACKING',
'MOZ_NATIVE_DEVICES',
'MOZ_SWITCHBOARD'):
if CONFIG[var]:
DEFINES[var] = 1
@@ -107,16 +108,19 @@ def _defines():
# leak the value to build logs.
if CONFIG['MOZ_INSTALL_TRACKING']:
DEFINES['MOZ_INSTALL_TRACKING_ADJUST_SDK_APP_TOKEN'] = CONFIG['MOZ_ADJUST_SDK_KEY']
if CONFIG['MOZ_ANDROID_MMA']:
DEFINES['MOZ_LEANPLUM_SDK_KEY'] = CONFIG['MOZ_LEANPLUM_SDK_KEY']
DEFINES['MOZ_LEANPLUM_SDK_CLIENTID'] = CONFIG['MOZ_LEANPLUM_SDK_CLIENTID']
+ if CONFIG['MOZ_ANDROID_POCKET']:
+ DEFINES['MOZ_POCKET_API_KEY'] = CONFIG['MOZ_POCKET_API_KEY']
+
DEFINES['MOZ_BUILDID'] = open(os.path.join(buildconfig.topobjdir, 'buildid.h')).readline().split()[2]
# Set the appropriate version code if not set by MOZ_APP_ANDROID_VERSION_CODE.
if CONFIG.get('MOZ_APP_ANDROID_VERSION_CODE'):
DEFINES['ANDROID_VERSION_CODE'] = \
CONFIG.get('MOZ_APP_ANDROID_VERSION_CODE')
else:
min_sdk = int(CONFIG.get('MOZ_ANDROID_MIN_SDK_VERSION') or '0') or None
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/topstories/PocketStoriesLoader.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/topstories/PocketStoriesLoader.java
@@ -6,16 +6,17 @@
package org.mozilla.gecko.activitystream.homepanel.topstories;
import android.content.AsyncTaskLoader;
import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri;
import android.util.Log;
+import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.Locales;
import org.mozilla.gecko.util.FileUtils;
import org.mozilla.gecko.util.ProxySelector;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
@@ -24,30 +25,38 @@ import java.net.URISyntaxException;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
/**
* Loader implementation for loading fresh or cached content from the Pocket Stories API.
* {@link #loadInBackground()} returns a JSON string of Pocket stories.
*
* NB: Using AsyncTaskLoader rather than AsyncTask so that loader is tied Activity lifecycle.
+ *
+ * Access to Pocket Stories is controlled by a private Pocket API token.
+ * Add the following to your mozconfig to compile with the Pocket Stories:
+ *
+ * export MOZ_ANDROID_POCKET=1
+ * ac_add_options --with-pocket-api-keyfile=$topsrcdir/mobile/android/base/pocket-api-sandbox.token
+ *
+ * and include the Pocket API token in the token file.
*/
public class PocketStoriesLoader extends AsyncTaskLoader<String> {
public static String LOGTAG = "PocketStoriesLoader";
// Pocket SharedPreferences keys
private static final String POCKET_PREFS_FILE = "PocketStories";
private static final String CACHE_TIMESTAMP_MILLIS_PREFIX = "timestampMillis-";
private static final String STORIES_CACHE_PREFIX = "storiesCache-";
// Pocket API params and defaults
private static final String GLOBAL_ENDPOINT = "https://getpocket.com/v3/firefox/global-recs";
private static final String PARAM_APIKEY = "consumer_key";
- private static final String APIKEY = "KEY_PLACEHOLDER"; // Bug 1386906: Add Pocket keys to builders.
+ private static final String APIKEY = AppConstants.MOZ_POCKET_API_KEY;
private static final String PARAM_COUNT = "count";
private static final int DEFAULT_COUNT = 20;
private static final String PARAM_LOCALE = "locale_lang";
private static final long REFRESH_INTERVAL_MILLIS = TimeUnit.HOURS.toMillis(3);
private static final int BUFFER_SIZE = 2048;
private static final int CONNECT_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(15);
@@ -77,16 +86,20 @@ public class PocketStoriesLoader extends
@Override
protected void onReset() {
localeLang = Locales.getLanguageTag(Locale.getDefault());
}
@Override
public String loadInBackground() {
+ if (APIKEY == null) {
+ Log.e(LOGTAG, "Missing Pocket API key! See class comment about how to set up a mozconfig.");
+ return null;
+ }
return makeAPIRequestWithKey(APIKEY);
}
protected String makeAPIRequestWithKey(final String apiKey) {
HttpURLConnection connection = null;
final Uri uri = Uri.parse(GLOBAL_ENDPOINT)
.buildUpon()
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -11,16 +11,19 @@ with Files('*.java.*'):
BUG_COMPONENT = ('Firefox for Android', 'General')
with Files('*Manifest*'):
BUG_COMPONENT = ('Firefox for Android', 'General')
with Files('adjust-sdk-sandbox.token'):
BUG_COMPONENT = ('Firefox for Android', 'Build Config & IDE Support')
+with Files('pocket-api-sandbox.token'):
+ BUG_COMPONENT = ('Firefox for Android', 'Build Config & IDE Support')
+
with Files('android-services.mozbuild'):
BUG_COMPONENT = ('Android Background Services', 'Android Sync')
with Files('geckoview.ddf'):
BUG_COMPONENT = ('Firefox for Android', 'GeckoView')
with Files('crashreporter/**'):
BUG_COMPONENT = ('Firefox for Android', 'General')
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/pocket-api-sandbox.token
@@ -0,0 +1,1 @@
+123456789
--- a/mobile/android/config/mozconfigs/android-aarch64/l10n-nightly
+++ b/mobile/android/config/mozconfigs/android-aarch64/l10n-nightly
@@ -28,12 +28,13 @@ ac_add_options --disable-stdcxx-compat
mk_add_options AUTOCLOBBER=
# Disable Keyfile Loading (and checks) since l10n doesn't need these keys
# This overrides the settings in the common android mozconfig
ac_add_options --without-mozilla-api-keyfile
ac_add_options --without-google-api-keyfile
ac_add_options --without-adjust-sdk-keyfile
ac_add_options --without-leanplum-sdk-keyfile
+ac_add_options --without-pocket-api-keyfile
# Similarly explicitly disable install tracking for l10n, we'll inherit from en-US
export MOZ_INSTALL_TRACKING=
. "$topsrcdir/mobile/android/config/mozconfigs/common.override"
--- a/mobile/android/config/mozconfigs/android-api-15/l10n-nightly
+++ b/mobile/android/config/mozconfigs/android-api-15/l10n-nightly
@@ -28,12 +28,13 @@ ac_add_options --disable-stdcxx-compat
mk_add_options AUTOCLOBBER=
# Disable Keyfile Loading (and checks) since l10n doesn't need these keys
# This overrides the settings in the common android mozconfig
ac_add_options --without-mozilla-api-keyfile
ac_add_options --without-google-api-keyfile
ac_add_options --without-adjust-sdk-keyfile
ac_add_options --without-leanplum-sdk-keyfile
+ac_add_options --without-pocket-api-keyfile
# Similarly explicitly disable install tracking for l10n, we'll inherit from en-US
export MOZ_INSTALL_TRACKING=
. "$topsrcdir/mobile/android/config/mozconfigs/common.override"
--- a/mobile/android/config/mozconfigs/android-api-15/nightly
+++ b/mobile/android/config/mozconfigs/android-api-15/nightly
@@ -10,10 +10,11 @@ ac_add_options --with-branding=mobile/an
# This will overwrite the default of stripping everything and keep the symbol table.
# This is useful for profiling with eideticker. See bug 788680
STRIP_FLAGS="--strip-debug"
export MOZILLA_OFFICIAL=1
export MOZ_TELEMETRY_REPORTING=1
export MOZ_ANDROID_MMA=1
+export MOZ_ANDROID_POCKET=1
. "$topsrcdir/mobile/android/config/mozconfigs/common.override"
--- a/mobile/android/config/mozconfigs/android-api-15/nightly-old-id
+++ b/mobile/android/config/mozconfigs/android-api-15/nightly-old-id
@@ -10,10 +10,11 @@ ac_add_options --with-branding=mobile/an
# This will overwrite the default of stripping everything and keep the symbol table.
# This is useful for profiling with eideticker. See bug 788680
STRIP_FLAGS="--strip-debug"
export MOZILLA_OFFICIAL=1
export MOZ_TELEMETRY_REPORTING=1
export MOZ_ANDROID_MMA=1
+export MOZ_ANDROID_POCKET=1
. "$topsrcdir/mobile/android/config/mozconfigs/common.override"
--- a/mobile/android/config/mozconfigs/common
+++ b/mobile/android/config/mozconfigs/common
@@ -73,16 +73,29 @@ if test "$MOZ_UPDATE_CHANNEL" = "release
elif test "$MOZ_UPDATE_CHANNEL" = "beta" ; then
ac_add_options --with-leanplum-sdk-keyfile=/builds/leanplum-sdk-beta.token
elif test "$MOZ_UPDATE_CHANNEL" = "nightly" ; then
ac_add_options --with-leanplum-sdk-keyfile=/builds/leanplum-sdk-nightly.token
else
ac_add_options --with-leanplum-sdk-keyfile="$topsrcdir/mobile/android/base/leanplum-sdk-sandbox.token"
fi
+# MOZ_ANDROID_POCKET depends on --with-pocket-api-keyfile, and will
+# fail if MOZ_ANDROID_POCKET is specified but a keyfile is not. We set a default
+# dummy key for non-channel builds, because Pocket is not a critical component.
+if test "$MOZ_UPDATE_CHANNEL" = "release" ; then
+ ac_add_options --with-pocket-api-keyfile=/builds/pocket-api-release.token
+elif test "$MOZ_UPDATE_CHANNEL" = "beta" ; then
+ ac_add_options --with-pocket-api-keyfile=/builds/pocket-api-beta.token
+elif test "$MOZ_UPDATE_CHANNEL" = "nightly" ; then
+ ac_add_options --with-pocket-api-keyfile=/builds/pocket-api-nightly.token
+else
+ ac_add_options --with-pocket-api-keyfile="$topsrcdir/mobile/android/base/pocket-api-sandbox.token"
+fi
+
export SOCORRO_SYMBOL_UPLOAD_TOKEN_FILE=/builds/crash-stats-api.token
# Package js shell.
export MOZ_PACKAGE_JSSHELL=1
# Use ccache
HOST_CC="$topsrcdir/gcc/bin/gcc"
--- a/mobile/android/moz.configure
+++ b/mobile/android/moz.configure
@@ -39,16 +39,23 @@ add_old_configure_assignment('MOZ_INSTAL
option(env='MOZ_ANDROID_MMA',
help='Enable mobile marketing automation (currently using the Leanplum SDK).',
default=False)
set_config('MOZ_ANDROID_MMA',
depends_if('MOZ_ANDROID_MMA')(lambda _: True))
+option(env='MOZ_ANDROID_POCKET',
+ help='Enable Pocket Stories in Activity Stream.',
+ default=True)
+
+set_config('MOZ_ANDROID_POCKET',
+ depends_if('MOZ_ANDROID_POCKET')(lambda _: True))
+
project_flag('MOZ_ANDROID_DOWNLOADS_INTEGRATION',
help='Enable system download manager on Android',
default=True)
project_flag('MOZ_ANDROID_BEAM',
help='Enable NFC permission on Android',
default=True)
@@ -154,8 +161,15 @@ def check_android_mma(android_mma,
die('You must specify MOZ_NATIVE_DEVICES=1 when'
' building with MOZ_ANDROID_MMA=1')
if not android_gcm:
die('You must specify MOZ_ANDROID_GCM=1 when'
' building with MOZ_ANDROID_MMA=1')
if not leanplum_sdk_keyfile:
die('You must specify --with-leanplum-sdk-keyfile=/path/to/keyfile when'
' building with MOZ_ANDROID_MMA=1')
+
+@depends('MOZ_ANDROID_POCKET',
+ '--with-pocket-api-keyfile')
+def check_android_pocket(android_pocket, pocket_api_keyfile):
+ if android_pocket and not pocket_api_keyfile:
+ die('You must specify --with-pocket-api-keyfile=/path/to/keyfile when'
+ ' building with MOZ_ANDROID_POCKET=1')
--- a/toolkit/moz.configure
+++ b/toolkit/moz.configure
@@ -555,16 +555,18 @@ simple_keyfile('Mozilla API')
simple_keyfile('Google API')
id_and_secret_keyfile('Bing API')
simple_keyfile('Adjust SDK')
id_and_secret_keyfile('Leanplum SDK')
+simple_keyfile('Pocket API')
+
# Servo integration
# ==============================================================
option('--enable-stylo', nargs='?', choices=('build',),
help='Include Stylo in the build and/or enable it at runtime')
@depends('--enable-stylo', '--help', target)
def stylo_config(value, _, target):
build_stylo = None