expo-app-blocker 0.1.28 → 0.1.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,24 +1,19 @@
|
|
|
1
1
|
package expo.modules.appblocker
|
|
2
2
|
|
|
3
|
-
import android.Manifest
|
|
4
3
|
import android.app.AppOpsManager
|
|
5
4
|
import android.content.Context
|
|
6
5
|
import android.content.Intent
|
|
7
6
|
import android.content.pm.ApplicationInfo
|
|
8
|
-
import android.content.pm.PackageManager
|
|
9
7
|
import android.net.Uri
|
|
10
|
-
import android.os.Build
|
|
11
8
|
import android.os.Process
|
|
12
9
|
import android.provider.Settings
|
|
13
10
|
import android.util.Log
|
|
14
|
-
import androidx.core.app.
|
|
15
|
-
import androidx.core.content.ContextCompat
|
|
11
|
+
import androidx.core.app.NotificationManagerCompat
|
|
16
12
|
import expo.modules.kotlin.exception.Exceptions
|
|
17
13
|
import expo.modules.kotlin.modules.Module
|
|
18
14
|
import expo.modules.kotlin.modules.ModuleDefinition
|
|
19
15
|
|
|
20
16
|
private const val TAG = "ExpoAppBlocker"
|
|
21
|
-
private const val NOTIFICATION_PERMISSION_REQUEST_CODE = 9003
|
|
22
17
|
|
|
23
18
|
class ExpoAppBlockerModule : Module() {
|
|
24
19
|
private val context: Context
|
|
@@ -28,7 +23,6 @@ class ExpoAppBlockerModule : Module() {
|
|
|
28
23
|
Name("ExpoAppBlocker")
|
|
29
24
|
|
|
30
25
|
OnCreate {
|
|
31
|
-
requestNotificationPermissionIfNeeded()
|
|
32
26
|
AppBlockerService.start(context)
|
|
33
27
|
Log.d(TAG, "Module OnCreate: started AppBlockerService")
|
|
34
28
|
}
|
|
@@ -47,6 +41,10 @@ class ExpoAppBlockerModule : Module() {
|
|
|
47
41
|
mode == AppOpsManager.MODE_ALLOWED
|
|
48
42
|
}
|
|
49
43
|
|
|
44
|
+
AsyncFunction("checkNotificationPermission") {
|
|
45
|
+
NotificationManagerCompat.from(context).areNotificationsEnabled()
|
|
46
|
+
}
|
|
47
|
+
|
|
50
48
|
Function("openOverlaySettings") {
|
|
51
49
|
val intent = Intent(
|
|
52
50
|
Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
|
|
@@ -109,18 +107,4 @@ class ExpoAppBlockerModule : Module() {
|
|
|
109
107
|
}
|
|
110
108
|
}
|
|
111
109
|
|
|
112
|
-
private fun requestNotificationPermissionIfNeeded() {
|
|
113
|
-
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) return
|
|
114
|
-
val granted = ContextCompat.checkSelfPermission(
|
|
115
|
-
context,
|
|
116
|
-
Manifest.permission.POST_NOTIFICATIONS
|
|
117
|
-
) == PackageManager.PERMISSION_GRANTED
|
|
118
|
-
if (granted) return
|
|
119
|
-
val activity = appContext.currentActivity ?: return
|
|
120
|
-
ActivityCompat.requestPermissions(
|
|
121
|
-
activity,
|
|
122
|
-
arrayOf(Manifest.permission.POST_NOTIFICATIONS),
|
|
123
|
-
NOTIFICATION_PERMISSION_REQUEST_CODE
|
|
124
|
-
)
|
|
125
|
-
}
|
|
126
110
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-app-blocker",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.30",
|
|
4
4
|
"description": "Expo module for cross-platform app blocking. Android: UsageStatsManager + Overlay. iOS: Screen Time API (FamilyControls + ManagedSettings + DeviceActivity).",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"types": "src/index.ts",
|
package/src/index.ts
CHANGED
|
@@ -52,8 +52,9 @@ export async function getPermissionStatus(): Promise<PermissionStatus> {
|
|
|
52
52
|
if (Platform.OS === "android") {
|
|
53
53
|
const overlay = await NativeModule.checkOverlayPermission();
|
|
54
54
|
const usageStats = await NativeModule.checkUsageStatsPermission();
|
|
55
|
-
const
|
|
56
|
-
|
|
55
|
+
const notifications = await NativeModule.checkNotificationPermission();
|
|
56
|
+
const details: AndroidPermissions = { platform: "android", overlay, usageStats, notifications };
|
|
57
|
+
return { allGranted: overlay && usageStats && notifications, details };
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
if (Platform.OS === "ios") {
|