コード例 #1
0
  /* Description:Disconnect MAS connection if exist*/
  private synchronized int disconnectServer() {
    log("disconnectServer()");
    int index;
    ArrayList<Instance> instances = mManager.getAllInstances();

    clearAuthorizingDevices();

    if (instances == null || instances.size() == 0) {
      return SUCCESS;
    }
    for (index = 0; index < instances.size(); index++) {
      if (instances.get(index).isMasConnected()) {
        if (PENDING == disconnectMasSession(instances.get(index))) {
          mHandler.sendMessageDelayed(
              mHandler.obtainMessage(MAP_DISCONNECT_INSTANCE_TIMEOUT, instances.get(index)),
              DISCONNECT_INSTANCE_DELAY_DURATION);
          return PENDING;
        }
      }
    }

    /*wait MNS connection is disconnected*/
    for (index = 0; index < instances.size(); index++) {
      if (instances.get(index).isMnsConnected()) {
        return PENDING;
      }
    }

    return SUCCESS;
  }
コード例 #2
0
 private synchronized boolean disconnect(BluetoothDevice device) {
   ArrayList<Instance> instances = mManager.getInstanceByDevice(device);
   for (int i = 0; instances != null && i < instances.size(); i++) {
     disconnectMasNative(instances.get(i).getInstanceId());
   }
   return true;
 }
コード例 #3
0
  private void disable(boolean checkState) {
    int index = 0;
    Instance instance;
    BluetoothDevice[] devices;
    log("disableServer()");
    if (checkState
        && (mState == BluetoothMap.STATE_DISABLING || mState == BluetoothMap.STATE_DISABLED)) {
      log("the serive is disabling or disabled");
      onStateChanged(mState);
      return;
    }
    setState(BluetoothMap.STATE_DISABLING);

    if (PENDING == disconnectServer()) {
      return;
    }

    // MAS has to be deregistered before disabling service
    ArrayList<Instance> instances = mManager.getAllInstances();
    for (index = 0; index < instances.size(); index++) {
      instance = instances.get(index);
      deregisterInstance(instance);
    }
    //		mManager.removeAllInstances();
    InstanceUtil.reset();

    disableNative();
  }
コード例 #4
0
 public boolean isConnected(BluetoothDevice device) {
   log("isConnetected");
   if (!isEnabled()) {
     log("error, the service has not been ready ");
   }
   return mManager.isConnected(device);
 }
コード例 #5
0
 private MessageRequest getMessageRequestCache(int masId) {
   Instance instance = mManager.getInstanceById(masId);
   if (instance != null) {
     return instance.getMessageReqCache();
   } else {
     return null;
   }
 }
コード例 #6
0
        public BluetoothDevice[] getConnectedDevices() {
          log("getConnectedDevice");
          if (!isEnabled()) {
            log("error, the service has not been ready ");
          }

          return mManager.getConnectedDevices();
        }
コード例 #7
0
        public int getState(BluetoothDevice device) {
          log("getState");
          if (!isEnabled()) {
            log("error, the service has not been ready ");
          }

          return mManager.getState(device);
        }
コード例 #8
0
  private SetFolderRequest getFolderCache(int masId) {

    Instance instance = mManager.getInstanceById(masId);
    if (instance != null) {
      return instance.getFolderReqCache();
    } else {
      return null;
    }
  }
コード例 #9
0
  /** *proxy method for advanced settings***** */
  private synchronized void registerServer() {
    log("registerServer()");
    if (!isEnabled()) {
      log("map service has not been initialized");
      return;
    }
    int index;
    ArrayList<Instance> instances = mManager.generateInstances(this);
    for (index = 0; index < instances.size(); index++) {

      registerInstance(instances.get(index));
    }
  }
コード例 #10
0
  public void onCreate() {
    log("MAP: onCreate...");
    //	mContext = getApplicationContext();
    //	mMessageListContainer = new HashMap<int, MessageList>();
    //	mFolderListContainer  = new HashMap<int, FolderList>();

    //	createInstance();
    mManager = InstanceManager.getDefaultManager(this);
    mNotification = new BluetoothMapNotification(this);
    mEventManager = new EventReportManager(this);
    mAdapter = BluetoothAdapter.getDefaultAdapter();
    IntentFilter filter = new IntentFilter();
    filter.addAction(BluetoothMap.ACTION_AUTHORIZE_RESULT);
    filter.addAction(BluetoothMap.ACTION_DISCONNECT_DEVICE);
    filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
    filter.addAction(BluetoothMapNotification.ACTION_MAP_CLEAR_NOTIFICATION);
    filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
    registerReceiver(mReceiver, filter);
  }
コード例 #11
0
        @Override
        public void onReceive(Context context, Intent intent) {
          String action = intent.getAction();
          log("receive intent:" + action);
          if (action.equals(BluetoothMap.ACTION_AUTHORIZE_RESULT)) {
            boolean allow = intent.getBooleanExtra(BluetoothMap.EXTRA_RESULT, false);
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

            authorizeResponse(device, allow);
          } else if (action.equals(BluetoothMap.ACTION_DISCONNECT_DEVICE)) {
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            disconnect(device);
          } else if (action.equals(BluetoothDevice.ACTION_NAME_CHANGED)) {
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            int state = mNotification.getDeviceState(device);
            if (state == BluetoothMap.STATE_AUTHORIZING) {
              mNotification.createNotification(
                  BluetoothMapNotification.ALERT_TYPE_AUTHORIZE, device, false);
            } else if (state == BluetoothMap.STATE_CONNECTED) {
              mNotification.createNotification(
                  BluetoothMapNotification.ALERT_TYPE_CONNECT, device, false);
            }
          } else if (action.equals(BluetoothDevice.ACTION_BOND_STATE_CHANGED)) {
            int state =
                intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.BOND_NONE);
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            if (state == BluetoothDevice.BOND_NONE && mManager.isConnected(device)) {
              disconnect(device);
            }
          } else if (action.equals(BluetoothMapNotification.ACTION_MAP_CLEAR_NOTIFICATION)) {
            clearAuthorizingDevices();
          } else if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
            // when proxy binds to the service using BIND_AUTO_CREATE, the onDestroy will not be
            // called
            int state = BluetoothAdapter.getDefaultAdapter().getState();
            if (state == BluetoothAdapter.STATE_TURNING_OFF) {
              clearService();
            } else if (state == BluetoothAdapter.STATE_ON) {
              initService();
            }
          }
        }
コード例 #12
0
 public long getEmailAccount() {
   return mManager.getEmailAccount();
 }
コード例 #13
0
 public int[] getSims() {
   return mManager.getSims();
 }
コード例 #14
0
 public boolean replaceAccount(long value) {
   return mManager.replaceAccount(value);
 }
コード例 #15
0
 public void unregisterSim(int value) {
   log("mSettingBinder:unregisterSim, " + value);
   mManager.unregisterSim(value);
 }
コード例 #16
0
 public boolean registerSim(int value) {
   log("mSettingBinder:registerSim," + value);
   return mManager.registerSim(value);
 }
コード例 #17
0
        //   @Override
        public void handleMessage(Message msg) {
          Instance instance;
          ArrayList<Instance> instances;
          int result = MAP.RESULT_ERROR;
          String addr;
          BluetoothDevice device = null;
          log("message received: " + msg.what);

          switch (msg.what) {
            case MAP_SERVER_ENABLE_CNF:
              /*to do: set state*/
              setState(BluetoothMap.STATE_ENABLED);
              sendMessage(obtainMessage(MAP_REGISTER_SERVER));
              onStateChanged(BluetoothMap.STATE_ENABLED);
              break;
            case MAP_SERVER_DISABLE_CNF:
              /*to do: set state*/
              mManager.removeAllInstances();
              setState(BluetoothMap.STATE_DISABLED);
              onStateChanged(BluetoothMap.STATE_DISABLED);
              deinitServer();
              break;
            case MAP_SERVER_REGISTER_CNF:
              instance = mManager.getInstanceById(msg.arg1);
              if (msg.arg2 >= 0 && instance != null) {
                instance.onInstanceRegistered();
              } else {
                mManager.removeInstance(msg.arg1);
              }
              break;
            case MAP_SERVER_DEREGISTER_CNF:
              instance = mManager.getInstanceById(msg.arg1);
              if (instance != null) {
                instance.onInstanceDeregistered();
              }
              mManager.removeInstance(msg.arg1);
              break;
            case MAP_SERVER_CONNECT_IND:
              instance = mManager.getInstanceById(msg.arg1);
              device = mAdapter.getRemoteDevice((String) msg.obj);
              if (instance != null) {
                instance.onDeviceConnected(device);
              } else {
                log("invalid instance ID is received");
                return;
              }

              mNotification.createNotification(
                  BluetoothMapNotification.ALERT_TYPE_CONNECT, device, true);
              break;
            case MAP_SERVER_DISCONNECT_CNF:
            case MAP_SERVER_DISCONNECT_IND:
              instance = mManager.getInstanceById(msg.arg1);
              device = mAdapter.getRemoteDevice((String) msg.obj);
              if (instance != null) {
                instance.onDeviceDisconnected(device);
              } else {
                log("invalid instance ID is received:" + msg.arg1);
              }
              if (mManager.getState(device) == BluetoothMap.STATE_DISCONNECTED) {
                mNotification.removeNotification(
                    BluetoothMapNotification.ALERT_TYPE_CONNECT, device);
              }
              if (mState == BluetoothMap.STATE_DISABLING) {
                removeMessages(MAP_DISCONNECT_INSTANCE_TIMEOUT, instance);
                disable(false);
              }
              break;
            case MAP_SERVER_SET_FOLDER:
              instance = mManager.getInstanceById(msg.arg1);
              if (msg.obj == null || instance == null) {
                log("SetFolderRequest or instance is null");
                return;
              }
              SetFolderRequest setFolderReq = (SetFolderRequest) msg.obj;
              result = instance.setFolder(setFolderReq);
              setFolderResponse(setFolderReq.getAddress(), msg.arg1, result);
              break;
            case MAP_SERVER_UPDATE_INBOX:
              instance = mManager.getInstanceById(msg.arg1);
              if (msg.obj == null || instance == null) {
                log("address or instance is null");
                return;
              }
              addr = (String) msg.obj;
              result = instance.updateInbox();
              updateInboxResponse(addr, msg.arg1, result);
              break;

            case MAP_SERVER_GET_MESSAGE_LIST:
              instance = mManager.getInstanceById(msg.arg1);
              if (msg.obj == null || instance == null) {
                log("address is null or instance is null");
                return;
              }
              MessageListRequest msgListReq = (MessageListRequest) msg.obj;
              MessageListObject msgListRsp = instance.getMessagelist(msgListReq);
              addr = msgListReq.getAddress();
              getMessageListResponse(addr, msg.arg1, MAP.RESULT_OK, msgListRsp);
              break;

            case MAP_SERVER_GET_FOLDER_LIST:
              instance = mManager.getInstanceById(msg.arg1);
              if (msg.obj == null || instance == null) {
                log("address is null or instance is null");
                return;
              }
              FolderListObject[] fodlerlistrsp = null;
              FolderListRequest folderListReq = (FolderListRequest) msg.obj;
              addr = folderListReq.getAddress();
              device = mAdapter.getRemoteDevice(addr);
              if (device != null && device.equals(instance.getDevice())) {
                fodlerlistrsp = instance.getFolderlist(folderListReq);
              }
              getFolderListResponse(addr, msg.arg1, MAP.RESULT_OK, fodlerlistrsp);
              break;
            case MAP_SERVER_GET_MESSAGE:
              instance = mManager.getInstanceById(msg.arg1);
              if (msg.obj == null || instance == null) {
                log("address is null or instance is null");
                return;
              }
              MessageRequest messagereq = (MessageRequest) msg.obj;
              BMessageObject messagersp = instance.getMessage(messagereq);
              if (messagersp != null) {
                result = MAP.RESULT_OK;
              }
              addr = messagereq.getAddress();
              getMessageResponse(addr, msg.arg1, result, messagersp);
              /*	if (messagersp != null) {
              messagersp.reset();
              } */
              break;
            case MAP_SERVER_SET_NOTIFICATION:
              instance = mManager.getInstanceById(msg.arg1);
              if (msg.obj == null || instance == null) {
                log("address is null or instance is null");
                return;
              }
              result = MAP.RESULT_OK;
              setNotificationRegResponse((String) msg.obj, msg.arg1, result);
              break;
            case MAP_SERVER_SEND_REPORT_CNF:
              instance = mManager.getInstanceById(msg.arg1);
              if (msg.obj == null || instance == null) {
                log("address is null or instance is null");
                return;
              }
              mEventManager.onEventSentCompleted();
              break;
            case MAP_SERVER_AUTHORIZE_IND:
              // TODO: launch an alert to notify user that a device is trying to access local
              // resource
              if (msg.obj == null) {
                log("address is null");
                return;
              }
              device = mAdapter.getRemoteDevice((String) msg.obj);
              int state = mNotification.getDeviceState(device);
              if (state == BluetoothMap.STATE_NONE) {
                mNotification.createNotification(
                    BluetoothMapNotification.ALERT_TYPE_AUTHORIZE, device, true);
              } else if (state == BluetoothMap.STATE_CONNECTED) {
                // already connected
                authorizeResponse(device, true);
              } else if (state == BluetoothMap.STATE_AUTHORIZING) {
                log("the device is authorizing");
                // do nothing
              } else {
                log("unexpected state : " + state);
                authorizeResponse(device, false);
              }
              break;
            case MAP_SERVER_PUSH_MESSAGE:
              instance = mManager.getInstanceById(msg.arg1);
              if (msg.obj == null || instance == null) {
                log("address is null or instance is null");
                return;
              }
              BMessageObject bMessageobject = instance.getBMessageObject();
              bMessageobject.reset();
              if (parseMessage((String) msg.obj, msg.arg1, bMessageobject) == false) {
                result = MAP.RESULT_ERROR;
              } else {
                if (instance.pushMessage(bMessageobject)) {
                  result = MAP.RESULT_OK;
                } else {
                  result = MAP.RESULT_ERROR;
                }
              }
              sendMessageResponse((String) msg.obj, msg.arg1, result, bMessageobject.getHandle());
              break;
              /*		case MAP_SERVER_DELETE_MESSAGE:
              instance = mManager.getInstanceById(msg.arg1);
              if (msg.obj == null || instance == null) {
              	log("address is null or instance is null");
              	return;
              }
              //BMessageObject bMessageobject = instance.getBMessageObject();
              //sendMessageResponse((String) msg.obj, msg.arg1 ,bMessageobject);
              if(instance.deleteMessage(msg.arg1, msg.arg2)){
              	result = MAP.RESULT_OK;
              } else {
              	result = MAP.RESULT_ERROR;
              }
              setMessageStatusResponse((String)msg.obj, msg.arg1, result);
              break;
              */
            case MAP_SERVER_SET_MESSAGE_STATUS:
              instance = mManager.getInstanceById(msg.arg1);
              if (msg.obj == null || instance == null) {
                log("address is null or instance is null");
                return;
              }
              StatusSwitchRequest req = (StatusSwitchRequest) msg.obj;
              if (instance.setMessageStatus(req)) {
                result = MAP.RESULT_OK;
              } else {
                result = MAP.RESULT_ERROR;
              }
              addr = req.getAddress();
              setMessageStatusResponse(addr, msg.arg1, result);
              break;
            case MAP_SERVER_MNS_DISCONNCET_CNF:
              device = mAdapter.getRemoteDevice((String) msg.obj);
              instances = mManager.getInstanceByDevice(device);
              for (int i = 0; i < instances.size(); i++) {
                instances.get(i).deregisterCallback();
              }
              if (mState == BluetoothMap.STATE_DISABLING) {
                disable(false);
              }
              break;
            case MAP_SERVER_MNS_CONNECT_CNF:
              if (msg.arg1 == MAP.RESULT_ERROR) {
                log("fail to set up mns connection");
              } else {
                device = mAdapter.getRemoteDevice((String) msg.obj);
                instances = mManager.getInstanceByDevice(device);
                for (int i = 0; i < instances.size(); i++) {
                  instances.get(i).registerCallback(mEventManager);
                }
              }
              break;
            case MAP_REGISTER_SERVER:
              if (NetworkUtil.isPhoneRadioReady()) {
                registerServer();
              } else {
                mRegSrvCnt++;
                if (mRegSrvCnt < 10) {
                  sendMessageDelayed(
                      obtainMessage(MAP_REGISTER_SERVER), REGISTER_SERVER_DELAY_DURATION);
                } else {
                  log("Network is still not ready after 10s, so phone radio maybe is in error");
                }
              }
              break;
            case MAP_DISCONNECT_INSTANCE_TIMEOUT:
              instance = (Instance) msg.obj;
              if (instance != null) {
                instance.onDeviceDisconnected(instance.getDevice());
                if (mState == BluetoothMap.STATE_DISABLING) {
                  disable(false);
                }
              }
              break;
            default:
              log("Unrecognized message");
          }
        }