Beispiel #1
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;
  }