fix regressions after target sdk 33 update

This commit is contained in:
Daniel Gultsch 2023-05-07 10:13:14 +02:00
parent 291091dbe4
commit f7f34c6bdd
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2
8 changed files with 35 additions and 18 deletions

View file

@ -48,8 +48,8 @@ dependencies {
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'com.google.android.material:material:1.8.0'
implementation "androidx.emoji2:emoji2:1.3.0"
freeImplementation "androidx.emoji2:emoji2-bundled:1.3.0"
implementation "androidx.emoji2:emoji2:1.2.0"
freeImplementation "androidx.emoji2:emoji2-bundled:1.2.0"
implementation 'org.bouncycastle:bcmail-jdk15on:1.64'
//zxing stopped supporting Java 7 so we have to stick with 3.3.3
@ -90,9 +90,9 @@ android {
defaultConfig {
minSdkVersion 21
targetSdkVersion 32
versionCode 42056
versionName "2.12.4"
targetSdkVersion 33
versionCode 42058
versionName "2.12.5"
archivesBaseName += "-$versionName"
applicationId "eu.siacs.conversations"
resValue "string", "applicationId", applicationId

View file

@ -1965,8 +1965,7 @@ public class ConversationFragment extends XmppFragment
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
final List<String> missingPermissions = new ArrayList<>();
for (String permission : permissions) {
if (Config.ONLY_INTERNAL_STORAGE
&& permission.equals(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU || Config.ONLY_INTERNAL_STORAGE) && permission.equals(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
continue;
}
if (activity.checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {

View file

@ -32,6 +32,7 @@ package eu.siacs.conversations.ui;
import static eu.siacs.conversations.ui.ConversationFragment.REQUEST_DECRYPT_PGP;
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Fragment;
@ -42,6 +43,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
@ -54,6 +56,7 @@ import androidx.annotation.IdRes;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.core.app.ActivityCompat;
import androidx.databinding.DataBindingUtil;
import org.openintents.openpgp.util.OpenPgpApi;
@ -207,7 +210,9 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
if (ExceptionHelper.checkForCrash(this)) {
return;
}
openBatteryOptimizationDialogIfNeeded();
if (openBatteryOptimizationDialogIfNeeded()) {
return;
}
}
}
@ -220,16 +225,16 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
getPreferences().edit().putBoolean(getBatteryOptimizationPreferenceKey(), false).apply();
}
private void openBatteryOptimizationDialogIfNeeded() {
private boolean openBatteryOptimizationDialogIfNeeded() {
if (isOptimizingBattery()
&& android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M
&& getPreferences().getBoolean(getBatteryOptimizationPreferenceKey(), true)) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.battery_optimizations_enabled);
builder.setMessage(getString(R.string.battery_optimizations_enabled_dialog, getString(R.string.app_name)));
builder.setPositiveButton(R.string.next, (dialog, which) -> {
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
Uri uri = Uri.parse("package:" + getPackageName());
final Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
final Uri uri = Uri.parse("package:" + getPackageName());
intent.setData(uri);
try {
startActivityForResult(intent, REQUEST_BATTERY_OP);
@ -241,6 +246,14 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
final AlertDialog dialog = builder.create();
dialog.setCanceledOnTouchOutside(false);
dialog.show();
return true;
}
return false;
}
private void requestNotificationPermissionIfNeeded() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && ActivityCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.POST_NOTIFICATIONS}, REQUEST_POST_NOTIFICATION);
}
}
@ -305,6 +318,9 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
} else {
handleNegativeActivityResult(activityResult.requestCode);
}
if (activityResult.requestCode == REQUEST_BATTERY_OP) {
requestNotificationPermissionIfNeeded();
}
}
private void handleNegativeActivityResult(int requestCode) {

View file

@ -98,6 +98,7 @@ public abstract class XmppActivity extends ActionBarActivity {
protected static final int REQUEST_INVITE_TO_CONVERSATION = 0x0102;
protected static final int REQUEST_CHOOSE_PGP_ID = 0x0103;
protected static final int REQUEST_BATTERY_OP = 0x49ff;
protected static final int REQUEST_POST_NOTIFICATION = 0x50ff;
public XmppConnectionService xmppConnectionService;
public boolean xmppConnectionServiceBound = false;
@ -809,7 +810,7 @@ public abstract class XmppActivity extends ActionBarActivity {
}
protected boolean hasStoragePermission(int requestCode) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, requestCode);
return false;

View file

@ -6,6 +6,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.Typeface;
import android.os.Build;
import android.preference.PreferenceManager;
import android.text.Spannable;
import android.text.SpannableString;
@ -873,7 +874,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
}
public void openDownloadable(Message message) {
if (ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU && ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ConversationFragment.registerPendingMessage(activity, message);
ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, ConversationsActivity.REQUEST_OPEN_MESSAGE);
return;

View file

@ -145,7 +145,7 @@ public class AudioPlayer implements View.OnClickListener, MediaPlayer.OnCompleti
}
private void startStop(ImageButton playPause) {
if (ContextCompat.checkSelfPermission(messageAdapter.getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU && ContextCompat.checkSelfPermission(messageAdapter.getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
pendingOnClickView.push(new WeakReference<>(playPause));
ActivityCompat.requestPermissions(messageAdapter.getActivity(), new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, ConversationsActivity.REQUEST_PLAY_PAUSE);
return;

View file

@ -40,8 +40,8 @@ public class Compatibility {
private static final List<String> UNUSED_SETTINGS_PRE_TWENTYSIX =
Collections.singletonList("message_notification_settings");
public static boolean hasStoragePermission(Context context) {
return Build.VERSION.SDK_INT < Build.VERSION_CODES.M
public static boolean hasStoragePermission(final Context context) {
return Build.VERSION.SDK_INT < Build.VERSION_CODES.M || Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU
|| ContextCompat.checkSelfPermission(
context, android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED;

View file

@ -72,7 +72,7 @@ public class PermissionUtils {
public static boolean hasPermission(
final Activity activity, final List<String> permissions, final int requestCode) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
final ImmutableList.Builder<String> missingPermissions = new ImmutableList.Builder<>();
for (final String permission : permissions) {
if (ActivityCompat.checkSelfPermission(activity, permission)