diff options
author | Ajay Panicker <apanicke@google.com> | 2015-10-21 00:54:34 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2015-10-21 00:54:34 +0000 |
commit | 33e7f11a36a8553285a1fd4c3cfff1e9458df842 (patch) | |
tree | c1724700a5bccdf2353c1bf71a7fff1fdb26f74b | |
parent | 5040e76e2b2742a210e5e1ef29ae1b1779f12ee3 (diff) | |
parent | 66d643091edba75b4524483ea640273344533378 (diff) | |
download | android_packages_apps_Bluetooth-33e7f11a36a8553285a1fd4c3cfff1e9458df842.tar.gz android_packages_apps_Bluetooth-33e7f11a36a8553285a1fd4c3cfff1e9458df842.tar.bz2 android_packages_apps_Bluetooth-33e7f11a36a8553285a1fd4c3cfff1e9458df842.zip |
Fix file permissions for Bluetooth share
am: 66d643091e
* commit '66d643091edba75b4524483ea640273344533378':
Fix file permissions for Bluetooth share
-rw-r--r-- | Android.mk | 2 | ||||
-rw-r--r-- | AndroidManifest.xml | 9 | ||||
-rw-r--r-- | res/xml/file_paths.xml | 3 | ||||
-rw-r--r-- | src/com/android/bluetooth/opp/BluetoothOppUtility.java | 19 |
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); |