Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
eritpchy committed Nov 19, 2023
1 parent ca5fc75 commit dd208b8
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {
minSdkVersion 14
targetSdkVersion 33
versionCode 30
versionName "4.99.8"
versionName "4.99.9"
buildConfigField "String", "APP_PRODUCT_NAME", "\"FingerprintPay\""
}

Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/com/surcumference/fingerprint/Lang.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ public static String getString(int res) {
return tr("通用设置", "一般选项", "General");
case R.id.settings_title_use_biometric_api:
return tr("使用 Biometric Api", "使用 Biometric Api", "Use Biometric Api");
case R.id.settings_title_start_logcat:
return tr("开始记录日志", "開始記錄日誌", "Start logging");
case R.id.settings_title_stop_logcat:
return tr("停止记录日志", "停止記錄日誌", "Stop logging");
case R.id.settings_sub_title_switch_alipay:
return tr("启用支付宝指纹支付", "啟用支付宝指紋支付", "Enable fingerprint payment for Alipay");
case R.id.settings_sub_title_switch_wechat:
Expand All @@ -147,6 +151,10 @@ public static String getString(int res) {
return tr("将同时升级以下模块", "將同時升級以下模塊", "The following modules will be upgraded at the same time");
case R.id.settings_sub_title_use_biometric_api:
return tr("实验性, 仅 Android 9+ 可用", "實驗性, 僅 Android 9+ 可用", "Experimental, available only on Android 9+");
case R.id.settings_sub_title_start_logcat:
return tr("开始 --> 你的表演 --> 停止 --> 发送给开发者", "開始 --> 你的表演 --> 停止 --> 發送給開發者", "Start --> Payment operation --> Stop --> Send to developer");
case R.id.settings_sub_title_stop_logcat:
return tr("开始 --> 你的表演 --> 停止 --> 发送给开发者", "開始 --> 你的表演 --> 停止 --> 發送給開發者", "Start --> Payment operation --> Stop --> Send to developer");
case R.id.fingerprint_verification:
return tr("请验证指纹", "請驗證指紋", "Fingerprint verification");
case R.id.wechat_general:
Expand Down Expand Up @@ -230,6 +238,10 @@ public static String getString(int res) {
return tr("调用QQ捐赠页失败, 您可以手动转账捐赠哦, 账号: " + Constant.AUTHOR_QQ, "調用QQ捐贈頁失敗, 您可以手動轉賬捐贈哦, 帳號: " + Constant.AUTHOR_QQ, "Can't jump to QQ donate page, You can do it manually by transfer to account: " + Constant.AUTHOR_QQ);
case R.id.toast_need_qq_7_2_5:
return tr("您的QQ版本过低, 不支持指纹功能, 请升级至7.2.5以上的版本", "您的QQ版本過低, 不支持指紋功能, 請升級至7.2.5以上的版本", "Your QQ version is too low, does not support the fingerprint function, please upgrade to version 7.2.5 and above");
case R.id.toast_start_logging:
return tr("请开始你的表演, 日志已开始记录\n日志路径: %s", "請開始你的表演, 日誌已開始記錄\n日誌路徑: %s", "Star logging\nlog path: %s");
case R.id.toast_stop_logging:
return tr("表演结束, 请将日志文件分享给开发者\n日志路径: %s", "表演结束, 请将日志文件分享给开发者\n日誌路徑: %s", "Stop logging\nlog path: %s");
case R.id.template:
return tr("", "", "");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package com.surcumference.fingerprint.util;

import com.surcumference.fingerprint.util.log.L;

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.Field;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class LogcatManager {
private Process process;
private final File targetFile;
private ScheduledExecutorService timeOutExecutor = Executors.newScheduledThreadPool(1);

public LogcatManager(File targetFile) {
this.targetFile = targetFile;
}

public void startLogging(long timeOutMS) {
synchronized (LogcatManager.class) {
try {
stopLoggingInternal();
this.process = Runtime.getRuntime().exec("logcat");
Task.onBackground(() -> {
PrintWriter pw = null;
try {
pw = new PrintWriter(targetFile);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = bufferedReader.readLine()) != null) {
pw.println(line);
}
} catch (Exception e) {
L.e(e);
} finally {
FileUtils.closeCloseable(pw);
}
});
timeOutExecutor.shutdown();
timeOutExecutor = Executors.newScheduledThreadPool(1);
timeOutExecutor.schedule(() -> {
stopLoggingInternal();
L.d("stopLogging on timeout");
}, timeOutMS, TimeUnit.MILLISECONDS);
L.d("startLogging timeOutMS", timeOutMS);
} catch (Exception e) {
L.e(e);
}
}
}

public void stopLogging() {
synchronized (LogcatManager.class) {
stopLoggingInternal();
L.d("stopLogging");
}
}

private void stopLoggingInternal() {
try {
if (!isRunning()) {
return;
}
int pid = getPid(process);
if (pid > -1) {
android.os.Process.killProcess(pid);
}
process.destroyForcibly();
} catch (Exception e) {
L.e(e);
} finally {
timeOutExecutor.shutdown();
timeOutExecutor = Executors.newScheduledThreadPool(1);
}
}

public boolean isRunning() {
Process process = this.process;
if (process == null) {
return false;
}
return process.isAlive();
}

public File getTargetFile() {
return this.targetFile;
}

public static int getPid(Process p) {
try {
Field f = p.getClass().getDeclaredField("pid");
f.setAccessible(true);
return f.getInt(p);
} catch (Throwable e) {
L.e(e);
}
return -1;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.surcumference.fingerprint.view;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.util.AttributeSet;
Expand All @@ -13,14 +14,23 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.hjq.toast.Toaster;
import com.surcumference.fingerprint.Lang;
import com.surcumference.fingerprint.R;
import com.surcumference.fingerprint.adapter.PreferenceAdapter;
import com.surcumference.fingerprint.util.Config;
import com.surcumference.fingerprint.util.DateUtils;
import com.surcumference.fingerprint.util.DpUtils;
import com.surcumference.fingerprint.util.FileUtils;
import com.surcumference.fingerprint.util.LogcatManager;
import com.surcumference.fingerprint.util.Task;
import com.surcumference.fingerprint.util.log.L;

import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;


/**
Expand All @@ -33,6 +43,8 @@ public class AdvanceSettingsView extends DialogFrameLayout implements AdapterVie
private PreferenceAdapter mListAdapter;
private ListView mListView;

private static LogcatManager sLogcatManager;

public AdvanceSettingsView(@NonNull Context context) {
super(context);
init(context);
Expand All @@ -49,6 +61,17 @@ public AdvanceSettingsView(@NonNull Context context, @Nullable AttributeSet attr
}

private void init(Context context) {
if (sLogcatManager == null) {
File logFile = FileUtils.getSharableFile(context, "flog/" + context.getPackageName() + ".log");
try {
FileUtils.delete(logFile.getParentFile());
logFile.getParentFile().mkdirs();
} catch (Exception e) {
L.e(e);
}
sLogcatManager = new LogcatManager(logFile);
sLogcatManager.getTargetFile().deleteOnExit();
}
LinearLayout rootVerticalLayout = new LinearLayout(context);
rootVerticalLayout.setOrientation(LinearLayout.VERTICAL);

Expand All @@ -65,6 +88,11 @@ private void init(Context context) {
mListView.setDivider(new ColorDrawable(Color.TRANSPARENT));
mSettingsDataList.add(new PreferenceAdapter.Data(Lang.getString(R.id.settings_title_no_fingerprint_icon), Lang.getString(R.id.settings_sub_title_no_fingerprint_icon), true, Config.from(context).isShowFingerprintIcon()));
mSettingsDataList.add(new PreferenceAdapter.Data(Lang.getString(R.id.settings_title_use_biometric_api), Lang.getString(R.id.settings_sub_title_use_biometric_api), true, Config.from(context).isUseBiometricApi()));
if (sLogcatManager.isRunning()) {
mSettingsDataList.add(new PreferenceAdapter.Data(Lang.getString(R.id.settings_title_stop_logcat), Lang.getString(R.id.settings_sub_title_stop_logcat)));
} else {
mSettingsDataList.add(new PreferenceAdapter.Data(Lang.getString(R.id.settings_title_start_logcat), Lang.getString(R.id.settings_sub_title_start_logcat)));
}
mListAdapter = new PreferenceAdapter(mSettingsDataList);

rootVerticalLayout.addView(lineView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, DpUtils.dip2px(context, 2)));
Expand Down Expand Up @@ -102,7 +130,45 @@ public void onItemClick(AdapterView<?> adapterView, View view, int position, lon
data.selectionState = !data.selectionState;
config.setUseBiometricApi(data.selectionState);
mListAdapter.notifyDataSetChanged();
} else if (Lang.getString(R.id.settings_title_start_logcat).equals(data.title)) {
sLogcatManager.startLogging(5 * 60 * 1000 /** 5min */);
data.title = Lang.getString(R.id.settings_title_stop_logcat);
data.subTitle = Lang.getString(R.id.settings_sub_title_stop_logcat);
mListAdapter.notifyDataSetChanged();
File logFile = sLogcatManager.getTargetFile();
Toaster.showLong(String.format(Locale.getDefault(),
Lang.getString(R.id.toast_start_logging), logFile.getAbsoluteFile()));
} else if (Lang.getString(R.id.settings_title_stop_logcat).equals(data.title)) {
sLogcatManager.stopLogging();
data.title = Lang.getString(R.id.settings_title_start_logcat);
data.subTitle = Lang.getString(R.id.settings_sub_title_start_logcat);
mListAdapter.notifyDataSetChanged();
File logFile = sLogcatManager.getTargetFile();
try {
File logShareFile = new File(logFile.getParentFile(), context.getPackageName() + "-" + DateUtils.toString(new Date()).replaceAll("[: ]", "-") + ".log");
if (logFile.renameTo(logShareFile)) {
logFile = logShareFile;
}
} catch (Exception e) {
L.e(e);
}
logFile.deleteOnExit();
File finalLogFile = logFile;
Task.onMain(500, () -> Toaster.showLong(String.format(Locale.getDefault(),
Lang.getString(R.id.toast_stop_logging), finalLogFile.getAbsoluteFile())));
shareFile(logFile);
}
}

private void shareFile(File targetFile) {
try {
Context context = getContext();
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_STREAM, FileUtils.getUri(context, targetFile));
context.startActivity(Intent.createChooser(intent, "Share File"));
} catch (Exception e) {
L.e(e);
}
}
}
6 changes: 6 additions & 0 deletions app/src/main/res/values/ids.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
<item name="settings_title_no_fingerprint_icon" type="id"/>
<item name="settings_title_donate" type="id"/>
<item name="settings_title_use_biometric_api" type="id"/>
<item name="settings_title_start_logcat" type="id"/>
<item name="settings_title_stop_logcat" type="id"/>
<item name="settings_sub_title_switch_alipay" type="id"/>
<item name="settings_sub_title_switch_wechat" type="id"/>
<item name="settings_sub_title_switch_qq" type="id"/>
Expand All @@ -58,6 +60,8 @@
<item name="settings_sub_title_advance" type="id"/>
<item name="settings_sub_title_update_modules_same_time" type="id"/>
<item name="settings_sub_title_use_biometric_api" type="id"/>
<item name="settings_sub_title_start_logcat" type="id"/>
<item name="settings_sub_title_stop_logcat" type="id"/>
<item name="fingerprint_verification" type="id"/>
<item name="wechat_general" type="id"/>
<item name="app_settings_name" type="id"/>
Expand Down Expand Up @@ -100,6 +104,8 @@
<item name="toast_goto_donate_page_fail_wechat" type="id"/>
<item name="toast_goto_donate_page_fail_qq" type="id"/>
<item name="toast_need_qq_7_2_5" type="id"/>
<item name="toast_start_logging" type="id"/>
<item name="toast_stop_logging" type="id"/>

<item name="tag_password_layout_listener" type="id"/>
</resources>

0 comments on commit dd208b8

Please sign in to comment.