Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
firelotus committed Aug 1, 2018
2 parents 6937812 + 6c6a41b commit 6e237d2
Show file tree
Hide file tree
Showing 34 changed files with 448 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ captures/
.idea/

# Keystore files
*.jks
#*.jks

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild
Expand Down
Binary file added MeteoriteKeyStore.jks
Binary file not shown.
4 changes: 3 additions & 1 deletion MeteoriteLibrary/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ dependencies {
compile "com.android.support.constraint:constraint-layout:${versions.constraintLayout}"
compile "com.android.support:support-annotations:${versions.supportLib}"

compile 'com.android.support:multidex:1.0.3'

//Simple, pretty and powerful logger for android
compile "com.orhanobut:logger:${versions.logger}"

Expand Down Expand Up @@ -101,6 +103,6 @@ dependencies {
compile "com.github.chrisbanes:PhotoView:${versions.PhotoView}"

//test

compile 'com.qianwen:okhttp-utils:3.8.0'

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.firelotus.meteoritelibrary.R;
import com.firelotus.meteoritelibrary.config.Constants;
import com.firelotus.meteoritelibrary.toast.MToast;
import com.firelotus.meteoritelibrary.utils.CleanLeakUtils;
import com.firelotus.meteoritelibrary.utils.DialogUtils;

import butterknife.ButterKnife;
Expand Down Expand Up @@ -77,7 +78,7 @@ public void setContentView(@LayoutRes int layoutResID) {
// content
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
activity.setLayoutParams(params);
RelativeLayout mContainer = (RelativeLayout) activity_base.findViewById(R.id.container);
RelativeLayout mContainer = activity_base.findViewById(R.id.container);
mContainer.addView(activity);
getWindow().setContentView(activity_base);

Expand Down Expand Up @@ -119,6 +120,7 @@ protected void onStop() {
protected void onDestroy() {
super.onDestroy();
mUnbinder.unbind();
CleanLeakUtils.fixInputMethodManagerLeak(context);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import android.widget.RelativeLayout;

import com.firelotus.meteoritelibrary.R;
import com.firelotus.meteoritelibrary.utils.CleanLeakUtils;

import butterknife.ButterKnife;
import butterknife.Unbinder;
Expand Down Expand Up @@ -77,7 +78,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
contentView = inflater.inflate(getLayoutId(), null, false);
contentView.setLayoutParams(params);
mContainer = (RelativeLayout) fragment_base.findViewById(R.id.container);
mContainer = fragment_base.findViewById(R.id.container);
mContainer.addView(contentView);
mUnbinder = ButterKnife.bind(this, contentView);
return fragment_base;
Expand Down Expand Up @@ -156,6 +157,7 @@ public void onDestroyView() {
isLoad = false;
isVisible = false;
mUnbinder.unbind();
CleanLeakUtils.fixInputMethodManagerLeak(activity);
}

/**
Expand Down Expand Up @@ -190,7 +192,7 @@ protected <E extends View> E findViewById(int viewId) {
if (contentView != null) {
E view = (E) mViews.get(viewId);
if (view == null) {
view = (E) contentView.findViewById(viewId);
view = contentView.findViewById(viewId);
mViews.put(viewId, view);
}
return view;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,20 @@

import android.content.Context;

import com.firelotus.meteoritelibrary.utils.Tls12SocketFactory;
import com.tamic.novate.Novate;

import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

/**
* Created by firelotus on 2017/12/13.
*/
Expand All @@ -24,10 +36,71 @@ public void init(Context context,String baseUrl){
if(novate == null){
novate = new Novate.Builder(context)
.baseUrl(baseUrl)
.addSSLSocketFactory(getTrustAllSSLSocketFactory())
.addHostnameVerifier(getTrustAllHostnameVerifier())
.addInterceptor(new NetworkInterceptor(context))
//.addCache(false)//解决无网络请求异常后,有网也无法获取数据问题
.build();
this.context = context;
}
}

/**
* 默认信任所有证书
*
* @return
*/
protected static SSLSocketFactory getTrustAllSSLSocketFactory() {
try {
TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
@Override
public void checkClientTrusted(
java.security.cert.X509Certificate[] x509Certificates,
String s) {
}

@Override
public void checkServerTrusted(
java.security.cert.X509Certificate[] x509Certificates,
String s) {
}

@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[]{};
}
}};

SSLContext sslContext = SSLContext.getInstance("TLS");

sslContext.init(null, trustAllCerts, new SecureRandom());
//SFLog.d("sslContext.getSocketFactory()==>>"+sslContext.getSocketFactory());
return new Tls12SocketFactory(sslContext.getSocketFactory());
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}

return null;
}

/**
* 网址不校验
*
* @return
*/
protected static HostnameVerifier getTrustAllHostnameVerifier() {

HostnameVerifier TRUSTED_VERIFIER = new HostnameVerifier() {

public boolean verify(String hostname, SSLSession session) {
//SFLog.d("verify==>>true");
return true;
}
};

return TRUSTED_VERIFIER;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.firelotus.meteoritelibrary.utils;

import android.content.Context;
import android.view.inputmethod.InputMethodManager;

import java.lang.reflect.Field;

/**
* InputMethodManager内存泄露现象及解决
*/
public class CleanLeakUtils {
public static void fixInputMethodManagerLeak(Context context) {
if (context == null) {
return;
}
try {
// 对 mCurRootView mServedView mNextServedView 进行置空...
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm == null) {
return;
}// author:sodino mail:[email protected]

Object obj_get = null;
Field f_mCurRootView = imm.getClass().getDeclaredField("mCurRootView");
Field f_mServedView = imm.getClass().getDeclaredField("mServedView");
Field f_mNextServedView = imm.getClass().getDeclaredField("mNextServedView");

if (f_mCurRootView.isAccessible() == false) {
f_mCurRootView.setAccessible(true);
}
obj_get = f_mCurRootView.get(imm);
if (obj_get != null) { // 不为null则置为空
f_mCurRootView.set(imm, null);
}

if (f_mServedView.isAccessible() == false) {
f_mServedView.setAccessible(true);
}
obj_get = f_mServedView.get(imm);
if (obj_get != null) { // 不为null则置为空
f_mServedView.set(imm, null);
}

if (f_mNextServedView.isAccessible() == false) {
f_mNextServedView.setAccessible(true);
}
obj_get = f_mNextServedView.get(imm);
if (obj_get != null) { // 不为null则置为空
f_mNextServedView.set(imm, null);
}
} catch (Throwable t) {
t.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.firelotus.meteoritelibrary.utils;

import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;

import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;

/**
* 解决Android4.x系统访问网络时可能出现TLS版本不支持异常报错的问题。
* https://blog.csdn.net/s003603u/article/details/53907910
* Android4.x系统对TLS的支持存在版本差异,
* TLSv1.0从API 1+就被默认打开
* TLSv1.1和TLSv1.2只有在API 20+ 才会被默认打开
* 也就是说低于API 20+的版本是默认关闭对TLSv1.1和TLSv1.2的支持,若要支持则必须自己打开
*/
public class Tls12SocketFactory extends SSLSocketFactory {
private static final String[] TLS_SUPPORT_VERSION = {"TLSv1.1", "TLSv1.2"};

final SSLSocketFactory delegate;

public Tls12SocketFactory(SSLSocketFactory base) {
this.delegate = base;
}

@Override
public String[] getDefaultCipherSuites() {
return delegate.getDefaultCipherSuites();
}

@Override
public String[] getSupportedCipherSuites() {
return delegate.getSupportedCipherSuites();
}

@Override
public Socket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException {
return patch(delegate.createSocket(s, host, port, autoClose));
}

@Override
public Socket createSocket(String host, int port) throws IOException {
return patch(delegate.createSocket(host, port));
}

@Override
public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException {
return patch(delegate.createSocket(host, port, localHost, localPort));
}

@Override
public Socket createSocket(InetAddress host, int port) throws IOException {
return patch(delegate.createSocket(host, port));
}

@Override
public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException {
return patch(delegate.createSocket(address, port, localAddress, localPort));
}

private Socket patch(Socket s) {
if (s instanceof SSLSocket) {
((SSLSocket) s).setEnabledProtocols(TLS_SUPPORT_VERSION);
}
return s;
}
}
Loading

0 comments on commit 6e237d2

Please sign in to comment.