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

Commit f7f647cf authored by Hansong Zhang's avatar Hansong Zhang Committed by android-build-merger
Browse files

Merge "PBAP: Use PbapStateMachine to handle new connection" am: 310c1d76

am: 12b73024

Change-Id: I0ba41a19aa165b93c0f870c9c29d717cca882062
parents f3b498ff 12b73024
Loading
Loading
Loading
Loading
+7 −19
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@

package com.android.bluetooth.pbap;

import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
@@ -47,7 +48,6 @@ import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;

@@ -85,16 +85,14 @@ public class BluetoothPbapActivity extends AlertActivity

    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 BluetoothDevice mDevice;

    private BroadcastReceiver mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
@@ -110,6 +108,7 @@ public class BluetoothPbapActivity extends AlertActivity
        super.onCreate(savedInstanceState);
        Intent i = getIntent();
        String action = i.getAction();
        mDevice = i.getParcelableExtra(BluetoothPbapService.EXTRA_DEVICE);
        if (action.equals(BluetoothPbapService.AUTH_CHALL_ACTION)) {
            showPbapDialog(DIALOG_YES_NO_AUTH);
            mCurrentDialog = DIALOG_YES_NO_AUTH;
@@ -142,10 +141,9 @@ public class BluetoothPbapActivity extends AlertActivity
    }

    private String createDisplayText(final int id) {
        String mRemoteName = BluetoothPbapService.getRemoteDeviceName();
        switch (id) {
            case DIALOG_YES_NO_AUTH:
                String mMessage2 = getString(R.string.pbap_session_key_dialog_title, mRemoteName);
                String mMessage2 = getString(R.string.pbap_session_key_dialog_title, mDevice);
                return mMessage2;
            default:
                return null;
@@ -193,16 +191,7 @@ public class BluetoothPbapActivity extends AlertActivity
            final String extraValue) {
        Intent intent = new Intent(intentName);
        intent.setPackage(BluetoothPbapService.THIS_PACKAGE_NAME);
        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.setPackage(BluetoothPbapService.THIS_PACKAGE_NAME);
        intent.putExtra(BluetoothPbapService.EXTRA_DEVICE, mDevice);
        if (extraName != null) {
            intent.putExtra(extraName, extraValue);
        }
@@ -230,8 +219,7 @@ public class BluetoothPbapActivity extends AlertActivity
    private void onTimeout() {
        mTimeout = true;
        if (mCurrentDialog == DIALOG_YES_NO_AUTH) {
            mMessageView.setText(getString(R.string.pbap_authentication_timeout_message,
                    BluetoothPbapService.getRemoteDeviceName()));
            mMessageView.setText(getString(R.string.pbap_authentication_timeout_message, mDevice));
            mKeyView.setVisibility(View.GONE);
            mKeyView.clearFocus();
            mKeyView.removeTextChangedListener(this);
+11 −17
Original line number Diff line number Diff line
@@ -32,8 +32,6 @@

package com.android.bluetooth.pbap;

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

import javax.obex.Authenticator;
@@ -44,39 +42,36 @@ import javax.obex.PasswordAuthentication;
 * authentication procedure.
 */
public class BluetoothPbapAuthenticator implements Authenticator {
    private static final String TAG = "BluetoothPbapAuthenticator";
    private static final String TAG = "PbapAuthenticator";

    private boolean mChallenged;

    private boolean mAuthCancelled;

    private String mSessionKey;
    private PbapStateMachine mPbapStateMachine;

    private Handler mCallback;

    public BluetoothPbapAuthenticator(final Handler callback) {
        mCallback = callback;
    BluetoothPbapAuthenticator(final PbapStateMachine stateMachine) {
        mPbapStateMachine = stateMachine;
        mChallenged = false;
        mAuthCancelled = false;
        mSessionKey = null;
    }

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

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

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

    private void waitUserConfirmation() {
        Message msg = Message.obtain(mCallback);
        msg.what = BluetoothPbapService.MSG_OBEX_AUTH_CHALL;
        msg.sendToTarget();
        mPbapStateMachine.sendMessage(PbapStateMachine.CREATE_NOTIFICATION);
        mPbapStateMachine.sendMessageDelayed(PbapStateMachine.REMOVE_NOTIFICATION,
                BluetoothPbapService.USER_CONFIRM_TIMEOUT_VALUE);
        synchronized (this) {
            while (!mChallenged && !mAuthCancelled) {
                try {
@@ -93,8 +88,7 @@ public class BluetoothPbapAuthenticator implements Authenticator {
            final boolean isUserIdRequired, final boolean isFullAccess) {
        waitUserConfirmation();
        if (mSessionKey.trim().length() != 0) {
            PasswordAuthentication pa = new PasswordAuthentication(null, mSessionKey.getBytes());
            return pa;
            return new PasswordAuthentication(null, mSessionKey.getBytes());
        }
        return null;
    }
+8 −19
Original line number Diff line number Diff line
@@ -171,8 +171,6 @@ public class BluetoothPbapObexServer extends ServerRequestHandler {

    private boolean mVcardSelector = false;

    private int mMissedCallSize = 0;

    // record current path the client are browsing
    private String mCurrentPath = "";

@@ -180,8 +178,6 @@ public class BluetoothPbapObexServer extends ServerRequestHandler {

    private Context mContext;

    private BluetoothPbapService mService;

    private BluetoothPbapVcardManager mVcardManager;

    private int mOrderBy = ORDER_BY_INDEXED;
@@ -204,6 +200,8 @@ public class BluetoothPbapObexServer extends ServerRequestHandler {

    private AppParamValue mConnAppParamValue;

    private PbapStateMachine mStateMachine;

    public static class ContentType {
        public static final int PHONEBOOK = 1;

@@ -216,12 +214,13 @@ public class BluetoothPbapObexServer extends ServerRequestHandler {
        public static final int COMBINED_CALL_HISTORY = 5;
    }

    public BluetoothPbapObexServer(Handler callback, BluetoothPbapService service) {
    public BluetoothPbapObexServer(Handler callback, Context context,
            PbapStateMachine stateMachine) {
        super();
        mCallback = callback;
        mService = service;
        mContext = service.getApplicationContext();
        mContext = context;
        mVcardManager = new BluetoothPbapVcardManager(mContext);
        mStateMachine = stateMachine;
    }

    @Override
@@ -284,9 +283,6 @@ public class BluetoothPbapObexServer extends ServerRequestHandler {
            Log.v(TAG, "onConnect(): uuid is ok, will send out " + "MSG_SESSION_ESTABLISHED msg.");
        }

        Message msg = Message.obtain(mCallback);
        msg.what = BluetoothPbapService.MSG_SESSION_ESTABLISHED;
        msg.sendToTarget();
        return ResponseCodes.OBEX_HTTP_OK;
    }

@@ -383,14 +379,7 @@ public class BluetoothPbapObexServer extends ServerRequestHandler {

    @Override
    public void onClose() {
        if (mCallback != null) {
            Message msg = Message.obtain(mCallback);
            msg.what = BluetoothPbapService.MSG_SERVERSESSION_CLOSE;
            msg.sendToTarget();
            if (D) {
                Log.d(TAG, "onClose(): msg MSG_SERVERSESSION_CLOSE sent out.");
            }
        }
        mStateMachine.sendMessage(PbapStateMachine.DISCONNECT);
    }

    @Override
@@ -1439,7 +1428,7 @@ public class BluetoothPbapObexServer extends ServerRequestHandler {

    private byte[] getDatabaseIdentifier() {
        mDatabaseIdentifierHigh = 0;
        mDatabaseIdentifierLow = mService.getDbIdentifier();
        mDatabaseIdentifierLow = BluetoothPbapUtils.sDbIdentifier.get();
        if (mDatabaseIdentifierLow != INVALID_VALUE_PARAMETER
                && mDatabaseIdentifierHigh != INVALID_VALUE_PARAMETER) {
            ByteBuffer ret = ByteBuffer.allocate(16);
Loading