[MediaWiki-commits] [Gerrit] Avoid StackOverflowError when initializing channel preference - change (apps...wikipedia)
Dbrant has submitted this change and it was merged. Change subject: Avoid StackOverflowError when initializing channel preference .. Avoid StackOverflowError when initializing channel preference No recursion of getChannel() anymore. Bug: T78833 Change-Id: Idd8fd49002bc24750b6a1fa0f8550350cd53ee29 --- M wikipedia/src/main/java/org/wikipedia/Utils.java 1 file changed, 6 insertions(+), 12 deletions(-) Approvals: Dbrant: Looks good to me, approved diff --git a/wikipedia/src/main/java/org/wikipedia/Utils.java b/wikipedia/src/main/java/org/wikipedia/Utils.java index da00f1e..b93ebaf 100644 --- a/wikipedia/src/main/java/org/wikipedia/Utils.java +++ b/wikipedia/src/main/java/org/wikipedia/Utils.java @@ -676,10 +676,9 @@ /** * Returns the distribution channel for the app from AndroidManifest.xml - * @param ctx * @return The channel (the empty string if not defined) */ -public static String getChannelDescriptor(Context ctx) { +private static String getChannelDescriptor(Context ctx) { try { ApplicationInfo a = ctx.getPackageManager().getApplicationInfo(ctx.getPackageName(), PackageManager.GET_META_DATA); String channel = a.metaData.getString(PrefKeys.getChannel()); @@ -692,27 +691,22 @@ /** * Sets the distribution channel for the app into SharedPreferences - * @param ctx */ -public static void setChannel(Context ctx) { +private static void setChannel(Context ctx, String channel) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx); -String channel = getChannelDescriptor(ctx); prefs.edit().putString(PrefKeys.getChannel(), channel).apply(); } /** * Gets the distribution channel for the app from SharedPreferences - * @param ctx */ public static String getChannel(Context ctx) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx); String channel = prefs.getString(PrefKeys.getChannel(), null); -if (channel != null) { -return channel; -} else { -setChannel(ctx); -return getChannel(ctx); +if (channel == null) { +channel = getChannelDescriptor(ctx); +setChannel(ctx, channel); } +return channel; } - } -- To view, visit https://gerrit.wikimedia.org/r/180652 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Idd8fd49002bc24750b6a1fa0f8550350cd53ee29 Gerrit-PatchSet: 1 Gerrit-Project: apps/android/wikipedia Gerrit-Branch: master Gerrit-Owner: BearND Gerrit-Reviewer: Brion VIBBER Gerrit-Reviewer: Dbrant Gerrit-Reviewer: jenkins-bot <> ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] Avoid StackOverflowError when initializing channel preference - change (apps...wikipedia)
BearND has uploaded a new change for review. https://gerrit.wikimedia.org/r/180652 Change subject: Avoid StackOverflowError when initializing channel preference .. Avoid StackOverflowError when initializing channel preference No recursion of getChannel() anymore. Bug: T78833 Change-Id: Idd8fd49002bc24750b6a1fa0f8550350cd53ee29 --- M wikipedia/src/main/java/org/wikipedia/Utils.java 1 file changed, 6 insertions(+), 12 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia refs/changes/52/180652/1 diff --git a/wikipedia/src/main/java/org/wikipedia/Utils.java b/wikipedia/src/main/java/org/wikipedia/Utils.java index da00f1e..b93ebaf 100644 --- a/wikipedia/src/main/java/org/wikipedia/Utils.java +++ b/wikipedia/src/main/java/org/wikipedia/Utils.java @@ -676,10 +676,9 @@ /** * Returns the distribution channel for the app from AndroidManifest.xml - * @param ctx * @return The channel (the empty string if not defined) */ -public static String getChannelDescriptor(Context ctx) { +private static String getChannelDescriptor(Context ctx) { try { ApplicationInfo a = ctx.getPackageManager().getApplicationInfo(ctx.getPackageName(), PackageManager.GET_META_DATA); String channel = a.metaData.getString(PrefKeys.getChannel()); @@ -692,27 +691,22 @@ /** * Sets the distribution channel for the app into SharedPreferences - * @param ctx */ -public static void setChannel(Context ctx) { +private static void setChannel(Context ctx, String channel) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx); -String channel = getChannelDescriptor(ctx); prefs.edit().putString(PrefKeys.getChannel(), channel).apply(); } /** * Gets the distribution channel for the app from SharedPreferences - * @param ctx */ public static String getChannel(Context ctx) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx); String channel = prefs.getString(PrefKeys.getChannel(), null); -if (channel != null) { -return channel; -} else { -setChannel(ctx); -return getChannel(ctx); +if (channel == null) { +channel = getChannelDescriptor(ctx); +setChannel(ctx, channel); } +return channel; } - } -- To view, visit https://gerrit.wikimedia.org/r/180652 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Idd8fd49002bc24750b6a1fa0f8550350cd53ee29 Gerrit-PatchSet: 1 Gerrit-Project: apps/android/wikipedia Gerrit-Branch: master Gerrit-Owner: BearND ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits