[sonar] code bug

This commit is contained in:
zhongchao
2023-10-19 16:28:13 +08:00
parent 195f971425
commit 2a3e01f66e
44 changed files with 392 additions and 2756 deletions

View File

@@ -96,21 +96,6 @@
</activity>
<!-- <activity-->
<!-- android:name="com.mogo.eagle.core.function.main.VideoAdAtc"-->
<!-- android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|screenLayout|fontScale|uiMode|orientation|screenSize|smallestScreenSize"-->
<!-- android:enabled="true"-->
<!-- android:exported="true"-->
<!-- android:process=":video_ad"-->
<!-- android:resizeableActivity="false"-->
<!-- android:resumeWhilePausing="true"-->
<!-- android:screenOrientation="landscape"-->
<!-- android:stateNotNeeded="true"-->
<!-- android:theme="@style/Main"-->
<!-- android:windowSoftInputMode="adjustPan|stateHidden">-->
<!-- </activity>-->
<activity
android:name="com.mogo.eagle.core.function.main.AppListActivity"
android:exported="true"

View File

@@ -25,7 +25,7 @@ public class LogLine {
"\\): ");
private static final String filterPattern = "ResourceType|memtrack|android.os.Debug|BufferItemConsumer|DPM.*|MDM.*|ChimeraUtils|BatteryExternalStats.*|chatty.*|DisplayPowerController|WidgetHelper|WearableService|DigitalWidget.*|^ANDR-PERF-.*";
private static final String failPattern = "^maxLineHeight.*|Failed to read.*";
private static final String failPattern = "(^maxLineHeight.*)|(Failed to read.*)";
private int logLevel;
private String tag;
private String logOutput;

View File

@@ -1,29 +0,0 @@
package com.mogo.eagle.core.function.main
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.mogo.eagle.core.function.hmi.R
import com.mogo.eagle.core.utilcode.util.BarUtils
import com.mogo.eagle.core.widget.TextureVideoView
/**
* 视频广告 TODO 测试用的,可删除
*/
class VideoAdAtc : AppCompatActivity() {
// private lateinit var svpFrame: TextureVideoView
//
// override fun onCreate(savedInstanceState: Bundle?) {
// super.onCreate(savedInstanceState)
// setContentView(R.layout.activity_video_ad_atc)
//
// svpFrame = findViewById(R.id.svp_frame)
//
// val url = "android.resource://" + packageName + "/" + R.raw.mogo_ad
// svpFrame.videoPath = url
// svpFrame.start()
//
// BarUtils.hideStatusBarAndSticky(this.window)
// }
}

View File

@@ -1,16 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/road_video_bg"
tools:context="com.mogo.eagle.core.function.main.VideoAdAtc">
<com.mogo.eagle.core.widget.TextureVideoView
android:id="@+id/svp_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -1,18 +0,0 @@
package com.mogo.eagle.core.network;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSession;
/**
* @author congtaowang
* @since 2019-08-30
* <p>
* 信任所有域名
*/
public class AllAllowedHostnameVerifier implements HostnameVerifier {
@Override
public boolean verify( String hostname, SSLSession session ) {
return true;
}
}

View File

@@ -3,8 +3,6 @@ package com.mogo.eagle.core.network;
import android.app.Application;
import android.content.Context;
import com.mogo.cloud.passport.SpStorage;
import androidx.collection.ArraySet;
import java.security.SecureRandom;
@@ -13,7 +11,6 @@ import java.util.Set;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import okhttp3.Interceptor;
@@ -34,15 +31,10 @@ public final class NetConfig {
private final Set< Interceptor > interceptors = new ArraySet<>();
private final Set< Interceptor > networkInterceptors = new ArraySet<>();
private final HostnameVerifier allowAllHostnameVerifier = new HostnameVerifier() {
@Override
public boolean verify( String hostname, SSLSession session ) {
return true;
}
};
private final HostnameVerifier allowAllHostnameVerifier = (hostname, session) -> true;
private String signaturePrefix = "com.foundation.network";
private HostnameVerifier hostnameVerifier = OkHostnameVerifier.INSTANCE;
private final HostnameVerifier hostnameVerifier = OkHostnameVerifier.INSTANCE;
private Map< String, Object > publicParams;
private boolean isLoggable;
private Context appContext;

View File

@@ -1,5 +1,7 @@
package com.mogo.eagle.core.network;
import android.annotation.SuppressLint;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
@@ -13,11 +15,13 @@ import javax.net.ssl.X509TrustManager;
*/
public class X509TrustManagerImpl implements X509TrustManager {
@SuppressLint("TrustAllX509TrustManager")
@Override
public void checkClientTrusted( X509Certificate[] chain, String authType ) throws CertificateException {
}
@SuppressLint("TrustAllX509TrustManager")
@Override
public void checkServerTrusted( X509Certificate[] chain, String authType ) throws CertificateException {

View File

@@ -43,7 +43,6 @@ import java.util.Map;
* provides various display options such as scaling and tinting.
*/
public class TextureVideoView extends TextureView implements MediaPlayerControl {
private String TAG = "TextureVideoView";
public static final int STATE_ERROR = -1;
public static final int STATE_IDLE = 0;

View File

@@ -38,9 +38,9 @@ public class GlideCircleBitmapTransform extends BitmapTransformation {
int radius = newSize / 2;
Bitmap bitmap = Bitmap.createBitmap( toTransform, x, y, newSize, newSize );
Bitmap result = pool.get( newSize, newSize, toTransform.getConfig() );
if ( result == null ) {
result = Bitmap.createBitmap( newSize, newSize, toTransform.getConfig() );
}
// if ( result == null ) { //get() func always return not null
// result = Bitmap.createBitmap( newSize, newSize, toTransform.getConfig() );
// }
Canvas canvas = new Canvas( result );
if ( mBorderWidth > 0 ) {

View File

@@ -18,11 +18,11 @@ import java.security.MessageDigest;
public class GlideRoundBitmapTransform extends BitmapTransformation {
private int mRadius;
private int mBorderWidth;
private int mBorderColor;
private String mKey;
private Context mContext;
private final int mRadius;
private final int mBorderWidth;
private final int mBorderColor;
private final String mKey;
private final Context mContext;
public GlideRoundBitmapTransform( Context context, String key, int radius, int borderWidth, int borderColor ) {
this.mContext = context;
@@ -41,9 +41,9 @@ public class GlideRoundBitmapTransform extends BitmapTransformation {
int height = toTransform.getHeight();
RectF rectF = new RectF( mBorderWidth, mBorderWidth, width - mBorderWidth, height - mBorderWidth );
Bitmap result = pool.get( width, height, toTransform.getConfig() );
if ( result == null ) {
result = toTransform.copy( toTransform.getConfig(), true );
}
// if ( result == null ) { //get() func always return not null
// result = toTransform.copy( toTransform.getConfig(), true );
// }
Canvas canvas = new Canvas( result );
Paint paint = new Paint();
paint.setShader( new BitmapShader( toTransform, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP ) );

View File

@@ -22,8 +22,8 @@ import androidx.annotation.NonNull;
* @author tongchenfei
*/
public class GlideRoundedCornersTransform extends CenterCrop {
private float mRadius;
private CornerType mCornerType;
private final float mRadius;
private final CornerType mCornerType;
private static final int VERSION = 1;
private static final String ID = BuildConfig.LIBRARY_PACKAGE_NAME + "GlideRoundedCornersTransform." + VERSION;
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
@@ -62,10 +62,10 @@ public class GlideRoundedCornersTransform extends CenterCrop {
int height = source.getHeight();
Bitmap result = pool.get(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
if (result == null) {
result = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config
.ARGB_8888);
}
// if (result == null) { //get() func always return not null
// result = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config
// .ARGB_8888);
// }
Canvas canvas = new Canvas(result);
Paint paint = new Paint();
paint.setShader(new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader
@@ -102,6 +102,7 @@ public class GlideRoundedCornersTransform extends CenterCrop {
drawPath(rids, canvas, paint, path, width, height);
break;
case TOP:
case TOP_LEFT_TOP_RIGHT:
rids = new float[]{mRadius, mRadius, mRadius, mRadius, 0.0f, 0.0f, 0.0f, 0.0f};
drawPath(rids, canvas, paint, path, width, height);
break;
@@ -133,10 +134,6 @@ public class GlideRoundedCornersTransform extends CenterCrop {
rids = new float[]{0.0f, 0.0f, mRadius, mRadius, mRadius, mRadius, mRadius, mRadius};
drawPath(rids, canvas, paint, path, width, height);
break;
case TOP_LEFT_TOP_RIGHT:
rids = new float[]{mRadius, mRadius, mRadius, mRadius, 0.0f, 0.0f, 0.0f, 0.0f};
drawPath(rids, canvas, paint, path, width, height);
break;
default:
throw new RuntimeException("RoundedCorners type not belong to CornerType");
}

View File

@@ -107,7 +107,7 @@ final class LoggerPrinter implements Printer {
}
}
private static final String xmlHtml = "http://xml.apache.org/xslt";
private static final String xmlHtml = "{http://xml.apache.org/xslt}indent-amount";
public void xml( String tag, String xml) {
if ( TextUtils.isEmpty(xml)) {
@@ -118,7 +118,7 @@ final class LoggerPrinter implements Printer {
StreamResult xmlOutput = new StreamResult(new StringWriter());
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty("indent", "yes");
transformer.setOutputProperty("{" + xmlHtml + "}indent-amount", "2");
transformer.setOutputProperty(xmlHtml, "2");
transformer.transform(e, xmlOutput);
this.d(tag, xmlOutput.getWriter().toString().replaceFirst(">", ">\n"));
} catch ( TransformerException var5) {

View File

@@ -61,9 +61,7 @@ public final class CollectionUtils {
public static <E> ArrayList<E> newArrayList(E... array) {
ArrayList<E> list = new ArrayList<>();
if (array == null || array.length == 0) return list;
for (E e : array) {
list.add(e);
}
list.addAll(Arrays.asList(array));
return list;
}
@@ -82,9 +80,7 @@ public final class CollectionUtils {
public static <E> LinkedList<E> newLinkedList(E... array) {
LinkedList<E> list = new LinkedList<>();
if (array == null || array.length == 0) return list;
for (E e : array) {
list.add(e);
}
list.addAll(Arrays.asList(array));
return list;
}
@@ -103,9 +99,7 @@ public final class CollectionUtils {
public static <E> HashSet<E> newHashSet(E... array) {
HashSet<E> set = new HashSet<>();
if (array == null || array.length == 0) return set;
for (E e : array) {
set.add(e);
}
set.addAll(Arrays.asList(array));
return set;
}
@@ -124,9 +118,7 @@ public final class CollectionUtils {
public static <E> TreeSet<E> newTreeSet(Comparator<E> comparator, E... array) {
TreeSet<E> set = new TreeSet<>(comparator);
if (array == null || array.length == 0) return set;
for (E e : array) {
set.add(e);
}
set.addAll(Arrays.asList(array));
return set;
}

View File

@@ -578,7 +578,12 @@ public final class ConvertUtils {
*/
public static byte[] inputStream2Bytes(final InputStream is) {
if (is == null) return null;
return input2OutputStream(is).toByteArray();
ByteArrayOutputStream byteArrayOutputStream = input2OutputStream(is);
if(byteArrayOutputStream != null){
return byteArrayOutputStream.toByteArray();
}else{
return null;
}
}
/**

View File

@@ -3,6 +3,7 @@ package com.mogo.eagle.core.utilcode.util;
import org.jetbrains.annotations.NotNull;
import java.math.BigDecimal;
import java.math.RoundingMode;
/**
* @author donghongyu
@@ -10,10 +11,6 @@ import java.math.BigDecimal;
public class CoordinateUtils {
/**
* @param lon1
* @param lat1
* @param lon2
* @param lat2
* @return 两坐标的距离 单位M
*/
public static float calculateLineDistance( double lon1, double lat1, double lon2, double lat2 ) {
@@ -56,11 +53,11 @@ public class CoordinateUtils {
private static final double a = 6378245.0D;
private static final double ee = 0.006693421622965943D;
public static final boolean outOfChina( double lat, double lng ) {
public static boolean outOfChina(double lat, double lng ) {
return lng <= 73.66D || lng >= 135.05D || lat <= 3.86D || lat >= 53.55D;
}
private static final double transformLat( double lng, double lat ) {
private static double transformLat(double lng, double lat ) {
double ret = -100.0D + 2.0D * lng + 3.0D * lat + 0.2D * lat * lat + 0.1D * lng * lat + 0.2D * Math.sqrt( Math.abs( lng ) );
ret += ( 20.0D * Math.sin( 6.0D * lng * 3.141592653589793D ) + 20.0D * Math.sin( 2.0D * lng * 3.141592653589793D ) ) * 2.0D / 3.0D;
ret += ( 20.0D * Math.sin( lat * 3.141592653589793D ) + 40.0D * Math.sin( lat / 3.0D * 3.141592653589793D ) ) * 2.0D / 3.0D;
@@ -68,7 +65,7 @@ public class CoordinateUtils {
return ret;
}
private static final double transformLon( double lng, double lat ) {
private static double transformLon(double lng, double lat ) {
double ret = 300.0D + lng + 2.0D * lat + 0.1D * lng * lng + 0.1D * lng * lat + 0.1D * Math.sqrt( Math.abs( lng ) );
ret += ( 20.0D * Math.sin( 6.0D * lng * 3.141592653589793D ) + 20.0D * Math.sin( 2.0D * lng * 3.141592653589793D ) ) * 2.0D / 3.0D;
ret += ( 20.0D * Math.sin( lng * 3.141592653589793D ) + 40.0D * Math.sin( lng / 3.0D * 3.141592653589793D ) ) * 2.0D / 3.0D;
@@ -78,12 +75,11 @@ public class CoordinateUtils {
@NotNull
// World Geodetic System ==> Mars Geodetic System
public static final double[] transformWgsToGcj( double wgLat, double wgLon ) {
public static double[] transformWgsToGcj(double wgLat, double wgLon ) {
double[] point = new double[2];
if ( outOfChina( wgLat, wgLon ) ) {
point[0] = wgLon;
point[1] = wgLat;
return point;
} else {
double dLat = transformLat( wgLon - 105.0D, wgLat - 35.0D );
double dLon = transformLon( wgLon - 105.0D, wgLat - 35.0D );
@@ -97,12 +93,12 @@ public class CoordinateUtils {
double mgLon = wgLon + dLon;
point[0] = dealRound( mgLon );
point[1] = dealRound( mgLat );
return point;
}
return point;
}
@NotNull
public static final double[] transformGcj02toWgs84( double lat, double lng ) {
public static double[] transformGcj02toWgs84(double lat, double lng ) {
double[] var10000;
if ( outOfChina( lat, lng ) ) {
var10000 = new double[]{lng, lat};
@@ -123,10 +119,9 @@ public class CoordinateUtils {
return var10000;
}
private static final double dealRound( double value ) {
BigDecimal bg = new BigDecimal( value );
double result = bg.setScale( 6, 4 ).doubleValue();
return result;
private static double dealRound(double value ) {
BigDecimal bg = BigDecimal.valueOf( value );
return bg.setScale( 6, RoundingMode.HALF_UP).doubleValue();
}
}

View File

@@ -45,6 +45,9 @@ public class DateTimeUtils {
public static Calendar cleanCalendarTime( Calendar c) {
if(c == null){
return null;
}
c.set( Calendar.HOUR_OF_DAY, 0);
c.set( Calendar.MINUTE, 0);
c.set( Calendar.SECOND, 0);
@@ -54,10 +57,6 @@ public class DateTimeUtils {
/**
* 获得指定日期表示格式转换成Calendar的格式
*
* @param src
* @param fallback 若无法转换,返回一个默认值
* @return
*/
public static <T> Calendar getCalendar( T src, Calendar fallback) {
if (src != null) {
@@ -101,7 +100,7 @@ public class DateTimeUtils {
return getCalendarByPatterns(nSrc, PATTERNS);
} catch ( Exception e) {
try {
calendar.setTimeInMillis( Long.valueOf(nSrc));
calendar.setTimeInMillis( Long.parseLong(nSrc));
} catch ( NumberFormatException e1) {
throw new IllegalArgumentException(e1);
}
@@ -134,11 +133,6 @@ public class DateTimeUtils {
/**
* 匹配pattern获得时间若无法解析抛出异常
*
* @param dateTimeStr
* @param patternStr
* @return
* @throws IllegalArgumentException
*/
public static Calendar getCalendarByPattern( String dateTimeStr, String patternStr) {
try {
@@ -156,11 +150,6 @@ public class DateTimeUtils {
/**
* 匹配pattern数组中的所有pattern解析时间格式若没有可以解析的方式则抛出异常
*
* @param dateTimeStr
* @param patternStr
* @return
* @throws IllegalArgumentException
*/
public static Calendar getCalendarByPatterns( String dateTimeStr, String[] patternStr) {
for ( String string : patternStr) {
@@ -208,8 +197,6 @@ public class DateTimeUtils {
/**
* login时server的日期
*
* @return
*/
public static Calendar getLoginServerDate() {
return getCalendar(tss);
@@ -229,12 +216,8 @@ public class DateTimeUtils {
/**
* 获得时间间隔
*
* @param from
* @param to
* @param unit 时间间隔单位{@link DateTimeUtils#ONE_SECOND},{@link DateTimeUtils#ONE_MINUTE},
* {@link DateTimeUtils#ONE_HOUR}, {@link DateTimeUtils#ONE_DAY}
* @return
*/
public static long getIntervalTimes( Calendar from, Calendar to, long unit) {
if (from == null || to == null) {
@@ -245,12 +228,7 @@ public class DateTimeUtils {
/**
* 获得日期间隔 忽略小时
*
* @param startdate
* @param enddate
* @return
*/
public static int getIntervalDays( String startdate, String enddate, String pattern) {
int betweenDays = 0;
if (startdate == null || enddate == null) {
@@ -264,15 +242,15 @@ public class DateTimeUtils {
}
public static <T> int getIntervalDays(T from, T to) {
Calendar startdate = getCalendar(from);
Calendar enddate = getCalendar(to);
cleanCalendarTime(startdate);
cleanCalendarTime(enddate);
return (int) getIntervalTimes(startdate, enddate, ONE_DAY);
Calendar startDate = getCalendar(from);
Calendar endDate = getCalendar(to);
cleanCalendarTime(startDate);
cleanCalendarTime(endDate);
return (int) getIntervalTimes(startDate, endDate, ONE_DAY);
}
private static String[] weekdays = {"", "周日", "周一", "周二", "周三", "周四", "周五", "周六",};
private static String[] weekdays1 = {"", "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六",};
private static final String[] weekdays = {"", "周日", "周一", "周二", "周三", "周四", "周五", "周六",};
private static final String[] weekdays1 = {"", "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六",};
/**
* calendar --> 周一~周日
@@ -310,12 +288,12 @@ public class DateTimeUtils {
}
// 是否到刷新时间
public static boolean isRefersh(long beforeTime) {
return isRefersh(DATETIME_FIELD_REFERSH * 1000 * 60, beforeTime);
public static boolean isRefresh(long beforeTime) {
return isRefresh(DATETIME_FIELD_REFERSH * 1_000L * 60, beforeTime);
}
// 是否到刷新时间
public static boolean isRefersh(long gap, long beforeTime) {
public static boolean isRefresh(long gap, long beforeTime) {
return new Date().getTime() - beforeTime >= gap;
}
@@ -344,13 +322,7 @@ public class DateTimeUtils {
} else if (c1.get( Calendar.MONTH) < c2.get( Calendar.MONTH)) {
return -1;
} else {
if (c1.get( Calendar.DAY_OF_MONTH) > c2.get( Calendar.DAY_OF_MONTH)) {
return 1;
} else if (c1.get( Calendar.DAY_OF_MONTH) < c2.get( Calendar.DAY_OF_MONTH)) {
return -1;
} else {
return 0;
}
return Integer.compare(c1.get(Calendar.DAY_OF_MONTH), c2.get(Calendar.DAY_OF_MONTH));
}
}
}
@@ -359,14 +331,14 @@ public class DateTimeUtils {
if ( TextUtils.isEmpty(HH_mm) || null == src) {
return;
}
String s[] = HH_mm.split(":");
String[] s = HH_mm.split(":");
if (s.length != 2) {
return;
}
try {
cleanCalendarTime(src);
src.set( Calendar.HOUR_OF_DAY, Integer.valueOf(s[0]));
src.set( Calendar.MINUTE, Integer.valueOf(s[1]));
src.set( Calendar.HOUR_OF_DAY, Integer.parseInt(s[0]));
src.set( Calendar.MINUTE, Integer.parseInt(s[1]));
} catch ( NumberFormatException e) {
}
@@ -394,8 +366,7 @@ public class DateTimeUtils {
Calendar a = Calendar.getInstance();
a.set( Calendar.DATE, 1);
a.roll( Calendar.DATE, -1);
int maxDate = a.get( Calendar.DATE);
return maxDate;
return a.get( Calendar.DATE);
}
public static String convertToChineseWeekNumber( int number) {
@@ -444,22 +415,18 @@ public class DateTimeUtils {
/**
* 获取 06月07 格式的日期
* @param timestamp 时间戳
* @return
*/
public static String getTimeText( long timestamp, String dateFormat) {
SimpleDateFormat format = new SimpleDateFormat(dateFormat, Locale.US);
String strStart = format.format(new Date(timestamp));
return strStart;
return format.format(new Date(timestamp));
}
/**
* 获取 06月07 格式的日期
* @return
*/
public static String getTimeText(String dateFormat) {
SimpleDateFormat format = new SimpleDateFormat(dateFormat, Locale.US);
String strStart = format.format(new Date());
return strStart;
return format.format(new Date());
}
}

View File

@@ -24,7 +24,6 @@ import android.telephony.gsm.GsmCellLocation;
import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.RequiresApi;
import androidx.annotation.RequiresPermission;
import java.io.BufferedReader;
@@ -75,7 +74,6 @@ public final class DeviceUtils {
*
* @return {@code true}: yes<br>{@code false}: no
*/
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public static boolean isAdbEnabled() {
return Settings.Secure.getInt(
Utils.getApp().getContentResolver(),
@@ -277,7 +275,7 @@ public final class DeviceUtils {
InetAddress inetAddress = addresses.nextElement();
if (!inetAddress.isLoopbackAddress()) {
String hostAddress = inetAddress.getHostAddress();
if (hostAddress.indexOf(':') < 0) return inetAddress;
if (hostAddress != null && hostAddress.indexOf(':') < 0) return inetAddress;
}
}
}
@@ -345,14 +343,7 @@ public final class DeviceUtils {
* @return an ordered list of ABIs supported by this device
*/
public static String[] getABIs() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return Build.SUPPORTED_ABIS;
} else {
if (!TextUtils.isEmpty(Build.CPU_ABI2)) {
return new String[]{Build.CPU_ABI, Build.CPU_ABI2};
}
return new String[]{Build.CPU_ABI};
}
return Build.SUPPORTED_ABIS;
}
/**
@@ -391,20 +382,17 @@ public final class DeviceUtils {
operatorName = name;
}
}
boolean checkOperatorName = operatorName.toLowerCase().equals("android");
boolean checkOperatorName = operatorName.equalsIgnoreCase("android");
if (checkOperatorName) return true;
String url = "tel:" + "123456";
Intent intent = new Intent();
intent.setData(Uri.parse(url));
intent.setAction(Intent.ACTION_DIAL);
boolean checkDial = intent.resolveActivity(Utils.getApp().getPackageManager()) == null;
if (checkDial) return true;
return intent.resolveActivity(Utils.getApp().getPackageManager()) == null;
// boolean checkDebuggerConnected = Debug.isDebuggerConnected();
// if (checkDebuggerConnected) return true;
return false;
}
/**
@@ -412,7 +400,6 @@ public final class DeviceUtils {
*
* @return whether user has enabled development settings.
*/
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public static boolean isDevelopmentSettingsEnabled() {
return Settings.Global.getInt(
Utils.getApp().getContentResolver(),
@@ -497,8 +484,8 @@ public final class DeviceUtils {
if (!TextUtils.isEmpty(androidId)) {
return saveUdid(prefix + 2, androidId);
}
} catch (Exception ignore) {
ignore.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return saveUdid(prefix + 9, "");
}
@@ -565,8 +552,8 @@ public final class DeviceUtils {
// Gsm网络 , 联通移动的网络属于这一套
if (location instanceof GsmCellLocation) {
GsmCellLocation gsmLoc = (GsmCellLocation) location;
int cellid = gsmLoc.getCid();
return String.valueOf(cellid);
int cellId = gsmLoc.getCid();
return String.valueOf(cellId);
// Cdma网络 , 电信网络属于这一种
} else if (location instanceof CdmaCellLocation) {
CdmaCellLocation cdmaLoc = (CdmaCellLocation) location;
@@ -584,18 +571,13 @@ public final class DeviceUtils {
public static boolean isLocationEnabled() {
int locationMode = 0;
String locationProviders;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
try {
locationMode = Settings.Secure.getInt(Utils.getApp().getApplicationContext().getContentResolver(), Settings.Secure.LOCATION_MODE);
} catch (Settings.SettingNotFoundException e) {
e.printStackTrace();
return false;
}
return locationMode != Settings.Secure.LOCATION_MODE_OFF;
} else {
locationProviders = Settings.Secure.getString(Utils.getApp().getApplicationContext().getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
return !TextUtils.isEmpty(locationProviders);
try {
locationMode = Settings.Secure.getInt(Utils.getApp().getApplicationContext().getContentResolver(), Settings.Secure.LOCATION_MODE);
} catch (Settings.SettingNotFoundException e) {
e.printStackTrace();
return false;
}
return locationMode != Settings.Secure.LOCATION_MODE_OFF;
}
@@ -678,8 +660,8 @@ public final class DeviceUtils {
}
private static String getSerialnoNumbers() {
final String serialnoStr = "[ro.boot.serialno]";
private static String getSerialNoNumbers() {
final String serialNoStr = "[ro.boot.serialno]";
try {
Process p = Runtime.getRuntime().exec("getprop");
p.waitFor();
@@ -687,20 +669,20 @@ public final class DeviceUtils {
p.getInputStream()));
String temp = "";
while ((temp = stdInput.readLine()) != null) {
Log.i("getSerialnoNumbers", temp);
if (temp.contains(serialnoStr)) {
temp.replaceAll(" ", "");
int index = temp.indexOf(serialnoStr);
Log.i("getSerialNoNumbers", temp);
if (temp.contains(serialNoStr)) {
temp = temp.replaceAll(" ", "");
int index = temp.indexOf(serialNoStr);
temp = temp.substring(index + 20);
temp = temp.substring(1, temp.length() - 1);
Log.d("getSerialnoNumbers", temp);
Log.d("getSerialNoNumbers", temp);
return temp;
}
}
} catch (IOException | InterruptedException e) {
} catch (InterruptedException | IOException e) {
e.printStackTrace();
}
return serialnoStr;
return serialNoStr;
}
public static final String KEY_DEVICE_ID = "deviceId";

View File

@@ -104,7 +104,7 @@ public class MatcherUtils {
* @return
*/
public static boolean isMatches( String regex, String input) {
return input == null ? false : Pattern.compile(regex).matcher(input).find();
return input != null && Pattern.compile(regex).matcher(input).find();
}
/**
@@ -115,7 +115,7 @@ public class MatcherUtils {
* @return
*/
public static boolean isMatchesIgnoreCase( String regex, String input) {
return input == null ? false : Pattern.compile(regex, Pattern.CASE_INSENSITIVE).matcher(input).find();
return input != null && Pattern.compile(regex, Pattern.CASE_INSENSITIVE).matcher(input).find();
}
/**
@@ -274,15 +274,13 @@ public class MatcherUtils {
*/
public static boolean isCJK(char c) {
Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS // CJK统一汉字 \\u4E00-\\u9fAF
// 半形及全形字符 \\uFF00-\\uFFEF
return ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS // CJK统一汉字 \\u4E00-\\u9fAF
|| ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A // CJK统一汉字扩展-A \\u3400-\\u4dBF
|| ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS // CJK兼容汉字 \\uF900-\\uFAFF
|| ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION // CJK符号和标点 \\u3000-\\u303F
|| ub == Character.UnicodeBlock.GENERAL_PUNCTUATION // 广义标点 \\u2000-\\u206F
|| ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) { // 半形及全形字符 \\uFF00-\\uFFEF
return true;
}
return false;
|| ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS;
}
/**
@@ -358,6 +356,9 @@ public class MatcherUtils {
* @return
*/
public static boolean isFetionPassword( String input) {
if(input == null){
return false;
}
// 密码必须含有字母和数字符号可选但是必须符合Punct标准,否则返回false
// 首先判断是否含有无效字符含有则返回false
if (isIncludeInvalidChar(input)) {
@@ -374,11 +375,7 @@ public class MatcherUtils {
if (isMatches("[0-9]{1,15}", input)) {
tmpValue++;
}
if (tmpValue >= 2) {
return true;
} else {
return false;
}
return tmpValue >= 2;
}
/**
@@ -390,9 +387,6 @@ public class MatcherUtils {
public static boolean isNumeric( String str) {
Pattern pattern = Pattern.compile("[0-9]+");
Matcher isNum = pattern.matcher(str);
if (!isNum.matches()) {
return false;
}
return true;
return isNum.matches();
}
}

View File

@@ -20,6 +20,11 @@ public final class NumberUtils {
protected DecimalFormat initialValue() {
return (DecimalFormat) NumberFormat.getInstance();
}
@Override
public void remove() {
super.remove();
}
};
public static DecimalFormat getSafeDecimalFormat() {

View File

@@ -120,7 +120,7 @@ public final class PhoneUtils {
} else {
return getMinOne(tm.getMeid(0), tm.getMeid(1));
}
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
} else {
String ids = getSystemPropertyByReflect(isImei ? "ril.gsm.imei" : "ril.cdma.meid");
if (!TextUtils.isEmpty(ids)) {
String[] idArr = ids.split(",");
@@ -138,11 +138,7 @@ public final class PhoneUtils {
id1 = (String) method.invoke(tm,
isImei ? TelephonyManager.PHONE_TYPE_GSM
: TelephonyManager.PHONE_TYPE_CDMA);
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
if (isImei) {
@@ -161,19 +157,7 @@ public final class PhoneUtils {
}
}
return getMinOne(id0, id1);
} else {
String deviceId = tm.getDeviceId();
if (isImei) {
if (deviceId != null && deviceId.length() >= 15) {
return deviceId;
}
} else {
if (deviceId != null && deviceId.length() == 14) {
return deviceId;
}
}
}
return "";
}
private static String getMinOne(String s0, String s1) {

View File

@@ -158,23 +158,20 @@ public final class ReflectUtils {
}
private void sortConstructors(List<Constructor<?>> list) {
Collections.sort(list, new Comparator<Constructor<?>>() {
@Override
public int compare(Constructor<?> o1, Constructor<?> o2) {
Class<?>[] types1 = o1.getParameterTypes();
Class<?>[] types2 = o2.getParameterTypes();
int len = types1.length;
for (int i = 0; i < len; i++) {
if (!types1[i].equals(types2[i])) {
if (wrapper(types1[i]).isAssignableFrom(wrapper(types2[i]))) {
return 1;
} else {
return -1;
}
Collections.sort(list, (o1, o2) -> {
Class<?>[] types1 = o1.getParameterTypes();
Class<?>[] types2 = o2.getParameterTypes();
int len = types1.length;
for (int i = 0; i < len; i++) {
if (!types1[i].equals(types2[i])) {
if (wrapper(types1[i]).isAssignableFrom(wrapper(types2[i]))) {
return 1;
} else {
return -1;
}
}
return 0;
}
return 0;
});
}
@@ -363,23 +360,20 @@ public final class ReflectUtils {
}
private void sortMethods(final List<Method> methods) {
Collections.sort(methods, new Comparator<Method>() {
@Override
public int compare(Method o1, Method o2) {
Class<?>[] types1 = o1.getParameterTypes();
Class<?>[] types2 = o2.getParameterTypes();
int len = types1.length;
for (int i = 0; i < len; i++) {
if (!types1[i].equals(types2[i])) {
if (wrapper(types1[i]).isAssignableFrom(wrapper(types2[i]))) {
return 1;
} else {
return -1;
}
Collections.sort(methods, (o1, o2) -> {
Class<?>[] types1 = o1.getParameterTypes();
Class<?>[] types2 = o2.getParameterTypes();
int len = types1.length;
for (int i = 0; i < len; i++) {
if (!types1[i].equals(types2[i])) {
if (wrapper(types1[i]).isAssignableFrom(wrapper(types2[i]))) {
return 1;
} else {
return -1;
}
}
return 0;
}
return 0;
});
}
@@ -432,29 +426,25 @@ public final class ReflectUtils {
@SuppressWarnings("unchecked")
public <P> P proxy(final Class<P> proxyType) {
final boolean isMap = (object instanceof Map);
final InvocationHandler handler = new InvocationHandler() {
@Override
@SuppressWarnings("null")
public Object invoke(Object proxy, Method method, Object[] args) {
String name = method.getName();
try {
return reflect(object).method(name, args).get();
} catch (ReflectException e) {
if (isMap) {
Map<String, Object> map = (Map<String, Object>) object;
int length = (args == null ? 0 : args.length);
final InvocationHandler handler = (proxy, method, args) -> {
String name = method.getName();
try {
return reflect(object).method(name, args).get();
} catch (ReflectException e) {
if (isMap) {
Map<String, Object> map = (Map<String, Object>) object;
int length = (args == null ? 0 : args.length);
if (length == 0 && name.startsWith("get")) {
return map.get(property(name.substring(3)));
} else if (length == 0 && name.startsWith("is")) {
return map.get(property(name.substring(2)));
} else if (length == 1 && name.startsWith("set")) {
map.put(property(name.substring(3)), args[0]);
return null;
}
if (length == 0 && name.startsWith("get")) {
return map.get(property(name.substring(3)));
} else if (length == 0 && name.startsWith("is")) {
return map.get(property(name.substring(2)));
} else if (length == 1 && name.startsWith("set")) {
map.put(property(name.substring(3)), args[0]);
return null;
}
throw e;
}
throw e;
}
};
return (P) Proxy.newProxyInstance(proxyType.getClassLoader(),

View File

@@ -139,7 +139,7 @@ public final class SpanUtils {
private int spaceSize;
private int spaceColor;
private SerializableSpannableStringBuilder mBuilder;
private final SerializableSpannableStringBuilder mBuilder;
private boolean isCreated;
private int mType;
@@ -1189,7 +1189,7 @@ public final class SpanUtils {
final boolean first, final Layout l) {
if (((Spanned) text).getSpanStart(this) == start) {
Paint.Style style = p.getStyle();
int oldColor = 0;
int oldColor;
oldColor = p.getColor();
p.setColor(color);
p.setStyle(Paint.Style.FILL);
@@ -1249,9 +1249,6 @@ public final class SpanUtils {
if ((fake & Typeface.ITALIC) != 0) {
paint.setTextSkewX(-0.25f);
}
paint.getShader();
paint.setTypeface(tf);
}
}
@@ -1311,9 +1308,11 @@ public final class SpanUtils {
} else {
try {
drawable = ContextCompat.getDrawable(Utils.getApp(), mResourceId);
drawable.setBounds(
0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()
);
if(drawable != null){
drawable.setBounds(
0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()
);
}
} catch (Exception e) {
Log.e("sms", "Unable to find resource: " + mResourceId);
}
@@ -1358,14 +1357,12 @@ public final class SpanUtils {
int lineHeight = fm.bottom - fm.top;
if (lineHeight < rect.height()) {
if (mVerticalAlignment == ALIGN_TOP) {
fm.top = fm.top;
fm.bottom = rect.height() + fm.top;
} else if (mVerticalAlignment == ALIGN_CENTER) {
fm.top = -rect.height() / 2 - lineHeight / 4;
fm.bottom = rect.height() / 2 - lineHeight / 4;
} else {
fm.top = -rect.height() + fm.bottom;
fm.bottom = fm.bottom;
}
fm.ascent = fm.top;
fm.descent = fm.bottom;
@@ -1433,9 +1430,10 @@ public final class SpanUtils {
}
static class ShadowSpan extends CharacterStyle implements UpdateAppearance {
private float radius;
private float dx, dy;
private int shadowColor;
private final float radius;
private final float dx;
private final float dy;
private final int shadowColor;
private ShadowSpan(final float radius,
final float dx,

View File

@@ -1068,7 +1068,7 @@ public final class ThreadUtils {
private final AtomicInteger mSubmittedCount = new AtomicInteger();
private LinkedBlockingQueue4Util mWorkQueue;
private final LinkedBlockingQueue4Util mWorkQueue;
ThreadPoolExecutor4Util(int corePoolSize, int maximumPoolSize,
long keepAliveTime, TimeUnit unit,
@@ -1376,8 +1376,8 @@ public final class ThreadUtils {
public static class SyncValue<T> {
private CountDownLatch mLatch = new CountDownLatch(1);
private AtomicBoolean mFlag = new AtomicBoolean();
private final CountDownLatch mLatch = new CountDownLatch(1);
private final AtomicBoolean mFlag = new AtomicBoolean();
private T mValue;
public void setValue(T value) {

View File

@@ -36,6 +36,11 @@ public final class TimeUtils {
protected Map<String, SimpleDateFormat> initialValue() {
return new HashMap<>();
}
@Override
public void remove() {
super.remove();
}
};
private static SimpleDateFormat getDefaultFormat() {

View File

@@ -118,23 +118,13 @@ final class UtilsActivityLifecycleImpl implements Application.ActivityLifecycleC
void removeActivityLifecycleCallbacks(final Activity activity) {
if (activity == null) return;
UtilsBridge.runOnUiThread(new Runnable() {
@Override
public void run() {
mActivityLifecycleCallbacksMap.remove(activity);
}
});
UtilsBridge.runOnUiThread(() -> mActivityLifecycleCallbacksMap.remove(activity));
}
void removeActivityLifecycleCallbacks(final Activity activity,
final Utils.ActivityLifecycleCallbacks callbacks) {
if (activity == null || callbacks == null) return;
UtilsBridge.runOnUiThread(new Runnable() {
@Override
public void run() {
removeActivityLifecycleCallbacksInner(activity, callbacks);
}
});
UtilsBridge.runOnUiThread(() -> removeActivityLifecycleCallbacksInner(activity, callbacks));
}
private void removeActivityLifecycleCallbacksInner(final Activity activity,
@@ -182,13 +172,7 @@ final class UtilsActivityLifecycleImpl implements Application.ActivityLifecycleC
return null;
}
return (Application) app;
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
} catch (InvocationTargetException | NoSuchMethodException | IllegalAccessException | ClassNotFoundException e) {
e.printStackTrace();
}
return null;
@@ -323,16 +307,13 @@ final class UtilsActivityLifecycleImpl implements Application.ActivityLifecycleC
} else {
final Object tag = activity.getWindow().getDecorView().getTag(-123);
if (!(tag instanceof Integer)) return;
UtilsBridge.runOnUiThreadDelayed(new Runnable() {
@Override
public void run() {
try {
Window window = activity.getWindow();
if (window != null) {
window.setSoftInputMode(((Integer) tag));
}
} catch (Exception ignore) {
UtilsBridge.runOnUiThreadDelayed(() -> {
try {
Window window = activity.getWindow();
if (window != null) {
window.setSoftInputMode(((Integer) tag));
}
} catch (Exception ignore) {
}
}, 100);
}
@@ -370,6 +351,9 @@ final class UtilsActivityLifecycleImpl implements Application.ActivityLifecycleC
Activity topActivity = null;
try {
Object activityThread = getActivityThread();
if(activityThread == null){
return list;
}
Field mActivitiesField = activityThread.getClass().getDeclaredField("mActivities");
mActivitiesField.setAccessible(true);
Object mActivities = mActivitiesField.get(activityThread);
@@ -448,9 +432,7 @@ final class UtilsActivityLifecycleImpl implements Application.ActivityLifecycleC
sDurationScaleField.set(null, 1f);
Log.i("UtilsActivityLifecycle", "setAnimatorsEnabled: Animators are enabled now!");
}
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
}