├── .gitignore ├── LICENSE.txt ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── github │ │ └── hellocsl │ │ └── smartmonitor │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── github │ │ │ └── hellocsl │ │ │ └── smartmonitor │ │ │ ├── AppApplication.java │ │ │ ├── VideoAccessibilityService.java │ │ │ ├── base │ │ │ └── BaseApp.java │ │ │ ├── receiver │ │ │ └── BootCompletedReceiver.java │ │ │ ├── state │ │ │ ├── IMonitorService.java │ │ │ ├── Impl │ │ │ │ ├── EndingSate.java │ │ │ │ ├── IdleState.java │ │ │ │ ├── QQChatState.java │ │ │ │ └── StartVideoState.java │ │ │ └── MonitorState.java │ │ │ ├── ui │ │ │ ├── MainActivity.java │ │ │ └── widget │ │ │ │ └── SettingItem.java │ │ │ └── utils │ │ │ ├── AppUtils.java │ │ │ ├── Constant.java │ │ │ ├── RootCmd.java │ │ │ ├── SdUtils.java │ │ │ ├── TelephoneHelper.java │ │ │ └── UnLockUtils.java │ └── res │ │ ├── layout │ │ ├── activity_main.xml │ │ └── widget_setting_item.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ ├── values │ │ ├── attrs.xml │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ │ └── xml │ │ └── accessible_service_config.xml │ └── test │ └── java │ └── github │ └── hellocsl │ └── smartmonitor │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── screenshot └── Monitor.gif ├── script └── MonitorUnlock.txt └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/ 5 | .DS_Store 6 | /build 7 | /captures 8 | .externalNativeBuild 9 | 10 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 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 2014 Luke Deighton 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. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WaterMonitor 2 | 3 | 使用系统的辅助权限功能来实现~~监控电话打入~~监听特定QQ联系人的命令,自动解锁屏幕(如果有的话),打开QQ特定的联系人并打开视频功能,主要目的是为了满足自己上班有时候监控下家里的🐶子有没有拆家 4 | 5 | 详情请见[简书](http://www.jianshu.com/p/d91e2e015718) 6 | 7 | ## 编译和运行 8 | 9 | - 0.Server端手机登录QQ,用于监控,Client端的QQ添加Server端的QQ为好友,并在Server端的QQ面板中修改Client端的QQ账号备注格式为`WaterMonitor:Client端QQ`,例如QQ号码是`123456`,那么备注改成`WaterMonitor:12345`,那么当Client发送命令`1`到Server端,Server将会打开和QQ号码12345的视频电话,支持多个不同的Client 10 | 11 | - 1.`import github.hellocsl.smartmonitor.utils.Privacy;`这个没类只是再记录了自己默认的QQ帐号的常量,所以没上传,可以自己新建一个 12 | 13 | - 2.解锁脚本需要自己重新配置(如何配置?见**Root和屏幕解锁**),不同手机解锁方式和密码不一样,命名为**MonitorUnlock.txt**,并放到Sd卡根目录,以`quit`行为结尾 14 | 15 | ## 实现 16 | 17 | 辅助服务,当在锁屏或者非QQ面板的时候,分别监听`AccessibilityEvent#TYPE_WINDOW_CONTENT_CHANGED`和`AccessibilityEvent#TYPE_NOTIFICATION_STATE_CHANGED`事件可以读取到QQ的新消息,根据目标联系人和命令的解析,就可以作出相应的操作 18 | 19 | ### Root和屏幕解锁 20 | 21 | 需要Root权限,因为需要进行屏幕解锁,而使用辅助权限也很难达到目的,主要使用到`adb input`命令来模拟滑动和点击,[详情看这里](http://doc.okbase.net/travellife/archive/113675.html) 22 | 23 | 不同的手机的屏幕解锁密码或者方式不一样,所以需要自己来写脚本,脚本名字为**MonitorUnlock.txt**并放到Sd卡根目录,以`quit`行为结尾,[参考我的](https://github.com/BCsl/WaterMonitor/blob/master/script/MonitorUnlock.txt) 24 | 25 | **了解更多请见[简书](http://www.jianshu.com/p/d91e2e015718)** 26 | 27 | ## 效果 28 | 29 | ![动图](http://diycode.b0.upaiyun.com/photo/2016/51eac4f28e9f56db06147ee9e03362e7.gif) 30 | 31 | ![装置](http://diycode.b0.upaiyun.com/photo/2016/d5e267d159cee2c56979a362a4b9842f.png) 32 | 33 | ![监听](http://diycode.b0.upaiyun.com/photo/2016/243a7f8d06d9f7b6558fd6c80e21901d.png) 34 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'android-apt' 3 | 4 | android { 5 | compileSdkVersion 23 6 | buildToolsVersion "23.0.3" 7 | defaultConfig { 8 | applicationId "github.hellocsl.smartmonitor" 9 | minSdkVersion 18 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 14 | } 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | } 22 | 23 | dependencies { 24 | compile fileTree(dir: 'libs', include: ['*.jar']) 25 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 26 | exclude group: 'com.android.support', module: 'support-annotations' 27 | }) 28 | compile 'com.android.support:appcompat-v7:23.2.1' 29 | testCompile 'junit:junit:4.12' 30 | 31 | compile 'com.jakewharton:butterknife:8.4.0' 32 | apt 'com.jakewharton:butterknife-compiler:8.4.0' 33 | } 34 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /home/chensuilun/Android/Sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/github/hellocsl/smartmonitor/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package github.hellocsl.smartmonitor; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * @see Testing documentation 15 | */ 16 | @RunWith(AndroidJUnit4.class) 17 | public class ExampleInstrumentedTest { 18 | @Test 19 | public void useAppContext() throws Exception { 20 | // Context of the app under test. 21 | Context appContext = InstrumentationRegistry.getTargetContext(); 22 | 23 | assertEquals("github.hellocsl.smartmonitor", appContext.getPackageName()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 34 | 35 | 36 | 37 | 40 | 41 | 42 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /app/src/main/java/github/hellocsl/smartmonitor/AppApplication.java: -------------------------------------------------------------------------------- 1 | package github.hellocsl.smartmonitor; 2 | 3 | import android.content.Context; 4 | 5 | import github.hellocsl.smartmonitor.base.BaseApp; 6 | 7 | /** 8 | * Created by chensuilun on 16-10-8. 9 | */ 10 | public class AppApplication extends BaseApp { 11 | 12 | public static Context sAppContext; 13 | 14 | @Override 15 | public void onCreate() { 16 | super.onCreate(); 17 | sAppContext = this; 18 | } 19 | 20 | public static Context getContext() { 21 | return sAppContext; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/src/main/java/github/hellocsl/smartmonitor/VideoAccessibilityService.java: -------------------------------------------------------------------------------- 1 | package github.hellocsl.smartmonitor; 2 | 3 | 4 | import android.accessibilityservice.AccessibilityService; 5 | import android.accessibilityservice.AccessibilityServiceInfo; 6 | import android.content.BroadcastReceiver; 7 | import android.content.Context; 8 | import android.content.Intent; 9 | import android.content.IntentFilter; 10 | import android.util.Log; 11 | import android.view.accessibility.AccessibilityEvent; 12 | import android.view.accessibility.AccessibilityNodeInfo; 13 | 14 | import github.hellocsl.smartmonitor.state.IMonitorService; 15 | import github.hellocsl.smartmonitor.state.Impl.IdleState; 16 | import github.hellocsl.smartmonitor.state.MonitorState; 17 | import github.hellocsl.smartmonitor.utils.Constant; 18 | 19 | import static android.view.accessibility.AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED; 20 | import static android.view.accessibility.AccessibilityEvent.TYPE_WINDOWS_CHANGED; 21 | import static android.view.accessibility.AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED; 22 | import static android.view.accessibility.AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED; 23 | 24 | 25 | /** 26 | * Created by chensuilun on 16-10-8. 27 | */ 28 | public class VideoAccessibilityService extends AccessibilityService implements IMonitorService { 29 | private static final String TAG = "VideoAccessibilityServi"; 30 | public static boolean sIsEnable = false; 31 | 32 | private MonitorState mCurState; 33 | 34 | @Override 35 | public void setState(MonitorState state) { 36 | mCurState = state; 37 | } 38 | 39 | 40 | @Override 41 | protected void onServiceConnected() { 42 | super.onServiceConnected(); 43 | registerScreenReceiver(); 44 | if (BuildConfig.DEBUG) { 45 | Log.d(TAG, "onServiceConnected: "); 46 | } 47 | sIsEnable = true; 48 | AccessibilityServiceInfo info = new AccessibilityServiceInfo(); 49 | info.eventTypes = TYPE_WINDOW_CONTENT_CHANGED | TYPE_WINDOWS_CHANGED | TYPE_WINDOW_STATE_CHANGED | TYPE_NOTIFICATION_STATE_CHANGED; 50 | 51 | // If you only want this service to work with specific applications, set their 52 | // package names here. Otherwise, when the service is activated, it will listen 53 | // to events from all applications. 54 | info.packageNames = new String[]{Constant.QQ_PKG}; 55 | 56 | info.feedbackType = AccessibilityServiceInfo.FEEDBACK_SPOKEN; 57 | // info.flags = AccessibilityServiceInfo.DEFAULT; 58 | info.notificationTimeout = 100; 59 | 60 | this.setServiceInfo(info); 61 | setState(new IdleState(this)); 62 | } 63 | 64 | @Override 65 | public boolean onUnbind(Intent intent) { 66 | if (BuildConfig.DEBUG) { 67 | Log.d(TAG, "onUnbind: "); 68 | } 69 | unRegisterScreenReceiver(); 70 | sIsEnable = false; 71 | return super.onUnbind(intent); 72 | } 73 | 74 | @Override 75 | public void onAccessibilityEvent(AccessibilityEvent accessibilityEvent) { 76 | if (BuildConfig.DEBUG) { 77 | Log.v(TAG, "onAccessibilityEvent: event:" + accessibilityEvent.getEventType()); 78 | } 79 | if (mCurState != null) { 80 | mCurState.handle(accessibilityEvent); 81 | } 82 | } 83 | 84 | 85 | @Override 86 | public void onInterrupt() { 87 | if (BuildConfig.DEBUG) { 88 | Log.d(TAG, "onInterrupt: "); 89 | } 90 | } 91 | 92 | 93 | @Override 94 | public AccessibilityNodeInfo getWindowNode() { 95 | return getRootInActiveWindow(); 96 | } 97 | 98 | 99 | private ScreenReceiver mScreenReceiver; 100 | 101 | private void registerScreenReceiver() { 102 | if (mScreenReceiver == null) { 103 | mScreenReceiver = new ScreenReceiver(); 104 | IntentFilter intentFilter = new IntentFilter(); 105 | intentFilter.addAction(Intent.ACTION_SCREEN_OFF); 106 | registerReceiver(mScreenReceiver, intentFilter); 107 | } 108 | } 109 | 110 | private void unRegisterScreenReceiver() { 111 | if (mScreenReceiver != null) { 112 | unregisterReceiver(mScreenReceiver); 113 | } 114 | } 115 | 116 | /** 117 | * @author chensuilun 118 | */ 119 | public class ScreenReceiver extends BroadcastReceiver { 120 | 121 | @Override 122 | public void onReceive(Context context, Intent intent) { 123 | switch (intent.getAction()) { 124 | case Intent.ACTION_SCREEN_OFF: 125 | if (BuildConfig.DEBUG) { 126 | Log.d(TAG, "onReceive: Screen off"); 127 | } 128 | setState(new IdleState(VideoAccessibilityService.this)); 129 | break; 130 | default: 131 | break; 132 | } 133 | } 134 | } 135 | 136 | } 137 | -------------------------------------------------------------------------------- /app/src/main/java/github/hellocsl/smartmonitor/base/BaseApp.java: -------------------------------------------------------------------------------- 1 | package github.hellocsl.smartmonitor.base; 2 | 3 | import android.app.Application; 4 | import android.os.Handler; 5 | import android.os.HandlerThread; 6 | import android.os.Looper; 7 | 8 | /** 9 | * Created by chensuilun on 16-10-8. 10 | */ 11 | public class BaseApp extends Application { 12 | 13 | private static HandlerThread sWorkerThread = new HandlerThread("worker-main"); 14 | 15 | static { 16 | sWorkerThread.start(); 17 | } 18 | 19 | private static Handler sWorker = new Handler(sWorkerThread.getLooper()); 20 | 21 | private static Handler sHandler = new Handler(Looper.getMainLooper()); 22 | 23 | 24 | /** 25 | * 向线程发送数据 26 | * @param r runnable 对象 27 | */ 28 | public static void postThread(Runnable r) { 29 | sWorker.post(r); 30 | } 31 | 32 | /** 33 | * 向线程发送数据 34 | * @param r runnable 对象 35 | */ 36 | public static void removeThread(Runnable r) { 37 | sWorker.removeCallbacks(r); 38 | } 39 | 40 | public static void postThreadDelayed(Runnable r, long delayMillis) { 41 | sWorker.postDelayed(r, delayMillis); 42 | } 43 | 44 | /** 45 | * 向主线程发送任务 46 | * @param runnable 47 | */ 48 | public static void post(Runnable runnable) { 49 | sHandler.post(runnable); 50 | } 51 | 52 | /** 53 | * 主线程 54 | * @param runnable 55 | */ 56 | public static void remove(Runnable runnable) { 57 | sHandler.removeCallbacks(runnable); 58 | } 59 | 60 | /** 61 | * 主线程 62 | * @param runnable 63 | * @param delay 64 | */ 65 | public static void postDelay(Runnable runnable, long delay) { 66 | sHandler.postDelayed(runnable, delay); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /app/src/main/java/github/hellocsl/smartmonitor/receiver/BootCompletedReceiver.java: -------------------------------------------------------------------------------- 1 | package github.hellocsl.smartmonitor.receiver; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.support.v4.content.WakefulBroadcastReceiver; 6 | 7 | /** 8 | * Created by chensuilun on 16/10/14. 9 | */ 10 | 11 | public class BootCompletedReceiver extends WakefulBroadcastReceiver { 12 | @Override 13 | public void onReceive(Context context, Intent intent) { 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /app/src/main/java/github/hellocsl/smartmonitor/state/IMonitorService.java: -------------------------------------------------------------------------------- 1 | package github.hellocsl.smartmonitor.state; 2 | 3 | import android.accessibilityservice.AccessibilityService; 4 | import android.view.accessibility.AccessibilityNodeInfo; 5 | 6 | /** 7 | * Created by chensuilun on 16-10-9. 8 | */ 9 | public interface IMonitorService { 10 | 11 | void setState(MonitorState state); 12 | 13 | /** 14 | * @see AccessibilityService#getRootInActiveWindow() 15 | * @return The root node if this service can retrieve window content. 16 | */ 17 | AccessibilityNodeInfo getWindowNode(); 18 | } 19 | -------------------------------------------------------------------------------- /app/src/main/java/github/hellocsl/smartmonitor/state/Impl/EndingSate.java: -------------------------------------------------------------------------------- 1 | package github.hellocsl.smartmonitor.state.Impl; 2 | 3 | import android.util.Log; 4 | import android.view.KeyEvent; 5 | import android.view.accessibility.AccessibilityEvent; 6 | import android.view.accessibility.AccessibilityNodeInfo; 7 | import android.widget.RelativeLayout; 8 | 9 | import java.util.List; 10 | 11 | import github.hellocsl.smartmonitor.BuildConfig; 12 | import github.hellocsl.smartmonitor.state.IMonitorService; 13 | import github.hellocsl.smartmonitor.state.MonitorState; 14 | import github.hellocsl.smartmonitor.utils.AppUtils; 15 | import github.hellocsl.smartmonitor.utils.Constant; 16 | import github.hellocsl.smartmonitor.utils.RootCmd; 17 | 18 | /** 19 | * Created by chensuilun on 16/10/23. 20 | */ 21 | 22 | public class EndingSate extends MonitorState { 23 | private static final String TAG = "EndingSate"; 24 | 25 | public EndingSate(IMonitorService contextService) { 26 | super(contextService); 27 | } 28 | 29 | @Override 30 | public void handle(AccessibilityEvent accessibilityEvent) { 31 | AccessibilityNodeInfo nodeInfo = mContextService.getWindowNode(); 32 | if (nodeInfo == null) { 33 | if (BuildConfig.DEBUG) { 34 | Log.v(TAG, "handle: null nodeInfo"); 35 | } 36 | return; 37 | } 38 | if (BuildConfig.DEBUG) { 39 | Log.d(TAG, "handle: "); 40 | } 41 | if (isVideoChatEnded(nodeInfo, accessibilityEvent)) { 42 | if (!AppUtils.isInLockScreen()) { 43 | if (BuildConfig.DEBUG) { 44 | Log.d(TAG, "handle: close screen"); 45 | } 46 | //熄屏,等待下次命令 47 | RootCmd.execRootCmd("sleep 0.1 && input keyevent " + KeyEvent.KEYCODE_POWER); 48 | } 49 | mContextService.setState(new IdleState(mContextService)); 50 | } 51 | } 52 | 53 | /** 54 | * @param nodeInfo 55 | * @param accessibilityEvent 56 | * @return 消息列表的最后一个Item是否为视频通话结束或取消 57 | */ 58 | private boolean isVideoChatEnded(AccessibilityNodeInfo nodeInfo, AccessibilityEvent accessibilityEvent) { 59 | String pkg = accessibilityEvent.getPackageName().toString(); 60 | List listNode = nodeInfo.findAccessibilityNodeInfosByViewId("com.tencent.mobileqq:id/listView1"); 61 | AccessibilityNodeInfo tempNode = null; 62 | try { 63 | if (Constant.QQ_PKG.equals(pkg)) { 64 | if (!AppUtils.isListEmpty(listNode)) { 65 | tempNode = listNode.get(0); 66 | tempNode = tempNode.getChild(tempNode.getChildCount() - 1); 67 | if (tempNode != null && tempNode.getClassName().equals(RelativeLayout.class.getName())) { 68 | return !AppUtils.isListEmpty(tempNode.findAccessibilityNodeInfosByText("拒绝")) 69 | || !AppUtils.isListEmpty(tempNode.findAccessibilityNodeInfosByText("通话时长")) 70 | || !AppUtils.isListEmpty(tempNode.findAccessibilityNodeInfosByText("取消")); 71 | } 72 | } 73 | } 74 | } finally { 75 | if (tempNode != null) { 76 | tempNode.recycle(); 77 | } 78 | } 79 | return false; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /app/src/main/java/github/hellocsl/smartmonitor/state/Impl/IdleState.java: -------------------------------------------------------------------------------- 1 | package github.hellocsl.smartmonitor.state.Impl; 2 | 3 | import android.app.Notification; 4 | import android.os.Parcelable; 5 | import android.text.TextUtils; 6 | import android.util.Log; 7 | import android.view.KeyEvent; 8 | import android.view.accessibility.AccessibilityEvent; 9 | import android.view.accessibility.AccessibilityNodeInfo; 10 | 11 | import java.util.List; 12 | 13 | import github.hellocsl.smartmonitor.AppApplication; 14 | import github.hellocsl.smartmonitor.BuildConfig; 15 | import github.hellocsl.smartmonitor.state.IMonitorService; 16 | import github.hellocsl.smartmonitor.state.MonitorState; 17 | import github.hellocsl.smartmonitor.utils.AppUtils; 18 | import github.hellocsl.smartmonitor.utils.Constant; 19 | import github.hellocsl.smartmonitor.utils.Privacy; 20 | import github.hellocsl.smartmonitor.utils.RootCmd; 21 | import github.hellocsl.smartmonitor.utils.UnLockUtils; 22 | 23 | import static android.view.accessibility.AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED; 24 | import static android.view.accessibility.AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED; 25 | import static github.hellocsl.smartmonitor.utils.Constant.MONITOR_TAG; 26 | 27 | /** 28 | * 初始状态,等待来电处理 29 | * change to monitor QQ new message (LockScreen, Notification , QQ App) 30 | * Created by chensuilun on 16-10-9. 31 | */ 32 | public class IdleState extends MonitorState { 33 | private static final String TAG = "IdleState"; 34 | 35 | public IdleState(IMonitorService contextService) { 36 | super(contextService); 37 | } 38 | 39 | @Override 40 | public void handle(AccessibilityEvent accessibilityEvent) { 41 | AccessibilityNodeInfo nodeInfo = mContextService.getWindowNode(); 42 | if (nodeInfo == null) { 43 | if (BuildConfig.DEBUG) { 44 | Log.v(TAG, "handle: null nodeInfo"); 45 | } 46 | return; 47 | } 48 | if (BuildConfig.DEBUG) { 49 | Log.v(TAG, "handle:"); 50 | } 51 | if (isLockScreenMonitorMsg(nodeInfo, accessibilityEvent) || isNotificationMonitorMsg(nodeInfo, accessibilityEvent)) { 52 | if (BuildConfig.DEBUG) { 53 | Log.d(TAG, "handle: monitor msg"); 54 | } 55 | if (AppUtils.isInLockScreen()) { 56 | if (BuildConfig.DEBUG) { 57 | Log.d(TAG, "handle: unlock screen"); 58 | } 59 | //back press 60 | RootCmd.execRootCmd("input keyevent " + KeyEvent.KEYCODE_BACK); 61 | RootCmd.execRootCmd("sleep 0.1 && input keyevent " + KeyEvent.KEYCODE_HOME); 62 | unlockScreen(nodeInfo); 63 | } 64 | final String qqNumber = retrieveQQNumber(nodeInfo, accessibilityEvent); 65 | mContextService.setState(new QQChatState(mContextService)); 66 | AppApplication.postDelay(new Runnable() { 67 | @Override 68 | public void run() { 69 | AppUtils.openQQChat(qqNumber); 70 | } 71 | }, 1000); 72 | } 73 | } 74 | 75 | /** 76 | * retract monitor cmd from notification 77 | * 78 | * @param nodeInfo 79 | * @param accessibilityEvent 80 | * @return 81 | */ 82 | private boolean isNotificationMonitorMsg(AccessibilityNodeInfo nodeInfo, AccessibilityEvent accessibilityEvent) { 83 | if (accessibilityEvent.getEventType() == TYPE_NOTIFICATION_STATE_CHANGED) { 84 | if (BuildConfig.DEBUG) { 85 | Log.d(TAG, "isNotificationMonitorMsg: "); 86 | } 87 | Parcelable data = accessibilityEvent.getParcelableData(); 88 | if (data instanceof Notification) { 89 | if (((Notification) data).tickerText != null) { 90 | return (((Notification) data).tickerText.toString().startsWith(MONITOR_TAG) 91 | && ((Notification) data).tickerText.toString().endsWith(Constant.MONITOR_CMD_VIDEO)); 92 | } 93 | } 94 | } 95 | return false; 96 | } 97 | 98 | /** 99 | * @param nodeInfo 100 | * @param accessibilityEvent 101 | * @return If from notification ,msg format :{@link Constant#MONITOR_TAG} + ":real QQ No: "+{@link Constant#MONITOR_CMD_VIDEO} 102 | */ 103 | private String retrieveQQNumber(AccessibilityNodeInfo nodeInfo, AccessibilityEvent accessibilityEvent) { 104 | if (accessibilityEvent.getEventType() == TYPE_NOTIFICATION_STATE_CHANGED) { 105 | Parcelable data = accessibilityEvent.getParcelableData(); 106 | if (data instanceof Notification) { 107 | if (((Notification) data).tickerText != null) { 108 | return ((Notification) data).tickerText.toString().split(":")[1]; 109 | } 110 | } 111 | } else { 112 | List nodeInfos = nodeInfo.findAccessibilityNodeInfosByText(MONITOR_TAG); 113 | if (!AppUtils.isListEmpty(nodeInfos)) { 114 | String tag; 115 | for (AccessibilityNodeInfo info : nodeInfos) { 116 | if (BuildConfig.DEBUG) { 117 | Log.d(TAG, "retrieveQQNumber: " + info.getText()); 118 | } 119 | tag = (String) info.getText(); 120 | if (!TextUtils.isEmpty(tag) && tag.contains(MONITOR_TAG)) { 121 | return tag.substring(Constant.MONITOR_TAG.length()); 122 | } 123 | } 124 | } 125 | } 126 | return Privacy.QQ_NUMBER; 127 | } 128 | 129 | /** 130 | * receive monitor cmd in LockScreen 131 | * 132 | * @param nodeInfo 133 | * @param accessibilityEvent 134 | * @return 135 | */ 136 | private boolean isLockScreenMonitorMsg(AccessibilityNodeInfo nodeInfo, AccessibilityEvent accessibilityEvent) { 137 | if (BuildConfig.DEBUG) { 138 | Log.d(TAG, "isMonitorMsg: pkg:" + nodeInfo.getPackageName()); 139 | } 140 | if (AppUtils.isInLockScreen() && Constant.QQ_PKG.equals(nodeInfo.getPackageName()) && TYPE_WINDOW_CONTENT_CHANGED == accessibilityEvent.getEventType()) { 141 | if (!AppUtils.isListEmpty(nodeInfo.findAccessibilityNodeInfosByText(MONITOR_TAG)) 142 | && !AppUtils.isListEmpty(nodeInfo.findAccessibilityNodeInfosByText(Constant.MONITOR_CMD_VIDEO))) { 143 | return true; 144 | } 145 | } 146 | return false; 147 | } 148 | 149 | 150 | /** 151 | * 解锁魅族 152 | * 153 | * @param nodeInfo 154 | */ 155 | private void unlockScreen(AccessibilityNodeInfo nodeInfo) { 156 | UnLockUtils.unlock(); 157 | } 158 | 159 | 160 | } 161 | -------------------------------------------------------------------------------- /app/src/main/java/github/hellocsl/smartmonitor/state/Impl/QQChatState.java: -------------------------------------------------------------------------------- 1 | package github.hellocsl.smartmonitor.state.Impl; 2 | 3 | import android.util.Log; 4 | import android.view.accessibility.AccessibilityEvent; 5 | import android.view.accessibility.AccessibilityNodeInfo; 6 | import android.widget.ImageView; 7 | 8 | import java.util.List; 9 | 10 | import github.hellocsl.smartmonitor.BuildConfig; 11 | import github.hellocsl.smartmonitor.state.IMonitorService; 12 | import github.hellocsl.smartmonitor.state.MonitorState; 13 | import github.hellocsl.smartmonitor.utils.AppUtils; 14 | import github.hellocsl.smartmonitor.utils.Constant; 15 | 16 | 17 | /** 18 | * QQ聊天面板状态,监测到+号并点击 19 | * Created by chensuilun on 16-10-9. 20 | */ 21 | public class QQChatState extends MonitorState { 22 | private static final String TAG = "QQChatState"; 23 | 24 | public QQChatState(IMonitorService contextService) { 25 | super(contextService); 26 | } 27 | 28 | @Override 29 | public void handle(AccessibilityEvent accessibilityEvent) { 30 | AccessibilityNodeInfo nodeInfo = mContextService.getWindowNode(); 31 | if (nodeInfo == null) { 32 | if (BuildConfig.DEBUG) { 33 | Log.v(TAG, "handle: null nodeInfo"); 34 | } 35 | return; 36 | } 37 | if (BuildConfig.DEBUG) { 38 | Log.v(TAG, "handle:"); 39 | } 40 | if (isQQChat(nodeInfo) && isNotVideoChat(nodeInfo)) { 41 | if (!preStartVideoChat(nodeInfo)) { 42 | mContextService.setState(new IdleState(mContextService)); 43 | } else { 44 | mContextService.setState(new StartVideoState(mContextService)); 45 | } 46 | } else { 47 | // TODO: 16-10-9 自动登录等其他处理 48 | } 49 | } 50 | 51 | /** 52 | * 点击,打开视频聊天面板 53 | * 54 | * @param nodeInfo 55 | * @return 是否找到 56 | */ 57 | private boolean preStartVideoChat(AccessibilityNodeInfo nodeInfo) { 58 | //并不能直接通过ID或者Text找到+号按钮,应该是动态添加的,先找到输入库,通过输入框找到相同的parent,+号的Index在倒数第二的位置上 59 | List inputNodes = nodeInfo.findAccessibilityNodeInfosByViewId("com.tencent.mobileqq:id/inputBar"); 60 | if (!AppUtils.isListEmpty(inputNodes)) { 61 | AccessibilityNodeInfo node = inputNodes.get(0).getParent(); 62 | node = node.getChild(Math.max(0, node.getChildCount() - 2)); 63 | if (node.getClassName().toString().contains(ImageView.class.getName())) { 64 | node.performAction(AccessibilityNodeInfo.ACTION_CLICK); 65 | return true; 66 | } 67 | } 68 | return false; 69 | } 70 | 71 | /** 72 | * @param nodeInfo 73 | * @return 74 | */ 75 | private boolean isQQChat(AccessibilityNodeInfo nodeInfo) { 76 | List sendNodes = nodeInfo.findAccessibilityNodeInfosByText("发送"); 77 | if (!sendNodes.isEmpty() && Constant.QQ_PKG.equals(nodeInfo.getPackageName().toString())) { 78 | return true; 79 | } 80 | return false; 81 | } 82 | 83 | /** 84 | * @param nodeInfo 85 | * @return 86 | */ 87 | private boolean isNotVideoChat(AccessibilityNodeInfo nodeInfo) { 88 | // TODO: 16-10-8 89 | return true; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /app/src/main/java/github/hellocsl/smartmonitor/state/Impl/StartVideoState.java: -------------------------------------------------------------------------------- 1 | package github.hellocsl.smartmonitor.state.Impl; 2 | 3 | import android.util.Log; 4 | import android.view.accessibility.AccessibilityEvent; 5 | import android.view.accessibility.AccessibilityNodeInfo; 6 | import android.widget.RelativeLayout; 7 | 8 | import java.util.List; 9 | 10 | import github.hellocsl.smartmonitor.BuildConfig; 11 | import github.hellocsl.smartmonitor.state.IMonitorService; 12 | import github.hellocsl.smartmonitor.state.MonitorState; 13 | 14 | import static github.hellocsl.smartmonitor.utils.AppUtils.isListEmpty; 15 | 16 | /** 17 | * 视频聊天状态,找到视频电话按钮并点击 18 | * Created by chensuilun on 16-10-9. 19 | */ 20 | public class StartVideoState extends MonitorState { 21 | private static final String TAG = "StartVideoState"; 22 | 23 | public StartVideoState(IMonitorService contextService) { 24 | super(contextService); 25 | } 26 | 27 | @Override 28 | public void handle(AccessibilityEvent accessibilityEvent) { 29 | AccessibilityNodeInfo nodeInfo = mContextService.getWindowNode(); 30 | if (nodeInfo == null) { 31 | if (BuildConfig.DEBUG) { 32 | Log.v(TAG, "handle: null nodeInfo"); 33 | } 34 | return; 35 | } 36 | if (BuildConfig.DEBUG) { 37 | Log.v(TAG, "handle:"); 38 | } 39 | if (startVideoChat(nodeInfo)) { 40 | if (BuildConfig.DEBUG) { 41 | Log.d(TAG, "handle: start suc"); 42 | } 43 | mContextService.setState(new EndingSate(mContextService)); 44 | } else { 45 | mContextService.setState(new QQChatState(mContextService)); 46 | } 47 | } 48 | 49 | /** 50 | * 点击视频聊天按钮 51 | * @param nodeInfo 52 | * @return 是否成功 53 | */ 54 | private boolean startVideoChat(AccessibilityNodeInfo nodeInfo) { 55 | List videoTextNodes = nodeInfo.findAccessibilityNodeInfosByText("视频电话"); 56 | if (!isListEmpty(videoTextNodes)) { 57 | for (AccessibilityNodeInfo textNode : videoTextNodes) { 58 | if (textNode.getClassName().toString().contains(RelativeLayout.class.getName())) { //contextDesc 59 | textNode.performAction(AccessibilityNodeInfo.ACTION_CLICK); 60 | return true; 61 | } 62 | } 63 | } 64 | return false; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /app/src/main/java/github/hellocsl/smartmonitor/state/MonitorState.java: -------------------------------------------------------------------------------- 1 | package github.hellocsl.smartmonitor.state; 2 | 3 | import android.view.accessibility.AccessibilityEvent; 4 | 5 | /** 6 | * Created by chensuilun on 16-10-9. 7 | */ 8 | public abstract class MonitorState { 9 | protected IMonitorService mContextService; 10 | 11 | public MonitorState(IMonitorService contextService) { 12 | mContextService = contextService; 13 | } 14 | 15 | public abstract void handle(AccessibilityEvent accessibilityEvent); 16 | } 17 | -------------------------------------------------------------------------------- /app/src/main/java/github/hellocsl/smartmonitor/ui/MainActivity.java: -------------------------------------------------------------------------------- 1 | package github.hellocsl.smartmonitor.ui; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.util.Log; 6 | import android.widget.Toast; 7 | 8 | import butterknife.BindView; 9 | import butterknife.ButterKnife; 10 | import butterknife.OnClick; 11 | import github.hellocsl.smartmonitor.AppApplication; 12 | import github.hellocsl.smartmonitor.BuildConfig; 13 | import github.hellocsl.smartmonitor.R; 14 | import github.hellocsl.smartmonitor.ui.widget.SettingItem; 15 | import github.hellocsl.smartmonitor.utils.AppUtils; 16 | import github.hellocsl.smartmonitor.utils.Constant; 17 | import github.hellocsl.smartmonitor.utils.RootCmd; 18 | 19 | public class MainActivity extends AppCompatActivity { 20 | private static final String TAG = "MainActivity"; 21 | @BindView(R.id.setting_start_service) 22 | SettingItem mSettingService; 23 | @BindView(R.id.setting_root) 24 | SettingItem mSettingRoot; 25 | 26 | @Override 27 | protected void onCreate(Bundle savedInstanceState) { 28 | super.onCreate(savedInstanceState); 29 | setContentView(R.layout.activity_main); 30 | ButterKnife.bind(this); 31 | if (!AppUtils.isRooted()) { 32 | Toast.makeText(AppApplication.getContext(), R.string.can_not_run_without_root, Toast.LENGTH_SHORT).show(); 33 | finish(); 34 | } 35 | mSettingRoot.setCheck(RootCmd.haveRoot()); 36 | } 37 | 38 | private boolean mProtected; 39 | 40 | @Override 41 | protected void onResume() { 42 | super.onResume(); 43 | if (BuildConfig.DEBUG) { 44 | Log.d(TAG, "onResume: "); 45 | } 46 | mSettingRoot.setCheck(RootCmd.sHaveRoot); 47 | mSettingService.setCheck(AppUtils.checkAccessibility(Constant.ACCESSIBILITY_SERVICE)); 48 | 49 | } 50 | 51 | @OnClick(R.id.setting_start_service) 52 | public void onClickService() { 53 | boolean pending = !mSettingService.isCheck(); 54 | AppUtils.gotoAccessibilitySettings(this); 55 | mSettingService.setCheck(pending); 56 | } 57 | 58 | @OnClick(R.id.setting_root) 59 | public void onClickRoot() { 60 | if (!mSettingRoot.isCheck()) { 61 | mSettingRoot.setCheck(RootCmd.haveRoot()); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /app/src/main/java/github/hellocsl/smartmonitor/ui/widget/SettingItem.java: -------------------------------------------------------------------------------- 1 | package github.hellocsl.smartmonitor.ui.widget; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.Context; 5 | import android.content.res.TypedArray; 6 | import android.graphics.drawable.Drawable; 7 | import android.os.Build; 8 | import android.support.v7.widget.AppCompatCheckBox; 9 | import android.util.AttributeSet; 10 | import android.view.View; 11 | import android.widget.ImageView; 12 | import android.widget.RelativeLayout; 13 | import android.widget.TextView; 14 | 15 | import butterknife.BindView; 16 | import butterknife.ButterKnife; 17 | import github.hellocsl.smartmonitor.R; 18 | 19 | /** 20 | * Created by chensuilun on 16-10-20. 21 | */ 22 | 23 | public class SettingItem extends RelativeLayout { 24 | public static final int STYLE_CHECK = 0; 25 | @BindView(R.id.setting_iv) 26 | ImageView mSettingIv; 27 | @BindView(R.id.setting_checkbox) 28 | AppCompatCheckBox mSettingCheckbox; 29 | @BindView(R.id.setting_title) 30 | TextView mSettingTitle; 31 | @BindView(R.id.setting_desc) 32 | TextView mSettingDesc; 33 | 34 | public SettingItem(Context context) { 35 | super(context); 36 | init(context, null); 37 | } 38 | 39 | public SettingItem(Context context, AttributeSet attrs) { 40 | super(context, attrs); 41 | init(context, attrs); 42 | } 43 | 44 | public SettingItem(Context context, AttributeSet attrs, int defStyleAttr) { 45 | super(context, attrs, defStyleAttr); 46 | init(context, attrs); 47 | } 48 | 49 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 50 | public SettingItem(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 51 | super(context, attrs, defStyleAttr, defStyleRes); 52 | init(context, attrs); 53 | } 54 | 55 | private void init(Context context, AttributeSet attrs) { 56 | inflate(getContext(), R.layout.widget_setting_item, this); 57 | ButterKnife.bind(this); 58 | if (attrs != null) { 59 | TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SettingItem); 60 | boolean isCheck = ta.getBoolean(R.styleable.SettingItem_check, false); 61 | int titleId = ta.getResourceId(R.styleable.SettingItem_settingTitle, -1); 62 | int descId = ta.getResourceId(R.styleable.SettingItem_settingDesc, -1); 63 | Drawable icon = ta.getDrawable(R.styleable.SettingItem_settingIcon); 64 | int style = ta.getInt(R.styleable.SettingItem_style, 0); 65 | if (icon == null) { 66 | mSettingIv.setVisibility(View.GONE); 67 | } else { 68 | mSettingIv.setVisibility(View.VISIBLE); 69 | mSettingIv.setImageDrawable(icon); 70 | } 71 | if (titleId == -1) { 72 | mSettingTitle.setVisibility(GONE); 73 | } else { 74 | mSettingTitle.setVisibility(VISIBLE); 75 | mSettingTitle.setText(titleId); 76 | } 77 | if (descId == -1) { 78 | mSettingDesc.setVisibility(GONE); 79 | } else { 80 | mSettingDesc.setVisibility(VISIBLE); 81 | mSettingDesc.setText(descId); 82 | } 83 | if (style == STYLE_CHECK) { 84 | mSettingCheckbox.setVisibility(View.VISIBLE); 85 | mSettingCheckbox.setChecked(isCheck); 86 | } else { 87 | mSettingCheckbox.setVisibility(GONE); 88 | } 89 | 90 | } 91 | } 92 | 93 | public void setCheck(boolean check) { 94 | if (mSettingCheckbox != null) { 95 | mSettingCheckbox.setChecked(check); 96 | } 97 | } 98 | 99 | public boolean isCheck() { 100 | if (mSettingCheckbox != null) { 101 | return mSettingCheckbox.isChecked(); 102 | } 103 | return false; 104 | } 105 | 106 | 107 | } 108 | -------------------------------------------------------------------------------- /app/src/main/java/github/hellocsl/smartmonitor/utils/AppUtils.java: -------------------------------------------------------------------------------- 1 | package github.hellocsl.smartmonitor.utils; 2 | 3 | import android.app.Activity; 4 | import android.app.KeyguardManager; 5 | import android.content.ActivityNotFoundException; 6 | import android.content.Context; 7 | import android.content.Intent; 8 | import android.net.Uri; 9 | import android.os.Build; 10 | import android.os.PowerManager; 11 | import android.provider.Settings; 12 | import android.text.TextUtils; 13 | import android.util.Log; 14 | 15 | import java.io.File; 16 | import java.util.List; 17 | 18 | import github.hellocsl.smartmonitor.AppApplication; 19 | import github.hellocsl.smartmonitor.BuildConfig; 20 | 21 | import static android.content.Context.KEYGUARD_SERVICE; 22 | import static android.os.Build.VERSION_CODES.JELLY_BEAN; 23 | import static github.hellocsl.smartmonitor.AppApplication.sAppContext; 24 | 25 | /** 26 | * Created by chensuilun on 16-10-8. 27 | */ 28 | public class AppUtils { 29 | private static final String TAG = "AppUtils"; 30 | 31 | /** 32 | * 打开QQ聊天界面 33 | * 34 | * @param qqNumber 35 | */ 36 | public static void openQQChat(String qqNumber) { 37 | if (BuildConfig.DEBUG) { 38 | Log.d(TAG, "openQQChat() called with: " + "qqNumber = [" + qqNumber + "]"); 39 | } 40 | String url = "mqqwpa://im/chat?chat_type=wpa&uin=" + qqNumber + "&version=1"; 41 | Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); 42 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 43 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); 44 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 45 | try { 46 | AppApplication.getContext().startActivity(intent); 47 | } catch (Exception e) { 48 | Log.e(TAG, "openQQChat: QQ not install!!!"); 49 | return; 50 | } 51 | } 52 | 53 | public static void acquireTimedWakeLock(long timeout, String tag) { 54 | PowerManager pm = (PowerManager) sAppContext.getSystemService(Context.POWER_SERVICE); 55 | PowerManager.WakeLock wakeLock = pm.newWakeLock(PowerManager.ON_AFTER_RELEASE | PowerManager.ACQUIRE_CAUSES_WAKEUP, tag); 56 | wakeLock.acquire(timeout); 57 | } 58 | 59 | 60 | /** 61 | * 跳转到系统辅助功能设置页面.
62 | * 63 | * @param context 64 | */ 65 | public static boolean gotoAccessibilitySettings(Context context) { 66 | Intent settingsIntent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS); 67 | if (!(context instanceof Activity)) { 68 | settingsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 69 | } 70 | boolean isOk = true; 71 | try { 72 | context.startActivity(settingsIntent); 73 | } catch (ActivityNotFoundException e) { 74 | isOk = false; 75 | } 76 | return isOk; 77 | } 78 | 79 | 80 | public static boolean isInLockScreen() { 81 | KeyguardManager keyguardManager = (KeyguardManager) AppApplication.getContext().getSystemService(KEYGUARD_SERVICE); 82 | return keyguardManager.inKeyguardRestrictedInputMode(); 83 | } 84 | 85 | /** 86 | * 是否支持使用辅助服务.
87 | * 88 | * @return 89 | */ 90 | public static boolean isSupportBoostAccessibilityService() { 91 | return Build.VERSION.SDK_INT >= JELLY_BEAN; 92 | } 93 | 94 | 95 | public static boolean isListEmpty(List list) { 96 | return list == null || list.isEmpty(); 97 | } 98 | 99 | 100 | public static boolean checkAccessibility(String service) { 101 | int ok = 0; 102 | try { 103 | ok = Settings.Secure.getInt(AppApplication.getContext().getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED); 104 | } catch (Settings.SettingNotFoundException e) { 105 | } 106 | 107 | TextUtils.SimpleStringSplitter ms = new TextUtils.SimpleStringSplitter(':'); 108 | if (ok == 1) { 109 | String settingValue = Settings.Secure.getString(AppApplication.getContext().getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES); 110 | if (settingValue != null) { 111 | ms.setString(settingValue); 112 | while (ms.hasNext()) { 113 | String accessibilityService = ms.next(); 114 | if (accessibilityService.equalsIgnoreCase(service)) { 115 | return true; 116 | } 117 | 118 | } 119 | } 120 | } 121 | return false; 122 | } 123 | 124 | //See https://github.com/Stericson/RootTools 125 | public static boolean isRooted() { 126 | return findBinary("su"); 127 | } 128 | 129 | 130 | private static boolean findBinary(String binaryName) { 131 | boolean found = false; 132 | if (!found) { 133 | String[] places = {"/sbin/", "/system/bin/", "/system/xbin/", "/data/local/xbin/", 134 | "/data/local/bin/", "/system/sd/xbin/", "/system/bin/failsafe/", "/data/local/"}; 135 | for (String where : places) { 136 | if (new File(where + binaryName).exists()) { 137 | found = true; 138 | break; 139 | } 140 | } 141 | } 142 | return found; 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /app/src/main/java/github/hellocsl/smartmonitor/utils/Constant.java: -------------------------------------------------------------------------------- 1 | package github.hellocsl.smartmonitor.utils; 2 | 3 | /** 4 | * Created by chensuilun on 16-10-9. 5 | */ 6 | 7 | public interface Constant { 8 | String ACCESSIBILITY_SERVICE = "github.hellocsl.smartmonitor/github.hellocsl.smartmonitor.VideoAccessibilityService"; 9 | 10 | String QQ_PKG = "com.tencent.mobileqq"; 11 | 12 | 13 | String MONITOR_TAG = "WaterMonitor"; 14 | 15 | String MONITOR_CMD_VIDEO = "1"; 16 | 17 | 18 | } 19 | -------------------------------------------------------------------------------- /app/src/main/java/github/hellocsl/smartmonitor/utils/RootCmd.java: -------------------------------------------------------------------------------- 1 | package github.hellocsl.smartmonitor.utils; 2 | 3 | import android.util.Log; 4 | 5 | import java.io.DataInputStream; 6 | import java.io.DataOutputStream; 7 | import java.io.IOException; 8 | 9 | /** 10 | * Created by chensuilun on 16-10-11. 11 | */ 12 | public final class RootCmd { 13 | 14 | private static final String TAG = "RootCmd"; 15 | public static boolean sHaveRoot = false; 16 | 17 | // 判断机器Android是否已经root,即是否获取root权限 18 | public static boolean haveRoot() { 19 | if (!sHaveRoot) { 20 | int ret = execRootCmdSilent("echo test"); // 通过执行测试命令来检测 21 | if (ret != -1) { 22 | Log.i(TAG, "have root!"); 23 | sHaveRoot = true; 24 | } else { 25 | Log.i(TAG, "not root!"); 26 | sHaveRoot = false; 27 | } 28 | } else { 29 | Log.i(TAG, "sHaveRoot = true, have root!"); 30 | } 31 | return sHaveRoot; 32 | } 33 | 34 | // 执行命令并且输出结果 35 | public static String execRootCmd(String cmd) { 36 | String result = ""; 37 | DataOutputStream dos = null; 38 | DataInputStream dis = null; 39 | 40 | try { 41 | Process p = Runtime.getRuntime().exec("su"); // 经过Root处理的android系统即有su命令 42 | dos = new DataOutputStream(p.getOutputStream()); 43 | dis = new DataInputStream(p.getInputStream()); 44 | 45 | Log.i(TAG, cmd); 46 | dos.writeBytes(cmd + "\n"); 47 | dos.flush(); 48 | dos.writeBytes("exit\n"); 49 | dos.flush(); 50 | String line = null; 51 | while ((line = dis.readLine()) != null) { 52 | Log.d("result", line); 53 | result += line; 54 | } 55 | p.waitFor(); 56 | } catch (Exception e) { 57 | e.printStackTrace(); 58 | } finally { 59 | if (dos != null) { 60 | try { 61 | dos.close(); 62 | } catch (IOException e) { 63 | e.printStackTrace(); 64 | } 65 | } 66 | if (dis != null) { 67 | try { 68 | dis.close(); 69 | } catch (IOException e) { 70 | e.printStackTrace(); 71 | } 72 | } 73 | } 74 | return result; 75 | } 76 | 77 | // 执行命令但不关注结果输出 78 | public static int execRootCmdSilent(String cmd) { 79 | int result = -1; 80 | DataOutputStream dos = null; 81 | 82 | try { 83 | Process p = Runtime.getRuntime().exec("su"); 84 | dos = new DataOutputStream(p.getOutputStream()); 85 | 86 | Log.i(TAG, cmd); 87 | dos.writeBytes(cmd + "\n"); 88 | dos.flush(); 89 | dos.writeBytes("exit\n"); 90 | dos.flush(); 91 | p.waitFor(); 92 | result = p.exitValue(); 93 | } catch (Exception e) { 94 | e.printStackTrace(); 95 | result = -1; 96 | return result; 97 | } finally { 98 | if (dos != null) { 99 | try { 100 | dos.close(); 101 | } catch (IOException e) { 102 | e.printStackTrace(); 103 | } 104 | } 105 | } 106 | return result; 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /app/src/main/java/github/hellocsl/smartmonitor/utils/SdUtils.java: -------------------------------------------------------------------------------- 1 | package github.hellocsl.smartmonitor.utils; 2 | 3 | import android.os.Build; 4 | import android.os.Environment; 5 | import android.text.TextUtils; 6 | 7 | import java.io.File; 8 | import java.util.Collections; 9 | import java.util.HashSet; 10 | import java.util.Set; 11 | import java.util.regex.Pattern; 12 | 13 | /** 14 | * Created by chensuilun on 16-10-17. 15 | */ 16 | 17 | public class SdUtils { 18 | /** 19 | * sdcard head 20 | */ 21 | public final static String SDCARD = Environment.getExternalStorageDirectory().getPath() + File.separator; 22 | 23 | 24 | private static final Pattern DIR_SEPORATOR = Pattern.compile("/"); 25 | 26 | private static final String ENV_EXTERNAL_STORAGE = "EXTERNAL_STORAGE"; 27 | private static final String ENV_EMULATED_STORAGE_TARGET = "EMULATED_STORAGE_TARGET"; 28 | private static final String ENV_SECONDARY_STORAGE = "SECONDARY_STORAGE"; 29 | 30 | 31 | /** 32 | * Return all available SD-Cards in the system (include emulated) 33 | * @return paths to all available SD-Cards in the system (include emulated) 34 | */ 35 | public static String[] getStorageDirectories() { 36 | // 最终的输出路径集合,用set保证不重复 37 | final Set dirs = new HashSet(); 38 | // 所有SD卡路径 39 | final String rawExternalStorage = System.getenv(ENV_EXTERNAL_STORAGE); 40 | // 所有二级SD卡路径 41 | final String rawSecondaryStoragesStr = System 42 | .getenv(ENV_SECONDARY_STORAGE); 43 | // 模拟SD卡路径 44 | final String rawEmulatedStorageTarget = System 45 | .getenv(ENV_EMULATED_STORAGE_TARGET); 46 | if (TextUtils.isEmpty(rawEmulatedStorageTarget)) { 47 | if (TextUtils.isEmpty(rawExternalStorage)) { 48 | // 如果都没有路径,直接写死用下面默认路径(源码) 49 | dirs.add("/storage/sdcard0"); 50 | } else { 51 | dirs.add(rawExternalStorage); 52 | } 53 | } else { 54 | final String rawUserId; 55 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { 56 | rawUserId = ""; 57 | } else { 58 | final String path = Environment.getExternalStorageDirectory() 59 | .getAbsolutePath(); 60 | final String[] folders = DIR_SEPORATOR.split(path); 61 | final String lastFolder = folders[folders.length - 1]; 62 | boolean isDigit = false; 63 | try { 64 | Integer.valueOf(lastFolder); 65 | isDigit = true; 66 | } catch (NumberFormatException ignored) { 67 | } 68 | rawUserId = isDigit ? lastFolder : ""; 69 | } 70 | // 各种模拟路径 /storage/emulated/0[1,2,...] 71 | if (TextUtils.isEmpty(rawUserId)) { 72 | dirs.add(rawEmulatedStorageTarget); 73 | } else { 74 | dirs.add(rawEmulatedStorageTarget + File.separator + rawUserId); 75 | } 76 | } 77 | // 二级SD卡路径 78 | if (!TextUtils.isEmpty(rawSecondaryStoragesStr)) { 79 | final String[] rawSecondaryStorages = rawSecondaryStoragesStr 80 | .split(File.pathSeparator); 81 | Collections.addAll(dirs, rawSecondaryStorages); 82 | } 83 | 84 | // 所有在默认SD卡下的默认路径父目录下的文件夹 85 | File innerDir = Environment.getExternalStorageDirectory(); 86 | File rootDir = innerDir.getParentFile(); 87 | File[] files = rootDir.listFiles(); 88 | if (files != null) { 89 | for (File file : files) { 90 | dirs.add(file.getPath()); 91 | } 92 | } 93 | 94 | return dirs.toArray(new String[dirs.size()]); 95 | } 96 | 97 | /** 98 | *
功能简述: 判断该目录能否写入 99 | *
功能详细描述: 100 | *
注意: 101 | * @param path 102 | * @return 103 | */ 104 | public static boolean canWrite(String path) { 105 | File file = new File(path); 106 | 107 | // 判断file能否读取写入,并且不是一个 USB drive 108 | // 分开写用于debug 109 | if (file != null) { 110 | if (file.isDirectory() && file.canRead() && file.canWrite()) { 111 | if (file.listFiles() != null) { 112 | if (file.listFiles().length > 0) { 113 | return true; 114 | } 115 | } 116 | } 117 | } 118 | 119 | return false; 120 | } 121 | 122 | /** 123 | *
功能简述:获取合适的存储目录 124 | *
功能详细描述: 125 | *
注意: 暂时取第一个可以写的目录 126 | * TODO 可以优化增加条件 127 | * @return 128 | */ 129 | public static String getSuitableStorage() { 130 | String[] dirs = getStorageDirectories(); 131 | for (String dir : dirs) { 132 | if (canWrite(dir)) { 133 | return dir; 134 | } 135 | } 136 | return Environment.getExternalStorageDirectory().getPath(); 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /app/src/main/java/github/hellocsl/smartmonitor/utils/TelephoneHelper.java: -------------------------------------------------------------------------------- 1 | package github.hellocsl.smartmonitor.utils; 2 | 3 | import android.os.Binder; 4 | import android.os.IBinder; 5 | import android.util.Log; 6 | 7 | import java.lang.reflect.Method; 8 | 9 | /** 10 | * Created by chensuilun on 16-10-10. 11 | */ 12 | public class TelephoneHelper { 13 | private static final String TAG = "TelephoneHelper"; 14 | /** 15 | * 挂断电话 16 | * @Permission android.permission.CALL_PHONE 17 | * @Permission android.permission.READ_PHONE_STATE 18 | * @Permission android.permission.PROCESS_OUTGOING_CALLS 19 | */ 20 | public static void killCall() { 21 | try { 22 | String serviceManagerName = "android.os.ServiceManager"; 23 | String serviceManagerNativeName = "android.os.ServiceManagerNative"; 24 | String telephonyName = "com.android.internal.telephony.ITelephony"; 25 | Class telephonyClass; 26 | Class telephonyStubClass; 27 | Class serviceManagerClass; 28 | Class serviceManagerNativeClass; 29 | Method telephonyEndCall; 30 | Object telephonyObject; 31 | Object serviceManagerObject; 32 | telephonyClass = Class.forName(telephonyName); 33 | telephonyStubClass = telephonyClass.getClasses()[0]; 34 | serviceManagerClass = Class.forName(serviceManagerName); 35 | serviceManagerNativeClass = Class.forName(serviceManagerNativeName); 36 | Method getService = // getDefaults[29]; 37 | serviceManagerClass.getMethod("getService", String.class); 38 | Method tempInterfaceMethod = serviceManagerNativeClass.getMethod("asInterface", IBinder.class); 39 | Binder tmpBinder = new Binder(); 40 | tmpBinder.attachInterface(null, "fake"); 41 | serviceManagerObject = tempInterfaceMethod.invoke(null, tmpBinder); 42 | IBinder retbinder = (IBinder) getService.invoke(serviceManagerObject, "phone"); 43 | Method serviceMethod = telephonyStubClass.getMethod("asInterface", IBinder.class); 44 | telephonyObject = serviceMethod.invoke(null, retbinder); 45 | telephonyEndCall = telephonyClass.getMethod("endCall"); 46 | telephonyEndCall.invoke(telephonyObject); 47 | 48 | } catch (Exception e) { 49 | e.printStackTrace(); 50 | Log.e(TAG, "FATAL ERROR: could not connect to telephony subsystem"); 51 | Log.e(TAG, "Exception object: " + e); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/java/github/hellocsl/smartmonitor/utils/UnLockUtils.java: -------------------------------------------------------------------------------- 1 | package github.hellocsl.smartmonitor.utils; 2 | 3 | import android.text.TextUtils; 4 | import android.util.Log; 5 | import android.view.KeyEvent; 6 | 7 | import java.io.BufferedReader; 8 | import java.io.File; 9 | import java.io.FileInputStream; 10 | import java.io.FileNotFoundException; 11 | import java.io.IOException; 12 | import java.io.InputStreamReader; 13 | 14 | /** 15 | * Created by chensuilun on 16/10/14. 16 | * 解锁工具类,通过辅助服务来解锁屏幕还是有点困难(滑动操作的模拟和一些自定义View的支持) 17 | * 所以解决方案只能用命令行实现,但需要root权限 18 | */ 19 | public class UnLockUtils { 20 | private static final String TAG = "UnLockUtils"; 21 | private final static String UNLOCK_FILE = SdUtils.SDCARD + "MonitorUnlock.txt"; 22 | 23 | 24 | private UnLockUtils() { 25 | } 26 | 27 | 28 | public static void unlock() { 29 | File file = new File(UNLOCK_FILE); 30 | if (!file.exists()) { 31 | Log.e(TAG, "unlock: unlock file not exist!!!"); 32 | return; 33 | } 34 | BufferedReader bufferedReader = null; 35 | try { 36 | InputStreamReader streamReader = new InputStreamReader(new FileInputStream(file)); 37 | bufferedReader = new BufferedReader(streamReader); 38 | String input = null; 39 | while (!(input = bufferedReader.readLine()).equals("quit")) { 40 | if (TextUtils.isEmpty(input)) { 41 | continue; 42 | } 43 | RootCmd.execRootCmd(input.trim()); 44 | } 45 | } catch (FileNotFoundException e) { 46 | e.printStackTrace(); 47 | } catch (IOException e) { 48 | e.printStackTrace(); 49 | } finally { 50 | if (bufferedReader != null) { 51 | try { 52 | bufferedReader.close(); 53 | } catch (IOException e) { 54 | e.printStackTrace(); 55 | } 56 | } 57 | } 58 | } 59 | 60 | /** 61 | * 解锁我的Nexus5 62 | */ 63 | public static void unlockMyNexus5() { 64 | RootCmd.execRootCmd("input tap 450 450 "); 65 | //上滑动进入解锁 66 | RootCmd.execRootCmd("input swipe 655 1774 655 874"); 67 | RootCmd.execRootCmd("sleep 1 && input text 1"); 68 | RootCmd.execRootCmd("sleep 0.1 && input text 2"); 69 | RootCmd.execRootCmd("sleep 0.1 && input text 3"); 70 | RootCmd.execRootCmd("sleep 0.1 && input text 4"); 71 | RootCmd.execRootCmd("sleep 0.1 && input keyevent " + KeyEvent.KEYCODE_ENTER); 72 | } 73 | 74 | public static void unlockMyMx() { 75 | RootCmd.execRootCmd("sleep 0.1 && input keyevent" + KeyEvent.KEYCODE_HOME); 76 | //上滑进入解锁 77 | RootCmd.execRootCmd("input swipe 655 1774 655 874"); 78 | RootCmd.execRootCmd("sleep 1 && input tap 612 726"); 79 | RootCmd.execRootCmd("sleep 0.1 && input tap 813 1000"); 80 | RootCmd.execRootCmd("sleep 0.1 && input tap 813 1000"); 81 | RootCmd.execRootCmd("sleep 0.1 && input tap 255 1000"); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 20 | 21 | 28 | 29 | 30 | 34 | 35 | 41 | 42 | 43 | 47 | 48 | -------------------------------------------------------------------------------- /app/src/main/res/layout/widget_setting_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 19 | 20 | 30 | 31 | 32 | 43 | 44 | 45 | 54 | 55 | 56 | 65 | 66 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BCsl/WaterMonitor/eb31b90b07607118355e04de458d223c2e18e454/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BCsl/WaterMonitor/eb31b90b07607118355e04de458d223c2e18e454/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BCsl/WaterMonitor/eb31b90b07607118355e04de458d223c2e18e454/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BCsl/WaterMonitor/eb31b90b07607118355e04de458d223c2e18e454/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BCsl/WaterMonitor/eb31b90b07607118355e04de458d223c2e18e454/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #607D8B 4 | #455A64 5 | #FFC107 6 | #212121 7 | #727272 8 | #ffffff 9 | #4cffffff 10 | #3C4952 11 | #33000000 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | WaterMonitor 3 | 开启服务 4 | Root状态 5 | 需要获取Root权限来解锁手机屏幕 6 | 需要运行在已经Root的设备 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | 13 | 16 | 17 | 20 | 21 | 24 | 25 | 28 | 29 | 32 | 33 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /app/src/main/res/xml/accessible_service_config.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /app/src/test/java/github/hellocsl/smartmonitor/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package github.hellocsl.smartmonitor; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * @see Testing documentation 10 | */ 11 | public class ExampleUnitTest { 12 | @Test 13 | public void addition_isCorrect() throws Exception { 14 | assertEquals(4, 2 + 2); 15 | } 16 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.2.0' 9 | classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BCsl/WaterMonitor/eb31b90b07607118355e04de458d223c2e18e454/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /screenshot/Monitor.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BCsl/WaterMonitor/eb31b90b07607118355e04de458d223c2e18e454/screenshot/Monitor.gif -------------------------------------------------------------------------------- /script/MonitorUnlock.txt: -------------------------------------------------------------------------------- 1 | sleep 0.1 && input keyevent 3 2 | input swipe 655 1774 655 874 3 | sleep 1 && input tap 612 726 4 | sleep 0.1 && input tap 813 1000 5 | sleep 0.1 && input tap 813 1000 6 | sleep 0.1 && input tap 255 1000 7 | quit 8 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------