Convert QcRilAm to SDK compliant app without PRIVATE_API access.

In order to build devices on API 28 and above, all vendor apps need to
use public, "stable" SDK APIs. Use of LOCAL_PRIVATE_PLATFORM_APIS is not
allowed anymore.

Noteworthy changes:
- The app doesn't need to be privileged. Both permissions have
  protectionLevel=normal, and the selinux domain can be applied to
  non-privileged apps just fine.
- AudioManager is a wrapper around AudioSystem, at least when it comes
  to get/setParameters which are used here.
- Sim slot count now comes from SubscriptionManager, which internally
  uses the isub system service and needs an extra selinux permission to
  retrieve.
  Note that the Max() variant, which retrieves the number of sim slots,
  does not require the dangerous permission READ_PHONE_STATE, while the
  "actual inserted sim count" variant of this function does.
- the android.hidl.manager dependency isn't necessary.

Signed-off-by: MarijnS95 <marijns95@gmail.com>
This commit is contained in:
MarijnS95 2019-12-04 17:59:09 +01:00
parent b8a8935fe8
commit 4a4608a898
2 changed files with 17 additions and 11 deletions

View file

@ -8,11 +8,9 @@ LOCAL_PROPRIETARY_MODULE := true
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_JAVA_LIBRARIES := android.hidl.manager-V1.0-java
LOCAL_STATIC_JAVA_LIBRARIES := vendor.qti.hardware.radio.am-V1.0-java
LOCAL_PROGUARD_FLAG_FILES := proguard.flags
LOCAL_PRIVATE_PLATFORM_APIS := true
LOCAL_PRIVILEGED_MODULE := true
LOCAL_SDK_VERSION := system_current
include $(BUILD_PACKAGE)

View file

@ -2,10 +2,10 @@ package com.sony.qcrilam;
import android.app.Service;
import android.content.Intent;
import android.media.AudioSystem;
import android.media.AudioManager;
import android.os.IBinder;
import android.os.RemoteException;
import android.telephony.TelephonyManager;
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;
@ -18,7 +18,7 @@ public class QcRilAmService extends Service {
return isRunning;
}
private void addCallbackForSimSlot(int simSlotNo) {
private void addCallbackForSimSlot(final int simSlotNo, final AudioManager audioManager) {
try {
IQcRilAudio QcRilAudio = IQcRilAudio.getService("slot" + simSlotNo);
if (QcRilAudio == null) {
@ -26,15 +26,19 @@ public class QcRilAmService extends Service {
} else {
QcRilAudio.setCallback(new IQcRilAudioCallback.Stub() {
public String getParameters(String keys) {
return AudioSystem.getParameters(keys);
return audioManager.getParameters(keys);
}
public int setParameters(String keyValuePairs) {
return AudioSystem.setParameters(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) {
} catch (RemoteException exception) {
Log.e(TAG, "RemoteException while trying to add callback for slot" + simSlotNo);
}
}
@ -47,9 +51,13 @@ public class QcRilAmService extends Service {
@Override
public void onCreate() {
isRunning = true;
int simCount = TelephonyManager.from(this).getSimCount();
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);
addCallbackForSimSlot(simSlotNo, audioManager);
}
}