From 9d46a01e044696eb4d101778992fed4966520251 Mon Sep 17 00:00:00 2001 From: Mark Wei Date: Thu, 17 Oct 2013 13:50:19 -0700 Subject: Trace without reflection. Avoid crashing on ICS. Change-Id: Ic75143a38d252278329a6f775c137ff1321eaf28 --- src/com/android/bitmap/util/Trace.java | 55 ++++++++++++++-------------------- 1 file changed, 23 insertions(+), 32 deletions(-) (limited to 'src/com') diff --git a/src/com/android/bitmap/util/Trace.java b/src/com/android/bitmap/util/Trace.java index e303d72..63d02cd 100644 --- a/src/com/android/bitmap/util/Trace.java +++ b/src/com/android/bitmap/util/Trace.java @@ -16,45 +16,36 @@ package com.android.bitmap.util; -import java.lang.reflect.Method; +import android.os.Build; -public class Trace { - - private static Method sBegin; - private static Method sEnd; - - public static void init() { - if (sBegin != null && sEnd != null) { - return; - } - try { - final Class cls = Class.forName("android.os.Trace"); - sBegin = cls.getMethod("beginSection", String.class); - sEnd = cls.getMethod("endSection"); - } catch (Exception e) { - e.printStackTrace(); - } - } +/** + * Stand-in for {@link android.os.Trace}. + */ +public abstract class Trace { + /** + * Begins systrace tracing for a given tag. No-op on unsupported platform versions. + * + * @param tag systrace tag to use + * + * @see android.os.Trace#beginSection(String) + */ public static void beginSection(String tag) { - if (sBegin == null) { - return; - } - try { - sBegin.invoke(null, tag); - } catch (Exception e) { - e.printStackTrace(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { + android.os.Trace.beginSection(tag); } } + /** + * Ends systrace tracing for the most recently begun section. No-op on unsupported platform + * versions. + * + * @see android.os.Trace#endSection() + */ public static void endSection() { - if (sEnd == null) { - return; - } - try { - sEnd.invoke(null, (Object[]) null); - } catch (Exception e) { - e.printStackTrace(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { + android.os.Trace.endSection(); } } + } -- cgit v1.2.3