From 846ee219dc5db94a99ebac3c9919bf2190006624 Mon Sep 17 00:00:00 2001 From: Pavel Dubrova Date: Tue, 14 Jan 2020 23:32:01 +0200 Subject: [PATCH] Rewrite in Kotlin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit At the I/O 2019 Developer Conference, Google announced that the Kotlin programming language is now the preferred language for Android apps. Kotlin is the future, Android system frameworks begin to correspond in this language, and new apps will be implemented in Kotlin as well. AOSP build system supports compilation of Kotlin source code since 2017, so nothing prevents us from rewriting our apps on it. All source code corresponds to Google’s Android coding standards which is clearly described here: https://developer.android.com/kotlin/style-guide Signed-off-by: Pavel Dubrova --- Android.bp | 2 +- src/com/sony/qcrilam/BootReceiver.java | 20 ------- src/com/sony/qcrilam/BootReceiver.kt | 31 ++++++++++ src/com/sony/qcrilam/QcRilAmService.java | 58 ------------------ src/com/sony/qcrilam/QcRilAmService.kt | 76 ++++++++++++++++++++++++ 5 files changed, 108 insertions(+), 79 deletions(-) delete mode 100644 src/com/sony/qcrilam/BootReceiver.java create mode 100644 src/com/sony/qcrilam/BootReceiver.kt delete mode 100644 src/com/sony/qcrilam/QcRilAmService.java create mode 100644 src/com/sony/qcrilam/QcRilAmService.kt 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) + } + } +}