Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
whoscall
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Wei Han
whoscall
Commits
b72847bb
Commit
b72847bb
authored
Sep 10, 2025
by
alep
Browse files
Options
Browse Files
Download
Plain Diff
merge with master
parents
94f91fc0
c6c3917f
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
236 additions
and
234 deletions
+236
-234
App.tsx
App.tsx
+189
-192
IncomingCallService.kt
...oid/app/src/main/java/com/whoscall/IncomingCallService.kt
+2
-2
MainActivity.kt
android/app/src/main/java/com/whoscall/MainActivity.kt
+16
-2
OverlayPermissionModule.kt
...app/src/main/java/com/whoscall/OverlayPermissionModule.kt
+18
-30
project.pbxproj
ios/whoscall.xcodeproj/project.pbxproj
+8
-4
CallDirectoryHandler.swift
ios/whoscallDirectoryExtension/CallDirectoryHandler.swift
+3
-4
No files found.
App.tsx
View file @
b72847bb
...
@@ -15,7 +15,7 @@ import {
...
@@ -15,7 +15,7 @@ import {
AppState
,
AppState
,
}
from
'react-native'
;
}
from
'react-native'
;
import
{
check
,
request
,
PERMISSIONS
,
RESULTS
}
from
'react-native-permissions'
;
import
{
check
,
request
,
PERMISSIONS
,
RESULTS
}
from
'react-native-permissions'
;
import
AsyncStorage
from
'@react-native-async-storage/async-storage'
;
//
import AsyncStorage from '@react-native-async-storage/async-storage';
import
DeviceInfo
from
'react-native-device-info'
;
import
DeviceInfo
from
'react-native-device-info'
;
const
{
ContactModule
,
VIPStorage
,
OverlayPermission
}
=
NativeModules
as
any
;
const
{
ContactModule
,
VIPStorage
,
OverlayPermission
}
=
NativeModules
as
any
;
...
@@ -25,34 +25,71 @@ type Contact = { name: string; number: string };
...
@@ -25,34 +25,71 @@ type Contact = { name: string; number: string };
const
CONTACTS_KEY
=
'whoscallContacts'
;
const
CONTACTS_KEY
=
'whoscallContacts'
;
const
permissionsList
=
[
const
permissionsList
=
Platform
.
select
({
{
key
:
'READ_PHONE_STATE'
,
android
:
PERMISSIONS
.
ANDROID
.
READ_PHONE_STATE
},
android
:
[
{
key
:
'READ_CALL_LOG'
,
android
:
PERMISSIONS
.
ANDROID
.
READ_CALL_LOG
},
{
key
:
'READ_PHONE_STATE'
,
android
:
PERMISSIONS
.
ANDROID
.
READ_PHONE_STATE
},
{
key
:
'Display Over Other Apps'
,
android
:
null
},
// overlay special case
{
key
:
'READ_CALL_LOG'
,
android
:
PERMISSIONS
.
ANDROID
.
READ_CALL_LOG
},
];
{
key
:
'Display Over Other Apps'
,
android
:
null
},
// overlay special case
],
function
normalize
(
n
:
string
)
{
ios
:
[{
key
:
'Call Directory Extension'
,
ios
:
true
}],
return
(
n
||
''
).
replace
(
/
[^
+0-9
]
/g
,
''
);
})
!
;
}
const
{
OverlayPermission
}
=
NativeModules
;
async
function
loadContacts
():
Promise
<
Contact
[]
>
{
type
CallDirectoryManagerType
=
{
const
json
=
await
AsyncStorage
.
getItem
(
CONTACTS_KEY
);
getEnabledStatusForExtension
(
identifier
:
string
):
Promise
<
number
>
;
return
json
?
JSON
.
parse
(
json
)
:
[];
reloadExtension
(
identifier
:
string
):
Promise
<
boolean
>
;
}
};
const
CallDirectoryManager
:
CallDirectoryManagerType
|
undefined
=
NativeModules
.
CallDirectoryManager
;
async
function
persistContacts
(
contacts
:
Contact
[])
{
const
json
=
JSON
.
stringify
(
contacts
);
// async function saveVIPNumber(name: string, number: string) {
await
AsyncStorage
.
setItem
(
CONTACTS_KEY
,
json
);
// try {
// Sync to native so IncomingCallService can resolve when JS isn’t active
// await AsyncStorage.setItem('vipName', name);
if
(
VIPStorage
?.
setContactsJson
)
{
// await AsyncStorage.setItem('vipNumber', number);
// const {VIPStorage} = NativeModules;
// if (!VIPStorage) {
// console.error("❌ VIPStorage is undefined. Did you register StoragePackage in MainApplication?");
// return;
// }
// await VIPStorage.saveVIP(name, number);
// console.log('VIPStorage from NativeModules:', NativeModules.VIPStorage);
// } catch (error) {
// console.error('Failed to save VIP info:', error);
// }
// }
async
function
checkOverlayPermission
()
{
if
(
Platform
.
OS
===
'android'
)
{
try
{
try
{
await
VIPStorage
.
setContactsJson
(
json
);
const
granted
:
boolean
=
await
OverlayPermission
.
hasPermission
();
if
(
!
granted
)
{
Alert
.
alert
(
'Overlay Permission Required'
,
'This app needs permission to display over other apps.'
,
[{
text
:
'Open Settings'
,
onPress
:
openOverlaySettings
}]
);
}
return
granted
;
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
warn
(
'VIPStorage.setContactsJson failed:'
,
e
);
console
.
error
(
'Error checking overlay permission:'
,
e
);
return
false
;
}
}
}
else
{
return
true
;
// iOS doesn't require this
}
}
}
}
const
openOverlaySettings
=
async
()
=>
{
if
(
Platform
.
OS
===
'android'
)
{
const
pkg
=
DeviceInfo
.
getBundleId
();
// gets your app package name
try
{
await
Linking
.
openSettings
();
// fallback
await
Linking
.
openURL
(
`package:
${
pkg
}
`
);
}
catch
(
err
)
{
console
.
warn
(
'Failed to open overlay settings:'
,
err
);
}
}
};
export
default
function
App
()
{
export
default
function
App
()
{
const
[
statuses
,
setStatuses
]
=
useState
<
Record
<
string
,
string
>>
({});
const
[
statuses
,
setStatuses
]
=
useState
<
Record
<
string
,
string
>>
({});
const
[
contacts
,
setContacts
]
=
useState
<
Contact
[]
>
([]);
const
[
contacts
,
setContacts
]
=
useState
<
Contact
[]
>
([]);
...
@@ -107,200 +144,156 @@ const openOverlaySettings = async () => {
...
@@ -107,200 +144,156 @@ const openOverlaySettings = async () => {
const
checkAllPermissions
=
useCallback
(
async
()
=>
{
const
checkAllPermissions
=
useCallback
(
async
()
=>
{
const
newStatuses
:
Record
<
string
,
string
>
=
{};
const
newStatuses
:
Record
<
string
,
string
>
=
{};
for
(
const
perm
of
permissionsList
)
{
if
(
Platform
.
OS
===
'ios'
)
{
if
(
perm
.
key
===
'Display Over Other Apps'
)
{
// ✅ Ask native for the real status
try
{
try
{
const
allowed
=
await
OverlayPermission
.
hasOverlayPermission
();
if
(
CallDirectoryManager
)
{
newStatuses
[
perm
.
key
]
=
RESULTS_BOOL
[
String
(
allowed
)
as
'true'
|
'false'
];
const
status
=
await
CallDirectoryManager
.
getEnabledStatusForExtension
(
}
catch
{
"com.whoscall.whosallDirectoryExtension"
newStatuses
[
perm
.
key
]
=
RESULTS
.
DENIED
;
);
newStatuses
[
'Call Directory Extension'
]
=
status
===
2
?
RESULTS
.
GRANTED
:
RESULTS
.
DENIED
;
}
else
{
console
.
warn
(
"⚠️ CallDirectoryManager native module not available"
);
newStatuses
[
'Call Directory Extension'
]
=
RESULTS
.
DENIED
;
}
}
catch
(
e
)
{
console
.
error
(
"Error checking Call Directory extension:"
,
e
);
newStatuses
[
'Call Directory Extension'
]
=
RESULTS
.
DENIED
;
}
}
else
{
for
(
const
perm
of
permissionsList
)
{
if
(
perm
.
key
===
'Display Over Other Apps'
)
{
const
granted
=
await
checkOverlayPermission
();
newStatuses
[
perm
.
key
]
=
granted
?
RESULTS
.
GRANTED
:
RESULTS
.
DENIED
;
continue
;
}
}
continue
;
}
const
result
=
await
check
(
perm
.
android
!
);
if
(
'android'
in
perm
&&
perm
.
android
)
{
newStatuses
[
perm
.
key
]
=
result
;
const
result
=
await
check
(
perm
.
android
);
}
newStatuses
[
perm
.
key
]
=
result
;
}
}
setStatuses
(
newStatuses
);
setStatuses
(
newStatuses
);
// Request any missing ones (overlay requires manual settings)
for
(
const
perm
of
permissionsList
)
{
for
(
const
perm
of
permissionsList
)
{
if
(
newStatuses
[
perm
.
key
]
!==
RESULTS
.
GRANTED
)
{
if
(
newStatuses
[
perm
.
key
]
!==
RESULTS
.
GRANTED
)
{
if
(
perm
.
key
===
'Display Over Other Apps'
)
{
if
(
perm
.
key
===
'Display Over Other Apps'
)
{
Alert
.
alert
(
Alert
.
alert
(
'Overlay Permission Required'
,
'Overlay Permission Required'
,
'This app needs permission to display over other apps.'
,
'This app needs permission to display over other apps.'
,
[{
text
:
'Open Settings'
,
onPress
:
openOverlaySettings
}]
[{
text
:
'Open Settings'
,
onPress
:
openOverlaySettings
}]
);
}
else
if
(
'android'
in
perm
&&
perm
.
android
)
{
const
result
=
await
request
(
perm
.
android
);
setStatuses
(
prev
=>
({
...
prev
,
[
perm
.
key
]:
result
}));
}
}
}
}
if
(
Platform
.
OS
===
'ios'
)
{
try
{
if
(
CallDirectoryManager
)
{
const
status
=
await
CallDirectoryManager
.
getEnabledStatusForExtension
(
"com.whoscall.whoscallDirectoryExtension"
);
);
let
mapped
:
typeof
RESULTS
[
keyof
typeof
RESULTS
];
// tells TS it's a valid RESULTS value
if
(
status
===
2
)
{
mapped
=
RESULTS
.
GRANTED
;
// enabled
}
else
if
(
status
===
1
)
{
mapped
=
RESULTS
.
DENIED
;
// disabled by user
}
else
{
mapped
=
RESULTS
.
UNAVAILABLE
;
// unknown / not supported
}
newStatuses
[
'Call Directory Extension'
]
=
mapped
;
}
else
{
}
else
{
const
result
=
await
request
(
perm
.
android
!
);
console
.
warn
(
"⚠️ CallDirectoryManager native module not available"
);
setStatuses
(
prev
=>
({
...
prev
,
[
perm
.
key
]:
result
}));
newStatuses
[
'Call Directory Extension'
]
=
RESULTS
.
DENIED
;
Alert
.
alert
(
"Enable Caller ID"
,
"Go to Settings → Phone → Call Blocking & Identification and enable [whoscall] to see caller ID labels."
,
[
{
text
:
"Open Settings"
,
onPress
:
()
=>
Linking
.
openURL
(
"app-settings:"
)
},
{
text
:
"Cancel"
,
style
:
"cancel"
}
]
);
}
}
}
catch
(
e
)
{
console
.
error
(
"Error checking Call Directory extension:"
,
e
);
newStatuses
[
'Call Directory Extension'
]
=
RESULTS
.
DENIED
;
Alert
.
alert
(
"Enable Caller ID"
,
"Go to Settings → Phone → Call Blocking & Identification and enable [Your App] to see caller ID labels."
,
[
{
text
:
"Open Settings"
,
onPress
:
()
=>
Linking
.
openURL
(
"app-settings:"
)
},
{
text
:
"Cancel"
,
style
:
"cancel"
}
]
);
}
}
}
}
},
[]);
},
[]);
useEffect
(()
=>
{
useEffect
(()
=>
{
const
sub
=
AppState
.
addEventListener
(
'change'
,
(
state
)
=>
{
console
.
log
(
"PermissionsScreen mounted"
);
if
(
state
===
'active'
)
checkAllPermissions
();
});
return
()
=>
sub
.
remove
();
},
[
checkAllPermissions
]);
// (Optional) Guard the old event flow so it won't crash if method not present
console
.
log
(
"All NativeModules keys:"
,
Object
.
keys
(
NativeModules
));
useEffect
(()
=>
{
// console.log("VIPStorage:", NativeModules.VIPStorage);
const
subscription
=
eventEmitter
.
addListener
(
'resolveContact'
,
async
(
incomingNumber
:
string
)
=>
{
try
{
const
json
=
await
AsyncStorage
.
getItem
(
CONTACTS_KEY
);
if
(
!
json
)
return
;
const
displayName
=
await
ContactModule
.
getDisplayName
(
json
,
incomingNumber
);
// saveVIPNumber('VIP User', '+60123456789');
if
(
ContactModule
?.
sendResolvedContact
)
{
checkAllPermissions
();
ContactModule
.
sendResolvedContact
(
incomingNumber
,
displayName
||
incomingNumber
);
},[
checkAllPermissions
]);
}
}
catch
(
err
)
{
console
.
error
(
'Failed to resolve contact:'
,
err
);
}
});
return
()
=>
subscription
.
remove
();
const
allGranted
=
Object
.
values
(
statuses
).
every
(
s
=>
s
===
RESULTS
.
GRANTED
);
},
[]);
useEffect
(()
=>
{
// --- iOS: Call Directory management ---
console
.
log
(
'PermissionsScreen mounted'
);
// const checkCallDirectoryStatus = async () => {
console
.
log
(
'All NativeModules keys:'
,
Object
.
keys
(
NativeModules
));
// if (Platform.OS !== "ios" || !CallDirectoryManager) {
console
.
log
(
'VIPStorage:'
,
VIPStorage
);
// console.warn("CallDirectoryManager not available on this platform");
// Initial load
// return;
refreshContacts
();
// }
checkAllPermissions
();
// try {
},
[
checkAllPermissions
,
refreshContacts
]);
// const status = await CallDirectoryManager.getEnabledStatusForExtension(
// "com.whoscall.whoscallDirectoryExtension" // <-- must match your extension bundle ID
// );
// console.log("Call Directory status:", status);
// ---- Overlay settings opener (kept) ----
// if (status === 2) {
// const openOverlaySettings = async () => {
// Alert.alert("✅ Enabled", "Call Directory Extension is enabled");
// if (Platform.OS === 'android') {
// } else {
// const pkg = DeviceInfo.getBundleId(); // gets your app package name
// Alert.alert(
// const url = `package:${pkg}`;
// "⚠️ Not Enabled",
// try {
// "Go to Settings → Phone → Call Blocking & Identification and enable Whoscall."
// await Linking.openSettings(); // fallback
// );
// await Linking.openURL(`android.settings.action.MANAGE_OVERLAY_PERMISSION/${url}`);
// } catch (err) {
// console.warn('Failed to open overlay settings:', err);
// }
// }
// } catch (e) {
// console.error("Error checking Call Directory status:", e);
// }
// }
// };
// };
const
allGranted
=
Object
.
values
(
statuses
).
every
(
s
=>
s
===
RESULTS
.
GRANTED
);
const
reloadCallDirectory
=
async
()
=>
{
if
(
Platform
.
OS
!==
"ios"
||
!
CallDirectoryManager
)
{
// ---- Contacts CRUD ----
console
.
warn
(
"CallDirectoryManager not available on this platform"
);
const
onAddOrUpdate
=
async
()
=>
{
const
trimmedName
=
name
.
trim
();
const
trimmedNum
=
number
.
trim
();
if
(
!
trimmedName
)
{
Alert
.
alert
(
'Validation'
,
'Please enter a name.'
);
return
;
return
;
}
}
if
(
!
trimmedNum
)
{
try
{
Alert
.
alert
(
'Validation'
,
'Please enter a number.'
);
const
success
=
await
CallDirectoryManager
.
reloadExtension
(
return
;
"com.whoscall.whoscallDirectoryExtension"
);
console
.
log
(
"Reload result:"
,
success
);
if
(
success
)
{
Alert
.
alert
(
"🔄 Reloaded"
,
"Extension reloaded successfully"
);
}
}
catch
(
e
)
{
console
.
error
(
"Error reloading Call Directory:"
,
e
);
Alert
.
alert
(
"❌ Reload Failed"
,
String
(
e
));
}
}
const
normalized
=
normalize
(
trimmedNum
);
const
next
=
[...
contacts
];
const
idx
=
next
.
findIndex
(
c
=>
normalize
(
c
.
number
)
===
normalized
);
const
newContact
=
{
name
:
trimmedName
,
number
:
trimmedNum
};
if
(
idx
>=
0
)
next
[
idx
]
=
newContact
;
else
next
.
push
(
newContact
);
await
persistContacts
(
next
);
setContacts
(
next
);
setName
(
''
);
setNumber
(
''
);
};
};
const
onDelete
=
async
(
target
:
Contact
)
=>
{
const
targetNorm
=
normalize
(
target
.
number
);
const
next
=
contacts
.
filter
(
c
=>
normalize
(
c
.
number
)
!==
targetNorm
);
await
persistContacts
(
next
);
setContacts
(
next
);
};
const
onClearAll
=
async
()
=>
{
Alert
.
alert
(
'Clear All'
,
'Remove all contacts?'
,
[
{
text
:
'Cancel'
,
style
:
'cancel'
},
{
text
:
'Clear'
,
style
:
'destructive'
,
onPress
:
async
()
=>
{
await
AsyncStorage
.
removeItem
(
CONTACTS_KEY
);
if
(
VIPStorage
?.
setContactsJson
)
{
try
{
await
VIPStorage
.
setContactsJson
(
'[]'
);
}
catch
{}
}
setContacts
([]);
},
},
]);
};
const
renderItem
=
({
item
}:
{
item
:
Contact
})
=>
(
<
View
style=
{
styles
.
itemRow
}
>
<
View
style=
{
{
flex
:
1
}
}
>
<
Text
style=
{
styles
.
itemName
}
>
{
item
.
name
}
</
Text
>
<
Text
style=
{
styles
.
itemNumber
}
>
{
item
.
number
}
</
Text
>
</
View
>
<
TouchableOpacity
style=
{
styles
.
deleteBtn
}
onPress=
{
()
=>
onDelete
(
item
)
}
>
<
Text
style=
{
styles
.
deleteTxt
}
>
Delete
</
Text
>
</
TouchableOpacity
>
</
View
>
);
return
(
return
(
<
View
style=
{
styles
.
container
}
>
<
View
style=
{
styles
.
container
}
>
<
Text
style=
{
styles
.
header
}
>
Whoscall Contacts
</
Text
>
<
Text
style=
{
styles
.
title
}
>
Permissions Status
</
Text
>
{
(
permissionsList
??
[]).
map
(
perm
=>
(
{
/* Add / Update form */
}
<
View
key=
{
perm
.
key
}
style=
{
styles
.
row
}
>
<
View
style=
{
styles
.
form
}
>
<
Text
style=
{
styles
.
text
}
>
{
perm
.
key
}
</
Text
>
<
Text
>
Name :
</
Text
>
<
TextInput
value=
{
name
}
onChangeText=
{
setName
}
placeholder=
"Contact name"
style=
{
styles
.
input
}
autoCapitalize=
"words"
/>
<
Text
>
Number phone :
</
Text
>
<
TextInput
value=
{
number
}
onChangeText=
{
setNumber
}
placeholder=
"Phone number (e.g., +60123456789)"
style=
{
styles
.
input
}
keyboardType=
"phone-pad"
/>
<
View
style=
{
{
flexDirection
:
'row'
,
gap
:
12
}
}
>
<
Button
title=
"Save Contact"
onPress=
{
onAddOrUpdate
}
/>
<
Button
title=
"Clear All"
color=
"#c62828"
onPress=
{
onClearAll
}
/>
</
View
>
</
View
>
{
/* Contact list */
}
<
Text
style=
{
styles
.
subheader
}
>
Saved Contacts (
{
contacts
.
length
}
)
</
Text
>
<
FlatList
data=
{
contacts
}
keyExtractor=
{
(
item
,
idx
)
=>
`${normalize(item.number)}_${idx}`
}
renderItem=
{
renderItem
}
ItemSeparatorComponent=
{
()
=>
<
View
style=
{
styles
.
separator
}
/>
}
style=
{
{
flexGrow
:
0
,
maxHeight
:
260
}
}
ListEmptyComponent=
{
<
Text
style=
{
styles
.
empty
}
>
No contacts yet. Add one above.
</
Text
>
}
/>
{
/* Permissions status */
}
<
Text
style=
{
styles
.
subheader
}
>
Permissions Status
</
Text
>
{
permissionsList
.
map
(
perm
=>
(
<
View
key=
{
perm
.
key
}
style=
{
styles
.
permRow
}
>
<
Text
style=
{
styles
.
permKey
}
>
{
perm
.
key
}
</
Text
>
<
Text
<
Text
style=
{
[
style=
{
[
styles
.
permVal
,
styles
.
permVal
,
...
@@ -310,9 +303,13 @@ const checkAllPermissions = useCallback(async () => {
...
@@ -310,9 +303,13 @@ const checkAllPermissions = useCallback(async () => {
</
Text
>
</
Text
>
</
View
>
</
View
>
))
}
))
}
{
allGranted
&&
<
Text
style=
{
styles
.
granted
}
>
All permissions granted ✅
</
Text
>
}
{
Platform
.
OS
===
"android"
&&
allGranted
&&
<
Text
style=
{
styles
.
granted
}
>
All permissions granted ✅
</
Text
>
}
<
View
style=
{
{
height
:
12
}
}
/>
<
Button
title=
"Check Again"
onPress=
{
checkAllPermissions
}
/>
<
Button
title=
"Check Again"
onPress=
{
checkAllPermissions
}
/>
{
Platform
.
OS
===
"ios"
&&
(
<>
<
Button
title=
"Reload Call Directory"
onPress=
{
reloadCallDirectory
}
/>
</>
)
}
</
View
>
</
View
>
);
);
}
}
...
...
android/app/src/main/java/com/whoscall/IncomingCallService.kt
View file @
b72847bb
...
@@ -23,8 +23,8 @@ class IncomingCallService : CallScreeningService() {
...
@@ -23,8 +23,8 @@ class IncomingCallService : CallScreeningService() {
// Lookup VIPs
// Lookup VIPs
// val prefs = getSharedPreferences("WhoscallPrefs", MODE_PRIVATE)
// val prefs = getSharedPreferences("WhoscallPrefs", MODE_PRIVATE)
val
vipNumber
=
"+601
08222562
"
val
vipNumber
=
"+601
64034061
"
val
vipName
=
"A
rvin
"
val
vipName
=
"A
lyp
"
Log
.
d
(
"IncomingCallReceiver"
,
"Looking up number: $number, Found VIPNumber: $vipNumber, Found VIPName: $vipName"
)
Log
.
d
(
"IncomingCallReceiver"
,
"Looking up number: $number, Found VIPNumber: $vipNumber, Found VIPName: $vipName"
)
// Only show overlay if VIP
// Only show overlay if VIP
...
...
android/app/src/main/java/com/whoscall/MainActivity.kt
View file @
b72847bb
...
@@ -8,6 +8,7 @@ import android.provider.Settings
...
@@ -8,6 +8,7 @@ import android.provider.Settings
import
android.app.role.RoleManager
import
android.app.role.RoleManager
import
androidx.activity.result.contract.ActivityResultContracts
import
androidx.activity.result.contract.ActivityResultContracts
import
com.facebook.react.ReactActivity
import
com.facebook.react.ReactActivity
import
android.os.Bundle
class
MainActivity
:
ReactActivity
()
{
class
MainActivity
:
ReactActivity
()
{
...
@@ -35,11 +36,24 @@ class MainActivity : ReactActivity() {
...
@@ -35,11 +36,24 @@ class MainActivity : ReactActivity() {
private
fun
requestCallScreeningRoleIfNeeded
()
{
private
fun
requestCallScreeningRoleIfNeeded
()
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
Q
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
Q
)
{
val
roleManager
=
getSystemService
(
Context
.
ROLE_SERVICE
)
as
RoleManager
val
roleManager
=
getSystemService
(
Context
.
ROLE_SERVICE
)
as
RoleManager
val
intent
=
roleManager
.
createRequestRoleIntent
(
RoleManager
.
ROLE_CALL_SCREENING
)
if
(!
roleManager
.
isRoleHeld
(
RoleManager
.
ROLE_CALL_SCREENING
))
{
roleLauncher
.
launch
(
intent
)
val
intent
=
roleManager
.
createRequestRoleIntent
(
RoleManager
.
ROLE_CALL_SCREENING
)
roleLauncher
.
launch
(
intent
)
}
}
}
}
}
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
// Ask for overlay if needed
requestOverlay
()
// Ask for call screening role if needed
requestCallScreeningRoleIfNeeded
()
}
private
fun
simulateVipCall
()
{
private
fun
simulateVipCall
()
{
val
vipNumber
=
"+60189884118"
val
vipNumber
=
"+60189884118"
val
vipName
=
"Wei Yi"
val
vipName
=
"Wei Yi"
...
...
android/app/src/main/java/com/whoscall/OverlayPermissionModule.kt
View file @
b72847bb
// OverlayPermissionModule.kt
package
com.whoscall
package
com.whoscall
import
android.content.Intent
import
com.facebook.react.bridge.ReactApplicationContext
import
android.net.Uri
import
com.facebook.react.bridge.ReactContextBaseJavaModule
import
com.facebook.react.bridge.ReactMethod
import
com.facebook.react.bridge.Promise
import
android.os.Build
import
android.os.Build
import
android.provider.Settings
import
android.provider.Settings
import
com.facebook.react.bridge.*
class
OverlayPermissionModule
(
private
val
reactContext
:
ReactApplicationContext
)
class
OverlayPermissionModule
(
reactContext
:
ReactApplicationContext
)
:
:
ReactContextBaseJavaModule
(
reactContext
)
{
ReactContextBaseJavaModule
(
reactContext
)
{
override
fun
getName
():
String
=
"OverlayPermission"
override
fun
getName
():
String
{
return
"OverlayPermission"
@ReactMethod
fun
hasOverlayPermission
(
promise
:
Promise
)
{
try
{
val
allowed
=
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
M
)
{
Settings
.
canDrawOverlays
(
reactContext
)
}
else
true
promise
.
resolve
(
allowed
)
}
catch
(
e
:
Exception
)
{
promise
.
reject
(
"OVERLAY_CHECK_ERROR"
,
e
)
}
}
}
@ReactMethod
@ReactMethod
fun
openOverlaySettings
()
{
fun
hasPermission
(
promise
:
Promise
)
{
try
{
val
canDraw
=
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
M
)
{
val
ctx
=
reactContext
.
currentActivity
?:
reactContext
Settings
.
canDrawOverlays
(
reactApplicationContext
)
val
intent
=
Intent
(
}
else
{
Settings
.
ACTION_MANAGE_OVERLAY_PERMISSION
,
true
Uri
.
parse
(
"package:${reactContext.packageName}"
)
}
).
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
)
promise
.
resolve
(
canDraw
)
ctx
.
startActivity
(
intent
)
}
}
catch
(
_
:
Exception
)
{
// best-effort
}
}
}
}
ios/whoscall.xcodeproj/project.pbxproj
View file @
b72847bb
...
@@ -366,6 +366,7 @@
...
@@ -366,6 +366,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME
=
AppIcon
;
ASSETCATALOG_COMPILER_APPICON_NAME
=
AppIcon
;
CLANG_ENABLE_MODULES
=
YES
;
CLANG_ENABLE_MODULES
=
YES
;
CURRENT_PROJECT_VERSION
=
1
;
CURRENT_PROJECT_VERSION
=
1
;
DEVELOPMENT_TEAM
=
SLK4N5KC2N
;
ENABLE_BITCODE
=
NO
;
ENABLE_BITCODE
=
NO
;
INFOPLIST_FILE
=
whoscall/Info.plist
;
INFOPLIST_FILE
=
whoscall/Info.plist
;
IPHONEOS_DEPLOYMENT_TARGET
=
15.1
;
IPHONEOS_DEPLOYMENT_TARGET
=
15.1
;
...
@@ -379,7 +380,7 @@
...
@@ -379,7 +380,7 @@
"-ObjC"
,
"-ObjC"
,
"-lc++"
,
"-lc++"
,
);
);
PRODUCT_BUNDLE_IDENTIFIER
=
"org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)"
;
PRODUCT_BUNDLE_IDENTIFIER
=
com.whoscall
;
PRODUCT_NAME
=
whoscall
;
PRODUCT_NAME
=
whoscall
;
SWIFT_OPTIMIZATION_LEVEL
=
"-Onone"
;
SWIFT_OPTIMIZATION_LEVEL
=
"-Onone"
;
SWIFT_VERSION
=
5.0
;
SWIFT_VERSION
=
5.0
;
...
@@ -394,6 +395,7 @@
...
@@ -394,6 +395,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME
=
AppIcon
;
ASSETCATALOG_COMPILER_APPICON_NAME
=
AppIcon
;
CLANG_ENABLE_MODULES
=
YES
;
CLANG_ENABLE_MODULES
=
YES
;
CURRENT_PROJECT_VERSION
=
1
;
CURRENT_PROJECT_VERSION
=
1
;
DEVELOPMENT_TEAM
=
SLK4N5KC2N
;
INFOPLIST_FILE
=
whoscall/Info.plist
;
INFOPLIST_FILE
=
whoscall/Info.plist
;
IPHONEOS_DEPLOYMENT_TARGET
=
15.1
;
IPHONEOS_DEPLOYMENT_TARGET
=
15.1
;
LD_RUNPATH_SEARCH_PATHS
=
(
LD_RUNPATH_SEARCH_PATHS
=
(
...
@@ -406,7 +408,7 @@
...
@@ -406,7 +408,7 @@
"-ObjC"
,
"-ObjC"
,
"-lc++"
,
"-lc++"
,
);
);
PRODUCT_BUNDLE_IDENTIFIER
=
"org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)"
;
PRODUCT_BUNDLE_IDENTIFIER
=
com.whoscall
;
PRODUCT_NAME
=
whoscall
;
PRODUCT_NAME
=
whoscall
;
SWIFT_VERSION
=
5.0
;
SWIFT_VERSION
=
5.0
;
VERSIONING_SYSTEM
=
"apple-generic"
;
VERSIONING_SYSTEM
=
"apple-generic"
;
...
@@ -427,6 +429,7 @@
...
@@ -427,6 +429,7 @@
CODE_SIGN_STYLE
=
Automatic
;
CODE_SIGN_STYLE
=
Automatic
;
CURRENT_PROJECT_VERSION
=
1
;
CURRENT_PROJECT_VERSION
=
1
;
DEBUG_INFORMATION_FORMAT
=
dwarf
;
DEBUG_INFORMATION_FORMAT
=
dwarf
;
DEVELOPMENT_TEAM
=
SLK4N5KC2N
;
ENABLE_USER_SCRIPT_SANDBOXING
=
YES
;
ENABLE_USER_SCRIPT_SANDBOXING
=
YES
;
GCC_C_LANGUAGE_STANDARD
=
gnu17
;
GCC_C_LANGUAGE_STANDARD
=
gnu17
;
GENERATE_INFOPLIST_FILE
=
YES
;
GENERATE_INFOPLIST_FILE
=
YES
;
...
@@ -443,7 +446,7 @@
...
@@ -443,7 +446,7 @@
MARKETING_VERSION
=
1.0
;
MARKETING_VERSION
=
1.0
;
MTL_ENABLE_DEBUG_INFO
=
INCLUDE_SOURCE
;
MTL_ENABLE_DEBUG_INFO
=
INCLUDE_SOURCE
;
MTL_FAST_MATH
=
YES
;
MTL_FAST_MATH
=
YES
;
PRODUCT_BUNDLE_IDENTIFIER
=
org.reactjs.native.example
.whoscall.whoscallDirectoryExtension
;
PRODUCT_BUNDLE_IDENTIFIER
=
com
.whoscall.whoscallDirectoryExtension
;
PRODUCT_NAME
=
"$(TARGET_NAME)"
;
PRODUCT_NAME
=
"$(TARGET_NAME)"
;
SKIP_INSTALL
=
YES
;
SKIP_INSTALL
=
YES
;
SWIFT_ACTIVE_COMPILATION_CONDITIONS
=
"DEBUG $(inherited)"
;
SWIFT_ACTIVE_COMPILATION_CONDITIONS
=
"DEBUG $(inherited)"
;
...
@@ -469,6 +472,7 @@
...
@@ -469,6 +472,7 @@
COPY_PHASE_STRIP
=
NO
;
COPY_PHASE_STRIP
=
NO
;
CURRENT_PROJECT_VERSION
=
1
;
CURRENT_PROJECT_VERSION
=
1
;
DEBUG_INFORMATION_FORMAT
=
"dwarf-with-dsym"
;
DEBUG_INFORMATION_FORMAT
=
"dwarf-with-dsym"
;
DEVELOPMENT_TEAM
=
SLK4N5KC2N
;
ENABLE_USER_SCRIPT_SANDBOXING
=
YES
;
ENABLE_USER_SCRIPT_SANDBOXING
=
YES
;
GCC_C_LANGUAGE_STANDARD
=
gnu17
;
GCC_C_LANGUAGE_STANDARD
=
gnu17
;
GENERATE_INFOPLIST_FILE
=
YES
;
GENERATE_INFOPLIST_FILE
=
YES
;
...
@@ -484,7 +488,7 @@
...
@@ -484,7 +488,7 @@
LOCALIZATION_PREFERS_STRING_CATALOGS
=
YES
;
LOCALIZATION_PREFERS_STRING_CATALOGS
=
YES
;
MARKETING_VERSION
=
1.0
;
MARKETING_VERSION
=
1.0
;
MTL_FAST_MATH
=
YES
;
MTL_FAST_MATH
=
YES
;
PRODUCT_BUNDLE_IDENTIFIER
=
org.reactjs.native.example
.whoscall.whoscallDirectoryExtension
;
PRODUCT_BUNDLE_IDENTIFIER
=
com
.whoscall.whoscallDirectoryExtension
;
PRODUCT_NAME
=
"$(TARGET_NAME)"
;
PRODUCT_NAME
=
"$(TARGET_NAME)"
;
SKIP_INSTALL
=
YES
;
SKIP_INSTALL
=
YES
;
SWIFT_COMPILATION_MODE
=
wholemodule
;
SWIFT_COMPILATION_MODE
=
wholemodule
;
...
...
ios/whoscallDirectoryExtension/CallDirectoryHandler.swift
View file @
b72847bb
#if os(iOS)
#if os(iOS)
#if os(iOS)
import
Foundation
import
Foundation
import
CallKit
import
CallKit
...
@@ -19,10 +20,7 @@ class CallDirectoryHandler: CXCallDirectoryProvider {
...
@@ -19,10 +20,7 @@ class CallDirectoryHandler: CXCallDirectoryProvider {
// Example: add VIP numbers
// Example: add VIP numbers
// Numbers must be E.164 format (+60 for Malaysia)
// Numbers must be E.164 format (+60 for Malaysia)
let
vipNumbers
:
[(
number
:
Int64
,
label
:
String
)]
=
[
let
vipNumbers
:
[(
number
:
Int64
,
label
:
String
)]
=
[
(
60189884118
,
"Wei Yi"
),
(
60189884118
,
"Wei Han"
),
(
60123456789
,
"Spam Caller"
),
(
60122553372
,
"Someone Else"
),
(
60123456789
,
"Scam Caller"
),
]
]
for
entry
in
vipNumbers
{
for
entry
in
vipNumbers
{
...
@@ -50,3 +48,4 @@ extension CallDirectoryHandler: CXCallDirectoryExtensionContextDelegate {
...
@@ -50,3 +48,4 @@ extension CallDirectoryHandler: CXCallDirectoryExtensionContextDelegate {
}
}
}
}
#endif
#endif
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment