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

Commit 1e405e77 authored by Kim Schulz's avatar Kim Schulz Committed by Zhihai Xu
Browse files

Fixes to the google review comments + spec 1.1

- updated code to comply with MAP spec 1.1
- removed activity + strings.xml
- removed unused notification code
- fixed TODOs
- added more string validation and case insensitivity
- fixed internal+google review comments
- Added dump of incoming bMessages to /sdcard/bluetooth/log when verbose debug in enabled. Only the latest received message will be stored
- Fix functions msgListingSize and msgListingHasUnread to also consider mms filter message type
- Fix wrong tag length define for notification status parameter
- Re-added shutdown code to interupt the MNS
- removed map activity
- Added initial bluetooth map unit tests
- Fix map event report xml start tag to uppercase 'MAP'
- added support for using ProfileService class
- changed the way the Broadcast Receiver was implemented
- Fixed minor bugs found during Automotive Test Event
  - FilterPeriod application parameters can be present, but with zero length
  - For MMS the end-boundary were added too early
  - The FOLDER entry in bMessage can be empty for a message push
  - Wrong error value returned for a set status operation with a wrong handle
- In getMessage() exclude all binary content and smil.xml if the appParam attachment is set to "no".
- Set correct content id and content location for mms. Fix mms mime parser bug.
- moved disconnect to Handler thread
- fixed multipart-message split bug.
- added a few Unit tests for multi-part messages
- MMS parser optimized
- fixed exception in MNS obex Client
- fixed problem with Native PDUs not getting correct timestamp
- corrected mixup in ordinator/recipient for MMS

Change-Id: I3875762822a7f8ce0132065e0da5d0257e3850a1
Bug:10692365
parent 56c876bd
Loading
Loading
Loading
Loading
+1 −21
Original line number Diff line number Diff line
@@ -52,11 +52,11 @@
    <uses-permission android:name="com.android.gallery3d.permission.GALLERY_PROVIDER"/>
    <uses-permission android:name="android.permission.MMS_SEND_OUTBOX_MSG"/>
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.SEND_SMS" />
    <uses-permission android:name="android.permission.READ_SMS" />
    <uses-permission android:name="android.permission.WRITE_SMS" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />

    <!-- For PBAP Owner Vcard Info -->
    <uses-permission android:name="android.permission.READ_PROFILE"/>
@@ -227,15 +227,6 @@
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </receiver>
        <activity android:name=".map.BluetoothMapActivity"
            android:process="@string/process"
            android:excludeFromRecents="true"
            android:theme="@*android:style/Theme.Holo.Dialog.Alert"
            android:enabled="@bool/profile_supported_map">
            <intent-filter>
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <service
            android:process="@string/process"
            android:name=".map.BluetoothMapService"
@@ -244,17 +235,6 @@
                <action android:name="android.bluetooth.IBluetoothMap" />
            </intent-filter>
        </service>
        <receiver
            android:process="@string/process"
            android:exported="true"
            android:name=".map.BluetoothMapReceiver"
            android:enabled="@bool/profile_supported_map">
            <intent-filter>
                <action android:name="android.bluetooth.adapter.action.STATE_CHANGED"/>
                <action android:name="android.bluetooth.device.action.CONNECTION_ACCESS_REPLY" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </receiver>
        <service
            android:process="@string/process"
            android:name = ".gatt.GattService"
+0 −16
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="map_session_key_dialog_title">Type session key for %1$s</string>
    <string name="map_session_key_dialog_header">Bluetooth session key required</string>
    <string name="map_acceptance_timeout_message">There was time out to accept connection with %1$s</string>
    <string name="map_authentication_timeout_message">There was time out to input session key with %1$s</string>
    <string name="map_auth_notif_ticker">Obex authentication request</string>
    <!-- Notification title when a Bluetooth device wants to pair with us -->
    <string name="map_auth_notif_title">Session Key</string>
    <!-- Notification message when a Bluetooth device wants to pair with us -->
    <string name="map_auth_notif_message">Type session key for %1$s</string>
    <string name="map_defaultname">Carkit</string>
    <string name="map_unknownName">Unknown name</string>
    <string name="map_localPhoneName">My name</string>
    <string name="map_defaultnumber">000000</string>
</resources>
+5 −2
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import com.android.bluetooth.hfp.HeadsetService;
import com.android.bluetooth.hid.HidService;
import com.android.bluetooth.pan.PanService;
import com.android.bluetooth.gatt.GattService;
import com.android.bluetooth.map.BluetoothMapService;

public class Config {
    private static final String TAG = "AdapterServiceConfig";
@@ -44,7 +45,8 @@ public class Config {
        HidService.class,
        HealthService.class,
        PanService.class,
        GattService.class
        GattService.class,
        BluetoothMapService.class
    };
    /**
     * Resource flag to indicate whether profile is supported or not.
@@ -55,7 +57,8 @@ public class Config {
        R.bool.profile_supported_hid,
        R.bool.profile_supported_hdp,
        R.bool.profile_supported_pan,
        R.bool.profile_supported_gatt
        R.bool.profile_supported_gatt,
        R.bool.profile_supported_map
    };

    private static Class[] SUPPORTED_PROFILES = new Class[0];
+6 −2
Original line number Diff line number Diff line
@@ -104,10 +104,14 @@ public class HeadsetService extends ProfileService {
                }
            }
            else if (action.equals(BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY)) {
                Log.v(TAG, "HeadsetService -  Received BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY");
                int requestType = intent.getIntExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE,
                                               BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS);
                if (requestType == BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS) {
                    Log.v(TAG, "Received BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY");
                    mStateMachine.handleAccessPermissionResult(intent);
                }
            }
        }
    };

    /**
+0 −284
Original line number Diff line number Diff line

/*
* Copyright (C) 2013 Samsung System LSI
* 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.
*/
package com.android.bluetooth.map;

import com.android.bluetooth.R;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.preference.Preference;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Button;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.text.InputFilter;
import android.text.TextWatcher;
import android.text.InputFilter.LengthFilter;

import com.android.internal.app.AlertActivity;
import com.android.internal.app.AlertController;

/**
 * MapActivity shows two dialogues: One for accepting incoming map request and
 * the other prompts the user to enter a session key for authentication with a
 * remote Bluetooth device.
 */
public class BluetoothMapActivity extends AlertActivity implements
        DialogInterface.OnClickListener, Preference.OnPreferenceChangeListener, TextWatcher {
    private static final String TAG = "BluetoothMapActivity";

    private static final boolean V = BluetoothMapService.VERBOSE;

    private static final int BLUETOOTH_OBEX_AUTHKEY_MAX_LENGTH = 16;

    private static final int DIALOG_YES_NO_AUTH = 1;

    private static final String KEY_USER_TIMEOUT = "user_timeout";

    private View mView;

    private EditText mKeyView;

    private TextView messageView;

    private String mSessionKey = "";

    private int mCurrentDialog;

    private Button mOkButton;

    private CheckBox mAlwaysAllowed;

    private boolean mTimeout = false;

    private boolean mAlwaysAllowedValue = true;

    private static final int DISMISS_TIMEOUT_DIALOG = 0;

    private static final int DISMISS_TIMEOUT_DIALOG_VALUE = 2000;

    private BroadcastReceiver mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (!BluetoothMapService.USER_CONFIRM_TIMEOUT_ACTION.equals(intent.getAction())) {
                return;
            }
            onTimeout();
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent i = getIntent();
        String action = i.getAction();
        if (action.equals(BluetoothMapService.AUTH_CHALL_ACTION)) {
            showMapDialog(DIALOG_YES_NO_AUTH);
            mCurrentDialog = DIALOG_YES_NO_AUTH;
        } else {
            Log.e(TAG, "Error: this activity may be started only with intent "
                    + "MAP_ACCESS_REQUEST or MAP_AUTH_CHALL ");
            finish();
        }
        registerReceiver(mReceiver, new IntentFilter(
                BluetoothMapService.USER_CONFIRM_TIMEOUT_ACTION));
    }

    private void showMapDialog(int id) {
        final AlertController.AlertParams p = mAlertParams;
        switch (id) {
            case DIALOG_YES_NO_AUTH:
                p.mIconId = android.R.drawable.ic_dialog_info;
                p.mTitle = getString(R.string.map_session_key_dialog_header);
                p.mView = createView(DIALOG_YES_NO_AUTH);
                p.mPositiveButtonText = getString(android.R.string.ok);
                p.mPositiveButtonListener = this;
                p.mNegativeButtonText = getString(android.R.string.cancel);
                p.mNegativeButtonListener = this;
                setupAlert();
                mOkButton = mAlert.getButton(DialogInterface.BUTTON_POSITIVE);
                mOkButton.setEnabled(false);
                break;
            default:
                break;
        }
    }

    private String createDisplayText(final int id) {
        String mRemoteName = BluetoothMapService.getRemoteDeviceName();
        switch (id) {
            case DIALOG_YES_NO_AUTH:
                String mMessage2 = getString(R.string.map_session_key_dialog_title, mRemoteName);
                return mMessage2;
            default:
                return null;
        }
    }

    private View createView(final int id) {
        switch (id) {
            case DIALOG_YES_NO_AUTH:
                mView = getLayoutInflater().inflate(R.layout.auth, null);
                messageView = (TextView)mView.findViewById(R.id.message);
                messageView.setText(createDisplayText(id));
                mKeyView = (EditText)mView.findViewById(R.id.text);
                mKeyView.addTextChangedListener(this);
                mKeyView.setFilters(new InputFilter[] {
                    new LengthFilter(BLUETOOTH_OBEX_AUTHKEY_MAX_LENGTH)
                });
                return mView;
            default:
                return null;
        }
    }

    private void onPositive() {
        if (!mTimeout) {
            if (mCurrentDialog == DIALOG_YES_NO_AUTH) {
                sendIntentToReceiver(BluetoothMapService.AUTH_RESPONSE_ACTION,
                        BluetoothMapService.EXTRA_SESSION_KEY, mSessionKey);
                mKeyView.removeTextChangedListener(this);
            }
        }
        mTimeout = false;
        finish();
    }

    private void onNegative() {
        if (mCurrentDialog == DIALOG_YES_NO_AUTH) {
            sendIntentToReceiver(BluetoothMapService.AUTH_CANCELLED_ACTION, null, null);
            mKeyView.removeTextChangedListener(this);
        }
        finish();
    }

    private void sendIntentToReceiver(final String intentName, final String extraName,
            final String extraValue) {
        Intent intent = new Intent(intentName);
        intent.setClassName(BluetoothMapService.THIS_PACKAGE_NAME, BluetoothMapReceiver.class
                .getName());
        if (extraName != null) {
            intent.putExtra(extraName, extraValue);
        }
        sendBroadcast(intent);
    }

    private void sendIntentToReceiver(final String intentName, final String extraName,
            final boolean extraValue) {
        Intent intent = new Intent(intentName);
        intent.setClassName(BluetoothMapService.THIS_PACKAGE_NAME, BluetoothMapReceiver.class
                .getName());
        if (extraName != null) {
            intent.putExtra(extraName, extraValue);
        }
        sendBroadcast(intent);
    }

    public void onClick(DialogInterface dialog, int which) {
        switch (which) {
            case DialogInterface.BUTTON_POSITIVE:
                if (mCurrentDialog == DIALOG_YES_NO_AUTH) {
                    mSessionKey = mKeyView.getText().toString();
                }
                onPositive();
                break;

            case DialogInterface.BUTTON_NEGATIVE:
                onNegative();
                break;
            default:
                break;
        }
    }

    private void onTimeout() {
        mTimeout = true;
        if (mCurrentDialog == DIALOG_YES_NO_AUTH) {
            messageView.setText(getString(R.string.map_authentication_timeout_message,
                    BluetoothMapService.getRemoteDeviceName()));
            mKeyView.setVisibility(View.GONE);
            mKeyView.clearFocus();
            mKeyView.removeTextChangedListener(this);
            mOkButton.setEnabled(true);
            mAlert.getButton(DialogInterface.BUTTON_NEGATIVE).setVisibility(View.GONE);
        }

        mTimeoutHandler.sendMessageDelayed(mTimeoutHandler.obtainMessage(DISMISS_TIMEOUT_DIALOG),
                DISMISS_TIMEOUT_DIALOG_VALUE);
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        mTimeout = savedInstanceState.getBoolean(KEY_USER_TIMEOUT);
        if (V) Log.v(TAG, "onRestoreInstanceState() mTimeout: " + mTimeout);
        if (mTimeout) {
            onTimeout();
        }
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putBoolean(KEY_USER_TIMEOUT, mTimeout);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(mReceiver);
    }

    public boolean onPreferenceChange(Preference preference, Object newValue) {
        return true;
    }

    public void beforeTextChanged(CharSequence s, int start, int before, int after) {
    }

    public void onTextChanged(CharSequence s, int start, int before, int count) {
    }

    public void afterTextChanged(android.text.Editable s) {
        if (s.length() > 0) {
            mOkButton.setEnabled(true);
        }
    }

    private final Handler mTimeoutHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case DISMISS_TIMEOUT_DIALOG:
                    if (V) Log.v(TAG, "Received DISMISS_TIMEOUT_DIALOG msg.");
                    finish();
                    break;
                default:
                    break;
            }
        }
    };
}
Loading