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

Commit 65b4d447 authored by Casper Bonde's avatar Casper Bonde Committed by Andre Eisenbach
Browse files

Add support for Bluetooth Sim Access Profile (3/4)

Server side of the Sim Access Profile. Enables a Bluetooth device
to take over control of the SIM. This is usefull in cars where the
internal antenna in the phone can have a low signal level.

For this profile to work, the RIL driver must allow for this feature
to be used, and it must provide the API needed. The API is based on
protoBuf.

This change includes some SAP test cases.

Change-Id: Ia46493383efed6b8a89ca270bdafa60fc1a150c1
parent a39a4f83
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -21,8 +21,8 @@ LOCAL_PACKAGE_NAME := Bluetooth
LOCAL_CERTIFICATE := platform

LOCAL_JNI_SHARED_LIBRARIES := libbluetooth_jni
LOCAL_JAVA_LIBRARIES := javax.obex telephony-common
LOCAL_STATIC_JAVA_LIBRARIES := com.android.vcard  bluetooth.mapsapi
LOCAL_JAVA_LIBRARIES := javax.obex telephony-common libprotobuf-java-2.3.0-micro
LOCAL_STATIC_JAVA_LIBRARIES := com.android.vcard  bluetooth.mapsapi sap-api-java-static

LOCAL_REQUIRED_MODULES := bluetooth.default
LOCAL_MULTILIB := 32
+8 −0
Original line number Diff line number Diff line
@@ -252,6 +252,14 @@
                  android:grantUriPermissions="true"
                  android:exported="false">
        </provider>
        <service
            android:process="@string/process"
            android:name=".sap.SapService"
            android:enabled="@bool/profile_supported_sap" >
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothSap" />
            </intent-filter>
        </service>
        <service
            android:process="@string/process"
            android:name = ".gatt.GattService"
+1 −0
Original line number Diff line number Diff line
@@ -27,4 +27,5 @@
    <bool name="pbap_use_profile_for_owner_vcard">true</bool>
    <bool name="profile_supported_map">true</bool>
    <bool name="profile_supported_avrcp_controller">false</bool>
    <bool name="profile_supported_sap">true</bool>
</resources>
+9 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
    <string name="bluetooth_sap_notif_title">Bluetooth SIM access</string>
    <string name="bluetooth_sap_notif_ticker">Bluetooth SIM Access</string>
    <string name="bluetooth_sap_notif_message">Request client to disconnect?</string>
    <string name="bluetooth_sap_notif_disconnecting">Waiting for client to disconnect</string>
    <string name="bluetooth_sap_notif_disconnect_button">Disconnect</string>
    <string name="bluetooth_sap_notif_force_disconnect_button">Force disconnect</string>
</resources>
+49 −0
Original line number Diff line number Diff line
@@ -119,6 +119,8 @@ public class AdapterService extends Service {
            "phonebook_access_permission";
    private static final String MESSAGE_ACCESS_PERMISSION_PREFERENCE_FILE =
            "message_access_permission";
    private static final String SIM_ACCESS_PERMISSION_PREFERENCE_FILE =
            "sim_access_permission";

    private static final int ADAPTER_SERVICE_TYPE=Service.START_STICKY;

@@ -1150,6 +1152,28 @@ public class AdapterService extends Service {
            return service.setMessageAccessPermission(device, value);
        }

        public int getSimAccessPermission(BluetoothDevice device) {
            if (!Utils.checkCaller()) {
                Log.w(TAG, "getSimAccessPermission() - Not allowed for non-active user");
                return BluetoothDevice.ACCESS_UNKNOWN;
            }

            AdapterService service = getService();
            if (service == null) return BluetoothDevice.ACCESS_UNKNOWN;
            return service.getSimAccessPermission(device);
        }

        public boolean setSimAccessPermission(BluetoothDevice device, int value) {
            if (!Utils.checkCaller()) {
                Log.w(TAG, "setSimAccessPermission() - Not allowed for non-active user");
                return false;
            }

            AdapterService service = getService();
            if (service == null) return false;
            return service.setSimAccessPermission(device, value);
        }

        public void sendConnectionStateChange(BluetoothDevice
                device, int profile, int state, int prevState) {
            AdapterService service = getService();
@@ -1755,6 +1779,31 @@ public class AdapterService extends Service {
        return editor.commit();
    }

    int getSimAccessPermission(BluetoothDevice device) {
        enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
        SharedPreferences pref = getSharedPreferences(SIM_ACCESS_PERMISSION_PREFERENCE_FILE,
                Context.MODE_PRIVATE);
        if (!pref.contains(device.getAddress())) {
            return BluetoothDevice.ACCESS_UNKNOWN;
        }
        return pref.getBoolean(device.getAddress(), false)
                ? BluetoothDevice.ACCESS_ALLOWED : BluetoothDevice.ACCESS_REJECTED;
    }

    boolean setSimAccessPermission(BluetoothDevice device, int value) {
        enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED,
                                       "Need BLUETOOTH PRIVILEGED permission");
        SharedPreferences pref = getSharedPreferences(SIM_ACCESS_PERMISSION_PREFERENCE_FILE,
                Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = pref.edit();
        if (value == BluetoothDevice.ACCESS_UNKNOWN) {
            editor.remove(device.getAddress());
        } else {
            editor.putBoolean(device.getAddress(), value == BluetoothDevice.ACCESS_ALLOWED);
        }
        return editor.commit();
    }

     void sendConnectionStateChange(BluetoothDevice
            device, int profile, int state, int prevState) {
        // TODO(BT) permission check?
Loading