diff --git a/Android.bp b/Android.bp index e3a714e..b60e265 100755 --- a/Android.bp +++ b/Android.bp @@ -13,7 +13,7 @@ android_app { proprietary: true, - srcs: ["src/**/*.java"], + srcs: ["src/**/*.kt"], static_libs: ["vendor.qti.hardware.radio.am-V1.0-java"], diff --git a/src/com/sony/qcrilam/BootReceiver.java b/src/com/sony/qcrilam/BootReceiver.java deleted file mode 100644 index 67b210b..0000000 --- a/src/com/sony/qcrilam/BootReceiver.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.sony.qcrilam; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.util.Log; - -public class BootReceiver extends BroadcastReceiver { - private static final String TAG = "QcRilAm-BootReceiver"; - - @Override - public void onReceive(Context context, Intent intent) { - if (context == null || intent == null) { - Log.w(TAG, "BOOT_COMPLETE NULL intent"); - return; - } - - context.startService(new Intent(context, QcRilAmService.class)); - } -} diff --git a/src/com/sony/qcrilam/BootReceiver.kt b/src/com/sony/qcrilam/BootReceiver.kt new file mode 100644 index 0000000..f5ef8fe --- /dev/null +++ b/src/com/sony/qcrilam/BootReceiver.kt @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2018-2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Rewritten in Kotlin by Pavel Dubrova + */ + +package com.sony.qcrilam + +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent + +class BootReceiver : BroadcastReceiver() { + override fun onReceive(context: Context, intent: Intent?) { + context.startService(Intent(context, QcRilAmService::class.java)) + } +} diff --git a/src/com/sony/qcrilam/QcRilAmService.java b/src/com/sony/qcrilam/QcRilAmService.java deleted file mode 100644 index 471c0a9..0000000 --- a/src/com/sony/qcrilam/QcRilAmService.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.sony.qcrilam; - -import android.app.Service; -import android.content.Intent; -import android.media.AudioManager; -import android.os.IBinder; -import android.os.RemoteException; -import android.telephony.SubscriptionManager; -import android.util.Log; -import vendor.qti.hardware.radio.am.V1_0.IQcRilAudio; -import vendor.qti.hardware.radio.am.V1_0.IQcRilAudioCallback; - -public class QcRilAmService extends Service { - private static final String TAG = "QcRilAm-Service"; - - private void addCallbackForSimSlot(final int simSlotNo, final AudioManager audioManager) { - try { - IQcRilAudio QcRilAudio = IQcRilAudio.getService("slot" + simSlotNo); - if (QcRilAudio == null) { - Log.e(TAG, "Could not get service instance for slot" + simSlotNo + ", failing"); - } else { - QcRilAudio.setCallback(new IQcRilAudioCallback.Stub() { - public String getParameters(String keys) { - return audioManager.getParameters(keys); - } - - public int setParameters(String keyValuePairs) { - /* return */ audioManager.setParameters(keyValuePairs); - // AudioManager.setParameters does not check nor return - // the value coming from AudioSystem.setParameters. - // Assume there was no error: - return 0; - } - }); - } - } catch (RemoteException exception) { - Log.e(TAG, "RemoteException while trying to add callback for slot" + simSlotNo); - } - } - - @Override - public IBinder onBind(Intent intent) { - return null; - } - - @Override - public void onCreate() { - int simCount = SubscriptionManager.from(this).getActiveSubscriptionInfoCountMax(); - Log.i(TAG, "Device has " + simCount + " sim slots"); - final AudioManager audioManager = getSystemService(AudioManager.class); - if (audioManager == null) - throw new RuntimeException("Can't get audiomanager!"); - for (int simSlotNo = 1; simSlotNo <= simCount; simSlotNo++) { - addCallbackForSimSlot(simSlotNo, audioManager); - } - } - -} diff --git a/src/com/sony/qcrilam/QcRilAmService.kt b/src/com/sony/qcrilam/QcRilAmService.kt new file mode 100644 index 0000000..ef91dab --- /dev/null +++ b/src/com/sony/qcrilam/QcRilAmService.kt @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2018-2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Rewritten in Kotlin by Pavel Dubrova + */ + +package com.sony.qcrilam + +import android.app.Service +import android.content.Intent +import android.media.AudioManager +import android.os.IBinder +import android.os.RemoteException +import android.telephony.SubscriptionManager +import android.util.Log +import vendor.qti.hardware.radio.am.V1_0.IQcRilAudio +import vendor.qti.hardware.radio.am.V1_0.IQcRilAudioCallback + +class QcRilAmService : Service() { + private var TAG = "QcRilAm-Service" + + private fun addCallbackForSimSlot(simSlotNo: Int, audioManager: AudioManager) { + try { + val qcRilAudio = IQcRilAudio.getService("slot$simSlotNo") + if (qcRilAudio == null) { + Log.e(TAG, "Could not get service instance for slot$simSlotNo, failing") + } else { + qcRilAudio.setCallback(object : IQcRilAudioCallback.Stub() { + override fun getParameters(keys: String?): String { + return audioManager.getParameters(keys) + } + + override fun setParameters(keyValuePairs: String?): Int { + // AudioManager.setParameters does not check nor return + // the value coming from AudioSystem.setParameters. + // Assume there was no error: + audioManager.setParameters(keyValuePairs) + return 0 + } + }) + } + } catch (exception: RemoteException) { + Log.e(TAG, "RemoteException while trying to add callback for slot$simSlotNo") + } + } + + override fun onBind(intent: Intent?): IBinder? { + return null + } + + override fun onCreate() { + val simCount = getSystemService(SubscriptionManager::class.java).getActiveSubscriptionInfoCountMax() + Log.i(TAG, "Device has $simCount sim slots") + val audioManager = getSystemService(AudioManager::class.java) + if (audioManager == null) { + throw RuntimeException("Can't get audiomanager!") + } + for (simSlotNo in 1..simCount) { + addCallbackForSimSlot(simSlotNo, audioManager) + } + } +}