Skip to content

Commit b172b1a

Browse files
committed
Added flow to start recording during ongoing call and some state validations on recording start
1 parent 796a784 commit b172b1a

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

src/com/callrecorder/android/Constants.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ public class Constants {
3232
public static final int STATE_INCOMING_NUMBER = 1;
3333
public static final int STATE_CALL_START = 2;
3434
public static final int STATE_CALL_END = 3;
35-
public static final int STATE_STOP_RECORDING = 4;
36-
public static final int RECORDING_ENABLED = 5;
37-
public static final int RECORDING_DISABLED = 6;
35+
public static final int STATE_START_RECORDING = 4;
36+
public static final int STATE_STOP_RECORDING = 5;
37+
public static final int RECORDING_ENABLED = 6;
38+
public static final int RECORDING_DISABLED = 7;
3839

3940
}

src/com/callrecorder/android/MainActivity.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ public void onCreate(Bundle savedInstanceState) {
7878
Constants.LISTEN_ENABLED, 0);
7979
boolean silentMode = settings.getBoolean("silentMode", true);
8080

81-
if (silentMode) showDialog(CATEGORY_DETAIL);
81+
if (silentMode)
82+
showDialog(CATEGORY_DETAIL);
8283

8384
context = this.getBaseContext();
8485
// showDialog(TERMS);
@@ -281,6 +282,7 @@ private void setSharedPreferences(boolean silentMode) {
281282
myIntent.putExtra("commandType",
282283
silentMode ? Constants.RECORDING_DISABLED
283284
: Constants.RECORDING_ENABLED);
285+
myIntent.putExtra("silentMode", silentMode);
284286
context.startService(myIntent);
285287
}
286288

src/com/callrecorder/android/RecordService.java

+20-11
Original file line numberDiff line numberDiff line change
@@ -55,34 +55,37 @@ public void onCreate() {
5555

5656
@Override
5757
public int onStartCommand(Intent intent, int flags, int startId) {
58+
Log.d(Constants.TAG, "RecordService onStartCommand");
5859
if (intent != null) {
5960
int commandType = intent.getIntExtra("commandType", 0);
6061
if (commandType != 0) {
61-
Log.d(Constants.TAG, "RecordService onStartCommand");
6262
if (commandType == Constants.RECORDING_ENABLED) {
6363
Log.d(Constants.TAG, "RecordService RECORDING_ENABLED");
64-
silentMode = false;
65-
if (onCall && phoneNumber != null && !recording)
66-
commandType = Constants.STATE_CALL_START;
64+
silentMode = intent.getBooleanExtra("silentMode", true);
65+
if (!silentMode && phoneNumber != null && onCall
66+
&& !recording)
67+
commandType = Constants.STATE_START_RECORDING;
68+
6769
} else if (commandType == Constants.RECORDING_DISABLED) {
6870
Log.d(Constants.TAG, "RecordService RECORDING_DISABLED");
69-
silentMode = true;
70-
if (onCall && phoneNumber != null)
71+
silentMode = intent.getBooleanExtra("silentMode", true);
72+
if (onCall && phoneNumber != null && recording)
7173
commandType = Constants.STATE_STOP_RECORDING;
7274
}
73-
75+
7476
if (commandType == Constants.STATE_INCOMING_NUMBER) {
75-
startService();
7677
Log.d(Constants.TAG, "RecordService STATE_INCOMING_NUMBER");
78+
startService();
7779
if (phoneNumber == null)
7880
phoneNumber = intent.getStringExtra("phoneNumber");
79-
81+
8082
silentMode = intent.getBooleanExtra("silentMode", true);
8183
} else if (commandType == Constants.STATE_CALL_START) {
8284
Log.d(Constants.TAG, "RecordService STATE_CALL_START");
8385
onCall = true;
84-
85-
if (!silentMode && phoneNumber != null) {
86+
87+
if (!silentMode && phoneNumber != null && onCall
88+
&& !recording) {
8689
startService();
8790
startRecording(intent);
8891
}
@@ -93,6 +96,12 @@ public int onStartCommand(Intent intent, int flags, int startId) {
9396
stopAndReleaseRecorder();
9497
recording = false;
9598
stopService();
99+
} else if (commandType == Constants.STATE_START_RECORDING) {
100+
Log.d(Constants.TAG, "RecordService STATE_START_RECORDING");
101+
if (!silentMode && phoneNumber != null && onCall) {
102+
startService();
103+
startRecording(intent);
104+
}
96105
} else if (commandType == Constants.STATE_STOP_RECORDING) {
97106
Log.d(Constants.TAG, "RecordService STATE_STOP_RECORDING");
98107
stopAndReleaseRecorder();

0 commit comments

Comments
 (0)