Android Open Source - utwitterapi Ok Http Client Modify Request Callback






From Project

Back to project page utwitterapi.

License

The source code is released under:

GNU General Public License

If you think the Android project utwitterapi listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.mariotaku.utwitterapi.hook;
/*from   w w w  .  ja v a  2s .  c  om*/
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.net.URLConnection;

import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSocketFactory;

import org.mariotaku.utwitterapi.Constants;
import org.mariotaku.utwitterapi.util.AllowAllHostnameVerifierImpl;
import org.mariotaku.utwitterapi.util.TrustAllSSLSocketFactory;
import org.mariotaku.utwitterapi.util.Utils;
import org.mariotaku.utwitterapi.util.XposedPluginUtils;

import android.text.TextUtils;
import de.robv.android.xposed.XC_MethodReplacement;
import de.robv.android.xposed.XposedBridge;

public class OkHttpClientModifyRequestCallback extends XC_MethodReplacement implements Constants {

  @Override
  protected Object replaceHookedMethod(final MethodHookParam param) throws Throwable {
    try {
      final Object[] args = param.args;
      if (args == null || args.length != 1 || !(args[0] instanceof URL))
        return XposedBridge.invokeOriginalMethod(param.method, param.thisObject, param.args);
      final URL url = (URL) args[0];
      final String origUriString = url.toString();
      final String host = url.getHost();
      if (Utils.isTwitterAPIHost(host) && XposedPluginUtils.isUsingCustomAPI()) {
        final String replacedUriString = XposedPluginUtils.replaceAPIUri(origUriString);
        final String hostHeaderValue = XposedPluginUtils.getCustomAPIHostHeader(origUriString);
        args[0] = new URL(replacedUriString);
        final Object result = XposedBridge.invokeOriginalMethod(param.method, param.thisObject, args);
        if (result instanceof URLConnection && !TextUtils.isEmpty(hostHeaderValue)) {
          final URLConnection conn = (URLConnection) result;
          conn.setRequestProperty("Host", hostHeaderValue);
        }
        if (result instanceof HttpsURLConnection) {
          final HttpsURLConnection conn = (HttpsURLConnection) result;
          conn.setHostnameVerifier(new AllowAllHostnameVerifierImpl());
          final SSLSocketFactory factory = TrustAllSSLSocketFactory.getSocketFactory();
          if (factory != null) {
            conn.setSSLSocketFactory(factory);
          }
        }
        return result;
      }
      return XposedBridge.invokeOriginalMethod(param.method, param.thisObject, param.args);
    } catch (final InvocationTargetException e) {
      final Throwable cause = e.getCause();
      if (cause != null) throw cause;
      throw e;
    }
  }

}




Java Source Code List

org.mariotaku.utwitterapi.Constants.java
org.mariotaku.utwitterapi.UTwitterAPIPlugin.java
org.mariotaku.utwitterapi.activity.BrowserSigninAgentActivity.java
org.mariotaku.utwitterapi.activity.PinCodeActivity.java
org.mariotaku.utwitterapi.activity.PluginSettingsActivity.java
org.mariotaku.utwitterapi.adapter.ApplicationsListAdapter.java
org.mariotaku.utwitterapi.fragment.AddApplicationDialogFragmnt.java
org.mariotaku.utwitterapi.fragment.EditAPIDialogFragment.java
org.mariotaku.utwitterapi.fragment.ProgressDialogFragment.java
org.mariotaku.utwitterapi.fragment.ProxiedClientsListFragment.java
org.mariotaku.utwitterapi.fragment.XposedNotAvailableDialogFragment.java
org.mariotaku.utwitterapi.hook.ApacheSSLSocketFactoryHook.java
org.mariotaku.utwitterapi.hook.HttpClientModifyRequestCallback.java
org.mariotaku.utwitterapi.hook.HttpsURLConnectionSetHostnameVerifierCallback.java
org.mariotaku.utwitterapi.hook.HttpsURLConnectionSetSSLSocketFactoryCallback.java
org.mariotaku.utwitterapi.hook.OkHttpClientModifyRequestCallback.java
org.mariotaku.utwitterapi.hook.SchemeGetSocketFactoryCallback.java
org.mariotaku.utwitterapi.hook.Twitter4JFixURLCallback.java
org.mariotaku.utwitterapi.hook.Twitter4JForceHttpsCallback.java
org.mariotaku.utwitterapi.hook.URLConnectionModifyRequestCallback.java
org.mariotaku.utwitterapi.loader.AbsApplicationsLoader.java
org.mariotaku.utwitterapi.loader.ApplicationsLoader.java
org.mariotaku.utwitterapi.loader.ProxiedApplicationsLoader.java
org.mariotaku.utwitterapi.util.AllowAllHostnameVerifierImpl.java
org.mariotaku.utwitterapi.util.OAuthPasswordAuthenticator.java
org.mariotaku.utwitterapi.util.TrustAllApacheSSLSocketFactory.java
org.mariotaku.utwitterapi.util.TrustAllSSLSocketFactory.java
org.mariotaku.utwitterapi.util.TrustAllX509TrustManager.java
org.mariotaku.utwitterapi.util.Utils.java
org.mariotaku.utwitterapi.util.XposedPluginUtils.java