-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
Add basic test framework Add a basic accesibility filters
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
app/google-services.json | ||
*.iml | ||
.gradle | ||
local.properties | ||
.idea/caches | ||
.idea/libraries | ||
.idea/modules.xml | ||
.idea/workspace.xml | ||
.idea/navEditor.xml | ||
.idea/assetWizardSettings.xml | ||
.DS_Store | ||
build | ||
local.properties |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
|
||
plugins { | ||
id 'com.android.application' | ||
id 'org.jetbrains.kotlin.android' | ||
id 'com.google.gms.google-services' | ||
} | ||
|
||
android { | ||
namespace 'com.ttt246.puppet' | ||
compileSdkVersion 33 | ||
kotlinOptions { | ||
jvmTarget = "1.8" | ||
} | ||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
defaultConfig { | ||
applicationId "com.ttt246.puppet" | ||
minSdkVersion 32 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
dependenciesInfo { | ||
includeInApk true | ||
includeInBundle true | ||
} | ||
} | ||
|
||
|
||
dependencies { | ||
implementation(platform("com.google.firebase:firebase-bom:32.2.0")) | ||
implementation 'com.google.firebase:firebase-analytics-ktx' | ||
implementation 'com.google.firebase:firebase-auth-ktx' | ||
implementation 'com.google.firebase:firebase-firestore-ktx' | ||
implementation 'androidx.appcompat:appcompat:1.6.1' | ||
implementation 'com.google.android.material:material:1.9.0' | ||
implementation 'com.google.firebase:firebase-messaging-ktx:23.2.0' | ||
testImplementation 'junit:junit:4.13.2' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.5' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.ttt246.puppet | ||
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import androidx.test.platform.app.InstrumentationRegistry | ||
import org.junit.Assert.* | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class IntegrationTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("com.ttt246.puppet", appContext.packageName) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.ttt246.puppet | ||
|
||
import android.content.pm.PackageManager | ||
import android.util.Log | ||
import androidx.test.ext.junit.rules.ActivityScenarioRule | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import androidx.test.platform.app.InstrumentationRegistry | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class MyAccessibilityServiceTest { | ||
@get:Rule | ||
var rule: ActivityScenarioRule<ChatterAct> = ActivityScenarioRule(ChatterAct::class.java) | ||
|
||
private val context = InstrumentationRegistry.getInstrumentation().targetContext | ||
|
||
@Test | ||
fun testHandleEvent() { | ||
val myService = PuppetAS() | ||
val packageManager = context.packageManager | ||
|
||
val applications = packageManager.getInstalledApplications(PackageManager.GET_META_DATA) | ||
for (applicationInfo in applications) { | ||
val packageName = applicationInfo.packageName | ||
val appName = packageManager.getApplicationLabel(applicationInfo).toString() | ||
Log.d("AppList", "App: $appName, Package: $packageName") | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
<uses-permission android:name="android.permission.BIND_ACCESSIBILITY_SERVICE" | ||
tools:ignore="ProtectedPermissions" /> | ||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:dataExtractionRules="@xml/data_extraction_rules" | ||
android:fullBackupContent="@xml/backup_rules" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.Puppet"> | ||
|
||
<activity | ||
android:name=".ChatterAct" | ||
android:exported="true"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
|
||
<service | ||
android:name=".PuppetAS" | ||
android:enabled="true" | ||
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE" | ||
android:foregroundServiceType="dataSync" | ||
android:exported="false"> | ||
<intent-filter> | ||
<action android:name="android.accessibilityservice.AccessibilityService" /> | ||
</intent-filter> | ||
<meta-data | ||
android:name="android.accessibilityservice" | ||
android:resource="@xml/accessibility_service_config"/> | ||
</service> | ||
</application> | ||
|
||
</manifest> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.ttt246.puppet | ||
import android.annotation.SuppressLint | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.os.Handler | ||
import android.os.Looper | ||
import android.provider.Settings | ||
import android.view.View | ||
import android.widget.TextView | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.google.android.gms.tasks.OnCompleteListener | ||
import com.google.firebase.messaging.FirebaseMessaging | ||
import java.io.File | ||
import java.io.IOException | ||
|
||
|
||
@Suppress("DEPRECATION") | ||
class ChatterAct : AppCompatActivity() { | ||
private var fcmToken: String = String() | ||
private var uuid: String = String() | ||
|
||
@SuppressLint("HardwareIds") | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
// Hide the status bar (system toolbar) | ||
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN | ||
supportActionBar?.hide() | ||
|
||
initToken() | ||
// on below line we are getting device id. | ||
uuid = Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID) | ||
val intent = Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS) | ||
startActivity(intent) | ||
|
||
} | ||
|
||
private fun initToken() { | ||
FirebaseMessaging.getInstance().token.addOnCompleteListener(OnCompleteListener { task -> | ||
if (!task.isSuccessful) { | ||
return@OnCompleteListener | ||
} | ||
|
||
fcmToken = task.result | ||
}) | ||
} | ||
|
||
fun getFCMToken(): String { | ||
return this.fcmToken | ||
} | ||
|
||
fun getUUID(): String { | ||
return this.uuid | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.ttt246.puppet | ||
import android.accessibilityservice.AccessibilityService | ||
import android.app.NotificationChannel | ||
import android.app.NotificationManager | ||
import android.util.Log | ||
import android.view.accessibility.AccessibilityEvent | ||
import androidx.core.app.NotificationCompat | ||
import java.io.File | ||
|
||
class PuppetAS : AccessibilityService() { | ||
|
||
override fun onAccessibilityEvent(event: AccessibilityEvent?) { | ||
Log.d("MyAccessibilityService", "onAccessibilityEvent: $event") | ||
writeLogToFile("$event") | ||
} | ||
|
||
override fun onInterrupt() { | ||
Log.d("MyAccessibilityService", "onInterrupt") | ||
} | ||
override fun onServiceConnected() { | ||
super.onServiceConnected() | ||
createNotificationChannel() | ||
|
||
val notification = NotificationCompat.Builder(this, "MyAccessibilityServiceChannel") | ||
.setContentTitle("My Accessibility Service") | ||
.setContentText("Running...") | ||
.setSmallIcon(R.drawable.ic_launcher_foreground) // replace with your own small icon | ||
.build() | ||
|
||
startForeground(1, notification) | ||
} | ||
|
||
private fun createNotificationChannel() { | ||
val serviceChannel = NotificationChannel( | ||
"MyAccessibilityServiceChannel", | ||
"My Accessibility Service Channel", | ||
NotificationManager.IMPORTANCE_DEFAULT | ||
) | ||
|
||
val manager: NotificationManager = getSystemService(NotificationManager::class.java) | ||
manager.createNotificationChannel(serviceChannel) | ||
} | ||
private fun writeLogToFile(logMessage: String) { | ||
val logFile = File(filesDir, "accessibility.log") | ||
logFile.appendText("$logMessage\n") | ||
} | ||
|
||
} |