NTP-38623 |copy changes| aman singh
This commit is contained in:
@@ -33,8 +33,11 @@
|
||||
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
|
||||
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"
|
||||
tools:ignore="QueryAllPackagesPermission" />
|
||||
<uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE" tools:ignore="ProtectedPermissions" />
|
||||
|
||||
<uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" tools:ignore="ProtectedPermissions" />
|
||||
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
|
||||
<queries>
|
||||
@@ -64,6 +67,12 @@
|
||||
android:name="com.supersami.foregroundservice.notification_color"
|
||||
android:resource="@color/blue"
|
||||
/>
|
||||
<receiver android:name=".CallReceiver" android:enabled="true" android:exported="false">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.PHONE_STATE" />
|
||||
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<service android:name="com.supersami.foregroundservice.ForegroundService" android:foregroundServiceType="location"></service>
|
||||
<service android:name="com.supersami.foregroundservice.ForegroundServiceTask" android:foregroundServiceType="location"></service>
|
||||
<provider
|
||||
|
||||
161
android/app/src/main/java/com/avapp/CallReceiver.java
Normal file
161
android/app/src/main/java/com/avapp/CallReceiver.java
Normal file
@@ -0,0 +1,161 @@
|
||||
package com.avapp;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.telecom.TelecomManager;
|
||||
import android.util.Log;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
|
||||
public class CallReceiver extends BroadcastReceiver {
|
||||
|
||||
private static String lastState = null; // Store the last known call state
|
||||
private static JSONObject lastCallData = null; // Store the last call data to avoid duplicates
|
||||
private static String lastNumber = null; // Store the phone number (for both incoming/outgoing)
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Log.d("CALL_RECEIVER", "onReceive: Callback received");
|
||||
|
||||
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
|
||||
String incomingNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
|
||||
String outgoingNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
|
||||
long timestamp = new Date().getTime(); // Capture the timestamp
|
||||
|
||||
// Retain the number depending on whether it's incoming or outgoing
|
||||
if (incomingNumber != null) {
|
||||
lastNumber = incomingNumber; // Save incoming number when the phone is ringing
|
||||
}
|
||||
if (outgoingNumber != null) {
|
||||
lastNumber = outgoingNumber; // Save outgoing number when dialing
|
||||
}
|
||||
|
||||
// Get default dialer information
|
||||
String defaultDialer = getDefaultDialer(context);
|
||||
|
||||
// Handle call in progress (OFFHOOK state for both incoming and outgoing)
|
||||
if (state != null && TelephonyManager.EXTRA_STATE_OFFHOOK.equals(state)) {
|
||||
Log.d("CALL_RECEIVER", "Call in progress (OFFHOOK event detected)");
|
||||
|
||||
// Proceed only if we have a valid phone number
|
||||
if (lastNumber != null && !lastNumber.isEmpty()) {
|
||||
JSONObject callData = new JSONObject();
|
||||
try {
|
||||
callData.put("type", "offhook");
|
||||
callData.put("number", lastNumber);
|
||||
callData.put("timestamp", timestamp);
|
||||
callData.put("defaultDialer", defaultDialer);
|
||||
|
||||
// Save the call data
|
||||
if (!isDuplicateCall(lastNumber)) {
|
||||
saveToJsonFile(context, callData);
|
||||
lastCallData = callData; // Store the last saved call data to prevent duplicates
|
||||
}
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Reset the phone number when the call ends (optional)
|
||||
if (TelephonyManager.EXTRA_STATE_IDLE.equals(state)) {
|
||||
lastNumber = null; // Reset the number when the call ends
|
||||
lastCallData = null;
|
||||
}
|
||||
|
||||
// Update the last state
|
||||
lastState = state;
|
||||
}
|
||||
|
||||
// Modify isDuplicateCall to check only the phone number
|
||||
private boolean isDuplicateCall(String currentNumber) {
|
||||
// Check if the last call data exists and compare phone numbers
|
||||
if (lastCallData == null) {
|
||||
return false; // No previous call, so it's not a duplicate
|
||||
}
|
||||
|
||||
try {
|
||||
String lastCallNumber = lastCallData.getString("number");
|
||||
return lastCallNumber.equals(currentNumber); // Return true if the numbers match
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return false; // Default to false if any error occurs
|
||||
}
|
||||
|
||||
private String getDefaultDialer(Context context) {
|
||||
TelecomManager telecomManager = (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
|
||||
return telecomManager != null ? telecomManager.getDefaultDialerPackage() : "Unknown";
|
||||
}
|
||||
|
||||
private void saveToJsonFile(Context context, JSONObject newCallData) throws JSONException {
|
||||
Log.d("CALL_RECEIVER", "saveToJsonFile: JSON ::::::" + newCallData.toString());
|
||||
|
||||
// Define the file where JSON data will be saved
|
||||
File jsonFile = new File(context.getCacheDir(), "call_data.json");
|
||||
|
||||
JSONArray jsonArray = new JSONArray(); // Initialize an empty array to store all calls
|
||||
|
||||
// Read existing data from the JSON file
|
||||
if (jsonFile.exists()) {
|
||||
FileReader reader = null;
|
||||
try {
|
||||
reader = new FileReader(jsonFile);
|
||||
char[] buffer = new char[(int) jsonFile.length()];
|
||||
reader.read(buffer);
|
||||
String fileContent = new String(buffer);
|
||||
|
||||
if (!fileContent.isEmpty()) {
|
||||
// If the file has content, parse it as an existing JSONArray
|
||||
jsonArray = new JSONArray(fileContent);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (reader != null) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Append the new call data to the existing array
|
||||
jsonArray.put(newCallData);
|
||||
|
||||
// Write the updated array back to the JSON file
|
||||
FileWriter fileWriter = null;
|
||||
try {
|
||||
fileWriter = new FileWriter(jsonFile, false); // Overwrite the file with new data
|
||||
fileWriter.write(jsonArray.toString(4)); // Write the array with indentation for readability
|
||||
fileWriter.flush();
|
||||
Log.d("CALL_RECEIVER", "saveToJsonFile: Data saved to JSON file");
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (fileWriter != null) {
|
||||
try {
|
||||
fileWriter.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1491,6 +1491,10 @@ export const CLICKSTREAM_EVENT_NAMES = {
|
||||
FA_COSMOS_DEFAULT_DIALER: {
|
||||
name: 'FA_COSMOS_DEFAULT_DIALER',
|
||||
description: 'Cosmos default dialer',
|
||||
},
|
||||
FA_COSMOS_CONNECTED_CALL_EVENTS: {
|
||||
name: 'FA_COSMOS_CONNECTED_CALL_EVENTS',
|
||||
description: 'Cosmos connected call events',
|
||||
}
|
||||
} as const;
|
||||
|
||||
|
||||
@@ -110,8 +110,19 @@ const TrackingComponent: React.FC<ITrackingComponent> = ({ children }) => {
|
||||
|
||||
const checkDefaultDialerApp = async () => {
|
||||
const defaultDialer = await getDefaultCallingApp();
|
||||
const path = RNFS.CachesDirectoryPath + '/call_data.json'; // Path to your file
|
||||
// Read the JSON file
|
||||
RNFS.readFile(path).then((contents) => {
|
||||
addClickstreamEvent(CLICKSTREAM_EVENT_NAMES.FA_COSMOS_CONNECTED_CALL_EVENTS, {
|
||||
data: JSON.stringify(contents)
|
||||
});
|
||||
RNFS.unlink(path);
|
||||
}).catch((err) => {
|
||||
console.error('Error reading file:', err);
|
||||
});
|
||||
|
||||
addClickstreamEvent(CLICKSTREAM_EVENT_NAMES.FA_COSMOS_DEFAULT_DIALER, {
|
||||
defaultDialer,
|
||||
defaultDialer
|
||||
});
|
||||
};
|
||||
|
||||
@@ -248,7 +259,7 @@ const TrackingComponent: React.FC<ITrackingComponent> = ({ children }) => {
|
||||
{
|
||||
taskId: FOREGROUND_TASKS.DEFAULT_DIALER_APP,
|
||||
task: checkDefaultDialerApp,
|
||||
delay: 5 * MILLISECONDS_IN_A_MINUTE, // 5 minutes
|
||||
delay: 0.5 * MILLISECONDS_IN_A_MINUTE, // 5 minutes
|
||||
onLoop: true,
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user