Skip to content
This repository has been archived by the owner on Nov 11, 2023. It is now read-only.

Commit

Permalink
Checkin android studio generated skeleton
Browse files Browse the repository at this point in the history
	Add basic test framework
	Add a basic accesibility filters
  • Loading branch information
posix4e committed Jul 15, 2023
1 parent 9855c74 commit 3090bb5
Show file tree
Hide file tree
Showing 45 changed files with 1,003 additions and 0 deletions.
14 changes: 14 additions & 0 deletions puppet/.gitignore
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
3 changes: 3 additions & 0 deletions puppet/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions puppet/.idea/androidTestResultsUserPreferences.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions puppet/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions puppet/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions puppet/.idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions puppet/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions puppet/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions puppet/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
52 changes: 52 additions & 0 deletions puppet/app/build.gradle
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'
}
21 changes: 21 additions & 0 deletions puppet/app/proguard-rules.pro
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")
}
}
}
41 changes: 41 additions & 0 deletions puppet/app/src/main/AndroidManifest.xml
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>
54 changes: 54 additions & 0 deletions puppet/app/src/main/java/com/ttt246/puppet/ChatterAct.kt
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
}
}
48 changes: 48 additions & 0 deletions puppet/app/src/main/java/com/ttt246/puppet/PuppetAS.kt
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")
}

}
Loading

0 comments on commit 3090bb5

Please sign in to comment.