Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2707)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/AllDismissedItem.java

Issue 2778743002: 📰 Handle ReadFromDisk violations in AllDismissed item (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/android/javatests/src/org/chromium/chrome/browser/suggestions/TileGroupTest.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/AllDismissedItem.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/AllDismissedItem.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/AllDismissedItem.java
index a5f11e05ff91002ad78f4c3a8fa2198dc3509935..fe6c0641ab39e9f6718e91ffa0a2efece5d35661 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/AllDismissedItem.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/AllDismissedItem.java
@@ -4,6 +4,7 @@
package org.chromium.chrome.browser.ntp.cards;
+import android.os.StrictMode;
import android.support.annotation.StringRes;
import android.view.LayoutInflater;
import android.view.View;
@@ -58,7 +59,7 @@ public void onClick(View v) {
}
public void onBindViewHolder() {
- int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
+ int hour = safelyGetCalendar().get(Calendar.HOUR_OF_DAY);
@StringRes
int messageId;
if (hour >= 0 && hour < 12) {
@@ -70,5 +71,18 @@ public void onBindViewHolder() {
}
mBodyTextView.setText(messageId);
}
+
+ /**
+ * Returns a {@link Calendar} instance in a way that does not trigger StrictMode violations
+ * during instrumentation tests. See https://crbug.com/705477 and http://crbug.com/577185
Bernhard Bauer 2017/03/27 11:57:40 Nit: https for both links :)
+ */
+ private static Calendar safelyGetCalendar() {
+ StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
+ try {
+ return Calendar.getInstance();
+ } finally {
+ StrictMode.setThreadPolicy(oldPolicy);
+ }
+ }
}
}
« no previous file with comments | « no previous file | chrome/android/javatests/src/org/chromium/chrome/browser/suggestions/TileGroupTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698