Esempio n. 1
0
  private String retrieve() throws Exception {
    // we need always send the DIM request to get the Ptn Encrypted & isAllowFallback arguments.
    dimProxy =
        (JsonDimProxy)
            ServerProxyFactory.getInstance()
                .createDimProxy(null, CommManager.getInstance().getComm(), this, null);
    dimProxy.requestGetToken();

    synchronized (mutex_overall) {
      mutex_overall.wait(60 * 1000);
    }

    dimProxy.cancel();

    retrievePTN();

    notifyDimFinish();

    if (ptn != null && ptn.length() > 0) {
      return ptn;
    } else if (this.errorMessage != null && this.errorMessage.length() > 0) {
      throw new IllegalStateException(this.errorMessage);
    }

    return ptn;
  }
Esempio n. 2
0
  private void retrievePTN() {
    if (retryIntervals != null && retryIntervals.length > 0) {
      TnTelephonyManager.getInstance().startMMSAtBackground(destination, token);

      while (retryCount < retryIntervals.length) {
        if (isCancelled) break;

        synchronized (mutex_get_ptn) {
          try {
            writeLog(
                "DimProvider - retry time:"
                    + retryCount
                    + ", interval:"
                    + retryIntervals[retryCount]
                    + "ms");
            mutex_get_ptn.wait(retryIntervals[retryCount]);
          } catch (InterruptedException e) {
            Logger.log(this.getClass().getName(), e);
          }
        }

        if (isCancelled) break;

        writeLog("DimProvider - retry time:" + retryCount + ", start request PTN !!!");

        dimProxy =
            (JsonDimProxy)
                ServerProxyFactory.getInstance()
                    .createDimProxy(null, CommManager.getInstance().getComm(), this, null);
        dimProxy.requestGetPtn(token, isPtnEncrypted, (byte) 0, 30000);

        synchronized (mutex_retry) {
          try {
            writeLog(
                "DimProvider - retry time:" + retryCount + ", request work wait:" + timeout + "ms");
            mutex_retry.wait(timeout);
          } catch (InterruptedException e) {
            Logger.log(this.getClass().getName(), e);
          }
        }

        dimProxy.cancel();

        writeLog("DimProvider - retry time:" + retryCount + ", request work wait, wake up now!!!");

        retryCount++;
      }
    }
    notifyDimFinish();
  }
Esempio n. 3
0
  public void transactionFinished(AbstractServerProxy proxy, String jobId) {
    if (proxy instanceof JsonDimProxy) {
      JsonDimProxy dimProxy = (JsonDimProxy) proxy;
      int status = dimProxy.getStatus();
      String action = dimProxy.getRequestAction();

      if (action.equals(IServerProxyConstants.ACT_GET_DIM_TOKEN)) {
        if (status == IServerProxyConstants.SUCCESS) {
          this.token = dimProxy.getToken();
          this.destination = dimProxy.getDestination();
          this.port = dimProxy.getPort();
          retryIntervals = dimProxy.getRetryIntervals();
          if (retryIntervals == null) {
            // retryIntervals unit is ms, we retry ptn 3 times and every time use 15s
            retryIntervals = new int[] {8000, 5000, 5000};
          }

          int serverDrivenTimeout = dimProxy.getTimeout();

          if (serverDrivenTimeout > MIN_TIMEOUT) {
            this.timeout = serverDrivenTimeout;
          } else {
            this.timeout = DEFAULT_TIMEOUT;
          }

          isAllowFallback = dimProxy.isAllowFallback();
          isPtnEncrypted = dimProxy.isPtnEncrypted();

          synchronized (mutex_overall) {
            mutex_overall.notifyAll();
          }
        } else {
          this.ptn = "";
          notifyDimFinish();
        }

        writeLog(
            "DimProvider - action: "
                + action
                + " status:"
                + status
                + " token:"
                + token
                + " destination:"
                + destination
                + " port:"
                + port
                + " timeout:"
                + timeout
                + " isAllowFallback:"
                + isAllowFallback
                + " isPtnEncrypted:"
                + isPtnEncrypted);

      } else if (action.equals(IServerProxyConstants.ACT_GET_DIM_PTN)) {
        if (status == IServerProxyConstants.SUCCESS) {
          this.errorMessage = null;
          this.ptn = dimProxy.getPTN();
          this.carrier = dimProxy.getCarrier();
          // FIX ME: Remove this hardcode after dim server support retrieving carrier.
          if (AppConfigHelper.BRAND_BELL.equals(AppConfigHelper.brandName)) {
            this.carrier = "70";
          }
          if (this.ptn == null || this.ptn.trim().equalsIgnoreCase(NULL_RESPONSE)) this.ptn = "";

          if (this.carrier == null || this.carrier.trim().equalsIgnoreCase(NULL_RESPONSE))
            this.carrier = "";

          if (ptn != null
              && ptn.trim().length() > 0
              && carrier != null
              && carrier.trim().length() > 0) {
            notifyDimFinish();
          } else {
            notifyGetPtnMutex();
          }
        } else {
          this.ptn = "";
          this.carrier = "";

          notifyGetPtnMutex();
        }

        writeLog(
            "DimProvider - action: "
                + action
                + " status:"
                + status
                + " ptn:"
                + ptn
                + " carrier:"
                + carrier);
      }
    }
  }
Esempio n. 4
0
 public void cancel() {
   if (null != dimProxy) {
     dimProxy.cancel();
   }
   notifyDimFinish();
 }