Skip to content

Commit

Permalink
breeze: ImsInit: Toggle airplane mode in ImsInit
Browse files Browse the repository at this point in the history
* Doing this in an initscript is weird, and makes it a pain in the ass to address denials from it on Enforcing.
* Convert the code into Java, and do it in the ImsInit app instead.

Co-authored-by: R0rt1z2 <rogerortizleal@gmail.com>
Signed-off-by: bengris32 <bengris32@protonmail.ch>
Signed-off-by: techyminati <sinha.aryan03@gmail.com>
Change-Id: I6042eb476b1b227d7d1f82c2f2bbd9433891cb4b
  • Loading branch information
2 people authored and Hadenix committed Oct 9, 2023
1 parent d79427e commit 54bcaae
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
3 changes: 2 additions & 1 deletion ImsInit/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS"/>
<uses-permission android:name="android.permission.DIAGNOSTIC"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.provider.Settings;
import android.os.UserHandle;
import android.util.Log;

import com.android.ims.ImsManager;
Expand All @@ -27,6 +29,35 @@ public class BootCompletedReceiver extends BroadcastReceiver {
@Override
public void onReceive(final Context context, Intent intent) {
Log.i(LOG_TAG, "onBoot");

/* Toggle airplane mode on and off at boot to enable VoLTE. */
Log.i(LOG_TAG, "Trying to toggle airplane mode to enable VoLTE");
new Thread(() -> {
Intent tIntent;

try {
Thread.sleep(2000);
} catch (Exception e) {}

tIntent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
tIntent.putExtra("state", true);
Settings.Global.putInt(context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 1);
context.sendBroadcastAsUser(tIntent, UserHandle.ALL);

/*
* Sleep for a second before toggling airplane mode
* off. Without this, airplane mode can sometimes
* fail to be toggled off again.
*/
try {
Thread.sleep(1000);
} catch (Exception e) {}

tIntent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
tIntent.putExtra("state", false);
Settings.Global.putInt(context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0);
context.sendBroadcastAsUser(tIntent, UserHandle.ALL);
}).start();

context.startService(new Intent(context, PhoneStateService.class));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<permissions>
<privapp-permissions package="org.lineageos.umidigi.imsinit">
<permission name="android.permission.INTERACT_ACROSS_USERS"/>
<permission name="android.permission.WRITE_SECURE_SETTINGS"/>
</privapp-permissions>
</permissions>
3 changes: 2 additions & 1 deletion device.mk
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ PRODUCT_PACKAGES += \
ImsInit

PRODUCT_COPY_FILES += \
$(LOCAL_PATH)/configs/permissions/privapp-permissions-mediatek.xml:$(TARGET_COPY_OUT_SYSTEM)/etc/permissions/privapp-permissions-mediatek.xml
$(LOCAL_PATH)/configs/permissions/privapp-permissions-mediatek.xml:$(TARGET_COPY_OUT_SYSTEM)/etc/permissions/privapp-permissions-mediatek.xml \
$(LOCAL_PATH)/configs/permissions/privapp-permissions-org.lineageos.umidigi.imsinit.xml:$(TARGET_COPY_OUT_SYSTEM)/etc/permissions/privapp-permissions-org.lineageos.umidigi.imsinit.xml

# Keylayout
PRODUCT_COPY_FILES += \
Expand Down

0 comments on commit 54bcaae

Please sign in to comment.