Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7e4252f1 authored by Ajay Panicker's avatar Ajay Panicker
Browse files

Fix file permissions for Bluetooth share

Used a file provider to serve up URIs to allow
applications to access files in the external
Bluetooth directory.

Bug: 23367919
Change-Id: Iadcdcafb235f3eeb50a0e147f3ef982fc9ee38b3
parent 9013d987
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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
+9 −0
Original line number Diff line number Diff line
@@ -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">
+3 −0
Original line number Diff line number Diff line
<paths xmlns:android="https://schemas.android.com/apk/res/android">
    <external-path name="bluetooth" path="/" />
</paths>
+18 −1
Original line number Diff line number Diff line
@@ -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);