Merge pull request #6 from bartcubbins/master_kotlin

[master] Rewrite in Kotlin
This commit is contained in:
Alin Jerpelea 2020-03-10 09:01:49 +01:00 committed by GitHub
commit 0ebbf676e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 108 additions and 79 deletions

View file

@ -13,7 +13,7 @@ android_app {
proprietary: true,
srcs: ["src/**/*.java"],
srcs: ["src/**/*.kt"],
static_libs: ["vendor.qti.hardware.radio.am-V1.0-java"],

View file

@ -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));
}
}

View file

@ -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 <pashadubrova@gmail.com>
*/
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))
}
}

View file

@ -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);
}
}
}

View file

@ -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 <pashadubrova@gmail.com>
*/
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)
}
}
}