@ReactMethod
  public void getAuthCredentials(
      ReadableMap args, Callback successCallback, Callback errorCallback) {
    ClientManager clientManager =
        new ClientManager(
            getReactApplicationContext(),
            SalesforceSDKManager.getInstance().getAccountType(),
            SalesforceSDKManager.getInstance().getLoginOptions(),
            SalesforceSDKManager.getInstance().shouldLogoutWhenTokenRevoked());
    RestClient client = clientManager.peekRestClient();

    RestClient.ClientInfo clientInfo = client.getClientInfo();
    try {
      JSONObject data = new JSONObject();
      data.put(ACCESS_TOKEN, client.getAuthToken());
      data.put(REFRESH_TOKEN, client.getRefreshToken());
      data.put(USER_ID, clientInfo.userId);
      data.put(ORG_ID, clientInfo.orgId);
      data.put(CLIENT_ID, clientInfo.clientId);
      data.put(LOGIN_URL, clientInfo.loginUrl.toString());
      data.put(IDENTITY_URL, clientInfo.identityUrl.toString());
      data.put(INSTANCE_URL, clientInfo.instanceUrl.toString());
      data.put(COMMUNITY_ID, clientInfo.communityId);
      data.put(COMMUNITY_URL, clientInfo.communityUrl);

      ReactBridgeHelper.invokeSuccess(successCallback, data);
    } catch (JSONException e) {
      Log.e("OauthReactBridge", "getAuthCredentials", e);
      errorCallback.invoke(e.toString());
    }
  }
 protected ClientManager buildClientManager() {
   return new ClientManager(
       this,
       SalesforceSDKManager.getInstance().getAccountType(),
       SalesforceSDKManager.getInstance().getLoginOptions(),
       SalesforceSDKManager.getInstance().shouldLogoutWhenTokenRevoked());
 }
  @ReactMethod
  public void logoutCurrentUser(
      ReadableMap args, Callback successCallback, Callback errorCallback) {
    UserAccount account =
        SalesforceSDKManager.getInstance().getUserAccountManager().getCurrentUser();
    SalesforceSDKManager.getInstance().getUserAccountManager().signoutUser(account, null);

    successCallback.invoke();
  }
  @Override
  public void setUp() throws Exception {
    super.setUp();
    targetContext = getInstrumentation().getTargetContext();
    eq = new EventsListenerQueue();

    // Wait for app initialization to complete.
    final Application app = Instrumentation.newApplication(TestForceApp.class, targetContext);
    getInstrumentation().callApplicationOnCreate(app);
    if (SalesforceSDKManager.getInstance() == null) {
      eq.waitForEvent(EventType.AppCreateComplete, 5000);
    }
    loginServerManager = SalesforceSDKManager.getInstance().getLoginServerManager();
  }
 @Override
 public void setUp() throws Exception {
   super.setUp();
   final Context targetContext = getInstrumentation().getTargetContext();
   final Application app = Instrumentation.newApplication(TestForceApp.class, targetContext);
   getInstrumentation().callApplicationOnCreate(app);
   eq = new EventsListenerQueue();
   if (!SalesforceSDKManager.hasInstance()) {
     eq.waitForEvent(EventsObservable.EventType.AppCreateComplete, 5000);
   }
   SalesforceSDKManager.getInstance()
       .getPasscodeManager()
       .setPasscodeHash(ClientManagerTest.TEST_PASSCODE_HASH);
   SalesforceSDKManager.getInstance().setAdditionalOauthKeys(createAdditionalOauthKeys());
 }
  @Override
  public void onCreate() {
    super.onCreate();
    SalesforceSDKManager.initHybrid(
        getApplicationContext(), new KeyImpl(), SplashScreenActivity.class, LoginActivity.class);
    SalesforceSDKManager.initHybrid(getApplicationContext(), new KeyImpl());

    /*
     * Un-comment the line below to enable push notifications in this app.
     * Replace 'pnInterface' with your implementation of 'PushNotificationInterface'.
     * Add your Google package ID in 'bootonfig.json', as the value
     * for the key 'androidPushNotificationClientId'.
     */
    // SalesforceSDKManager.getInstance().setPushNotificationReceiver(pnInterface);
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Passcode manager
    passcodeManager = SalesforceSDKManager.getInstance().getPasscodeManager();
    tokenRevocationReceiver = new TokenRevocationReceiver(this);

    // ApiVersion
    apiVersion = getString(R.string.api_version);

    // Setup view
    setContentView(R.layout.explorer);

    // Setup tabs
    TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
    addTab(tabHost, "versions", R.string.versions_tab, R.id.versions_tab);
    addTab(tabHost, "resources", R.string.resources_tab, R.id.resources_tab);
    addTab(tabHost, "describe_global", R.string.describe_global_tab, R.id.describe_global_tab);
    addTab(tabHost, "metadata", R.string.metadata_tab, R.id.metadata_tab);
    addTab(tabHost, "describe", R.string.describe_tab, R.id.describe_tab);
    addTab(tabHost, "create", R.string.create_tab, R.id.create_tab);
    addTab(tabHost, "retrieve", R.string.retrieve_tab, R.id.retrieve_tab);
    addTab(tabHost, "update", R.string.update_tab, R.id.update_tab);
    addTab(tabHost, "upsert", R.string.upsert_tab, R.id.upsert_tab);
    addTab(tabHost, "delete", R.string.delete_tab, R.id.delete_tab);
    addTab(tabHost, "query", R.string.query_tab, R.id.query_tab);
    addTab(tabHost, "search", R.string.search_tab, R.id.search_tab);
    addTab(tabHost, "manual", R.string.manual_request_tab, R.id.manual_request_tab);

    // Make result area scrollable
    resultText = (TextView) findViewById(R.id.result_text);
    resultText.setMovementMethod(new ScrollingMovementMethod());
  }
 /** Tests creating an account from JSON */
 public void testCreateAccountFromJSON() throws JSONException {
   JSONObject testJSON = createTestAccountJSON();
   UserAccount account = new UserAccount(testJSON);
   assertEquals("Auth token should match", TEST_AUTH_TOKEN, account.getAuthToken());
   assertEquals("Refresh token should match", TEST_REFRESH_TOKEN, account.getRefreshToken());
   assertEquals("Login server URL should match", TEST_LOGIN_URL, account.getLoginServer());
   assertEquals("Identity URL should match", TEST_IDENTITY_URL, account.getIdUrl());
   assertEquals("Instance URL should match", TEST_INSTANCE_URL, account.getInstanceServer());
   assertEquals("Org ID should match", TEST_ORG_ID, account.getOrgId());
   assertEquals("User ID should match", TEST_USER_ID, account.getUserId());
   assertEquals("User name should match", TEST_USERNAME, account.getUsername());
   assertEquals("Client ID should match", TEST_CLIENT_ID, account.getClientId());
   assertEquals("Community ID should match", TEST_COMMUNITY_ID, account.getCommunityId());
   assertEquals("Community URL should match", TEST_COMMUNITY_URL, account.getCommunityUrl());
   assertEquals("First name should match", TEST_FIRST_NAME, account.getFirstName());
   assertEquals("Last name should match", TEST_LAST_NAME, account.getLastName());
   assertEquals("Display name should match", TEST_DISPLAY_NAME, account.getDisplayName());
   assertEquals("Email should match", TEST_EMAIL, account.getEmail());
   assertEquals("Photo URL should match", TEST_PHOTO_URL, account.getPhotoUrl());
   assertEquals("Thumbnail URL should match", TEST_THUMBNAIL_URL, account.getThumbnailUrl());
   assertEquals(
       "Additional OAuth values should match",
       createAdditionalOauthValues(),
       account.getAdditionalOauthValues());
   assertEquals(
       "Account name should match",
       String.format(
           "%s (%s) (%s)",
           TEST_USERNAME,
           TEST_INSTANCE_URL,
           SalesforceSDKManager.getInstance().getApplicationName()),
       account.getAccountName());
 }
 @Override
 public void tearDown() throws Exception {
   if (eq != null) {
     eq.tearDown();
     eq = null;
   }
   SalesforceSDKManager.getInstance().setAdditionalOauthKeys(null);
   super.tearDown();
 }
  @Override
  public void onResume() {
    super.onResume();
    registerReceiver(
        tokenRevocationReceiver, new IntentFilter(ClientManager.ACCESS_TOKEN_REVOKE_INTENT));

    // Hide everything until we are logged in
    findViewById(R.id.root).setVisibility(View.INVISIBLE);

    // Bring up passcode screen if needed
    if (passcodeManager.onResume(this)) {
      // Login options
      String accountType = SalesforceSDKManager.getInstance().getAccountType();

      // Get a rest client
      new ClientManager(
              this,
              accountType,
              SalesforceSDKManager.getInstance().getLoginOptions(),
              SalesforceSDKManager.getInstance().shouldLogoutWhenTokenRevoked())
          .getRestClient(
              this,
              new RestClientCallback() {
                @Override
                public void authenticatedRestClient(RestClient client) {
                  if (client == null) {
                    SalesforceSDKManager.getInstance().logout(ExplorerActivity.this);
                    return;
                  }
                  ExplorerActivity.this.client = client;

                  // Show everything
                  findViewById(R.id.root).setVisibility(View.VISIBLE);
                }
              });
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, "onCreate called");
    super.onCreate(savedInstanceState);

    // Get clientManager
    clientManager = buildClientManager();

    // Gets an instance of the passcode manager.
    passcodeManager = SalesforceSDKManager.getInstance().getPasscodeManager();

    // TODO
    // Have a user switcher once we have an account manager bridge for react native

    // Let observers know
    EventsObservable.get().notifyEvent(EventType.MainActivityCreateComplete, this);
  }
  /** Called when resuming activity and user is not authenticated */
  private void onResumeNotLoggedIn() {

    // Need to be authenticated
    if (shouldAuthenticate()) {

      // Online
      if (SalesforceSDKManager.getInstance().hasNetwork()) {
        Log.i(TAG, "onResumeNotLoggedIn - Should authenticate / online - authenticating");
        login();
      }

      // Offline
      else {
        Log.w(TAG, "onResumeNotLoggedIn - Should authenticate / offline - cannot proceed");
        onErrorAuthenticateOffline();
      }
    }

    // Does not need to be authenticated
    else {
      Log.i(TAG, "onResumeNotLoggedIn - Should not authenticate");
    }
  }
  private void getCase() {

    // Creating Case and save id in the running Activity

    if (activity.geteServiceAdministration() != null) {
      activity.setCaseFields(new HashMap<String, Object>());
      Map<String, Object> caseFields = activity.getCaseFields();
      caseFields.put("Service_Requested__c", activity.geteServiceAdministration().getID());
      caseFields.put("AccountId", activity.getUser().get_contact().get_account().getID());
      caseFields.put("RecordTypeId", activity.getCaseRecordTypeId());
      caseFields.put("Status", "Draft");
      caseFields.put("Type", "License Services");
      caseFields.put("Origin", "Mobile");
      caseFields.put(
          "License_Ref__c",
          activity.getUser().get_contact().get_account().get_currentLicenseNumber().getId());
      caseFields.put("isCourierRequired__c", true);
      activity.setCaseFields(caseFields);
      if (activity.getInsertedCaseId() != null && !activity.getInsertedCaseId().equals("")) {
        try {
          restRequest =
              RestRequest.getRequestForUpdate(
                  getActivity().getString(R.string.api_version),
                  "Case",
                  activity.getInsertedCaseId(),
                  activity.getCaseFields());
        } catch (IOException e) {
          e.printStackTrace();
        }
      } else {
        try {
          restRequest =
              RestRequest.getRequestForCreate(
                  getActivity().getString(R.string.api_version), "Case", activity.getCaseFields());
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      new ClientManager(
              getActivity(),
              SalesforceSDKManager.getInstance().getAccountType(),
              SalesforceSDKManager.getInstance().getLoginOptions(),
              SalesforceSDKManager.getInstance().shouldLogoutWhenTokenRevoked())
          .getRestClient(
              getActivity(),
              new ClientManager.RestClientCallback() {
                @Override
                public void authenticatedRestClient(final RestClient client) {
                  if (client == null) {
                    SalesforceSDKManager.getInstance().logout(getActivity());
                    return;
                  } else {
                    client.sendAsync(
                        restRequest,
                        new RestClient.AsyncRequestCallback() {
                          @Override
                          public void onSuccess(RestRequest request, RestResponse response) {
                            try {
                              JSONObject jsonObject = new JSONObject(response.toString());
                              activity.setInsertedCaseId(jsonObject.getString("id"));
                              // Getting other information Related to Created Case
                              try {
                                restRequest =
                                    RestRequest.getRequestForQuery(
                                        getString(R.string.api_version),
                                        SoqlStatements.getCaseNumberQuery(
                                            activity.getInsertedCaseId()));
                              } catch (UnsupportedEncodingException e) {
                                e.printStackTrace();
                              }
                              client.sendAsync(
                                  restRequest,
                                  new RestClient.AsyncRequestCallback() {
                                    @Override
                                    public void onSuccess(
                                        RestRequest request, RestResponse response) {
                                      JSONObject jsonObject = null;
                                      Utilities.dismissLoadingDialog();
                                      try {
                                        jsonObject = new JSONObject(response.toString());
                                        JSONArray jsonArray =
                                            jsonObject.getJSONArray(JSONConstants.RECORDS);
                                        JSONObject jsonRecord = jsonArray.getJSONObject(0);
                                        Log.d("resultcase", response.toString());
                                        activity.setCaseNumber(jsonRecord.getString("CaseNumber"));
                                      } catch (JSONException e) {
                                        e.printStackTrace();
                                      }
                                    }

                                    @Override
                                    public void onError(Exception exception) {}
                                  });
                              Log.d("", response.toString());

                            } catch (JSONException e) {
                              e.printStackTrace();
                            }
                          }

                          @Override
                          public void onError(Exception exception) {
                            VolleyError volleyError = (VolleyError) exception;
                            NetworkResponse response = volleyError.networkResponse;
                            String json = new String(response.data);
                            Log.d("", json);
                            Utilities.dismissLoadingDialog();
                            getActivity().finish();
                          }
                        });
                  }
                }
              });
    }
  }
 /**
  * Method called from bridge to logout
  *
  * @param successCallback
  */
 public void logout(Callback successCallback) {
   Log.i(TAG, "logout called");
   SalesforceSDKManager.getInstance().logout(this);
 }
  private void InitializeViews(View view) {
    servicePrice = (EditText) view.findViewById(R.id.servicePrice);
    Utilities.showloadingDialog(activity);
    new ClientManager(
            getActivity(),
            SalesforceSDKManager.getInstance().getAccountType(),
            SalesforceSDKManager.getInstance().getLoginOptions(),
            SalesforceSDKManager.getInstance().shouldLogoutWhenTokenRevoked())
        .getRestClient(
            getActivity(),
            new ClientManager.RestClientCallback() {
              @Override
              public void authenticatedRestClient(final RestClient client) {
                if (client == null) {
                  System.exit(0);
                } else {
                  String Value = "";

                  if (activity
                      .getUser()
                      .get_contact()
                      .get_account()
                      .getLegalForm()
                      .equals("DWC-LLC")) {
                    Value = "Branch";
                  } else if (activity
                      .getUser()
                      .get_contact()
                      .get_account()
                      .getLegalForm()
                      .equals("DWC-Branch")) {
                    Value = "LLC";
                  }
                  String SoqlEServiceQuery = String.format(eServiceAdmin, Value);
                  try {

                    // Getting E-Service Administration
                    restRequest =
                        RestRequest.getRequestForQuery(
                            getActivity().getString(R.string.api_version), SoqlEServiceQuery);
                    client.sendAsync(
                        restRequest,
                        new RestClient.AsyncRequestCallback() {

                          @Override
                          public void onSuccess(RestRequest request, RestResponse result) {

                            activity.seteServiceAdministration(
                                SFResponseManager.parseReceiptObjectResponse(result.toString())
                                    .get(0));
                            servicePrice.setText(
                                activity.geteServiceAdministration().getTotal_Amount__c() + "AED");
                            getRecordType();
                          }

                          @Override
                          public void onError(Exception exception) {
                            VolleyError volleyError = (VolleyError) exception;
                            NetworkResponse response = volleyError.networkResponse;
                            String json = new String(response.data);
                            Log.d("", json);
                            Utilities.dismissLoadingDialog();
                            getActivity().finish();
                          }
                        });
                  } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                  }
                }
              }
            });
  }
Exemplo n.º 16
0
  private void perFormFormFieldsRequest(String soql) {
    try {
      restRequest = RestRequest.getRequestForQuery(getString(R.string.api_version), soql);
      new ClientManager(
              getActivity(),
              SalesforceSDKManager.getInstance().getAccountType(),
              SalesforceSDKManager.getInstance().getLoginOptions(),
              SalesforceSDKManager.getInstance().shouldLogoutWhenTokenRevoked())
          .getRestClient(
              getActivity(),
              new ClientManager.RestClientCallback() {
                @Override
                public void authenticatedRestClient(RestClient client) {
                  if (client == null) {
                    SalesforceSDKManager.getInstance().logout(getActivity());
                    return;
                  } else {
                    Utilities.showloadingDialog(getActivity());
                    client.sendAsync(
                        restRequest,
                        new RestClient.AsyncRequestCallback() {

                          @Override
                          public void onSuccess(RestRequest request, RestResponse result) {
                            picklist = new ArrayList<FormField>();

                            Log.d("", result.toString());
                            NocMainFragment._webForm =
                                SFResponseManager.parseWebFormObject(result.toString());
                            for (int i = 0;
                                i < NocMainFragment._webForm.get_formFields().size();
                                i++) {
                              if (!NocMainFragment._webForm
                                      .get_formFields()
                                      .get(i)
                                      .getType()
                                      .equals("CUSTOMTEXT")
                                  && NocMainFragment._webForm.get_formFields().get(i).isParameter()
                                      == false
                                  && NocMainFragment._webForm.get_formFields().get(i).isQuery()
                                      == true) {
                                visaQueryBuilder +=
                                    NocMainFragment._webForm.get_formFields().get(i).getTextValue()
                                        + ",";
                              } else if (!NocMainFragment._webForm
                                      .get_formFields()
                                      .get(i)
                                      .isParameter()
                                  && NocMainFragment._webForm
                                      .get_formFields()
                                      .get(i)
                                      .getType()
                                      .equals("PICKLIST")) {
                                picklist.add(NocMainFragment._webForm.get_formFields().get(i));
                              }
                            }

                            visaQueryBuilder =
                                visaQueryBuilder.substring(0, visaQueryBuilder.length() - 1);
                            visaQuery =
                                String.format(
                                    visaQuery,
                                    visaQueryBuilder,
                                    NocActivity.get_visa().getVisa_Holder__r().getID());
                            PerformVisaQueryValues(NocMainFragment._webForm, visaQuery);
                          }

                          @Override
                          public void onError(Exception exception) {
                            Utilities.showToast(
                                getActivity(), RestMessages.getInstance().getErrorMessage());
                            Utilities.dismissLoadingDialog();
                            getActivity().finish();
                          }
                        });
                  }
                }
              });
    } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 17
0
  private void PerformVisaQueryValues(final WebForm _webFormFields, String visaQuery) {
    try {
      restRequest = RestRequest.getRequestForQuery(getString(R.string.api_version), visaQuery);
      new ClientManager(
              getActivity(),
              SalesforceSDKManager.getInstance().getAccountType(),
              SalesforceSDKManager.getInstance().getLoginOptions(),
              SalesforceSDKManager.getInstance().shouldLogoutWhenTokenRevoked())
          .getRestClient(
              getActivity(),
              new ClientManager.RestClientCallback() {
                @Override
                public void authenticatedRestClient(RestClient client) {
                  if (client == null) {
                    SalesforceSDKManager.getInstance().logout(getActivity());
                    return;
                  } else {
                    client.sendAsync(
                        restRequest,
                        new RestClient.AsyncRequestCallback() {

                          @Override
                          public void onSuccess(RestRequest request, RestResponse result) {
                            _currentVisa =
                                SFResponseManager.parseVisaData(result.toString()).get(0);
                            visaJson = SFResponseManager.parseJsonVisaData(result.toString());
                            Utilities.dismissLoadingDialog();
                            formFields = _webFormFields.get_formFields();
                            new ClientManager(
                                    getActivity(),
                                    SalesforceSDKManager.getInstance().getAccountType(),
                                    SalesforceSDKManager.getInstance().getLoginOptions(),
                                    SalesforceSDKManager.getInstance()
                                        .shouldLogoutWhenTokenRevoked())
                                .getRestClient(
                                    getActivity(),
                                    new ClientManager.RestClientCallback() {
                                      @Override
                                      public void authenticatedRestClient(final RestClient client) {
                                        if (client == null) {
                                          System.exit(0);
                                        } else {

                                          new GetPickLists(client).execute(picklist);
                                        }
                                      }
                                    });
                            Log.d("Hello", result.toString());
                          }

                          @Override
                          public void onError(Exception exception) {
                            Utilities.showToast(
                                getActivity(), RestMessages.getInstance().getErrorMessage());
                            Utilities.dismissLoadingDialog();
                            getActivity().finish();
                          }
                        });
                  }
                }
              });
    } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
    }
  }
  private void getRecordType() {
    // Getting  Case record Type
    String soql =
        "SELECT Id, Name, DeveloperName, SobjectType FROM RecordType WHERE SObjectType = 'Case' AND DeveloperName = 'License_Request'";
    try {
      restRequest =
          RestRequest.getRequestForQuery(getActivity().getString(R.string.api_version), soql);
      new ClientManager(
              getActivity(),
              SalesforceSDKManager.getInstance().getAccountType(),
              SalesforceSDKManager.getInstance().getLoginOptions(),
              SalesforceSDKManager.getInstance().shouldLogoutWhenTokenRevoked())
          .getRestClient(
              getActivity(),
              new ClientManager.RestClientCallback() {
                @Override
                public void authenticatedRestClient(RestClient client) {
                  if (client == null) {
                    SalesforceSDKManager.getInstance().logout(getActivity());
                    return;
                  } else {
                    client.sendAsync(
                        restRequest,
                        new RestClient.AsyncRequestCallback() {

                          @Override
                          public void onSuccess(RestRequest request, RestResponse result) {
                            try {
                              JSONObject jsonObject = new JSONObject(result.toString());
                              JSONArray jsonArrayRecords =
                                  jsonObject.getJSONArray(JSONConstants.RECORDS);
                              for (int i = 0; i < jsonArrayRecords.length(); i++) {
                                JSONObject jsonRecord = jsonArrayRecords.getJSONObject(i);
                                String objectType = jsonRecord.getString("SobjectType");
                                String DeveloperName = jsonRecord.getString("DeveloperName");
                                if (objectType.equals("Case")
                                    && DeveloperName.equals("License_Request")) {
                                  activity.setCaseRecordTypeId(jsonRecord.getString("Id"));
                                  getCase();
                                }
                              }
                            } catch (JSONException e) {
                              e.printStackTrace();
                            }
                          }

                          @Override
                          public void onError(Exception exception) {
                            VolleyError volleyError = (VolleyError) exception;
                            NetworkResponse response = volleyError.networkResponse;
                            String json = new String(response.data);
                            Log.d("", json);
                            Utilities.dismissLoadingDialog();
                            getActivity().finish();
                          }
                        });
                  }
                }
              });
    } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
    }
  }
  @Override
  public void setUp() throws Exception {

    if (testResults == null || !testResults.containsKey(jsSuite)) {
      if (testResults == null) {
        testResults = new HashMap<String, Map<String, TestResult>>();
      }

      if (!testResults.containsKey(jsSuite)) {
        testResults.put(jsSuite, new HashMap<String, TestResult>());
      }

      // Wait for app initialization to complete
      EventsListenerQueue eq = new EventsListenerQueue();
      if (!SalesforceSDKManager.hasInstance()) {
        eq.waitForEvent(EventType.AppCreateComplete, 5000);
      }

      // Start main activity
      Instrumentation instrumentation = getInstrumentation();
      final Intent intent = new Intent(Intent.ACTION_MAIN);
      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      intent.setClassName(
          instrumentation.getTargetContext(),
          SalesforceSDKManager.getInstance().getMainActivityClass().getName());
      SalesforceDroidGapActivity activity =
          (SalesforceDroidGapActivity) instrumentation.startActivitySync(intent);

      // Block until the javascript has notified the container that it's ready
      TestRunnerPlugin.readyForTests.take();

      // Now run all the tests and collect the resuts in testResults
      for (String testName : getTestNames()) {
        final String jsCmd =
            "javascript:"
                + "navigator.testrunner.setTestSuite('"
                + jsSuite
                + "');"
                + "navigator.testrunner.startTest('"
                + testName
                + "');";
        final CordovaWebView appView = activity.getAppView();
        if (appView != null) {
          appView
              .getView()
              .post(
                  new Runnable() {
                    @Override
                    public void run() {
                      appView.loadUrl(jsCmd);
                    }
                  });
        }
        Log.i(getClass().getSimpleName(), "running test:" + testName);

        // Block until test completes or times out
        TestResult result = null;
        int timeout = getMaxRuntimeInSecondsForTest(testName);
        try {
          result = TestRunnerPlugin.testResults.poll(timeout, TimeUnit.SECONDS);
          if (result == null) {
            result =
                new TestResult(
                    testName, false, "Timeout (" + timeout + " seconds) exceeded", timeout);
          }
        } catch (Exception e) {
          result = new TestResult(testName, false, "Test failed", timeout);
        }
        Log.i(getClass().getSimpleName(), "done running test:" + testName);

        // Save result
        testResults.get(jsSuite).put(testName, result);
      }

      // Cleanup
      eq.tearDown();
      activity.finish();
    }
  }
 /** Dump info about app and rest client */
 private void printInfo() {
   printHeader("Info");
   println(SalesforceSDKManager.getInstance());
   println(client);
 }
 /**
  * Called when "Logout" button is clicked.
  *
  * @param v View that was clicked.
  */
 public void onLogoutClick(View v) {
   SalesforceSDKManager.getInstance().logout(this);
 }