summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AndroidManifest.xml10
-rw-r--r--OWNERS3
-rw-r--r--gallerycommon/src/com/android/gallery3d/common/ApiHelper.java29
-rw-r--r--jni/filters/edge.c4
-rw-r--r--jni/filters/geometry.c12
-rw-r--r--jni/filters/highlight.c2
-rw-r--r--jni/filters/shadows.c2
-rw-r--r--jni/filters/wbalance.c56
-rw-r--r--res/xml/provider_paths.xml19
-rw-r--r--src/com/android/gallery3d/app/MuteVideo.java8
-rw-r--r--src/com/android/gallery3d/app/PhotoPage.java27
-rw-r--r--src/com/android/gallery3d/app/TrimVideo.java8
-rw-r--r--src/com/android/gallery3d/data/LocalVideo.java6
-rw-r--r--src/com/android/gallery3d/data/MtpClient.java2
-rw-r--r--src/com/android/gallery3d/filtershow/FilterShowActivity.java1
-rw-r--r--src/com/android/gallery3d/filtershow/imageshow/ControlPoint.java5
-rw-r--r--src/com/android/gallery3d/filtershow/provider/SharedImageProvider.java35
-rw-r--r--src/com/android/gallery3d/ingest/data/MtpClient.java2
-rw-r--r--src/com/android/gallery3d/ui/ActionModeHandler.java15
-rw-r--r--src/com/android/photos/SelectionManager.java17
20 files changed, 140 insertions, 123 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index b9cf2a7f1..6c78774f0 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -249,6 +249,16 @@
android:name=".filtershow.pipeline.ProcessingService"
android:exported="false" />
+ <provider
+ android:name="androidx.core.content.FileProvider"
+ android:authorities="${applicationId}.provider"
+ android:exported="false"
+ android:grantUriPermissions="true">
+ <meta-data
+ android:name="android.support.FILE_PROVIDER_PATHS"
+ android:resource="@xml/provider_paths" />
+ </provider>
+
<activity
android:name="com.android.gallery3d.filtershow.FilterShowActivity"
android:label="@string/title_activity_filter_show"
diff --git a/OWNERS b/OWNERS
index ed1d60aa5..93b1446ad 100644
--- a/OWNERS
+++ b/OWNERS
@@ -1,3 +1,4 @@
# Default code reviewers picked from top 3 or more developers.
# Please update this list if you find better candidates.
-rtenneti@google.com
+amithds@google.com
+iankaz@google.com
diff --git a/gallerycommon/src/com/android/gallery3d/common/ApiHelper.java b/gallerycommon/src/com/android/gallery3d/common/ApiHelper.java
index f4de5c9ff..d4cf4a96f 100644
--- a/gallerycommon/src/com/android/gallery3d/common/ApiHelper.java
+++ b/gallerycommon/src/com/android/gallery3d/common/ApiHelper.java
@@ -24,7 +24,10 @@ import android.provider.MediaStore.MediaColumns;
import android.view.View;
import android.view.WindowManager;
+import java.lang.ClassNotFoundException;
import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Arrays;
public class ApiHelper {
public static interface VERSION_CODES {
@@ -203,32 +206,32 @@ public class ApiHelper {
}
private static boolean hasField(Class<?> klass, String fieldName) {
- try {
- klass.getDeclaredField(fieldName);
- return true;
- } catch (NoSuchFieldException e) {
- return false;
+ for (Field f : klass.getDeclaredFields()) {
+ if (f.getName().equals(fieldName)) {
+ return true;
+ }
}
+ return false;
}
private static boolean hasMethod(String className, String methodName,
Class<?>... parameterTypes) {
try {
Class<?> klass = Class.forName(className);
- klass.getDeclaredMethod(methodName, parameterTypes);
- return true;
- } catch (Throwable th) {
+ return hasMethod(klass, methodName, parameterTypes);
+ } catch (ClassNotFoundException e) {
return false;
}
}
private static boolean hasMethod(
Class<?> klass, String methodName, Class<?> ... paramTypes) {
- try {
- klass.getDeclaredMethod(methodName, paramTypes);
- return true;
- } catch (NoSuchMethodException e) {
- return false;
+ for (Method method : klass.getDeclaredMethods()) {
+ if (method.getName().equals(methodName) &&
+ Arrays.equals(method.getParameterTypes(), paramTypes)) {
+ return true;
+ }
}
+ return false;
}
}
diff --git a/jni/filters/edge.c b/jni/filters/edge.c
index 5e7be3c4c..75e99a1c9 100644
--- a/jni/filters/edge.c
+++ b/jni/filters/edge.c
@@ -46,7 +46,7 @@ void JNIFUNCF(ImageFilterEdge, nativeApplyFilter, jobject bitmap, jint width, ji
// set initial buffer to black
memset(buf, 0, buf_len * sizeof(char));
for (j = 3; j < buf_len; j+=4) {
- *(buf + j) = 255; // set initial alphas
+ *(buf + j) = (uint8_t) 255; // set initial alphas
}
// apply sobel filter
@@ -120,7 +120,7 @@ void JNIFUNCF(ImageFilterEdge, nativeApplyFilter, jobject bitmap, jint width, ji
int last_row = row_stride * (height - 1);
memset((dst + last_row), 0, row_stride * sizeof(char));
for (j = 3; j < row_stride; j+=4) {
- *(dst + last_row + j) = 255; // set alphas
+ *(dst + last_row + j) = (uint8_t) 255; // set alphas
}
AndroidBitmap_unlockPixels(env, bitmap);
}
diff --git a/jni/filters/geometry.c b/jni/filters/geometry.c
index c2d80f380..023092208 100644
--- a/jni/filters/geometry.c
+++ b/jni/filters/geometry.c
@@ -170,11 +170,13 @@ void JNIFUNCF(ImageFilterGeometry, nativeApplyFilterStraighten, jobject src, jin
AndroidBitmap_lockPixels(env, src, (void**) &source);
AndroidBitmap_lockPixels(env, dst, (void**) &destination);
// TODO: implement straighten
- int i = 0;
- for (; i < len; i += 4) {
- destination[RED] = 128;
- destination[GREEN] = source[GREEN];
- destination[BLUE] = 128;
+ if (source != NULL && destination != NULL) {
+ int i = 0;
+ for (; i < len; i += 4) {
+ destination[RED] = (uint8_t) 128;
+ destination[GREEN] = (uint8_t) source[GREEN];
+ destination[BLUE] = (uint8_t) 128;
+ }
}
AndroidBitmap_unlockPixels(env, dst);
AndroidBitmap_unlockPixels(env, src);
diff --git a/jni/filters/highlight.c b/jni/filters/highlight.c
index 567a216e0..3130f9c71 100644
--- a/jni/filters/highlight.c
+++ b/jni/filters/highlight.c
@@ -27,7 +27,7 @@ void JNIFUNCF(ImageFilterHighlights, nativeApplyFilter, jobject bitmap,
int i;
int len = width * height * 4;
jfloat* lum = (*env)->GetFloatArrayElements(env, luminanceMap,0);
- unsigned short * hsv = (unsigned short *)malloc(3*sizeof(short));
+ unsigned short * hsv = (unsigned short *)malloc(3*sizeof(unsigned short));
for (i = 0; i < len; i+=4)
{
diff --git a/jni/filters/shadows.c b/jni/filters/shadows.c
index 5f802dd21..335b027fb 100644
--- a/jni/filters/shadows.c
+++ b/jni/filters/shadows.c
@@ -40,7 +40,7 @@ void JNIFUNCF(ImageFilterShadows, nativeApplyFilter, jobject bitmap, jint width,
poly[i] = fastevalPoly(shadowFilterMap+i*2,2 , s);
}
- unsigned short * hsv = (unsigned short *)malloc(3*sizeof(short));
+ unsigned short * hsv = (unsigned short *)malloc(3*sizeof(unsigned short));
for (i = 0; i < len; i+=4)
{
diff --git a/jni/filters/wbalance.c b/jni/filters/wbalance.c
index 99a7d2e0d..2ca4c7273 100644
--- a/jni/filters/wbalance.c
+++ b/jni/filters/wbalance.c
@@ -18,7 +18,7 @@
#include "filters.h"
-void estmateWhite(unsigned char *src, int len, int *wr, int *wb, int *wg){
+void estmateWhite(unsigned char *src, int len, int *wr, int *wb, int *wg) {
int STEP = 4;
int RANGE = 256;
@@ -27,7 +27,7 @@ void estmateWhite(unsigned char *src, int len, int *wr, int *wb, int *wg){
int *histB = (int *) malloc(256*sizeof(int));
int i;
for (i = 0; i < 255; i++) {
- histR[i] = histG[i] = histB[i] =0;
+ histR[i] = histG[i] = histB[i] = 0;
}
for (i = 0; i < len; i+=STEP) {
@@ -35,9 +35,8 @@ void estmateWhite(unsigned char *src, int len, int *wr, int *wb, int *wg){
histG[(src[GREEN])]++;
histB[(src[BLUE])]++;
}
- int min_r = -1, min_g = -1,min_b = -1;
- int max_r = 0, max_g = 0,max_b = 0;
- int sum_r = 0,sum_g=0,sum_b=0;
+ int min_r = -1, min_g = -1, min_b = -1;
+ int sum_r = 0, sum_g = 0, sum_b = 0;
for (i = 1; i < RANGE-1; i++) {
int r = histR[i];
@@ -47,25 +46,22 @@ void estmateWhite(unsigned char *src, int len, int *wr, int *wb, int *wg){
sum_g += g;
sum_b += b;
- if (r>0){
- if (min_r < 0) min_r = i;
- max_r = i;
+ if (r > 0 && min_r < 0) {
+ min_r = i;
}
- if (g>0){
- if (min_g < 0) min_g = i;
- max_g = i;
+ if (g > 0 && min_g < 0) {
+ min_g = i;
}
- if (b>0){
- if (min_b < 0) min_b = i;
- max_b = i;
+ if (b > 0 && min_b < 0) {
+ min_b = i;
}
}
- int sum15r = 0,sum15g=0,sum15b=0;
- int count15r = 0,count15g=0,count15b=0;
- int tmp_r = 0,tmp_g=0,tmp_b=0;
+ int sum15r = 0, sum15g = 0, sum15b = 0;
+ int count15r = 0, count15g=0, count15b = 0;
+ int tmp_r = 0, tmp_g = 0, tmp_b = 0;
- for (i = RANGE-2; i >0; i--) {
+ for (i = RANGE-2; i > 0; i--) {
int r = histR[i];
int g = histG[i];
int b = histB[i];
@@ -91,33 +87,33 @@ void estmateWhite(unsigned char *src, int len, int *wr, int *wb, int *wg){
free(histG);
free(histB);
- if ((count15r>0) && (count15g>0) && (count15b>0) ){
+ if ((count15r > 0) && (count15g > 0) && (count15b > 0)) {
*wr = sum15r/count15r;
*wb = sum15g/count15g;
*wg = sum15b/count15b;
- }else {
+ } else {
*wg = *wb = *wr=255;
}
}
-void estmateWhiteBox(unsigned char *src, int iw, int ih, int x,int y, int *wr, int *wb, int *wg){
+void estmateWhiteBox(unsigned char *src, int iw, int ih, int x,int y, int *wr, int *wb, int *wg) {
int r = 0;
int g = 0;
int b = 0;
int sum = 0;
- int xp,yp;
+ int xp, yp;
int bounds = 5;
- if (x<0) x = bounds;
- if (y<0) y = bounds;
- if (x>=(iw-bounds)) x = (iw-bounds-1);
- if (y>=(ih-bounds)) y = (ih-bounds-1);
+ if (x < 0) x = bounds;
+ if (y < 0) y = bounds;
+ if (x >= (iw-bounds)) x = (iw-bounds-1);
+ if (y >= (ih-bounds)) y = (ih-bounds-1);
int startx = x - bounds;
int starty = y - bounds;
int endx = x + bounds;
int endy = y + bounds;
- for(yp= starty;yp<endy;yp++) {
- for(xp= startx;xp<endx;xp++) {
+ for (yp = starty; yp < endy; yp++) {
+ for (xp = startx; xp < endx; xp++) {
int i = 4*(xp+yp*iw);
r += src[RED];
g += src[GREEN];
@@ -141,7 +137,7 @@ void JNIFUNCF(ImageFilterWBalance, nativeApplyFilter, jobject bitmap, jint width
int wg;
int wb;
- if (locX==-1)
+ if (locX == -1)
estmateWhite(rgb,len,&wr,&wg,&wb);
else
estmateWhiteBox(rgb, width, height,locX,locY,&wr,&wg,&wb);
@@ -153,7 +149,7 @@ void JNIFUNCF(ImageFilterWBalance, nativeApplyFilter, jobject bitmap, jint width
float scaleG = avg/wg;
float scaleB = avg/wb;
- for (i = 0; i < len; i+=4)
+ for (i = 0; i < len; i += 4)
{
int r = rgb[RED];
int g = rgb[GREEN];
diff --git a/res/xml/provider_paths.xml b/res/xml/provider_paths.xml
new file mode 100644
index 000000000..5650a8ef4
--- /dev/null
+++ b/res/xml/provider_paths.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2008 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<paths>
+ <external-path name="external_files" path="."/>
+</paths> \ No newline at end of file
diff --git a/src/com/android/gallery3d/app/MuteVideo.java b/src/com/android/gallery3d/app/MuteVideo.java
index d3f3aa594..8fc42f154 100644
--- a/src/com/android/gallery3d/app/MuteVideo.java
+++ b/src/com/android/gallery3d/app/MuteVideo.java
@@ -24,6 +24,8 @@ import android.os.Handler;
import android.provider.MediaStore;
import android.widget.Toast;
+import androidx.core.content.FileProvider;
+
import com.android.gallery3d.R;
import com.android.gallery3d.data.MediaItem;
import com.android.gallery3d.util.SaveVideoFileInfo;
@@ -83,7 +85,11 @@ public class MuteVideo {
// Show the result only when the activity not
// stopped.
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
- intent.setDataAndType(Uri.fromFile(mDstFileInfo.mFile), "video/*");
+ Uri videoUri = FileProvider.getUriForFile(
+ mActivity,
+ mActivity.getApplicationContext().getPackageName()
+ + ".provider", mDstFileInfo.mFile);
+ intent.setDataAndType(videoUri, "video/*");
intent.putExtra(MediaStore.EXTRA_FINISH_ON_COMPLETION, false);
mActivity.startActivity(intent);
}
diff --git a/src/com/android/gallery3d/app/PhotoPage.java b/src/com/android/gallery3d/app/PhotoPage.java
index f2d568ec4..4659692c4 100644
--- a/src/com/android/gallery3d/app/PhotoPage.java
+++ b/src/com/android/gallery3d/app/PhotoPage.java
@@ -26,9 +26,6 @@ import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Rect;
import android.net.Uri;
-import android.nfc.NfcAdapter;
-import android.nfc.NfcAdapter.CreateBeamUrisCallback;
-import android.nfc.NfcEvent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
@@ -179,8 +176,6 @@ public abstract class PhotoPage extends ActivityState implements
private Path mDeletePath;
private boolean mDeleteIsFocus; // whether the deleted item was in focus
- private Uri[] mNfcPushUris = new Uri[1];
-
private final MyMenuVisibilityListener mMenuVisibilityListener =
new MyMenuVisibilityListener();
@@ -364,7 +359,6 @@ public abstract class PhotoPage extends ActivityState implements
Intent shareIntent = createShareIntent(mCurrentPhoto);
mActionBar.setShareIntents(panoramaIntent, shareIntent, PhotoPage.this);
- setNfcBeamPushUri(contentUri);
}
break;
}
@@ -383,7 +377,6 @@ public abstract class PhotoPage extends ActivityState implements
mSetPathString = data.getString(KEY_MEDIA_SET_PATH);
mReadOnlyView = data.getBoolean(KEY_READONLY);
mOriginalSetPathString = mSetPathString;
- setupNfcBeamPush();
String itemPathString = data.getString(KEY_MEDIA_ITEM_PATH);
Path itemPath = itemPathString != null ?
Path.fromString(data.getString(KEY_MEDIA_ITEM_PATH)) :
@@ -617,26 +610,6 @@ public abstract class PhotoPage extends ActivityState implements
}
}
- @TargetApi(ApiHelper.VERSION_CODES.JELLY_BEAN)
- private void setupNfcBeamPush() {
- if (!ApiHelper.HAS_SET_BEAM_PUSH_URIS) return;
-
- NfcAdapter adapter = NfcAdapter.getDefaultAdapter(mActivity);
- if (adapter != null) {
- adapter.setBeamPushUris(null, mActivity);
- adapter.setBeamPushUrisCallback(new CreateBeamUrisCallback() {
- @Override
- public Uri[] createBeamUris(NfcEvent event) {
- return mNfcPushUris;
- }
- }, mActivity);
- }
- }
-
- private void setNfcBeamPushUri(Uri uri) {
- mNfcPushUris[0] = uri;
- }
-
private static Intent createShareIntent(MediaObject mediaObject) {
int type = mediaObject.getMediaType();
return new Intent(Intent.ACTION_SEND)
diff --git a/src/com/android/gallery3d/app/TrimVideo.java b/src/com/android/gallery3d/app/TrimVideo.java
index b0ed8e635..a064e6039 100644
--- a/src/com/android/gallery3d/app/TrimVideo.java
+++ b/src/com/android/gallery3d/app/TrimVideo.java
@@ -33,6 +33,8 @@ import android.widget.TextView;
import android.widget.Toast;
import android.widget.VideoView;
+import androidx.core.content.FileProvider;
+
import com.android.gallery3d.R;
import com.android.gallery3d.util.SaveVideoFileInfo;
import com.android.gallery3d.util.SaveVideoFileUtils;
@@ -261,7 +263,11 @@ public class TrimVideo extends Activity implements
mProgress = null;
// Show the result only when the activity not stopped.
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
- intent.setDataAndType(Uri.fromFile(mDstFileInfo.mFile), "video/*");
+ Uri videoUri = FileProvider.getUriForFile(
+ TrimVideo.this,
+ getApplicationContext().getPackageName()
+ + ".provider", mDstFileInfo.mFile);
+ intent.setDataAndType(videoUri, "video/*");
intent.putExtra(MediaStore.EXTRA_FINISH_ON_COMPLETION, false);
startActivity(intent);
finish();
diff --git a/src/com/android/gallery3d/data/LocalVideo.java b/src/com/android/gallery3d/data/LocalVideo.java
index 4b8774ca4..ed39de63e 100644
--- a/src/com/android/gallery3d/data/LocalVideo.java
+++ b/src/com/android/gallery3d/data/LocalVideo.java
@@ -117,7 +117,11 @@ public class LocalVideo extends LocalMediaItem {
private void parseResolution(String resolution) {
if (resolution == null) return;
int m = resolution.indexOf('x');
- if (m == -1) return;
+ if (m == -1) {
+ // Fix b/216176283 - Handle special character '×' in the resolution.
+ m = resolution.indexOf('×');
+ if (m == -1) return;
+ }
try {
int w = Integer.parseInt(resolution.substring(0, m));
int h = Integer.parseInt(resolution.substring(m + 1));
diff --git a/src/com/android/gallery3d/data/MtpClient.java b/src/com/android/gallery3d/data/MtpClient.java
index 737b5b60d..0b25bf975 100644
--- a/src/com/android/gallery3d/data/MtpClient.java
+++ b/src/com/android/gallery3d/data/MtpClient.java
@@ -172,7 +172,7 @@ public class MtpClient {
filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
filter.addAction(ACTION_USB_PERMISSION);
- context.registerReceiver(mUsbReceiver, filter);
+ context.registerReceiver(mUsbReceiver, filter, Context.RECEIVER_EXPORTED/*UNAUDITED*/);
}
/**
diff --git a/src/com/android/gallery3d/filtershow/FilterShowActivity.java b/src/com/android/gallery3d/filtershow/FilterShowActivity.java
index e827b82aa..4542c1972 100644
--- a/src/com/android/gallery3d/filtershow/FilterShowActivity.java
+++ b/src/com/android/gallery3d/filtershow/FilterShowActivity.java
@@ -1383,6 +1383,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
SELECT_PICTURE);
}
+ @SuppressWarnings("MissingSuperCall") // TODO: Fix me
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
diff --git a/src/com/android/gallery3d/filtershow/imageshow/ControlPoint.java b/src/com/android/gallery3d/filtershow/imageshow/ControlPoint.java
index aaec728a6..cc1f1af5d 100644
--- a/src/com/android/gallery3d/filtershow/imageshow/ControlPoint.java
+++ b/src/com/android/gallery3d/filtershow/imageshow/ControlPoint.java
@@ -16,7 +16,7 @@
package com.android.gallery3d.filtershow.imageshow;
-public class ControlPoint implements Comparable {
+public class ControlPoint implements Comparable<ControlPoint> {
public float x;
public float y;
@@ -52,8 +52,7 @@ public class ControlPoint implements Comparable {
}
@Override
- public int compareTo(Object another) {
- ControlPoint p = (ControlPoint) another;
+ public int compareTo(ControlPoint p) {
if (p.x < x) {
return 1;
} else if (p.x > x) {
diff --git a/src/com/android/gallery3d/filtershow/provider/SharedImageProvider.java b/src/com/android/gallery3d/filtershow/provider/SharedImageProvider.java
index bc17a6e03..fc7ec608e 100644
--- a/src/com/android/gallery3d/filtershow/provider/SharedImageProvider.java
+++ b/src/com/android/gallery3d/filtershow/provider/SharedImageProvider.java
@@ -29,16 +29,20 @@ import android.provider.OpenableColumns;
import java.io.File;
import java.io.FileNotFoundException;
+import java.io.IOException;
public class SharedImageProvider extends ContentProvider {
private static final String LOGTAG = "SharedImageProvider";
public static final String MIME_TYPE = "image/jpeg";
- public static final String AUTHORITY = "com.android.gallery3d.filtershow.provider.SharedImageProvider";
+ public static final String AUTHORITY =
+ "com.android.gallery3d.filtershow.provider.SharedImageProvider";
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/image");
public static final String PREPARE = "prepare";
+ public static String LOCAL_PATH = (new File(CONTENT_URI.getPath())).getAbsolutePath();
+
private final String[] mMimeStreamType = {
MIME_TYPE
};
@@ -83,13 +87,14 @@ public class SharedImageProvider extends ContentProvider {
}
@Override
- public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
+ public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
+ String sortOrder) {
String uriPath = uri.getLastPathSegment();
if (uriPath == null) {
return null;
}
if (projection == null) {
- projection = new String[] {
+ projection = new String[]{
BaseColumns._ID,
MediaStore.MediaColumns.DATA,
OpenableColumns.DISPLAY_NAME,
@@ -130,8 +135,32 @@ public class SharedImageProvider extends ContentProvider {
// Here we need to block until the image is ready
mImageReadyCond.block();
File path = new File(uriPath);
+ ensureValidImagePath(path);
int imode = 0;
imode |= ParcelFileDescriptor.MODE_READ_ONLY;
return ParcelFileDescriptor.open(path, imode);
}
+
+ /**
+ * Ensure that the provided file path is part of the image directory.
+ * Prevent unauthorized access to other directories by path traversal.
+ * Throw security exception for paths outside the directory.
+ *
+ * @param path The path of the file to check. This path is expected to point to the image
+ * directory.
+ * @throws SecurityException Throws SecurityException if the path is not part of the image
+ * directory.
+ * @throws FileNotFoundException Throws FileNotFoundException if there is
+ * no file associated with the given URI.
+ */
+ private void ensureValidImagePath(File path) throws FileNotFoundException {
+ try {
+ if (!path.getCanonicalPath().startsWith(LOCAL_PATH)) {
+ throw new SecurityException(
+ "The requested file path is not part of the image directory");
+ }
+ } catch (IOException e) {
+ throw new FileNotFoundException(e.getMessage());
+ }
+ }
}
diff --git a/src/com/android/gallery3d/ingest/data/MtpClient.java b/src/com/android/gallery3d/ingest/data/MtpClient.java
index cc6c9ce07..3943a6d5c 100644
--- a/src/com/android/gallery3d/ingest/data/MtpClient.java
+++ b/src/com/android/gallery3d/ingest/data/MtpClient.java
@@ -170,7 +170,7 @@ public class MtpClient {
filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
filter.addAction(ACTION_USB_PERMISSION);
- context.registerReceiver(mUsbReceiver, filter);
+ context.registerReceiver(mUsbReceiver, filter, Context.RECEIVER_EXPORTED/*UNAUDITED*/);
}
/**
diff --git a/src/com/android/gallery3d/ui/ActionModeHandler.java b/src/com/android/gallery3d/ui/ActionModeHandler.java
index 6b4f10312..b5a819c70 100644
--- a/src/com/android/gallery3d/ui/ActionModeHandler.java
+++ b/src/com/android/gallery3d/ui/ActionModeHandler.java
@@ -20,7 +20,6 @@ import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
-import android.nfc.NfcAdapter;
import android.os.Handler;
import android.view.ActionMode;
import android.view.ActionMode.Callback;
@@ -67,7 +66,6 @@ public class ActionModeHandler implements Callback, PopupList.OnPopupItemClickLi
private final AbstractGalleryActivity mActivity;
private final MenuExecutor mMenuExecutor;
private final SelectionManager mSelectionManager;
- private final NfcAdapter mNfcAdapter;
private Menu mMenu;
private MenuItem mSharePanoramaMenuItem;
private MenuItem mShareMenuItem;
@@ -128,7 +126,6 @@ public class ActionModeHandler implements Callback, PopupList.OnPopupItemClickLi
mSelectionManager = Utils.checkNotNull(selectionManager);
mMenuExecutor = new MenuExecutor(activity, selectionManager);
mMainHandler = new Handler(activity.getMainLooper());
- mNfcAdapter = NfcAdapter.getDefaultAdapter(mActivity.getAndroidContext());
}
public void startActionMode() {
@@ -307,14 +304,6 @@ public class ActionModeHandler implements Callback, PopupList.OnPopupItemClickLi
return operation;
}
- @TargetApi(ApiHelper.VERSION_CODES.JELLY_BEAN)
- private void setNfcBeamPushUris(Uri[] uris) {
- if (mNfcAdapter != null && ApiHelper.HAS_SET_BEAM_PUSH_URIS) {
- mNfcAdapter.setBeamPushUrisCallback(null, mActivity);
- mNfcAdapter.setBeamPushUris(uris, mActivity);
- }
- }
-
// Share intent needs to expand the selection set so we can get URI of
// each media item
private Intent computePanoramaSharingIntent(JobContext jc, int maxItems) {
@@ -350,7 +339,6 @@ public class ActionModeHandler implements Callback, PopupList.OnPopupItemClickLi
private Intent computeSharingIntent(JobContext jc, int maxItems) {
ArrayList<Path> expandedPaths = mSelectionManager.getSelected(true, maxItems);
if (expandedPaths == null || expandedPaths.size() == 0) {
- setNfcBeamPushUris(null);
return new Intent();
}
final ArrayList<Uri> uris = new ArrayList<Uri>();
@@ -378,9 +366,6 @@ public class ActionModeHandler implements Callback, PopupList.OnPopupItemClickLi
intent.putExtra(Intent.EXTRA_STREAM, uris.get(0));
}
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
- setNfcBeamPushUris(uris.toArray(new Uri[uris.size()]));
- } else {
- setNfcBeamPushUris(null);
}
return intent;
diff --git a/src/com/android/photos/SelectionManager.java b/src/com/android/photos/SelectionManager.java
index 98b827bb3..eccf73f0c 100644
--- a/src/com/android/photos/SelectionManager.java
+++ b/src/com/android/photos/SelectionManager.java
@@ -19,13 +19,9 @@ package com.android.photos;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
-import android.nfc.NfcAdapter;
-import android.nfc.NfcAdapter.CreateBeamUrisCallback;
-import android.nfc.NfcEvent;
import android.provider.MediaStore.Files.FileColumns;
import android.widget.ShareActionProvider;
-import com.android.gallery3d.common.ApiHelper;
import com.android.gallery3d.data.MediaObject;
import com.android.gallery3d.util.GalleryUtils;
@@ -33,7 +29,6 @@ import java.util.ArrayList;
public class SelectionManager {
private Activity mActivity;
- private NfcAdapter mNfcAdapter;
private SelectedUriSource mUriSource;
private Intent mShareIntent = new Intent();
@@ -43,18 +38,6 @@ public class SelectionManager {
public SelectionManager(Activity activity) {
mActivity = activity;
- if (ApiHelper.AT_LEAST_16) {
- mNfcAdapter = NfcAdapter.getDefaultAdapter(mActivity);
- mNfcAdapter.setBeamPushUrisCallback(new CreateBeamUrisCallback() {
- @Override
- public Uri[] createBeamUris(NfcEvent arg0) {
- // This will have been preceded by a call to onItemSelectedStateChange
- if (mCachedShareableUris == null) return null;
- return mCachedShareableUris.toArray(
- new Uri[mCachedShareableUris.size()]);
- }
- }, mActivity);
- }
}
public void setSelectedUriSource(SelectedUriSource source) {