mirror of
https://github.com/pppscn/SmsForwarder
synced 2025-08-03 01:17:41 +08:00
优化:一键克隆机制优化,提高成功率
This commit is contained in:
parent
f37ce20fcb
commit
4172087e25
@ -66,7 +66,7 @@ public class CloneActivity extends AppCompatActivity {
|
|||||||
} else if (msg.what == DOWNLOAD) {
|
} else if (msg.what == DOWNLOAD) {
|
||||||
String savePath = context.getCacheDir().getPath() + File.separator + BackupDbTask.BACKUP_FILE;
|
String savePath = context.getCacheDir().getPath() + File.separator + BackupDbTask.BACKUP_FILE;
|
||||||
Log.d(TAG, savePath);
|
Log.d(TAG, savePath);
|
||||||
downloadFile(msg.getData().getString("URL"), context.getCacheDir().getPath(), BackupDbTask.BACKUP_FILE);
|
downloadFile(msg.getData().getString("URL"), context.getCacheDir().getPath(), BackupDbTask.BACKUP_FILE, msg.getData().getString("INFO"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -186,7 +186,7 @@ public class CloneActivity extends AppCompatActivity {
|
|||||||
client.newCall(request).enqueue(new Callback() {
|
client.newCall(request).enqueue(new Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call call, @NonNull final IOException e) {
|
public void onFailure(@NonNull Call call, @NonNull final IOException e) {
|
||||||
Toast(handError, TAG, "从发送端获取一键克隆信息失败");
|
Toast(handError, TAG, getString(R.string.tips_get_info_failed));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -195,44 +195,28 @@ public class CloneActivity extends AppCompatActivity {
|
|||||||
Log.d(TAG, "Response:" + response.code() + "," + responseStr);
|
Log.d(TAG, "Response:" + response.code() + "," + responseStr);
|
||||||
|
|
||||||
if (TextUtils.isEmpty(responseStr)) {
|
if (TextUtils.isEmpty(responseStr)) {
|
||||||
Toast(handError, TAG, "从发送端获取一键克隆信息失败");
|
Toast(handError, TAG, getString(R.string.tips_get_info_failed));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
CloneInfoVo cloneInfoVo = JSON.parseObject(responseStr, CloneInfoVo.class);
|
CloneInfoVo cloneInfoVo = JSON.parseObject(responseStr, CloneInfoVo.class);
|
||||||
if (SettingUtil.getVersionCode() != cloneInfoVo.getVersionCode()) {
|
if (SettingUtil.getVersionCode() != cloneInfoVo.getVersionCode()) {
|
||||||
Toast(handError, TAG, "发送端与接收端的APP版本不一致,无法一键克隆!");
|
Toast(handError, TAG, getString(R.string.tips_versions_inconsistent));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//应用配置
|
|
||||||
SettingUtil.switchEnableSms(cloneInfoVo.isEnableSms());
|
|
||||||
SettingUtil.switchEnablePhone(cloneInfoVo.isEnablePhone());
|
|
||||||
SettingUtil.switchCallType1(cloneInfoVo.isCallType1());
|
|
||||||
SettingUtil.switchCallType2(cloneInfoVo.isCallType2());
|
|
||||||
SettingUtil.switchCallType3(cloneInfoVo.isCallType3());
|
|
||||||
SettingUtil.switchEnableAppNotify(cloneInfoVo.isEnableAppNotify());
|
|
||||||
SettingUtil.switchCancelAppNotify(cloneInfoVo.isCancelAppNotify());
|
|
||||||
SettingUtil.smsHubApiUrl(cloneInfoVo.getSmsHubApiUrl());
|
|
||||||
SettingUtil.setBatteryLevelAlarmMin(cloneInfoVo.getBatteryLevelAlarmMin());
|
|
||||||
SettingUtil.setBatteryLevelAlarmMax(cloneInfoVo.getBatteryLevelAlarmMax());
|
|
||||||
SettingUtil.switchBatteryLevelAlarmOnce(cloneInfoVo.isBatteryLevelAlarmOnce());
|
|
||||||
SettingUtil.setRetryTimes(cloneInfoVo.getRetryTimes());
|
|
||||||
SettingUtil.setDelayTime(cloneInfoVo.getDelayTime());
|
|
||||||
SettingUtil.switchSmsTemplate(cloneInfoVo.isEnableSmsTemplate());
|
|
||||||
SettingUtil.setSmsTemplate(cloneInfoVo.getSmsTemplate());
|
|
||||||
|
|
||||||
//下载备份文件
|
//下载备份文件
|
||||||
Message msg = new Message();
|
Message msg = new Message();
|
||||||
msg.what = DOWNLOAD;
|
msg.what = DOWNLOAD;
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putString("URL", requestUrl);
|
bundle.putString("URL", requestUrl);
|
||||||
|
bundle.putString("INFO", responseStr);
|
||||||
msg.setData(bundle);
|
msg.setData(bundle);
|
||||||
handError.sendMessage(msg);
|
handError.sendMessage(msg);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Toast(handError, TAG, "一键克隆失败:" + e.getMessage());
|
Toast(handError, TAG, getString(R.string.tips_clone_failed) + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -256,11 +240,11 @@ public class CloneActivity extends AppCompatActivity {
|
|||||||
*
|
*
|
||||||
* @param url 下载链接
|
* @param url 下载链接
|
||||||
*/
|
*/
|
||||||
public void downloadFile(String url, final String destFileDir, final String destFileName) {
|
public void downloadFile(String url, final String destFileDir, final String destFileName, final String cloneInfo) {
|
||||||
ProgressDialog progressDialog = new ProgressDialog(context);
|
ProgressDialog progressDialog = new ProgressDialog(context);
|
||||||
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
|
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
|
||||||
progressDialog.setTitle("正在下载");
|
progressDialog.setTitle(getString(R.string.tips_downloading));
|
||||||
progressDialog.setMessage("请稍后...");
|
progressDialog.setMessage(getString(R.string.tips_please_wait));
|
||||||
progressDialog.setProgress(0);
|
progressDialog.setProgress(0);
|
||||||
progressDialog.setMax(100);
|
progressDialog.setMax(100);
|
||||||
progressDialog.show();
|
progressDialog.show();
|
||||||
@ -269,7 +253,7 @@ public class CloneActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onDownloadSuccess(File file) {
|
public void onDownloadSuccess(File file) {
|
||||||
if (progressDialog.isShowing()) {
|
if (progressDialog.isShowing()) {
|
||||||
Toast(handError, TAG, "下载完成,正准备还原数据...");
|
Toast(handError, TAG, getString(R.string.tips_download_done));
|
||||||
progressDialog.dismiss();
|
progressDialog.dismiss();
|
||||||
}
|
}
|
||||||
//下载完成进行相关逻辑操作
|
//下载完成进行相关逻辑操作
|
||||||
@ -280,7 +264,27 @@ public class CloneActivity extends AppCompatActivity {
|
|||||||
String backup_version = task.doInBackground(BackupDbTask.COMMAND_RESTORE);
|
String backup_version = task.doInBackground(BackupDbTask.COMMAND_RESTORE);
|
||||||
Log.d(TAG, "backup_version = " + backup_version);
|
Log.d(TAG, "backup_version = " + backup_version);
|
||||||
|
|
||||||
Toast(handError, TAG, "一键克隆操作成功!请进入通用设置检查各项开关是否已开启!");
|
//应用配置
|
||||||
|
CloneInfoVo cloneInfoVo = JSON.parseObject(cloneInfo, CloneInfoVo.class);
|
||||||
|
System.out.println(cloneInfoVo.toString());
|
||||||
|
SettingUtil.init(context);
|
||||||
|
SettingUtil.switchEnableSms(cloneInfoVo.isEnableSms());
|
||||||
|
SettingUtil.switchEnablePhone(cloneInfoVo.isEnablePhone());
|
||||||
|
SettingUtil.switchCallType1(cloneInfoVo.isCallType1());
|
||||||
|
SettingUtil.switchCallType2(cloneInfoVo.isCallType2());
|
||||||
|
SettingUtil.switchCallType3(cloneInfoVo.isCallType3());
|
||||||
|
SettingUtil.switchEnableAppNotify(cloneInfoVo.isEnableAppNotify());
|
||||||
|
SettingUtil.switchCancelAppNotify(cloneInfoVo.isCancelAppNotify());
|
||||||
|
SettingUtil.smsHubApiUrl(cloneInfoVo.getSmsHubApiUrl());
|
||||||
|
SettingUtil.setBatteryLevelAlarmMin(cloneInfoVo.getBatteryLevelAlarmMin());
|
||||||
|
SettingUtil.setBatteryLevelAlarmMax(cloneInfoVo.getBatteryLevelAlarmMax());
|
||||||
|
SettingUtil.switchBatteryLevelAlarmOnce(cloneInfoVo.isBatteryLevelAlarmOnce());
|
||||||
|
SettingUtil.setRetryTimes(cloneInfoVo.getRetryTimes());
|
||||||
|
SettingUtil.setDelayTime(cloneInfoVo.getDelayTime());
|
||||||
|
SettingUtil.switchSmsTemplate(cloneInfoVo.isEnableSmsTemplate());
|
||||||
|
SettingUtil.setSmsTemplate(cloneInfoVo.getSmsTemplate());
|
||||||
|
|
||||||
|
Toast(handError, TAG, getString(R.string.tips_clone_done));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -292,8 +296,8 @@ public class CloneActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onDownloadFailed(Exception e) {
|
public void onDownloadFailed(Exception e) {
|
||||||
//下载异常进行相关提示操作
|
//下载异常进行相关提示操作
|
||||||
Log.e(TAG, "下载失败:" + e.getMessage());
|
Log.e(TAG, getString(R.string.tips_download_failed) + e.getMessage());
|
||||||
Toast(handError, TAG, "下载失败:" + e.getMessage());
|
Toast(handError, TAG, getString(R.string.tips_download_failed) + e.getMessage());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
package com.idormy.sms.forwarder.model.vo;
|
package com.idormy.sms.forwarder.model.vo;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
@Data
|
@Setter
|
||||||
|
@Getter
|
||||||
public class CloneInfoVo implements Serializable {
|
public class CloneInfoVo implements Serializable {
|
||||||
|
|
||||||
private int versionCode;
|
private int versionCode;
|
||||||
@ -25,4 +29,27 @@ public class CloneInfoVo implements Serializable {
|
|||||||
private boolean enableSmsTemplate;
|
private boolean enableSmsTemplate;
|
||||||
private String smsTemplate;
|
private String smsTemplate;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "CloneInfoVo{" +
|
||||||
|
"versionCode='" + versionCode + '\'' +
|
||||||
|
", versionName='" + versionName + '\'' +
|
||||||
|
", enableSms=" + enableSms +
|
||||||
|
", enablePhone=" + enablePhone +
|
||||||
|
", callType1=" + callType1 +
|
||||||
|
", callType2=" + callType2 +
|
||||||
|
", callType3=" + callType3 +
|
||||||
|
", enableAppNotify=" + enableAppNotify +
|
||||||
|
", cancelAppNotify=" + cancelAppNotify +
|
||||||
|
", smsHubApiUrl=" + smsHubApiUrl +
|
||||||
|
", batteryLevelAlarmMin=" + batteryLevelAlarmMin +
|
||||||
|
", batteryLevelAlarmMax=" + batteryLevelAlarmMax +
|
||||||
|
", batteryLevelAlarmOnce=" + batteryLevelAlarmOnce +
|
||||||
|
", retryTimes=" + retryTimes +
|
||||||
|
", delayTime=" + delayTime +
|
||||||
|
", enableSmsTemplate=" + enableSmsTemplate +
|
||||||
|
", smsTemplate=" + smsTemplate +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,7 @@ public class BaseServlet extends HttpServlet {
|
|||||||
public BaseServlet(String path, Context context) {
|
public BaseServlet(String path, Context context) {
|
||||||
this.path = path;
|
this.path = path;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
SettingUtil.init(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String path;
|
private final String path;
|
||||||
|
@ -44,10 +44,10 @@ public class ZipUtils {
|
|||||||
File folder = new File(outPathString + File.separator + szName);
|
File folder = new File(outPathString + File.separator + szName);
|
||||||
folder.mkdirs();
|
folder.mkdirs();
|
||||||
} else {
|
} else {
|
||||||
Log.e(TAG, outPathString + File.separator + szName);
|
Log.d(TAG, outPathString + File.separator + szName);
|
||||||
File file = new File(outPathString + File.separator + szName);
|
File file = new File(outPathString + File.separator + szName);
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
Log.e(TAG, "Create the file:" + outPathString + File.separator + szName);
|
Log.d(TAG, "Create the file:" + outPathString + File.separator + szName);
|
||||||
Objects.requireNonNull(file.getParentFile()).mkdirs();
|
Objects.requireNonNull(file.getParentFile()).mkdirs();
|
||||||
file.createNewFile();
|
file.createNewFile();
|
||||||
}
|
}
|
||||||
@ -78,10 +78,10 @@ public class ZipUtils {
|
|||||||
File folder = new File(outPathString + File.separator + szName);
|
File folder = new File(outPathString + File.separator + szName);
|
||||||
folder.mkdirs();
|
folder.mkdirs();
|
||||||
} else {
|
} else {
|
||||||
Log.e(TAG, outPathString + File.separator + szName);
|
Log.d(TAG, outPathString + File.separator + szName);
|
||||||
File file = new File(outPathString + File.separator + szName);
|
File file = new File(outPathString + File.separator + szName);
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
Log.e(TAG, "Create the file:" + outPathString + File.separator + szName);
|
Log.d(TAG, "Create the file:" + outPathString + File.separator + szName);
|
||||||
Objects.requireNonNull(file.getParentFile()).mkdirs();
|
Objects.requireNonNull(file.getParentFile()).mkdirs();
|
||||||
file.createNewFile();
|
file.createNewFile();
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
@ -95,15 +96,17 @@
|
|||||||
android:id="@+id/ipText"
|
android:id="@+id/ipText"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="10sp"
|
android:layout_marginTop="10dp"
|
||||||
android:text="@string/local_ip"
|
android:text="@string/local_ip"
|
||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="10sp"
|
android:layout_marginTop="10dp"
|
||||||
android:text="@string/operating_instruction" />
|
android:text="@string/operating_instruction"
|
||||||
|
android:textSize="10sp"
|
||||||
|
tools:ignore="SmallSp" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
@ -382,4 +382,12 @@
|
|||||||
<string name="tips_battery_level_alarm_once">[Note] The upper and lower limits of the battery warning threshold are 0, and the continuous warning does not work.</string>
|
<string name="tips_battery_level_alarm_once">[Note] The upper and lower limits of the battery warning threshold are 0, and the continuous warning does not work.</string>
|
||||||
<string name="tips_compatible_solution">Compatible solution</string>
|
<string name="tips_compatible_solution">Compatible solution</string>
|
||||||
<string name="tips_wait_3_seconds">Please wait 3 seconds after clicking start</string>
|
<string name="tips_wait_3_seconds">Please wait 3 seconds after clicking start</string>
|
||||||
|
<string name="tips_clone_done">One-click clone operation is complete! \nPlease check whether the general settings and switches are turned on!</string>
|
||||||
|
<string name="tips_download_done">Download complete, preparing to restore data…</string>
|
||||||
|
<string name="tips_download_failed">Download failed:</string>
|
||||||
|
<string name="tips_downloading">Downloading</string>
|
||||||
|
<string name="tips_please_wait">Please wait…</string>
|
||||||
|
<string name="tips_clone_failed">One-click clone failed:</string>
|
||||||
|
<string name="tips_versions_inconsistent">The APP versions of the sender and the receiver are inconsistent, and cannot be cloned with one click!</string>
|
||||||
|
<string name="tips_get_info_failed">Failed to get one-click clone information from sender</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -217,7 +217,7 @@
|
|||||||
<string name="post">POST</string>
|
<string name="post">POST</string>
|
||||||
<string name="get">GET</string>
|
<string name="get">GET</string>
|
||||||
<string name="local_ip">本机IP:</string>
|
<string name="local_ip">本机IP:</string>
|
||||||
<string name="operating_instruction">操作说明:\n【注意】发送方与接收方的APP版本号必须一致!\n1.新旧手机连接同一个WiFi网络(禁用AP隔离)\n2.旧手机直接点【发送】按钮,获取到【服务端IP】\n3.新手机填写【服务端IP】后,点【接收】按钮\n【注意】新手机接收后,发送通道、转发规则将完全被覆盖,清空历史记录!</string>
|
<string name="operating_instruction">操作说明:\n1.新旧手机连接同一个WiFi网络(禁用AP隔离)\n2.旧手机直接点【发送】按钮,获取到【服务端IP】\n3.新手机填写【服务端IP】后,点【接收】按钮\n\n注意事项:\n1.发送方与接收方的APP版本号必须一致,才能克隆!\n2.新手机接收后,发送通道、转发规则将完全被覆盖,清空历史记录!\n3.主动请求、保活措施、个性设置不在克隆范围</string>
|
||||||
<string name="send">启动</string>
|
<string name="send">启动</string>
|
||||||
<string name="stop">停止</string>
|
<string name="stop">停止</string>
|
||||||
<string name="old_mobile_phone">我是旧手机</string>
|
<string name="old_mobile_phone">我是旧手机</string>
|
||||||
@ -381,4 +381,12 @@
|
|||||||
<string name="tips_battery_level_alarm_once">【注意】电量预警阈值上下限都是0,持续提醒不起作用</string>
|
<string name="tips_battery_level_alarm_once">【注意】电量预警阈值上下限都是0,持续提醒不起作用</string>
|
||||||
<string name="tips_compatible_solution">兼容方案</string>
|
<string name="tips_compatible_solution">兼容方案</string>
|
||||||
<string name="tips_wait_3_seconds">点击启动后请等待3秒</string>
|
<string name="tips_wait_3_seconds">点击启动后请等待3秒</string>
|
||||||
|
<string name="tips_clone_done">一键克隆操作完成!\n请检查·通用设置·各项开关是否已开启!</string>
|
||||||
|
<string name="tips_download_done">下载完成,正准备还原数据...</string>
|
||||||
|
<string name="tips_download_failed">下载失败:</string>
|
||||||
|
<string name="tips_downloading">正在下载</string>
|
||||||
|
<string name="tips_please_wait">请稍后...</string>
|
||||||
|
<string name="tips_clone_failed">一键克隆失败:</string>
|
||||||
|
<string name="tips_versions_inconsistent">发送端与接收端的APP版本不一致,无法一键克隆!</string>
|
||||||
|
<string name="tips_get_info_failed">从发送端获取一键克隆信息失败</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user