Beispiel #1
0
  /**
   * The callback result of process dead.
   *
   * @param record process record
   */
  public void onProcessDiedLocked(ProcessRecord record) {

    if (mSwipOccupiedProcess == record) {
      mSwipOccupiedProcess = null;
    }
    removeProcessRecordLocked(record.getPid(), record.getUid());
  }
Beispiel #2
0
  /**
   * Checks if the command set already exists.
   *
   * @param pid process id
   * @param uid user id
   * @param setName command set name
   * @param featureType feature type
   * @return result
   */
  public int isSetCreatedLocked(int pid, int uid, String setName, int featureType) {

    int result = VoiceCommonState.SUCCESS;

    ProcessRecord processRecord = getProcessRecordLocked(pid, uid);
    ListenerRecord listenerRecord =
        processRecord == null ? null : processRecord.getListenerRecord(getFeatureName(featureType));

    if (processRecord == null || listenerRecord == null) {
      // Check whether is illegal process from third party application
      // Maybe third application connect service without using
      // VoiceCommandManager
      result = VoiceCommonState.PROCESS_ILLEGAL;
    } else {
      // Ask swip to check whether the set is already created
      if (!setName.equals(listenerRecord.getSetName())) {
        // First check whether the set is already selected
        String swipSet =
            ProcessRecord.getSetNameForSwip(
                processRecord.getProcssName(),
                processRecord.getPid(),
                getFeatureName(featureType),
                setName);
        result = mSwip.isSetCreated(swipSet, featureType);
      }
    }

    return result;
  }
Beispiel #3
0
  /**
   * Creates a command set for commands operation.
   *
   * @param pid process id
   * @param uid user id
   * @param setName command set name
   * @param featureType feature type
   * @return result
   */
  public int createSetLocked(int pid, int uid, String setName, int featureType) {
    // TODO Auto-generated method stub

    int result = VoiceCommonState.SUCCESS;

    ProcessRecord processRecord = getProcessRecordLocked(pid, uid);
    ListenerRecord listenerRecord =
        processRecord == null ? null : processRecord.getListenerRecord(getFeatureName(featureType));

    if (listenerRecord == null) {
      // Check whether is illegal process from third party application
      // Maybe third application connect service without using
      // VoiceCommandManager
      result = VoiceCommonState.PROCESS_ILLEGAL;
    } else {

      if (setName.equals(listenerRecord.getSetName())) {
        // The setName already in used ,so don't need to ask swip
        // creating the set
        result = VoiceCommonState.SET_ALREADY_EXIST;
      } else {
        // Ask Swip whether the setName is created
        String swipSet =
            ProcessRecord.getSetNameForSwip(
                processRecord.getProcssName(),
                processRecord.getPid(),
                getFeatureName(featureType),
                setName);
        result = mSwip.createSetName(swipSet, featureType);
      }
    }

    return result;
  }
Beispiel #4
0
  /**
   * Register record for application from voice service.
   *
   * @param pid process id
   * @param uid user id
   * @param listener a callback that receive asynchronous notification from swip
   * @param featureType feature type
   * @param commonState common state or main state
   * @param featureState feture state or sub state
   * @param handler FeatureManager instance
   * @return result
   */
  public int registerListenerLocked(
      int pid,
      int uid,
      Object listener,
      int featureType,
      int commonState,
      int featureState,
      FeatureManager handler) {

    int result = VoiceCommonState.SUCCESS;

    ProcessRecord processRecord = createProcessRecordLocked(pid, uid);
    String featureName = getFeatureName(featureType);
    if (processRecord == null) {
      result = VoiceCommonState.PROCESS_ILLEGAL;
    } else {

      ListenerRecord record = processRecord.getListenerRecord(featureName);

      if (record == null) {
        record = processRecord.createListenerRecord();
        try {
          ((IInterface) listener).asBinder().linkToDeath(processRecord, 0);
          processRecord.addListenerRecord(featureName, record);
        } catch (RemoteException ex) {
          result = VoiceCommonState.PROCESS_ILLEGAL;
        }
      } else {
        // This case only can be happened while service didn't
        // receive
        // the died notification.
        // We need to notify native if possible
        if (CommonManager.DEBUG) {
          Log.d(
              TAG,
              "Register listener old pid="
                  + processRecord.getPid()
                  + " old uid="
                  + processRecord.getUid()
                  + " old processName="
                  + processRecord.getProcssName());
        }
      }
      if (result == VoiceCommonState.SUCCESS) {
        record.init(listener, featureType, featureName, commonState, featureState, handler);
      }
    }

    return result;
  }
Beispiel #5
0
  /**
   * Selects a command set for setting up commands or command recognition operation.
   *
   * @param pid process id
   * @param uid user id
   * @param setName command set name
   * @param featureType feature type
   * @return result
   */
  public int selectSetLocked(int pid, int uid, String setName, int featureType) {

    int result = VoiceCommonState.SUCCESS;

    if (setName == null) {

      result = VoiceCommonState.SET_ILLEGAL;
      Log.e(TAG, "select Set fail, set name =" + setName);

    } else {

      ProcessRecord processRecord = getProcessRecordLocked(pid, uid);
      ListenerRecord listenerRecord =
          processRecord == null
              ? null
              : processRecord.getListenerRecord(getFeatureName(featureType));
      if (processRecord == null || listenerRecord == null) {
        // Check whether is illegal process from third party application
        // Maybe third application connect service without using
        // VoiceCommandManager
        result = VoiceCommonState.PROCESS_ILLEGAL;
      } else if (setName.equals(listenerRecord.getSetName())) {
        result = VoiceCommonState.SET_SELECTED;
      } else if (processRecord.isListenerOccupiedSwip(listenerRecord)) {
        // Current listenerRecord occupy the swip , can't switch set
        result = VoiceCommonState.MIC_OCCUPIED;
      } else {
        // Ask swip that is this set created
        String swipSet =
            ProcessRecord.getSetNameForSwip(
                processRecord.getProcssName(),
                processRecord.getPid(),
                getFeatureName(featureType),
                setName);
        result = mSwip.isSetCreated(swipSet, featureType);
        if (result == VoiceCommonState.SET_ALREADY_EXIST) {
          listenerRecord.setSetName(setName);
          // result = processRecord
          // .switchSwipListenerRecord(listenerRecord);
          result = VoiceCommonState.SUCCESS;
        }
      }
    }
    return result;
  }
Beispiel #6
0
  /**
   * Deletes the command set.
   *
   * @param pid process id
   * @param uid user id
   * @param setName command set name
   * @param featureType feature type
   * @return result
   */
  public int deleteSetLocked(int pid, int uid, String setName, int featureType) {

    int result = VoiceCommonState.SUCCESS;

    ProcessRecord processRecord = getProcessRecordLocked(pid, uid);
    ListenerRecord listenerRecord =
        processRecord == null ? null : processRecord.getListenerRecord(getFeatureName(featureType));

    if (processRecord == null || listenerRecord == null) {
      // Check whether is illegal process from third party application
      // Maybe third application connect service without using
      // VoiceCommandManager
      result = VoiceCommonState.PROCESS_ILLEGAL;
    } else {

      if (setName.equals(listenerRecord.getSetName())) {
        if (listenerRecord == processRecord.getSwipListenerRecord()) {
          // The setName already in used ,so we need to check state
          // Swip is using the set , so we can't delete the set
          result = VoiceCommonState.SET_OCCUPIED;
        } else {
          listenerRecord.setSetName(null);
        }
      }
      // Ask swip to delete the set
      // listenerRecord.selectSet(null);
      if (result == VoiceCommonState.SUCCESS) {
        String swipSet =
            ProcessRecord.getSetNameForSwip(
                processRecord.getProcssName(),
                processRecord.getPid(),
                getFeatureName(featureType),
                setName);
        result = mSwip.deleteSetName(swipSet);
      }
    }
    return result;
  }