-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
lalakii
committed
Jan 22, 2024
0 parents
commit 232a3f8
Showing
19 changed files
with
598 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx | ||
local.properties | ||
/.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Android GetEvent | ||
|
||
[English](README_en.md) | [中文](README.md) | ||
|
||
**通过Shizuku权限,读取触摸屏事件示例** [下载演示APP](https://github.com/lalakii/get_event/releases/) | ||
|
||
读取到的数据还需要解析,我只实现到这一步,有功能需求自行完善。 | ||
|
||
<img src="./video/demo.gif" width="300"/> | ||
|
||
## By lalaki.cn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Android GetEvent | ||
|
||
[中文](README.md) | [English](README_en.md) | ||
|
||
**Example of reading touch screen events with Shizuku privileges** [Download Sample App](https://github.com/lalakii/get_event/releases/) | ||
|
||
The read data still need to be parsed, I have only completed to this point, there are functional requirements to improve their own. | ||
|
||
<img src="./video/demo.gif" width="300"/> | ||
|
||
## By lalaki.cn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/build | ||
/release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
plugins { | ||
id 'com.android.application' | ||
} | ||
|
||
android { | ||
namespace 'cn.lalaki.touch_event' | ||
compileSdk 34 | ||
|
||
defaultConfig { | ||
applicationId "cn.lalaki.touch_event" | ||
minSdk 24 | ||
//noinspection EditedTargetSdkVersion | ||
targetSdk 34 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_17 | ||
targetCompatibility JavaVersion.VERSION_17 | ||
} | ||
} | ||
|
||
dependencies { | ||
def shizuku_version = "13.1.5" | ||
implementation "dev.rikka.shizuku:api:$shizuku_version" | ||
// Add this line if you want to support Shizuku | ||
implementation "dev.rikka.shizuku:provider:$shizuku_version" | ||
// https://mvnrepository.com/artifact/com.google.guava/guava | ||
implementation("com.google.guava:guava:33.0.0-android") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<application | ||
android:icon="@android:drawable/sym_def_app_icon" | ||
android:label="@string/app_name" | ||
android:theme="@android:style/Theme.DeviceDefault"> | ||
|
||
<activity android:name=".MainActivity" | ||
android:exported="true"> | ||
|
||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
|
||
<provider | ||
android:name="rikka.shizuku.ShizukuProvider" | ||
android:authorities="${applicationId}.shizuku" | ||
android:multiprocess="false" | ||
android:enabled="true" | ||
android:exported="true" | ||
android:permission="android.permission.INTERACT_ACROSS_USERS_FULL" /> | ||
|
||
<!-- android:permission="android.permission.INTERACT_ACROSS_USERS_FULL" is to protect this provider from accessing by normal apps --> | ||
</application> | ||
|
||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/system/bin/sh | ||
BASEDIR=$(dirname "$0") | ||
DEX="$BASEDIR"/rish_shizuku.dex | ||
|
||
if [ ! -f "$DEX" ]; then | ||
echo "Cannot find $DEX, please check the tutorial in Shizuku app" | ||
exit 1 | ||
fi | ||
|
||
if [ $(getprop ro.build.version.sdk) -ge 34 ]; then | ||
if [ -w $DEX ]; then | ||
echo "On Android 14+, app_process cannot load writable dex." | ||
echo "Attempting to remove the write permission..." | ||
chmod 400 $DEX | ||
fi | ||
if [ -w $DEX ]; then | ||
echo "Cannot remove the write permission of $DEX." | ||
echo "You can copy to file to terminal app's private directory (/data/data/<package>, so that remove write permission is possible" | ||
exit 1 | ||
fi | ||
fi | ||
|
||
# Replace "PKG" with the application id of your terminal app | ||
[ -z "$RISH_APPLICATION_ID" ] && export RISH_APPLICATION_ID="cn.lalaki.touch_event" | ||
/system/bin/app_process -Djava.class.path="$DEX" /system/bin --nice-name=rish rikka.shizuku.shell.ShizukuShellLoader "$@" |
Binary file not shown.
110 changes: 110 additions & 0 deletions
110
app/src/main/java/cn/lalaki/touch_event/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package cn.lalaki.touch_event; | ||
|
||
import android.app.Activity; | ||
import android.content.Intent; | ||
import android.content.pm.PackageManager; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.widget.TextView; | ||
import android.widget.Toast; | ||
|
||
import com.google.common.io.ByteStreams; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
import rikka.shizuku.Shizuku; | ||
|
||
public class MainActivity extends Activity implements View.OnClickListener, Shizuku.OnRequestPermissionResultListener { | ||
private boolean permissionIsGranted = false; | ||
private TextView te_data; | ||
private File rish; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.main); | ||
te_data = findViewById(R.id.touch_data); | ||
File external = getFilesDir(); | ||
if (external != null) { | ||
String path = external.getAbsolutePath() + "/private/"; | ||
if (new File(path).mkdirs()) { | ||
Toast.makeText(this, "create private dir is done.", Toast.LENGTH_SHORT).show(); | ||
} | ||
rish = new File(path + "rish"); | ||
if (!rish.exists()) { | ||
String[] files = {"rish_shizuku.dex", "rish"}; | ||
for (String name : files) { | ||
try (InputStream rish_dex = getAssets().open(name)) { | ||
try (FileOutputStream out = new FileOutputStream(path + name)) { | ||
ByteStreams.copy(rish_dex, out); | ||
} | ||
} catch (IOException ignored) { | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
protected void onResume() { | ||
Intent shizukuIntent = getPackageManager().getLaunchIntentForPackage("moe.shizuku.privileged.api"); | ||
if (shizukuIntent != null) { | ||
if (Shizuku.pingBinder()) { | ||
permissionIsGranted = Shizuku.checkSelfPermission() == PackageManager.PERMISSION_GRANTED; | ||
if (permissionIsGranted) { | ||
findViewById(R.id.tips).setAlpha(0F); | ||
} else { | ||
Shizuku.addRequestPermissionResultListener(this); | ||
Shizuku.requestPermission(0); | ||
} | ||
} | ||
} | ||
super.onResume(); | ||
} | ||
|
||
@Override | ||
public void onRequestPermissionResult(int requestCode, int grantResult) { | ||
permissionIsGranted = grantResult == 0; | ||
} | ||
|
||
private InputStream in; | ||
private String line; | ||
private boolean isRunning = false; | ||
private final ProcessBuilder builder = new ProcessBuilder(); | ||
|
||
@Override | ||
public void onClick(View view) { | ||
if (!permissionIsGranted) return; | ||
if (isRunning) { | ||
Toast.makeText(this, R.string.end, Toast.LENGTH_SHORT).show(); | ||
finish(); | ||
System.exit(0); | ||
} | ||
if (rish.exists()) { | ||
isRunning = !isRunning; | ||
Toast.makeText(this, R.string.touch_tips, Toast.LENGTH_SHORT).show(); | ||
new Thread(() -> { | ||
try { | ||
in = builder.command("sh", rish.getAbsolutePath(), "-c", "getevent -t").start().getInputStream(); | ||
new Thread(() -> { | ||
while (in != null) { | ||
try { | ||
byte[] data = new byte[2048]; | ||
ByteStreams.readFully(in, data); | ||
line = new String(data); | ||
runOnUiThread(() -> te_data.setText(line)); | ||
} catch (IOException e) { | ||
runOnUiThread(() -> te_data.setText(e.getLocalizedMessage())); | ||
} | ||
} | ||
}).start(); | ||
} catch (IOException e) { | ||
runOnUiThread(() -> te_data.setText(e.getLocalizedMessage())); | ||
} | ||
}).start(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<TextView | ||
android:id="@+id/touch_data" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_above="@id/switcher" | ||
android:textSize="10sp" /> | ||
|
||
<TextView | ||
android:id="@+id/tips" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_centerInParent="true" | ||
android:text="@string/need_permission" /> | ||
|
||
<Switch | ||
android:id="@+id/switcher" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_below="@id/tips" | ||
android:layout_centerHorizontal="true" | ||
android:minHeight="48dp" | ||
android:onClick="onClick" | ||
android:text="@string/start" | ||
android:textSize="22sp" /> | ||
|
||
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<resources> | ||
<string name="app_name">get_event</string> | ||
<string name="start">开始监听</string> | ||
<string name="need_permission">需要安装或激活Shizuku、并授予相应权限</string> | ||
<string name="touch_tips">此时在屏幕任意位置触摸可查看事件</string> | ||
<string name="end">退出程序</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Top-level build file where you can add configuration options common to all sub-projects/modules. | ||
plugins { | ||
id 'com.android.application' version '8.1.4' apply false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Project-wide Gradle settings. | ||
# IDE (e.g. Android Studio) users: | ||
# Gradle settings configured through the IDE *will override* | ||
# any settings specified in this file. | ||
# For more details on how to configure your build environment visit | ||
# http://www.gradle.org/docs/current/userguide/build_environment.html | ||
# Specifies the JVM arguments used for the daemon process. | ||
# The setting is particularly useful for tweaking memory settings. | ||
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 | ||
# When configured, Gradle will run in incubating parallel mode. | ||
# This option should only be used with decoupled projects. More details, visit | ||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects | ||
# org.gradle.parallel=true | ||
# AndroidX package structure to make it clearer which packages are bundled with the | ||
# Android operating system, and which are packaged with your app's APK | ||
# https://developer.android.com/topic/libraries/support-library/androidx-rn | ||
android.useAndroidX=true | ||
# Enables namespacing of each library's R class so that its R class includes only the | ||
# resources declared in the library itself and none from the library's dependencies, | ||
# thereby reducing the size of the R class for that library | ||
android.nonTransitiveRClass=true |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#Tue May 30 16:28:10 CST 2023 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=http\://mirrors.cloud.tencent.com/gradle/gradle-8.1.1-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Oops, something went wrong.