Snap for 10447354 from 23275881d49f316717b283105f826393ef27fe6b to mainline-cellbroadcast-release

Change-Id: I032c5018c3306e64b11033a16ca715c0fd06d004
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index b9cf2a7..6c78774 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 ed1d60a..93b1446 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 f4de5c9..d4cf4a9 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.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 @@
     }
 
     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 5e7be3c..75e99a1 100644
--- a/jni/filters/edge.c
+++ b/jni/filters/edge.c
@@ -46,7 +46,7 @@
     // 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 @@
     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 c2d80f3..0230922 100644
--- a/jni/filters/geometry.c
+++ b/jni/filters/geometry.c
@@ -170,11 +170,13 @@
     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 567a216..3130f9c 100644
--- a/jni/filters/highlight.c
+++ b/jni/filters/highlight.c
@@ -27,7 +27,7 @@
     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 5f802dd..335b027 100644
--- a/jni/filters/shadows.c
+++ b/jni/filters/shadows.c
@@ -40,7 +40,7 @@
         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 99a7d2e..2ca4c72 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 @@
     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 @@
         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 @@
         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 @@
     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 @@
     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 @@
     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 0000000..5650a8e
--- /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 d3f3aa5..8fc42f1 100644
--- a/src/com/android/gallery3d/app/MuteVideo.java
+++ b/src/com/android/gallery3d/app/MuteVideo.java
@@ -24,6 +24,8 @@
 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 @@
                             // 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 f2d568e..4659692 100644
--- a/src/com/android/gallery3d/app/PhotoPage.java
+++ b/src/com/android/gallery3d/app/PhotoPage.java
@@ -26,9 +26,6 @@
 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 @@
     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 @@
                             Intent shareIntent = createShareIntent(mCurrentPhoto);
 
                             mActionBar.setShareIntents(panoramaIntent, shareIntent, PhotoPage.this);
-                            setNfcBeamPushUri(contentUri);
                         }
                         break;
                     }
@@ -383,7 +377,6 @@
         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 @@
         }
     }
 
-    @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 b0ed8e6..a064e60 100644
--- a/src/com/android/gallery3d/app/TrimVideo.java
+++ b/src/com/android/gallery3d/app/TrimVideo.java
@@ -33,6 +33,8 @@
 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 @@
                             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 4b8774c..ed39de6 100644
--- a/src/com/android/gallery3d/data/LocalVideo.java
+++ b/src/com/android/gallery3d/data/LocalVideo.java
@@ -117,7 +117,11 @@
     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 737b5b6..0b25bf9 100644
--- a/src/com/android/gallery3d/data/MtpClient.java
+++ b/src/com/android/gallery3d/data/MtpClient.java
@@ -172,7 +172,7 @@
         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 e827b82..4542c19 100644
--- a/src/com/android/gallery3d/filtershow/FilterShowActivity.java
+++ b/src/com/android/gallery3d/filtershow/FilterShowActivity.java
@@ -1383,6 +1383,7 @@
                 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 aaec728..cc1f1af 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 @@
     }
 
     @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 bc17a6e..fc7ec60 100644
--- a/src/com/android/gallery3d/filtershow/provider/SharedImageProvider.java
+++ b/src/com/android/gallery3d/filtershow/provider/SharedImageProvider.java
@@ -29,16 +29,20 @@
 
 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 @@
     }
 
     @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 @@
         // 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 cc6c9ce..3943a6d 100644
--- a/src/com/android/gallery3d/ingest/data/MtpClient.java
+++ b/src/com/android/gallery3d/ingest/data/MtpClient.java
@@ -170,7 +170,7 @@
     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 6b4f103..b5a819c 100644
--- a/src/com/android/gallery3d/ui/ActionModeHandler.java
+++ b/src/com/android/gallery3d/ui/ActionModeHandler.java
@@ -20,7 +20,6 @@
 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 @@
     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 @@
         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 @@
         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 @@
     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 @@
                 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 98b827b..eccf73f 100644
--- a/src/com/android/photos/SelectionManager.java
+++ b/src/com/android/photos/SelectionManager.java
@@ -19,13 +19,9 @@
 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 @@
 
 public class SelectionManager {
     private Activity mActivity;
-    private NfcAdapter mNfcAdapter;
     private SelectedUriSource mUriSource;
     private Intent mShareIntent = new Intent();
 
@@ -43,18 +38,6 @@
 
     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) {