-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feat/permission]: special permission 허용 요청 기능 구현 #26
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
289f3cc
[feat]: 넘버피커 코드 이동 후 접근권한 허용용 온보딩 뷰 구현
kangyuri1114 4790d29
[delete]: 넘버피커 주석 처리
kangyuri1114 1b23b55
[feat]: 사용 기록에 액세스 허용이 되어있지 않은 경우 사용 정보 허용으로 이동 하는 기능 구현
kangyuri1114 85651e3
[feat]: 사용 정보 허용 기능 구현
kangyuri1114 682a0be
[feat]: 설치된 앱 목록 가져오기 기능 임시 추가
kangyuri1114 55be136
[feat]: 설치된 앱 목록 세부정보 가져오기 기능 임시 추가
kangyuri1114 db86698
[fix]: Request Permission
kez-lab bd23756
[fix]: Request Permission
kez-lab 474ccb9
[fix]: Request Permission
kez-lab d62dd0f
[delete]: 불필요한 권한 삭제
kangyuri1114 1246483
[feat]: 권한 버튼 추가
kangyuri1114 b8edc68
[fix]: 함수 이름 변경
kangyuri1114 a014304
[fix]: Fix Usage Permission
kez-lab 4cd8c02
[fix]: Fix Usage Permission
kez-lab e192362
[fix]: Fix Usage Permission
kez-lab 099b90e
[feat]: 다른 앱 위에 그리기 권한 허용 구현
kangyuri1114 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
24 changes: 0 additions & 24 deletions
24
...ing/src/androidTest/java/com/hmh/hamyeonham/feature/onboarding/ExampleInstrumentedTest.kt
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,10 +1,29 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
|
||
<uses-permission | ||
android:name="android.permission.PACKAGE_USAGE_STATS" | ||
tools:ignore="ProtectedPermissions" /> | ||
|
||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> | ||
|
||
<application> | ||
<activity | ||
android:name=".OnBoardingActivity" | ||
android:exported="false" /> | ||
</application> | ||
|
||
<service | ||
android:name=".OnBoardingAccessibilityService" | ||
android:exported="true" | ||
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"> | ||
<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> |
19 changes: 19 additions & 0 deletions
19
...ing/src/main/java/com/hmh/hamyeonham/feature/onboarding/OnBoardingAccessibilityService.kt
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,19 @@ | ||
package com.hmh.hamyeonham.feature.onboarding | ||
|
||
import android.accessibilityservice.AccessibilityService | ||
import android.util.Log | ||
import android.view.accessibility.AccessibilityEvent | ||
import com.hmh.hamyeonham.common.context.toast | ||
|
||
class OnBoardingAccessibilityService : AccessibilityService() { | ||
override fun onAccessibilityEvent(event: AccessibilityEvent) { | ||
if (event.eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) { | ||
val packageName = event.packageName ?: return | ||
Log.d("AccessibilityService", "현재 실행 중인 앱 패키지: $packageName") | ||
} | ||
} | ||
|
||
override fun onInterrupt() { | ||
|
||
} | ||
} |
95 changes: 90 additions & 5 deletions
95
feature/onboarding/src/main/java/com/hmh/hamyeonham/feature/onboarding/OnBoardingActivity.kt
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 |
---|---|---|
@@ -1,21 +1,106 @@ | ||
package com.hmh.hamyeonham.feature.onboarding | ||
|
||
import android.app.usage.UsageStatsManager | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.net.Uri | ||
import android.os.Bundle | ||
import android.provider.Settings | ||
import androidx.activity.result.ActivityResultLauncher | ||
import androidx.activity.result.contract.ActivityResultContracts | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.hmh.hamyeonham.common.context.toast | ||
import com.hmh.hamyeonham.feature.onboarding.databinding.ActivityOnBoardingBinding | ||
|
||
class OnBoardingActivity : AppCompatActivity() { | ||
|
||
private lateinit var binding: ActivityOnBoardingBinding | ||
|
||
private val accessibilitySettingsLauncher: ActivityResultLauncher<Intent> = | ||
registerForActivityResult( | ||
ActivityResultContracts.StartActivityForResult(), | ||
) { | ||
if (isAccessibilityServiceEnabled()) { | ||
toast("접근성 서비스가 활성화되었습니다.") | ||
} else { | ||
toast("접근성 서비스가 활성화되지 않았습니다.") | ||
} | ||
} | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
binding = ActivityOnBoardingBinding.inflate(layoutInflater) | ||
super.onCreate(savedInstanceState) | ||
setContentView(binding.root) | ||
clickRequireAccessibilityBtn() | ||
} | ||
|
||
binding.run { | ||
numberPicker.npCustomHours.minValue = 1 | ||
numberPicker.npCustomHours.maxValue = 6 | ||
numberPicker.npCustomMinutes.minValue = 1 | ||
numberPicker.npCustomMinutes.maxValue = 59 | ||
private fun clickRequireAccessibilityBtn() { | ||
binding.btnAccessibility.setOnClickListener { | ||
openAccessibilitySettingsIfNeeded() | ||
} | ||
binding.btnUsage.setOnClickListener { | ||
requestUsageAccessPermission() | ||
} | ||
binding.btnDrawOnOthers.setOnClickListener { | ||
if (!hasOverlayPermission()) { | ||
requestOverlayPermission() | ||
} else { | ||
toast("다른 앱 위에 그리기 권한이 이미 허용되어 있습니다.") | ||
} | ||
} | ||
} | ||
|
||
private fun requestUsageAccessPermission() { | ||
if (!hasUsageStatsPermission()) { | ||
try { | ||
val packageUri = Uri.parse("package:$packageName") | ||
val intent = Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS, packageUri) | ||
startActivity(intent) | ||
} catch (e: Exception) { | ||
val intent = Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS) | ||
startActivity(intent) | ||
} | ||
} else { | ||
toast("사용 정보 접근 권한이 이미 허용되어 있습니다.") | ||
} | ||
} | ||
|
||
private fun requestOverlayPermission() { | ||
val packageUri = Uri.parse("package:$packageName") | ||
val intent = Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, packageUri) | ||
startActivity(intent) | ||
} | ||
|
||
private fun hasOverlayPermission(): Boolean { | ||
return Settings.canDrawOverlays(this) | ||
} | ||
|
||
private fun isAccessibilityServiceEnabled(): Boolean { | ||
val service = packageName + "/" + OnBoardingAccessibilityService::class.java.canonicalName | ||
val enabledServicesSetting = Settings.Secure.getString( | ||
contentResolver, | ||
Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, | ||
) | ||
return enabledServicesSetting?.contains(service) == true | ||
} | ||
|
||
private fun openAccessibilitySettingsIfNeeded() { | ||
if (!isAccessibilityServiceEnabled()) { | ||
val intent = Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS) | ||
accessibilitySettingsLauncher.launch(intent) | ||
} else { | ||
toast("접근성 권한이 이미 허용되어 있습니다.") | ||
} | ||
} | ||
|
||
private fun hasUsageStatsPermission(): Boolean { | ||
val usageStatsManager = getSystemService(Context.USAGE_STATS_SERVICE) as UsageStatsManager | ||
val time = System.currentTimeMillis() | ||
val stats = usageStatsManager.queryUsageStats( | ||
UsageStatsManager.INTERVAL_DAILY, | ||
time - 1000 * 60, | ||
time, | ||
) | ||
return stats != null && stats.isNotEmpty() | ||
} | ||
} |
34 changes: 28 additions & 6 deletions
34
feature/onboarding/src/main/res/layout/activity_on_boarding.xml
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 |
---|---|---|
@@ -1,16 +1,38 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
tools:context=".OnBoardingActivity"> | ||
|
||
<include | ||
android:id="@+id/numberPicker" | ||
layout="@layout/dialog_numberpicker_custom" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
<Button | ||
android:id="@+id/btn_accessibility" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="접근성 허용하러 가기" | ||
app:layout_constraintBottom_toTopOf="@+id/btn_usage" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent"/> | ||
android:layout_marginBottom="30dp"/> | ||
|
||
<Button | ||
android:id="@+id/btn_usage" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="사용 정보접근 허용하러 가기" | ||
app:layout_constraintBottom_toTopOf="@+id/btn_draw_on_others" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
android:layout_marginBottom="30dp"/> | ||
|
||
<Button | ||
android:id="@+id/btn_draw_on_others" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginBottom="30dp" | ||
android:text="다른 앱 위에 그리기허용하러 가기" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" /> | ||
</androidx.constraintlayout.widget.ConstraintLayout> |
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
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
<resources></resources> | ||
<resources> | ||
<string name="accessibility_service_description">화면 동작 감지</string> | ||
</resources> |
7 changes: 7 additions & 0 deletions
7
feature/onboarding/src/main/res/xml/accessibility_service_config.xml
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 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:accessibilityEventTypes="typeWindowStateChanged" | ||
android:accessibilityFeedbackType="feedbackSpoken" | ||
android:accessibilityFlags="flagDefault" | ||
android:canRetrieveWindowContent="true" | ||
android:notificationTimeout="100" /> |
17 changes: 0 additions & 17 deletions
17
feature/onboarding/src/test/java/com/hmh/hamyeonham/feature/onboarding/ExampleUnitTest.kt
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
별견 아니지만 onCreate같은 퍼블릭 메소드가 먼저 나오는 게 좋을 것 같아요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
변수라서 해당 부분이 컨벤션상 먼저 있는게 맞습니당~!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아 그렇군요 감사합니다!