summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAjay Panicker <apanicke@google.com>2015-10-21 00:57:39 +0000
committerandroid-build-merger <android-build-merger@google.com>2015-10-21 00:57:39 +0000
commit3a7bd34e6024f7553c3f2999a215e2be20c94b91 (patch)
tree179cb28b32d106b1c9775d69ebb0c4d860c01f44
parent264d46d6a57507ffc60d1cdd17cd63fa6da01161 (diff)
parent33e7f11a36a8553285a1fd4c3cfff1e9458df842 (diff)
downloadandroid_packages_apps_Bluetooth-3a7bd34e6024f7553c3f2999a215e2be20c94b91.tar.gz
android_packages_apps_Bluetooth-3a7bd34e6024f7553c3f2999a215e2be20c94b91.tar.bz2
android_packages_apps_Bluetooth-3a7bd34e6024f7553c3f2999a215e2be20c94b91.zip
Fix file permissions for Bluetooth share am: 66d643091e
am: 33e7f11a36 * commit '33e7f11a36a8553285a1fd4c3cfff1e9458df842': Fix file permissions for Bluetooth share
-rw-r--r--Android.mk2
-rw-r--r--AndroidManifest.xml9
-rw-r--r--res/xml/file_paths.xml3
-rw-r--r--src/com/android/bluetooth/opp/BluetoothOppUtility.java19
4 files changed, 31 insertions, 2 deletions
diff --git a/Android.mk b/Android.mk
index e03acdc80..7b724d049 100644
--- a/Android.mk
+++ b/Android.mk
@@ -22,7 +22,7 @@ LOCAL_CERTIFICATE := platform
LOCAL_JNI_SHARED_LIBRARIES := libbluetooth_jni
LOCAL_JAVA_LIBRARIES := javax.obex telephony-common libprotobuf-java-micro
-LOCAL_STATIC_JAVA_LIBRARIES := com.android.vcard bluetooth.mapsapi sap-api-java-static
+LOCAL_STATIC_JAVA_LIBRARIES := com.android.vcard bluetooth.mapsapi sap-api-java-static android-support-v4
LOCAL_REQUIRED_MODULES := bluetooth.default
LOCAL_MULTILIB := 32
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 85910aa46..3652fd3a0 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -27,6 +27,7 @@
<uses-permission android:name="android.permission.BLUETOOTH_MAP" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+ <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<!-- WRITE_CONTACTS is used for test cases only -->
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
@@ -80,6 +81,14 @@
android:pathPrefix="/btopp"
android:permission="android.permission.ACCESS_BLUETOOTH_SHARE" />
</provider>
+ <provider android:name="android.support.v4.content.FileProvider"
+ android:authorities="com.google.android.bluetooth.fileprovider"
+ android:grantUriPermissions="true"
+ android:exported="false">
+ <meta-data
+ android:name="android.support.FILE_PROVIDER_PATHS"
+ android:resource="@xml/file_paths" />
+ </provider>
<service
android:process="@string/process"
android:name = ".btservice.AdapterService">
diff --git a/res/xml/file_paths.xml b/res/xml/file_paths.xml
new file mode 100644
index 000000000..72d848d15
--- /dev/null
+++ b/res/xml/file_paths.xml
@@ -0,0 +1,3 @@
+<paths xmlns:android="https://schemas.android.com/apk/res/android">
+ <external-path name="bluetooth" path="/" />
+</paths>
diff --git a/src/com/android/bluetooth/opp/BluetoothOppUtility.java b/src/com/android/bluetooth/opp/BluetoothOppUtility.java
index ea465f464..58f467794 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppUtility.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppUtility.java
@@ -54,6 +54,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
+import android.support.v4.content.FileProvider;
/**
* This class has some utilities for Opp application;
*/
@@ -186,7 +187,8 @@ public class BluetoothOppUtility {
return;
}
- Uri path = Uri.parse(fileName);
+ Uri path = FileProvider.getUriForFile(context,
+ "com.google.android.bluetooth.fileprovider", f);
// If there is no scheme, then it must be a file
if (path.getScheme() == null) {
path = Uri.fromFile(new File(fileName));
@@ -196,7 +198,22 @@ public class BluetoothOppUtility {
Intent activityIntent = new Intent(Intent.ACTION_VIEW);
activityIntent.setDataAndTypeAndNormalize(path, mimetype);
+ List<ResolveInfo> resInfoList = context.getPackageManager()
+ .queryIntentActivities(activityIntent,
+ 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;
+ context.grantUriPermission(packageName, path,
+ Intent.FLAG_GRANT_WRITE_URI_PERMISSION |
+ Intent.FLAG_GRANT_READ_URI_PERMISSION);
+ }
+
activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ activityIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+ activityIntent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
+
try {
if (V) Log.d(TAG, "ACTION_VIEW intent sent out: " + path + " / " + mimetype);
context.startActivity(activityIntent);