Browse Source

add debug activity

main
MTing 2 weeks ago
parent
commit
a07a65d029
  1. 6
      app/src/main/AndroidManifest.xml
  2. 373
      app/src/main/java/com/ouxuan/oxface/DebugActivity.java
  3. 50
      app/src/main/java/com/ouxuan/oxface/MainActivity.java
  4. 8
      app/src/main/res/drawable/log_background.xml
  5. 212
      app/src/main/res/layout/activity_debug.xml
  6. 2
      settings.gradle

6
app/src/main/AndroidManifest.xml

@ -97,6 +97,12 @@
android:name=".debug.DirectBootTestActivity" android:name=".debug.DirectBootTestActivity"
android:exported="true" android:exported="true"
android:theme="@style/Theme.OxFaceLogin" /> android:theme="@style/Theme.OxFaceLogin" />
<!-- 调试界面Activity -->
<activity
android:name=".DebugActivity"
android:exported="false"
android:theme="@style/Theme.OxFaceLogin" />
</application> </application>
</manifest> </manifest>

373
app/src/main/java/com/ouxuan/oxface/DebugActivity.java

@ -0,0 +1,373 @@
package com.ouxuan.oxface;
import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
import com.ouxuan.oxface.device.DeviceUtils;
import com.ouxuan.oxface.network.utils.NetworkUtils;
import com.ouxuan.oxface.utils.AutoStartManager;
import com.ouxuan.oxface.utils.BootSimulationHelper;
import com.ouxuan.oxface.utils.LogManager;
import com.ouxuan.oxface.utils.UtilCodeHelper;
import java.io.File;
import java.util.Date;
public class DebugActivity extends Activity {
private static final String TAG = "DebugActivity";
private TextView tvLogOutput;
private ScrollView logScrollView;
private AutoStartManager autoStartManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_debug);
initViews();
initManagers();
setupClickListeners();
}
private void initViews() {
tvLogOutput = findViewById(R.id.tvLogOutput);
logScrollView = findViewById(R.id.logScrollView);
// 初始化日志显示
tvLogOutput.setText("调试界面已启动 - " + new Date().toString() + "\n");
}
private void initManagers() {
autoStartManager = AutoStartManager.getInstance(this);
}
private void setupClickListeners() {
// 测试自启动按钮
Button btnTestAutoStart = findViewById(R.id.btnTestAutoStart);
btnTestAutoStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
logMessage("触发自启动测试...");
triggerAutoStartTest();
}
});
// 测试直接启动按钮
Button btnTestDirectStart = findViewById(R.id.btnTestDirectStart);
btnTestDirectStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
logMessage("触发直接启动测试...");
triggerDirectStartTest();
}
});
// 显示日志路径按钮
Button btnShowLogPath = findViewById(R.id.btnShowLogPath);
btnShowLogPath.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showLogPathInfo();
}
});
// 写入测试日志按钮
Button btnWriteTestLog = findViewById(R.id.btnWriteTestLog);
btnWriteTestLog.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
writeTestLogs();
}
});
// 显示自启动状态按钮
Button btnShowAutoStartStatus = findViewById(R.id.btnShowAutoStartStatus);
btnShowAutoStartStatus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showAutoStartStatus();
}
});
// 重置统计信息按钮
Button btnResetAutoStartStats = findViewById(R.id.btnResetAutoStartStats);
btnResetAutoStartStats.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
resetAutoStartStats();
}
});
// 显示设备信息按钮
Button btnShowDeviceInfo = findViewById(R.id.btnShowDeviceInfo);
btnShowDeviceInfo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showDeviceInfo();
}
});
// 测试网络连接按钮
Button btnTestNetwork = findViewById(R.id.btnTestNetwork);
btnTestNetwork.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
testNetworkConnection();
}
});
// 清空日志按钮
Button btnClearLogs = findViewById(R.id.btnClearLogs);
btnClearLogs.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
clearLogs();
}
});
// 测试Shell命令按钮
Button btnTestShellCommand = findViewById(R.id.btnTestShellCommand);
btnTestShellCommand.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
testShellCommand();
}
});
// 测试闹钟按钮
Button btnTestAlarm = findViewById(R.id.btnTestAlarm);
btnTestAlarm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
testAlarm();
}
});
// 关闭按钮
Button btnClose = findViewById(R.id.btnClose);
btnClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
/**
* 触发自启动测试
*/
private void triggerAutoStartTest() {
try {
BootSimulationHelper.simulateBootCompleted(this);
logMessage("自启动测试已触发");
showToast("自启动测试已触发");
} catch (Exception e) {
Log.e(TAG, "触发自启动测试失败", e);
logMessage("触发自启动测试失败: " + e.getMessage());
showToast("触发自启动测试失败");
}
}
/**
* 直接启动应用测试
*/
private void triggerDirectStartTest() {
try {
BootSimulationHelper.directStartApp(this);
logMessage("直接启动测试已触发");
showToast("直接启动测试已触发");
} catch (Exception e) {
Log.e(TAG, "触发直接启动测试失败", e);
logMessage("触发直接启动测试失败: " + e.getMessage());
showToast("触发直接启动测试失败");
}
}
/**
* 显示日志路径信息
*/
private void showLogPathInfo() {
String pathInfo = LogManager.getLogPathInfo(this);
logMessage("日志路径信息:\n" + pathInfo);
// 写入一条测试日志
LogManager.logOperation("调试", "用户查看日志路径信息");
// 复制日志目录路径到剪贴板
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
if (clipboard != null) {
LogManager logManager = LogManager.getInstance(this);
String logDirPath = logManager.getLogDirectory().getAbsolutePath();
ClipData clip = ClipData.newPlainText("日志目录路径", logDirPath);
clipboard.setPrimaryClip(clip);
showToast("日志目录路径已复制: " + logDirPath);
}
}
/**
* 写入测试日志
*/
private void writeTestLogs() {
// 写入一些测试日志
LogManager.logInfo("DEBUG", "这是一条测试信息日志 - " + new Date());
LogManager.logWarning("DEBUG", "这是一条测试警告日志 - " + new Date());
LogManager.logError("DEBUG", "这是一条测试错误日志 - " + new Date());
LogManager.logOperation("测试操作", "用户触发测试日志写入");
LogManager.logPerformance("测试性能", 88);
logMessage("测试日志已写入,请稍后再查看路径信息");
showToast("测试日志已写入");
}
/**
* 显示自启动状态
*/
private void showAutoStartStatus() {
if (autoStartManager != null) {
String statusInfo = autoStartManager.getAutoStartStatusInfo();
logMessage("自启动状态信息:\n" + statusInfo);
showToast("自启动状态信息已显示");
} else {
logMessage("自启动管理器未初始化");
showToast("自启动管理器未初始化");
}
}
/**
* 重置统计信息
*/
private void resetAutoStartStats() {
if (autoStartManager != null) {
autoStartManager.resetAutoStartStats();
logMessage("自启动统计信息已重置");
showToast("自启动统计信息已重置");
} else {
logMessage("自启动管理器未初始化");
showToast("自启动管理器未初始化");
}
}
/**
* 显示设备信息
*/
private void showDeviceInfo() {
String deviceInfo = DeviceUtils.getDeviceInfo(this);
logMessage("设备信息:\n" + deviceInfo);
showToast("设备信息已显示");
}
/**
* 测试网络连接
*/
private void testNetworkConnection() {
logMessage("正在测试网络连接...");
boolean isConnected = UtilCodeHelper.Network.isConnected();
logMessage("网络连接状态: " + (isConnected ? "已连接" : "未连接"));
showToast("网络连接测试完成");
}
/**
* 清空日志
*/
private void clearLogs() {
// 删除日志目录中的所有文件
LogManager logManager = LogManager.getInstance(this);
File logDir = logManager.getLogDirectory();
if (logDir.exists() && logDir.isDirectory()) {
File[] logFiles = logDir.listFiles();
if (logFiles != null) {
for (File file : logFiles) {
if (file.isFile()) {
file.delete();
}
}
}
}
logMessage("日志已清空");
showToast("日志已清空");
}
/**
* 测试Shell命令
*/
private void testShellCommand() {
logMessage("测试Shell命令执行...");
try {
// 执行简单的Shell命令
String result = UtilCodeHelper.Device.getModel();
logMessage("设备型号: " + result);
showToast("设备信息获取完成");
} catch (Exception e) {
Log.e(TAG, "设备信息获取失败", e);
logMessage("设备信息获取失败: " + e.getMessage());
showToast("设备信息获取失败");
}
}
/**
* 测试闹钟
*/
private void testAlarm() {
logMessage("测试闹钟功能...");
try {
// 设置一个5秒后的闹钟测试
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("auto_start", true);
intent.putExtra("boot_reason", "alarm_test");
intent.putExtra("start_source", "debug_test");
// 使用BootSimulationHelper来设置测试闹钟
BootSimulationHelper.simulateBootCompleted(this);
logMessage("闹钟测试已触发,将在系统启动模拟后执行");
showToast("闹钟测试已触发");
} catch (Exception e) {
Log.e(TAG, "闹钟测试失败", e);
logMessage("闹钟测试失败: " + e.getMessage());
showToast("闹钟测试失败");
}
}
/**
* 在日志输出区域添加消息
* @param message 要添加的消息
*/
private void logMessage(String message) {
runOnUiThread(new Runnable() {
@Override
public void run() {
String currentTime = android.text.format.DateFormat.format("HH:mm:ss", new Date()).toString();
String logEntry = "[" + currentTime + "] " + message + "\n";
tvLogOutput.append(logEntry);
// 滚动到底部
logScrollView.post(new Runnable() {
@Override
public void run() {
logScrollView.fullScroll(View.FOCUS_DOWN);
}
});
}
});
}
/**
* 显示Toast消息
* @param message 要显示的消息
*/
private void showToast(String message) {
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
}
}

50
app/src/main/java/com/ouxuan/oxface/MainActivity.java

@ -18,6 +18,7 @@ import android.view.Window;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
@ -768,11 +769,60 @@ public class MainActivity extends AppCompatActivity {
} }
}); });
// 添加长按版本号打开调试界面的功能
setupVersionLongClick();
// 添加双击测试功能 // 添加双击测试功能
setupDoubleTapTest(); setupDoubleTapTest();
} }
/** /**
* 设置长按版本号打开调试界面的功能
*/
private void setupVersionLongClick() {
// 查找版本号TextView在布局文件中没有明确的ID我们需要通过遍历查找
View bottomInfoLayout = findViewById(R.id.bottomInfoLayout);
if (bottomInfoLayout instanceof LinearLayout) {
LinearLayout layout = (LinearLayout) bottomInfoLayout;
// 遍历子视图找到包含版本号的LinearLayout
for (int i = 0; i < layout.getChildCount(); i++) {
View child = layout.getChildAt(i);
if (child instanceof LinearLayout) {
LinearLayout versionLayout = (LinearLayout) child;
// 查找版本号TextView
for (int j = 0; j < versionLayout.getChildCount(); j++) {
View versionChild = versionLayout.getChildAt(j);
if (versionChild instanceof TextView) {
TextView versionTextView = (TextView) versionChild;
// 检查是否包含版本号文本
if (versionTextView.getText().toString().contains("Version")) {
// 设置长按监听器
versionTextView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
// 打开调试界面
openDebugActivity();
return true;
}
});
break;
}
}
}
}
}
}
}
/**
* 打开调试界面
*/
private void openDebugActivity() {
Intent intent = new Intent(this, DebugActivity.class);
startActivity(intent);
}
/**
* 设置双击测试功能 * 设置双击测试功能
*/ */
private void setupDoubleTapTest() { private void setupDoubleTapTest() {

8
app/src/main/res/drawable/log_background.xml

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#F0F0F0" />
<stroke
android:width="1dp"
android:color="#CCCCCC" />
<corners android:radius="4dp" />
</shape>

212
app/src/main/res/layout/activity_debug.xml

@ -0,0 +1,212 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
android:background="@color/white">
<!-- 标题栏 -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="调试工具"
android:textSize="24sp"
android:textStyle="bold"
android:textColor="@color/black"
android:gravity="center"
android:layout_marginBottom="16dp" />
<!-- 按钮区域 - 使用GridLayout实现每行3个按钮 -->
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<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"
android:orientation="horizontal"
android:layout_marginBottom="8dp">
<Button
android:id="@+id/btnTestAutoStart"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="测试自启动"
android:layout_marginEnd="4dp"
android:textSize="12sp" />
<Button
android:id="@+id/btnTestDirectStart"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="测试直接启动"
android:layout_marginStart="4dp"
android:layout_marginEnd="4dp"
android:textSize="12sp" />
<Button
android:id="@+id/btnShowLogPath"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="显示日志路径"
android:layout_marginStart="4dp"
android:textSize="12sp" />
</LinearLayout>
<!-- 第二行按钮 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="8dp">
<Button
android:id="@+id/btnWriteTestLog"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="写入测试日志"
android:layout_marginEnd="4dp"
android:textSize="12sp" />
<Button
android:id="@+id/btnShowAutoStartStatus"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="显示自启动状态"
android:layout_marginStart="4dp"
android:layout_marginEnd="4dp"
android:textSize="12sp" />
<Button
android:id="@+id/btnResetAutoStartStats"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="重置统计信息"
android:layout_marginStart="4dp"
android:textSize="12sp" />
</LinearLayout>
<!-- 第三行按钮 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="8dp">
<Button
android:id="@+id/btnShowDeviceInfo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="显示设备信息"
android:layout_marginEnd="4dp"
android:textSize="12sp" />
<Button
android:id="@+id/btnTestNetwork"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="测试网络连接"
android:layout_marginStart="4dp"
android:layout_marginEnd="4dp"
android:textSize="12sp" />
<Button
android:id="@+id/btnClearLogs"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="清空日志"
android:layout_marginStart="4dp"
android:textSize="12sp" />
</LinearLayout>
<!-- 第四行按钮 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="8dp">
<Button
android:id="@+id/btnTestShellCommand"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="测试Shell命令"
android:layout_marginEnd="4dp"
android:textSize="12sp" />
<Button
android:id="@+id/btnTestAlarm"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="测试闹钟"
android:layout_marginStart="4dp"
android:layout_marginEnd="4dp"
android:textSize="12sp" />
<Button
android:id="@+id/btnClose"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="关闭"
android:layout_marginStart="4dp"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<!-- 日志输出区域 -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="日志输出:"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="@color/black"
android:layout_marginTop="16dp"
android:layout_marginBottom="8dp" />
<ScrollView
android:id="@+id/logScrollView"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="@drawable/log_background"
android:padding="8dp">
<TextView
android:id="@+id/tvLogOutput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="日志将在此显示..."
android:textSize="12sp"
android:textColor="@color/black"
android:fontFamily="monospace" />
</ScrollView>
</LinearLayout>

2
settings.gradle

@ -22,4 +22,4 @@ include ':app'
include ':facelibrary' include ':facelibrary'
include ':financelibrary' include ':financelibrary'
include ':datalibrary' include ':datalibrary'
include ':oxplugin_padface'
// include ':oxplugin_padface'
Loading…
Cancel
Save