This commit is contained in:
wangcongtao
2020-12-08 14:08:53 +08:00
840 changed files with 31903 additions and 11168 deletions

View File

@@ -110,6 +110,9 @@ public class AppUtils {
* @return true 表示正在运行false 表示没有运行
*/
public static boolean isProcessRunning( Context context, int uid ) {
if ( context == null ) {
return false;
}
ActivityManager am = ( ActivityManager ) context.getSystemService( Context.ACTIVITY_SERVICE );
List< ActivityManager.RunningServiceInfo > runningServiceInfos = am.getRunningServices( 200 );
if ( runningServiceInfos.size() > 0 ) {

View File

@@ -16,14 +16,23 @@ public class WorkThreadHandler {
private Handler mHandler;
private HandlerThread mThread;
private WorkThreadHandler() {
public static WorkThreadHandler newInstance( String name ) {
return new WorkThreadHandler( name );
}
private WorkThreadHandler( String name ) {
// private constructor
mThread = new HandlerThread( "work-thread-handler" );
mThread = new HandlerThread( name );
mThread.start();
mThreadLooper = mThread.getLooper();
mHandler = new Handler( mThreadLooper );
}
private WorkThreadHandler() {
// private constructor
this( "work-thread-handler" );
}
private static final class InstanceHolder {
private static final WorkThreadHandler INSTANCE = new WorkThreadHandler();
}

View File

@@ -0,0 +1,17 @@
package com.mogo.utils.network;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.List;
public
/**
* @author congtaowang
* @since 2020/11/18
*
* 将HOST转换为HttpDNS的ip
*/
interface HttpDns {
List< InetAddress > lookup( String hostname ) throws UnknownHostException;
}

View File

@@ -46,6 +46,8 @@ public final class NetConfig {
private SSLContext sslContext;
private HttpDns httpDns;
private NetConfig() {
}
@@ -157,4 +159,13 @@ public final class NetConfig {
public synchronized void setSslContext( SSLContext sslContext ) {
this.sslContext = sslContext;
}
public HttpDns getHttpDns() {
return httpDns;
}
public NetConfig setHttpDns( HttpDns httpDns ) {
this.httpDns = httpDns;
return this;
}
}

View File

@@ -1,8 +1,12 @@
package com.mogo.utils.network;
import java.net.InetAddress;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import okhttp3.ConnectionPool;
import okhttp3.Dns;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
@@ -45,6 +49,17 @@ public final class OkHttpFactory {
builder.addNetworkInterceptor(networkInterceptor);
}
HttpDns httpDns = NetConfig.instance().getHttpDns();
if ( httpDns != null ) {
builder.dns( hostname -> {
List< InetAddress > addresses = httpDns.lookup( hostname );
if ( addresses != null && !addresses.isEmpty() ) {
return addresses;
}
return Dns.SYSTEM.lookup( hostname );
} );
}
sInstance = builder.build();
}
}

View File

@@ -65,7 +65,7 @@ public class RequestOptions {
/**
* Mutator for indicating whether loading message should be displayed while request is ongoing
*/
private RequestOptions loading( boolean loading ) {
public RequestOptions loading( boolean loading ) {
this.loading = loading;
return this;
}