예제 #1
0
  private boolean canSync() {
    if (!AccountEntity.hasAccount(context)) // 没有帐号则不进行同步
    {
      return false;
    }

    if (!NetworkControl.getNetworkState(context)) // 没有网络不进行同步
    {
      return false;
    }

    if (StringUtil.isNullOrEmpty(new MyAccountManager(context).getAccount().getToken())) { // 无token
      return false;
    }
    return true;
  }
  /**
   * When the instrumentation is created it performs the basic configuration actions of initializing
   * the log, getting the test suite script url, initializing the required command runners to be
   * used by the BasicCommandRunner in order to run the test suite. After the initialization the
   * instrumentation is started.
   *
   * @param arguments the Bundle object with the Instrumentation arguments. The script url should be
   *     defined here
   */
  @Override
  public void onCreate(Bundle arguments) {
    instance = this;
    super.onCreate(arguments);

    // Init log
    Log.initLog(new AndroidLogAppender(TAG_LOG), Log.TRACE);

    boolean stopOnFailure = false;

    // Get the extra params
    if (arguments != null) {
      mainScriptUrl = arguments.getString(EXTRA_SCRIPT_URL);
      stopOnFailure = arguments.containsKey(EXTRA_STOP_ON_FAILURE);
      scriptUrlFromCommandLine = mainScriptUrl;
    }
    if (StringUtil.isNullOrEmpty(mainScriptUrl)) {
      mainScriptUrl = SCRIPT_URL_DEFAULT;
    }

    AndroidBasicRobot basicRobot = new AndroidBasicRobot(this);
    acr = new AndroidCommandRunner(this, basicRobot);
    basicRunner = new BasicScriptRunner();
    basicRunner.addCommandRunner(acr);
    // Setup contacts script runner
    AndroidContactsRobot aContactRobot = new AndroidContactsRobot(this, basicRobot);
    aContactRobot.setScriptRunner(basicRunner);
    ContactsCommandRunner contactsCommandRunner = new ContactsCommandRunner(aContactRobot);
    basicRunner.addCommandRunner(contactsCommandRunner);
    // Setup contacts script runner
    AndroidCalendarsRobot aCalendarsRobot = new AndroidCalendarsRobot(this, basicRobot);
    aCalendarsRobot.setScriptRunner(basicRunner);
    CalendarCommandRunner calendarCommandRunner = new CalendarCommandRunner(aCalendarsRobot);
    basicRunner.addCommandRunner(calendarCommandRunner);
    // Other properties
    basicRunner.setStopOnFailure(stopOnFailure);
    start();
  }