public void onReceive(Context context, Intent intent) {

    try {
      if (intent != null && (intent.getAction().equals("com.android.vending.INSTALL_REFERRER"))) {
        String encodedreferrer = intent.getStringExtra("referrer");

        if (encodedreferrer != null) {

          String decodedreferrer = URLDecoder.decode(encodedreferrer, "utf-8");

          UrlQuerySanitizer querydecoder = new UrlQuerySanitizer();
          querydecoder.setAllowUnregisteredParamaters(true);
          querydecoder.parseQuery(decodedreferrer);

          if (querydecoder.hasParameter(REFERER_KEY)) {
            MeasurementServiceLog.d("Referrer Tracker - recovered install referrer");
            context
                .getSharedPreferences(REFERER_PREFS, Context.MODE_PRIVATE)
                .edit()
                .putString(REFERER_KEY, querydecoder.getValue(REFERER_KEY))
                .apply();
          } else {
            MeasurementServiceLog.d("Referrer Tracker - referrer missing PHN reference parameter");
          }
        } else {
          MeasurementServiceLog.d("Referrer Tracker - missing referrer from install broadcast");
        }
      }
    } catch (UnsupportedEncodingException exception) {
      MeasurementServiceLog.e("Referrer Tracker Exception");
    }
  }
Ejemplo n.º 2
0
  private void performAuthentication(DefaultHttpClient httpClient, AuthToken authToken)
      throws IOException, AuthenticationException {
    HttpResponse resp;
    final ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair(PARAM_USERNAME, authToken.username));
    params.add(new BasicNameValuePair(PARAM_PASSWORD, authToken.password));
    params.add(new BasicNameValuePair(PARAM_USER_TIME, "dummy"));
    final HttpEntity entity;
    try {
      entity = new UrlEncodedFormEntity(params);
    } catch (final UnsupportedEncodingException e) {
      // this should never happen.
      throw new IllegalStateException(e);
    }
    String uri =
        BASE_URL
            + "?"
            + URLEncodedUtils.format(
                Arrays.asList(new BasicNameValuePair(XML_ID, AUTH_XML_ID)), ENCODING);
    Log.i(TAG, "Authenticating to: " + uri);

    final HttpPost post = new HttpPost(uri);
    post.addHeader(entity.getContentType());
    post.setHeader("Accept", "*/*");
    post.setEntity(entity);
    resp = httpClient.execute(post);

    // check for bad status
    if (resp.getStatusLine().getStatusCode() != HttpStatus.SC_MOVED_TEMPORARILY) {
      throw new ParseException(
          "status after auth: "
              + resp.getStatusLine().getStatusCode()
              + " "
              + resp.getStatusLine().getReasonPhrase());
    }

    // check header redirect
    Header[] locations = resp.getHeaders(HEADER_LOCATION);
    if (locations.length != 1) {
      throw new ParseException(locations.length + " header locations received!");
    }

    String location = "https://" + DOMAIN + locations[0].getValue();
    Log.v(TAG, "location=" + location);

    UrlQuerySanitizer sanitizer = new UrlQuerySanitizer(location);
    authToken.userId = sanitizer.getValue(PARAM_USER_ID);
    authToken.sessionId = sanitizer.getValue(PARAM_SESSION_ID);
    String redirectedXmlId = sanitizer.getValue(XML_ID);

    if (authToken.userId == null
        || authToken.userId.length() == 0
        || authToken.sessionId == null
        || authToken.sessionId.length() == 0
        || AUTH_XML_ID.equalsIgnoreCase(redirectedXmlId)) {
      checkAuthError(sanitizer);
    }
  }
Ejemplo n.º 3
0
 private void checkAuthError(UrlQuerySanitizer sanitizer) throws AuthenticationException {
   String loginReasonId = sanitizer.getValue("strLoginReason");
   if (loginReasonId == null) {
     throw new ParseException("Unknown reason for bad auth");
   }
   throw new AuthenticationException("Bad auth because of " + loginReasonId);
 }