From 030eeeee6d1c1cdba4a85557f78ab1ee6571901c Mon Sep 17 00:00:00 2001 From: Salvador Martinez Date: Wed, 24 Aug 2016 15:11:21 -0700 Subject: [PATCH] Added guard to logging in AsyncTask An async task was trying to get the context in an InstrumentedFragment. This could return null if the context disappears before the new thread gets to that line. Logging will now be aborted if context is null to avoid this. Test: Manual/Monkey Stability Test Bug: 31058928 Change-Id: Iae97d389e58a76b0f213a2749415501894ebf649 (cherry picked from commit 566b66e27c69fbf48860f367781800442c5110e7) --- src/com/android/settings/dashboard/DashboardSummary.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/com/android/settings/dashboard/DashboardSummary.java b/src/com/android/settings/dashboard/DashboardSummary.java index 12f036a12cb..e0f727fc14c 100644 --- a/src/com/android/settings/dashboard/DashboardSummary.java +++ b/src/com/android/settings/dashboard/DashboardSummary.java @@ -236,17 +236,18 @@ public class DashboardSummary extends InstrumentedFragment @Override protected List doInBackground(Void... params) { + final Context context = getContext(); List suggestions = mSuggestionParser.getSuggestions(); for (int i = 0; i < suggestions.size(); i++) { Tile suggestion = suggestions.get(i); if (mSuggestionsChecks.isSuggestionComplete(suggestion)) { mAdapter.disableSuggestion(suggestion); suggestions.remove(i--); - } else { - String id = DashboardAdapter.getSuggestionIdentifier(getContext(), suggestion); + } else if (context != null) { + String id = DashboardAdapter.getSuggestionIdentifier(context, suggestion); if (!mSuggestionsShownLogged.contains(id)) { mSuggestionsShownLogged.add(id); - MetricsLogger.action(getContext(), + MetricsLogger.action(context, MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION, id); } }