added recommendations for app fixes + added more gmsless instructions

This commit is contained in:
gdlbo
2023-09-23 01:22:13 +03:00
parent 25634b2469
commit c5c898aa4e
10 changed files with 135 additions and 100 deletions
@@ -14,7 +14,6 @@ import ru.vtosters.lite.concurrent.VTExecutors;
import ru.vtosters.lite.downloaders.notifications.NotificationChannels;
import ru.vtosters.lite.ssfs.UsersList;
import ru.vtosters.lite.themes.ThemesManager;
import ru.vtosters.lite.ui.dialogs.DisableBattery;
import ru.vtosters.lite.ui.dialogs.InstallGMS;
import ru.vtosters.lite.ui.dialogs.OTADialog;
import ru.vtosters.lite.ui.dialogs.Start;
@@ -64,7 +63,6 @@ public class MainActivityInjector {
Start.alert(activity);
InstallGMS.alert(activity);
DisableBattery.alert(activity);
// VKIDProtection.alert(activity);
//needs to show selected tgs pack count in settings after cold launch
TelegramStickersService.getInstance(activity);
@@ -1,39 +0,0 @@
package ru.vtosters.lite.ui.dialogs;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.PowerManager;
import android.provider.Settings;
import com.vk.core.dialogs.alert.VkAlertDialog;
import com.vtosters.lite.R;
import ru.vtosters.hooks.other.Preferences;
import ru.vtosters.lite.deviceinfo.OEMDetector;
public class DisableBattery {
public static void alert(Activity activity) {
if (!(OEMDetector.isOEM() && Build.VERSION.SDK_INT >= 23 && Preferences.getBoolValue("showDoze", true)))
return;
String packName = activity.getPackageName();
PowerManager manager = (PowerManager) activity.getSystemService(Context.POWER_SERVICE);
if (manager.isIgnoringBatteryOptimizations(packName)) return;
new VkAlertDialog.Builder(activity)
.setTitle(R.string.batteryissuetitle)
.setMessage(R.string.batteryissuesumm)
.setCancelable(false)
.setPositiveButton(R.string.batteryissuebtn1, (dialogInterface, i) -> {
@SuppressLint("BatteryLife")
var intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.setData(Uri.parse("package:" + packName));
activity.startActivity(intent);
})
.setNeutralButton(R.string.batteryissuebtn2,
(dialogInterface, i) -> Preferences.getPreferences().edit().putBoolean("showDoze", false).apply()
)
.show();
}
}
@@ -1,6 +1,9 @@
package ru.vtosters.lite.ui.fragments;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import com.vk.core.dialogs.alert.VkAlertDialog;
import com.vtosters.lite.R;
public class InstallGMSFragment extends TrackedMaterialPreferenceToolbarFragment {
@@ -8,6 +11,22 @@ public class InstallGMSFragment extends TrackedMaterialPreferenceToolbarFragment
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
addPreferencesFromResource(R.xml.preferences_gms);
findPreference("microg").setOnPreferenceClickListener((preference) -> {
String[] items = {"Уменьшенный MicroG (Vanced MicroG)", "Полноценный MicroG (Замена GMS)"};
new VkAlertDialog.Builder(requireActivity()).setItems(items, (dialog, which) -> {
switch (which) {
case 0 ->
requireContext().startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://github.com/TeamVanced/VancedMicroG/releases/latest/download/microg.apk")));
case 1 ->
requireContext().startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://github.com/microg/GmsCore/releases")));
}
dismiss();
}).show();;
return true;
});
}
@Override
@@ -6,6 +6,8 @@ import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.PowerManager;
import android.provider.Settings;
import androidx.annotation.StringRes;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;
@@ -38,6 +40,7 @@ import ru.vtosters.lite.BuildConfig;
import ru.vtosters.lite.concurrent.VTExecutors;
import ru.vtosters.lite.deviceinfo.OEMDetector;
import ru.vtosters.lite.ssfs.Utils;
import ru.vtosters.lite.themes.utils.RecolorUtils;
import ru.vtosters.lite.ui.PreferenceFragmentUtils;
import ru.vtosters.lite.ui.dialogs.OTADialog;
import ru.vtosters.lite.ui.fragments.tgstickers.StickersFragment;
@@ -99,7 +102,11 @@ public class VTSettings extends TrackedMaterialPreferenceToolbarFragment {
this.addPreferencesFromResource(R.xml.empty);
AndroidUtils.checkLinksVerified(this.requireActivity());
PowerManager manager = (PowerManager) requireActivity().getSystemService(Context.POWER_SERVICE);
boolean isLinksUnverified = AndroidUtils.isLinksUnverified(requireActivity());
boolean isDozingAvailable = Build.VERSION.SDK_INT >= 23 && !manager.isIgnoringBatteryOptimizations(AndroidUtils.getPackageName());
boolean areNotificationsDisabled = !AndroidUtils.areNotificationsEnabled();
boolean isGMSNotInstalled = !GmsHook.isAnyServicesInstalled();
if (AccountManagerUtils.isLogin()) {
Preference accountSwitcher = PreferenceFragmentUtils.addPreference(
@@ -183,20 +190,82 @@ public class VTSettings extends TrackedMaterialPreferenceToolbarFragment {
);
}
if (!GmsHook.isAnyServicesInstalled()) {
PreferenceFragmentUtils.addPreferenceCategory(getPreferenceScreen(), R.string.gmsname);
if (isLinksUnverified || isDozingAvailable || areNotificationsDisabled || isGMSNotInstalled) {
PreferenceFragmentUtils.addPreferenceCategory(getPreferenceScreen(), "Рекомендации");
PreferenceFragmentUtils.addPreference(
getPreferenceScreen(),
"",
requireContext().getString(R.string.installgms),
"",
R.drawable.ic_about_outline_28,
preference -> {
NavigatorUtils.switchFragment(requireContext(), InstallGMSFragment.class);
return false;
}
);
if (isGMSNotInstalled) {
PreferenceFragmentUtils.addPreference(
getPreferenceScreen(),
"",
requireContext().getString(R.string.installgms),
"Отсутствие этих сервисов приводит к поломке фоновых уведомлений и проблемами работы компонентов приложения",
RecolorUtils.recolorDrawable(R.drawable.ic_about_outline_28, ThemesUtils.getColor(R.color.red)),
preference -> {
NavigatorUtils.switchFragment(requireContext(), InstallGMSFragment.class);
return false;
}
);
}
if (isLinksUnverified) {
PreferenceFragmentUtils.addPreference(
getPreferenceScreen(),
"",
"Не выбраны ссылки для открытия приложением",
"Это помешает открытию внешинх ссылок для их открытия с помощью этого приложения\n\nВ некоторых случаях необходимо отключить открытие ссылок официальным приложениям ВКонтакте",
RecolorUtils.recolorDrawable(R.drawable.ic_about_outline_28, ThemesUtils.getColor(R.color.red)),
preference -> {
try {
Intent intent = new Intent(Settings.ACTION_APP_OPEN_BY_DEFAULT_SETTINGS, Uri.parse("package:" + AndroidUtils.getPackageName()));
requireActivity().startActivity(intent);
} catch (Throwable t1) {
try {
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.parse("package:" + AndroidUtils.getPackageName()));
requireActivity().startActivity(intent);
} catch (Throwable ignored) {
// ignored
}
}
return false;
}
);
}
if (isDozingAvailable) {
PreferenceFragmentUtils.addPreference(
getPreferenceScreen(),
"",
"Отключите экономию батареи",
"Экономия батареи мешает получению фоновых сообщений, уведомлений и работе музыки",
RecolorUtils.recolorDrawable(R.drawable.ic_about_outline_28, ThemesUtils.getColor(R.color.red)),
preference -> {
@SuppressLint("BatteryLife")
var intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.setData(Uri.parse("package:" + AndroidUtils.getPackageName()));
requireActivity().startActivity(intent);
return false;
}
);
}
if (areNotificationsDisabled) {
PreferenceFragmentUtils.addPreference(
getPreferenceScreen(),
"",
"Включите уведомления",
"Без включенных уведомлений не получится получать сообщения и многое другое",
RecolorUtils.recolorDrawable(R.drawable.ic_about_outline_28, ThemesUtils.getColor(R.color.red)),
preference -> {
@SuppressLint("BatteryLife")
var intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra(Settings.EXTRA_APP_PACKAGE, AndroidUtils.getPackageName());
requireActivity().startActivity(intent);
return false;
}
);
}
}
if (Preferences.devmenu()) {
@@ -577,6 +646,18 @@ public class VTSettings extends TrackedMaterialPreferenceToolbarFragment {
}
);
PreferenceFragmentUtils.addPreference(
getPreferenceScreen(),
"",
"Помочь проекту",
"За донат можно получить приятные бонусы на аккаунт",
R.drawable.ic_money_circle_outline_28,
preference -> {
requireContext().startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://vtosters.app/donate")));
return false;
}
);
PreferenceFragmentUtils.addPreference(
getPreferenceScreen(),
"",
@@ -1,9 +1,9 @@
package ru.vtosters.lite.utils;
import android.app.Activity;
import android.app.NotificationManager;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.verify.domain.DomainVerificationManager;
@@ -15,11 +15,10 @@ import android.provider.Settings;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import com.vk.core.dialogs.alert.VkAlertDialog;
import androidx.core.app.NotificationManagerCompat;
import com.vk.core.util.Screen;
import com.vk.core.util.ToastUtils;
import com.vtosters.lite.general.fragments.WebViewFragment;
import ru.vtosters.hooks.other.Preferences;
import java.io.File;
import java.io.FileOutputStream;
@@ -31,8 +30,6 @@ import java.security.NoSuchAlgorithmException;
import java.util.Map;
import java.util.Random;
import static ru.vtosters.hooks.other.Preferences.getBoolValue;
public class AndroidUtils {
private static final String ALLOWED_CHARACTERS = "0123456789qwertyuiopasdfghjklzxcvbnm";
@@ -124,8 +121,8 @@ public class AndroidUtils {
new WebViewFragment.g(url).l().m().h().j().a(activity);
}
public static void checkLinksVerified(Activity activity) {
if (Build.VERSION.SDK_INT < 31) return;
public static boolean isLinksUnverified(Activity activity) {
if (Build.VERSION.SDK_INT < 31) return false;
DomainVerificationManager manager = activity.getSystemService(DomainVerificationManager.class);
DomainVerificationUserState userState;
@@ -133,7 +130,7 @@ public class AndroidUtils {
try {
userState = manager.getDomainVerificationUserState(getPackageName());
} catch (PackageManager.NameNotFoundException ignore) {
return;
return false;
}
boolean hasUnverified = false;
@@ -145,32 +142,7 @@ public class AndroidUtils {
hasUnverified = stateValue != null && stateValue != DomainVerificationUserState.DOMAIN_STATE_VERIFIED && stateValue != DomainVerificationUserState.DOMAIN_STATE_SELECTED;
}
if (hasUnverified) {
if (getBoolValue("showUnverifDialog", true)) {
new VkAlertDialog.Builder(activity)
.setTitle(com.vtosters.lite.R.string.warning)
.setMessage(AndroidUtils.getString("app_open_by_default_settings"))
.setCancelable(false)
.setPositiveButton(com.vtosters.lite.R.string.social_graph_skip,
(dialogInterface, i) -> Preferences.getPreferences().edit().putBoolean("showUnverifDialog", false).apply()
)
.setNeutralButton(com.vtosters.lite.R.string.open_settings,
(dialogInterface, i) -> {
try {
Intent intent = new Intent(Settings.ACTION_APP_OPEN_BY_DEFAULT_SETTINGS, Uri.parse("package:" + getPackageName()));
activity.startActivity(intent);
} catch (Throwable t1) {
try {
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.parse("package:" + getPackageName()));
activity.startActivity(intent);
} catch (Throwable ignored) {
}
}
}
)
.show();
}
}
return hasUnverified;
}
public static String MD5(String s) {
@@ -192,6 +164,15 @@ public class AndroidUtils {
return null;
}
public static boolean areNotificationsEnabled() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager manager = (NotificationManager) getGlobalContext().getSystemService(Context.NOTIFICATION_SERVICE);
return manager.areNotificationsEnabled();
} else {
return NotificationManagerCompat.from(getGlobalContext()).areNotificationsEnabled();
}
}
private static String getRandomString(int sizeOfRandomString) {
Random random = new Random();
StringBuilder sb = new StringBuilder(sizeOfRandomString);