toggle foreground service to set correct type when gaining permissions
This commit is contained in:
parent
cec8a7ec55
commit
48ffde9656
|
@ -126,6 +126,7 @@ import eu.siacs.conversations.persistance.DatabaseBackend;
|
||||||
import eu.siacs.conversations.persistance.FileBackend;
|
import eu.siacs.conversations.persistance.FileBackend;
|
||||||
import eu.siacs.conversations.persistance.UnifiedPushDatabase;
|
import eu.siacs.conversations.persistance.UnifiedPushDatabase;
|
||||||
import eu.siacs.conversations.ui.ChooseAccountForProfilePictureActivity;
|
import eu.siacs.conversations.ui.ChooseAccountForProfilePictureActivity;
|
||||||
|
import eu.siacs.conversations.ui.ConversationsActivity;
|
||||||
import eu.siacs.conversations.ui.RtpSessionActivity;
|
import eu.siacs.conversations.ui.RtpSessionActivity;
|
||||||
import eu.siacs.conversations.ui.SettingsActivity;
|
import eu.siacs.conversations.ui.SettingsActivity;
|
||||||
import eu.siacs.conversations.ui.UiCallback;
|
import eu.siacs.conversations.ui.UiCallback;
|
||||||
|
@ -5149,4 +5150,18 @@ public class XmppConnectionService extends Service {
|
||||||
return Objects.hashCode(id, media, reconnecting);
|
return Objects.hashCode(id, media, reconnecting);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void toggleForegroundService(final XmppConnectionService service) {
|
||||||
|
if (service == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
service.toggleForegroundService();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void toggleForegroundService(final ConversationsActivity activity) {
|
||||||
|
if (activity == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
toggleForegroundService(activity.xmppConnectionService);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ import static eu.siacs.conversations.ui.XmppActivity.EXTRA_ACCOUNT;
|
||||||
import static eu.siacs.conversations.ui.XmppActivity.REQUEST_INVITE_TO_CONVERSATION;
|
import static eu.siacs.conversations.ui.XmppActivity.REQUEST_INVITE_TO_CONVERSATION;
|
||||||
import static eu.siacs.conversations.ui.util.SoftKeyboardUtils.hideSoftKeyboard;
|
import static eu.siacs.conversations.ui.util.SoftKeyboardUtils.hideSoftKeyboard;
|
||||||
import static eu.siacs.conversations.utils.PermissionUtils.allGranted;
|
import static eu.siacs.conversations.utils.PermissionUtils.allGranted;
|
||||||
|
import static eu.siacs.conversations.utils.PermissionUtils.audioGranted;
|
||||||
|
import static eu.siacs.conversations.utils.PermissionUtils.cameraGranted;
|
||||||
import static eu.siacs.conversations.utils.PermissionUtils.getFirstDenied;
|
import static eu.siacs.conversations.utils.PermissionUtils.getFirstDenied;
|
||||||
import static eu.siacs.conversations.utils.PermissionUtils.writeGranted;
|
import static eu.siacs.conversations.utils.PermissionUtils.writeGranted;
|
||||||
|
|
||||||
|
@ -1869,6 +1871,9 @@ public class ConversationFragment extends XmppFragment
|
||||||
}
|
}
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
if (cameraGranted(grantResults, permissions) || audioGranted(grantResults, permissions)) {
|
||||||
|
XmppConnectionService.toggleForegroundService(activity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startDownloadable(Message message) {
|
public void startDownloadable(Message message) {
|
||||||
|
|
|
@ -63,6 +63,7 @@ import org.openintents.openpgp.util.OpenPgpApi;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import eu.siacs.conversations.Config;
|
import eu.siacs.conversations.Config;
|
||||||
|
@ -312,14 +313,16 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleActivityResult(ActivityResult activityResult) {
|
private void handleActivityResult(final ActivityResult activityResult) {
|
||||||
if (activityResult.resultCode == Activity.RESULT_OK) {
|
if (activityResult.resultCode == Activity.RESULT_OK) {
|
||||||
handlePositiveActivityResult(activityResult.requestCode, activityResult.data);
|
handlePositiveActivityResult(activityResult.requestCode, activityResult.data);
|
||||||
} else {
|
} else {
|
||||||
handleNegativeActivityResult(activityResult.requestCode);
|
handleNegativeActivityResult(activityResult.requestCode);
|
||||||
}
|
}
|
||||||
if (activityResult.requestCode == REQUEST_BATTERY_OP) {
|
if (activityResult.requestCode == REQUEST_BATTERY_OP) {
|
||||||
|
// the result code is always 0 even when battery permission were granted
|
||||||
requestNotificationPermissionIfNeeded();
|
requestNotificationPermissionIfNeeded();
|
||||||
|
XmppConnectionService.toggleForegroundService(xmppConnectionService);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -472,6 +472,10 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
|
||||||
if (requestCode == REQUEST_BATTERY_OP || requestCode == REQUEST_DATA_SAVER) {
|
if (requestCode == REQUEST_BATTERY_OP || requestCode == REQUEST_DATA_SAVER) {
|
||||||
updateAccountInformation(mAccount == null);
|
updateAccountInformation(mAccount == null);
|
||||||
}
|
}
|
||||||
|
if (requestCode == REQUEST_BATTERY_OP) {
|
||||||
|
// the result code is always 0 even when battery permission were granted
|
||||||
|
XmppConnectionService.toggleForegroundService(xmppConnectionService);
|
||||||
|
}
|
||||||
if (requestCode == REQUEST_CHANGE_STATUS) {
|
if (requestCode == REQUEST_CHANGE_STATUS) {
|
||||||
PresenceTemplate template = mPendingPresenceTemplate.pop();
|
PresenceTemplate template = mPendingPresenceTemplate.pop();
|
||||||
if (template != null && resultCode == Activity.RESULT_OK) {
|
if (template != null && resultCode == Activity.RESULT_OK) {
|
||||||
|
|
|
@ -24,9 +24,23 @@ public class PermissionUtils {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean writeGranted(int[] grantResults, String[] permission) {
|
public static boolean writeGranted(final int[] grantResults, final String[] permissions) {
|
||||||
|
return permissionGranted(
|
||||||
|
Manifest.permission.WRITE_EXTERNAL_STORAGE, grantResults, permissions);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean audioGranted(final int[] grantResults, final String[] permissions) {
|
||||||
|
return permissionGranted(Manifest.permission.RECORD_AUDIO, grantResults, permissions);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean cameraGranted(final int[] grantResults, final String[] permissions) {
|
||||||
|
return permissionGranted(Manifest.permission.CAMERA, grantResults, permissions);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean permissionGranted(
|
||||||
|
final String permission, final int[] grantResults, final String[] permissions) {
|
||||||
for (int i = 0; i < grantResults.length; ++i) {
|
for (int i = 0; i < grantResults.length; ++i) {
|
||||||
if (Manifest.permission.WRITE_EXTERNAL_STORAGE.equals(permission[i])) {
|
if (permission.equals(permissions[i])) {
|
||||||
return grantResults[i] == PackageManager.PERMISSION_GRANTED;
|
return grantResults[i] == PackageManager.PERMISSION_GRANTED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue