mirror of https://github.com/jitsi/jitsi-meet
feat(android) set target SDK to 34 (#14129)
* feat(android) set target SDK to 34 and fixed mediaProjection service typepull/14260/head jitsi-meet_9213
parent
e00b6be06c
commit
f8cef330f7
@ -0,0 +1,42 @@ |
||||
package org.jitsi.meet.sdk; |
||||
|
||||
import android.content.Context; |
||||
|
||||
import androidx.annotation.NonNull; |
||||
|
||||
import com.facebook.react.bridge.ReactApplicationContext; |
||||
import com.facebook.react.bridge.ReactContextBaseJavaModule; |
||||
import com.facebook.react.bridge.ReactMethod; |
||||
import com.facebook.react.module.annotations.ReactModule; |
||||
|
||||
|
||||
@ReactModule(name = JitsiMeetMediaProjectionModule.NAME) |
||||
class JitsiMeetMediaProjectionModule |
||||
extends ReactContextBaseJavaModule { |
||||
|
||||
public static final String NAME = "JitsiMeetMediaProjectionModule"; |
||||
|
||||
public JitsiMeetMediaProjectionModule(ReactApplicationContext reactContext) { |
||||
super(reactContext); |
||||
} |
||||
|
||||
@ReactMethod |
||||
public void launch() { |
||||
Context context = getReactApplicationContext(); |
||||
|
||||
JitsiMeetMediaProjectionService.launch(context); |
||||
} |
||||
|
||||
@ReactMethod |
||||
public void abort() { |
||||
Context context = getReactApplicationContext(); |
||||
|
||||
JitsiMeetMediaProjectionService.abort(context); |
||||
} |
||||
|
||||
@NonNull |
||||
@Override |
||||
public String getName() { |
||||
return NAME; |
||||
} |
||||
} |
@ -0,0 +1,100 @@ |
||||
/* |
||||
* Copyright @ 2019-present 8x8, Inc. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.jitsi.meet.sdk; |
||||
|
||||
|
||||
import android.app.Notification; |
||||
import android.app.Service; |
||||
import android.content.ComponentName; |
||||
import android.content.Context; |
||||
import android.content.Intent; |
||||
import android.content.pm.ServiceInfo; |
||||
import android.os.Build; |
||||
import android.os.IBinder; |
||||
|
||||
import org.jitsi.meet.sdk.log.JitsiMeetLogger; |
||||
|
||||
|
||||
/** |
||||
* This class implements an Android {@link Service}, a foreground one specifically, and it's |
||||
* responsible for presenting an ongoing notification when a conference is in progress. |
||||
* The service will help keep the app running while in the background. |
||||
* |
||||
* See: https://developer.android.com/guide/components/services
|
||||
*/ |
||||
public class JitsiMeetMediaProjectionService extends Service { |
||||
private static final String TAG = JitsiMeetMediaProjectionService.class.getSimpleName(); |
||||
|
||||
public static void launch(Context context) { |
||||
OngoingNotification.createOngoingConferenceNotificationChannel(); |
||||
|
||||
Intent intent = new Intent(context, JitsiMeetMediaProjectionService.class); |
||||
|
||||
ComponentName componentName; |
||||
|
||||
try { |
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { |
||||
componentName = context.startForegroundService(intent); |
||||
} else { |
||||
componentName = context.startService(intent); |
||||
} |
||||
} catch (RuntimeException e) { |
||||
// Avoid crashing due to ForegroundServiceStartNotAllowedException (API level 31).
|
||||
// See: https://developer.android.com/guide/components/foreground-services#background-start-restrictions
|
||||
JitsiMeetLogger.w(TAG + " Ongoing conference service not started", e); |
||||
return; |
||||
} |
||||
|
||||
if (componentName == null) { |
||||
JitsiMeetLogger.w(TAG + " Ongoing conference service not started"); |
||||
} |
||||
} |
||||
|
||||
public static void abort(Context context) { |
||||
Intent intent = new Intent(context, JitsiMeetMediaProjectionService.class); |
||||
context.stopService(intent); |
||||
} |
||||
|
||||
@Override |
||||
public void onCreate() { |
||||
super.onCreate(); |
||||
|
||||
Notification notification = OngoingNotification.buildOngoingConferenceNotification(null); |
||||
|
||||
if (notification == null) { |
||||
stopSelf(); |
||||
JitsiMeetLogger.w(TAG + " Couldn't start service, notification is null"); |
||||
} |
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { |
||||
startForeground(OngoingNotification.NOTIFICATION_ID, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION); |
||||
} else { |
||||
startForeground(OngoingNotification.NOTIFICATION_ID, notification); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public IBinder onBind(Intent intent) { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public int onStartCommand(Intent intent, int flags, int startId) { |
||||
|
||||
return START_NOT_STICKY; |
||||
} |
||||
} |
Loading…
Reference in new issue