Reload video devices after camera permission granted to ensure to be able to capture & send video right after
This commit is contained in:
parent
dec9442a47
commit
b8dc84bdac
6 changed files with 42 additions and 26 deletions
|
@ -549,6 +549,9 @@ public abstract class MainActivity extends LinphoneGenericActivity
|
||||||
boolean enableRingtone = grantResults[i] == PackageManager.PERMISSION_GRANTED;
|
boolean enableRingtone = grantResults[i] == PackageManager.PERMISSION_GRANTED;
|
||||||
LinphonePreferences.instance().enableDeviceRingtone(enableRingtone);
|
LinphonePreferences.instance().enableDeviceRingtone(enableRingtone);
|
||||||
LinphoneManager.getInstance().enableDeviceRingtone(enableRingtone);
|
LinphoneManager.getInstance().enableDeviceRingtone(enableRingtone);
|
||||||
|
} else if (permissions[i].equals(Manifest.permission.CAMERA)
|
||||||
|
&& grantResults[i] == PackageManager.PERMISSION_GRANTED) {
|
||||||
|
LinphoneUtils.reloadVideoDevices();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ import org.linphone.core.Core;
|
||||||
import org.linphone.core.CoreListenerStub;
|
import org.linphone.core.CoreListenerStub;
|
||||||
import org.linphone.core.tools.Log;
|
import org.linphone.core.tools.Log;
|
||||||
import org.linphone.settings.LinphonePreferences;
|
import org.linphone.settings.LinphonePreferences;
|
||||||
|
import org.linphone.utils.LinphoneUtils;
|
||||||
|
|
||||||
public class RemoteConfigurationAssistantActivity extends AssistantActivity {
|
public class RemoteConfigurationAssistantActivity extends AssistantActivity {
|
||||||
private static final int QR_CODE_ACTIVITY_RESULT = 1;
|
private static final int QR_CODE_ACTIVITY_RESULT = 1;
|
||||||
|
@ -191,6 +192,7 @@ public class RemoteConfigurationAssistantActivity extends AssistantActivity {
|
||||||
|
|
||||||
if (requestCode == CAMERA_PERMISSION_RESULT) {
|
if (requestCode == CAMERA_PERMISSION_RESULT) {
|
||||||
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||||
|
LinphoneUtils.reloadVideoDevices();
|
||||||
startActivityForResult(
|
startActivityForResult(
|
||||||
new Intent(
|
new Intent(
|
||||||
RemoteConfigurationAssistantActivity.this,
|
RemoteConfigurationAssistantActivity.this,
|
||||||
|
|
|
@ -522,6 +522,7 @@ public class CallActivity extends LinphoneGenericActivity
|
||||||
|
|
||||||
switch (requestCode) {
|
switch (requestCode) {
|
||||||
case CAMERA_TO_TOGGLE_VIDEO:
|
case CAMERA_TO_TOGGLE_VIDEO:
|
||||||
|
LinphoneUtils.reloadVideoDevices();
|
||||||
toggleVideo();
|
toggleVideo();
|
||||||
break;
|
break;
|
||||||
case MIC_TO_DISABLE_MUTE:
|
case MIC_TO_DISABLE_MUTE:
|
||||||
|
@ -531,6 +532,7 @@ public class CallActivity extends LinphoneGenericActivity
|
||||||
toggleRecording();
|
toggleRecording();
|
||||||
break;
|
break;
|
||||||
case CAMERA_TO_ACCEPT_UPDATE:
|
case CAMERA_TO_ACCEPT_UPDATE:
|
||||||
|
LinphoneUtils.reloadVideoDevices();
|
||||||
acceptCallUpdate(true);
|
acceptCallUpdate(true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -291,6 +291,10 @@ public class CallIncomingActivity extends LinphoneGenericActivity {
|
||||||
+ (grantResults[i] == PackageManager.PERMISSION_GRANTED
|
+ (grantResults[i] == PackageManager.PERMISSION_GRANTED
|
||||||
? "granted"
|
? "granted"
|
||||||
: "denied"));
|
: "denied"));
|
||||||
|
if (permissions[i].equals(Manifest.permission.CAMERA)
|
||||||
|
&& grantResults[i] == PackageManager.PERMISSION_GRANTED) {
|
||||||
|
LinphoneUtils.reloadVideoDevices();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -299,6 +299,10 @@ public class CallOutgoingActivity extends LinphoneGenericActivity implements OnC
|
||||||
+ (grantResults[i] == PackageManager.PERMISSION_GRANTED
|
+ (grantResults[i] == PackageManager.PERMISSION_GRANTED
|
||||||
? "granted"
|
? "granted"
|
||||||
: "denied"));
|
: "denied"));
|
||||||
|
if (permissions[i].equals(Manifest.permission.CAMERA)
|
||||||
|
&& grantResults[i] == PackageManager.PERMISSION_GRANTED) {
|
||||||
|
LinphoneUtils.reloadVideoDevices();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,11 +19,9 @@ along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
|
||||||
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
|
@ -33,7 +31,6 @@ import android.os.Looper;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
import android.text.Spanned;
|
import android.text.Spanned;
|
||||||
import android.view.KeyEvent;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
@ -44,8 +41,6 @@ import androidx.core.content.ContextCompat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import org.linphone.LinphoneManager;
|
import org.linphone.LinphoneManager;
|
||||||
|
@ -53,7 +48,6 @@ import org.linphone.LinphoneService;
|
||||||
import org.linphone.R;
|
import org.linphone.R;
|
||||||
import org.linphone.core.Address;
|
import org.linphone.core.Address;
|
||||||
import org.linphone.core.Call;
|
import org.linphone.core.Call;
|
||||||
import org.linphone.core.Call.State;
|
|
||||||
import org.linphone.core.CallLog;
|
import org.linphone.core.CallLog;
|
||||||
import org.linphone.core.ChatRoom;
|
import org.linphone.core.ChatRoom;
|
||||||
import org.linphone.core.ChatRoomCapabilities;
|
import org.linphone.core.ChatRoomCapabilities;
|
||||||
|
@ -61,6 +55,8 @@ import org.linphone.core.Core;
|
||||||
import org.linphone.core.Factory;
|
import org.linphone.core.Factory;
|
||||||
import org.linphone.core.LogCollectionState;
|
import org.linphone.core.LogCollectionState;
|
||||||
import org.linphone.core.ProxyConfig;
|
import org.linphone.core.ProxyConfig;
|
||||||
|
import org.linphone.core.tools.Log;
|
||||||
|
import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration;
|
||||||
import org.linphone.settings.LinphonePreferences;
|
import org.linphone.settings.LinphonePreferences;
|
||||||
|
|
||||||
/** Helpers. */
|
/** Helpers. */
|
||||||
|
@ -134,16 +130,6 @@ public final class LinphoneUtils {
|
||||||
return displayName;
|
return displayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean onKeyBackGoHome(Activity activity, int keyCode, KeyEvent event) {
|
|
||||||
if (!(keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0)) {
|
|
||||||
return false; // continue
|
|
||||||
}
|
|
||||||
|
|
||||||
activity.startActivity(
|
|
||||||
new Intent().setAction(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String timestampToHumanDate(Context context, long timestamp, int format) {
|
public static String timestampToHumanDate(Context context, long timestamp, int format) {
|
||||||
return timestampToHumanDate(context, timestamp, context.getString(format));
|
return timestampToHumanDate(context, timestamp, context.getString(format));
|
||||||
}
|
}
|
||||||
|
@ -183,16 +169,6 @@ public final class LinphoneUtils {
|
||||||
&& cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR));
|
&& cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Call> getCallsInState(Core core, Collection<State> states) {
|
|
||||||
List<Call> foundCalls = new ArrayList<>();
|
|
||||||
for (Call call : core.getCalls()) {
|
|
||||||
if (states.contains(call.getState())) {
|
|
||||||
foundCalls.add(call);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return foundCalls;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isCallRunning(Call call) {
|
private static boolean isCallRunning(Call call) {
|
||||||
if (call == null) {
|
if (call == null) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -242,6 +218,31 @@ public final class LinphoneUtils {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void reloadVideoDevices() {
|
||||||
|
Core core = LinphoneManager.getCore();
|
||||||
|
if (core == null) return;
|
||||||
|
|
||||||
|
Log.i("[Utils] Reloading camera");
|
||||||
|
core.reloadVideoDevices();
|
||||||
|
|
||||||
|
boolean useFrontCam = LinphonePreferences.instance().useFrontCam();
|
||||||
|
int camId = 0;
|
||||||
|
AndroidCameraConfiguration.AndroidCamera[] cameras =
|
||||||
|
AndroidCameraConfiguration.retrieveCameras();
|
||||||
|
for (AndroidCameraConfiguration.AndroidCamera androidCamera : cameras) {
|
||||||
|
if (androidCamera.frontFacing == useFrontCam) {
|
||||||
|
camId = androidCamera.id;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String[] devices = core.getVideoDevicesList();
|
||||||
|
if (camId >= devices.length) {
|
||||||
|
camId = 0;
|
||||||
|
}
|
||||||
|
String newDevice = devices[camId];
|
||||||
|
core.setVideoDevice(newDevice);
|
||||||
|
}
|
||||||
|
|
||||||
public static String getDisplayableUsernameFromAddress(String sipAddress) {
|
public static String getDisplayableUsernameFromAddress(String sipAddress) {
|
||||||
String username = sipAddress;
|
String username = sipAddress;
|
||||||
Core core = LinphoneManager.getCore();
|
Core core = LinphoneManager.getCore();
|
||||||
|
|
Loading…
Reference in a new issue