Skip to content

Commit

Permalink
4.2.0-videochat-java
Browse files Browse the repository at this point in the history
  • Loading branch information
vdovbnya-qb committed Sep 4, 2024
1 parent 57638df commit 8ca8994
Show file tree
Hide file tree
Showing 26 changed files with 581 additions and 92 deletions.
23 changes: 10 additions & 13 deletions sample-videochat-java/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,24 @@ repositories {
android {
def versionQACode = 1

compileSdkVersion 31
buildToolsVersion "31.0.0"
flavorDimensions "default"

defaultConfig {
applicationId "com.quickblox.sample.videochat.java"
minSdkVersion 21
targetSdkVersion 31
versionCode 410010
versionName '4.1.1'
targetSdkVersion 34
compileSdk 34
versionCode 420000
versionName '4.2.0'
multiDexEnabled true
}

flavorDimensions += "dimension"
productFlavors {
dev {
dimension "default"
buildConfigField('boolean', "IS_QA", "false")
buildConfigField("int", "VERSION_QA_CODE", versionQACode.toString())
}

qa {
dimension "default"
buildConfigField("boolean", "IS_QA", "true")
buildConfigField("int", "VERSION_QA_CODE", versionQACode.toString())
}
Expand Down Expand Up @@ -80,16 +76,17 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
namespace 'com.quickblox.sample.videochat.java'
}

dependencies {
implementation 'com.quickblox:quickblox-android-sdk-videochat-webrtc:3.10.1'
implementation 'com.quickblox:quickblox-android-sdk-messages:3.10.1'
implementation 'com.quickblox:quickblox-android-sdk-videochat-webrtc:4.1.3'
implementation 'com.quickblox:quickblox-android-sdk-messages:4.1.3'

implementation 'com.google.firebase:firebase-core:21.1.0'
implementation 'com.google.firebase:firebase-core:21.1.1'
implementation 'com.navercorp.pulltorefresh:library:3.2.3@aar'

implementation 'com.google.android.material:material:1.6.1'
implementation 'com.google.android.material:material:1.12.0'
implementation 'com.github.johnkil.android-robototextview:robototextview:4.0.0'
}

Expand Down
5 changes: 4 additions & 1 deletion sample-videochat-java/app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,7 @@
-keep class com.google.android.gms.** { *; }

#json
-keep class org.json.** { *; }
-keep class org.json.** { *; }
-keep class com.google.gson.reflect.TypeToken
-keep class * extends com.google.gson.reflect.TypeToken
-keep public class * implements java.lang.reflect.Type
13 changes: 9 additions & 4 deletions sample-videochat-java/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.quickblox.sample.videochat.java">
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
Expand All @@ -14,6 +14,10 @@
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.ACTION_MANAGE_OVERLAY_PERMISSION" />

<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CAMERA" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />

<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />

Expand Down Expand Up @@ -70,7 +74,8 @@

<service
android:name=".services.CallService"
android:foregroundServiceType="mediaProjection" />
android:exported="false"
android:foregroundServiceType="camera|microphone|mediaProjection" />

<service
android:name=".services.fcm.PushListenerService"
Expand All @@ -90,7 +95,7 @@

<meta-data
android:name="com.quickblox.messages.TYPE"
android:value="GCM" />
android:value="FCM" />

<meta-data
android:name="com.quickblox.messages.SENDER_ID"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.quickblox.sample.videochat.java.activities;

import static com.quickblox.sample.videochat.java.services.CallService.ONE_OPPONENT;
import static com.quickblox.videochat.webrtc.BaseSession.QBRTCSessionState.QB_RTC_SESSION_NEW;
import static com.quickblox.videochat.webrtc.BaseSession.QBRTCSessionState.QB_RTC_SESSION_PENDING;

import android.app.Activity;
import android.app.KeyguardManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.media.projection.MediaProjectionManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
Expand Down Expand Up @@ -44,11 +49,11 @@
import com.quickblox.sample.videochat.java.utils.UsersUtils;
import com.quickblox.sample.videochat.java.utils.WebRtcSessionManager;
import com.quickblox.users.model.QBUser;
import com.quickblox.videochat.webrtc.AppRTCAudioManager;
import com.quickblox.videochat.webrtc.BaseSession;
import com.quickblox.videochat.webrtc.QBRTCScreenCapturer;
import com.quickblox.videochat.webrtc.QBRTCSession;
import com.quickblox.videochat.webrtc.QBRTCTypes;
import com.quickblox.videochat.webrtc.audio.QBAudioManager;
import com.quickblox.videochat.webrtc.callbacks.QBRTCClientSessionCallbacks;
import com.quickblox.videochat.webrtc.callbacks.QBRTCClientVideoTracksCallbacks;
import com.quickblox.videochat.webrtc.callbacks.QBRTCSessionEventsCallback;
Expand All @@ -64,9 +69,6 @@
import java.util.List;
import java.util.Map;

import static com.quickblox.sample.videochat.java.services.CallService.ONE_OPPONENT;
import static com.quickblox.videochat.webrtc.BaseSession.QBRTCSessionState.QB_RTC_SESSION_PENDING;

/**
* QuickBlox team
*/
Expand All @@ -77,6 +79,7 @@ public class CallActivity extends BaseActivity implements IncomeCallFragmentCall

public static final String INCOME_CALL_FRAGMENT = "income_call_fragment";
public static final int REQUEST_PERMISSION_SETTING = 545;
public static final int REQUEST_SHARING_MEDIA_PROJECTION = 1060;

private final ArrayList<CurrentCallStateCallback> currentCallStateCallbackList = new ArrayList<>();
private final UsersDbManager dbManager = UsersDbManager.getInstance();
Expand All @@ -97,7 +100,6 @@ public static void start(Context context, boolean isIncomingCall) {
intent.putExtra(Consts.EXTRA_IS_INCOMING_CALL, isIncomingCall);
SharedPrefsHelper.getInstance().save(Consts.EXTRA_IS_INCOMING_CALL, isIncomingCall);
context.startActivity(intent);
CallService.start(context);
}

@Override
Expand All @@ -107,6 +109,38 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);
checker = new PermissionsChecker(this);
connectionView = (LinearLayout) View.inflate(CallActivity.this, R.layout.connection_popup, null);

boolean isVideoCall = isVideoSession();
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.TIRAMISU && isVideoCall && isNewSession()) {
requestSharingPermissions(this);
return;
}

CallService.start(this);
}

private boolean isNewSession() {
QBRTCSession currentSession = WebRtcSessionManager.getInstance(getApplicationContext()).getCurrentSession();
if (currentSession == null) {
return false;
}

BaseSession.QBRTCSessionState sessionState = currentSession.getState();
if (sessionState == null) {
return false;
}

return currentSession.getState().equals(QB_RTC_SESSION_NEW) || currentSession.getState().equals(QB_RTC_SESSION_PENDING);
}

private boolean isVideoSession() {
QBRTCSession currentSession = WebRtcSessionManager.getInstance(getApplicationContext()).getCurrentSession();
return currentSession != null && currentSession.getConferenceType().equals(QBRTCTypes.QBConferenceType.QB_CONFERENCE_TYPE_VIDEO);
}

public void requestSharingPermissions(Activity context) {
MediaProjectionManager mMediaProjectionManager = (MediaProjectionManager) context.getSystemService(MEDIA_PROJECTION_SERVICE);
context.startActivityForResult(mMediaProjectionManager.createScreenCaptureIntent(), REQUEST_SHARING_MEDIA_PROJECTION);
}

@Override
Expand Down Expand Up @@ -134,6 +168,7 @@ public void finish() {
@Override
public void onBackPressed() {
// to prevent returning from Call Fragment
super.onBackPressed();
}

private void allowOnLockScreen() {
Expand Down Expand Up @@ -211,8 +246,17 @@ protected void onActivityResult(int requestCode, int resultCode, final Intent da
startScreenSharing(data);
Log.i(TAG, "Starting Screen Capture");
}

if (requestCode == REQUEST_SHARING_MEDIA_PROJECTION) {
if (resultCode == Activity.RESULT_OK) {
CallService.start(this);
} else {
finish();
}
}
}


private void startScreenSharing(final Intent data) {
Fragment fragmentByTag = getSupportFragmentManager().findFragmentByTag(ScreenShareFragment.class.getSimpleName());
if (!(fragmentByTag instanceof ScreenShareFragment)) {
Expand Down Expand Up @@ -341,7 +385,9 @@ private void startIncomeCallTimer(long time) {

private void stopIncomeCallTimer() {
Log.d(TAG, "stopIncomeCallTimer");
showIncomingCallWindowTaskHandler.removeCallbacks(showIncomingCallWindowTask);
if (showIncomingCallWindowTask != null) {
showIncomingCallWindowTaskHandler.removeCallbacks(showIncomingCallWindowTask);
}
}

private void addIncomeCallFragment() {
Expand Down Expand Up @@ -448,6 +494,11 @@ public void onReceiveHangUpFromUser(final QBRTCSession session, final Integer us
}
}

@Override
public void onChangeReconnectionState(QBRTCSession qbrtcSession, Integer userId, QBRTCTypes.QBRTCReconnectionState qbrtcReconnectionState) {
// empty
}

@Override
public void onCallAcceptByUser(QBRTCSession session, Integer userId, Map<String, String> userInfo) {
if (callService.isCurrentSession(session)) {
Expand Down Expand Up @@ -646,6 +697,11 @@ public QBRTCVideoTrack getVideoTrack(Integer userId) {
return callService.getVideoTrack(userId);
}

@Override
public QBRTCTypes.QBRTCReconnectionState getState(Integer userId) {
return callService.getState(userId);
}

@Override
public void onStopPreview() {
callService.stopScreenSharing();
Expand Down Expand Up @@ -707,7 +763,7 @@ public void run() {
}

public interface OnChangeAudioDevice {
void audioDeviceChanged(AppRTCAudioManager.AudioDevice newAudioDevice);
void audioDeviceChanged(QBAudioManager.AudioDevice newAudioDevice);
}

public interface CurrentCallStateCallback {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ private void allPermissionsGranted() {

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == PERMISSION_REQUEST_CODE && hasAllPermissionsGranted(grantResults)) {
requiresCheck = true;
allPermissionsGranted();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.quickblox.sample.videochat.java.activities;

import android.Manifest;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
Expand All @@ -11,17 +12,22 @@
import android.util.Log;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AlertDialog;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import com.quickblox.sample.videochat.java.R;
import com.quickblox.sample.videochat.java.services.LoginService;
import com.quickblox.sample.videochat.java.utils.PermissionsChecker;
import com.quickblox.sample.videochat.java.utils.SharedPrefsHelper;
import com.quickblox.sample.videochat.java.utils.ToastUtils;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;

public class SplashActivity extends BaseActivity {
private static final String TAG = SplashActivity.class.getSimpleName();
private static final int NOTIFICATION_PERMISSION_REQUEST_CODE = 1010;

private static final int SPLASH_DELAY = 1500;

Expand All @@ -32,6 +38,7 @@ public class SplashActivity extends BaseActivity {

private SharedPrefsHelper sharedPrefsHelper;

@RequiresApi(api = Build.VERSION_CODES.TIRAMISU)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -44,11 +51,32 @@ protected void onCreate(Bundle savedInstanceState) {
getSupportActionBar().hide();
}

checkNotificationPermission();

if (checkOverlayPermissions()) {
runNextScreen();
}
}

private void checkNotificationPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
boolean isNotificationPermissionDenied = ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_DENIED;

if (isNotificationPermissionDenied) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.POST_NOTIFICATIONS}, NOTIFICATION_PERMISSION_REQUEST_CODE);
}
}
}

@RequiresApi(api = Build.VERSION_CODES.TIRAMISU)
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == NOTIFICATION_PERMISSION_REQUEST_CODE && grantResults.length > 0 && grantResults[0] != 0) {
ToastUtils.longToast(getString(R.string.permission_unavailable, Manifest.permission.POST_NOTIFICATIONS));
}
}

private void runNextScreen() {
if (sharedPrefsHelper.hasUser()) {
LoginService.start(SplashActivity.this, sharedPrefsHelper.getUser());
Expand Down
Loading

0 comments on commit 8ca8994

Please sign in to comment.