• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.android.wallpaper.asset;
2 
3 import com.android.wallpaper.compat.BuildCompat;
4 
5 import java.io.IOException;
6 import java.io.InputStream;
7 
8 import androidx.exifinterface.media.ExifInterface;
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  */
14 class 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      */
ExifInterfaceCompat(InputStream inputStream)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 
getAttributeInt(String tag, int defaultValue)39     public int getAttributeInt(String tag, int defaultValue) {
40         return mFrameworkExifInterface != null
41                 ? mFrameworkExifInterface.getAttributeInt(tag, defaultValue)
42                 : mSupportExifInterface.getAttributeInt(tag, defaultValue);
43     }
44 
getAttribute(String tag)45     public String getAttribute(String tag) {
46         return mFrameworkExifInterface != null
47                 ? mFrameworkExifInterface.getAttribute(tag)
48                 : mSupportExifInterface.getAttribute(tag);
49     }
50 }
51