|
1 | 1 | package com.twiliovoicereactnative; |
2 | 2 |
|
3 | 3 | import androidx.annotation.NonNull; |
4 | | -import androidx.core.app.NotificationManagerCompat; |
5 | 4 |
|
6 | 5 | import com.facebook.react.bridge.Arguments; |
7 | 6 | import com.facebook.react.bridge.Promise; |
|
53 | 52 | import static com.twiliovoicereactnative.CommonConstants.VoiceEventError; |
54 | 53 | import static com.twiliovoicereactnative.CommonConstants.VoiceEventRegistered; |
55 | 54 | import static com.twiliovoicereactnative.CommonConstants.VoiceEventUnregistered; |
56 | | -import static com.twiliovoicereactnative.ConfigurationProperties.isFullScreenNotificationEnabled; |
57 | 55 | import static com.twiliovoicereactnative.JSEventEmitter.constructJSMap; |
58 | 56 | import static com.twiliovoicereactnative.ReactNativeArgumentsSerializer.serializeCall; |
59 | 57 | import static com.twiliovoicereactnative.ReactNativeArgumentsSerializer.serializeCallInvite; |
|
64 | 62 | import static com.twiliovoicereactnative.ReactNativeArgumentsSerializer.*; |
65 | 63 |
|
66 | 64 | import android.annotation.SuppressLint; |
67 | | -import android.content.Intent; |
68 | | -import android.net.Uri; |
69 | | -import android.os.Build; |
70 | 65 | import android.os.Handler; |
71 | 66 | import android.os.Looper; |
72 | | -import android.provider.Settings; |
73 | 67 | import android.util.Pair; |
74 | 68 |
|
75 | 69 | import com.twiliovoicereactnative.CallRecordDatabase.CallRecord; |
@@ -160,6 +154,67 @@ public void removeListeners(Integer count) { |
160 | 154 | logger.debug("Calling removeListeners: " + count); |
161 | 155 | } |
162 | 156 |
|
| 157 | + @Override |
| 158 | + @NonNull |
| 159 | + public String getName() { |
| 160 | + return TAG; |
| 161 | + } |
| 162 | + |
| 163 | + private RegistrationListener createRegistrationListener(Promise promise) { |
| 164 | + return new RegistrationListener() { |
| 165 | + @Override |
| 166 | + public void onRegistered(@NonNull String accessToken, @NonNull String fcmToken) { |
| 167 | + logger.log("Successfully registered FCM"); |
| 168 | + sendJSEvent(constructJSMap(new Pair<>(VoiceEventType, VoiceEventRegistered))); |
| 169 | + promise.resolve(null); |
| 170 | + } |
| 171 | + |
| 172 | + @Override |
| 173 | + public void onError(@NonNull RegistrationException registrationException, |
| 174 | + @NonNull String accessToken, |
| 175 | + @NonNull String fcmToken) { |
| 176 | + String errorMessage = reactContext.getString( |
| 177 | + R.string.registration_error, |
| 178 | + registrationException.getErrorCode(), |
| 179 | + registrationException.getMessage()); |
| 180 | + logger.error(errorMessage); |
| 181 | + |
| 182 | + sendJSEvent(constructJSMap( |
| 183 | + new Pair<>(VoiceEventType, VoiceEventError), |
| 184 | + new Pair<>(VoiceErrorKeyError, serializeVoiceException(registrationException)))); |
| 185 | + |
| 186 | + promise.reject(errorMessage); |
| 187 | + } |
| 188 | + }; |
| 189 | + } |
| 190 | + |
| 191 | + private UnregistrationListener createUnregistrationListener(Promise promise) { |
| 192 | + return new UnregistrationListener() { |
| 193 | + @Override |
| 194 | + public void onUnregistered(String accessToken, String fcmToken) { |
| 195 | + logger.log("Successfully unregistered FCM"); |
| 196 | + sendJSEvent(constructJSMap(new Pair<>(VoiceEventType, VoiceEventUnregistered))); |
| 197 | + promise.resolve(null); |
| 198 | + } |
| 199 | + |
| 200 | + @Override |
| 201 | + public void onError(RegistrationException registrationException, String accessToken, String fcmToken) { |
| 202 | + @SuppressLint("DefaultLocale") |
| 203 | + String errorMessage = reactContext.getString( |
| 204 | + R.string.unregistration_error, |
| 205 | + registrationException.getErrorCode(), |
| 206 | + registrationException.getMessage()); |
| 207 | + logger.error(errorMessage); |
| 208 | + |
| 209 | + sendJSEvent(constructJSMap( |
| 210 | + new Pair<>(VoiceEventType, VoiceEventError), |
| 211 | + new Pair<>(VoiceErrorKeyError, serializeVoiceException(registrationException)))); |
| 212 | + |
| 213 | + promise.reject(errorMessage); |
| 214 | + } |
| 215 | + }; |
| 216 | + } |
| 217 | + |
163 | 218 | @ReactMethod |
164 | 219 | public void voice_connect_android( |
165 | 220 | String accessToken, |
@@ -908,97 +963,6 @@ public void callInvite_reject(String uuid, Promise promise) { |
908 | 963 | }); |
909 | 964 | } |
910 | 965 |
|
911 | | - @ReactMethod |
912 | | - public void system_isFullScreenNotificationEnabled(Promise promise) { |
913 | | - boolean isEnabled = |
914 | | - isFullScreenNotificationEnabled(reactContext) && |
915 | | - NotificationManagerCompat.from(reactContext).canUseFullScreenIntent(); |
916 | | - |
917 | | - promise.resolve(isEnabled); |
918 | | - } |
919 | | - |
920 | | - @ReactMethod |
921 | | - public void system_requestFullScreenNotificationPermission(Promise promise) { |
922 | | - final boolean shouldStartActivity = |
923 | | - Build.VERSION.SDK_INT > Build.VERSION_CODES.TIRAMISU && |
924 | | - isFullScreenNotificationEnabled(reactContext); |
925 | | - |
926 | | - if (shouldStartActivity) { |
927 | | - try { |
928 | | - Intent intent = new Intent( |
929 | | - Settings.ACTION_MANAGE_APP_USE_FULL_SCREEN_INTENT, |
930 | | - Uri.parse("package:" + reactContext.getPackageName())); |
931 | | - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
932 | | - reactContext.startActivity(intent); |
933 | | - } catch (Exception e) { |
934 | | - promise.reject(e); |
935 | | - } |
936 | | - } |
937 | | - |
938 | | - promise.resolve(null); |
939 | | - } |
940 | | - |
941 | | - @Override |
942 | | - @NonNull |
943 | | - public String getName() { |
944 | | - return TAG; |
945 | | - } |
946 | | - |
947 | | - private RegistrationListener createRegistrationListener(Promise promise) { |
948 | | - return new RegistrationListener() { |
949 | | - @Override |
950 | | - public void onRegistered(@NonNull String accessToken, @NonNull String fcmToken) { |
951 | | - logger.log("Successfully registered FCM"); |
952 | | - sendJSEvent(constructJSMap(new Pair<>(VoiceEventType, VoiceEventRegistered))); |
953 | | - promise.resolve(null); |
954 | | - } |
955 | | - |
956 | | - @Override |
957 | | - public void onError(@NonNull RegistrationException registrationException, |
958 | | - @NonNull String accessToken, |
959 | | - @NonNull String fcmToken) { |
960 | | - String errorMessage = reactContext.getString( |
961 | | - R.string.registration_error, |
962 | | - registrationException.getErrorCode(), |
963 | | - registrationException.getMessage()); |
964 | | - logger.error(errorMessage); |
965 | | - |
966 | | - sendJSEvent(constructJSMap( |
967 | | - new Pair<>(VoiceEventType, VoiceEventError), |
968 | | - new Pair<>(VoiceErrorKeyError, serializeVoiceException(registrationException)))); |
969 | | - |
970 | | - promise.reject(errorMessage); |
971 | | - } |
972 | | - }; |
973 | | - } |
974 | | - |
975 | | - private UnregistrationListener createUnregistrationListener(Promise promise) { |
976 | | - return new UnregistrationListener() { |
977 | | - @Override |
978 | | - public void onUnregistered(String accessToken, String fcmToken) { |
979 | | - logger.log("Successfully unregistered FCM"); |
980 | | - sendJSEvent(constructJSMap(new Pair<>(VoiceEventType, VoiceEventUnregistered))); |
981 | | - promise.resolve(null); |
982 | | - } |
983 | | - |
984 | | - @Override |
985 | | - public void onError(RegistrationException registrationException, String accessToken, String fcmToken) { |
986 | | - @SuppressLint("DefaultLocale") |
987 | | - String errorMessage = reactContext.getString( |
988 | | - R.string.unregistration_error, |
989 | | - registrationException.getErrorCode(), |
990 | | - registrationException.getMessage()); |
991 | | - logger.error(errorMessage); |
992 | | - |
993 | | - sendJSEvent(constructJSMap( |
994 | | - new Pair<>(VoiceEventType, VoiceEventError), |
995 | | - new Pair<>(VoiceErrorKeyError, serializeVoiceException(registrationException)))); |
996 | | - |
997 | | - promise.reject(errorMessage); |
998 | | - } |
999 | | - }; |
1000 | | - } |
1001 | | - |
1002 | 966 | /** |
1003 | 967 | * Use the score map to get a Call.Score value from a string. |
1004 | 968 | * @param score The score as a string passed from the JS layer. |
|
0 commit comments