├── LICENSE ├── README.md └── app └── src └── main ├── AndroidManifest.xml ├── ic_launcher-web.png ├── java └── cn │ └── xylin │ └── mistep │ ├── StepApplication.java │ ├── activitys │ ├── BaseActivity.java │ └── Main.java │ ├── utils │ ├── MyCrash.java │ ├── MyFile.java │ ├── NotificationUtil.java │ ├── Shared.java │ ├── StepUtil.java │ ├── Util.java │ └── WLOG.java │ └── works │ ├── AutoModifySteps.java │ └── BaseWorker.java └── res ├── drawable ├── ic_app.xml └── ic_launcher_background.xml ├── layout ├── activity_main.xml └── content_view.xml ├── mipmap-anydpi-v26 ├── ic_launcher.xml └── ic_launcher_round.xml ├── mipmap-hdpi ├── ic_launcher.png └── ic_launcher_round.png ├── mipmap-mdpi ├── ic_launcher.png └── ic_launcher_round.png ├── mipmap-xhdpi ├── ic_launcher.png └── ic_launcher_round.png ├── mipmap-xxhdpi ├── ic_launcher.png └── ic_launcher_round.png ├── mipmap-xxxhdpi ├── ic_launcher.png └── ic_launcher_round.png └── values ├── colors.xml ├── strings.xml └── styles.xml /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### 小米步数管理(重制) 2 |   时隔一年,小米步数管理又完善了一点点。第一代在完成1.35的时候就被我放弃了,原因有很多,例如ROOT模式使用的SQLite3在高版本并不是特别好、其次每天手动打开软件让我很烦躁、还有6月份的时候换三颗星了...... 3 | 4 |   所以这一次为大家带来了可能、大概、也许、应该是最终版的小米步数管理,它拥有:增加和指定两种修改步数类型、第一次打开和0点定时(需要手动为APP启用自启动权限)两种自动修改方式、核心破解和ROOT两种修改模式。其中ROOT模式采用GitHub用户“nkh0472”提供的content命令进行修改,完美解决了第一代因使用SQLite3命令导致的无法修改步数和电量与性能屡次停止运行问题,非常感谢这位用户提供的思路。 5 | 6 |   在此对我放弃小米步数管理项目期间通过邮件反馈问题的用户表示歉意,因为开发者的懒惰导致了你们的问题无法解决...... 7 | 8 |   负一屏或健康APP显示的步数无法减少不是BUG,是官方修改了统计方式。当初能够减少步数可以说是官方BUG,现已修复。 9 | 10 |   禁用/卸载“电量与性能”或“Joyose”APP可能会导致系统无法记录步数,因此APP也无法修改步数。 11 | 12 |   APP图标来源:[阿里巴巴矢量图标库](https://www.iconfont.cn "阿里巴巴矢量图标库") 图标所属用户“琴十三” 13 | 14 | ### 下载(一代+重制) 15 |   [蓝奏云](https://wwa.lanzous.com/b059y5jwf "蓝奏云") -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 14 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LinYuLuo/MiStep/cf966f30e256384dd2223dd1fdf1c51e10c05c39/app/src/main/ic_launcher-web.png -------------------------------------------------------------------------------- /app/src/main/java/cn/xylin/mistep/StepApplication.java: -------------------------------------------------------------------------------- 1 | package cn.xylin.mistep; 2 | 3 | import android.app.Activity; 4 | import android.app.Application; 5 | 6 | import java.util.ArrayList; 7 | 8 | import cn.xylin.mistep.activitys.Main; 9 | import cn.xylin.mistep.utils.MyCrash; 10 | import cn.xylin.mistep.utils.NotificationUtil; 11 | import cn.xylin.mistep.utils.Shared; 12 | import cn.xylin.mistep.utils.WLOG; 13 | 14 | 15 | /** 16 | * @author XyLin 17 | * @date 2020年11月17日 23:01:00 18 | * StepApplication.java 19 | **/ 20 | public class StepApplication extends Application { 21 | private static final ArrayList ACTIVITYS = new ArrayList<>(); 22 | 23 | @Override 24 | public void onCreate() { 25 | super.onCreate(); 26 | WLOG.initLogFile(this); 27 | MyCrash.getInstance().initContext(this); 28 | Shared.getShared().addShared(this, Main.USER_SETTING); 29 | NotificationUtil.get().init(this); 30 | } 31 | 32 | public static void add(Activity appActivity) { 33 | ACTIVITYS.add(appActivity); 34 | } 35 | 36 | public static void remove(Activity appActivity) { 37 | ACTIVITYS.remove(appActivity); 38 | } 39 | 40 | public static Activity get() { 41 | return ACTIVITYS.get(ACTIVITYS.size() - 1); 42 | } 43 | 44 | public static void finishAll() { 45 | int size = ACTIVITYS.size(); 46 | for (int index = 0; index < size; index++) { 47 | if ((index + 1) < size) { 48 | ACTIVITYS.get(index).finish(); 49 | } else { 50 | ACTIVITYS.get(index).finishAndRemoveTask(); 51 | } 52 | } 53 | ACTIVITYS.clear(); 54 | //Util.TASK_SERVICE.shutdownNow(); 55 | android.os.Process.killProcess(android.os.Process.myPid()); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /app/src/main/java/cn/xylin/mistep/activitys/BaseActivity.java: -------------------------------------------------------------------------------- 1 | package cn.xylin.mistep.activitys; 2 | 3 | import android.os.Bundle; 4 | import android.widget.LinearLayout; 5 | import com.google.android.material.appbar.MaterialToolbar; 6 | import androidx.annotation.LayoutRes; 7 | import androidx.appcompat.app.AppCompatActivity; 8 | import cn.xylin.mistep.R; 9 | import cn.xylin.mistep.StepApplication; 10 | import cn.xylin.mistep.utils.Util; 11 | 12 | /** 13 | * @author XyLin 14 | * @date 2020年11月21日 22:31:00 15 | * BaseActivity.java 16 | **/ 17 | public abstract class BaseActivity extends AppCompatActivity { 18 | 19 | AppCompatActivity appActivity; 20 | boolean isCanExitActivity = false; 21 | long clickBackTime; 22 | MaterialToolbar trBar; 23 | 24 | @Override 25 | protected void onCreate(Bundle savedInstanceState) { 26 | super.onCreate(savedInstanceState); 27 | super.setContentView(R.layout.content_view); 28 | appActivity = this; 29 | StepApplication.add(appActivity); 30 | trBar = findViewById(R.id.trBar); 31 | setSupportActionBar(trBar); 32 | initActivityControl(); 33 | initControlAttribute(); 34 | } 35 | 36 | abstract void initActivityControl(); 37 | 38 | abstract void initControlAttribute(); 39 | 40 | @Override 41 | protected void onDestroy() { 42 | super.onDestroy(); 43 | StepApplication.remove(appActivity); 44 | } 45 | 46 | @Override 47 | public void onBackPressed() { 48 | if (isCanExitActivity) { 49 | if ((System.currentTimeMillis() - clickBackTime) > Util.DELAY_TIME) { 50 | clickBackTime = System.currentTimeMillis(); 51 | Util.toast(appActivity, "再按一次以退出程序"); 52 | return; 53 | } 54 | StepApplication.finishAll(); 55 | } 56 | super.onBackPressed(); 57 | } 58 | 59 | @Override 60 | public void setContentView(@LayoutRes int layoutId) { 61 | ((LinearLayout) findViewById(R.id.llGroup)).addView(getLayoutInflater().inflate(layoutId, null)); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /app/src/main/java/cn/xylin/mistep/activitys/Main.java: -------------------------------------------------------------------------------- 1 | package cn.xylin.mistep.activitys; 2 | 3 | import android.app.AlertDialog; 4 | import android.app.TimePickerDialog; 5 | import android.content.DialogInterface; 6 | import android.text.method.ScrollingMovementMethod; 7 | import android.view.View; 8 | import android.widget.CompoundButton; 9 | import android.widget.RadioGroup; 10 | import android.widget.TimePicker; 11 | import com.google.android.material.button.MaterialButton; 12 | import com.google.android.material.switchmaterial.SwitchMaterial; 13 | import com.google.android.material.textfield.TextInputEditText; 14 | import com.google.android.material.textview.MaterialTextView; 15 | import java.util.Calendar; 16 | import java.util.TimeZone; 17 | import cn.xylin.mistep.R; 18 | import cn.xylin.mistep.StepApplication; 19 | import cn.xylin.mistep.utils.Shared; 20 | import cn.xylin.mistep.utils.StepUtil; 21 | import cn.xylin.mistep.utils.Util; 22 | import cn.xylin.mistep.works.AutoModifySteps; 23 | 24 | /** 25 | * @author XyLin 26 | * @date 2021/1/25 23:06:22 27 | * Main.java 28 | **/ 29 | public class Main extends BaseActivity implements View.OnClickListener, CompoundButton.OnCheckedChangeListener, View.OnLongClickListener { 30 | public static final String USER_SETTING = "userSetting"; 31 | public static final String ROOT_MODE = "isRootMode"; 32 | public static final String MODIFY_MODE_ADD = "modifyModeAdd"; 33 | public static final String AUTO_MODIFY_MODE = "autoModifyMode"; 34 | public static final String AUTO_ADD_STEPS = "autoAddSteps"; 35 | public static final String TIMING_NOTIFICATION = "isNotificationTimingModifyResult"; 36 | public static final String TIMING_HOUR = "timingHour"; 37 | public static final String TIMING_MINUTE = "timingMinute"; 38 | private static final String DAY_INT = "dayInt"; 39 | private static final String CHECK_RECORD_APP = "checkRecordApp"; 40 | private MaterialTextView tvTodaySteps; 41 | private TextInputEditText edtAddSteps; 42 | private RadioGroup rdgModifyMode; 43 | private SwitchMaterial shFirstOpenAutoAdd, shTimingModify, shTimingNotification; 44 | private Shared shared; 45 | private boolean isRootMode; 46 | private TimePickerDialog timeDialog; 47 | 48 | @Override 49 | void initActivityControl() { 50 | isCanExitActivity = true; 51 | setContentView(R.layout.activity_main); 52 | tvTodaySteps = findViewById(R.id.tvTodaySteps); 53 | edtAddSteps = findViewById(R.id.edtAddSteps); 54 | rdgModifyMode = findViewById(R.id.rdgModifyMode); 55 | shFirstOpenAutoAdd = findViewById(R.id.shFirstOpenAutoAdd); 56 | shTimingModify = findViewById(R.id.shTimingModify); 57 | shTimingNotification = findViewById(R.id.shTimingNotification); 58 | shared = Shared.getShared(); 59 | } 60 | 61 | @Override 62 | void initControlAttribute() { 63 | isRootMode = shared.getValue(USER_SETTING, ROOT_MODE, false); 64 | updateTodaySteps(); 65 | edtAddSteps.setText(shared.getValue(USER_SETTING, AUTO_ADD_STEPS, 0).toString()); 66 | rdgModifyMode.check(shared.getValue(USER_SETTING, MODIFY_MODE_ADD, true) ? R.id.rdbAddSteps : R.id.rdbSetSteps); 67 | int autoModifyMode = shared.getValue(USER_SETTING, AUTO_MODIFY_MODE, 0); 68 | shFirstOpenAutoAdd.setChecked(autoModifyMode == 1); 69 | shTimingModify.setChecked(autoModifyMode == 2); 70 | if (autoModifyMode == 2) { 71 | shTimingNotification.setVisibility(View.VISIBLE); 72 | shTimingNotification.setChecked(shared.getValue(USER_SETTING, TIMING_NOTIFICATION, false)); 73 | } 74 | rdgModifyMode.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { 75 | @Override 76 | public void onCheckedChanged(RadioGroup group, int checkedId) { 77 | shared.putValue(USER_SETTING, MODIFY_MODE_ADD, checkedId == R.id.rdbAddSteps).commitShared(USER_SETTING); 78 | } 79 | }); 80 | shFirstOpenAutoAdd.setOnCheckedChangeListener(this); 81 | shTimingModify.setOnCheckedChangeListener(this); 82 | shTimingNotification.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 83 | @Override 84 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 85 | shared.putValue(USER_SETTING, TIMING_NOTIFICATION, isChecked).commitShared(USER_SETTING); 86 | } 87 | }); 88 | MaterialButton button = findViewById(R.id.btnModifySteps); 89 | button.setOnClickListener(this); 90 | button.setOnLongClickListener(this); 91 | ((MaterialTextView) findViewById(R.id.tvUseTip)).setMovementMethod(ScrollingMovementMethod.getInstance()); 92 | if (autoModifyMode == 1) { 93 | checkNewDay(); 94 | return; 95 | } 96 | if (!shared.getValue(USER_SETTING, CHECK_RECORD_APP, false)) { 97 | checkRecordAppState(); 98 | } 99 | } 100 | 101 | private void checkNewDay() { 102 | int day = Calendar.getInstance(TimeZone.getDefault()).get(Calendar.DAY_OF_MONTH); 103 | if (shared.getValue(USER_SETTING, DAY_INT, -1) != day) { 104 | shared.putValue(USER_SETTING, DAY_INT, day).commitShared(USER_SETTING); 105 | findViewById(R.id.btnModifySteps).callOnClick(); 106 | StepApplication.finishAll(); 107 | } 108 | } 109 | 110 | @Override 111 | public void onClick(View v) { 112 | if (v.getId() == R.id.btnModifySteps) { 113 | String inputStr = Util.getControlText(edtAddSteps); 114 | if (Util.isStrEmpty(inputStr)) { 115 | Util.toast(appActivity, R.string.toast_empty_steps); 116 | } else { 117 | try { 118 | int steps = Integer.parseInt(inputStr); 119 | shared.putValue(USER_SETTING, AUTO_ADD_STEPS, steps).commitShared(USER_SETTING); 120 | Util.toast(appActivity, StepUtil.modifySteps(getApplicationContext(), rdgModifyMode.getCheckedRadioButtonId() == R.id.rdbSetSteps, isRootMode, steps) ? "修改步数成功。" : "修改步数失败,请尝试切换模式。"); 121 | updateTodaySteps(); 122 | } catch (NumberFormatException ignore) { 123 | Util.toast(appActivity, R.string.toast_input_steps_error); 124 | } 125 | } 126 | } 127 | } 128 | 129 | @Override 130 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 131 | int switchId = buttonView.getId(); 132 | if (buttonView.isPressed()) { 133 | switch (switchId) { 134 | case R.id.shFirstOpenAutoAdd: { 135 | if (isChecked) { 136 | shTimingModify.setChecked(false); 137 | shared.putValue(USER_SETTING, DAY_INT, Calendar.getInstance(TimeZone.getDefault()).get(Calendar.DAY_OF_MONTH)); 138 | } else { 139 | shared.removeValue(USER_SETTING, DAY_INT); 140 | } 141 | break; 142 | } 143 | case R.id.shTimingModify: { 144 | if (isChecked) { 145 | if (timeDialog == null) { 146 | timeDialog = new TimePickerDialog( 147 | appActivity, 148 | new TimePickerDialog.OnTimeSetListener() { 149 | @Override 150 | public void onTimeSet(TimePicker view, int hourOfDay, int minute) { 151 | shFirstOpenAutoAdd.setChecked(false); 152 | shTimingNotification.setVisibility(View.VISIBLE); 153 | shared.putValue(USER_SETTING, TIMING_HOUR, hourOfDay) 154 | .putValue(USER_SETTING, TIMING_MINUTE, minute) 155 | .commitShared(USER_SETTING); 156 | AutoModifySteps.setNextModifySteps(getApplicationContext(), false); 157 | Util.toast(appActivity, "将于每天的" + hourOfDay + "点" + (minute > 0 && minute < 10 ? "0" + minute : minute) + "分自动修改"); 158 | } 159 | }, 160 | shared.getValue(USER_SETTING, TIMING_HOUR, 0), 161 | shared.getValue(USER_SETTING, TIMING_MINUTE, 1), 162 | true 163 | ); 164 | timeDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { 165 | @Override 166 | public void onCancel(DialogInterface dialog) { 167 | shTimingModify.setChecked(false); 168 | AutoModifySteps.setNextModifySteps(getApplicationContext(), true); 169 | } 170 | }); 171 | } 172 | timeDialog.show(); 173 | Util.toast(appActivity, R.string.toast_please_appoint_time); 174 | } else { 175 | shTimingNotification.setVisibility(View.GONE); 176 | } 177 | break; 178 | } 179 | default: { 180 | return; 181 | } 182 | } 183 | shared.putValue(USER_SETTING, AUTO_MODIFY_MODE, !shFirstOpenAutoAdd.isChecked() && !shTimingModify.isChecked() ? 0 : shFirstOpenAutoAdd.isChecked() ? 1 : 2) 184 | .commitShared(USER_SETTING); 185 | } else if (!isChecked) { 186 | if (switchId == R.id.shFirstOpenAutoAdd) { 187 | shared.removeValue(USER_SETTING, DAY_INT).commitShared(USER_SETTING); 188 | } else if (switchId == R.id.shTimingModify) { 189 | shTimingNotification.setVisibility(View.GONE); 190 | AutoModifySteps.setNextModifySteps(getApplicationContext(), true); 191 | } 192 | } 193 | } 194 | 195 | private void updateTodaySteps() { 196 | tvTodaySteps.setText("今日步数:" + StepUtil.getTodaySteps(getApplicationContext())); 197 | } 198 | 199 | @Override 200 | public boolean onLongClick(View v) { 201 | isRootMode = !isRootMode; 202 | Util.toast(appActivity, "已切换为" + (isRootMode ? "ROOT" : "核心破解") + "模式。"); 203 | shared.putValue(USER_SETTING, ROOT_MODE, isRootMode).commitShared(USER_SETTING); 204 | return true; 205 | } 206 | 207 | private void checkRecordAppState() { 208 | if (!StepUtil.checkRecordDisable(getApplicationContext())) { 209 | new AlertDialog.Builder(appActivity) 210 | .setTitle(R.string.dialog_record_title) 211 | .setMessage(R.string.dialog_record_message) 212 | .setNeutralButton(R.string.dialog_record_btn_enable, new DialogInterface.OnClickListener() { 213 | @Override 214 | public void onClick(DialogInterface dialog, int which) { 215 | Util.toast(appActivity, StepUtil.rootEnableRecordApp() ? R.string.toast_record_enable_success : R.string.toast_record_enable_fail); 216 | updateTodaySteps(); 217 | } 218 | }) 219 | .setNegativeButton(R.string.dialog_record_btn_cancel, new DialogInterface.OnClickListener() { 220 | @Override 221 | public void onClick(DialogInterface dialog, int which) { 222 | shared.putValue(USER_SETTING, CHECK_RECORD_APP, true).applyShared(USER_SETTING); 223 | } 224 | }) 225 | .setPositiveButton(R.string.dialog_record_btn_ok, null) 226 | .show(); 227 | } 228 | } 229 | } 230 | -------------------------------------------------------------------------------- /app/src/main/java/cn/xylin/mistep/utils/MyCrash.java: -------------------------------------------------------------------------------- 1 | package cn.xylin.mistep.utils; 2 | 3 | import android.content.Context; 4 | import android.os.Looper; 5 | import android.widget.Toast; 6 | 7 | import cn.xylin.mistep.StepApplication; 8 | 9 | /** 10 | * @author XyLin 11 | * @date 2020年3月14日 09:53:13 12 | * MyCrash.java 用于捕捉全局异常 13 | **/ 14 | public class MyCrash implements Thread.UncaughtExceptionHandler { 15 | private static final Object SYN_ROOT = new Object(); 16 | private Context myContext; 17 | private Thread.UncaughtExceptionHandler defaultHandler; 18 | 19 | public static MyCrash getInstance() { 20 | synchronized (SYN_ROOT) { 21 | return new MyCrash(); 22 | } 23 | } 24 | 25 | public void initContext(Context myContext) { 26 | this.myContext = myContext; 27 | this.defaultHandler = Thread.getDefaultUncaughtExceptionHandler(); 28 | Thread.setDefaultUncaughtExceptionHandler(this); 29 | } 30 | 31 | @Override 32 | public void uncaughtException(Thread thread, Throwable throwable) { 33 | if (!isHandlerSuccess(throwable) && defaultHandler != null) { 34 | defaultHandler.uncaughtException(thread, throwable); 35 | } else { 36 | try { 37 | Thread.sleep(2000L); 38 | } catch (InterruptedException ignored) { 39 | } 40 | StepApplication.finishAll(); 41 | } 42 | } 43 | 44 | private boolean isHandlerSuccess(final Throwable throwable) { 45 | if (throwable == null) { 46 | return true; 47 | } 48 | if (throwable.toString().trim().length() > 0) { 49 | new Thread(new Runnable() { 50 | @Override 51 | public void run() { 52 | Looper.prepare(); 53 | WLOG.outThrowable(throwable); 54 | Toast.makeText(myContext, "程序出现未知错误,请查看日志文件。", Toast.LENGTH_SHORT).show(); 55 | Looper.loop(); 56 | } 57 | }).start(); 58 | return true; 59 | } 60 | return false; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /app/src/main/java/cn/xylin/mistep/utils/MyFile.java: -------------------------------------------------------------------------------- 1 | package cn.xylin.mistep.utils; 2 | 3 | import android.content.Context; 4 | import java.io.File; 5 | 6 | /** 7 | * @author XyLin 8 | * @date 2020/8/19 09:02:40 9 | * MyFile.java 10 | **/ 11 | public class MyFile { 12 | private static MyFile file; 13 | 14 | public static MyFile getFile(Context baseContext) { 15 | if (file == null && baseContext != null) { 16 | file = new MyFile(baseContext); 17 | } 18 | return file; 19 | } 20 | 21 | private File externalFile; 22 | 23 | private MyFile(Context baseContext) { 24 | this.externalFile = baseContext.getExternalFilesDir("").getParentFile(); 25 | } 26 | 27 | public File getDir(String dirName) { 28 | File dir = new File(externalFile, dirName); 29 | if (!dir.exists()) { 30 | dir.mkdir(); 31 | } else if (dir.isFile()) { 32 | dir.delete(); 33 | dir.mkdir(); 34 | } 35 | return dir; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/cn/xylin/mistep/utils/NotificationUtil.java: -------------------------------------------------------------------------------- 1 | package cn.xylin.mistep.utils; 2 | 3 | import android.app.Notification; 4 | import android.app.NotificationChannel; 5 | import android.app.NotificationManager; 6 | import android.content.Context; 7 | import android.os.Build; 8 | import androidx.annotation.DrawableRes; 9 | import androidx.core.app.NotificationCompat; 10 | import cn.xylin.mistep.BuildConfig; 11 | import cn.xylin.mistep.R; 12 | 13 | /** 14 | * @author XyLin 15 | * @date 2021/2/24 21:42:09 16 | * NotificationUtil.java 17 | **/ 18 | public class NotificationUtil { 19 | private static NotificationUtil instance; 20 | private static final String CHANNEL_ID = BuildConfig.APPLICATION_ID; 21 | private static final boolean NEED_CHANNEL = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O; 22 | 23 | public static NotificationUtil get() { 24 | if (instance == null) { 25 | instance = new NotificationUtil(); 26 | } 27 | return instance; 28 | } 29 | 30 | private Context context; 31 | private final NotificationChannel channel; 32 | private NotificationManager notificationManager; 33 | //该项目去掉通知ID,已碰到指定步数多次发送成功通知的问题,但Debug却没有触发 34 | //private int notificationId = 0; 35 | 36 | private NotificationUtil() { 37 | if (NEED_CHANNEL) { 38 | channel = new NotificationChannel(CHANNEL_ID, "定时修改结果通知", NotificationManager.IMPORTANCE_LOW); 39 | } else { 40 | channel = null; 41 | } 42 | } 43 | 44 | public void init(Context appContext) { 45 | context = appContext; 46 | notificationManager = (NotificationManager) appContext.getSystemService(Context.NOTIFICATION_SERVICE); 47 | if (NEED_CHANNEL) { 48 | notificationManager.createNotificationChannel(channel); 49 | } 50 | } 51 | 52 | public void sendNotification(String title, String message) { 53 | sendNotification(R.drawable.ic_app, title, message); 54 | } 55 | 56 | public void sendNotification(@DrawableRes int icon, String title, String message) { 57 | if (context != null) { 58 | //notificationId++; 59 | Notification notification = new NotificationCompat.Builder(context, CHANNEL_ID) 60 | .setSmallIcon(icon) 61 | .setContentTitle(title) 62 | .setContentText(message) 63 | .setAutoCancel(true) 64 | .setWhen(System.currentTimeMillis()) 65 | .build(); 66 | notificationManager.notify(0, notification); 67 | } 68 | } 69 | 70 | public void cancelNotification(int notificationId) { 71 | if (context != null) { 72 | notificationManager.cancel(notificationId); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /app/src/main/java/cn/xylin/mistep/utils/Shared.java: -------------------------------------------------------------------------------- 1 | package cn.xylin.mistep.utils; 2 | 3 | import android.content.Context; 4 | import android.content.SharedPreferences; 5 | 6 | import java.util.Set; 7 | import java.util.concurrent.ConcurrentHashMap; 8 | 9 | /** 10 | * @author XyLin 11 | * @date 2020/8/21 16:39:33 12 | * Shared.java 13 | **/ 14 | public class Shared { 15 | private static Shared shared; 16 | 17 | public static Shared getShared() { 18 | if (shared == null) { 19 | shared = new Shared(); 20 | } 21 | return shared; 22 | } 23 | 24 | private final ConcurrentHashMap sharedMap; 25 | private final ConcurrentHashMap editorMap; 26 | 27 | private Shared() { 28 | this.sharedMap = new ConcurrentHashMap<>(); 29 | this.editorMap = new ConcurrentHashMap<>(); 30 | } 31 | 32 | public Shared addShared(Context baseContext, String xmlName) { 33 | sharedMap.put(xmlName, baseContext.getSharedPreferences(xmlName, Context.MODE_PRIVATE)); 34 | editorMap.put(xmlName, sharedMap.get(xmlName).edit()); 35 | return this; 36 | } 37 | 38 | public T getValue(String xmlName, String key, T defValue) { 39 | if (sharedMap.containsKey(xmlName)) { 40 | SharedPreferences preferences = sharedMap.get(xmlName); 41 | T retValue; 42 | if (defValue instanceof Integer) { 43 | retValue = (T) (Integer) preferences.getInt(key, (Integer) defValue); 44 | } else if (defValue instanceof Boolean) { 45 | retValue = (T) (Boolean) preferences.getBoolean(key, (Boolean) defValue); 46 | } else if (defValue instanceof Float) { 47 | retValue = (T) (Float) preferences.getFloat(key, (Float) defValue); 48 | } else if (defValue instanceof Long) { 49 | retValue = (T) (Long) preferences.getLong(key, (Long) defValue); 50 | } else if (defValue instanceof String) { 51 | retValue = (T) preferences.getString(key, (String) defValue); 52 | } else { 53 | retValue = defValue; 54 | } 55 | return retValue; 56 | } 57 | return defValue; 58 | } 59 | 60 | public Shared putValue(String xmlName, String key, Object value) { 61 | if (editorMap.containsKey(xmlName)) { 62 | SharedPreferences.Editor editor = editorMap.get(xmlName); 63 | if (value instanceof Integer) { 64 | editor.putInt(key, (Integer) value); 65 | } else if (value instanceof Boolean) { 66 | editor.putBoolean(key, (Boolean) value); 67 | } else if (value instanceof Float) { 68 | editor.putFloat(key, (Float) value); 69 | } else if (value instanceof Long) { 70 | editor.putLong(key, (Long) value); 71 | } else if (value instanceof String) { 72 | editor.putString(key, (String) value); 73 | } 74 | } 75 | return this; 76 | } 77 | 78 | public Shared removeValue(String xmlName, String key) { 79 | if (editorMap.containsKey(xmlName)) { 80 | editorMap.get(xmlName).remove(key); 81 | } 82 | return this; 83 | } 84 | 85 | public void applyShared(String xmlName) { 86 | if (editorMap.containsKey(xmlName)) { 87 | editorMap.get(xmlName).apply(); 88 | reloadEdit(xmlName); 89 | } 90 | } 91 | 92 | public void commitShared(String xmlName) { 93 | if (editorMap.containsKey(xmlName)) { 94 | editorMap.get(xmlName).commit(); 95 | reloadEdit(xmlName); 96 | } 97 | } 98 | 99 | public void clearShared(String xmlName) { 100 | if (sharedMap.containsKey(xmlName)) { 101 | Set keys = sharedMap.get(xmlName).getAll().keySet(); 102 | SharedPreferences.Editor editor = editorMap.get(xmlName); 103 | for (String key : keys) { 104 | editor.remove(key); 105 | } 106 | editor.commit(); 107 | reloadEdit(xmlName); 108 | } 109 | } 110 | 111 | private void reloadEdit(String xmlName) { 112 | if (sharedMap.containsKey(xmlName)) { 113 | editorMap.put(xmlName, sharedMap.get(xmlName).edit()); 114 | } 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /app/src/main/java/cn/xylin/mistep/utils/StepUtil.java: -------------------------------------------------------------------------------- 1 | package cn.xylin.mistep.utils; 2 | 3 | import android.content.ContentValues; 4 | import android.content.Context; 5 | import android.content.pm.ApplicationInfo; 6 | import android.content.pm.PackageManager; 7 | import android.database.Cursor; 8 | import android.net.Uri; 9 | 10 | import java.io.DataOutputStream; 11 | import java.io.IOException; 12 | import java.text.SimpleDateFormat; 13 | import java.util.Locale; 14 | 15 | /** 16 | * @author XyLin 17 | * @date 2021/1/26 17:28:20 18 | * StepUtil.java 19 | **/ 20 | public class StepUtil { 21 | private static final String[] MAY_BE_RECORD_APP = {"com.miui.powerkeeper", "com.xiaomi.joyose"}; 22 | private static final Uri STEP_URI = Uri.parse("content://com.miui.providers.steps/item"); 23 | private static final String ROOT_ADD_STEPS = "content insert --uri content://com.miui.providers.steps/item --bind _begin_time:l:%d --bind _end_time:l:%d --bind _mode:i:2 --bind _steps:i:%d"; 24 | private static final String BEGIN_TIME = "_begin_time"; 25 | private static final String END_TIME = "_end_time"; 26 | private static final String MODE = "_mode"; 27 | private static final String STEPS = "_steps"; 28 | private static final String[] QUERY_FILED = {"_id", BEGIN_TIME, END_TIME, MODE, STEPS}; 29 | private static final SimpleDateFormat TIME_FORMAT = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.CHINA); 30 | private static final ContentValues STEPS_VALUE = new ContentValues(4); 31 | 32 | static { 33 | STEPS_VALUE.put(MODE, 2); 34 | } 35 | 36 | public static int getTodaySteps(Context context) { 37 | try { 38 | Cursor cursor = context.getContentResolver().query(STEP_URI, QUERY_FILED, null, null, null); 39 | if (cursor != null) { 40 | long todayBeginTime = TIME_FORMAT.parse(getTodayTime(true)).getTime(); 41 | long todayEndTime = TIME_FORMAT.parse(getTodayTime(false)).getTime(); 42 | int todayStepCount = 0; 43 | while (cursor.moveToNext()) { 44 | if (cursor.getLong(1) > todayBeginTime && cursor.getLong(2) < todayEndTime && cursor.getInt(3) == 2) { 45 | todayStepCount += cursor.getInt(4); 46 | } 47 | } 48 | cursor.close(); 49 | return todayStepCount; 50 | } 51 | } catch (Exception ignored) { 52 | } 53 | return 0; 54 | } 55 | 56 | private static String getTodayTime(boolean flag) { 57 | return String.format("%s%s", TIME_FORMAT.format(System.currentTimeMillis()).substring(0, 11), flag ? "00:00:00" : "23:59:59"); 58 | } 59 | 60 | public static boolean modifySteps(Context context, boolean isSetMode, boolean isRootMode, int steps) { 61 | int todaySteps = getTodaySteps(context); 62 | if (isSetMode) { 63 | if (todaySteps == steps) { 64 | return true; 65 | } else { 66 | steps -= todaySteps; 67 | } 68 | } 69 | if (isRootMode) { 70 | return rootModeAddSteps(steps); 71 | } else { 72 | return coreModeAddSteps(context, steps); 73 | } 74 | } 75 | 76 | private static boolean coreModeAddSteps(Context context, int steps) { 77 | try { 78 | STEPS_VALUE.put(BEGIN_TIME, System.currentTimeMillis() - 1000L); 79 | STEPS_VALUE.put(END_TIME, System.currentTimeMillis()); 80 | STEPS_VALUE.put(STEPS, steps); 81 | context.getContentResolver().insert(STEP_URI, STEPS_VALUE); 82 | return true; 83 | } catch (SecurityException ignore) { 84 | } 85 | return false; 86 | } 87 | 88 | private static boolean runRootCommand(String command) { 89 | try { 90 | Process process = Runtime.getRuntime().exec("su"); 91 | DataOutputStream dataOutputStream = new DataOutputStream(process.getOutputStream()); 92 | dataOutputStream.writeBytes(command); 93 | dataOutputStream.flush(); 94 | dataOutputStream.close(); 95 | return process.waitFor() == 0; 96 | } catch (IOException | InterruptedException ignored) { 97 | } 98 | return false; 99 | } 100 | 101 | private static boolean rootModeAddSteps(int steps) { 102 | return runRootCommand(String.format( 103 | Locale.CHINA, 104 | ROOT_ADD_STEPS, 105 | System.currentTimeMillis() - 1000L, 106 | System.currentTimeMillis(), 107 | steps 108 | )); 109 | } 110 | 111 | public static boolean rootEnableRecordApp() { 112 | boolean enableSuccess = false; 113 | for (String pkg : MAY_BE_RECORD_APP) { 114 | boolean enableResult = runRootCommand("pm enable " + pkg); 115 | if (!enableSuccess && enableResult) { 116 | enableSuccess = true; 117 | } 118 | } 119 | return enableSuccess; 120 | } 121 | 122 | public static boolean checkRecordDisable(Context context) { 123 | PackageManager packageManager = context.getPackageManager(); 124 | try { 125 | for (String pkg : MAY_BE_RECORD_APP) { 126 | ApplicationInfo info = packageManager.getApplicationInfo(pkg, 0); 127 | if (!info.enabled) { 128 | return false; 129 | } 130 | } 131 | return true; 132 | } catch (PackageManager.NameNotFoundException ignore) { 133 | } 134 | return false; 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /app/src/main/java/cn/xylin/mistep/utils/Util.java: -------------------------------------------------------------------------------- 1 | package cn.xylin.mistep.utils; 2 | 3 | import android.app.Activity; 4 | import android.os.Looper; 5 | import android.text.TextUtils; 6 | import android.widget.Button; 7 | import android.widget.EditText; 8 | import android.widget.TextView; 9 | import android.widget.Toast; 10 | 11 | /** 12 | * @author XyLin 13 | * @date 2020/5/3 09:48:01 14 | * Util.java 15 | **/ 16 | public class Util { 17 | public static final String STRING_NULL = ""; 18 | public static final boolean BOOLEAN_NULL = false; 19 | public static final int INT_NULL = 0; 20 | public static final long DELAY_TIME = 2000L; 21 | //public static final ExecutorService TASK_SERVICE = Executors.newFixedThreadPool(5); 22 | 23 | public static boolean isStrEmpty(CharSequence sequence) { 24 | return TextUtils.isEmpty(sequence); 25 | } 26 | 27 | /** 28 | * @param equal 被拿来做相等判断主体的字符串 29 | * @param beEquals 被主体判断是否相等的字符串数组 30 | * @return 返回主体是否等于被判断的字符串数组中的一个 31 | */ 32 | public static boolean isStrEquals(CharSequence equal, CharSequence... beEquals) { 33 | for (CharSequence beEqual : beEquals) { 34 | if (TextUtils.equals(equal, beEqual)) { 35 | return true; 36 | } 37 | } 38 | return BOOLEAN_NULL; 39 | } 40 | 41 | /** 42 | * @param contain 被拿来做包含判断主体的字符串 43 | * @param beContains 被主体判断是否包含的字符串数组 44 | * @return 返回主体是否包含被判断的字符串数组 45 | */ 46 | public static boolean isStrContains(CharSequence contain, CharSequence... beContains) { 47 | for (CharSequence beContain : beContains) { 48 | if (contain.toString().contains(beContain)) { 49 | return true; 50 | } 51 | } 52 | return BOOLEAN_NULL; 53 | } 54 | 55 | public static String getControlText(Object control) { 56 | if (control instanceof EditText) { 57 | return ((EditText) control).getText().toString().trim(); 58 | } else if (control instanceof Button) { 59 | return ((Button) control).getText().toString().trim(); 60 | } else if (control instanceof TextView) { 61 | return ((TextView) control).getText().toString().trim(); 62 | } 63 | return STRING_NULL; 64 | } 65 | 66 | public static void toast(Activity appActivity, Object idOrString) { 67 | toast(appActivity, idOrString, Toast.LENGTH_SHORT); 68 | } 69 | 70 | public static void toast(final Activity appActivity, final Object idOrString, final int duration) { 71 | if (appActivity != null) { 72 | if (Looper.myLooper() == Looper.getMainLooper()) { 73 | String str; 74 | if (idOrString instanceof Integer) { 75 | str = appActivity.getString((int) idOrString); 76 | } else if (idOrString instanceof String) { 77 | str = String.valueOf(idOrString); 78 | } else { 79 | return; 80 | } 81 | Toast.makeText(appActivity.getApplicationContext(), str, duration).show(); 82 | } else { 83 | appActivity.runOnUiThread(new Runnable() { 84 | @Override 85 | public void run() { 86 | toast(appActivity, idOrString, duration); 87 | } 88 | }); 89 | } 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /app/src/main/java/cn/xylin/mistep/utils/WLOG.java: -------------------------------------------------------------------------------- 1 | package cn.xylin.mistep.utils; 2 | 3 | import android.content.Context; 4 | import android.os.Build; 5 | import android.util.Log; 6 | 7 | import java.io.File; 8 | import java.io.FileOutputStream; 9 | import java.io.IOException; 10 | import java.nio.charset.StandardCharsets; 11 | import java.util.Calendar; 12 | 13 | /** 14 | * @author XyLin 15 | * @date 2020年11月17日 23:01:00 16 | * WLOG.java 17 | **/ 18 | public class WLOG { 19 | private static File logFileDir; 20 | private static File logFilePath; 21 | 22 | public static void initLogFile(Context appContext) { 23 | try { 24 | logFileDir = MyFile.getFile(appContext).getDir("logs"); 25 | Calendar calendar = Calendar.getInstance(); 26 | logFilePath = new File(logFileDir, String.format("%s-%s-%s.log", calendar.get(Calendar.YEAR), (calendar.get(Calendar.MONTH) + 1), calendar.get(Calendar.DAY_OF_MONTH))); 27 | } catch (RuntimeException ignore) { 28 | } 29 | } 30 | 31 | public static void outLogs(String... logs) { 32 | if (logFileDir == null || logFilePath == null) { 33 | return; 34 | } 35 | try { 36 | FileOutputStream outputStream = new FileOutputStream(logFilePath, true); 37 | for (String log : logs) { 38 | outputStream.write(log.getBytes(StandardCharsets.UTF_8)); 39 | outputStream.write("\n".getBytes(StandardCharsets.UTF_8)); 40 | } 41 | outputStream.flush(); 42 | outputStream.close(); 43 | } catch (IOException ignore) { 44 | } 45 | } 46 | 47 | public static void outThrowable(Throwable throwable) { 48 | for (StackTraceElement traceElement : throwable.getStackTrace()) { 49 | WLOG.outLogs( 50 | "Class=" + traceElement.getClassName(), 51 | "Method=" + traceElement.getMethodName(), 52 | "Line=" + traceElement.getLineNumber(), 53 | "StackTrace=" + traceElement.toString(), "" 54 | ); 55 | } 56 | WLOG.outLogs( 57 | "Throwable=" + throwable.toString(), "", 58 | "Device Brand=" + Build.BRAND, 59 | "Device Model=" + Build.MODEL, 60 | "Android Device=" + Build.DEVICE, 61 | "Android ID=" + Build.DISPLAY, 62 | "Android Incremental=" + Build.VERSION.INCREMENTAL, 63 | "Android Sdk=" + Build.VERSION.SDK_INT, 64 | "Android Version=" + Build.VERSION.RELEASE, 65 | "--------------------------------------" 66 | ); 67 | } 68 | 69 | public static void printLogs(String tag, Object... logs) { 70 | StringBuilder builder = new StringBuilder(tag).append(":"); 71 | for (Object log : logs) { 72 | builder.append(log); 73 | } 74 | Log.i("WLOG", builder.toString()); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /app/src/main/java/cn/xylin/mistep/works/AutoModifySteps.java: -------------------------------------------------------------------------------- 1 | package cn.xylin.mistep.works; 2 | 3 | import android.content.Context; 4 | import java.util.concurrent.TimeUnit; 5 | import androidx.annotation.NonNull; 6 | import androidx.work.OneTimeWorkRequest; 7 | import androidx.work.WorkManager; 8 | import androidx.work.Worker; 9 | import androidx.work.WorkerParameters; 10 | import cn.xylin.mistep.activitys.Main; 11 | import cn.xylin.mistep.utils.NotificationUtil; 12 | import cn.xylin.mistep.utils.Shared; 13 | import cn.xylin.mistep.utils.StepUtil; 14 | 15 | /** 16 | * @author XyLin 17 | * @date 2021/1/27 19:18:55 18 | * AutoModifySteps.java 19 | **/ 20 | public class AutoModifySteps extends BaseWorker { 21 | private static final String WORK_TAG = "autoModifySteps"; 22 | 23 | /** 24 | * 用来开启或关闭定时增加步数功能 25 | * 26 | * @param context context 27 | * @param isCancel 指定是否关闭定时增加步数,只可通过Main界面进行调整 28 | */ 29 | public static void setNextModifySteps(Context context, boolean isCancel) { 30 | WorkManager manager = WorkManager.getInstance(context); 31 | if (isCancel) { 32 | manager.cancelAllWorkByTag(WORK_TAG); 33 | } else { 34 | OneTimeWorkRequest workRequest = new OneTimeWorkRequest.Builder(AutoModifySteps.class) 35 | .addTag(WORK_TAG) 36 | .setInitialDelay(getNextTime(), TimeUnit.MILLISECONDS) 37 | .build(); 38 | manager.enqueue(workRequest); 39 | } 40 | } 41 | 42 | public AutoModifySteps(@NonNull Context context, @NonNull WorkerParameters workerParams) { 43 | super(context, workerParams); 44 | } 45 | 46 | /** 47 | * 定时任务也许有BUG,指定+定时+通知,测试是看到发送了6-8个通知(但后续又没触发了),所以我把通知ID固定了【滑稽】。 48 | * 49 | * @return 一直成功,无论结果如何...... 50 | */ 51 | @NonNull 52 | @Override 53 | public Result doWork() { 54 | setNextModifySteps(getApplicationContext(), false); 55 | boolean isSetMode = !Shared.getShared().getValue(Main.USER_SETTING, Main.MODIFY_MODE_ADD, true); 56 | boolean isRootMode = Shared.getShared().getValue(Main.USER_SETTING, Main.ROOT_MODE, false); 57 | int steps = Shared.getShared().getValue(Main.USER_SETTING, Main.AUTO_ADD_STEPS, 0); 58 | boolean result = StepUtil.modifySteps(getApplicationContext(), isSetMode, isRootMode, steps); 59 | if (Shared.getShared().getValue(Main.USER_SETTING, Main.TIMING_NOTIFICATION, false)) { 60 | NotificationUtil.get().sendNotification( 61 | "小米步数管理-" + (isRootMode ? "ROOT" : "核心破解"), 62 | (isSetMode ? "指定步数为" : "增加") + steps + "步" + (result ? "成功" : "失败") 63 | ); 64 | } 65 | return Worker.Result.success(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /app/src/main/java/cn/xylin/mistep/works/BaseWorker.java: -------------------------------------------------------------------------------- 1 | package cn.xylin.mistep.works; 2 | 3 | import android.content.Context; 4 | 5 | import java.util.Calendar; 6 | 7 | import androidx.annotation.NonNull; 8 | import androidx.work.Worker; 9 | import androidx.work.WorkerParameters; 10 | import cn.xylin.mistep.activitys.Main; 11 | import cn.xylin.mistep.utils.Shared; 12 | 13 | /** 14 | * @author XyLin 15 | * @date 2021/1/29 16:17:14 16 | * BaseWorker.java 17 | **/ 18 | abstract class BaseWorker extends Worker { 19 | /** 20 | * 获取下一次执行定时任务需要等待的时间 21 | * 22 | * @return 返回执行下一次任务需要等待的毫秒数 23 | */ 24 | static long getNextTime() { 25 | Calendar currCalendar = Calendar.getInstance(); 26 | Calendar nextCalendar = Calendar.getInstance(); 27 | Shared shared = Shared.getShared(); 28 | nextCalendar.set(Calendar.HOUR_OF_DAY, shared.getValue(Main.USER_SETTING, Main.TIMING_HOUR, 0)); 29 | nextCalendar.set(Calendar.MINUTE, shared.getValue(Main.USER_SETTING, Main.TIMING_MINUTE, 1)); 30 | nextCalendar.set(Calendar.SECOND, 0); 31 | if (nextCalendar.before(currCalendar)) { 32 | nextCalendar.add(Calendar.HOUR_OF_DAY, 24); 33 | } 34 | return nextCalendar.getTimeInMillis() - currCalendar.getTimeInMillis(); 35 | } 36 | 37 | BaseWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) { 38 | super(context, workerParams); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_app.xml: -------------------------------------------------------------------------------- 1 | 6 | 8 | 11 | 14 | 17 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 10 | 12 | 14 | 16 | 18 | 20 | 22 | 24 | 26 | 28 | 30 | 32 | 34 | 36 | 38 | 40 | 42 | 44 | 46 | 48 | 50 | 52 | 54 | 56 | 58 | 60 | 62 | 64 | 66 | 68 | 70 | 72 | 74 | 75 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 16 | 17 | 23 | 24 | 37 | 38 | 46 | 47 | 58 | 59 | 64 | 65 | 71 | 72 | 73 | 79 | 80 | 88 | 89 | 97 | 98 | 105 | 106 | 114 | 115 | 124 | -------------------------------------------------------------------------------- /app/src/main/res/layout/content_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LinYuLuo/MiStep/cf966f30e256384dd2223dd1fdf1c51e10c05c39/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LinYuLuo/MiStep/cf966f30e256384dd2223dd1fdf1c51e10c05c39/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LinYuLuo/MiStep/cf966f30e256384dd2223dd1fdf1c51e10c05c39/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LinYuLuo/MiStep/cf966f30e256384dd2223dd1fdf1c51e10c05c39/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LinYuLuo/MiStep/cf966f30e256384dd2223dd1fdf1c51e10c05c39/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LinYuLuo/MiStep/cf966f30e256384dd2223dd1fdf1c51e10c05c39/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LinYuLuo/MiStep/cf966f30e256384dd2223dd1fdf1c51e10c05c39/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LinYuLuo/MiStep/cf966f30e256384dd2223dd1fdf1c51e10c05c39/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LinYuLuo/MiStep/cf966f30e256384dd2223dd1fdf1c51e10c05c39/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LinYuLuo/MiStep/cf966f30e256384dd2223dd1fdf1c51e10c05c39/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | #3F51B5 7 | #303F9F 8 | #FF4081 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 小米步数管理 3 | 自动修改说明:\n\t\t建议使用定时修改,免去每天手动打开软件,步数将在点击修改时进行保存。\n\n模式说明:\n\t\t核心破解:一般仅适用于已被核心破解的系统上,官改ROM大部分自带核心破解。\n\t\tROOT:需要ROOT权限,可以兼容极大部分机型。如果您不知道ROOT是什么,建议在了解ROOT的危害后再考虑是否进行ROOT。\n\t\t通过长按修改步数按钮可以切换运行模式。\n\n开发者信息:\n\t\tAuthor:XyLin\n\t\tEmail:android.xylin@foxmail.com\n\t\t该软件仅供个人娱乐使用,禁止用于商业以及其它非法用途,如有侵权或其它问题请通过邮件联系。 4 | 修改步数 5 | 定时运行 6 | 初次打开 7 | 自动修改(每天): 8 | 增加步数 9 | 指定步数 10 | 修改方式: 11 | 步数变量: 12 | 请输入步数 13 | 您输入的步数有误,请修改后重试。 14 | 请输入步数变量后再点击修改。 15 | 提示 16 | 检测到设备可能禁用/卸载了“电量与性能”或“Joyose”APP,修改步数功能可能无法正常使用。\n\n如果系统可以正常记录步数则表明这是误报,反之则代表您需要启用/安装这两个应用才能修改步数,否则步数将一直为0。\n\n可使用“一键启用”按钮启用这两个APP,但该操作需要ROOT权限。 17 | 一键启用 18 | 不再提醒 19 | 确定 20 | 一键启用成功,请尝试修改步数。 21 | 一键启用失败,可能无法修改步数。 22 | 修改后通知修改结果 23 | 请指定时间 24 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 15 | 16 | 17 | --------------------------------------------------------------------------------