Skip to content

Commit

Permalink
fix using deprecated constants in Android API Level 29
Browse files Browse the repository at this point in the history
Summary:
Changelog: [Internal]

# Context

FB4A recently updated from [Android API level 28 to level 29](https://fb.workplace.com/groups/782862961920333/permalink/1409529345920355/). This [deprecated](https://developer.android.com/reference/android/provider/MediaStore.Images.ImageColumns#LATITUDE) the constants `Images.Media.Latitude` and `Image.Media.Longitude`, and we started to get the exception found in the attached task.

# This diff

Similar to this [pull request](react-native-cameraroll/react-native-cameraroll#170), it removes the usage of the deprecated latitude and longitude constants. However for our case I don't know if latitude and longitude are being used or not, so for this diff I will check on the Android API level before adding the latitude and longitude in the project list. This is a similar implementation to the [first version](react-native-cameraroll/react-native-cameraroll@adeeb3e) of the above pull request where it checks the api level before extracting the location data.

Differential Revision: D21774607

fbshipit-source-id: 632ea871b530b8e157f4ca74a5bc319b2abf7ba5
  • Loading branch information
Danny Yan authored and facebook-github-bot committed May 29, 2020
1 parent 5d39bfa commit f29238c
Showing 1 changed file with 29 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import android.media.MediaScannerConnection;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Environment;
import android.provider.MediaStore;
import android.provider.MediaStore.Images;
Expand Down Expand Up @@ -47,6 +48,7 @@
import java.nio.channels.FileChannel;
import java.nio.channels.ReadableByteChannel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

// TODO #6015104: rename to something less iOSish
Expand All @@ -68,22 +70,33 @@ public class CameraRollManager extends NativeCameraRollManagerSpec {
private static final String ASSET_TYPE_VIDEOS = "Videos";
private static final String ASSET_TYPE_ALL = "All";

private static final String[] PROJECTION = {
Images.Media._ID,
Images.Media.MIME_TYPE,
Images.Media.BUCKET_DISPLAY_NAME,
Images.Media.DATE_TAKEN,
MediaStore.MediaColumns.WIDTH,
MediaStore.MediaColumns.HEIGHT,
Images.Media.LONGITUDE,
Images.Media.LATITUDE,
MediaStore.MediaColumns.DATA
};

private static final String SELECTION_BUCKET = Images.Media.BUCKET_DISPLAY_NAME + " = ?";
private static final String SELECTION_DATE_TAKEN = Images.Media.DATE_TAKEN + " < ?";
private static final String SELECTION_MEDIA_SIZE = Images.Media.SIZE + " < ?";

private static final int IMAGES_MEDIA_LATITUDE_LONGITUDE_DEPRECATED_API_LEVEL = 29;
private static final String[] PROJECTION_LIST;

static {
ArrayList<String> projection_list =
new ArrayList<>(
Arrays.asList(
Images.Media._ID,
Images.Media.MIME_TYPE,
Images.Media.BUCKET_DISPLAY_NAME,
Images.Media.DATE_TAKEN,
MediaStore.MediaColumns.WIDTH,
MediaStore.MediaColumns.HEIGHT,
MediaStore.MediaColumns.DATA));
if (Build.VERSION.SDK_INT < IMAGES_MEDIA_LATITUDE_LONGITUDE_DEPRECATED_API_LEVEL) {
projection_list.add(Images.Media.LATITUDE);
projection_list.add(Images.Media.LONGITUDE);
PROJECTION_LIST = projection_list.toArray(new String[0]);
} else {
PROJECTION_LIST = projection_list.toArray(new String[0]);
}
}

public CameraRollManager(ReactApplicationContext reactContext) {
super(reactContext);
}
Expand Down Expand Up @@ -351,7 +364,7 @@ protected void doInBackgroundGuarded(Void... params) {
Cursor media =
resolver.query(
MediaStore.Files.getContentUri("external"),
PROJECTION,
PROJECTION_LIST,
selection.toString(),
selectionArgs.toArray(new String[selectionArgs.size()]),
Images.Media.DATE_TAKEN
Expand Down Expand Up @@ -413,7 +426,9 @@ private static void putEdges(
resolver, media, node, idIndex, widthIndex, heightIndex, dataIndex, mimeTypeIndex);
if (imageInfoSuccess) {
putBasicNodeInfo(media, node, mimeTypeIndex, groupNameIndex, dateTakenIndex);
putLocationInfo(media, node, longitudeIndex, latitudeIndex);
if (Build.VERSION.SDK_INT < IMAGES_MEDIA_LATITUDE_LONGITUDE_DEPRECATED_API_LEVEL) {
putLocationInfo(media, node, longitudeIndex, latitudeIndex);
}

edge.putMap("node", node);
edges.pushMap(edge);
Expand Down

0 comments on commit f29238c

Please sign in to comment.