aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Android.mk1
-rw-r--r--AndroidManifest.xml10
-rw-r--r--res/xml/file_paths.xml32
-rw-r--r--src/com/android/nfc/beam/BeamTransferManager.java37
4 files changed, 76 insertions, 4 deletions
diff --git a/Android.mk b/Android.mk
index 8e10d585..30952dea 100644
--- a/Android.mk
+++ b/Android.mk
@@ -20,6 +20,7 @@ LOCAL_CERTIFICATE := platform
LOCAL_JNI_SHARED_LIBRARIES := libnqnfc_nci_jni
LOCAL_JAVA_LIBRARIES := com.nxp.nfc.nq
LOCAL_PROGUARD_ENABLED := disabled
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-v4
LOCAL_PROPRIETARY_MODULE := true
LOCAL_MODULE_OWNER := nxp
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index f6a96e57..e8e0f052 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -40,6 +40,7 @@
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+ <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.MANAGE_USERS" />
@@ -157,6 +158,15 @@
<service android:name=".handover.PeripheralHandoverService"
/>
+ <provider android:name="android.support.v4.content.FileProvider"
+ android:authorities="com.android.nfc.fileprovider"
+ android:grantUriPermissions="true"
+ android:exported="false">
+ <meta-data
+ android:name="android.support.FILE_PROVIDER_PATHS"
+ android:resource="@xml/file_paths" />
+ </provider>
+
<uses-library android:name="com.nxp.nfc.nq"
android:required="true"
/>
diff --git a/res/xml/file_paths.xml b/res/xml/file_paths.xml
new file mode 100644
index 00000000..61365138
--- /dev/null
+++ b/res/xml/file_paths.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+Copyright (c) 2016, The Linux Foundation. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+ * Neither the name of The Linux Foundation nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ -->
+<paths xmlns:android="https://schemas.android.com/apk/res/android">
+ <external-path path="/" name="beam" />
+</paths>
diff --git a/src/com/android/nfc/beam/BeamTransferManager.java b/src/com/android/nfc/beam/BeamTransferManager.java
index b65cec74..9c38c2f5 100644
--- a/src/com/android/nfc/beam/BeamTransferManager.java
+++ b/src/com/android/nfc/beam/BeamTransferManager.java
@@ -1,4 +1,7 @@
/*
+ * Copyright (c) 2016, The Linux Foundation. All rights reserved.
+ * Not a Contribution.
+ *
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -35,6 +38,9 @@ import android.os.Message;
import android.os.SystemClock;
import android.os.UserHandle;
import android.util.Log;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.support.v4.content.FileProvider;
import java.io.File;
import java.text.SimpleDateFormat;
@@ -43,6 +49,7 @@ import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
+import java.util.List;
/**
* A BeamTransferManager object represents a set of files
@@ -468,10 +475,32 @@ public class BeamTransferManager implements Handler.Callback,
String filePath = mPaths.get(0);
Uri mediaUri = mMediaUris.get(filePath);
- Uri uri = mediaUri != null ? mediaUri :
- Uri.parse(ContentResolver.SCHEME_FILE + "://" + filePath);
- viewIntent.setDataAndTypeAndNormalize(uri, mMimeTypes.get(filePath));
- viewIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
+ Uri uri = null;
+ if(mediaUri != null) {
+ //Check for mediaUri, media file Uri is not required to be converted to content Uri
+ uri = mediaUri;
+ viewIntent.setDataAndTypeAndNormalize(uri, mMimeTypes.get(filePath));
+ viewIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
+ }
+ else {
+ uri = Uri.parse(ContentResolver.SCHEME_FILE + "://" + filePath);
+ File file = new File(uri.getPath());
+ Uri content_uri = FileProvider.getUriForFile(mContext,
+ "com.android.nfc.fileprovider", file);
+ uri = content_uri;
+ viewIntent.setDataAndTypeAndNormalize(uri, mMimeTypes.get(filePath));
+ List<ResolveInfo> resInfoList = mContext.getPackageManager().queryIntentActivities(viewIntent,PackageManager.MATCH_DEFAULT_ONLY);
+ // Grant permissions for any app that can handle a file to access it
+ for (ResolveInfo resolveInfo : resInfoList) {
+ String packageName = resolveInfo.activityInfo.packageName;
+ mContext.grantUriPermission(packageName, content_uri,
+ Intent.FLAG_GRANT_WRITE_URI_PERMISSION |
+ Intent.FLAG_GRANT_READ_URI_PERMISSION);
+ }
+ viewIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
+ viewIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+ viewIntent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
+ }
return viewIntent;
}