Skip to content

Commit

Permalink
Adding Special Permission (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
highjun committed Dec 5, 2024
1 parent 24be1b8 commit 9bbb2c9
Show file tree
Hide file tree
Showing 15 changed files with 445 additions and 80 deletions.
33 changes: 0 additions & 33 deletions field-smartphone/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<!-- <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>-->
<!-- <uses-permission android:name="android.permission.FOREGROUND_SERVICE_HEALTH"/>-->
<!-- <uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION"/>-->
<!-- <uses-permission android:name="android.permission.FOREGROUND_SERVICE_CAMERA"/>-->
<!-- <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE"/>-->
<!-- <uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE"/>-->
<!-- <uses-permission android:name="android.permission.FOREGROUND_SERVICE_CONNECTED_DEVICE"/>-->
<!-- <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>-->

<!-- <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"-->
<!-- tools:ignore="ProtectedPermissions" />-->

<!-- <uses-permission android:name="android.permission.INTERNET" />-->
<!-- &lt;!&ndash; ???&ndash;&gt;-->
<!-- <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>-->
<!-- &lt;!&ndash; GPS &ndash;&gt;-->
<!-- <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />-->
<!-- <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />-->
<!-- <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />-->
<!-- &lt;!&ndash; Activity Recognition &ndash;&gt;-->
<!-- <uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />-->

<!-- &lt;!&ndash; Booting &ndash;&gt;-->
<!-- <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />-->
<!-- &lt;!&ndash;WiFi&ndash;&gt;-->
<!-- <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>-->
<!-- &lt;!&ndash; Notification &ndash;&gt;-->
<!-- <uses-permission android:name="Manifest.permission.BIND_NOTIFICATION_LISTENER_SERVICE"/>-->
<!--&lt;!&ndash; App Usage Log&ndash;&gt;-->
<!-- <uses-permission android:name="android.permission.PACKAGE_USAGE_STATS"-->
<!-- tools:ignore="ProtectedPermissions" />-->

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
Expand All @@ -50,7 +18,6 @@
android:theme="@style/Theme.Tracker">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package kaist.iclab.field_tracker

import android.Manifest
import android.app.AppOpsManager
import android.app.PendingIntent
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.provider.ContactsContract.Data
import android.provider.Settings
import android.util.Log
import android.widget.Toast
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
Expand Down Expand Up @@ -52,20 +55,49 @@ class MainActivity : PermissionActivity() {
}
}
}
}


// if(!Tracker.getPermissionManager().isPermissionGranted(Manifest.permission.BIND_ACCESSIBILITY_SERVICE)){
//// startActivity(Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS))
//// val intent = Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS).apply {
//// data = Uri.fromParts("package", (this@MainActivity as Context).packageName, null)
//// }
//// startActivity(Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS))
// startActivity(Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS))
//
// }else{
// Toast.makeText(this, "Permission granted", Toast.LENGTH_SHORT).show()
// }

// if(!Tracker.getPermissionManager().isPermissionGranted(Manifest.permission.PACKAGE_USAGE_STATS)){
// startActivity(Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS))
// }
startActivity(Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS))
// startActivity(Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS))

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
Tracker.getPermissionManager().request(
arrayOf(Manifest.permission.POST_NOTIFICATIONS)
// Manifest.permission.SCHEDULE_EXACT_ALARM)
) {
Log.d("MAIN_ACTIVITY", "Permission $it")
}
}
// checkAndRequestUsageStatsPermission(this)

}
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
// Tracker.getPermissionManager().request(
// arrayOf(Manifest.permission.POST_NOTIFICATIONS)
//// Manifest.permission.SCHEDULE_EXACT_ALARM)
// ) {
// Log.d("MAIN_ACTIVITY", "Permission $it")
// }
// }

// private fun checkAndRequestUsageStatsPermission(context: Context) {
// if (!hasUsageStatsPermission(context)) {
// // 권한이 없으므로 설정 화면으로 이동
// Toast.makeText(context, "Usage Stats 권한이 필요합니다.", Toast.LENGTH_SHORT).show()
// val intent = Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS).apply {
// data = Uri.fromParts("package", context.packageName, null)
// }
// context.startActivity(intent)
// } else {
// // 권한이 이미 있음
// Toast.makeText(context, "Usage Stats 권한이 이미 허용되었습니다.", Toast.LENGTH_SHORT).show()
// }
// }

}
Binary file not shown.
40 changes: 30 additions & 10 deletions tracker-library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,7 @@
android:exported="false">
</service>

<!-- <service android:name=".collectors.NotificationCollector$NotificationTrigger"-->
<!-- android:exported="false"-->
<!-- android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">-->
<!-- <intent-filter>-->
<!-- <action android:name="android.service.notification.NotificationListenerService" />-->
<!-- </intent-filter>-->
<!-- </service>-->

<service
android:name=".collectors.UserInteractionCollector$MyAccessibilityService"
<service android:name=".listeners.AccessibilityListener"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"
android:exported="false">
<intent-filter>
Expand All @@ -91,5 +82,34 @@
android:name="android.accessibilityservice"
android:resource="@xml/accessibility_service_config" />
</service>

<service android:name=".listeners.NotificationListener"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"
android:exported="false">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>

<!-- <service android:name=".collectors.NotificationCollector$NotificationTrigger"-->
<!-- android:exported="false"-->
<!-- android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">-->
<!-- <intent-filter>-->
<!-- <action android:name="android.service.notification.NotificationListenerService" />-->
<!-- </intent-filter>-->
<!-- </service>-->


<!-- <service-->
<!-- android:name=".collectors.UserInteractionCollector$MyAccessibilityService"-->
<!-- android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"-->
<!-- 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>
5 changes: 3 additions & 2 deletions tracker-library/src/main/java/kaist/iclab/tracker/Tracker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import kaist.iclab.tracker.controller.CollectorControllerImpl
import kaist.iclab.tracker.controller.CollectorControllerInterface
import kaist.iclab.tracker.notf.NotfManagerImpl
import kaist.iclab.tracker.notf.NotfManagerInterface
import kaist.iclab.tracker.permission.PermissionManagerImpl
//import kaist.iclab.tracker.permission.PermissionManagerImpl
import kaist.iclab.tracker.permission.PermissionManagerImpl2
import kaist.iclab.tracker.permission.PermissionManagerInterface
import java.lang.ref.WeakReference

Expand Down Expand Up @@ -44,7 +45,7 @@ object Tracker {
fun initialize(context: Context){
val notfManager_ = NotfManagerImpl()
notfManager_.createServiceNotfChannel(context)
initialize(context,PermissionManagerImpl(context),notfManager_, CollectorControllerImpl(context))
initialize(context,PermissionManagerImpl2(context),notfManager_, CollectorControllerImpl(context))

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,26 @@ class UserInteractionCollector(
}


class MyAccessibilityService : AccessibilityService() {
override fun onAccessibilityEvent(event: AccessibilityEvent?) {
// Log.d("MyAccessibilityService", "onAccessibilityEvent: $event")
val isRunning = instance?.get()?.stateFlow?.value?.flag == CollectorState.FLAG.RUNNING
if(!isRunning) return
event?.let { it->
val timestamp = System.currentTimeMillis()
instance?.get()?.listener?.invoke(
Entity(
timestamp,
timestamp,
it.packageName?.toString()?: "UNKNOWN",
it.className?.toString()?: "UNKNOWN",
it.eventType,
it.text.toString()
)
)
}
}
override fun onInterrupt() {}
}
// class MyAccessibilityService : AccessibilityService() {
// override fun onAccessibilityEvent(event: AccessibilityEvent?) {
// val isRunning = instance?.get()?.stateFlow?.value?.flag == CollectorState.FLAG.RUNNING
// if(!isRunning) return
// event?.let { it->
// val timestamp = System.currentTimeMillis()
// instance?.get()?.listener?.invoke(
// Entity(
// timestamp,
// timestamp,
// it.packageName?.toString()?: "UNKNOWN",
// it.className?.toString()?: "UNKNOWN",
// it.eventType,
// it.text.toString()
// )
// )
// }
// }
// override fun onInterrupt() {}
// }


data class Entity(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package kaist.iclab.tracker.listeners

import android.accessibilityservice.AccessibilityService
import android.util.Log
import android.view.accessibility.AccessibilityEvent

class AccessibilityListener: AccessibilityService() {
override fun onAccessibilityEvent(event: AccessibilityEvent?) {
Log.d(javaClass.simpleName, "onAccessibilityEvent: $event")
}

override fun onInterrupt() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package kaist.iclab.tracker.listeners

import android.service.notification.NotificationListenerService

class NotificationListener: NotificationListenerService(){

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package kaist.iclab.tracker.modals

interface ModalManagerInterface {
fun showModal(
title: String,
message: String,
onResult: (accepted: Boolean) -> Unit,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ open class PermissionActivity: ComponentActivity() {
super.onCreate(savedInstanceState)
permissionManager.attach(this@PermissionActivity)
}

override fun onResume() {
super.onResume()
permissionManager.checkPermissions()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import java.lang.ref.WeakReference

typealias PermissionResult = Map<String, Boolean>
typealias PermissionResultCallback = (PermissionResult) -> Unit
private typealias ActivityWeakRef = WeakReference<PermissionActivity>
typealias ActivityWeakRef = WeakReference<PermissionActivity>


class PermissionManagerImpl(
Expand Down Expand Up @@ -49,6 +49,9 @@ class PermissionManagerImpl(
?: throw IllegalStateException("PermissionActivity not attached")
}

override fun checkPermissions() {
TODO("Not yet implemented")
}

override fun isPermissionGranted(permission: String): Boolean {
return ContextCompat.checkSelfPermission(
Expand Down Expand Up @@ -225,5 +228,4 @@ class PermissionManagerImpl(
}



}
Loading

0 comments on commit 9bbb2c9

Please sign in to comment.