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

Commit 122b5ce6 authored by Marie Janssen's avatar Marie Janssen
Browse files

Services: start PBAP and OPP like other services

PBAP and OPP are currently normal services that are started and stopped
by the system.  Have AdapterService start them just like all of the
other profile services instead.

Bug: 34395439
Fix: 35216901
Test: connect to a carkit that does PBAP
Test: use beam to receive a file
Change-Id: I84e769886f6aa4e698bd07fb9900f124111b50b3
parent 3a72c7f0
Loading
Loading
Loading
Loading
+0 −13
Original line number Diff line number Diff line
@@ -114,7 +114,6 @@
            android:name=".opp.BluetoothOppReceiver"
            android:enabled="@bool/profile_supported_opp">
            <intent-filter>
                <action android:name="android.bluetooth.adapter.action.STATE_CHANGED" />
                <action android:name="android.btopp.intent.action.OPEN_RECEIVED_FILES" />
            </intent-filter>
        </receiver>
@@ -229,18 +228,6 @@
                <action android:name="android.bluetooth.IBluetoothPbap" />
            </intent-filter>
        </service>
        <receiver
            android:process="@string/process"
            android:exported="true"
            android:name=".pbap.BluetoothPbapReceiver"
            android:enabled="@bool/profile_supported_pbap">
            <intent-filter>
                <action android:name="android.bluetooth.adapter.action.STATE_CHANGED"/>
                <action android:name="android.bluetooth.device.action.CONNECTION_ACCESS_REPLY" />
                <action android:name="android.bluetooth.device.action.ACL_DISCONNECTED" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </receiver>
        <service
            android:process="@string/process"
            android:name=".map.BluetoothMapService"
+17 −23
Original line number Diff line number Diff line
@@ -40,6 +40,8 @@ import com.android.bluetooth.mapclient.MapClientService;
import com.android.bluetooth.sap.SapService;
import com.android.bluetooth.pbapclient.PbapClientService;
import com.android.bluetooth.hid.HidDevService;
import com.android.bluetooth.pbap.BluetoothPbapService;
import com.android.bluetooth.opp.BluetoothOppService;

public class Config {
    private static final String TAG = "AdapterServiceConfig";
@@ -49,32 +51,24 @@ public class Config {
    @SuppressWarnings("rawtypes")
    // Do not inclue OPP and PBAP, because their services
    // are not managed by AdapterService
    private static final Class[] PROFILE_SERVICES = {
        HeadsetService.class,       A2dpService.class,
        A2dpSinkService.class,      HidService.class,
        HealthService.class,        PanService.class,
        GattService.class,          BluetoothMapService.class,
        HeadsetClientService.class, AvrcpControllerService.class,
        SapService.class,           PbapClientService.class,
        MapClientService.class,     HidDevService.class};
    private static final Class[] PROFILE_SERVICES = {HeadsetService.class, A2dpService.class,
            A2dpSinkService.class, HidService.class, HealthService.class, PanService.class,
            GattService.class, BluetoothMapService.class, HeadsetClientService.class,
            AvrcpControllerService.class, SapService.class, PbapClientService.class,
            MapClientService.class, HidDevService.class, BluetoothOppService.class,
            BluetoothPbapService.class};
    /**
     * Resource flag to indicate whether profile is supported or not.
     */
    private static final int[] PROFILE_SERVICES_FLAG = {
        R.bool.profile_supported_hs_hfp,
        R.bool.profile_supported_a2dp,
        R.bool.profile_supported_a2dp_sink,
        R.bool.profile_supported_hid,
        R.bool.profile_supported_hdp,
        R.bool.profile_supported_pan,
        R.bool.profile_supported_gatt,
        R.bool.profile_supported_map,
        R.bool.profile_supported_hfpclient,
        R.bool.profile_supported_avrcp_controller,
        R.bool.profile_supported_sap,
        R.bool.profile_supported_pbapclient,
        R.bool.profile_supported_mapmce,
        R.bool.profile_supported_hidd};
    private static final int[] PROFILE_SERVICES_FLAG = {R.bool.profile_supported_hs_hfp,
            R.bool.profile_supported_a2dp, R.bool.profile_supported_a2dp_sink,
            R.bool.profile_supported_hid, R.bool.profile_supported_hdp,
            R.bool.profile_supported_pan, R.bool.profile_supported_gatt,
            R.bool.profile_supported_map, R.bool.profile_supported_hfpclient,
            R.bool.profile_supported_avrcp_controller, R.bool.profile_supported_sap,
            R.bool.profile_supported_pbapclient, R.bool.profile_supported_mapmce,
            R.bool.profile_supported_hidd, R.bool.profile_supported_opp,
            R.bool.profile_supported_pbap};

    private static Class[] SUPPORTED_PROFILES = new Class[0];

+7 −0
Original line number Diff line number Diff line
@@ -62,8 +62,10 @@ public abstract class ProfileService extends Service {
    }

    protected abstract IProfileServiceBinder initBinder();

    protected abstract boolean start();
    protected abstract boolean stop();
    protected void create() {}
    protected boolean cleanup() {
        return true;
    }
@@ -105,6 +107,7 @@ public abstract class ProfileService extends Service {
        super.onCreate();
        mAdapter = BluetoothAdapter.getDefaultAdapter();
        mBinder = initBinder();
        create();
    }

    public int onStartCommand(Intent intent, int flags, int startId) {
@@ -148,6 +151,10 @@ public abstract class ProfileService extends Service {

    public IBinder onBind(Intent intent) {
        if (DBG) log("onBind");
        if (mAdapter != null && mBinder == null) {
            // initBinder returned null, you can't bind
            throw new UnsupportedOperationException("Cannot bind to " + mName);
        }
        return mBinder;
    }

+1 −29
Original line number Diff line number Diff line
@@ -61,35 +61,7 @@ public class BluetoothOppReceiver extends BroadcastReceiver {
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();


        if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
            if (BluetoothAdapter.STATE_ON == intent.getIntExtra(
                    BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR)) {
                if (V) Log.v(TAG, "Received BLUETOOTH_STATE_CHANGED_ACTION, BLUETOOTH_STATE_ON");
                context.startService(new Intent(context, BluetoothOppService.class));

                // If this is within a sending process, continue the handle
                // logic to display device picker dialog.
                synchronized (this) {
                    if (BluetoothOppManager.getInstance(context).mSendingFlag) {
                        // reset the flags
                        BluetoothOppManager.getInstance(context).mSendingFlag = false;

                        Intent in1 = new Intent(BluetoothDevicePicker.ACTION_LAUNCH);
                        in1.putExtra(BluetoothDevicePicker.EXTRA_NEED_AUTH, false);
                        in1.putExtra(BluetoothDevicePicker.EXTRA_FILTER_TYPE,
                                BluetoothDevicePicker.FILTER_TYPE_TRANSFER);
                        in1.putExtra(BluetoothDevicePicker.EXTRA_LAUNCH_PACKAGE,
                                Constants.THIS_PACKAGE_NAME);
                        in1.putExtra(BluetoothDevicePicker.EXTRA_LAUNCH_CLASS,
                                BluetoothOppReceiver.class.getName());

                        in1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        context.startActivity(in1);
                    }
                }
            }
        } else if (action.equals(BluetoothDevicePicker.ACTION_DEVICE_SELECTED)) {
        if (action.equals(BluetoothDevicePicker.ACTION_DEVICE_SELECTED)) {
            BluetoothOppManager mOppManager = BluetoothOppManager.getInstance(context);

            BluetoothDevice remoteDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
+47 −40
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import javax.obex.ObexTransport;

import android.app.Service;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevicePicker;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.ContentValues;
@@ -56,6 +57,9 @@ import android.os.PowerManager;
import android.util.Log;
import android.os.Process;

import com.android.bluetooth.btservice.ProfileService;
import com.android.bluetooth.btservice.ProfileService.IProfileServiceBinder;

import java.io.IOException;
import java.util.ArrayList;

@@ -64,7 +68,7 @@ import java.util.ArrayList;
 * accept incoming OPP connection.
 */

public class BluetoothOppService extends Service {
public class BluetoothOppService extends ProfileService {
    private static final boolean D = Constants.DEBUG;
    private static final boolean V = Constants.VERBOSE;

@@ -114,8 +118,6 @@ public class BluetoothOppService extends Service {
     */
    private CharArrayBuffer mNewChars;

    private BluetoothAdapter mAdapter;

    private PowerManager mPowerManager;

    private BluetoothOppRfcommListener mSocketListener;
@@ -136,15 +138,13 @@ public class BluetoothOppService extends Service {
    private BluetoothOppObexServerSession mServerSession;

    @Override
    public IBinder onBind(Intent arg0) {
        throw new UnsupportedOperationException("Cannot bind to Bluetooth OPP Service");
    protected IProfileServiceBinder initBinder() {
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();
    protected void create() {
        if (V) Log.v(TAG, "onCreate");
        mAdapter = BluetoothAdapter.getDefaultAdapter();
        mSocketListener = new BluetoothOppRfcommListener(mAdapter);
        mShares = Lists.newArrayList();
        mBatchs = Lists.newArrayList();
@@ -177,18 +177,17 @@ public class BluetoothOppService extends Service {
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        if (V) Log.v(TAG, "onStartCommand");
        //int retCode = super.onStartCommand(intent, flags, startId);
        //if (retCode == START_STICKY) {
            if (mAdapter == null) {
                Log.w(TAG, "Local BT device is not enabled");
            } else {
    public boolean start() {
        if (V) Log.v(TAG, "start()");
        startListener();
            }
        updateFromProvider();
        //}
        return START_NOT_STICKY;
        return true;
    }

    @Override
    public boolean stop() {
        mHandler.sendMessage(mHandler.obtainMessage(STOP_LISTENER));
        return true;
    }

    private void startListener() {
@@ -329,16 +328,14 @@ public class BluetoothOppService extends Service {
    };

    private void startSocketListener() {

        if (V) Log.v(TAG, "start RfcommListener");
        mSocketListener.start(mHandler);
        if (V) Log.v(TAG, "RfcommListener started");
    }

    @Override
    public void onDestroy() {
    public boolean cleanup() {
        if (V) Log.v(TAG, "onDestroy");
        super.onDestroy();
        getContentResolver().unregisterContentObserver(mObserver);
        unregisterReceiver(mBluetoothReceiver);
        mSocketListener.stop();
@@ -352,6 +349,7 @@ public class BluetoothOppService extends Service {
        if (mHandler != null) {
            mHandler.removeCallbacksAndMessages(null);
        }
        return true;
    }

    /* suppose we auto accept an incoming OPUSH connection */
@@ -370,24 +368,33 @@ public class BluetoothOppService extends Service {
            if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
                switch (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR)) {
                    case BluetoothAdapter.STATE_ON:
                        if (V) Log.v(TAG,
                                    "Receiver BLUETOOTH_STATE_CHANGED_ACTION, BLUETOOTH_STATE_ON");
                        if (V) Log.v(TAG, "Bluetooth state changed: STATE_ON");
                        startSocketListener();
                        break;
                    case BluetoothAdapter.STATE_TURNING_OFF:
                        if (V) Log.v(TAG, "Receiver DISABLED_ACTION ");
                        //FIX: Don't block main thread
                        /*
                        mSocketListener.stop();
                        mListenStarted = false;
                        synchronized (BluetoothOppService.this) {
                            if (mUpdateThread == null) {
                                stopSelf();
                        // If this is within a sending process, continue the handle
                        // logic to display device picker dialog.
                        synchronized (this) {
                            if (BluetoothOppManager.getInstance(context).mSendingFlag) {
                                // reset the flags
                                BluetoothOppManager.getInstance(context).mSendingFlag = false;

                                Intent in1 = new Intent(BluetoothDevicePicker.ACTION_LAUNCH);
                                in1.putExtra(BluetoothDevicePicker.EXTRA_NEED_AUTH, false);
                                in1.putExtra(BluetoothDevicePicker.EXTRA_FILTER_TYPE,
                                        BluetoothDevicePicker.FILTER_TYPE_TRANSFER);
                                in1.putExtra(BluetoothDevicePicker.EXTRA_LAUNCH_PACKAGE,
                                        Constants.THIS_PACKAGE_NAME);
                                in1.putExtra(BluetoothDevicePicker.EXTRA_LAUNCH_CLASS,
                                        BluetoothOppReceiver.class.getName());

                                in1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                context.startActivity(in1);
                            }
                        }
                        */
                        mHandler.sendMessage(mHandler.obtainMessage(STOP_LISTENER));

                        break;
                    case BluetoothAdapter.STATE_TURNING_OFF:
                        if (V) Log.v(TAG, "Bluetooth state changed: STATE_TURNING_OFF");
                        mHandler.sendMessage(mHandler.obtainMessage(STOP_LISTENER));
                        break;
                }
            }
Loading