blob: a9034e6b7592551af38424bf40f0ecc6f4f5e65c [file] [log] [blame]
Santiago Etchebehere8e9a8472018-07-24 14:30:21 -07001package com.android.wallpaper.asset;
2
3import android.support.media.ExifInterface;
4
5import com.android.wallpaper.compat.BuildCompat;
6
7import java.io.IOException;
8import java.io.InputStream;
9
10/**
11 * Provides access to basic ExifInterface APIs using {@link android.media.ExifInterface} in OMR1+
12 * SDK or SupportLibrary's {@link ExifInterface} for earlier SDK versions.
13 */
14class ExifInterfaceCompat {
15
16 public static final String TAG_ORIENTATION = ExifInterface.TAG_ORIENTATION;
17 public static final int EXIF_ORIENTATION_NORMAL = 1;
18 public static final int EXIF_ORIENTATION_UNKNOWN = -1;
19
20 private ExifInterface mSupportExifInterface;
21 private android.media.ExifInterface mFrameworkExifInterface;
22
23 /**
24 * Reads Exif tags from the specified image input stream. It's the caller's responsibility to
25 * close the given InputStream after use.
26 * @see ExifInterface#ExifInterface(InputStream)
27 * @see android.media.ExifInterface#ExifInterface(InputStream)
28 */
29 public ExifInterfaceCompat(InputStream inputStream) throws IOException {
30 // O-MR1 added support for more formats (HEIF), which Support Library cannot implement,
31 // so use the framework version for SDK 27+
32 if (BuildCompat.isAtLeastOMR1()) {
33 mFrameworkExifInterface = new android.media.ExifInterface(inputStream);
34 } else {
35 mSupportExifInterface = new ExifInterface(inputStream);
36 }
37 }
38
39 public int getAttributeInt(String tag, int defaultValue) {
40 return mFrameworkExifInterface != null
41 ? mFrameworkExifInterface.getAttributeInt(tag, defaultValue)
42 : mSupportExifInterface.getAttributeInt(tag, defaultValue);
43 }
44
45 public String getAttribute(String tag) {
46 return mFrameworkExifInterface != null
47 ? mFrameworkExifInterface.getAttribute(tag)
48 : mSupportExifInterface.getAttribute(tag);
49 }
50}