コード例 #1
0
  public int onStartCommand(Intent intent, int flags, int startId) {

    if (DBG) log("Bluetooth Dun Service is started");

    if (!mHasInitiated) {
      if (!initNative()) {
        Log.e(TAG, "Could not init BluetoothDunService");
        notifyProfileState(BluetoothProfileManager.STATE_ABNORMAL);
        return START_STICKY;
      }

      IntentFilter intentFilter = new IntentFilter();
      intentFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
      intentFilter.addAction(BluetoothDunService.ACCESS_RESPONSE_ACTION);
      intentFilter.addAction(BluetoothDunService.RESEND_NOTIFICATION_ACTION);
      intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
      intentFilter.addAction(BluetoothTethering.BLUETOOTH_INTERFACE_ADDED);
      mContext.registerReceiver(mReceiver, intentFilter);

      mBTtethering = BluetoothTethering.getBluetoothTetheringInstance();
      mBTtethering.registerBTTether(this);

      dunEnableNative();
      // broadcast enabling to profilemanager
      notifyProfileState(BluetoothProfileManager.STATE_ENABLING);

      mHasInitiated = true;
    } else {
      if (DBG) log("Already started, just return!");
      return START_STICKY;
    }

    return START_STICKY;
  }
コード例 #2
0
  private void clearService() {
    if (!mHasInitiated) {
      return;
    }

    if (mDunState != BluetoothDun.STATE_DISCONNECTED) {
      // stopNetworkService();

      if (mDunState == BluetoothDun.STATE_CONNECTING) {
        mHandler.removeMessages(MESSAGE_CONNECT_TIMEOUT);
        removeDunAuthNotification(DUN_AUTHORIZE_NOTIFY);
      }
    }

    mBTtethering.unregisterBTTether();

    dunDisableNative();
    cleanupNative();
    mHasInitiated = false;

    mContext.unregisterReceiver(mReceiver);
  }