feat: add useless code

Signed-off-by: ACh Sulfate <xenonhydride@gmail.com>
This commit is contained in:
ACh Sulfate
2022-08-05 16:19:44 +08:00
parent 66d03cc8f9
commit 0cbe2f2c6b
5 changed files with 277 additions and 0 deletions

View File

@@ -933,3 +933,15 @@ Java_io_github_qauxv_util_Natives_lseek(JNIEnv *env, jclass, jint fd, jlong offs
}
return (jlong) result;
}
extern "C" JNIEXPORT jint JNICALL
Java_cc_ioctl_util_JunkCodeUtils_getJunkCode(JNIEnv *, jclass, jint jtc) {
auto tc = uint32_t(jtc);
const char *magic = "mIplOkwgxe3bzGc6g9K1BNJlXbuNmM+kYGWuoFGDOAZD1vHBEROCj+AN2TmBKXc0wEDLXgE+XgxL";
auto magic_len = strlen(magic);
uint32_t a32 = update_adler32(tc, reinterpret_cast<const uint8_t *>(magic), magic_len);
uint32_t o = a32 & 0xf;
// code should be in the range [0, 999999]
uint32_t code = (a32 >> o) % 1000000;
return jint(code);
}

View File

@@ -0,0 +1,104 @@
/*
* QAuxiliary - An Xposed module for QQ/TIM
* Copyright (C) 2019-2022 qwq233@qwq2333.top
* https://github.com/cinit/QAuxiliary
*
* This software is non-free but opensource software: you can redistribute it
* and/or modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation; either
* version 3 of the License, or any later version and our eula as published
* by QAuxiliary contributors.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* and eula along with this software. If not, see
* <https://www.gnu.org/licenses/>
* <https://github.com/cinit/QAuxiliary/blob/master/LICENSE.md>.
*/
package cc.ioctl.fragment
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.annotation.UiThread
import androidx.core.view.doOnLayout
import cc.ioctl.util.JunkCodeUtils
import io.github.qauxv.databinding.FragmentJunkCodeBinding
import io.github.qauxv.fragment.BaseRootLayoutFragment
import xyz.nextalone.util.SystemServiceUtils
import java.text.SimpleDateFormat
class JunkCodeFragment : BaseRootLayoutFragment(), Runnable {
override fun getTitle(): String = "动态验证码"
private val mTimeFormat = SimpleDateFormat("HH:mm:ss", java.util.Locale.ROOT)
private var mLasttc: Int = 0
private var mBinding: FragmentJunkCodeBinding? = null
override fun doOnCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
mBinding = FragmentJunkCodeBinding.inflate(inflater, container, false).apply {
junkCodeCopy.setOnClickListener {
val code = getCodeForTime(System.currentTimeMillis())
SystemServiceUtils.copyToClipboard(it.context, code)
Toast.makeText(it.context, "已复制到剪贴板", Toast.LENGTH_SHORT).show()
}
}
rootLayoutView = mBinding?.root
return mBinding!!.root
}
@UiThread
private fun updateStatus(binding: FragmentJunkCodeBinding) {
val now = System.currentTimeMillis()
val tc = (now / 1000L / 30L).toInt()
val expireTime = (tc + 1) * 30L * 1000L
val code = JunkCodeUtils.getJunkCode(tc)
val timeRemainingMs = expireTime - now
val remainPercentage = timeRemainingMs.toFloat() / (30L * 1000L).toFloat()
if (tc != mLasttc) {
binding.junkCodeCode.text = code.toString()
}
binding.junkCodeInvalidateTime.text = "过期时间: " + mTimeFormat.format(expireTime) +
" (剩余 " + (timeRemainingMs / 1000L).coerceAtLeast(1) + " 秒)"
mLasttc = tc
binding.junkCodeProgressBar.layoutParams.apply {
val parentWidth = (binding.junkCodeProgressBar.parent as ViewGroup).width
width = (parentWidth * remainPercentage).toInt()
}
binding.junkCodeProgressBar.requestLayout()
}
override fun run() {
if (isResumed) {
mBinding?.let {
updateStatus(it)
it.junkCodeInvalidateTime.postDelayed(this, 1000L)
}
}
}
override fun onResume() {
super.onResume()
mBinding?.let { binding ->
binding.rootMainLayout.doOnLayout {
updateStatus(binding)
}
// schedule a job to update the time every second
binding.junkCodeInvalidateTime.postDelayed(this, 1000L)
}
}
private fun getCodeForTime(time: Long): String {
val tc = (time / 1000L / 30L).toInt()
val code = JunkCodeUtils.getJunkCode(tc)
return code.toString()
}
}

View File

@@ -0,0 +1,35 @@
/*
* QAuxiliary - An Xposed module for QQ/TIM
* Copyright (C) 2019-2022 qwq233@qwq2333.top
* https://github.com/cinit/QAuxiliary
*
* This software is non-free but opensource software: you can redistribute it
* and/or modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation; either
* version 3 of the License, or any later version and our eula as published
* by QAuxiliary contributors.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* and eula along with this software. If not, see
* <https://www.gnu.org/licenses/>
* <https://github.com/cinit/QAuxiliary/blob/master/LICENSE.md>.
*/
package cc.ioctl.util;
public class JunkCodeUtils {
private JunkCodeUtils() {
throw new UnsupportedOperationException();
}
/**
* Result code should be in the range [0, 999999]
*/
public static native int getJunkCode(int tc);
}

View File

@@ -42,6 +42,7 @@ import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.core.content.res.ResourcesCompat;
import cc.ioctl.fragment.JunkCodeFragment;
import cc.ioctl.util.HostInfo;
import io.github.qauxv.BuildConfig;
import io.github.qauxv.R;
@@ -65,6 +66,7 @@ public class ConfigV2Activity extends AppCompatTransferActivity {
private static final String ALIAS_ACTIVITY_NAME = "io.github.qauxv.activity.ConfigV2ActivityAlias";
private MainV2NormalBinding mainV2Binding = null;
private boolean mHintLongPressed = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -101,6 +103,14 @@ public class ConfigV2Activity extends AppCompatTransferActivity {
HolidayHelper.setup(this);
updateActivationStatus();
SyncUtils.postDelayed(3000, this::updateActivationStatus);
mainV2Binding.mainV2Help.setOnLongClickListener(v -> {
if (!mHintLongPressed) {
mHintLongPressed = true;
} else {
SettingsUiFragmentHostActivity.startActivityForFragment(this, JunkCodeFragment.class, null);
}
return true;
});
}
public void updateActivationStatus() {

View File

@@ -0,0 +1,116 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ QAuxiliary - An Xposed module for QQ/TIM
~ Copyright (C) 2019-2022 qwq233@qwq2333.top
~ https://github.com/cinit/QAuxiliary
~
~ This software is non-free but opensource software: you can redistribute it
~ and/or modify it under the terms of the GNU Affero General Public License
~ as published by the Free Software Foundation; either
~ version 3 of the License, or any later version and our eula as published
~ by QAuxiliary contributors.
~
~ This software is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
~ Affero General Public License for more details.
~
~ You should have received a copy of the GNU Affero General Public License
~ and eula along with this software. If not, see
~ <https://www.gnu.org/licenses/>
~ <https://github.com/cinit/QAuxiliary/blob/master/LICENSE.md>.
-->
<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:fadeScrollbars="true"
android:orientation="vertical">
<LinearLayout
android:id="@+id/rootMainLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top|center_horizontal"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:orientation="horizontal">
<View
android:id="@+id/junkCode_progressBar"
android:layout_width="match_parent"
android:layout_height="4dp"
android:background="?attr/themeColor" />
</LinearLayout>
<TextView
android:id="@+id/junkCode_hint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingRight="20dp"
android:paddingLeft="20dp"
android:gravity="start"
android:text="此动态验证码每 30 秒刷新一次,目前没有任何作用。"
android:textColor="@color/secondTextColor"
android:textSize="14sp" />
<TextView
android:id="@+id/junkCode_code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:fontFamily="monospace"
android:gravity="center"
android:text="******"
android:textColor="@color/firstTextColor"
android:textIsSelectable="true"
android:textSize="40dp"
tools:ignore="SpUsage" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:gravity="center_vertical">
<Button
android:id="@+id/junkCode_copy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:text="复制" />
<TextView
android:id="@+id/junkCode_invalidateTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:padding="10dp"
android:gravity="start"
android:text="过期时间: HH:MM:SS"
android:textColor="@color/secondTextColor"
android:textSize="14sp" />
</RelativeLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:gravity="start"
android:text="您可以将此动态验证码分享给任何人,因为它与您的账号或设备无关。\n相同版本的模块在任何设备上在同一时间总是显示相同的动态验证码。"
android:textColor="@color/secondTextColor"
android:textSize="14sp" />
</LinearLayout>
</ScrollView>