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

Commit e3b96554 authored by Corey Garst's avatar Corey Garst Committed by Steve Kondik
Browse files

Ported: Bluetooth Message Access Profile (MAP) from CM9

This was added to CM10 to restore message exchange capabilities with automotive systems.

Change-Id: Ic78369daf7382de0121f854bae75e5810be41568
parent 60f8bb99
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -34,6 +34,13 @@
    <uses-permission android:name="android.permission.READ_CALL_LOG" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
    <uses-permission android:name="android.permission.READ_SMS"></uses-permission>
    <uses-permission android:name="android.permission.WRITE_SMS"></uses-permission>
    <uses-permission android:name="android.permission.BROADCAST_SMS"></uses-permission>
    <uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
    <uses-permission android:name="android.permission.SEND_SMS"></uses-permission>
    <uses-permission android:name="com.android.email.permission.ACCESS_PROVIDER"></uses-permission>
    <uses-permission android:name="com.android.email.permission.READ_ATTACHMENT"></uses-permission>
    <uses-permission android:name="com.android.permission.HANDOVER_STATUS" />
    <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
    <uses-permission android:name="android.permission.NET_ADMIN" />
@@ -268,5 +275,24 @@
                <action android:name="android.bluetooth.IBluetoothPan" />
            </intent-filter>
        </service>
        <activity android:name=".map.BluetoothMasActivity"
            android:process="@string/process"
            android:excludeFromRecents="true"
            android:theme="@*android:style/Theme.Dialog.Alert">
            <intent-filter>
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <service
            android:process="@string/process"
            android:name=".map.BluetoothMasService" >
        </service>
        <receiver
            android:process="@string/process"
            android:name=".map.BluetoothMasReceiver">
            <intent-filter>
                <action android:name="android.bluetooth.adapter.action.STATE_CHANGED"/>
            </intent-filter>
        </receiver>
    </application>
</manifest>

res/layout/access.xml

0 → 100644
+48 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
** Copyright 2009, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
-->

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent">

    <LinearLayout
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:orientation="vertical">

        <TextView
            android:id="@+id/message"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dip"
            android:layout_marginRight="20dip"
            android:gravity="center_horizontal"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <CheckBox android:id="@+id/alwaysallowed"
            style="?android:attr/textAppearanceMedium"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="2dip"
            android:text="@string/alwaysallowed" />

    </LinearLayout>

</ScrollView>
 No newline at end of file
+1 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@
    <string name="auth_notif_title">Session Key</string>
    <!-- Notification message when a Bluetooth device wants to pair with us -->
    <string name="auth_notif_message">Type session key for %1$s</string>
    <string name="alwaysallowed">Always allowed?</string>
    <string name="defaultname">Carkit</string>
    <string name="unknownName">Unknown name</string>
    <string name="localPhoneName">My name</string>
+102 −0
Original line number Diff line number Diff line
/*
 * Copyright (c) 2010-2011, Code Aurora Forum. 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 Code Aurora 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 BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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.
 */

package com.android.bluetooth.map;

import android.os.Handler;
import android.os.Message;
import android.util.Log;

import javax.obex.*;

/**
 * BluetoothMapAuthenticator is a used by BluetoothObexServer for obex
 * authentication procedure.
 */
public class BluetoothMapAuthenticator implements Authenticator {
    private static final String TAG = "BluetoothMapAuthenticator";

    private boolean mChallenged;

    private boolean mAuthCancelled;

    private String mSessionKey;

    private Handler mCallback;

    public BluetoothMapAuthenticator(final Handler callback) {
        mCallback = callback;
        mChallenged = false;
        mAuthCancelled = false;
        mSessionKey = null;
    }

    public final synchronized void setChallenged(final boolean bool) {
        mChallenged = bool;
    }

    public final synchronized void setCancelled(final boolean bool) {
        mAuthCancelled = bool;
    }

    public final synchronized void setSessionKey(final String string) {
        mSessionKey = string;
    }

    private void waitUserConfirmation() {
        Message msg = Message.obtain(mCallback);
        msg.what = BluetoothMasService.MSG_OBEX_AUTH_CHALL;
        msg.sendToTarget();
        synchronized (this) {
            while (!mChallenged && !mAuthCancelled) {
                try {
                    wait();
                } catch (InterruptedException e) {
                    Log.e(TAG, "Interrupted while waiting on isChalled");
                }
            }
        }
    }

      public PasswordAuthentication onAuthenticationChallenge(final String description,
            final boolean isUserIdRequired, final boolean isFullAccess) {
        waitUserConfirmation();
        if (mSessionKey.trim().length() != 0) {
            PasswordAuthentication pa = new PasswordAuthentication(null, mSessionKey.getBytes());
            return pa;
        }
        return null;
    }

    // TODO: Reserved for future use only, in case PSE challenge PCE
    public byte[] onAuthenticationResponse(final byte[] userName) {
        byte[] b = null;
        return b;
    }
}
+87 −0
Original line number Diff line number Diff line
/*
 * Copyright (c) 2010-2011, Code Aurora Forum. 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 Code Aurora 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 BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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.
 */

package com.android.bluetooth.map;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;


import javax.obex.*;

import android.bluetooth.BluetoothSocket;

public class BluetoothMapRfcommTransport implements ObexTransport {
    private BluetoothSocket mSocket = null;

    public BluetoothMapRfcommTransport(BluetoothSocket rfs) {
        super();
        this.mSocket = rfs;
    }

    public void close() throws IOException {
        mSocket.close();
    }

    public DataInputStream openDataInputStream() throws IOException {
        return new DataInputStream(openInputStream());
    }

    public DataOutputStream openDataOutputStream() throws IOException {
        return new DataOutputStream(openOutputStream());
    }

    public InputStream openInputStream() throws IOException {
        return mSocket.getInputStream();
    }

    public OutputStream openOutputStream() throws IOException {
        return mSocket.getOutputStream();
    }

    public void connect() throws IOException {
    }

    public void create() throws IOException {
    }

    public void disconnect() throws IOException {
    }

    public void listen() throws IOException {
    }

    public boolean isConnected() throws IOException {
        return true;
    }

}
Loading