整理:code review

This commit is contained in:
pppscn 2022-01-14 17:55:15 +08:00
parent b97f075171
commit 18d2c6cd1e
10 changed files with 142 additions and 73 deletions

View File

@ -15,7 +15,7 @@ if (versionPropsFile.exists()) {
android {
buildToolsVersion '30.0.3'
compileSdkVersion 30
compileSdkVersion 31
compileOptions {
sourceCompatibility 11
targetCompatibility 11
@ -23,7 +23,7 @@ android {
defaultConfig {
applicationId "com.idormy.sms.forwarder"
minSdkVersion 21
targetSdkVersion 30
targetSdkVersion 31
versionCode versionProps['versionCode'].toInteger()
versionName versionProps['versionName']
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
@ -127,24 +127,29 @@ void cmdExecute(String cmd) {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
//noinspection GradleDependency
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
//noinspection GradleDependency
implementation 'com.google.firebase:firebase-crashlytics-buildtools:2.5.2'
//noinspection GradleDynamicVersion
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
//okhttp
implementation 'com.squareup.okhttp3:okhttp:4.9.1'
implementation 'com.squareup.okio:okio:2.10.0'
//noinspection GradleDependency
implementation 'com.squareup.okhttp3:okhttp:4.9.3'
implementation 'com.squareup.okio:okio:3.0.0'
//fastjson
implementation "com.alibaba:fastjson:1.2.78"
implementation "com.alibaba:fastjson:1.2.79"
//SDK
implementation 'com.umeng.umsdk:common:9.4.4'//
implementation 'com.umeng.umsdk:asms:1.4.1'//
//implementation 'com.umeng.umsdk:apm:1.4.2' // SDKcrash数据请一定集成
implementation 'com.umeng.umsdk:common:9.4.5'//
implementation 'com.umeng.umsdk:asms:1.5.0'// asms包依赖必选
//implementation 'com.umeng.umsdk:abtest:1.0.0'//使U-App中ABTest能力
implementation 'com.umeng.umsdk:apm:1.5.2'// U-APM产品包依赖()
//XUpdate
implementation 'com.github.xuexiangjys:XUpdate:2.1.1'
@ -156,18 +161,19 @@ dependencies {
//Lombok
//noinspection AnnotationProcessorOnCompilePath
compileOnly 'org.projectlombok:lombok:1.18.20'
annotationProcessor 'org.projectlombok:lombok:1.18.20'
compileOnly 'org.projectlombok:lombok:1.18.22'
annotationProcessor 'org.projectlombok:lombok:1.18.22'
//RxJava
implementation 'io.reactivex.rxjava3:rxjava:3.1.1'
implementation 'io.reactivex.rxjava3:rxjava:3.1.3'
//AndroidAsync
implementation 'com.koushikdutta.async:androidasync:3.1.0'
// https://github.com/getActivity/XXPermissions
implementation 'com.github.getActivity:XXPermissions:13.2'
//jetty
implementation "org.eclipse.jetty:jetty-server:$jetty_version"
implementation "org.eclipse.jetty:jetty-servlet:$jetty_version"
implementation "org.eclipse.jetty:jetty-server:9.2.30.v20200428"
implementation "org.eclipse.jetty:jetty-servlet:9.2.30.v20200428"
}

View File

@ -4,14 +4,21 @@ import androidx.annotation.NonNull;
import com.alibaba.fastjson.JSON;
import com.idormy.sms.forwarder.sender.SmsHubApiTask;
import com.idormy.sms.forwarder.utils.*;
import com.idormy.sms.forwarder.utils.PhoneUtils;
import com.idormy.sms.forwarder.utils.SettingUtil;
import com.idormy.sms.forwarder.utils.SimUtil;
import java.io.Serializable;
import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import lombok.Data;
@SuppressWarnings("unchecked")
@Data
public class SmsHubVo implements Serializable {
private static final long serialVersionUID = 1L;
@ -84,7 +91,7 @@ public class SmsHubVo implements Serializable {
cache.put(key, deviInfoMap);
return deviInfoMap;
}
return (HashMap<String, String>) cache.get(key);
return (HashMap<String, String>) Objects.requireNonNull(cache.get(key));
}
public enum Action {

View File

@ -8,7 +8,9 @@ import android.widget.Toast;
import com.idormy.sms.forwarder.R;
import com.idormy.sms.forwarder.model.vo.SmsHubVo;
import com.idormy.sms.forwarder.receiver.BaseServlet;
import com.idormy.sms.forwarder.utils.*;
import com.idormy.sms.forwarder.utils.NetUtil;
import com.idormy.sms.forwarder.utils.SettingUtil;
import com.idormy.sms.forwarder.utils.SmsHubActionHandler;
import org.eclipse.jetty.server.Server;
@ -16,7 +18,7 @@ import org.eclipse.jetty.server.Server;
public class HttpServer {
private static Boolean hasInit = false;
private static Server jettyServer;
private static int port = 5000;
private static final int port = 5000;
@SuppressLint("StaticFieldLeak")
private static Context context;
private static long ts = 0L;

View File

@ -2,7 +2,6 @@ package com.idormy.sms.forwarder.utils;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.*;
import android.util.Log;
import android.widget.Toast;
@ -16,19 +15,23 @@ import java.net.URLEncoder;
import java.util.Map;
import java.util.Objects;
import okhttp3.*;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
@SuppressWarnings("unchecked")
public class HttpUtil {
private static final OkHttpClient client = new OkHttpClient();
private static final String TAG = "HttpUtil";
private static Boolean hasInit = false;
@SuppressLint("StaticFieldLeak")
private static Context context;
// @SuppressLint("StaticFieldLeak")
// private static Handler handError;
private static final MediaType MEDIA_TYPE_JSON = MediaType.parse("application/json;charset=utf-8");
@SuppressLint("HandlerLeak")
public static void init(Context context) {
//noinspection SynchronizeOnNonFinalField
@ -95,6 +98,7 @@ public class HttpUtil {
}
}
@SuppressWarnings("deprecation")
@NonNull
public static StringBuilder appendQueryStr(String tag, String url, Object param) {
StringBuilder resUrl = new StringBuilder(url);

View File

@ -12,6 +12,7 @@ public class Lamda {
}
}
@SuppressWarnings("UnusedReturnValue")
public interface Func<T, R> {
R execute(T t) throws Exception;

View File

@ -7,7 +7,10 @@ import android.util.Log;
import com.idormy.sms.forwarder.model.LogModel;
import com.idormy.sms.forwarder.model.vo.SmsHubVo;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
public class SmsHubActionHandler {
@ -44,6 +47,7 @@ public class SmsHubActionHandler {
public static synchronized List<SmsHubVo> getData(SmsHubMode smsHubMode) {
List<SmsHubVo> smsHubVoList = cache.get(smsHubMode);
assert smsHubVoList != null;
if (smsHubVoList.size() > 0) {
cache.put(smsHubMode, new ArrayList<>());
return smsHubVoList;

View File

@ -2,12 +2,14 @@
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
tools:ignore="TooManyViews">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -250,56 +252,100 @@
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:background="@android:color/white"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="15dp">
android:id="@+id/layout_cancel_app_notify"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:background="@android:color/white"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="15dp"
android:visibility="gone">
<LinearLayout
android:layout_width="0dp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="4"
android:orientation="vertical">
android:text="@string/cancel_app_notify"
android:textStyle="bold"
tools:ignore="RelativeOverlap" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/send_sms_config_title"
android:textStyle="bold"
tools:ignore="RelativeOverlap" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="end"
android:text="@string/send_sms_config_title2"
android:textSize="9sp"
tools:ignore="SmallSp" />
<EditText
android:id="@+id/editText_text_sms_hub_url"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:autofillHints=""
android:ems="16"
android:inputType="text"
android:maxLines="1"
android:text=""
tools:ignore="LabelFor" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="end"
android:text="@string/cancel_app_notify_tips"
android:textSize="9sp"
tools:ignore="SmallSp" />
</LinearLayout>
<Switch
android:id="@+id/switch_enable_sms_hub"
android:layout_width="0dp"
android:id="@+id/switch_cancel_app_notify"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end"
android:textSize="18sp"
tools:ignore="UseSwitchCompatOrMaterialXml" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:background="@android:color/white"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="15dp">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/send_sms_config_title"
android:textStyle="bold"
tools:ignore="RelativeOverlap" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end"
android:textSize="18sp"
tools:ignore="UseSwitchCompatOrMaterialXml" />
android:text="@string/send_sms_config_title2"
android:textSize="9sp"
tools:ignore="SmallSp" />
<EditText
android:id="@+id/editText_text_sms_hub_url"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:autofillHints=""
android:ems="16"
android:inputType="textUri"
android:maxLines="1"
android:text=""
tools:ignore="LabelFor" />
</LinearLayout>
<Switch
android:id="@+id/switch_enable_sms_hub"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end"
android:textSize="18sp"
tools:ignore="UseSwitchCompatOrMaterialXml" />
</LinearLayout>
<LinearLayout
@ -710,7 +756,7 @@
android:gravity="end"
android:text="@string/enable_exclude_from_recents_tips"
android:textSize="9sp"
tools:ignore="SmallSp,TooManyViews" />
tools:ignore="SmallSp" />
</LinearLayout>
<Switch
@ -760,7 +806,7 @@
android:background="@color/colorBlueGreyDark"
android:onClick="initSetting"
android:text="@string/init_setting"
tools:ignore="ButtonStyle,NestedWeights,TooManyViews,UsingOnClickInXml" />
tools:ignore="ButtonStyle,NestedWeights,UsingOnClickInXml" />
</LinearLayout>
</LinearLayout>

View File

@ -166,7 +166,7 @@
<string name="retry_interval_tips">Retry five times after it fails</string>
<string name="forward_sms">Forward sms</string>
<string name="forward_sms_tips">Main switch, requires permissions to read and sned SMS messages, especially verification SMS texts.</string>
<string name="forward_missed_calls">Forward missed calls</string>
<string name="forward_missed_calls">Forward calls log</string>
<string name="forward_missed_calls_tips">Main switch, requires permissions to read call log and contacts.</string>
<string name="forward_app_notify">Forward app Ntf.</string>
<string name="forward_app_notify_tips">Main switch, requires permission to read notification.</string>
@ -211,7 +211,7 @@
<string name="local_ip">Local IP</string>
<string name="operating_instruction">Instructions: \n1. Please keep the SOURCE and DESTINATION phones in the same Wi-Fi network, and do not turn on isolation. \n2. Tap "Send" on SOURCE mobile phone, and get "server IP" \n3. After filling in "Server IP" on DESTINATION phone, tap "Receive". \n [NOTE:] sender(s), forwarding rule(s) and log(s) will be overwritten after cloning!</string> <!-- 原文是“新旧手机”,英文翻译中处理为“源”手机和“目标”手机,因为担心“新旧”的表述引起混淆(有没一种可能就是用户就是用从新手机的设备复制到旧手机上去呢?)。 -->
<string name="send">Start Server</string>
<string name="stop">Stop</string>
<string name="stop">Stop Server</string>
<string name="old_mobile_phone">I\'m the SCOURCE phone</string>
<string name="receive">Receive</string>
<string name="new_mobile_phone">I\'m the DESTINATION phone</string>
@ -271,5 +271,5 @@
<string name="privacy_policy">Privacy Policy</string>
<string name="agree">Agree</string>
<string name="disagree">Disagree</string>
<string name="privacy_policy_text">SmsForwarder (the "Application/App"), is 100% free and open source, and is compliled and released basing on repository hosted on GitHub. The App will not collect any of your privacy data!\n\n Version information of the App will be sent in the following situations: \n 1. As startup, version information will be sent to "Umeng +· U-APP Mobile Statistics" for user retention analyze and crash stats;\n 2. Manual update check triggered by user;\n The App collects no any other data!!\n\n The App collects and uses version information only in accordance with the Privacy Policy, and will not collect any other information as an abuse of users\' consent to the Privacy Policy;</string>
<string name="privacy_policy_text">SmsForwarder (the "Application/App"), is 100\% free and open source, and is compliled and released basing on repository hosted on GitHub. The App will not collect any of your privacy data!\n\n Version information of the App will be sent in the following situations: \n 1. As startup, version information will be sent to "Umeng +· U-APP Mobile Statistics" for user retention analyze and crash stats;\n 2. Manual update check triggered by user;\n The App collects no any other data!!\n\n The App collects and uses version information only in accordance with the Privacy Policy, and will not collect any other information as an abuse of users\' consent to the Privacy Policy;</string>
</resources>

View File

@ -166,7 +166,7 @@
<string name="retry_interval_tips">接口请求失败后将重试5次</string>
<string name="forward_sms">转发短信广播</string>
<string name="forward_sms_tips">总开关,请授予读取短信、通知类短信、发送短信等权限</string>
<string name="forward_missed_calls">转发未接来电</string>
<string name="forward_missed_calls">转发通话记录</string>
<string name="forward_missed_calls_tips">总开关,请授予读取通话记录、联系人等权限</string>
<string name="forward_app_notify">转发应用通知</string>
<string name="forward_app_notify_tips">总开关,请先授予通知使用权</string>
@ -210,7 +210,7 @@
<string name="local_ip">本机IP</string>
<string name="operating_instruction">操作说明:\n1.新旧手机连接同一个WiFi网络(禁用AP隔离)\n2.旧手机直接点【发送】按钮获取到【服务端IP】\n3.新手机填写【服务端IP】后点【接收】按钮\n【注意】新手机接收后发送通道、转发规则将完全被覆盖清空历史记录</string>
<string name="send">启动服务</string>
<string name="stop">停止</string>
<string name="stop">停止服务</string>
<string name="old_mobile_phone">我是旧手机</string>
<string name="receive">接收</string>
<string name="new_mobile_phone">我是新手机</string>

View File

@ -1,7 +1,6 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.jetty_version = '9.2.30.v20200428'
repositories {
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/central' }