【发布时间】:2014-03-21 13:04:47
【问题描述】:
在BitmapFactory.decodeStream方法中:
public static Bitmap decodeStream(InputStream is, Rect outPadding, Options opts) {
// we don't throw in this case, thus allowing the caller to only check
// the cache, and not force the image to be decoded.
if (is == null) {
return null;
}
Bitmap bm = null;
Trace.traceBegin(Trace.TRACE_TAG_GRAPHICS, "decodeBitmap");
try {
if (is instanceof AssetManager.AssetInputStream) {
final int asset = ((AssetManager.AssetInputStream) is).getAssetInt();
bm = nativeDecodeAsset(asset, outPadding, opts);
} else {
bm = decodeStreamInternal(is, outPadding, opts);
}
if (bm == null && opts != null && opts.inBitmap != null) {
throw new IllegalArgumentException("Problem decoding into existing bitmap");
}
setDensityFromOptions(bm, opts);
} finally {
Trace.traceEnd(Trace.TRACE_TAG_GRAPHICS); // THAT IS COLLISION LINE
}
return bm;
}
我们看到Trace.TRACE_TAG_GRAPHICS 的用法。好的,我们来看看Trace.java:
public final class Trace {
/*
* Writes trace events to the kernel trace buffer. These trace events can be
* collected using the "atrace" program for offline analysis.
*/
private static final String TAG = "Trace";
// These tags must be kept in sync with system/core/include/cutils/trace.h.
/** @hide */
public static final long TRACE_TAG_NEVER = 0;
/** @hide */
public static final long TRACE_TAG_ALWAYS = 1L << 0;
/** @hide */
public static final long TRACE_TAG_GRAPHICS = 1L << 1;
...
当我尝试使用Trace.TRACE_TAG_GRAPHICS 标志编译器给我错误,这个标签不对我负责。我同意他的看法。
但问题是 - 为什么 BitmapFactory 可以访问 @hide 变量,而为什么我不能?
【问题讨论】:
-
这就是@hide 所做的。它可以防止第三方开发人员访问框架中的内容。
-
因为编译了常规和未隐藏的 android 版本,我可以告诉你一个事实,@hide 的东西不包含在已发布的 API 中。 (您可以自己看到,因为您可以看到您无法针对它们进行编译)
-
这是一个不重复的问题......
-
我认为,重复问题的答案确实回答了您的问题。