Skip to content

Commit

Permalink
Add recovery utils
Browse files Browse the repository at this point in the history
  • Loading branch information
Tornaco committed Jan 2, 2025
1 parent 0d2d7f4 commit 654b20f
Show file tree
Hide file tree
Showing 18 changed files with 672 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,6 @@ interface IPkgManager {

void setFreezeTipEnabled(boolean enable);
boolean isFreezeTipEnabled();

void restoreAllAppComponentSettings();
}
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ public List<Pkg> enableAllThanoxDisabledPackages(boolean removeFromSmartFreezeLi
return pm.enableAllThanoxDisabledPackages(removeFromSmartFreezeList);
}

@SneakyThrows
public void restoreAllAppComponentSettings() {
pm.restoreAllAppComponentSettings();
}

@SneakyThrows
public boolean isPkgSmartFreezeEnabled(Pkg pkgName) {
return pm.isPkgSmartFreezeEnabled(pkgName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,13 @@
<string name="menu_title_activity_intent_shortcut">Activity intent shortcut</string>
<string name="dialog_message_create_shortcut_apk">Create a shortcut stub apk, you can install this app to as a workaround of the launcher icon for disabling apps</string>

<string name="feature_title_recovery_tools">Recovery tools</string>
<string name="feature_title_recovery_tools_component_settings">Restore app component settings</string>
<string name="feature_title_recovery_tools_component_settings_summary">Restores the component settings of all apps configured through Thanox, including activities, services, broadcasts, and content providers.</string>

<string name="feature_title_recovery_tools_component_settings_flags_summary">If your device fails to boot normally due to modifications to system components, you can try to manually create an empty file in the /data/system/thanos directory using recovery or ADB tools on your computer. Name the file: %s \n Thanox will attempt to restore all component settings for all apps during system startup.</string>


<string name="dialog_title_smart_app_standby_need_enable_platform_app_idle">Enabled Adaptive Battery</string>
<string name="dialog_message_smart_app_standby_need_enable_platform_app_idle">
This feature works only if Adaptive battery is enabled @Android Pie+.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,12 @@
<string name="menu_title_activity_intent_shortcut">Etkinlik niyeti kısayolu</string>
<string name="dialog_message_create_shortcut_apk">Bir kısayol apksı oluştur, bu uygulamayı yükleyerek devre dışı bırakılmış uygulamalar için başlatıcı simgesi çözümü olarak kullanabilirsiniz</string>

<string name="feature_title_recovery_tools">Recovery tools</string>
<string name="feature_title_recovery_tools_component_settings">Restore app component settings</string>
<string name="feature_title_recovery_tools_component_settings_summary">Restores the component settings of all apps configured through Thanox, including activities, services, broadcasts, and content providers.</string>

<string name="feature_title_recovery_tools_component_settings_flags_summary">If your device fails to boot normally due to modifications to system components, you can try to manually create an empty file in the /data/system/thanos directory using recovery or ADB tools on your computer. Name the file: %s \n Thanox will attempt to restore all component settings for all apps during system startup.</string>

<string name="dialog_title_smart_app_standby_need_enable_platform_app_idle">Adaptif Pil Etkinleştirildi</string>
<string name="dialog_message_smart_app_standby_need_enable_platform_app_idle">Bu özellik yalnızca Adaptif Pil etkinse çalışır @Android Pie+.</string>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,12 @@
<string name="menu_title_activity_intent_shortcut">活动意图</string>
<string name="dialog_message_create_shortcut_apk">生成一个专门用于启动该冻结应用的绿色Android app,生成的应用将只包含一个Activity,大约30K。你可以安装代理应用来解决桌面没有冻结应用图标问题。</string>

<string name="feature_title_recovery_tools">恢复工具</string>
<string name="feature_title_recovery_tools_component_settings">恢复应用组件设置</string>
<string name="feature_title_recovery_tools_component_settings_summary">恢复所有通过Thanox进行设置的应用的组件设置,包含活动、服务、广播、内容提供者</string>

<string name="feature_title_recovery_tools_component_settings_flags_summary">如果你的设备因为修改了系统组件,导致无法正常启动,你可以尝试通过recovery或者电脑adb工具,手动在/data/system/thanos目录下创建一个空文件,命名为:%s \nThanox在系统启动阶段会尝试恢复所有应用的所有组件设置</string>

<string name="dialog_title_smart_app_standby_need_enable_platform_app_idle">开启自适应电池</string>
<string name="dialog_message_smart_app_standby_need_enable_platform_app_idle">
Android 9+设备使用智能休眠需要开启系统设置中的电池-自适应电池选项才能正常工作。\n\nThanox当前无法准确判断你的系统是否支持并开启了该选项。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,12 @@
<string name="menu_title_activity_intent_shortcut">活動意圖</string>
<string name="dialog_message_create_shortcut_apk">產生一個專門用於啟動該凍結應用程式的綠色Android app,產生的應用程式將只包含一個Activity,大約30K。你可以安裝代理應用程式來解決桌面沒有凍結應用程式圖示問題。</string>

<string name="feature_title_recovery_tools">恢复工具</string>
<string name="feature_title_recovery_tools_component_settings">恢复应用组件设置</string>
<string name="feature_title_recovery_tools_component_settings_summary">恢复所有通过Thanox进行设置的应用的组件设置,包含活动、服务、广播、内容提供者</string>

<string name="feature_title_recovery_tools_component_settings_flags_summary">如果你的设备因为修改了系统组件,导致无法正常启动,你可以尝试通过recovery或者电脑adb工具,手动在/data/system/thanos目录下创建一个空文件,命名为:%s \nThanox在系统启动阶段会尝试恢复所有应用的所有组件设置</string>

<string name="dialog_title_smart_app_standby_need_enable_platform_app_idle">開啟自適應電池</string>
<string name="dialog_message_smart_app_standby_need_enable_platform_app_idle">Android 9+裝置使用智慧型休眠需要開啟系統設定中的電池-自適應電池選項才能正常運作。 \n\nThanox目前無法準確判斷你的系統是否支援並開啟了該選項。</string>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,12 @@
<string name="menu_title_activity_intent_shortcut">Activity intent shortcut</string>
<string name="dialog_message_create_shortcut_apk">Create a shortcut stub apk, you can install this app to as a workaround of the launcher icon for disabling apps</string>

<string name="feature_title_recovery_tools">Recovery tools</string>
<string name="feature_title_recovery_tools_component_settings">Restore app component settings</string>
<string name="feature_title_recovery_tools_component_settings_summary">Restores the component settings of all apps configured through Thanox, including activities, services, broadcasts, and content providers.</string>

<string name="feature_title_recovery_tools_component_settings_flags_summary">If your device fails to boot normally due to modifications to system components, you can try to manually create an empty file in the /data/system/thanos directory using recovery or ADB tools on your computer. Name the file: %s \nThanox will attempt to restore all component settings for all apps during system startup.</string>

<string name="dialog_title_smart_app_standby_need_enable_platform_app_idle">Enabled Adaptive Battery</string>
<string name="dialog_message_smart_app_standby_need_enable_platform_app_idle">
This feature works only if Adaptive battery is enabled @Android Pie+.
Expand Down
3 changes: 3 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@
<activity
android:name="now.fortuitous.thanos.privacy.SensorOffAppListActivity"
android:exported="false" />
<activity
android:name="now.fortuitous.thanos.recovery.RecoveryUtilsActivity"
android:exported="true" />

<meta-data
android:name="xposedmodule"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package now.fortuitous.thanos.recovery

import android.content.Context
import android.content.Intent
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import dagger.hilt.android.AndroidEntryPoint
import github.tornaco.android.thanos.common.settings.Preference
import github.tornaco.android.thanos.common.settings.PreferenceUi
import github.tornaco.android.thanos.core.app.ThanosManager
import github.tornaco.android.thanos.core.pm.PackageManager
import github.tornaco.android.thanos.core.util.ClipboardUtils
import github.tornaco.android.thanos.module.compose.common.ComposeThemeActivity
import github.tornaco.android.thanos.module.compose.common.theme.TypographyDefaults
import github.tornaco.android.thanos.module.compose.common.widget.ConfirmDialog
import github.tornaco.android.thanos.module.compose.common.widget.ThanoxSmallAppBarScaffold
import github.tornaco.android.thanos.module.compose.common.widget.rememberConfirmDialogState
import github.tornaco.android.thanos.res.R
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import tornaco.apps.thanox.base.ui.ProgressDialog
import tornaco.apps.thanox.base.ui.rememberProgressDialogState
import tornaco.apps.thanox.util.ToastUtils

@AndroidEntryPoint
class RecoveryUtilsActivity : ComposeThemeActivity() {
companion object {
@JvmStatic
fun start(context: Context) {
val starter = Intent(context, RecoveryUtilsActivity::class.java)
context.startActivity(starter)
}
}

override fun isADVF(): Boolean {
return false
}

@Composable
private fun prefs(): List<Preference> {
val context = LocalContext.current
val restoreAllAppComponentSettingsDialog = rememberConfirmDialogState()

val progressDialogState = rememberProgressDialogState(
message = stringResource(R.string.feature_title_recovery_tools_component_settings),
title = stringResource(R.string.common_text_wait_a_moment)
)
ProgressDialog(progressDialogState)

val scope = rememberCoroutineScope()
ConfirmDialog(title = stringResource(R.string.feature_title_recovery_tools_component_settings),
state = restoreAllAppComponentSettingsDialog,
data = stringResource(R.string.feature_title_recovery_tools_component_settings_summary),
messageHint = {
it
}) {
scope.launch {
progressDialogState.show()
withContext(Dispatchers.IO) {
ThanosManager.from(context).pkgManager.restoreAllAppComponentSettings()
}
delay(1000)
progressDialogState.dismiss()
}
}

return listOf(
Preference.TextPreference(
title = stringResource(R.string.feature_title_recovery_tools_component_settings),
summary = stringResource(R.string.feature_title_recovery_tools_component_settings_summary),
onClick = {
restoreAllAppComponentSettingsDialog.show()
},
icon = github.tornaco.android.thanos.icon.remix.R.drawable.ic_remix_settings_3_fill
),

Preference.Category(""),

Preference.TextPreference(
withCardBg = true,
title = "",
summary = stringResource(
R.string.feature_title_recovery_tools_component_settings_flags_summary,
PackageManager.RESTORE_ALL_APP_COMPONENT_SETTINGS_FILE_FLAGS
),
onClick = {
ClipboardUtils.copyToClipboard(
context,
PackageManager.RESTORE_ALL_APP_COMPONENT_SETTINGS_FILE_FLAGS,
PackageManager.RESTORE_ALL_APP_COMPONENT_SETTINGS_FILE_FLAGS
)
ToastUtils.copiedToClipboard(context)
},
icon = github.tornaco.android.thanos.R.drawable.ic_information_fill
)

)
}

@Composable
override fun Content() {
ThanoxSmallAppBarScaffold(
title = {
Text(
text = stringResource(R.string.feature_title_recovery_tools),
style = TypographyDefaults.appBarTitleTextStyle()
)
},
onBackPressed = {
thisActivity().finish()
},
actions = {
}
) { paddings ->
Column(Modifier.padding(paddings)) {
PreferenceUi(prefs())
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import github.tornaco.permission.requester.RequiresPermission;
import github.tornaco.permission.requester.RuntimePermissions;
import now.fortuitous.thanos.onboarding.OnBoardingActivity;
import now.fortuitous.thanos.recovery.RecoveryUtilsActivity;

@RuntimePermissions
public class SettingsDashboardActivity extends ThemeActivity {
Expand Down Expand Up @@ -68,6 +69,9 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
OnBoardingActivity.Starter.INSTANCE.start(thisActivity());
return true;
});
findViewById(R.id.recovery_utils).setOnClickListener(v -> {
RecoveryUtilsActivity.Companion.start(thisActivity());
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,10 @@ protected void onBindGeneralPreferences() {
globalWhitelistPref.setChecked(thanos.getPkgManager().isProtectedWhitelistEnabled());
globalWhitelistPref.setOnPreferenceChangeListener((preference, newValue) -> {
boolean checked = (boolean) newValue;
thanos.getPkgManager().setProtectedWhitelistEnabled(checked);
if (!checked) {
globalWhitelistPref.setChecked(true);
showDisableGlobalWhiteListConfirmDialog();
}
return true;
});
}
Expand All @@ -407,6 +410,23 @@ protected void onBindGeneralPreferences() {
}
}

private void showDisableGlobalWhiteListConfirmDialog() {
ThanosManager thanos = ThanosManager.from(getContext());
SwitchPreferenceCompat globalWhitelistPref = findPreference(getString(R.string.key_enable_global_white_list));
new MaterialAlertDialogBuilder(requireActivity())
.setTitle(getString(github.tornaco.android.thanos.res.R.string.pref_title_enable_global_white_list))
.setMessage(getString(github.tornaco.android.thanos.res.R.string.pref_summary_enable_global_white_list))
.setCancelable(true)
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
thanos.getPkgManager().setProtectedWhitelistEnabled(false);
globalWhitelistPref.setChecked(thanos.getPkgManager().isProtectedWhitelistEnabled());
})
.setNegativeButton(android.R.string.cancel, (dialog, which) -> {
thanos.getPkgManager().setProtectedWhitelistEnabled(true);
globalWhitelistPref.setChecked(thanos.getPkgManager().isProtectedWhitelistEnabled());
})
.show();
}

@SuppressWarnings("ConstantConditions")
protected void onBindDataPreferences() {
Expand Down
16 changes: 14 additions & 2 deletions android/app/src/main/res/layout/activity_settings_dashboard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
android:layout_width="match_parent"
android:layout_height="@dimen/common_coll_appbar_height"
android:layout_alignParentTop="true"
android:theme="?appbarTheme"
android:background="?android:attr/windowBackground"
android:theme="?appbarTheme"
app:elevation="@dimen/common_toolbar_elevation">

<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
style="?collapsingToolbarTheme"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/windowBackground"
android:fitsSystemWindows="true"
app:collapsedTitleTextAppearance="@style/ToolbarCollapsedTitleTextAppearance"
android:background="?android:attr/windowBackground"
app:expandedTitleTextAppearance="@style/ToolbarExpandedTitleTextAppearance"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:titleCollapseMode="scale"
Expand Down Expand Up @@ -69,6 +69,18 @@
android:visibility="gone"
app:icon="@drawable/ic_book_3_fill" />

<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/recovery_utils"
style="@style/FloatingActionButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/fab"
android:layout_alignParentEnd="true"
android:layout_marginEnd="@dimen/common_view_margin_default"
android:layout_marginBottom="@dimen/common_view_margin_default"
android:text="@string/feature_title_recovery_tools"
app:icon="@drawable/ic_remix_device_recover_fill" />

<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/fab"
style="@style/FloatingActionButtonStyle"
Expand Down
Loading

0 comments on commit 654b20f

Please sign in to comment.