|
|
|
|
@ -49,7 +49,6 @@ import androidx.annotation.NonNull;
|
|
|
|
|
import androidx.biometric.BiometricManager;
|
|
|
|
|
import androidx.biometric.BiometricPrompt;
|
|
|
|
|
import androidx.core.content.ContextCompat;
|
|
|
|
|
import com.google.android.material.snackbar.Snackbar;
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
@ -100,7 +99,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|
|
|
|
|
|
|
|
|
private ActivityResultLauncher<Intent> vpnPermissionLauncher;
|
|
|
|
|
private ActivityResultLauncher<String[]> requestPermissionsLauncher;
|
|
|
|
|
private ActivityResultLauncher<Intent> batteryOptLauncher;
|
|
|
|
|
|
|
|
|
|
private boolean isReadingLogs = false;
|
|
|
|
|
private final Handler sizeUpdateHandler = new Handler();
|
|
|
|
|
@ -135,14 +133,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
batteryOptLauncher = registerForActivityResult(
|
|
|
|
|
new ActivityResultContracts.StartActivityForResult(),
|
|
|
|
|
result -> {
|
|
|
|
|
Log.d(TAG, "Regresamos de la pantalla de ajustes de batería");
|
|
|
|
|
checkBatteryOptimizations();
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
requestPermissionsLauncher = registerForActivityResult(
|
|
|
|
|
new ActivityResultContracts.RequestMultiplePermissions(),
|
|
|
|
|
result -> {
|
|
|
|
|
@ -231,13 +221,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void showBatterySnackbar() {
|
|
|
|
|
View rootView = findViewById(android.R.id.content);
|
|
|
|
|
Snackbar.make(rootView, R.string.battery_opt_denied, Snackbar.LENGTH_INDEFINITE)
|
|
|
|
|
.setAction(R.string.fix_action, v -> checkBatteryOptimizations())
|
|
|
|
|
.show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initiatePermissionChain() {
|
|
|
|
|
List<String> permissions = new ArrayList<>();
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
|
|
|
@ -373,16 +356,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|
|
|
|
@Override
|
|
|
|
|
protected void onResume() {
|
|
|
|
|
super.onResume();
|
|
|
|
|
// Comprobamos batería siempre que volvemos a la app
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
|
|
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
|
|
|
|
if (pm != null && !pm.isIgnoringBatteryOptimizations(getPackageName())) {
|
|
|
|
|
// Si no está ignorado, mostramos el aviso (o Snackbar si ya se lanzó el diálogo)
|
|
|
|
|
Log.d(TAG, "onResume: Batería aún optimizada, mostrando aviso");
|
|
|
|
|
showBatterySnackbar();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (getIntent() != null && getIntent().getBooleanExtra(VpnRecoveryReceiver.EXTRA_RECOVERY, false)) {
|
|
|
|
|
addToLog(getString(R.string.recovery_pulse_received));
|
|
|
|
|
Intent vpnIntent = new Intent(this, TProxyService.class);
|
|
|
|
|
@ -404,71 +377,55 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
|
|
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
|
|
|
|
if (pm != null && !pm.isIgnoringBatteryOptimizations(getPackageName())) {
|
|
|
|
|
String manufacturer = Build.MANUFACTURER.toLowerCase();
|
|
|
|
|
String message = getString(R.string.battery_opt_msg);
|
|
|
|
|
String manufacturer = Build.MANUFACTURER.toLowerCase();
|
|
|
|
|
String message = getString(R.string.battery_opt_msg);
|
|
|
|
|
|
|
|
|
|
if (manufacturer.contains("oppo") || manufacturer.contains("realme") || manufacturer.contains("xiaomi")) {
|
|
|
|
|
if (manufacturer.contains("oppo") || manufacturer.contains("realme")) {
|
|
|
|
|
message += getString(R.string.battery_opt_oppo_extra);
|
|
|
|
|
} else if (manufacturer.contains("xiaomi")) {
|
|
|
|
|
message += getString(R.string.battery_opt_xiaomi_extra);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (manufacturer.contains("oppo") || manufacturer.contains("realme")) {
|
|
|
|
|
message += getString(R.string.battery_opt_oppo_extra);
|
|
|
|
|
} else if (manufacturer.contains("xiaomi")) {
|
|
|
|
|
message += getString(R.string.battery_opt_xiaomi_extra);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
new AlertDialog.Builder(this)
|
|
|
|
|
.setTitle(R.string.battery_opt_title)
|
|
|
|
|
.setMessage(message)
|
|
|
|
|
.setPositiveButton(R.string.go_to_settings, (dialog, which) -> openBatterySettings(manufacturer))
|
|
|
|
|
.setNegativeButton(R.string.cancel, null)
|
|
|
|
|
.show();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
|
|
|
|
|
intent.setData(Uri.parse("package:" + getPackageName()));
|
|
|
|
|
batteryOptLauncher.launch(intent);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
new AlertDialog.Builder(this)
|
|
|
|
|
.setTitle(R.string.battery_opt_title)
|
|
|
|
|
.setMessage(message)
|
|
|
|
|
.setPositiveButton(R.string.go_to_settings, (dialog, which) -> openBatterySettings(manufacturer))
|
|
|
|
|
.setNegativeButton(R.string.cancel, null)
|
|
|
|
|
.show();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void openBatterySettings(String manufacturer) {
|
|
|
|
|
boolean success = false;
|
|
|
|
|
private void openBatterySettings(String manufacturer) {
|
|
|
|
|
if (manufacturer.contains("oppo") || manufacturer.contains("realme")) {
|
|
|
|
|
try {
|
|
|
|
|
Intent intent = new Intent();
|
|
|
|
|
intent.setComponent(new ComponentName("com.coloros.safecenter", "com.coloros.safecenter.permission.startup.StartupAppListActivity"));
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
return;
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
try {
|
|
|
|
|
Intent intent = new Intent();
|
|
|
|
|
intent.setComponent(new ComponentName("com.coloros.oppoguardelf", "com.coloros.oppoguardelf.Permission.BackgroundAllowAppListActivity"));
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
return;
|
|
|
|
|
} catch (Exception e2) {}
|
|
|
|
|
}
|
|
|
|
|
} else if (manufacturer.contains("xiaomi")) {
|
|
|
|
|
try {
|
|
|
|
|
Intent intent = new Intent("miui.intent.action.APP_BATTERY_SAVER_SETTINGS");
|
|
|
|
|
intent.setComponent(new ComponentName("com.miui.powerkeeper", "com.miui.powerkeeper.ui.HiddenAppsConfigActivity"));
|
|
|
|
|
intent.putExtra("package_name", getPackageName());
|
|
|
|
|
intent.putExtra("package_label", getString(R.string.app_name));
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
return;
|
|
|
|
|
} catch (Exception e) {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (manufacturer.contains("oppo") || manufacturer.contains("realme")) {
|
|
|
|
|
try {
|
|
|
|
|
Intent intent = new Intent();
|
|
|
|
|
intent.setComponent(new ComponentName("com.coloros.safecenter", "com.coloros.safecenter.permission.startup.StartupAppListActivity"));
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
success = true;
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
try {
|
|
|
|
|
Intent intent = new Intent();
|
|
|
|
|
intent.setComponent(new ComponentName("com.coloros.oppoguardelf", "com.coloros.oppoguardelf.Permission.BackgroundAllowAppListActivity"));
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
success = true;
|
|
|
|
|
} catch (Exception e2) {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (manufacturer.contains("xiaomi")) {
|
|
|
|
|
try {
|
|
|
|
|
Intent intent = new Intent("miui.intent.action.APP_BATTERY_SAVER_SETTINGS");
|
|
|
|
|
intent.setComponent(new ComponentName("com.miui.powerkeeper", "com.miui.powerkeeper.ui.HiddenAppsConfigActivity"));
|
|
|
|
|
intent.putExtra("package_name", getPackageName());
|
|
|
|
|
intent.putExtra("package_label", getString(R.string.app_name));
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
success = true;
|
|
|
|
|
} catch (Exception e) {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
|
try {
|
|
|
|
|
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
|
|
|
|
intent.setData(Uri.parse("package:" + getPackageName()));
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
|
|
|
|
intent.setData(Uri.parse("package:" + getPackageName()));
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void toggleTheme() {
|
|
|
|
|
SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE);
|
|
|
|
|
|