Skip to content

Commit

Permalink
Add bootloop indication in xposed page
Browse files Browse the repository at this point in the history
Signed-off-by: DrDisagree <29881338+Mahmud0808@users.noreply.github.com>
  • Loading branch information
Mahmud0808 committed Mar 1, 2025
1 parent 1d9a06b commit 5c50d89
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class Xposed : ControlledPreferenceFragmentCompat() {
override fun onResume() {
super.onResume()

hookCheckPreference?.isHooked = false
HookCheckPreference.isHooked = false
hookCheckPreference?.initializeHookCheck()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import android.os.CountDownTimer
import android.os.Handler
import android.os.Looper
import android.util.AttributeSet
import android.widget.ImageView
import android.widget.TextView
import androidx.preference.Preference
import androidx.preference.PreferenceViewHolder
import com.drdisagree.iconify.Iconify.Companion.appContextLocale
Expand All @@ -22,62 +22,86 @@ import com.drdisagree.iconify.data.common.Const.ACTION_HOOK_CHECK_RESULT
import com.drdisagree.iconify.data.common.Preferences
import com.drdisagree.iconify.data.common.Preferences.XPOSED_HOOK_CHECK
import com.drdisagree.iconify.data.config.RPrefs
import com.drdisagree.iconify.xposed.utils.BootLoopProtector.PACKAGE_STRIKE_KEY_KEY
import com.google.android.material.button.MaterialButton
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import java.lang.ref.WeakReference

class HookCheckPreference(context: Context, attrs: AttributeSet?) : Preference(context, attrs) {

private val handler = Handler(Looper.getMainLooper())
private val delayedHandler = Handler(Looper.getMainLooper())
private val intentFilterHookedSystemUI = IntentFilter()
private var isHookSuccessful = false
var isHooked: Boolean = false

init {
intentFilterHookedSystemUI.addAction(ACTION_HOOK_CHECK_RESULT)
private var holderRef: WeakReference<PreferenceViewHolder>? = null
private var hookPackages = context.resources.getStringArray(R.array.module_scope)
private val intentFilterHookedSystemUI = IntentFilter().apply {
addAction(ACTION_HOOK_CHECK_RESULT)
}

override fun onBindViewHolder(holder: PreferenceViewHolder) {
super.onBindViewHolder(holder)
holderRef = WeakReference(holder)
updateUI()
}

holder.itemView.setOnClickListener {
try {
context.startActivity(
Intent(Intent.ACTION_MAIN).apply {
setComponent(
ComponentName(
"org.lsposed.manager",
"org.lsposed.manager.ui.activity.MainActivity"
private fun updateUI() {
holderRef?.get()?.itemView?.let { itemView ->
if (hasBootlooped) {
itemView.findViewById<TextView>(R.id.title)
.setText(R.string.xposed_module_bootlooped_title)
itemView.findViewById<TextView>(R.id.summary)
.setText(R.string.xposed_module_bootlooped_desc)
} else {
itemView.findViewById<TextView>(R.id.title)
.setText(R.string.xposed_module_disabled_title)
itemView.findViewById<TextView>(R.id.summary)
.setText(R.string.xposed_module_disabled_desc)
}

itemView.setOnClickListener {
try {
context.startActivity(
Intent(Intent.ACTION_MAIN).apply {
setComponent(
ComponentName(
"org.lsposed.manager",
"org.lsposed.manager.ui.activity.MainActivity"
)
)
)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
)
} catch (ignored: Exception) {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
)
} catch (ignored: Exception) {
}
}
}

holder.itemView.findViewById<ImageView>(R.id.info_icon).setOnClickListener {
MaterialAlertDialogBuilder(context)
.setTitle(context.resources.getString(R.string.attention))
.setMessage(
buildString {
append(
(if (Preferences.isXposedOnlyMode) {
appContextLocale.resources.getString(
R.string.xposed_only_desc
) + "\n\n"
} else {
""
})
)
append(appContextLocale.resources.getString(R.string.lsposed_warn))
itemView.findViewById<MaterialButton>(R.id.btn_more).setOnClickListener {
MaterialAlertDialogBuilder(context)
.setTitle(context.resources.getString(R.string.attention))
.setMessage(
if (!hasBootlooped) {
buildString {
append(
(if (Preferences.isXposedOnlyMode) {
appContextLocale.resources.getString(
R.string.xposed_only_desc
) + "\n\n"
} else {
""
})
)
append(appContextLocale.resources.getString(R.string.lsposed_warn))
}
} else {
context.resources.getString(R.string.lsposed_bootloop_warn)
}
)
.setPositiveButton(context.resources.getString(R.string.understood)) { dialog: DialogInterface, _: Int ->
dialog.dismiss()
}
)
.setPositiveButton(context.resources.getString(R.string.understood)) { dialog: DialogInterface, _: Int ->
dialog.dismiss()
}
.setCancelable(true)
.show()
.setCancelable(true)
.show()
}
}
}

Expand All @@ -104,6 +128,18 @@ class HookCheckPreference(context: Context, attrs: AttributeSet?) : Preference(c
private val delayedHookCheck: Runnable = Runnable {
if (!isHooked) {
RPrefs.putBoolean(XPOSED_HOOK_CHECK, false)

hasBootlooped = false
for (packageName in hookPackages) {
val strikeKey = "$PACKAGE_STRIKE_KEY_KEY$packageName"

if (RPrefs.getInt(strikeKey, 0) >= 3) {
hasBootlooped = true
break
}
}

notifyChanged()
}
}

Expand Down Expand Up @@ -172,4 +208,9 @@ class HookCheckPreference(context: Context, attrs: AttributeSet?) : Preference(c
} catch (ignored: Exception) {
}
}

companion object {
private var hasBootlooped: Boolean = false
var isHooked: Boolean = false
}
}
23 changes: 14 additions & 9 deletions app/src/main/res/layout/view_xposed_hook_check.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,20 @@
android:layout_centerVertical="true"
android:layout_marginHorizontal="18dp"
android:layout_marginVertical="16dp"
android:layout_toStartOf="@id/info_icon"
android:layout_toStartOf="@id/btn_more"
android:layout_toEndOf="@id/module_icon"
android:orientation="vertical">

<TextView
android:id="@+id/title"
style="@style/TextAppearance.Material3.TitleMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/xposed_module_disabled_title"
android:textColor="?colorOnError" />

<TextView
android:id="@+id/summary"
style="@style/TextAppearance.Material3.BodyMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -45,16 +47,19 @@

</LinearLayout>

<ImageView
android:id="@+id/info_icon"
android:layout_width="20dp"
android:layout_height="20dp"
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="24dp"
android:background="@drawable/action_bar_item_background_material_error"
android:contentDescription="@string/icon"
android:src="@drawable/ic_info"
app:tint="?colorOnError" />
android:backgroundTint="?attr/colorErrorContainer"
android:minWidth="0dp"
android:minHeight="0dp"
android:paddingHorizontal="12dp"
android:paddingVertical="6dp"
android:text="@string/more"
android:textColor="?attr/colorOnErrorContainer" />

</RelativeLayout>
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,12 @@

<!-- Xposed Menu -->
<string name="lsposed_warn">Before enabling Iconify from LSPosed modules, long press on Iconify and click on Re-optimize. After that enable Iconify and restart your SystemUI. This is necessary for a smoother experience.</string>
<string name="lsposed_bootloop_warn">One of the features you enabled is not compatible with your ROM. Please disable it and restart your SystemUI.</string>
<string name="xposed_only_desc">You are currently in Xposed Only mode. This requires iconify to be enabled in LSPosed app. Also make sure that Iconify module is shown in Magisk manager. To get access to all features, clear data of iconify app and go through the installation process!</string>
<string name="xposed_module_disabled_title">Module Not Activated</string>
<string name="xposed_module_disabled_desc">System service not running</string>
<string name="xposed_module_bootlooped_title">Bootloop Detected</string>
<string name="xposed_module_bootlooped_desc">Module has been disabled</string>
<string name="activity_title_transparency_blur">Transparency &amp; Blur</string>
<string name="activity_desc_transparency_blur">Enable QS blur and transparency</string>
<string name="activity_title_themes">Themes</string>
Expand Down Expand Up @@ -1196,6 +1199,7 @@
<string name="learn_more">Learn more</string>
<string name="custom_tiles_footer_info">To ensure custom tiles work properly, first use the default internet and bluetooth tiles once before using the custom ones.</string>
<string name="hig_res_image_footer_info">Avoid using high-resolution images, as they may cause your system UI to crash.</string>
<string name="more">More</string>

<!-- Weather -->
<!-- Omni Jaws Strings -->
Expand Down

0 comments on commit 5c50d89

Please sign in to comment.