-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
breeze: Introduce Mediatek In-Call Service
* My attempt at fixing in call gain control on MediaTek devices. * It attempts to replicate what the stock MediaTek framework does when controlling the volume of the earpiece speaker, since MTK's audio HAL is not able to set the gain of the speaker from the values sent by AOSP framework. [LinkBoi00] Rebrand to Mediatek In-Call Service Change-Id: I43f727f6fb73a0d38457a41a8361653d1d00e220 Signed-off-by: LinkBoi00 <linkdevel@protonmail.com>
- Loading branch information
Showing
7 changed files
with
171 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (C) 2022 bengris32 | ||
* Copyright (C) 2022 LineageOS | ||
* | ||
* 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. | ||
*/ | ||
|
||
android_app { | ||
name: "MtkInCallService", | ||
|
||
srcs: ["src/**/*.java"], | ||
resource_dirs: ["res"], | ||
|
||
certificate: "platform", | ||
platform_apis: true, | ||
privileged: true, | ||
|
||
optimize: { | ||
enabled: false, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="org.lineageos.mediatek.incallservice" | ||
android:versionCode="1" | ||
android:versionName="1.0" | ||
android:sharedUserId="android.uid.system"> | ||
|
||
<application | ||
android:label="@string/app_name" | ||
android:persistent="true"> | ||
<receiver | ||
android:directBootAware="true" | ||
android:exported="true" | ||
android:name="org.lineageos.mediatek.incallservice.OnLockedBootCompleteReceiver"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" /> | ||
<category android:name="android.intent.category.DEFAULT" /> | ||
</intent-filter> | ||
</receiver> | ||
<service | ||
android:directBootAware="true" | ||
android:name="org.lineageos.mediatek.incallservice.VolumeChangeService"> | ||
</service> | ||
</application> | ||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="app_name">Mediatek In-Call Service</string> | ||
</resources> |
19 changes: 19 additions & 0 deletions
19
app/InCallService/src/org/lineageos/mediatek/incallservice/OnLockedBootCompleteReceiver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.lineageos.mediatek.incallservice; | ||
|
||
import android.content.BroadcastReceiver; | ||
import android.content.Intent; | ||
import android.content.Context; | ||
|
||
import android.util.Log; | ||
|
||
public class OnLockedBootCompleteReceiver extends BroadcastReceiver { | ||
private static final String LOG_TAG = "MediatekInCallService"; | ||
|
||
@Override | ||
public void onReceive(final Context context, Intent intent) { | ||
Log.i(LOG_TAG, "onBoot"); | ||
|
||
Intent sIntent = new Intent(context, VolumeChangeService.class); | ||
context.startService(sIntent); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
app/InCallService/src/org/lineageos/mediatek/incallservice/VolumeChangeReceiver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.lineageos.mediatek.incallservice; | ||
|
||
import android.content.Intent; | ||
import android.content.Context; | ||
import android.content.BroadcastReceiver; | ||
|
||
import android.media.AudioManager; | ||
import android.media.AudioSystem; | ||
import android.media.AudioDeviceInfo; | ||
|
||
import android.util.Log; | ||
|
||
public class VolumeChangeReceiver extends BroadcastReceiver { | ||
public static final String LOG_TAG = "MediatekInCallService"; | ||
|
||
private AudioManager mAudioManager; | ||
|
||
public VolumeChangeReceiver(Context context) { | ||
mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); | ||
} | ||
|
||
@Override | ||
public void onReceive(Context context, Intent intent) { | ||
int streamType = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, -1); | ||
if (streamType == AudioSystem.STREAM_VOICE_CALL) { | ||
AudioDeviceInfo callDevice = mAudioManager.getCommunicationDevice(); | ||
if (callDevice.getInternalType() != AudioDeviceInfo.TYPE_BUILTIN_EARPIECE) { | ||
// Device is not the built in earpiece, we don't need to do anything. | ||
return; | ||
} | ||
|
||
// Start building parameters | ||
String parameters = "volumeDevice=" + (callDevice.getId() - 1) + ";"; | ||
int volumeIndex = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, -1); | ||
if (volumeIndex < 0) { | ||
Log.w(LOG_TAG, "Could not get volumeIndex!"); | ||
return; | ||
} | ||
|
||
// Limit volumeIndex to a max of 7 since that's the size of | ||
// MediaTek's gain table. | ||
parameters += "volumeIndex=" + Math.min(7, volumeIndex) + ";"; | ||
parameters += "volumeStreamType=" + streamType; | ||
|
||
// Set gain parameters | ||
Log.d(LOG_TAG, "Setting audio parameters: " + parameters); | ||
AudioSystem.setParameters(parameters); | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
app/InCallService/src/org/lineageos/mediatek/incallservice/VolumeChangeService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.lineageos.mediatek.incallservice; | ||
|
||
import android.media.AudioManager; | ||
|
||
import android.content.Intent; | ||
import android.content.IntentFilter; | ||
import android.content.Context; | ||
import android.app.Service; | ||
import android.os.IBinder; | ||
|
||
import android.util.Log; | ||
|
||
public class VolumeChangeService extends Service { | ||
public static final String LOG_TAG = "MediatekInCallService"; | ||
|
||
private Context mContext; | ||
private VolumeChangeReceiver mVolumeChangeReceiver; | ||
|
||
@Override | ||
public IBinder onBind(Intent intent) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void onDestroy() { | ||
super.onDestroy(); | ||
} | ||
|
||
@Override | ||
public int onStartCommand(Intent intent, int flags, int startid) { | ||
mContext = this; | ||
mVolumeChangeReceiver = new VolumeChangeReceiver(mContext); | ||
|
||
Log.i(LOG_TAG, "Service is starting..."); | ||
this.registerReceiver(mVolumeChangeReceiver, | ||
new IntentFilter(AudioManager.VOLUME_CHANGED_ACTION)); | ||
return START_STICKY; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters