blob: a1f82f2e10302d9b515601fe230dc909984e9f30 [file] [log] [blame]
Venkateshwarlu Domakondaaa253632013-03-25 16:53:03 +05301/*
2 * Copyright (c) 2009-2012, The Linux Foundation. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
11 * * Neither the name of The Linux Foundation nor
12 * the names of its contributors may be used to endorse or promote
13 * products derived from this software without specific prior written
14 * permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29package qcom.fmradio;
Satish kumar sugasi644b4882016-05-04 20:15:31 -070030import android.util.Log;
31import java.util.Arrays;
32import java.lang.Runnable;
33import qcom.fmradio.FmReceiver;
Venkateshwarlu Domakondaaa253632013-03-25 16:53:03 +053034
35class FmReceiverJNI {
36 /**
37 * General success
38 */
39 static final int FM_JNI_SUCCESS = 0;
40
41 /**
42 * General failure
43 */
44 static final int FM_JNI_FAILURE = -1;
45
46 /**
47 * native method: Open device
48 * @return The file descriptor of the device
49 *
50 */
Satish kumar sugasi10da44e2016-03-14 17:52:50 -070051 private static final String TAG = "FmReceiverJNI";
Venkateshwarlu Domakondaaa253632013-03-25 16:53:03 +053052
Satish kumar sugasi644b4882016-05-04 20:15:31 -070053 static {
Satish kumar sugasi10da44e2016-03-14 17:52:50 -070054 Log.d(TAG, "classinit native called");
Satish kumar sugasi644b4882016-05-04 20:15:31 -070055 classInitNative();
56 }
57 static native void classInitNative();
58 static native void initNative();
59 static native void cleanupNative();
60
himta ramaf268f22018-05-15 13:20:19 +053061 private FmRxEvCallbacks mCallback;
Satish kumar sugasi644b4882016-05-04 20:15:31 -070062 static private final int STD_BUF_SIZE = 256;
63 static private byte[] mRdsBuffer = new byte[STD_BUF_SIZE];
64
65 public static byte[] getPsBuffer(byte[] buff) {
Satish kumar sugasi10da44e2016-03-14 17:52:50 -070066 Log.d(TAG, "getPsBuffer enter");
Satish kumar sugasi644b4882016-05-04 20:15:31 -070067 buff = Arrays.copyOf(mRdsBuffer, mRdsBuffer.length);
Satish kumar sugasi10da44e2016-03-14 17:52:50 -070068 Log.d(TAG, "getPsBuffer exit");
Satish kumar sugasi644b4882016-05-04 20:15:31 -070069 return buff;
70 }
71
72 public void AflistCallback(byte[] aflist) {
73 Log.e(TAG, "AflistCallback enter " );
74 if (aflist == null) {
75 Log.e(TAG, "aflist null return ");
76 return;
77 }
78 mRdsBuffer = Arrays.copyOf(aflist, aflist.length);
79 FmReceiver.mCallback.FmRxEvRdsAfInfo();
80 Log.e(TAG, "AflistCallback exit " );
81 }
82
Kamal Negi8813e0f2016-02-10 19:12:09 +053083 public void getSigThCallback(int val, int status)
84 {
85 Log.d(TAG, "get Signal Threshold callback");
86
87 FmReceiver.mCallback.FmRxEvGetSignalThreshold(val, status);
88 }
89
90 public void getChDetThCallback(int val, int status)
91 {
92 FmReceiver.mCallback.FmRxEvGetChDetThreshold(val, status);
93 }
94
95 public void setChDetThCallback(int status)
96 {
97 FmReceiver.mCallback.FmRxEvSetChDetThreshold(status);
98 }
99
100 public void DefDataRdCallback(int val, int status)
101 {
102 FmReceiver.mCallback.FmRxEvDefDataRead(val, status);
103 }
104
105 public void DefDataWrtCallback(int status)
106 {
107 FmReceiver.mCallback.FmRxEvDefDataWrite(status);
108 }
109
110 public void getBlendCallback(int val, int status)
111 {
112 FmReceiver.mCallback.FmRxEvGetBlend(val, status);
113 }
114
115 public void setBlendCallback(int status)
116 {
117 FmReceiver.mCallback.FmRxEvSetBlend(status);
118 }
119
120 public void getStnParamCallback(int val, int status)
121 {
122 FmReceiver.mCallback.FmRxGetStationParam(val, status);
123 }
124
125 public void getStnDbgParamCallback(int val, int status)
126 {
127 FmReceiver.mCallback.FmRxGetStationDbgParam(val, status);
128 }
129
Rupesh Tatiya9917f922017-06-21 13:00:43 +0530130 public void enableSlimbusCallback(int status)
131 {
132 Log.d(TAG, "++enableSlimbusCallback" );
133 FmReceiver.mCallback.FmRxEvEnableSlimbus(status);
134 Log.d(TAG, "--enableSlimbusCallback" );
135 }
136
himta ram56984632018-03-19 13:07:29 +0530137 public void enableSoftMuteCallback(int status)
138 {
139 Log.d(TAG, "++enableSoftMuteCallback" );
140 FmReceiver.mCallback.FmRxEvEnableSoftMute(status);
141 Log.d(TAG, "--enableSoftMuteCallback" );
142 }
143
Satish kumar sugasi644b4882016-05-04 20:15:31 -0700144 public void RtPlusCallback(byte[] rtplus) {
Satish kumar sugasi10da44e2016-03-14 17:52:50 -0700145 Log.d(TAG, "RtPlusCallback enter " );
Satish kumar sugasi644b4882016-05-04 20:15:31 -0700146 if (rtplus == null) {
147 Log.e(TAG, "psInfo null return ");
148 return;
149 }
150 mRdsBuffer = Arrays.copyOf(rtplus, rtplus.length);
151 FmReceiver.mCallback.FmRxEvRTPlus();
Satish kumar sugasi10da44e2016-03-14 17:52:50 -0700152 Log.d(TAG, "RtPlusCallback exit " );
Satish kumar sugasi644b4882016-05-04 20:15:31 -0700153 }
154
155 public void RtCallback(byte[] rt) {
Satish kumar sugasi10da44e2016-03-14 17:52:50 -0700156 Log.d(TAG, "RtCallback enter " );
Satish kumar sugasi644b4882016-05-04 20:15:31 -0700157 if (rt == null) {
158 Log.e(TAG, "psInfo null return ");
159 return;
160 }
161 mRdsBuffer = Arrays.copyOf(rt, rt.length);
162 FmReceiver.mCallback.FmRxEvRdsRtInfo();
Satish kumar sugasi10da44e2016-03-14 17:52:50 -0700163 Log.d(TAG, "RtCallback exit " );
Satish kumar sugasi644b4882016-05-04 20:15:31 -0700164 }
165
166 public void ErtCallback(byte[] ert) {
Satish kumar sugasi10da44e2016-03-14 17:52:50 -0700167 Log.d(TAG, "ErtCallback enter " );
Satish kumar sugasi644b4882016-05-04 20:15:31 -0700168 if (ert == null) {
169 Log.e(TAG, "ERT null return ");
170 return;
171 }
172 mRdsBuffer = Arrays.copyOf(ert, ert.length);
173 FmReceiver.mCallback.FmRxEvERTInfo();
Satish kumar sugasi10da44e2016-03-14 17:52:50 -0700174 Log.d(TAG, "RtCallback exit " );
Satish kumar sugasi644b4882016-05-04 20:15:31 -0700175 }
176
Satish kumar sugasid8731b72016-01-27 14:45:45 -0800177 public void EccCallback(byte[] ecc) {
178 Log.i(TAG, "EccCallback enter " );
179 if (ecc == null) {
180 Log.e(TAG, "ECC null return ");
181 return;
182 }
183 mRdsBuffer = Arrays.copyOf(ecc, ecc.length);
184 FmReceiver.mCallback.FmRxEvECCInfo();
185 Log.i(TAG, "EccCallback exit " );
186 }
187
Satish kumar sugasi644b4882016-05-04 20:15:31 -0700188 public void PsInfoCallback(byte[] psInfo) {
Satish kumar sugasi10da44e2016-03-14 17:52:50 -0700189 Log.d(TAG, "PsInfoCallback enter " );
Satish kumar sugasi644b4882016-05-04 20:15:31 -0700190 if (psInfo == null) {
191 Log.e(TAG, "psInfo null return ");
192 return;
193 }
194 Log.e(TAG, "length = " +psInfo.length);
195 mRdsBuffer = Arrays.copyOf(psInfo, psInfo.length);
196 FmReceiver.mCallback.FmRxEvRdsPsInfo();
Satish kumar sugasi10da44e2016-03-14 17:52:50 -0700197 Log.d(TAG, "PsInfoCallback exit");
Satish kumar sugasi644b4882016-05-04 20:15:31 -0700198 }
199
200 public void enableCallback() {
Satish kumar sugasi10da44e2016-03-14 17:52:50 -0700201 Log.d(TAG, "enableCallback enter");
Satish kumar sugasi644b4882016-05-04 20:15:31 -0700202 FmTransceiver.setFMPowerState(FmTransceiver.FMState_Rx_Turned_On);
203 Log.v(TAG, "RxEvtList: CURRENT-STATE : FMRxStarting ---> NEW-STATE : FMRxOn");
204 FmReceiver.mCallback.FmRxEvEnableReceiver();
Satish kumar sugasi10da44e2016-03-14 17:52:50 -0700205 Log.d(TAG, "enableCallback exit");
Satish kumar sugasi644b4882016-05-04 20:15:31 -0700206 }
207
208 public void tuneCallback(int freq) {
209 int state;
Satish kumar sugasi10da44e2016-03-14 17:52:50 -0700210 Log.d(TAG, "tuneCallback enter");
Satish kumar sugasi644b4882016-05-04 20:15:31 -0700211 state = FmReceiver.getSearchState();
212 switch(state) {
213 case FmTransceiver.subSrchLevel_SrchAbort:
214 Log.v(TAG, "Current state is SRCH_ABORTED");
215 Log.v(TAG, "Aborting on-going search command...");
216 /* intentional fall through */
217 case FmTransceiver.subSrchLevel_SeekInPrg :
218 Log.v(TAG, "Current state is " + state);
219 FmReceiver.setSearchState(FmTransceiver.subSrchLevel_SrchComplete);
220 Log.v(TAG, "RxEvtList: CURRENT-STATE : Search ---> NEW-STATE : FMRxOn");
221 FmReceiver.mCallback.FmRxEvSearchComplete(freq);
222 break;
223 default:
224 if (freq > 0)
225 FmReceiver.mCallback.FmRxEvRadioTuneStatus(freq);
226 else
227 Log.e(TAG, "get frequency command failed");
228 break;
229 }
Satish kumar sugasi10da44e2016-03-14 17:52:50 -0700230 Log.d(TAG, "tuneCallback exit");
Satish kumar sugasi644b4882016-05-04 20:15:31 -0700231 }
232
233 public void seekCmplCallback(int freq) {
234 int state;
235
Satish kumar sugasi10da44e2016-03-14 17:52:50 -0700236 Log.d(TAG, "seekCmplCallback enter");
Satish kumar sugasi644b4882016-05-04 20:15:31 -0700237 state = FmReceiver.getSearchState();
Satish kumar sugasi44497e42016-10-18 23:11:59 -0700238 switch (state) {
Satish kumar sugasi644b4882016-05-04 20:15:31 -0700239 case FmTransceiver.subSrchLevel_ScanInProg:
240 Log.v(TAG, "Current state is " + state);
241 FmReceiver.setSearchState(FmTransceiver.subSrchLevel_SrchComplete);
242 Log.v(TAG, "RxEvtList: CURRENT-STATE : Search ---> NEW-STATE :FMRxOn");
243 FmReceiver.mCallback.FmRxEvSearchComplete(freq);
244 break;
245 case FmTransceiver.subSrchLevel_SrchAbort:
246 Log.v(TAG, "Current state is SRCH_ABORTED");
247 Log.v(TAG, "Aborting on-going search command...");
248 FmReceiver.setSearchState(FmTransceiver.subSrchLevel_SrchComplete);
249 Log.v(TAG, "RxEvtList: CURRENT-STATE : Search ---> NEW-STATE : FMRxOn");
250 FmReceiver.mCallback.FmRxEvSearchComplete(freq);
251 break;
252 }
Satish kumar sugasi10da44e2016-03-14 17:52:50 -0700253 Log.d(TAG, "seekCmplCallback exit");
Satish kumar sugasi644b4882016-05-04 20:15:31 -0700254 }
255
Satish kumar sugasi44497e42016-10-18 23:11:59 -0700256 public void srchListCallback(byte[] scan_tbl) {
257 int state;
258 state = FmReceiver.getSearchState();
259 switch (state) {
260 case FmTransceiver.subSrchLevel_SrchListInProg:
261 Log.v(TAG, "FmRxEventListener: Current state is AUTO_PRESET_INPROGRESS");
262 FmReceiver.setSearchState(FmTransceiver.subSrchLevel_SrchComplete);
263 Log.v(TAG, "RxEvtList: CURRENT-STATE : Search ---> NEW-STATE : FMRxOn");
264 FmReceiver.mCallback.FmRxEvSearchListComplete();
265 break;
266 case FmTransceiver.subSrchLevel_SrchAbort:
267 Log.v(TAG, "Current state is SRCH_ABORTED");
268 Log.v(TAG, "Aborting on-going SearchList command...");
269 FmReceiver.setSearchState(FmTransceiver.subSrchLevel_SrchComplete);
270 Log.v(TAG, "RxEvtList: CURRENT-STATE : Search ---> NEW-STATE : FMRxOn");
271 FmReceiver.mCallback.FmRxEvSearchCancelled();
272 break;
273 }
274 }
275
Satish kumar sugasi644b4882016-05-04 20:15:31 -0700276 public void scanNxtCallback() {
Satish kumar sugasi10da44e2016-03-14 17:52:50 -0700277 Log.d(TAG, "scanNxtCallback enter");
Satish kumar sugasi644b4882016-05-04 20:15:31 -0700278 FmReceiver.mCallback.FmRxEvSearchInProgress();
Satish kumar sugasi10da44e2016-03-14 17:52:50 -0700279 Log.d(TAG, "scanNxtCallback exit");
Satish kumar sugasi644b4882016-05-04 20:15:31 -0700280 }
281
282 public void stereostsCallback(boolean stereo) {
Satish kumar sugasi10da44e2016-03-14 17:52:50 -0700283 Log.d(TAG, "stereostsCallback enter");
Satish kumar sugasi644b4882016-05-04 20:15:31 -0700284 FmReceiver.mCallback.FmRxEvStereoStatus (stereo);
Satish kumar sugasi10da44e2016-03-14 17:52:50 -0700285 Log.d(TAG, "stereostsCallback exit");
Satish kumar sugasi644b4882016-05-04 20:15:31 -0700286 }
287
288 public void rdsAvlStsCallback(boolean rdsAvl) {
Satish kumar sugasi10da44e2016-03-14 17:52:50 -0700289 Log.d(TAG, "rdsAvlStsCallback enter");
Satish kumar sugasi644b4882016-05-04 20:15:31 -0700290 FmReceiver.mCallback.FmRxEvRdsLockStatus(rdsAvl);
Satish kumar sugasi10da44e2016-03-14 17:52:50 -0700291 Log.d(TAG, "rdsAvlStsCallback exit");
Satish kumar sugasi644b4882016-05-04 20:15:31 -0700292 }
293
294 public void disableCallback() {
Satish kumar sugasi10da44e2016-03-14 17:52:50 -0700295 Log.d(TAG, "disableCallback enter");
Satish kumar sugasi8a34ad32015-10-19 18:09:49 -0700296 if (FmTransceiver.getFMPowerState() == FmTransceiver.subPwrLevel_FMTurning_Off) {
297 /*Set the state as FMOff */
298 FmTransceiver.setFMPowerState(FmTransceiver.FMState_Turned_Off);
299 Log.v(TAG, "RxEvtList: CURRENT-STATE : FMTurningOff ---> NEW-STATE : FMOff");
300 FmReceiver.mCallback.FmRxEvDisableReceiver();
301 } else {
302 FmTransceiver.setFMPowerState(FmTransceiver.FMState_Turned_Off);
303 Log.d(TAG, "Unexpected RADIO_DISABLED recvd");
304 Log.v(TAG, "RxEvtList: CURRENT-STATE : FMRxOn ---> NEW-STATE : FMOff");
305 FmReceiver.mCallback.FmRxEvRadioReset();
Satish kumar sugasi10da44e2016-03-14 17:52:50 -0700306 Log.d(TAG, "disableCallback exit");
Satish kumar sugasi8a34ad32015-10-19 18:09:49 -0700307 }
Satish kumar sugasi644b4882016-05-04 20:15:31 -0700308 }
309
310 public FmReceiverJNI(FmRxEvCallbacks callback) {
311 mCallback = callback;
312 if (mCallback == null)
313 Log.e(TAG, "mCallback is null in JNI");
Satish kumar sugasi10da44e2016-03-14 17:52:50 -0700314 Log.d(TAG, "init native called");
Satish kumar sugasi644b4882016-05-04 20:15:31 -0700315 initNative();
316 }
317
himta ramaf268f22018-05-15 13:20:19 +0530318 public FmReceiverJNI() {
319 Log.d(TAG, "FmReceiverJNI constructor called");
320 }
321
Venkateshwarlu Domakondaaa253632013-03-25 16:53:03 +0530322 /**
323 * native method:
324 * @param fd
325 * @param control
326 * @param field
327 * @return
328 */
329 static native int audioControlNative(int fd, int control, int field);
330
331 /**
332 * native method: cancels search
333 * @param fd file descriptor of device
334 * @return May return
335 * {@link #FM_JNI_SUCCESS}
336 * {@link #FM_JNI_FAILURE}
337 */
338 static native int cancelSearchNative(int fd);
339
340 /**
Venkateshwarlu Domakondaaa253632013-03-25 16:53:03 +0530341 * native method: get frequency
342 * @param fd file descriptor of device
343 * @return Returns frequency in int form
344 */
345 static native int getFreqNative(int fd);
346
347 /**
348 * native method: set frequency
349 * @param fd file descriptor of device
350 * @param freq freq to be set in int form
351 * @return {@link #FM_JNI_SUCCESS}
352 * {@link #FM_JNI_FAILURE}
353 *
354 */
355 static native int setFreqNative(int fd, int freq);
356
357 /**
358 * native method: get v4l2 control
359 * @param fd file descriptor of device
360 * @param id v4l2 id to be retrieved
361 * @return Returns current value of the
362 * v4l2 control
363 */
364 static native int getControlNative (int fd, int id);
365
366 /**
367 * native method: set v4l2 control
368 * @param fd file descriptor of device
369 * @param id v4l2 control to be set
370 * @param value value to be set
371 * @return {@link #FM_JNI_SUCCESS}
372 * {@link #FM_JNI_FAILURE}
373 */
374 static native int setControlNative (int fd, int id, int value);
375
376 /**
377 * native method: start search
378 * @param fd file descriptor of device
379 * @param dir search direction
380 * @return {@link #FM_JNI_SUCCESS}
381 * {@link #FM_JNI_FAILURE}
382 */
383 static native int startSearchNative (int fd, int dir);
384
385 /**
Venkateshwarlu Domakondaaa253632013-03-25 16:53:03 +0530386 * native method: get RSSI value of the
387 * received signal
388 * @param fd file descriptor of device
389 * @return Returns signal strength in int form
390 * Signal value range from -120 to 10
391 */
392 static native int getRSSINative (int fd);
393
394 /**
395 * native method: set FM band
396 * @param fd file descriptor of device
397 * @param low lower band
398 * @param high higher band
399 * @return {@link #FM_JNI_SUCCESS}
400 * {@link #FM_JNI_FAILURE}
401 */
402 static native int setBandNative (int fd, int low, int high);
403
404 /**
405 * native method: get lower band
406 * @param fd file descriptor of device
407 * @return Returns lower band in int form
408 */
409 static native int getLowerBandNative (int fd);
410
411 /**
412 * native method: get upper band
413 * @param fd file descriptor of device
414 * @return Returns upper band in int form
415 */
416 static native int getUpperBandNative (int fd);
417
418 /**
419 * native method: force Mono/Stereo mode
420 * @param fd file descriptor of device
421 * @param val force mono/stereo indicator
422 * @return {@link #FM_JNI_SUCCESS}
423 * {@link #FM_JNI_FAILURE}
424 */
425 static native int setMonoStereoNative (int fd, int val);
426
427 /**
428 * native method: get Raw RDS data
429 * @param fd file descriptor of device
430 * @param buff[] buffer
431 * @param count number of bytes to be read
432 * @return Returns number of bytes read
433 */
434 static native int getRawRdsNative (int fd, byte buff[], int count);
435
Venkateshwarlu Domakondaaa253632013-03-25 16:53:03 +0530436 /**
437 * native method: Sets the repeat count for Programme service
438 * transmission.
439 * @param fd file descriptor of device
440 * @param repeatcount number of times PS string to be transmited
441 * repeatedly.
442 * @return {@link #FM_JNI_SUCCESS}
443 * {@link #FM_JNI_FAILURE}
444 */
445 static native int setPSRepeatCountNative(int fd, int repeatCount);
446 /**
447 * native method: Sets the power level for the tramsmitter
448 * transmission.
449 * @param fd file descriptor of device
450 * @param powLevel is the level at which transmitter operates.
451 * @return {@link #FM_JNI_SUCCESS}
452 * {@link #FM_JNI_FAILURE}
453 */
454 static native int setTxPowerLevelNative(int fd, int powLevel);
Venkateshwarlu Domakondaaa253632013-03-25 16:53:03 +0530455
456 /**
457 * native method: Configures the spur table
458 * @param fd file descriptor of device
459 * @return {@link #FM_JNI_SUCCESS}
460 * {@link #FM_JNI_FAILURE}
461 */
462 static native int configureSpurTable(int fd);
Venkateshwarlu Domakondac748b4b2014-05-19 10:41:10 +0530463
464 /**
465 * native method: Configures the new spur table
466 * @param fd file descriptor of device
467 * @return {@link #FM_JNI_SUCCESS}
468 * {@link #FM_JNI_FAILURE}
469 */
470 static native int setSpurDataNative(int fd, short buff[], int len);
Kamal Negice09c302016-12-29 16:45:38 +0530471 static native int enableSlimbus(int fd, int val);
himta ram56984632018-03-19 13:07:29 +0530472 static native int enableSoftMute(int fd, int val);
Venkateshwarlu Domakondaaa253632013-03-25 16:53:03 +0530473}