From 4078ebdf29438eafde23752668c8fcf7f2920a4d Mon Sep 17 00:00:00 2001 From: Nishant Dande Date: Tue, 4 Jul 2023 00:04:36 +0530 Subject: [PATCH 01/19] Modify Java 18, Added Google Play API dependency --- modules/build.gradle | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/modules/build.gradle b/modules/build.gradle index 68e0af9c5..17b61982a 100644 --- a/modules/build.gradle +++ b/modules/build.gradle @@ -11,6 +11,8 @@ ext { kotlin_reflection = '1.8.10' retrofit_version = '2.9.0' retrofit_interceptor_version = '5.0.0-alpha.2' + google_play_api = '3.0.1' + protobuf_java = '3.19.3' } android { @@ -32,11 +34,11 @@ android { } } compileOptions { - sourceCompatibility JavaVersion.VERSION_17 - targetCompatibility JavaVersion.VERSION_17 + sourceCompatibility JavaVersion.VERSION_18 + targetCompatibility JavaVersion.VERSION_18 } kotlinOptions { - jvmTarget = '17' + jvmTarget = '18' } } @@ -53,6 +55,11 @@ dependencies { implementation("com.squareup.okhttp3:logging-interceptor:$retrofit_interceptor_version") // endregion + // region Google Play API + implementation("foundation.e:gplayapi:$google_play_api") + implementation("com.google.protobuf:protobuf-java:$protobuf_java") + // endregion + testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' -- GitLab From e9c487724c974a3ed0c2a85ca7ba240c37e7278d Mon Sep 17 00:00:00 2001 From: Nishant Dande Date: Tue, 4 Jul 2023 00:05:33 +0530 Subject: [PATCH 02/19] Implemented AuthData request api for anonymous user --- .../src/main/java/app/lounge/users/anonymous/Anonymous.kt | 4 ++-- .../main/java/app/lounge/users/anonymous/AnonymousAPI.kt | 4 +--- .../app/lounge/users/anonymous/RetrofitAnonymousAPI.kt | 7 ++++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/modules/src/main/java/app/lounge/users/anonymous/Anonymous.kt b/modules/src/main/java/app/lounge/users/anonymous/Anonymous.kt index 9ca6f9067..4dd0ef0e6 100644 --- a/modules/src/main/java/app/lounge/users/anonymous/Anonymous.kt +++ b/modules/src/main/java/app/lounge/users/anonymous/Anonymous.kt @@ -16,7 +16,7 @@ interface Anonymous { companion object { fun anonymousRequestFor( - api: AnonymousAPI = AnonymousAPI.create() + api: AnonymousAPI ) : Anonymous { return object : Anonymous { override val api: AnonymousAPI = api @@ -27,7 +27,7 @@ interface Anonymous { // pass input from this function fun requestAuthData( anonymousAuthDataRequestBody: AnonymousAuthDataRequestBody, - success : (LoginResponse) -> Unit, + success : (AuthDataResponse) -> Unit, failure : (FetchError) -> Unit ) { api.requestAuthData( diff --git a/modules/src/main/java/app/lounge/users/anonymous/AnonymousAPI.kt b/modules/src/main/java/app/lounge/users/anonymous/AnonymousAPI.kt index 9da4d4368..83473fdf0 100644 --- a/modules/src/main/java/app/lounge/users/anonymous/AnonymousAPI.kt +++ b/modules/src/main/java/app/lounge/users/anonymous/AnonymousAPI.kt @@ -1,8 +1,6 @@ package app.lounge.users.anonymous -import app.lounge.BuildConfig import app.lounge.networking.FetchError -import com.google.gson.Gson import java.util.Properties interface AnonymousAPI { @@ -22,7 +20,7 @@ interface AnonymousAPI { fun requestAuthData( anonymousAuthDataRequestBody: AnonymousAuthDataRequestBody, - success : (LoginResponse) -> Unit, + success : (AuthDataResponse) -> Unit, failure : (FetchError) -> Unit ) diff --git a/modules/src/main/java/app/lounge/users/anonymous/RetrofitAnonymousAPI.kt b/modules/src/main/java/app/lounge/users/anonymous/RetrofitAnonymousAPI.kt index 8b2d3f608..4cf90c452 100644 --- a/modules/src/main/java/app/lounge/users/anonymous/RetrofitAnonymousAPI.kt +++ b/modules/src/main/java/app/lounge/users/anonymous/RetrofitAnonymousAPI.kt @@ -5,6 +5,7 @@ import app.lounge.networking.FetchError import app.lounge.networking.RetrofitFetching import app.lounge.networking.appLounge import app.lounge.networking.fetch +import com.aurora.gplayapi.data.models.AuthData import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.RequestBody import retrofit2.Call @@ -33,12 +34,12 @@ internal class RetrofitAnonymousAPI( @Url url: String = "https://eu.gtoken.ecloud.global", @HeaderMap headers: Map, @Body requestBody: RequestBody - ): Call + ): Call } override fun requestAuthData( anonymousAuthDataRequestBody: AnonymousAuthDataRequestBody, - success: (LoginResponse) -> Unit, + success: (AuthDataResponse) -> Unit, failure: (FetchError) -> Unit ) { val requestBody = RequestBody.create( @@ -60,4 +61,4 @@ internal class RetrofitAnonymousAPI( } -typealias LoginResponse = String +typealias AuthDataResponse = AuthData \ No newline at end of file -- GitLab From 5ce05c407e7a005860dbd88735ba34852cdd5c9f Mon Sep 17 00:00:00 2001 From: Nishant Dande Date: Tue, 4 Jul 2023 00:06:15 +0530 Subject: [PATCH 03/19] Implement testcase for anonymous use api --- .../lounge/networking/AnonymousUserAPITest.kt | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 modules/src/androidTest/java/app/lounge/networking/AnonymousUserAPITest.kt diff --git a/modules/src/androidTest/java/app/lounge/networking/AnonymousUserAPITest.kt b/modules/src/androidTest/java/app/lounge/networking/AnonymousUserAPITest.kt new file mode 100644 index 000000000..2b4eb65f3 --- /dev/null +++ b/modules/src/androidTest/java/app/lounge/networking/AnonymousUserAPITest.kt @@ -0,0 +1,84 @@ +package app.lounge.networking + +import app.lounge.users.anonymous.Anonymous +import app.lounge.users.anonymous.AnonymousAPI +import app.lounge.users.anonymous.AnonymousAuthDataRequestBody +import app.lounge.users.anonymous.AuthDataResponse +import org.junit.Test +import java.util.Properties + +class AnonymousUserAPITest { + + private val testAnonymousAPIForToken = Anonymous.anonymousRequestFor( + api = AnonymousAPI.create(AnonymousAPI.tokenBaseURL) + ) + +// private val testAnonymousAPIForLogin = Anonymous.anonymousRequestFor( +// api = AnonymousAPI.create(AnonymousAPI.loginBaseURL) +// ) + + private val requestBodyData = AnonymousAuthDataRequestBody( + properties = testSystemProperties, + userAgent = testUserAgent + ) + + @Test + fun testOnSuccessReturnsAuthData() { + var receivedData: AuthDataResponse? + testAnonymousAPIForToken.requestAuthData( + anonymousAuthDataRequestBody = requestBodyData, + success = { response -> + receivedData = response + assert(receivedData is AuthDataResponse) { "Assert!! Success must return data" } + }, + failure = {} + ) + Thread.sleep(3000) + } + +} + +// region TestData + +private const val testUserAgent: String = "{\"package\":\"foundation.e.apps.debug\",\"version\":\"2.5.5.debug\",\"device\":\"coral\",\"api\":32,\"os_version\":\"1.11-s-20230511288805-dev-coral\",\"build_id\":\"319e25cd.20230630224839\"}" + +private val testSystemProperties = Properties().apply { + setProperty("UserReadableName", "coral-default") + setProperty("Build.HARDWARE", "coral") + setProperty("Build.RADIO", "g8150-00123-220402-B-8399852") + setProperty("Build.FINGERPRINT","google/coral/coral:12/SQ3A.220705.003.A1/8672226:user/release-keys") + setProperty("Build.BRAND", "google") + setProperty("Build.DEVICE", "coral") + setProperty("Build.VERSION.SDK_INT", "32") + setProperty("Build.VERSION.RELEASE", "12") + setProperty("Build.MODEL", "Pixel 4 XL") + setProperty("Build.MANUFACTURER", "Google") + setProperty("Build.PRODUCT", "coral") + setProperty("Build.ID", "SQ3A.220705.004") + setProperty("Build.BOOTLOADER", "c2f2-0.4-8351033") + setProperty("TouchScreen", "3") + setProperty("Keyboard", "1") + setProperty("Navigation", "1") + setProperty("ScreenLayout", "2") + setProperty("HasHardKeyboard", "false") + setProperty("HasFiveWayNavigation", "false") + setProperty("Screen.Density", "560") + setProperty("Screen.Width", "1440") + setProperty("Screen.Height", "2984") + setProperty("Platforms", "arm64-v8a,armeabi-v7a,armeabi") + setProperty("Features", "android.hardware.sensor.proximity,com.verizon.hardware.telephony.lte,com.verizon.hardware.telephony.ehrpd,android.hardware.sensor.accelerometer,android.software.controls,android.hardware.faketouch,com.google.android.feature.D2D_CABLE_MIGRATION_FEATURE,android.hardware.telephony.euicc,android.hardware.reboot_escrow,android.hardware.usb.accessory,android.hardware.telephony.cdma,android.software.backup,android.hardware.touchscreen,android.hardware.touchscreen.multitouch,android.software.print,org.lineageos.weather,android.software.activities_on_secondary_displays,android.hardware.wifi.rtt,com.google.android.feature.PIXEL_2017_EXPERIENCE,android.software.voice_recognizers,android.software.picture_in_picture,android.hardware.sensor.gyroscope,android.hardware.audio.low_latency,android.software.vulkan.deqp.level,android.software.cant_save_state,com.google.android.feature.PIXEL_2018_EXPERIENCE,android.hardware.security.model.compatible,com.google.android.feature.PIXEL_2019_EXPERIENCE,android.hardware.opengles.aep,org.lineageos.livedisplay,org.lineageos.profiles,android.hardware.bluetooth,android.hardware.camera.autofocus,android.hardware.telephony.gsm,android.hardware.telephony.ims,android.software.incremental_delivery,android.software.sip.voip,android.hardware.se.omapi.ese,android.software.opengles.deqp.level,android.hardware.usb.host,android.hardware.audio.output,android.software.verified_boot,android.hardware.camera.flash,android.hardware.camera.front,android.hardware.sensor.hifi_sensors,com.google.android.apps.photos.PIXEL_2019_PRELOAD,android.hardware.se.omapi.uicc,android.hardware.strongbox_keystore,android.hardware.screen.portrait,android.hardware.nfc,com.google.android.feature.TURBO_PRELOAD,com.nxp.mifare,android.hardware.sensor.stepdetector,android.software.home_screen,android.hardware.context_hub,android.hardware.microphone,android.software.autofill,org.lineageos.hardware,org.lineageos.globalactions,android.software.securely_removes_users,com.google.android.feature.PIXEL_EXPERIENCE,android.hardware.bluetooth_le,android.hardware.sensor.compass,com.google.android.feature.GOOGLE_FI_BUNDLED,android.hardware.touchscreen.multitouch.jazzhand,android.hardware.sensor.barometer,android.software.app_widgets,android.hardware.telephony.carrierlock,android.software.input_methods,android.hardware.sensor.light,android.hardware.vulkan.version,android.software.companion_device_setup,android.software.device_admin,com.google.android.feature.WELLBEING,android.hardware.wifi.passpoint,android.hardware.camera,org.lineageos.trust,android.hardware.device_unique_attestation,android.hardware.screen.landscape,android.software.device_id_attestation,com.google.android.feature.AER_OPTIMIZED,android.hardware.ram.normal,org.lineageos.android,com.google.android.feature.PIXEL_2019_MIDYEAR_EXPERIENCE,android.software.managed_users,android.software.webview,android.hardware.sensor.stepcounter,android.hardware.camera.capability.manual_post_processing,android.hardware.camera.any,android.hardware.camera.capability.raw,android.hardware.vulkan.compute,android.software.connectionservice,android.hardware.touchscreen.multitouch.distinct,android.hardware.location.network,android.software.cts,android.software.sip,android.hardware.camera.capability.manual_sensor,android.software.app_enumeration,android.hardware.camera.level.full,android.hardware.identity_credential,android.hardware.wifi.direct,android.software.live_wallpaper,android.software.ipsec_tunnels,org.lineageos.settings,android.hardware.sensor.assist,android.hardware.audio.pro,android.hardware.nfc.hcef,android.hardware.nfc.uicc,android.hardware.location.gps,android.sofware.nfc.beam,android.software.midi,android.hardware.nfc.any,android.hardware.nfc.ese,android.hardware.nfc.hce,android.hardware.wifi,android.hardware.location,android.hardware.vulkan.level,android.hardware.wifi.aware,android.software.secure_lock_screen,android.hardware.biometrics.face,android.hardware.telephony,android.software.file_based_encryption") + setProperty("Locales", "af,af_ZA,am,am_ET,ar,ar_EG,ar_XB,as,ast_ES,az,be,bg,bg_BG,bn,bs,ca,ca_ES,cs,cs_CZ,cy,da,da_DK,de,de_DE,el,el_GR,en,en_AU,en_CA,en_GB,en_IN,en_US,en_XA,en_XC,es,es_419,es_ES,es_US,et,eu,fa,fa_IR,fi,fi_FI,fil,fil_PH,fr,fr_CA,fr_FR,gd,gl,gu,hi,hi_IN,hr,hr_HR,hu,hu_HU,hy,in,in_ID,is,it,it_IT,iw,iw_IL,ja,ja_JP,ka,kk,km,kn,ko,ko_KR,ky,lo,lt,lt_LT,lv,lv_LV,mk,ml,mn,mr,ms,ms_MY,my,nb,nb_NO,ne,nl,nl_NL,or,pa,pl,pl_PL,pt,pt_BR,pt_PT,ro,ro_RO,ru,ru_RU,si,sk,sk_SK,sl,sl_SI,sq,sr,sr_Latn,sr_RS,sv,sv_SE,sw,sw_TZ,ta,te,th,th_TH,tr,tr_TR,uk,uk_UA,ur,uz,vi,vi_VN,zh_CN,zh_HK,zh_TW,zu,zu_ZA") + setProperty("SharedLibraries", "android.test.base,android.test.mock,com.vzw.apnlib,android.hidl.manager-V1.0-java,qti-telephony-hidl-wrapper,libfastcvopt.so,google-ril,qti-telephony-utils,com.android.omadm.radioconfig,libcdsprpc.so,android.hidl.base-V1.0-java,com.qualcomm.qmapbridge,libairbrush-pixel.so,com.google.android.camera.experimental2019,libOpenCL-pixel.so,libadsprpc.so,com.android.location.provider,android.net.ipsec.ike,com.android.future.usb.accessory,libsdsprpc.so,android.ext.shared,javax.obex,izat.xt.srv,com.google.android.gms,lib_aion_buffer.so,com.qualcomm.uimremoteclientlibrary,libqdMetaData.so,com.qualcomm.uimremoteserverlibrary,com.qualcomm.qcrilhook,android.test.runner,org.apache.http.legacy,com.google.android.camera.extensions,com.google.android.hardwareinfo,com.android.cts.ctsshim.shared_library,com.android.nfc_extras,com.android.media.remotedisplay,com.android.mediadrm.signer,com.qualcomm.qti.imscmservice-V2.0-java,qti-telephony-hidl-wrapper-prd,com.qualcomm.qti.imscmservice-V2.1-java,com.qualcomm.qti.imscmservice-V2.2-java") + setProperty("GL.Version", "196610") + setProperty("GL.Extensions", ",GL_AMD_compressed_ATC_texture,GL_AMD_performance_monitor,GL_ANDROID_extension_pack_es31a,GL_APPLE_texture_2D_limited_npot,GL_ARB_vertex_buffer_object,GL_ARM_shader_framebuffer_fetch_depth_stencil,GL_EXT_EGL_image_array,GL_EXT_EGL_image_external_wrap_modes,GL_EXT_EGL_image_storage,GL_EXT_YUV_target,GL_EXT_blend_func_extended,GL_EXT_blit_framebuffer_params,GL_EXT_buffer_storage,GL_EXT_clip_control,GL_EXT_clip_cull_distance,GL_EXT_color_buffer_float,GL_EXT_color_buffer_half_float,GL_EXT_copy_image,GL_EXT_debug_label,GL_EXT_debug_marker,GL_EXT_discard_framebuffer,GL_EXT_disjoint_timer_query,GL_EXT_draw_buffers_indexed,GL_EXT_external_buffer,GL_EXT_fragment_invocation_density,GL_EXT_geometry_shader,GL_EXT_gpu_shader5,GL_EXT_memory_object,GL_EXT_memory_object_fd,GL_EXT_multisampled_render_to_texture,GL_EXT_multisampled_render_to_texture2,GL_EXT_primitive_bounding_box,GL_EXT_protected_textures,GL_EXT_read_format_bgra,GL_EXT_robustness,GL_EXT_sRGB,GL_EXT_sRGB_write_control,GL_EXT_shader_framebuffer_fetch,GL_EXT_shader_io_blocks,GL_EXT_shader_non_constant_global_initializers,GL_EXT_tessellation_shader,GL_EXT_texture_border_clamp,GL_EXT_texture_buffer,GL_EXT_texture_cube_map_array,GL_EXT_texture_filter_anisotropic,GL_EXT_texture_format_BGRA8888,GL_EXT_texture_format_sRGB_override,GL_EXT_texture_norm16,GL_EXT_texture_sRGB_R8,GL_EXT_texture_sRGB_decode,GL_EXT_texture_type_2_10_10_10_REV,GL_KHR_blend_equation_advanced,GL_KHR_blend_equation_advanced_coherent,GL_KHR_debug,GL_KHR_no_error,GL_KHR_robust_buffer_access_behavior,GL_KHR_texture_compression_astc_hdr,GL_KHR_texture_compression_astc_ldr,GL_NV_shader_noperspective_interpolation,GL_OES_EGL_image,GL_OES_EGL_image_external,GL_OES_EGL_image_external_essl3,GL_OES_EGL_sync,GL_OES_blend_equation_separate,GL_OES_blend_func_separate,GL_OES_blend_subtract,GL_OES_compressed_ETC1_RGB8_texture,GL_OES_compressed_paletted_texture,GL_OES_depth24,GL_OES_depth_texture,GL_OES_depth_texture_cube_map,GL_OES_draw_texture,GL_OES_element_index_uint,GL_OES_framebuffer_object,GL_OES_get_program_binary,GL_OES_matrix_palette,GL_OES_packed_depth_stencil,GL_OES_point_size_array,GL_OES_point_sprite,GL_OES_read_format,GL_OES_rgb8_rgba8,GL_OES_sample_shading,GL_OES_sample_variables,GL_OES_shader_image_atomic,GL_OES_shader_multisample_interpolation,GL_OES_standard_derivatives,GL_OES_stencil_wrap,GL_OES_surfaceless_context,GL_OES_texture_3D,GL_OES_texture_compression_astc,GL_OES_texture_cube_map,GL_OES_texture_env_crossbar,GL_OES_texture_float,GL_OES_texture_float_linear,GL_OES_texture_half_float,GL_OES_texture_half_float_linear,GL_OES_texture_mirrored_repeat,GL_OES_texture_npot,GL_OES_texture_stencil8,GL_OES_texture_storage_multisample_2d_array,GL_OES_texture_view,GL_OES_vertex_array_object,GL_OES_vertex_half_float,GL_OVR_multiview,GL_OVR_multiview2,GL_OVR_multiview_multisampled_render_to_texture,GL_QCOM_YUV_texture_gather,GL_QCOM_alpha_test,GL_QCOM_extended_get,GL_QCOM_motion_estimation,GL_QCOM_shader_framebuffer_fetch_noncoherent,GL_QCOM_shader_framebuffer_fetch_rate,GL_QCOM_texture_foveated,GL_QCOM_texture_foveated_subsampled_layout,GL_QCOM_tiled_rendering,GL_QCOM_validate_shader_binary") + setProperty("Client", "android-google") + setProperty("GSF.version", "223616055") + setProperty("Vending.version", "82151710") + setProperty("Vending.versionString", "21.5.17-21 [0] [PR] 326734551") + setProperty("Roaming", "mobile-notroaming") + setProperty("TimeZone", "UTC-10") + setProperty("CellOperator", "310") + setProperty("SimOperator", "38") +} + +// endregion \ No newline at end of file -- GitLab From b03c240cfeb8077598c241a034a2b2d6358aecad Mon Sep 17 00:00:00 2001 From: Nishant Dande Date: Tue, 4 Jul 2023 22:20:13 +0530 Subject: [PATCH 04/19] Added Anonymous login api --- modules/build.gradle | 6 +- .../java/app/lounge/AnonymousUserAPITest.kt | 79 ------------------- .../lounge/networking/AnonymousUserAPITest.kt | 57 +++++++++---- .../app/lounge/users/anonymous/Anonymous.kt | 19 ++++- .../lounge/users/anonymous/AnonymousAPI.kt | 17 +++- .../users/anonymous/RetrofitAnonymousAPI.kt | 40 +++++++--- 6 files changed, 111 insertions(+), 107 deletions(-) delete mode 100644 modules/src/androidTest/java/app/lounge/AnonymousUserAPITest.kt diff --git a/modules/build.gradle b/modules/build.gradle index 17b61982a..02731152a 100644 --- a/modules/build.gradle +++ b/modules/build.gradle @@ -34,11 +34,11 @@ android { } } compileOptions { - sourceCompatibility JavaVersion.VERSION_18 - targetCompatibility JavaVersion.VERSION_18 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = '18' + jvmTarget = '17' } } diff --git a/modules/src/androidTest/java/app/lounge/AnonymousUserAPITest.kt b/modules/src/androidTest/java/app/lounge/AnonymousUserAPITest.kt deleted file mode 100644 index 916c6fce4..000000000 --- a/modules/src/androidTest/java/app/lounge/AnonymousUserAPITest.kt +++ /dev/null @@ -1,79 +0,0 @@ -package app.lounge - -import app.lounge.users.anonymous.AnonymousAPI -import app.lounge.users.anonymous.AnonymousAuthDataRequestBody -import org.junit.Assert -import org.junit.Test -import java.util.Properties - -class AnonymousUserAPITest { - - private val testAnonymousAPI = AnonymousAPI.create( - baseURL = AnonymousAPI.tokenBaseURL - ) - - private val userAgent: String = "{\"package\":\"foundation.e.apps.debug\",\"version\":\"2.5.5.debug\",\"device\":\"coral\",\"api\":32,\"os_version\":\"1.11-s-20230511288805-dev-coral\",\"build_id\":\"319e25cd.20230630224839\"}" - - private val systemProperties = Properties().apply { - setProperty("UserReadableName", "coral-default") - setProperty("Build.HARDWARE", "coral") - setProperty("Build.RADIO", "g8150-00123-220402-B-8399852") - setProperty("Build.FINGERPRINT","google/coral/coral:12/SQ3A.220705.003.A1/8672226:user/release-keys") - setProperty("Build.BRAND", "google") - setProperty("Build.DEVICE", "coral") - setProperty("Build.VERSION.SDK_INT", "32") - setProperty("Build.VERSION.RELEASE", "12") - setProperty("Build.MODEL", "Pixel 4 XL") - setProperty("Build.MANUFACTURER", "Google") - setProperty("Build.PRODUCT", "coral") - setProperty("Build.ID", "SQ3A.220705.004") - setProperty("Build.BOOTLOADER", "c2f2-0.4-8351033") - setProperty("TouchScreen", "3") - setProperty("Keyboard", "1") - setProperty("Navigation", "1") - setProperty("ScreenLayout", "2") - setProperty("HasHardKeyboard", "false") - setProperty("HasFiveWayNavigation", "false") - setProperty("Screen.Density", "560") - setProperty("Screen.Width", "1440") - setProperty("Screen.Height", "2984") - setProperty("Platforms", "arm64-v8a,armeabi-v7a,armeabi") - setProperty("Features", "android.hardware.sensor.proximity,com.verizon.hardware.telephony.lte,com.verizon.hardware.telephony.ehrpd,android.hardware.sensor.accelerometer,android.software.controls,android.hardware.faketouch,com.google.android.feature.D2D_CABLE_MIGRATION_FEATURE,android.hardware.telephony.euicc,android.hardware.reboot_escrow,android.hardware.usb.accessory,android.hardware.telephony.cdma,android.software.backup,android.hardware.touchscreen,android.hardware.touchscreen.multitouch,android.software.print,org.lineageos.weather,android.software.activities_on_secondary_displays,android.hardware.wifi.rtt,com.google.android.feature.PIXEL_2017_EXPERIENCE,android.software.voice_recognizers,android.software.picture_in_picture,android.hardware.sensor.gyroscope,android.hardware.audio.low_latency,android.software.vulkan.deqp.level,android.software.cant_save_state,com.google.android.feature.PIXEL_2018_EXPERIENCE,android.hardware.security.model.compatible,com.google.android.feature.PIXEL_2019_EXPERIENCE,android.hardware.opengles.aep,org.lineageos.livedisplay,org.lineageos.profiles,android.hardware.bluetooth,android.hardware.camera.autofocus,android.hardware.telephony.gsm,android.hardware.telephony.ims,android.software.incremental_delivery,android.software.sip.voip,android.hardware.se.omapi.ese,android.software.opengles.deqp.level,android.hardware.usb.host,android.hardware.audio.output,android.software.verified_boot,android.hardware.camera.flash,android.hardware.camera.front,android.hardware.sensor.hifi_sensors,com.google.android.apps.photos.PIXEL_2019_PRELOAD,android.hardware.se.omapi.uicc,android.hardware.strongbox_keystore,android.hardware.screen.portrait,android.hardware.nfc,com.google.android.feature.TURBO_PRELOAD,com.nxp.mifare,android.hardware.sensor.stepdetector,android.software.home_screen,android.hardware.context_hub,android.hardware.microphone,android.software.autofill,org.lineageos.hardware,org.lineageos.globalactions,android.software.securely_removes_users,com.google.android.feature.PIXEL_EXPERIENCE,android.hardware.bluetooth_le,android.hardware.sensor.compass,com.google.android.feature.GOOGLE_FI_BUNDLED,android.hardware.touchscreen.multitouch.jazzhand,android.hardware.sensor.barometer,android.software.app_widgets,android.hardware.telephony.carrierlock,android.software.input_methods,android.hardware.sensor.light,android.hardware.vulkan.version,android.software.companion_device_setup,android.software.device_admin,com.google.android.feature.WELLBEING,android.hardware.wifi.passpoint,android.hardware.camera,org.lineageos.trust,android.hardware.device_unique_attestation,android.hardware.screen.landscape,android.software.device_id_attestation,com.google.android.feature.AER_OPTIMIZED,android.hardware.ram.normal,org.lineageos.android,com.google.android.feature.PIXEL_2019_MIDYEAR_EXPERIENCE,android.software.managed_users,android.software.webview,android.hardware.sensor.stepcounter,android.hardware.camera.capability.manual_post_processing,android.hardware.camera.any,android.hardware.camera.capability.raw,android.hardware.vulkan.compute,android.software.connectionservice,android.hardware.touchscreen.multitouch.distinct,android.hardware.location.network,android.software.cts,android.software.sip,android.hardware.camera.capability.manual_sensor,android.software.app_enumeration,android.hardware.camera.level.full,android.hardware.identity_credential,android.hardware.wifi.direct,android.software.live_wallpaper,android.software.ipsec_tunnels,org.lineageos.settings,android.hardware.sensor.assist,android.hardware.audio.pro,android.hardware.nfc.hcef,android.hardware.nfc.uicc,android.hardware.location.gps,android.sofware.nfc.beam,android.software.midi,android.hardware.nfc.any,android.hardware.nfc.ese,android.hardware.nfc.hce,android.hardware.wifi,android.hardware.location,android.hardware.vulkan.level,android.hardware.wifi.aware,android.software.secure_lock_screen,android.hardware.biometrics.face,android.hardware.telephony,android.software.file_based_encryption") - setProperty("Locales", "af,af_ZA,am,am_ET,ar,ar_EG,ar_XB,as,ast_ES,az,be,bg,bg_BG,bn,bs,ca,ca_ES,cs,cs_CZ,cy,da,da_DK,de,de_DE,el,el_GR,en,en_AU,en_CA,en_GB,en_IN,en_US,en_XA,en_XC,es,es_419,es_ES,es_US,et,eu,fa,fa_IR,fi,fi_FI,fil,fil_PH,fr,fr_CA,fr_FR,gd,gl,gu,hi,hi_IN,hr,hr_HR,hu,hu_HU,hy,in,in_ID,is,it,it_IT,iw,iw_IL,ja,ja_JP,ka,kk,km,kn,ko,ko_KR,ky,lo,lt,lt_LT,lv,lv_LV,mk,ml,mn,mr,ms,ms_MY,my,nb,nb_NO,ne,nl,nl_NL,or,pa,pl,pl_PL,pt,pt_BR,pt_PT,ro,ro_RO,ru,ru_RU,si,sk,sk_SK,sl,sl_SI,sq,sr,sr_Latn,sr_RS,sv,sv_SE,sw,sw_TZ,ta,te,th,th_TH,tr,tr_TR,uk,uk_UA,ur,uz,vi,vi_VN,zh_CN,zh_HK,zh_TW,zu,zu_ZA") - setProperty("SharedLibraries", "android.test.base,android.test.mock,com.vzw.apnlib,android.hidl.manager-V1.0-java,qti-telephony-hidl-wrapper,libfastcvopt.so,google-ril,qti-telephony-utils,com.android.omadm.radioconfig,libcdsprpc.so,android.hidl.base-V1.0-java,com.qualcomm.qmapbridge,libairbrush-pixel.so,com.google.android.camera.experimental2019,libOpenCL-pixel.so,libadsprpc.so,com.android.location.provider,android.net.ipsec.ike,com.android.future.usb.accessory,libsdsprpc.so,android.ext.shared,javax.obex,izat.xt.srv,com.google.android.gms,lib_aion_buffer.so,com.qualcomm.uimremoteclientlibrary,libqdMetaData.so,com.qualcomm.uimremoteserverlibrary,com.qualcomm.qcrilhook,android.test.runner,org.apache.http.legacy,com.google.android.camera.extensions,com.google.android.hardwareinfo,com.android.cts.ctsshim.shared_library,com.android.nfc_extras,com.android.media.remotedisplay,com.android.mediadrm.signer,com.qualcomm.qti.imscmservice-V2.0-java,qti-telephony-hidl-wrapper-prd,com.qualcomm.qti.imscmservice-V2.1-java,com.qualcomm.qti.imscmservice-V2.2-java") - setProperty("GL.Version", "196610") - setProperty("GL.Extensions", ",GL_AMD_compressed_ATC_texture,GL_AMD_performance_monitor,GL_ANDROID_extension_pack_es31a,GL_APPLE_texture_2D_limited_npot,GL_ARB_vertex_buffer_object,GL_ARM_shader_framebuffer_fetch_depth_stencil,GL_EXT_EGL_image_array,GL_EXT_EGL_image_external_wrap_modes,GL_EXT_EGL_image_storage,GL_EXT_YUV_target,GL_EXT_blend_func_extended,GL_EXT_blit_framebuffer_params,GL_EXT_buffer_storage,GL_EXT_clip_control,GL_EXT_clip_cull_distance,GL_EXT_color_buffer_float,GL_EXT_color_buffer_half_float,GL_EXT_copy_image,GL_EXT_debug_label,GL_EXT_debug_marker,GL_EXT_discard_framebuffer,GL_EXT_disjoint_timer_query,GL_EXT_draw_buffers_indexed,GL_EXT_external_buffer,GL_EXT_fragment_invocation_density,GL_EXT_geometry_shader,GL_EXT_gpu_shader5,GL_EXT_memory_object,GL_EXT_memory_object_fd,GL_EXT_multisampled_render_to_texture,GL_EXT_multisampled_render_to_texture2,GL_EXT_primitive_bounding_box,GL_EXT_protected_textures,GL_EXT_read_format_bgra,GL_EXT_robustness,GL_EXT_sRGB,GL_EXT_sRGB_write_control,GL_EXT_shader_framebuffer_fetch,GL_EXT_shader_io_blocks,GL_EXT_shader_non_constant_global_initializers,GL_EXT_tessellation_shader,GL_EXT_texture_border_clamp,GL_EXT_texture_buffer,GL_EXT_texture_cube_map_array,GL_EXT_texture_filter_anisotropic,GL_EXT_texture_format_BGRA8888,GL_EXT_texture_format_sRGB_override,GL_EXT_texture_norm16,GL_EXT_texture_sRGB_R8,GL_EXT_texture_sRGB_decode,GL_EXT_texture_type_2_10_10_10_REV,GL_KHR_blend_equation_advanced,GL_KHR_blend_equation_advanced_coherent,GL_KHR_debug,GL_KHR_no_error,GL_KHR_robust_buffer_access_behavior,GL_KHR_texture_compression_astc_hdr,GL_KHR_texture_compression_astc_ldr,GL_NV_shader_noperspective_interpolation,GL_OES_EGL_image,GL_OES_EGL_image_external,GL_OES_EGL_image_external_essl3,GL_OES_EGL_sync,GL_OES_blend_equation_separate,GL_OES_blend_func_separate,GL_OES_blend_subtract,GL_OES_compressed_ETC1_RGB8_texture,GL_OES_compressed_paletted_texture,GL_OES_depth24,GL_OES_depth_texture,GL_OES_depth_texture_cube_map,GL_OES_draw_texture,GL_OES_element_index_uint,GL_OES_framebuffer_object,GL_OES_get_program_binary,GL_OES_matrix_palette,GL_OES_packed_depth_stencil,GL_OES_point_size_array,GL_OES_point_sprite,GL_OES_read_format,GL_OES_rgb8_rgba8,GL_OES_sample_shading,GL_OES_sample_variables,GL_OES_shader_image_atomic,GL_OES_shader_multisample_interpolation,GL_OES_standard_derivatives,GL_OES_stencil_wrap,GL_OES_surfaceless_context,GL_OES_texture_3D,GL_OES_texture_compression_astc,GL_OES_texture_cube_map,GL_OES_texture_env_crossbar,GL_OES_texture_float,GL_OES_texture_float_linear,GL_OES_texture_half_float,GL_OES_texture_half_float_linear,GL_OES_texture_mirrored_repeat,GL_OES_texture_npot,GL_OES_texture_stencil8,GL_OES_texture_storage_multisample_2d_array,GL_OES_texture_view,GL_OES_vertex_array_object,GL_OES_vertex_half_float,GL_OVR_multiview,GL_OVR_multiview2,GL_OVR_multiview_multisampled_render_to_texture,GL_QCOM_YUV_texture_gather,GL_QCOM_alpha_test,GL_QCOM_extended_get,GL_QCOM_motion_estimation,GL_QCOM_shader_framebuffer_fetch_noncoherent,GL_QCOM_shader_framebuffer_fetch_rate,GL_QCOM_texture_foveated,GL_QCOM_texture_foveated_subsampled_layout,GL_QCOM_tiled_rendering,GL_QCOM_validate_shader_binary") - setProperty("Client", "android-google") - setProperty("GSF.version", "223616055") - setProperty("Vending.version", "82151710") - setProperty("Vending.versionString", "21.5.17-21 [0] [PR] 326734551") - setProperty("Roaming", "mobile-notroaming") - setProperty("TimeZone", "UTC-10") - setProperty("CellOperator", "310") - setProperty("SimOperator", "38") - } - - - private val requestBodyData = AnonymousAuthDataRequestBody( - properties = systemProperties, - userAgent = userAgent - ) - - @Test - fun testAPI() { - testAnonymousAPI.requestAuthData( - anonymousAuthDataRequestBody = requestBodyData, - success = { - print(it) - Assert.assertEquals("Hello", it) - }, - failure = { - print(it) - Assert.assertEquals("Hello", it.toString()) - } - ) - - Thread.sleep(30000) - } - -} \ No newline at end of file diff --git a/modules/src/androidTest/java/app/lounge/networking/AnonymousUserAPITest.kt b/modules/src/androidTest/java/app/lounge/networking/AnonymousUserAPITest.kt index 2b4eb65f3..7deb467ce 100644 --- a/modules/src/androidTest/java/app/lounge/networking/AnonymousUserAPITest.kt +++ b/modules/src/androidTest/java/app/lounge/networking/AnonymousUserAPITest.kt @@ -3,7 +3,9 @@ package app.lounge.networking import app.lounge.users.anonymous.Anonymous import app.lounge.users.anonymous.AnonymousAPI import app.lounge.users.anonymous.AnonymousAuthDataRequestBody +import app.lounge.users.anonymous.AnonymousLoginRequestBody import app.lounge.users.anonymous.AuthDataResponse +import org.junit.Assert import org.junit.Test import java.util.Properties @@ -13,27 +15,49 @@ class AnonymousUserAPITest { api = AnonymousAPI.create(AnonymousAPI.tokenBaseURL) ) -// private val testAnonymousAPIForLogin = Anonymous.anonymousRequestFor( -// api = AnonymousAPI.create(AnonymousAPI.loginBaseURL) -// ) + private val testAnonymousAPIForLogin = Anonymous.anonymousRequestFor( + api = AnonymousAPI.create(AnonymousAPI.loginBaseURL) + ) private val requestBodyData = AnonymousAuthDataRequestBody( properties = testSystemProperties, userAgent = testUserAgent ) + + companion object { + lateinit var receivedData: AuthDataResponse + } + @Test - fun testOnSuccessReturnsAuthData() { - var receivedData: AuthDataResponse? - testAnonymousAPIForToken.requestAuthData( - anonymousAuthDataRequestBody = requestBodyData, - success = { response -> - receivedData = response - assert(receivedData is AuthDataResponse) { "Assert!! Success must return data" } - }, - failure = {} - ) - Thread.sleep(3000) + fun test1OnSuccessReturnsAuthData() { + await { + testAnonymousAPIForToken.requestAuthData( + anonymousAuthDataRequestBody = requestBodyData, + success = { response -> + receivedData = response + assert(receivedData is AuthDataResponse) { "Assert!! Success must return data" } + }, + failure = {} + ) + } + } + + @Test + fun test2OnSuccessReturnsLoginData(){ + await { + testAnonymousAPIForLogin.requestLogin( + anonymousLoginRequestBody = AnonymousLoginRequestBody( + authDataResponse = receivedData + ), + success = { response -> + Assert.assertEquals("Hello", response.toString()) + }, + failure = { + Assert.assertEquals("Hello", it.toString()) + } + ) + } } } @@ -81,4 +105,9 @@ private val testSystemProperties = Properties().apply { setProperty("SimOperator", "38") } +fun await(callback: () -> Unit) { + callback.invoke() + Thread.sleep(3000) +} + // endregion \ No newline at end of file diff --git a/modules/src/main/java/app/lounge/users/anonymous/Anonymous.kt b/modules/src/main/java/app/lounge/users/anonymous/Anonymous.kt index 4dd0ef0e6..c53d75237 100644 --- a/modules/src/main/java/app/lounge/users/anonymous/Anonymous.kt +++ b/modules/src/main/java/app/lounge/users/anonymous/Anonymous.kt @@ -1,6 +1,8 @@ package app.lounge.users.anonymous import app.lounge.networking.FetchError +import com.aurora.gplayapi.data.models.AuthData +import com.aurora.gplayapi.data.models.PlayResponse /** * Implement API related to Anonymous login flow only. @@ -36,4 +38,19 @@ interface Anonymous { failure = failure ) } -} \ No newline at end of file + + fun requestLogin( + anonymousLoginRequestBody: AnonymousLoginRequestBody, + success : (LoginResponse) -> Unit, + failure : (FetchError) -> Unit + ) { + api.performUserLogin( + anonymousLoginRequestBody = anonymousLoginRequestBody, + success = success, + failure = failure + ) + } +} + +typealias AuthDataResponse = AuthData +typealias LoginResponse = PlayResponse \ No newline at end of file diff --git a/modules/src/main/java/app/lounge/users/anonymous/AnonymousAPI.kt b/modules/src/main/java/app/lounge/users/anonymous/AnonymousAPI.kt index 83473fdf0..fa237e9f5 100644 --- a/modules/src/main/java/app/lounge/users/anonymous/AnonymousAPI.kt +++ b/modules/src/main/java/app/lounge/users/anonymous/AnonymousAPI.kt @@ -1,13 +1,15 @@ package app.lounge.users.anonymous import app.lounge.networking.FetchError +import com.aurora.gplayapi.GooglePlayApi +import com.aurora.gplayapi.data.providers.HeaderProvider import java.util.Properties interface AnonymousAPI { companion object { const val tokenBaseURL: String = "https://eu.gtoken.ecloud.global" - const val loginBaseURL: String = "GooglePlayApi.URL_SYNC" + const val loginBaseURL: String = GooglePlayApi.URL_SYNC+"/" fun create(baseURL: String = tokenBaseURL) : AnonymousAPI { return RetrofitAnonymousAPI( @@ -24,6 +26,12 @@ interface AnonymousAPI { failure : (FetchError) -> Unit ) + fun performUserLogin( + anonymousLoginRequestBody: AnonymousLoginRequestBody, + success : (LoginResponse) -> Unit, + failure : (FetchError) -> Unit + ) + object Header { val authData: (() -> String) -> Map = { mapOf(Pair("User-Agent", it.invoke())) @@ -37,3 +45,10 @@ data class AnonymousAuthDataRequestBody( val properties: Properties, val userAgent: String ) + +/** AnonymousLoginRequestBody */ +data class AnonymousLoginRequestBody( + val authDataResponse: AuthDataResponse, +) { + val header = HeaderProvider.getAuthHeaders(authDataResponse) +} \ No newline at end of file diff --git a/modules/src/main/java/app/lounge/users/anonymous/RetrofitAnonymousAPI.kt b/modules/src/main/java/app/lounge/users/anonymous/RetrofitAnonymousAPI.kt index 4cf90c452..d65a6633f 100644 --- a/modules/src/main/java/app/lounge/users/anonymous/RetrofitAnonymousAPI.kt +++ b/modules/src/main/java/app/lounge/users/anonymous/RetrofitAnonymousAPI.kt @@ -5,9 +5,10 @@ import app.lounge.networking.FetchError import app.lounge.networking.RetrofitFetching import app.lounge.networking.appLounge import app.lounge.networking.fetch -import com.aurora.gplayapi.data.models.AuthData +import com.aurora.gplayapi.data.providers.HeaderProvider import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.RequestBody +import okhttp3.RequestBody.Companion.toRequestBody import retrofit2.Call import retrofit2.Retrofit import retrofit2.http.Body @@ -31,10 +32,16 @@ internal class RetrofitAnonymousAPI( @POST fun authDataRequest( - @Url url: String = "https://eu.gtoken.ecloud.global", + @Url url: String = AnonymousAPI.tokenBaseURL, @HeaderMap headers: Map, @Body requestBody: RequestBody ): Call + + @POST + fun loginUser( + @Url url: String = AnonymousAPI.loginBaseURL, + @HeaderMap headers: Map + ): Call } override fun requestAuthData( @@ -42,10 +49,14 @@ internal class RetrofitAnonymousAPI( success: (AuthDataResponse) -> Unit, failure: (FetchError) -> Unit ) { - val requestBody = RequestBody.create( - "application/json".toMediaTypeOrNull(), - anonymousAuthDataRequestBody.properties.toByteArray() - ) + val requestBody: RequestBody = + anonymousAuthDataRequestBody.properties.toByteArray().let { result -> + result.toRequestBody( + contentType = "application/json".toMediaTypeOrNull(), + offset = 0, + byteCount = result.size + ) + } fetch( endpoint = anonymousUserEndPoint.authDataRequest( @@ -59,6 +70,17 @@ internal class RetrofitAnonymousAPI( ) } -} - -typealias AuthDataResponse = AuthData \ No newline at end of file + override fun performUserLogin( + anonymousLoginRequestBody: AnonymousLoginRequestBody, + success: (LoginResponse) -> Unit, + failure: (FetchError) -> Unit + ) { + fetch( + endpoint = anonymousUserEndPoint.loginUser( + headers = anonymousLoginRequestBody.header + ), + success = success, + failure = failure + ) + } +} \ No newline at end of file -- GitLab From ca249997b95b3f979781ff9e15ac4612d519510e Mon Sep 17 00:00:00 2001 From: Nishant Dande Date: Wed, 5 Jul 2023 23:36:00 +0530 Subject: [PATCH 05/19] Handle auth data validation and timeout error --- .../lounge/networking/AnonymousUserAPITest.kt | 73 ++++++++++++++----- .../app/lounge/networking/RetrofitConfig.kt | 2 + .../app/lounge/users/anonymous/Anonymous.kt | 4 +- .../lounge/users/anonymous/AnonymousAPI.kt | 13 +++- .../users/anonymous/RetrofitAnonymousAPI.kt | 8 +- 5 files changed, 70 insertions(+), 30 deletions(-) diff --git a/modules/src/androidTest/java/app/lounge/networking/AnonymousUserAPITest.kt b/modules/src/androidTest/java/app/lounge/networking/AnonymousUserAPITest.kt index 7deb467ce..e39bb9f48 100644 --- a/modules/src/androidTest/java/app/lounge/networking/AnonymousUserAPITest.kt +++ b/modules/src/androidTest/java/app/lounge/networking/AnonymousUserAPITest.kt @@ -12,11 +12,18 @@ import java.util.Properties class AnonymousUserAPITest { private val testAnonymousAPIForToken = Anonymous.anonymousRequestFor( - api = AnonymousAPI.create(AnonymousAPI.tokenBaseURL) + api = AnonymousAPI.create(baseURL = AnonymousAPI.tokenBaseURL) ) private val testAnonymousAPIForLogin = Anonymous.anonymousRequestFor( - api = AnonymousAPI.create(AnonymousAPI.loginBaseURL) + api = AnonymousAPI.create(baseURL = AnonymousAPI.loginBaseURL) + ) + + private val testAnonymousAPIForLoginTimeout = Anonymous.anonymousRequestFor( + api = AnonymousAPI.create( + baseURL = AnonymousAPI.loginBaseURL, + callTimeoutInSeconds = 1 + ) ) private val requestBodyData = AnonymousAuthDataRequestBody( @@ -24,9 +31,8 @@ class AnonymousUserAPITest { userAgent = testUserAgent ) - companion object { - lateinit var receivedData: AuthDataResponse + var receivedData: AuthDataResponse? = null } @Test @@ -34,32 +40,59 @@ class AnonymousUserAPITest { await { testAnonymousAPIForToken.requestAuthData( anonymousAuthDataRequestBody = requestBodyData, - success = { response -> - receivedData = response - assert(receivedData is AuthDataResponse) { "Assert!! Success must return data" } - }, - failure = {} + success = { response -> receivedData = response }, + failure = { } ) } + assert(receivedData is AuthDataResponse) { "Assert!! Success must return data" } } @Test fun test2OnSuccessReturnsLoginData(){ await { - testAnonymousAPIForLogin.requestLogin( - anonymousLoginRequestBody = AnonymousLoginRequestBody( - authDataResponse = receivedData - ), - success = { response -> - Assert.assertEquals("Hello", response.toString()) - }, - failure = { - Assert.assertEquals("Hello", it.toString()) - } - ) + receivedData?.let { authData -> + authData.dfeCookie = "null" + + testAnonymousAPIForLogin.requestLogin( + anonymousLoginRequestBody = AnonymousLoginRequestBody( + authDataResponse = authData + ), + success = { response -> + Assert.assertNotNull( + "Assert!! `response` must have data", + response + ) + }, + failure = {} + ) + } ?: run { + assert(receivedData == null) { "Assert!! `receivedData` must not have null" } + } } } + @Test + fun test3OnTimeoutFailureReturnsError(){ + await { + receivedData?.let { authData -> + authData.dfeCookie = "null" + testAnonymousAPIForLoginTimeout.requestLogin( + anonymousLoginRequestBody = AnonymousLoginRequestBody( + authDataResponse = authData + ), + success = {}, + failure = { + assert(it.toString().contains("timeout")) { + "Assert!! Failure callback must handle timeout error" + } + } + ) + } ?: run { + assert(receivedData == null) { "Assert!! `receivedData` must have data" } + } + + } + } } // region TestData diff --git a/modules/src/main/java/app/lounge/networking/RetrofitConfig.kt b/modules/src/main/java/app/lounge/networking/RetrofitConfig.kt index fb6290cdf..8c1314f69 100644 --- a/modules/src/main/java/app/lounge/networking/RetrofitConfig.kt +++ b/modules/src/main/java/app/lounge/networking/RetrofitConfig.kt @@ -26,6 +26,8 @@ internal fun Retrofit.Builder.appLounge( OkHttpClient.Builder() .addNetworkInterceptor(interceptor) .callTimeout(callTimeoutInSeconds, TimeUnit.SECONDS) + .connectTimeout(callTimeoutInSeconds, TimeUnit.SECONDS) + .readTimeout(callTimeoutInSeconds, TimeUnit.SECONDS) .followRedirects(shouldFollowRedirects) .build() ) diff --git a/modules/src/main/java/app/lounge/users/anonymous/Anonymous.kt b/modules/src/main/java/app/lounge/users/anonymous/Anonymous.kt index c53d75237..3b1a2cbd0 100644 --- a/modules/src/main/java/app/lounge/users/anonymous/Anonymous.kt +++ b/modules/src/main/java/app/lounge/users/anonymous/Anonymous.kt @@ -2,7 +2,7 @@ package app.lounge.users.anonymous import app.lounge.networking.FetchError import com.aurora.gplayapi.data.models.AuthData -import com.aurora.gplayapi.data.models.PlayResponse +import okhttp3.ResponseBody /** * Implement API related to Anonymous login flow only. @@ -53,4 +53,4 @@ interface Anonymous { } typealias AuthDataResponse = AuthData -typealias LoginResponse = PlayResponse \ No newline at end of file +typealias LoginResponse = ResponseBody \ No newline at end of file diff --git a/modules/src/main/java/app/lounge/users/anonymous/AnonymousAPI.kt b/modules/src/main/java/app/lounge/users/anonymous/AnonymousAPI.kt index fa237e9f5..9d70ab61d 100644 --- a/modules/src/main/java/app/lounge/users/anonymous/AnonymousAPI.kt +++ b/modules/src/main/java/app/lounge/users/anonymous/AnonymousAPI.kt @@ -9,13 +9,13 @@ interface AnonymousAPI { companion object { const val tokenBaseURL: String = "https://eu.gtoken.ecloud.global" - const val loginBaseURL: String = GooglePlayApi.URL_SYNC+"/" + const val loginBaseURL: String = GooglePlayApi.URL_BASE - fun create(baseURL: String = tokenBaseURL) : AnonymousAPI { + fun create(baseURL: String = tokenBaseURL, callTimeoutInSeconds: Long = 10) : AnonymousAPI { return RetrofitAnonymousAPI( baseURL = baseURL, anonymousUserEndpointFollowsRedirects = true, - callTimeoutInSeconds = 30 + callTimeoutInSeconds = callTimeoutInSeconds ) } } @@ -38,6 +38,11 @@ interface AnonymousAPI { } } + object Path { + const val authData = "/" + const val sync = "/fdfe/apps/contentSync" + } + } /** AnonymousAuthDataRequestBody */ @@ -50,5 +55,5 @@ data class AnonymousAuthDataRequestBody( data class AnonymousLoginRequestBody( val authDataResponse: AuthDataResponse, ) { - val header = HeaderProvider.getAuthHeaders(authDataResponse) + val header = HeaderProvider.getDefaultHeaders(authDataResponse) } \ No newline at end of file diff --git a/modules/src/main/java/app/lounge/users/anonymous/RetrofitAnonymousAPI.kt b/modules/src/main/java/app/lounge/users/anonymous/RetrofitAnonymousAPI.kt index d65a6633f..d2d2aac97 100644 --- a/modules/src/main/java/app/lounge/users/anonymous/RetrofitAnonymousAPI.kt +++ b/modules/src/main/java/app/lounge/users/anonymous/RetrofitAnonymousAPI.kt @@ -9,10 +9,12 @@ import com.aurora.gplayapi.data.providers.HeaderProvider import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.RequestBody import okhttp3.RequestBody.Companion.toRequestBody +import org.json.JSONObject import retrofit2.Call import retrofit2.Retrofit import retrofit2.http.Body import retrofit2.http.HeaderMap +import retrofit2.http.Headers import retrofit2.http.POST import retrofit2.http.Url @@ -30,16 +32,14 @@ internal class RetrofitAnonymousAPI( interface AnonymousUserEndPointEndpoint { - @POST + @POST(AnonymousAPI.Path.authData) fun authDataRequest( - @Url url: String = AnonymousAPI.tokenBaseURL, @HeaderMap headers: Map, @Body requestBody: RequestBody ): Call - @POST + @POST(AnonymousAPI.Path.sync) fun loginUser( - @Url url: String = AnonymousAPI.loginBaseURL, @HeaderMap headers: Map ): Call } -- GitLab From 614472bc599f93d20b663f7a0545c31ebe851970 Mon Sep 17 00:00:00 2001 From: Nishant Dande Date: Wed, 5 Jul 2023 23:41:46 +0530 Subject: [PATCH 06/19] Rename UserLogin api to AuthDataValidation --- .../app/lounge/networking/AnonymousUserAPITest.kt | 10 +++++----- .../java/app/lounge/users/anonymous/Anonymous.kt | 12 ++++++------ .../app/lounge/users/anonymous/AnonymousAPI.kt | 8 ++++---- .../lounge/users/anonymous/RetrofitAnonymousAPI.kt | 14 +++++--------- 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/modules/src/androidTest/java/app/lounge/networking/AnonymousUserAPITest.kt b/modules/src/androidTest/java/app/lounge/networking/AnonymousUserAPITest.kt index e39bb9f48..897a93889 100644 --- a/modules/src/androidTest/java/app/lounge/networking/AnonymousUserAPITest.kt +++ b/modules/src/androidTest/java/app/lounge/networking/AnonymousUserAPITest.kt @@ -3,7 +3,7 @@ package app.lounge.networking import app.lounge.users.anonymous.Anonymous import app.lounge.users.anonymous.AnonymousAPI import app.lounge.users.anonymous.AnonymousAuthDataRequestBody -import app.lounge.users.anonymous.AnonymousLoginRequestBody +import app.lounge.users.anonymous.AnonymousAuthDataValidationRequestBody import app.lounge.users.anonymous.AuthDataResponse import org.junit.Assert import org.junit.Test @@ -53,8 +53,8 @@ class AnonymousUserAPITest { receivedData?.let { authData -> authData.dfeCookie = "null" - testAnonymousAPIForLogin.requestLogin( - anonymousLoginRequestBody = AnonymousLoginRequestBody( + testAnonymousAPIForLogin.requestAuthDataValidation( + anonymousAuthDataValidationRequestBody = AnonymousAuthDataValidationRequestBody( authDataResponse = authData ), success = { response -> @@ -76,8 +76,8 @@ class AnonymousUserAPITest { await { receivedData?.let { authData -> authData.dfeCookie = "null" - testAnonymousAPIForLoginTimeout.requestLogin( - anonymousLoginRequestBody = AnonymousLoginRequestBody( + testAnonymousAPIForLoginTimeout.requestAuthDataValidation( + anonymousAuthDataValidationRequestBody = AnonymousAuthDataValidationRequestBody( authDataResponse = authData ), success = {}, diff --git a/modules/src/main/java/app/lounge/users/anonymous/Anonymous.kt b/modules/src/main/java/app/lounge/users/anonymous/Anonymous.kt index 3b1a2cbd0..8054cc998 100644 --- a/modules/src/main/java/app/lounge/users/anonymous/Anonymous.kt +++ b/modules/src/main/java/app/lounge/users/anonymous/Anonymous.kt @@ -39,13 +39,13 @@ interface Anonymous { ) } - fun requestLogin( - anonymousLoginRequestBody: AnonymousLoginRequestBody, - success : (LoginResponse) -> Unit, + fun requestAuthDataValidation( + anonymousAuthDataValidationRequestBody: AnonymousAuthDataValidationRequestBody, + success : (AuthDataValidationResponse) -> Unit, failure : (FetchError) -> Unit ) { - api.performUserLogin( - anonymousLoginRequestBody = anonymousLoginRequestBody, + api.requestAuthDataValidation( + anonymousAuthDataValidationRequestBody = anonymousAuthDataValidationRequestBody, success = success, failure = failure ) @@ -53,4 +53,4 @@ interface Anonymous { } typealias AuthDataResponse = AuthData -typealias LoginResponse = ResponseBody \ No newline at end of file +typealias AuthDataValidationResponse = ResponseBody \ No newline at end of file diff --git a/modules/src/main/java/app/lounge/users/anonymous/AnonymousAPI.kt b/modules/src/main/java/app/lounge/users/anonymous/AnonymousAPI.kt index 9d70ab61d..44f9ad4e6 100644 --- a/modules/src/main/java/app/lounge/users/anonymous/AnonymousAPI.kt +++ b/modules/src/main/java/app/lounge/users/anonymous/AnonymousAPI.kt @@ -26,9 +26,9 @@ interface AnonymousAPI { failure : (FetchError) -> Unit ) - fun performUserLogin( - anonymousLoginRequestBody: AnonymousLoginRequestBody, - success : (LoginResponse) -> Unit, + fun requestAuthDataValidation( + anonymousAuthDataValidationRequestBody: AnonymousAuthDataValidationRequestBody, + success : (AuthDataValidationResponse) -> Unit, failure : (FetchError) -> Unit ) @@ -52,7 +52,7 @@ data class AnonymousAuthDataRequestBody( ) /** AnonymousLoginRequestBody */ -data class AnonymousLoginRequestBody( +data class AnonymousAuthDataValidationRequestBody( val authDataResponse: AuthDataResponse, ) { val header = HeaderProvider.getDefaultHeaders(authDataResponse) diff --git a/modules/src/main/java/app/lounge/users/anonymous/RetrofitAnonymousAPI.kt b/modules/src/main/java/app/lounge/users/anonymous/RetrofitAnonymousAPI.kt index d2d2aac97..49bf4c321 100644 --- a/modules/src/main/java/app/lounge/users/anonymous/RetrofitAnonymousAPI.kt +++ b/modules/src/main/java/app/lounge/users/anonymous/RetrofitAnonymousAPI.kt @@ -5,18 +5,14 @@ import app.lounge.networking.FetchError import app.lounge.networking.RetrofitFetching import app.lounge.networking.appLounge import app.lounge.networking.fetch -import com.aurora.gplayapi.data.providers.HeaderProvider import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.RequestBody import okhttp3.RequestBody.Companion.toRequestBody -import org.json.JSONObject import retrofit2.Call import retrofit2.Retrofit import retrofit2.http.Body import retrofit2.http.HeaderMap -import retrofit2.http.Headers import retrofit2.http.POST -import retrofit2.http.Url internal class RetrofitAnonymousAPI( baseURL: String, @@ -41,7 +37,7 @@ internal class RetrofitAnonymousAPI( @POST(AnonymousAPI.Path.sync) fun loginUser( @HeaderMap headers: Map - ): Call + ): Call } override fun requestAuthData( @@ -70,14 +66,14 @@ internal class RetrofitAnonymousAPI( ) } - override fun performUserLogin( - anonymousLoginRequestBody: AnonymousLoginRequestBody, - success: (LoginResponse) -> Unit, + override fun requestAuthDataValidation( + anonymousAuthDataValidationRequestBody: AnonymousAuthDataValidationRequestBody, + success: (AuthDataValidationResponse) -> Unit, failure: (FetchError) -> Unit ) { fetch( endpoint = anonymousUserEndPoint.loginUser( - headers = anonymousLoginRequestBody.header + headers = anonymousAuthDataValidationRequestBody.header ), success = success, failure = failure -- GitLab From 90ea86542ebcf07e6316bffcaed9b385534af8cc Mon Sep 17 00:00:00 2001 From: Nishant Dande Date: Thu, 6 Jul 2023 21:16:48 +0530 Subject: [PATCH 07/19] Modifiy the codebase as per review comment --- .../java/app/lounge/networking/AnonymousUserAPITest.kt | 4 ---- .../src/main/java/app/lounge/users/anonymous/Anonymous.kt | 7 ------- 2 files changed, 11 deletions(-) diff --git a/modules/src/androidTest/java/app/lounge/networking/AnonymousUserAPITest.kt b/modules/src/androidTest/java/app/lounge/networking/AnonymousUserAPITest.kt index 897a93889..428b3d632 100644 --- a/modules/src/androidTest/java/app/lounge/networking/AnonymousUserAPITest.kt +++ b/modules/src/androidTest/java/app/lounge/networking/AnonymousUserAPITest.kt @@ -95,8 +95,6 @@ class AnonymousUserAPITest { } } -// region TestData - private const val testUserAgent: String = "{\"package\":\"foundation.e.apps.debug\",\"version\":\"2.5.5.debug\",\"device\":\"coral\",\"api\":32,\"os_version\":\"1.11-s-20230511288805-dev-coral\",\"build_id\":\"319e25cd.20230630224839\"}" private val testSystemProperties = Properties().apply { @@ -142,5 +140,3 @@ fun await(callback: () -> Unit) { callback.invoke() Thread.sleep(3000) } - -// endregion \ No newline at end of file diff --git a/modules/src/main/java/app/lounge/users/anonymous/Anonymous.kt b/modules/src/main/java/app/lounge/users/anonymous/Anonymous.kt index 8054cc998..2192e021e 100644 --- a/modules/src/main/java/app/lounge/users/anonymous/Anonymous.kt +++ b/modules/src/main/java/app/lounge/users/anonymous/Anonymous.kt @@ -4,13 +4,6 @@ import app.lounge.networking.FetchError import com.aurora.gplayapi.data.models.AuthData import okhttp3.ResponseBody -/** - * Implement API related to Anonymous login flow only. - * 1. Login api for Anonymous users. - * 2. Parsing Anonymous user data. For now use typealias object, later we will refactor with generic type - * 3. Add unit test cases for the api functions. - * */ - interface Anonymous { val api: AnonymousAPI -- GitLab From cd686a0ca4a1881802d74f0f5352adb43fe11913 Mon Sep 17 00:00:00 2001 From: Nishant Dande Date: Thu, 6 Jul 2023 22:24:06 +0530 Subject: [PATCH 08/19] Fix CI build issue --- modules/build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/build.gradle b/modules/build.gradle index 02731152a..0323af5d3 100644 --- a/modules/build.gradle +++ b/modules/build.gradle @@ -34,11 +34,11 @@ android { } } compileOptions { - sourceCompatibility JavaVersion.VERSION_17 - targetCompatibility JavaVersion.VERSION_17 + sourceCompatibility JavaVersion.VERSION_11 + targetCompatibility JavaVersion.VERSION_11 } kotlinOptions { - jvmTarget = '17' + jvmTarget = '11' } } -- GitLab From 82e7a42b75948cc0473082097feb4942ef346f44 Mon Sep 17 00:00:00 2001 From: Nishant Dande Date: Thu, 6 Jul 2023 22:47:35 +0530 Subject: [PATCH 09/19] Fix build integration issue --- modules/src/main/java/app/lounge/storage/cache/Persistence.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/src/main/java/app/lounge/storage/cache/Persistence.kt b/modules/src/main/java/app/lounge/storage/cache/Persistence.kt index 9c0a98302..2130a092b 100644 --- a/modules/src/main/java/app/lounge/storage/cache/Persistence.kt +++ b/modules/src/main/java/app/lounge/storage/cache/Persistence.kt @@ -47,7 +47,7 @@ class PersistedConfiguration(context: Context) { //region - Persistence (in shared preferences) -private class PersistedItem( +internal class PersistedItem( context: Context, val key: PersistenceKey, var defaultValue: T @@ -91,7 +91,7 @@ private class PersistedItem( } -private fun Context.persisted(key: PersistenceKey, defaultValue: T) : PersistedItem { +internal fun Context.persisted(key: PersistenceKey, defaultValue: T) : PersistedItem { return PersistedItem(context = this, key = key, defaultValue = defaultValue) } -- GitLab From 8c7f3eb191fcc5af22bb1b2d09a6a8f7339f0a02 Mon Sep 17 00:00:00 2001 From: Nishant Dande Date: Thu, 6 Jul 2023 22:53:08 +0530 Subject: [PATCH 10/19] Modify Persistent name as per review comment --- .../java/app/lounge/PersistentStorageTest.kt | 6 +-- .../app/lounge/storage/cache/Persistence.kt | 49 +++++++------------ 2 files changed, 21 insertions(+), 34 deletions(-) diff --git a/modules/src/androidTest/java/app/lounge/PersistentStorageTest.kt b/modules/src/androidTest/java/app/lounge/PersistentStorageTest.kt index a51050bdf..6161b1cfb 100644 --- a/modules/src/androidTest/java/app/lounge/PersistentStorageTest.kt +++ b/modules/src/androidTest/java/app/lounge/PersistentStorageTest.kt @@ -2,7 +2,7 @@ package app.lounge import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.platform.app.InstrumentationRegistry -import app.lounge.storage.cache.PersistedConfiguration +import app.lounge.storage.cache.PersistentConfiguration import app.lounge.storage.cache.PersistenceKey import app.lounge.storage.cache.configurations import com.google.gson.Gson @@ -15,7 +15,7 @@ import kotlin.reflect.KClassifier @RunWith(AndroidJUnit4::class) class PersistentStorageTest { - private lateinit var testConfiguration: PersistedConfiguration + private lateinit var testConfiguration: PersistentConfiguration @Before fun setupPersistentConfiguration(){ @@ -92,7 +92,7 @@ private inline fun T.getPropertyReturnType(name: String): KCla .firstOrNull { it.name == name } ?.returnType ?.classifier -private fun PersistedConfiguration.evaluateValue(classifier: KClassifier?, key: PersistenceKey) { +private fun PersistentConfiguration.evaluateValue(classifier: KClassifier?, key: PersistenceKey) { when(classifier){ Int::class -> Assert.assertEquals( "Expected to be `$testIntValue`", testIntValue, this.callMethod(key.name) as Int) diff --git a/modules/src/main/java/app/lounge/storage/cache/Persistence.kt b/modules/src/main/java/app/lounge/storage/cache/Persistence.kt index 2130a092b..6c089a458 100644 --- a/modules/src/main/java/app/lounge/storage/cache/Persistence.kt +++ b/modules/src/main/java/app/lounge/storage/cache/Persistence.kt @@ -4,13 +4,7 @@ import android.content.Context import kotlin.reflect.KProperty -//region Setter Accessors (primarily used for setting) - -val Context.configurations: PersistedConfiguration get() = PersistedConfiguration(context = this) - -//endregion - -// region - Persistence Configuration +val Context.configurations: PersistentConfiguration get() = PersistentConfiguration(context = this) internal enum class PersistenceKey { updateInstallAuto, @@ -28,26 +22,22 @@ internal enum class PersistenceKey { tosversion } -class PersistedConfiguration(context: Context) { - var updateInstallAuto by context.persisted(PersistenceKey.updateInstallAuto, false) - var updateCheckIntervals by context.persisted(PersistenceKey.updateCheckIntervals, 24) - var updateAppsFromOtherStores by context.persisted(PersistenceKey.updateAppsFromOtherStores, false) - var showAllApplications by context.persisted(PersistenceKey.showAllApplications, true) - var showPWAApplications by context.persisted(PersistenceKey.showPWAApplications, true) - var showFOSSApplications by context.persisted(PersistenceKey.showFOSSApplications, true) - var authData by context.persisted(PersistenceKey.authData, "") - var email by context.persisted(PersistenceKey.email, "") - var oauthtoken by context.persisted(PersistenceKey.oauthtoken, "") - var userType by context.persisted(PersistenceKey.userType, "") - var tocStatus by context.persisted(PersistenceKey.tocStatus, false) - var tosversion by context.persisted(PersistenceKey.tosversion, "") +class PersistentConfiguration(context: Context) { + var updateInstallAuto by context.persistent(PersistenceKey.updateInstallAuto, false) + var updateCheckIntervals by context.persistent(PersistenceKey.updateCheckIntervals, 24) + var updateAppsFromOtherStores by context.persistent(PersistenceKey.updateAppsFromOtherStores, false) + var showAllApplications by context.persistent(PersistenceKey.showAllApplications, true) + var showPWAApplications by context.persistent(PersistenceKey.showPWAApplications, true) + var showFOSSApplications by context.persistent(PersistenceKey.showFOSSApplications, true) + var authData by context.persistent(PersistenceKey.authData, "") + var email by context.persistent(PersistenceKey.email, "") + var oauthtoken by context.persistent(PersistenceKey.oauthtoken, "") + var userType by context.persistent(PersistenceKey.userType, "") + var tocStatus by context.persistent(PersistenceKey.tocStatus, false) + var tosversion by context.persistent(PersistenceKey.tosversion, "") } -// endregion - -//region - Persistence (in shared preferences) - -internal class PersistedItem( +internal class PersistentItem( context: Context, val key: PersistenceKey, var defaultValue: T @@ -90,9 +80,6 @@ internal class PersistedItem( } } - -internal fun Context.persisted(key: PersistenceKey, defaultValue: T) : PersistedItem { - return PersistedItem(context = this, key = key, defaultValue = defaultValue) -} - -//endregion \ No newline at end of file +internal fun Context.persistent(key: PersistenceKey, defaultValue: T) : PersistentItem { + return PersistentItem(context = this, key = key, defaultValue = defaultValue) +} \ No newline at end of file -- GitLab From 3eb894861a48bb91ced0d4476507112d21701623 Mon Sep 17 00:00:00 2001 From: Nishant Dande Date: Fri, 7 Jul 2023 00:03:01 +0530 Subject: [PATCH 11/19] Modifed FetchError as per review comments --- .../lounge/networking/AnonymousUserAPITest.kt | 37 ++++++++----------- .../java/app/lounge/networking/FetchError.kt | 23 +++++------- .../app/lounge/networking/NetworkFetching.kt | 34 +++++++++-------- 3 files changed, 43 insertions(+), 51 deletions(-) diff --git a/modules/src/androidTest/java/app/lounge/networking/AnonymousUserAPITest.kt b/modules/src/androidTest/java/app/lounge/networking/AnonymousUserAPITest.kt index 428b3d632..ab364f291 100644 --- a/modules/src/androidTest/java/app/lounge/networking/AnonymousUserAPITest.kt +++ b/modules/src/androidTest/java/app/lounge/networking/AnonymousUserAPITest.kt @@ -5,7 +5,7 @@ import app.lounge.users.anonymous.AnonymousAPI import app.lounge.users.anonymous.AnonymousAuthDataRequestBody import app.lounge.users.anonymous.AnonymousAuthDataValidationRequestBody import app.lounge.users.anonymous.AuthDataResponse -import org.junit.Assert +import app.lounge.users.anonymous.AuthDataValidationResponse import org.junit.Test import java.util.Properties @@ -32,7 +32,7 @@ class AnonymousUserAPITest { ) companion object { - var receivedData: AuthDataResponse? = null + var authData: AuthDataResponse? = null } @Test @@ -40,58 +40,51 @@ class AnonymousUserAPITest { await { testAnonymousAPIForToken.requestAuthData( anonymousAuthDataRequestBody = requestBodyData, - success = { response -> receivedData = response }, + success = { response -> authData = response }, failure = { } ) } - assert(receivedData is AuthDataResponse) { "Assert!! Success must return data" } + assert(authData is AuthDataResponse) { "Assert!! Success must return data" } } @Test fun test2OnSuccessReturnsLoginData(){ + var response: AuthDataValidationResponse? = null await { - receivedData?.let { authData -> + authData?.let { authData -> authData.dfeCookie = "null" testAnonymousAPIForLogin.requestAuthDataValidation( anonymousAuthDataValidationRequestBody = AnonymousAuthDataValidationRequestBody( authDataResponse = authData ), - success = { response -> - Assert.assertNotNull( - "Assert!! `response` must have data", - response - ) - }, + success = { result -> response = result }, failure = {} ) - } ?: run { - assert(receivedData == null) { "Assert!! `receivedData` must not have null" } } } + assert(authData is AuthDataResponse) { "Assert!! AuthData must be present" } + assert(response is AuthDataValidationResponse) { "Assert!! `response` must have data" } } @Test fun test3OnTimeoutFailureReturnsError(){ + var failure: FetchError? = null await { - receivedData?.let { authData -> + authData?.let { authData -> authData.dfeCookie = "null" testAnonymousAPIForLoginTimeout.requestAuthDataValidation( anonymousAuthDataValidationRequestBody = AnonymousAuthDataValidationRequestBody( authDataResponse = authData ), success = {}, - failure = { - assert(it.toString().contains("timeout")) { - "Assert!! Failure callback must handle timeout error" - } - } + failure = { error -> failure = error } ) - } ?: run { - assert(receivedData == null) { "Assert!! `receivedData` must have data" } } - } + assert(authData is AuthDataResponse) { "Assert!! AuthData must be present" } + failure?.description?.contains("timeout") + ?.let { assert(it) { "Assert!! Timeout Failure callback must call" } } } } diff --git a/modules/src/main/java/app/lounge/networking/FetchError.kt b/modules/src/main/java/app/lounge/networking/FetchError.kt index 271b4ab3b..a02f19392 100644 --- a/modules/src/main/java/app/lounge/networking/FetchError.kt +++ b/modules/src/main/java/app/lounge/networking/FetchError.kt @@ -1,28 +1,25 @@ package app.lounge.networking -//region Generic Network Error Types - sealed interface FetchError { - data class Network(val underlyingError: AnyFetchError) : FetchError -} - -/** Supertype for network error types. */ -sealed interface AnyFetchError { var description: String - enum class BadRequest(override var description: String) : AnyFetchError { + enum class BadRequest(override var description: String) : FetchError { Encode("FIXME: Error encoding request! $dumpKeyWord"), Decode("FIXME: Error decoding request! $dumpKeyWord"), } - enum class NotFound(override var description: String) : AnyFetchError { + enum class NotFound(override var description: String) : FetchError { MissingData("No data found! $dumpKeyWord"), MissingNetwork("No network! $dumpKeyWord") } - data class BadStatusCode (val statusCode: Int, val rawResponse: Any) : AnyFetchError { + enum class InterruptedIO(override var description: String) : FetchError { + Timeout("Timeout Error! $dumpKeyWord") + } + + data class BadStatusCode (val statusCode: Int, val rawResponse: Any) : FetchError { override var description: String = "Bad status code: $statusCode. Raw response: $rawResponse" } @@ -34,17 +31,15 @@ sealed interface AnyFetchError { */ data class Unknown( override var description: String = "Unknown Error! $dumpKeyWord" - ) : AnyFetchError + ) : FetchError companion object { const val dumpKeyWord: String = "dump:-" - fun make(error: AnyFetchError, addingDump: String) : AnyFetchError { + fun make(error: FetchError, addingDump: String = "") : FetchError { error.description = error.description + addingDump return error } } } - -//endregion diff --git a/modules/src/main/java/app/lounge/networking/NetworkFetching.kt b/modules/src/main/java/app/lounge/networking/NetworkFetching.kt index a8493d686..ccbc0f8d6 100644 --- a/modules/src/main/java/app/lounge/networking/NetworkFetching.kt +++ b/modules/src/main/java/app/lounge/networking/NetworkFetching.kt @@ -3,6 +3,7 @@ package app.lounge.networking import retrofit2.Call import retrofit2.Callback import retrofit2.Response +import java.io.InterruptedIOException import java.lang.IllegalStateException import java.net.UnknownHostException @@ -35,7 +36,7 @@ interface NetworkFetching { val errorFromFailureResponse: (call: Call<*>, t: Throwable) -> E /** Return error object `E` that contains/represents the given `AnyFetchError` */ - val errorFromNetworkFailure: (AnyFetchError) -> E + val errorFromNetworkFailure: (FetchError) -> E } @@ -68,7 +69,7 @@ inline fun NetworkFetching.fetch( noinline failure: (FetchError) -> Unit ) { val resultProcessing = RetrofitResultProcessing( - errorFromNetworkFailure = { FetchError.Network(it) }, + errorFromNetworkFailure = { FetchError.make(it) }, hasNetwork = checkNetwork ) fetch(usingExecutor, endpoint, resultProcessing, success, failure) @@ -130,13 +131,13 @@ private fun fetch( /** Returns result processing object for given response type `R` and error type `E` */ open class RetrofitResultProcessing( override val tryCastResponseBody: (Any?) -> R?, - override val errorFromNetworkFailure: (AnyFetchError) -> E, + override val errorFromNetworkFailure: (FetchError) -> E, hasNetwork: (() -> Boolean)? = null, ) : NetworkFetching.ResultProcessing { companion object { inline operator fun invoke( - noinline errorFromNetworkFailure: (AnyFetchError) -> E, + noinline errorFromNetworkFailure: (FetchError) -> E, noinline hasNetwork: (() -> Boolean)? = null ) : RetrofitResultProcessing { return RetrofitResultProcessing( @@ -150,15 +151,16 @@ open class RetrofitResultProcessing( } override var errorFromFailureResponse: (call: Call<*>, t: Throwable) -> E = { call, t -> - val error: AnyFetchError = when(t) { + val error: FetchError = when(t) { is UnknownHostException -> errorForUnknownHostException is IllegalStateException -> errorForIllegalStateException + is InterruptedIOException -> errorForInterruptedIOException //TODO: Check other cases - else -> AnyFetchError.Unknown() + else -> FetchError.Unknown() } errorFromNetworkFailure( - AnyFetchError.make(error = error, addingDump = "(Throwable): $t\n(Call): $call") + FetchError.make(error = error, addingDump = "(Throwable): $t\n(Call): $call") ) } @@ -169,30 +171,32 @@ open class RetrofitResultProcessing( RetrofitResult.Success(body) } ?: RetrofitResult.Failure( errorFromNetworkFailure( - AnyFetchError.make( - error = AnyFetchError.NotFound.MissingData, + FetchError.make( + error = FetchError.NotFound.MissingData, addingDump = "(Response): $response\n(Call): $call" ) ) ) } else { RetrofitResult.Failure( - errorFromNetworkFailure(AnyFetchError.BadStatusCode(response.code(), response)) + errorFromNetworkFailure(FetchError.BadStatusCode(response.code(), response)) ) } } //region Exception to AnyFetchError mapping - var errorForUnknownHostException: AnyFetchError = if (hasNetwork != null) { - if (hasNetwork()) AnyFetchError.BadRequest.Encode - else AnyFetchError.NotFound.MissingNetwork + var errorForUnknownHostException: FetchError = if (hasNetwork != null) { + if (hasNetwork()) FetchError.BadRequest.Encode + else FetchError.NotFound.MissingNetwork } else { // Cannot distinguish the error case from `MissingNetwork` and `Encode` error. - AnyFetchError.Unknown() + FetchError.Unknown() } - var errorForIllegalStateException: AnyFetchError = AnyFetchError.BadRequest.Decode + var errorForIllegalStateException: FetchError = FetchError.BadRequest.Decode + + var errorForInterruptedIOException: FetchError = FetchError.InterruptedIO.Timeout //endregion -- GitLab From 029ac0ba7423be1320928961cb309a5a7b7adac0 Mon Sep 17 00:00:00 2001 From: Nishant Dande Date: Tue, 18 Jul 2023 22:49:45 +0530 Subject: [PATCH 12/19] Refine networking module for different endpoint --- .../java/app/lounge/NetworkFetchingAPITest.kt | 76 +++++----- .../lounge/networking/AnonymousUserAPITest.kt | 135 ------------------ .../main/java/app/lounge/di/NetworkModule.kt | 49 ++++++- .../networking/NetworkFetchingRetrofitImpl.kt | 14 +- 4 files changed, 85 insertions(+), 189 deletions(-) delete mode 100644 modules/src/androidTest/java/app/lounge/networking/AnonymousUserAPITest.kt diff --git a/modules/src/androidTest/java/app/lounge/NetworkFetchingAPITest.kt b/modules/src/androidTest/java/app/lounge/NetworkFetchingAPITest.kt index d2b92e219..46ef8cc8f 100644 --- a/modules/src/androidTest/java/app/lounge/NetworkFetchingAPITest.kt +++ b/modules/src/androidTest/java/app/lounge/NetworkFetchingAPITest.kt @@ -18,47 +18,6 @@ import java.util.concurrent.TimeUnit class NetworkFetchingAPITest { - private val networkFetchingToken: NetworkFetching = NetworkFetchingRetrofitImpl( - Retrofit.Builder() - .baseUrl(NetworkFetchingRetrofitAPI.tokenBaseURL) - .addConverterFactory(GsonConverterFactory.create()) - .client( - OkHttpClient.Builder() - .callTimeout(10, TimeUnit.SECONDS) - .build() - ) - .build() - ) - - private val networkFetchingGoogle: NetworkFetching = NetworkFetchingRetrofitImpl( - Retrofit.Builder() - .baseUrl(NetworkFetchingRetrofitAPI.googlePlayBaseURL) - .addConverterFactory(GsonConverterFactory.create()) - .client( - OkHttpClient.Builder() - .callTimeout(10, TimeUnit.SECONDS) - .build() - ) - .build() - ) - - private val networkFetchingTimeoutGoogle: NetworkFetching = NetworkFetchingRetrofitImpl( - Retrofit.Builder() - .baseUrl(NetworkFetchingRetrofitAPI.googlePlayBaseURL) - .addConverterFactory(GsonConverterFactory.create()) - .client( - OkHttpClient.Builder() - .callTimeout(10, TimeUnit.MILLISECONDS) - .build() - ) - .build() - ) - - private val requestBodyData = AnonymousAuthDataRequestBody( - properties = testSystemProperties, - userAgent = testUserAgent - ) - companion object { var authData: AuthDataResponse? = null } @@ -77,7 +36,7 @@ class NetworkFetchingAPITest { authData?.let { authData -> authData.dfeCookie = "null" - result = networkFetchingGoogle.requestAuthDataValidation( + result = networkFetchingToken.requestAuthDataValidation( anonymousAuthDataValidationRequestBody = AnonymousAuthDataValidationRequestBody( authDataResponse = authData ) @@ -105,6 +64,39 @@ class NetworkFetchingAPITest { assert(authData is AuthDataResponse) { "Assert!! AuthData must be present" } assert(failure is InterruptedIOException) { "Assert!! Timeout Failure callback must call" } } + + private fun retrofitTestConfig( + baseUrl: String, + timeoutInMillisecond: Long = 10000L + ): Retrofit = Retrofit.Builder() + .baseUrl(baseUrl) + .addConverterFactory(GsonConverterFactory.create()) + .client( + OkHttpClient.Builder() + .callTimeout(timeoutInMillisecond, TimeUnit.MILLISECONDS) + .build() + ) + .build() + + private val eCloudTest = retrofitTestConfig(NetworkFetchingRetrofitAPI.tokenBaseURL) + private val googleTest = retrofitTestConfig(NetworkFetchingRetrofitAPI.googlePlayBaseURL) + private val googleTestTimeout = retrofitTestConfig( + NetworkFetchingRetrofitAPI.googlePlayBaseURL, 50L) + + private val networkFetchingToken: NetworkFetching = NetworkFetchingRetrofitImpl( + eCloud = eCloudTest, + google = googleTest + ) + + private val networkFetchingTimeoutGoogle: NetworkFetching = NetworkFetchingRetrofitImpl( + eCloud = eCloudTest, + google = googleTestTimeout + ) + + private val requestBodyData = AnonymousAuthDataRequestBody( + properties = testSystemProperties, + userAgent = testUserAgent + ) } private const val testUserAgent: String = "{\"package\":\"foundation.e.apps.debug\",\"version\":\"2.5.5.debug\",\"device\":\"coral\",\"api\":32,\"os_version\":\"1.11-s-20230511288805-dev-coral\",\"build_id\":\"319e25cd.20230630224839\"}" diff --git a/modules/src/androidTest/java/app/lounge/networking/AnonymousUserAPITest.kt b/modules/src/androidTest/java/app/lounge/networking/AnonymousUserAPITest.kt deleted file mode 100644 index ab364f291..000000000 --- a/modules/src/androidTest/java/app/lounge/networking/AnonymousUserAPITest.kt +++ /dev/null @@ -1,135 +0,0 @@ -package app.lounge.networking - -import app.lounge.users.anonymous.Anonymous -import app.lounge.users.anonymous.AnonymousAPI -import app.lounge.users.anonymous.AnonymousAuthDataRequestBody -import app.lounge.users.anonymous.AnonymousAuthDataValidationRequestBody -import app.lounge.users.anonymous.AuthDataResponse -import app.lounge.users.anonymous.AuthDataValidationResponse -import org.junit.Test -import java.util.Properties - -class AnonymousUserAPITest { - - private val testAnonymousAPIForToken = Anonymous.anonymousRequestFor( - api = AnonymousAPI.create(baseURL = AnonymousAPI.tokenBaseURL) - ) - - private val testAnonymousAPIForLogin = Anonymous.anonymousRequestFor( - api = AnonymousAPI.create(baseURL = AnonymousAPI.loginBaseURL) - ) - - private val testAnonymousAPIForLoginTimeout = Anonymous.anonymousRequestFor( - api = AnonymousAPI.create( - baseURL = AnonymousAPI.loginBaseURL, - callTimeoutInSeconds = 1 - ) - ) - - private val requestBodyData = AnonymousAuthDataRequestBody( - properties = testSystemProperties, - userAgent = testUserAgent - ) - - companion object { - var authData: AuthDataResponse? = null - } - - @Test - fun test1OnSuccessReturnsAuthData() { - await { - testAnonymousAPIForToken.requestAuthData( - anonymousAuthDataRequestBody = requestBodyData, - success = { response -> authData = response }, - failure = { } - ) - } - assert(authData is AuthDataResponse) { "Assert!! Success must return data" } - } - - @Test - fun test2OnSuccessReturnsLoginData(){ - var response: AuthDataValidationResponse? = null - await { - authData?.let { authData -> - authData.dfeCookie = "null" - - testAnonymousAPIForLogin.requestAuthDataValidation( - anonymousAuthDataValidationRequestBody = AnonymousAuthDataValidationRequestBody( - authDataResponse = authData - ), - success = { result -> response = result }, - failure = {} - ) - } - } - assert(authData is AuthDataResponse) { "Assert!! AuthData must be present" } - assert(response is AuthDataValidationResponse) { "Assert!! `response` must have data" } - } - - @Test - fun test3OnTimeoutFailureReturnsError(){ - var failure: FetchError? = null - await { - authData?.let { authData -> - authData.dfeCookie = "null" - testAnonymousAPIForLoginTimeout.requestAuthDataValidation( - anonymousAuthDataValidationRequestBody = AnonymousAuthDataValidationRequestBody( - authDataResponse = authData - ), - success = {}, - failure = { error -> failure = error } - ) - } - } - assert(authData is AuthDataResponse) { "Assert!! AuthData must be present" } - failure?.description?.contains("timeout") - ?.let { assert(it) { "Assert!! Timeout Failure callback must call" } } - } -} - -private const val testUserAgent: String = "{\"package\":\"foundation.e.apps.debug\",\"version\":\"2.5.5.debug\",\"device\":\"coral\",\"api\":32,\"os_version\":\"1.11-s-20230511288805-dev-coral\",\"build_id\":\"319e25cd.20230630224839\"}" - -private val testSystemProperties = Properties().apply { - setProperty("UserReadableName", "coral-default") - setProperty("Build.HARDWARE", "coral") - setProperty("Build.RADIO", "g8150-00123-220402-B-8399852") - setProperty("Build.FINGERPRINT","google/coral/coral:12/SQ3A.220705.003.A1/8672226:user/release-keys") - setProperty("Build.BRAND", "google") - setProperty("Build.DEVICE", "coral") - setProperty("Build.VERSION.SDK_INT", "32") - setProperty("Build.VERSION.RELEASE", "12") - setProperty("Build.MODEL", "Pixel 4 XL") - setProperty("Build.MANUFACTURER", "Google") - setProperty("Build.PRODUCT", "coral") - setProperty("Build.ID", "SQ3A.220705.004") - setProperty("Build.BOOTLOADER", "c2f2-0.4-8351033") - setProperty("TouchScreen", "3") - setProperty("Keyboard", "1") - setProperty("Navigation", "1") - setProperty("ScreenLayout", "2") - setProperty("HasHardKeyboard", "false") - setProperty("HasFiveWayNavigation", "false") - setProperty("Screen.Density", "560") - setProperty("Screen.Width", "1440") - setProperty("Screen.Height", "2984") - setProperty("Platforms", "arm64-v8a,armeabi-v7a,armeabi") - setProperty("Features", "android.hardware.sensor.proximity,com.verizon.hardware.telephony.lte,com.verizon.hardware.telephony.ehrpd,android.hardware.sensor.accelerometer,android.software.controls,android.hardware.faketouch,com.google.android.feature.D2D_CABLE_MIGRATION_FEATURE,android.hardware.telephony.euicc,android.hardware.reboot_escrow,android.hardware.usb.accessory,android.hardware.telephony.cdma,android.software.backup,android.hardware.touchscreen,android.hardware.touchscreen.multitouch,android.software.print,org.lineageos.weather,android.software.activities_on_secondary_displays,android.hardware.wifi.rtt,com.google.android.feature.PIXEL_2017_EXPERIENCE,android.software.voice_recognizers,android.software.picture_in_picture,android.hardware.sensor.gyroscope,android.hardware.audio.low_latency,android.software.vulkan.deqp.level,android.software.cant_save_state,com.google.android.feature.PIXEL_2018_EXPERIENCE,android.hardware.security.model.compatible,com.google.android.feature.PIXEL_2019_EXPERIENCE,android.hardware.opengles.aep,org.lineageos.livedisplay,org.lineageos.profiles,android.hardware.bluetooth,android.hardware.camera.autofocus,android.hardware.telephony.gsm,android.hardware.telephony.ims,android.software.incremental_delivery,android.software.sip.voip,android.hardware.se.omapi.ese,android.software.opengles.deqp.level,android.hardware.usb.host,android.hardware.audio.output,android.software.verified_boot,android.hardware.camera.flash,android.hardware.camera.front,android.hardware.sensor.hifi_sensors,com.google.android.apps.photos.PIXEL_2019_PRELOAD,android.hardware.se.omapi.uicc,android.hardware.strongbox_keystore,android.hardware.screen.portrait,android.hardware.nfc,com.google.android.feature.TURBO_PRELOAD,com.nxp.mifare,android.hardware.sensor.stepdetector,android.software.home_screen,android.hardware.context_hub,android.hardware.microphone,android.software.autofill,org.lineageos.hardware,org.lineageos.globalactions,android.software.securely_removes_users,com.google.android.feature.PIXEL_EXPERIENCE,android.hardware.bluetooth_le,android.hardware.sensor.compass,com.google.android.feature.GOOGLE_FI_BUNDLED,android.hardware.touchscreen.multitouch.jazzhand,android.hardware.sensor.barometer,android.software.app_widgets,android.hardware.telephony.carrierlock,android.software.input_methods,android.hardware.sensor.light,android.hardware.vulkan.version,android.software.companion_device_setup,android.software.device_admin,com.google.android.feature.WELLBEING,android.hardware.wifi.passpoint,android.hardware.camera,org.lineageos.trust,android.hardware.device_unique_attestation,android.hardware.screen.landscape,android.software.device_id_attestation,com.google.android.feature.AER_OPTIMIZED,android.hardware.ram.normal,org.lineageos.android,com.google.android.feature.PIXEL_2019_MIDYEAR_EXPERIENCE,android.software.managed_users,android.software.webview,android.hardware.sensor.stepcounter,android.hardware.camera.capability.manual_post_processing,android.hardware.camera.any,android.hardware.camera.capability.raw,android.hardware.vulkan.compute,android.software.connectionservice,android.hardware.touchscreen.multitouch.distinct,android.hardware.location.network,android.software.cts,android.software.sip,android.hardware.camera.capability.manual_sensor,android.software.app_enumeration,android.hardware.camera.level.full,android.hardware.identity_credential,android.hardware.wifi.direct,android.software.live_wallpaper,android.software.ipsec_tunnels,org.lineageos.settings,android.hardware.sensor.assist,android.hardware.audio.pro,android.hardware.nfc.hcef,android.hardware.nfc.uicc,android.hardware.location.gps,android.sofware.nfc.beam,android.software.midi,android.hardware.nfc.any,android.hardware.nfc.ese,android.hardware.nfc.hce,android.hardware.wifi,android.hardware.location,android.hardware.vulkan.level,android.hardware.wifi.aware,android.software.secure_lock_screen,android.hardware.biometrics.face,android.hardware.telephony,android.software.file_based_encryption") - setProperty("Locales", "af,af_ZA,am,am_ET,ar,ar_EG,ar_XB,as,ast_ES,az,be,bg,bg_BG,bn,bs,ca,ca_ES,cs,cs_CZ,cy,da,da_DK,de,de_DE,el,el_GR,en,en_AU,en_CA,en_GB,en_IN,en_US,en_XA,en_XC,es,es_419,es_ES,es_US,et,eu,fa,fa_IR,fi,fi_FI,fil,fil_PH,fr,fr_CA,fr_FR,gd,gl,gu,hi,hi_IN,hr,hr_HR,hu,hu_HU,hy,in,in_ID,is,it,it_IT,iw,iw_IL,ja,ja_JP,ka,kk,km,kn,ko,ko_KR,ky,lo,lt,lt_LT,lv,lv_LV,mk,ml,mn,mr,ms,ms_MY,my,nb,nb_NO,ne,nl,nl_NL,or,pa,pl,pl_PL,pt,pt_BR,pt_PT,ro,ro_RO,ru,ru_RU,si,sk,sk_SK,sl,sl_SI,sq,sr,sr_Latn,sr_RS,sv,sv_SE,sw,sw_TZ,ta,te,th,th_TH,tr,tr_TR,uk,uk_UA,ur,uz,vi,vi_VN,zh_CN,zh_HK,zh_TW,zu,zu_ZA") - setProperty("SharedLibraries", "android.test.base,android.test.mock,com.vzw.apnlib,android.hidl.manager-V1.0-java,qti-telephony-hidl-wrapper,libfastcvopt.so,google-ril,qti-telephony-utils,com.android.omadm.radioconfig,libcdsprpc.so,android.hidl.base-V1.0-java,com.qualcomm.qmapbridge,libairbrush-pixel.so,com.google.android.camera.experimental2019,libOpenCL-pixel.so,libadsprpc.so,com.android.location.provider,android.net.ipsec.ike,com.android.future.usb.accessory,libsdsprpc.so,android.ext.shared,javax.obex,izat.xt.srv,com.google.android.gms,lib_aion_buffer.so,com.qualcomm.uimremoteclientlibrary,libqdMetaData.so,com.qualcomm.uimremoteserverlibrary,com.qualcomm.qcrilhook,android.test.runner,org.apache.http.legacy,com.google.android.camera.extensions,com.google.android.hardwareinfo,com.android.cts.ctsshim.shared_library,com.android.nfc_extras,com.android.media.remotedisplay,com.android.mediadrm.signer,com.qualcomm.qti.imscmservice-V2.0-java,qti-telephony-hidl-wrapper-prd,com.qualcomm.qti.imscmservice-V2.1-java,com.qualcomm.qti.imscmservice-V2.2-java") - setProperty("GL.Version", "196610") - setProperty("GL.Extensions", ",GL_AMD_compressed_ATC_texture,GL_AMD_performance_monitor,GL_ANDROID_extension_pack_es31a,GL_APPLE_texture_2D_limited_npot,GL_ARB_vertex_buffer_object,GL_ARM_shader_framebuffer_fetch_depth_stencil,GL_EXT_EGL_image_array,GL_EXT_EGL_image_external_wrap_modes,GL_EXT_EGL_image_storage,GL_EXT_YUV_target,GL_EXT_blend_func_extended,GL_EXT_blit_framebuffer_params,GL_EXT_buffer_storage,GL_EXT_clip_control,GL_EXT_clip_cull_distance,GL_EXT_color_buffer_float,GL_EXT_color_buffer_half_float,GL_EXT_copy_image,GL_EXT_debug_label,GL_EXT_debug_marker,GL_EXT_discard_framebuffer,GL_EXT_disjoint_timer_query,GL_EXT_draw_buffers_indexed,GL_EXT_external_buffer,GL_EXT_fragment_invocation_density,GL_EXT_geometry_shader,GL_EXT_gpu_shader5,GL_EXT_memory_object,GL_EXT_memory_object_fd,GL_EXT_multisampled_render_to_texture,GL_EXT_multisampled_render_to_texture2,GL_EXT_primitive_bounding_box,GL_EXT_protected_textures,GL_EXT_read_format_bgra,GL_EXT_robustness,GL_EXT_sRGB,GL_EXT_sRGB_write_control,GL_EXT_shader_framebuffer_fetch,GL_EXT_shader_io_blocks,GL_EXT_shader_non_constant_global_initializers,GL_EXT_tessellation_shader,GL_EXT_texture_border_clamp,GL_EXT_texture_buffer,GL_EXT_texture_cube_map_array,GL_EXT_texture_filter_anisotropic,GL_EXT_texture_format_BGRA8888,GL_EXT_texture_format_sRGB_override,GL_EXT_texture_norm16,GL_EXT_texture_sRGB_R8,GL_EXT_texture_sRGB_decode,GL_EXT_texture_type_2_10_10_10_REV,GL_KHR_blend_equation_advanced,GL_KHR_blend_equation_advanced_coherent,GL_KHR_debug,GL_KHR_no_error,GL_KHR_robust_buffer_access_behavior,GL_KHR_texture_compression_astc_hdr,GL_KHR_texture_compression_astc_ldr,GL_NV_shader_noperspective_interpolation,GL_OES_EGL_image,GL_OES_EGL_image_external,GL_OES_EGL_image_external_essl3,GL_OES_EGL_sync,GL_OES_blend_equation_separate,GL_OES_blend_func_separate,GL_OES_blend_subtract,GL_OES_compressed_ETC1_RGB8_texture,GL_OES_compressed_paletted_texture,GL_OES_depth24,GL_OES_depth_texture,GL_OES_depth_texture_cube_map,GL_OES_draw_texture,GL_OES_element_index_uint,GL_OES_framebuffer_object,GL_OES_get_program_binary,GL_OES_matrix_palette,GL_OES_packed_depth_stencil,GL_OES_point_size_array,GL_OES_point_sprite,GL_OES_read_format,GL_OES_rgb8_rgba8,GL_OES_sample_shading,GL_OES_sample_variables,GL_OES_shader_image_atomic,GL_OES_shader_multisample_interpolation,GL_OES_standard_derivatives,GL_OES_stencil_wrap,GL_OES_surfaceless_context,GL_OES_texture_3D,GL_OES_texture_compression_astc,GL_OES_texture_cube_map,GL_OES_texture_env_crossbar,GL_OES_texture_float,GL_OES_texture_float_linear,GL_OES_texture_half_float,GL_OES_texture_half_float_linear,GL_OES_texture_mirrored_repeat,GL_OES_texture_npot,GL_OES_texture_stencil8,GL_OES_texture_storage_multisample_2d_array,GL_OES_texture_view,GL_OES_vertex_array_object,GL_OES_vertex_half_float,GL_OVR_multiview,GL_OVR_multiview2,GL_OVR_multiview_multisampled_render_to_texture,GL_QCOM_YUV_texture_gather,GL_QCOM_alpha_test,GL_QCOM_extended_get,GL_QCOM_motion_estimation,GL_QCOM_shader_framebuffer_fetch_noncoherent,GL_QCOM_shader_framebuffer_fetch_rate,GL_QCOM_texture_foveated,GL_QCOM_texture_foveated_subsampled_layout,GL_QCOM_tiled_rendering,GL_QCOM_validate_shader_binary") - setProperty("Client", "android-google") - setProperty("GSF.version", "223616055") - setProperty("Vending.version", "82151710") - setProperty("Vending.versionString", "21.5.17-21 [0] [PR] 326734551") - setProperty("Roaming", "mobile-notroaming") - setProperty("TimeZone", "UTC-10") - setProperty("CellOperator", "310") - setProperty("SimOperator", "38") -} - -fun await(callback: () -> Unit) { - callback.invoke() - Thread.sleep(3000) -} diff --git a/modules/src/main/java/app/lounge/di/NetworkModule.kt b/modules/src/main/java/app/lounge/di/NetworkModule.kt index 1763676d2..d2ea451e8 100644 --- a/modules/src/main/java/app/lounge/di/NetworkModule.kt +++ b/modules/src/main/java/app/lounge/di/NetworkModule.kt @@ -1,7 +1,8 @@ package app.lounge.di +import app.lounge.networking.NetworkFetching import app.lounge.networking.NetworkFetchingRetrofitAPI -import dagger.Binds +import app.lounge.networking.NetworkFetchingRetrofitImpl import dagger.Module import dagger.Provides import dagger.hilt.InstallIn @@ -18,13 +19,11 @@ import javax.inject.Singleton @InstallIn(SingletonComponent::class) internal object NetworkModule { - private const val HTTP_TIMEOUT = 10L + private const val HTTP_TIMEOUT_IN_SECOND = 10L - @Provides - @Singleton - internal fun providesRetrofit( + private fun retrofit( okHttpClient: OkHttpClient, - baseUrl: String = NetworkFetchingRetrofitAPI.tokenBaseURL + baseUrl: String ) : Retrofit { return Retrofit.Builder() .baseUrl(baseUrl) @@ -33,6 +32,30 @@ internal object NetworkModule { .build() } + @Provides + @Singleton + @Named("ECloudRetrofit") + internal fun provideECloudRetrofit( + okHttpClient: OkHttpClient + ): Retrofit { + return retrofit( + okHttpClient = okHttpClient, + baseUrl = NetworkFetchingRetrofitAPI.tokenBaseURL + ) + } + + @Provides + @Singleton + @Named("GoogleRetrofit") + internal fun provideGoogleRetrofit( + okHttpClient: OkHttpClient + ): Retrofit { + return retrofit( + okHttpClient = okHttpClient, + baseUrl = NetworkFetchingRetrofitAPI.googlePlayBaseURL + ) + } + @Provides @Singleton @Named("privateOkHttpClient") @@ -41,7 +64,7 @@ internal object NetworkModule { ): OkHttpClient { return OkHttpClient.Builder() .addNetworkInterceptor(httpLogger) - .callTimeout(HTTP_TIMEOUT, TimeUnit.SECONDS) + .callTimeout(HTTP_TIMEOUT_IN_SECOND, TimeUnit.SECONDS) .build() } @@ -56,4 +79,16 @@ internal object NetworkModule { } } + @Provides + @Singleton + fun provideNetworkFetching( + @Named("ECloudRetrofit") ecloud: Retrofit, + @Named("GoogleRetrofit") google: Retrofit, + ) : NetworkFetching { + return NetworkFetchingRetrofitImpl( + eCloud = ecloud, + google = google + ) + } + } \ No newline at end of file diff --git a/modules/src/main/java/app/lounge/networking/NetworkFetchingRetrofitImpl.kt b/modules/src/main/java/app/lounge/networking/NetworkFetchingRetrofitImpl.kt index 04d3ddd7c..6621e4010 100644 --- a/modules/src/main/java/app/lounge/networking/NetworkFetchingRetrofitImpl.kt +++ b/modules/src/main/java/app/lounge/networking/NetworkFetchingRetrofitImpl.kt @@ -51,10 +51,15 @@ interface NetworkFetchingRetrofitAPI { @Singleton class NetworkFetchingRetrofitImpl @Inject constructor( - retrofit: Retrofit + val eCloud: Retrofit, + val google: Retrofit, ) : NetworkFetching { - private val networkFetchingRetrofitAPI = retrofit.create( + private val eCloudNetworkFetchingRetrofitAPI = eCloud.create( + NetworkFetchingRetrofitAPI::class.java + ) + + private val googleNetworkFetchingRetrofitAPI = google.create( NetworkFetchingRetrofitAPI::class.java ) @@ -69,7 +74,7 @@ class NetworkFetchingRetrofitImpl @Inject constructor( byteCount = result.size ) } - return networkFetchingRetrofitAPI.authDataRequest( + return eCloudNetworkFetchingRetrofitAPI.authDataRequest( requestBody = requestBody, headers = NetworkFetchingRetrofitAPI.Header.authData { anonymousAuthDataRequestBody.userAgent @@ -80,9 +85,8 @@ class NetworkFetchingRetrofitImpl @Inject constructor( override suspend fun requestAuthDataValidation( anonymousAuthDataValidationRequestBody: AnonymousAuthDataValidationRequestBody ): AuthDataValidationResponse { - return networkFetchingRetrofitAPI.validateAuthentication( + return googleNetworkFetchingRetrofitAPI.validateAuthentication( headers = anonymousAuthDataValidationRequestBody.header ) } - } \ No newline at end of file -- GitLab From bd29d531b49f49cceeac27673b86a2fce07587fd Mon Sep 17 00:00:00 2001 From: Nishant Dande Date: Thu, 27 Jul 2023 14:54:44 +0530 Subject: [PATCH 13/19] Implement Anonymous user network api --- .../java/app/lounge/AnonymousUserAPITest.kt | 158 ++++++++++++++++++ .../main/java/app/lounge/di/NetworkModule.kt | 47 +++++- .../java/app/lounge/extension/Extension.kt | 29 ++++ .../src/main/java/app/lounge/model/Model.kt | 37 ++++ .../AnonymousAnonymousUserRetrofitImpl.kt | 118 +++++++++++++ .../app/lounge/networking/AnonymousUser.kt | 36 ++++ 6 files changed, 420 insertions(+), 5 deletions(-) create mode 100644 modules/src/androidTest/java/app/lounge/AnonymousUserAPITest.kt create mode 100644 modules/src/main/java/app/lounge/extension/Extension.kt create mode 100644 modules/src/main/java/app/lounge/model/Model.kt create mode 100644 modules/src/main/java/app/lounge/networking/AnonymousAnonymousUserRetrofitImpl.kt create mode 100644 modules/src/main/java/app/lounge/networking/AnonymousUser.kt diff --git a/modules/src/androidTest/java/app/lounge/AnonymousUserAPITest.kt b/modules/src/androidTest/java/app/lounge/AnonymousUserAPITest.kt new file mode 100644 index 000000000..2651e08db --- /dev/null +++ b/modules/src/androidTest/java/app/lounge/AnonymousUserAPITest.kt @@ -0,0 +1,158 @@ +package app.lounge + +import app.lounge.model.AnonymousAuthDataRequestBody +import app.lounge.model.AnonymousAuthDataValidationRequestBody +import app.lounge.model.AuthDataResponse +import app.lounge.model.AuthDataValidationResponse +import app.lounge.networking.NetworkResult +import app.lounge.networking.UserAuthentication +import app.lounge.networking.UserAuthenticationRetrofitAPI +import app.lounge.networking.UserAuthenticationRetrofitImpl +import kotlinx.coroutines.runBlocking +import okhttp3.OkHttpClient +import org.junit.Test +import retrofit2.Retrofit +import retrofit2.converter.gson.GsonConverterFactory +import java.io.InterruptedIOException +import java.util.Properties +import java.util.concurrent.TimeUnit + +class UserAuthenticationAPITest { + + companion object { + var authData: AuthDataResponse? = null + } + + @Test + fun test1OnSuccessReturnsAuthData() = runBlocking { + val response = userAuthentication.requestAuthData( + anonymousAuthDataRequestBody = requestBodyData, + ) + when(response){ + is NetworkResult.Success -> authData = response.data + else -> {} + } + + assert(authData is AuthDataResponse) { "Assert!! Success must return data" } + } + + @Test + fun test2OnSuccessReturnsLoginData() = runBlocking { + var result: AuthDataValidationResponse? = null + authData?.let { authData -> + authData.dfeCookie = "null" + + val response = userAuthentication.requestAuthDataValidation( + anonymousAuthDataValidationRequestBody = AnonymousAuthDataValidationRequestBody( + authDataResponse = authData + ) + ) + when(response){ + is NetworkResult.Success -> result = response.data + else -> {} + } + } + + assert(authData is AuthDataResponse) { "Assert!! AuthData must be present" } + assert(result is AuthDataValidationResponse) { "Assert!! `response` must have data" } + } + + @Test + fun test3OnTimeoutFailureReturnsError(): Unit = runBlocking { + var failure: Throwable = Exception("No Error") + authData?.let { authData -> + authData.dfeCookie = "null" + + try { + val response = userAuthenticationGoogleTimeout.requestAuthDataValidation( + anonymousAuthDataValidationRequestBody = AnonymousAuthDataValidationRequestBody( + authDataResponse = authData + ) + ) + + when(response){ + is NetworkResult.Error -> failure = response.exception + else -> {} + } + } catch (e: InterruptedIOException) { failure = e } + } + assert(authData is AuthDataResponse) { "Assert!! AuthData must be present" } + assert(failure is InterruptedIOException) { "Assert!! Timeout Failure callback must call" } + } + + + private fun retrofitTestConfig( + baseUrl: String, + timeoutInMillisecond: Long = 10000L + ): Retrofit = Retrofit.Builder() + .baseUrl(baseUrl) + .addConverterFactory(GsonConverterFactory.create()) + .client( + OkHttpClient.Builder() + .callTimeout(timeoutInMillisecond, TimeUnit.MILLISECONDS) + .build() + ) + .build() + + private val eCloudTest = retrofitTestConfig(UserAuthenticationRetrofitAPI.tokenBaseURL) + private val googleTest = retrofitTestConfig(UserAuthenticationRetrofitAPI.googlePlayBaseURL) + private val googleTestTimeout = retrofitTestConfig( + UserAuthenticationRetrofitAPI.googlePlayBaseURL, 50L) + + private val userAuthentication: UserAuthentication = UserAuthenticationRetrofitImpl( + eCloud = eCloudTest, + google = googleTest + ) + + private val userAuthenticationGoogleTimeout: UserAuthentication = UserAuthenticationRetrofitImpl( + eCloud = eCloudTest, + google = googleTestTimeout + ) + + private val requestBodyData = AnonymousAuthDataRequestBody( + properties = testSystemProperties, + userAgent = testUserAgent + ) +} + +private const val testUserAgent: String = "{\"package\":\"foundation.e.apps.debug\",\"version\":\"2.5.5.debug\",\"device\":\"coral\",\"api\":32,\"os_version\":\"1.11-s-20230511288805-dev-coral\",\"build_id\":\"319e25cd.20230630224839\"}" + +private val testSystemProperties = Properties().apply { + setProperty("UserReadableName", "coral-default") + setProperty("Build.HARDWARE", "coral") + setProperty("Build.RADIO", "g8150-00123-220402-B-8399852") + setProperty("Build.FINGERPRINT","google/coral/coral:12/SQ3A.220705.003.A1/8672226:user/release-keys") + setProperty("Build.BRAND", "google") + setProperty("Build.DEVICE", "coral") + setProperty("Build.VERSION.SDK_INT", "32") + setProperty("Build.VERSION.RELEASE", "12") + setProperty("Build.MODEL", "Pixel 4 XL") + setProperty("Build.MANUFACTURER", "Google") + setProperty("Build.PRODUCT", "coral") + setProperty("Build.ID", "SQ3A.220705.004") + setProperty("Build.BOOTLOADER", "c2f2-0.4-8351033") + setProperty("TouchScreen", "3") + setProperty("Keyboard", "1") + setProperty("Navigation", "1") + setProperty("ScreenLayout", "2") + setProperty("HasHardKeyboard", "false") + setProperty("HasFiveWayNavigation", "false") + setProperty("Screen.Density", "560") + setProperty("Screen.Width", "1440") + setProperty("Screen.Height", "2984") + setProperty("Platforms", "arm64-v8a,armeabi-v7a,armeabi") + setProperty("Features", "android.hardware.sensor.proximity,com.verizon.hardware.telephony.lte,com.verizon.hardware.telephony.ehrpd,android.hardware.sensor.accelerometer,android.software.controls,android.hardware.faketouch,com.google.android.feature.D2D_CABLE_MIGRATION_FEATURE,android.hardware.telephony.euicc,android.hardware.reboot_escrow,android.hardware.usb.accessory,android.hardware.telephony.cdma,android.software.backup,android.hardware.touchscreen,android.hardware.touchscreen.multitouch,android.software.print,org.lineageos.weather,android.software.activities_on_secondary_displays,android.hardware.wifi.rtt,com.google.android.feature.PIXEL_2017_EXPERIENCE,android.software.voice_recognizers,android.software.picture_in_picture,android.hardware.sensor.gyroscope,android.hardware.audio.low_latency,android.software.vulkan.deqp.level,android.software.cant_save_state,com.google.android.feature.PIXEL_2018_EXPERIENCE,android.hardware.security.model.compatible,com.google.android.feature.PIXEL_2019_EXPERIENCE,android.hardware.opengles.aep,org.lineageos.livedisplay,org.lineageos.profiles,android.hardware.bluetooth,android.hardware.camera.autofocus,android.hardware.telephony.gsm,android.hardware.telephony.ims,android.software.incremental_delivery,android.software.sip.voip,android.hardware.se.omapi.ese,android.software.opengles.deqp.level,android.hardware.usb.host,android.hardware.audio.output,android.software.verified_boot,android.hardware.camera.flash,android.hardware.camera.front,android.hardware.sensor.hifi_sensors,com.google.android.apps.photos.PIXEL_2019_PRELOAD,android.hardware.se.omapi.uicc,android.hardware.strongbox_keystore,android.hardware.screen.portrait,android.hardware.nfc,com.google.android.feature.TURBO_PRELOAD,com.nxp.mifare,android.hardware.sensor.stepdetector,android.software.home_screen,android.hardware.context_hub,android.hardware.microphone,android.software.autofill,org.lineageos.hardware,org.lineageos.globalactions,android.software.securely_removes_users,com.google.android.feature.PIXEL_EXPERIENCE,android.hardware.bluetooth_le,android.hardware.sensor.compass,com.google.android.feature.GOOGLE_FI_BUNDLED,android.hardware.touchscreen.multitouch.jazzhand,android.hardware.sensor.barometer,android.software.app_widgets,android.hardware.telephony.carrierlock,android.software.input_methods,android.hardware.sensor.light,android.hardware.vulkan.version,android.software.companion_device_setup,android.software.device_admin,com.google.android.feature.WELLBEING,android.hardware.wifi.passpoint,android.hardware.camera,org.lineageos.trust,android.hardware.device_unique_attestation,android.hardware.screen.landscape,android.software.device_id_attestation,com.google.android.feature.AER_OPTIMIZED,android.hardware.ram.normal,org.lineageos.android,com.google.android.feature.PIXEL_2019_MIDYEAR_EXPERIENCE,android.software.managed_users,android.software.webview,android.hardware.sensor.stepcounter,android.hardware.camera.capability.manual_post_processing,android.hardware.camera.any,android.hardware.camera.capability.raw,android.hardware.vulkan.compute,android.software.connectionservice,android.hardware.touchscreen.multitouch.distinct,android.hardware.location.network,android.software.cts,android.software.sip,android.hardware.camera.capability.manual_sensor,android.software.app_enumeration,android.hardware.camera.level.full,android.hardware.identity_credential,android.hardware.wifi.direct,android.software.live_wallpaper,android.software.ipsec_tunnels,org.lineageos.settings,android.hardware.sensor.assist,android.hardware.audio.pro,android.hardware.nfc.hcef,android.hardware.nfc.uicc,android.hardware.location.gps,android.sofware.nfc.beam,android.software.midi,android.hardware.nfc.any,android.hardware.nfc.ese,android.hardware.nfc.hce,android.hardware.wifi,android.hardware.location,android.hardware.vulkan.level,android.hardware.wifi.aware,android.software.secure_lock_screen,android.hardware.biometrics.face,android.hardware.telephony,android.software.file_based_encryption") + setProperty("Locales", "af,af_ZA,am,am_ET,ar,ar_EG,ar_XB,as,ast_ES,az,be,bg,bg_BG,bn,bs,ca,ca_ES,cs,cs_CZ,cy,da,da_DK,de,de_DE,el,el_GR,en,en_AU,en_CA,en_GB,en_IN,en_US,en_XA,en_XC,es,es_419,es_ES,es_US,et,eu,fa,fa_IR,fi,fi_FI,fil,fil_PH,fr,fr_CA,fr_FR,gd,gl,gu,hi,hi_IN,hr,hr_HR,hu,hu_HU,hy,in,in_ID,is,it,it_IT,iw,iw_IL,ja,ja_JP,ka,kk,km,kn,ko,ko_KR,ky,lo,lt,lt_LT,lv,lv_LV,mk,ml,mn,mr,ms,ms_MY,my,nb,nb_NO,ne,nl,nl_NL,or,pa,pl,pl_PL,pt,pt_BR,pt_PT,ro,ro_RO,ru,ru_RU,si,sk,sk_SK,sl,sl_SI,sq,sr,sr_Latn,sr_RS,sv,sv_SE,sw,sw_TZ,ta,te,th,th_TH,tr,tr_TR,uk,uk_UA,ur,uz,vi,vi_VN,zh_CN,zh_HK,zh_TW,zu,zu_ZA") + setProperty("SharedLibraries", "android.test.base,android.test.mock,com.vzw.apnlib,android.hidl.manager-V1.0-java,qti-telephony-hidl-wrapper,libfastcvopt.so,google-ril,qti-telephony-utils,com.android.omadm.radioconfig,libcdsprpc.so,android.hidl.base-V1.0-java,com.qualcomm.qmapbridge,libairbrush-pixel.so,com.google.android.camera.experimental2019,libOpenCL-pixel.so,libadsprpc.so,com.android.location.provider,android.net.ipsec.ike,com.android.future.usb.accessory,libsdsprpc.so,android.ext.shared,javax.obex,izat.xt.srv,com.google.android.gms,lib_aion_buffer.so,com.qualcomm.uimremoteclientlibrary,libqdMetaData.so,com.qualcomm.uimremoteserverlibrary,com.qualcomm.qcrilhook,android.test.runner,org.apache.http.legacy,com.google.android.camera.extensions,com.google.android.hardwareinfo,com.android.cts.ctsshim.shared_library,com.android.nfc_extras,com.android.media.remotedisplay,com.android.mediadrm.signer,com.qualcomm.qti.imscmservice-V2.0-java,qti-telephony-hidl-wrapper-prd,com.qualcomm.qti.imscmservice-V2.1-java,com.qualcomm.qti.imscmservice-V2.2-java") + setProperty("GL.Version", "196610") + setProperty("GL.Extensions", ",GL_AMD_compressed_ATC_texture,GL_AMD_performance_monitor,GL_ANDROID_extension_pack_es31a,GL_APPLE_texture_2D_limited_npot,GL_ARB_vertex_buffer_object,GL_ARM_shader_framebuffer_fetch_depth_stencil,GL_EXT_EGL_image_array,GL_EXT_EGL_image_external_wrap_modes,GL_EXT_EGL_image_storage,GL_EXT_YUV_target,GL_EXT_blend_func_extended,GL_EXT_blit_framebuffer_params,GL_EXT_buffer_storage,GL_EXT_clip_control,GL_EXT_clip_cull_distance,GL_EXT_color_buffer_float,GL_EXT_color_buffer_half_float,GL_EXT_copy_image,GL_EXT_debug_label,GL_EXT_debug_marker,GL_EXT_discard_framebuffer,GL_EXT_disjoint_timer_query,GL_EXT_draw_buffers_indexed,GL_EXT_external_buffer,GL_EXT_fragment_invocation_density,GL_EXT_geometry_shader,GL_EXT_gpu_shader5,GL_EXT_memory_object,GL_EXT_memory_object_fd,GL_EXT_multisampled_render_to_texture,GL_EXT_multisampled_render_to_texture2,GL_EXT_primitive_bounding_box,GL_EXT_protected_textures,GL_EXT_read_format_bgra,GL_EXT_robustness,GL_EXT_sRGB,GL_EXT_sRGB_write_control,GL_EXT_shader_framebuffer_fetch,GL_EXT_shader_io_blocks,GL_EXT_shader_non_constant_global_initializers,GL_EXT_tessellation_shader,GL_EXT_texture_border_clamp,GL_EXT_texture_buffer,GL_EXT_texture_cube_map_array,GL_EXT_texture_filter_anisotropic,GL_EXT_texture_format_BGRA8888,GL_EXT_texture_format_sRGB_override,GL_EXT_texture_norm16,GL_EXT_texture_sRGB_R8,GL_EXT_texture_sRGB_decode,GL_EXT_texture_type_2_10_10_10_REV,GL_KHR_blend_equation_advanced,GL_KHR_blend_equation_advanced_coherent,GL_KHR_debug,GL_KHR_no_error,GL_KHR_robust_buffer_access_behavior,GL_KHR_texture_compression_astc_hdr,GL_KHR_texture_compression_astc_ldr,GL_NV_shader_noperspective_interpolation,GL_OES_EGL_image,GL_OES_EGL_image_external,GL_OES_EGL_image_external_essl3,GL_OES_EGL_sync,GL_OES_blend_equation_separate,GL_OES_blend_func_separate,GL_OES_blend_subtract,GL_OES_compressed_ETC1_RGB8_texture,GL_OES_compressed_paletted_texture,GL_OES_depth24,GL_OES_depth_texture,GL_OES_depth_texture_cube_map,GL_OES_draw_texture,GL_OES_element_index_uint,GL_OES_framebuffer_object,GL_OES_get_program_binary,GL_OES_matrix_palette,GL_OES_packed_depth_stencil,GL_OES_point_size_array,GL_OES_point_sprite,GL_OES_read_format,GL_OES_rgb8_rgba8,GL_OES_sample_shading,GL_OES_sample_variables,GL_OES_shader_image_atomic,GL_OES_shader_multisample_interpolation,GL_OES_standard_derivatives,GL_OES_stencil_wrap,GL_OES_surfaceless_context,GL_OES_texture_3D,GL_OES_texture_compression_astc,GL_OES_texture_cube_map,GL_OES_texture_env_crossbar,GL_OES_texture_float,GL_OES_texture_float_linear,GL_OES_texture_half_float,GL_OES_texture_half_float_linear,GL_OES_texture_mirrored_repeat,GL_OES_texture_npot,GL_OES_texture_stencil8,GL_OES_texture_storage_multisample_2d_array,GL_OES_texture_view,GL_OES_vertex_array_object,GL_OES_vertex_half_float,GL_OVR_multiview,GL_OVR_multiview2,GL_OVR_multiview_multisampled_render_to_texture,GL_QCOM_YUV_texture_gather,GL_QCOM_alpha_test,GL_QCOM_extended_get,GL_QCOM_motion_estimation,GL_QCOM_shader_framebuffer_fetch_noncoherent,GL_QCOM_shader_framebuffer_fetch_rate,GL_QCOM_texture_foveated,GL_QCOM_texture_foveated_subsampled_layout,GL_QCOM_tiled_rendering,GL_QCOM_validate_shader_binary") + setProperty("Client", "android-google") + setProperty("GSF.version", "223616055") + setProperty("Vending.version", "82151710") + setProperty("Vending.versionString", "21.5.17-21 [0] [PR] 326734551") + setProperty("Roaming", "mobile-notroaming") + setProperty("TimeZone", "UTC-10") + setProperty("CellOperator", "310") + setProperty("SimOperator", "38") +} + diff --git a/modules/src/main/java/app/lounge/di/NetworkModule.kt b/modules/src/main/java/app/lounge/di/NetworkModule.kt index 5251de66f..fb2c40163 100644 --- a/modules/src/main/java/app/lounge/di/NetworkModule.kt +++ b/modules/src/main/java/app/lounge/di/NetworkModule.kt @@ -1,5 +1,8 @@ package app.lounge.di +import app.lounge.networking.AnonymousUser +import app.lounge.networking.AnonymousUserRetrofitAPI +import app.lounge.networking.AnonymousAnonymousUserRetrofitImpl import dagger.Module import dagger.Provides import dagger.hilt.InstallIn @@ -16,11 +19,9 @@ import javax.inject.Singleton @InstallIn(SingletonComponent::class) internal object NetworkModule { - private const val HTTP_TIMEOUT = 10L + private const val HTTP_TIMEOUT_IN_SECOND = 10L - @Provides - @Singleton - internal fun providesRetrofit( + private fun retrofit( okHttpClient: OkHttpClient, baseUrl: String ) : Retrofit { @@ -31,6 +32,30 @@ internal object NetworkModule { .build() } + @Provides + @Singleton + @Named("ECloudRetrofit") + internal fun provideECloudRetrofit( + okHttpClient: OkHttpClient + ): Retrofit { + return retrofit( + okHttpClient = okHttpClient, + baseUrl = AnonymousUserRetrofitAPI.tokenBaseURL + ) + } + + @Provides + @Singleton + @Named("GoogleRetrofit") + internal fun provideGoogleRetrofit( + okHttpClient: OkHttpClient + ): Retrofit { + return retrofit( + okHttpClient = okHttpClient, + baseUrl = AnonymousUserRetrofitAPI.googlePlayBaseURL + ) + } + @Provides @Singleton @Named("privateOkHttpClient") @@ -39,7 +64,7 @@ internal object NetworkModule { ): OkHttpClient { return OkHttpClient.Builder() .addNetworkInterceptor(httpLogger) - .callTimeout(HTTP_TIMEOUT, TimeUnit.SECONDS) + .callTimeout(HTTP_TIMEOUT_IN_SECOND, TimeUnit.SECONDS) .build() } @@ -54,4 +79,16 @@ internal object NetworkModule { } } + @Provides + @Singleton + fun provideNetworkFetching( + @Named("ECloudRetrofit") ecloud: Retrofit, + @Named("GoogleRetrofit") google: Retrofit, + ) : AnonymousUser { + return AnonymousAnonymousUserRetrofitImpl( + eCloud = ecloud, + google = google + ) + } + } \ No newline at end of file diff --git a/modules/src/main/java/app/lounge/extension/Extension.kt b/modules/src/main/java/app/lounge/extension/Extension.kt new file mode 100644 index 000000000..98ac278b0 --- /dev/null +++ b/modules/src/main/java/app/lounge/extension/Extension.kt @@ -0,0 +1,29 @@ +/* + * Copyright MURENA SAS 2023 + * Apps Quickly and easily install Android apps onto your device! + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +package app.lounge.extension + +import com.google.gson.Gson +import java.util.Properties + +/** + * Convert Properties parameter to byte array + * @return Byte Array of Properties + * */ +fun Properties.toByteArray() = Gson().toJson(this).toByteArray() \ No newline at end of file diff --git a/modules/src/main/java/app/lounge/model/Model.kt b/modules/src/main/java/app/lounge/model/Model.kt new file mode 100644 index 000000000..acb1eb88c --- /dev/null +++ b/modules/src/main/java/app/lounge/model/Model.kt @@ -0,0 +1,37 @@ +/* + * Copyright MURENA SAS 2023 + * Apps Quickly and easily install Android apps onto your device! + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package app.lounge.model + +import com.aurora.gplayapi.data.models.AuthData +import com.aurora.gplayapi.data.providers.HeaderProvider +import java.util.Properties + + +/** AnonymousAuthDataRequestBody */ +data class AnonymousAuthDataRequestBody( + val properties: Properties, + val userAgent: String +) + +/** AnonymousLoginRequestBody */ +data class AnonymousAuthDataValidationRequestBody( + val authDataResponse: AuthData, +) { + val header = HeaderProvider.getDefaultHeaders(authDataResponse) +} \ No newline at end of file diff --git a/modules/src/main/java/app/lounge/networking/AnonymousAnonymousUserRetrofitImpl.kt b/modules/src/main/java/app/lounge/networking/AnonymousAnonymousUserRetrofitImpl.kt new file mode 100644 index 000000000..24e65bb46 --- /dev/null +++ b/modules/src/main/java/app/lounge/networking/AnonymousAnonymousUserRetrofitImpl.kt @@ -0,0 +1,118 @@ +/* + * Copyright MURENA SAS 2023 + * Apps Quickly and easily install Android apps onto your device! + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +package app.lounge.networking + +import app.lounge.extension.toByteArray +import app.lounge.model.AnonymousAuthDataRequestBody +import app.lounge.model.AnonymousAuthDataValidationRequestBody +import com.aurora.gplayapi.GooglePlayApi +import com.aurora.gplayapi.data.models.AuthData +import okhttp3.MediaType.Companion.toMediaTypeOrNull +import okhttp3.RequestBody +import okhttp3.RequestBody.Companion.toRequestBody +import okhttp3.ResponseBody +import retrofit2.Response +import retrofit2.Retrofit +import retrofit2.http.Body +import retrofit2.http.HeaderMap +import retrofit2.http.POST +import javax.inject.Inject +import javax.inject.Singleton + +interface AnonymousUserRetrofitAPI { + + companion object { + const val tokenBaseURL: String = "https://eu.gtoken.ecloud.global" + const val googlePlayBaseURL: String = GooglePlayApi.URL_BASE + } + + @POST(Path.authData) + suspend fun authDataRequest( + @HeaderMap headers: Map, + @Body requestBody: RequestBody + ): Response + + @POST(Path.sync) + suspend fun validateAuthentication( + @HeaderMap headers: Map + ): Response + + + + object Header { + val authData: (() -> String) -> Map = { + mapOf(Pair("User-Agent", it.invoke())) + } + } + + private object Path { + const val authData = "/" + const val sync = "/fdfe/apps/contentSync" + } + +} + +@Singleton +class AnonymousAnonymousUserRetrofitImpl @Inject constructor( + val eCloud: Retrofit, + val google: Retrofit +) : AnonymousUser { + + private val eCloudNetworkFetchingRetrofitAPI = eCloud.create( + AnonymousUserRetrofitAPI::class.java + ) + + private val googleNetworkFetchingRetrofitAPI = google.create( + AnonymousUserRetrofitAPI::class.java + ) + + + override suspend fun requestAuthData( + anonymousAuthDataRequestBody: AnonymousAuthDataRequestBody + ): NetworkResult { + val requestBody: RequestBody = + anonymousAuthDataRequestBody.properties.toByteArray().let { result -> + result.toRequestBody( + contentType = "application/json".toMediaTypeOrNull(), + offset = 0, + byteCount = result.size + ) + } + return fetch { + eCloudNetworkFetchingRetrofitAPI.authDataRequest( + requestBody = requestBody, + headers = AnonymousUserRetrofitAPI.Header.authData { + anonymousAuthDataRequestBody.userAgent + } + ) + } + } + + override suspend fun requestAuthDataValidation( + anonymousAuthDataValidationRequestBody: AnonymousAuthDataValidationRequestBody + ): NetworkResult { + return fetch { + googleNetworkFetchingRetrofitAPI.validateAuthentication( + headers = anonymousAuthDataValidationRequestBody.header + ) + } + } + +} \ No newline at end of file diff --git a/modules/src/main/java/app/lounge/networking/AnonymousUser.kt b/modules/src/main/java/app/lounge/networking/AnonymousUser.kt new file mode 100644 index 000000000..00ee7c54d --- /dev/null +++ b/modules/src/main/java/app/lounge/networking/AnonymousUser.kt @@ -0,0 +1,36 @@ +/* + * Copyright MURENA SAS 2023 + * Apps Quickly and easily install Android apps onto your device! + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +package app.lounge.networking + +import app.lounge.model.AnonymousAuthDataRequestBody +import app.lounge.model.AnonymousAuthDataValidationRequestBody +import com.aurora.gplayapi.data.models.AuthData +import okhttp3.ResponseBody + +interface AnonymousUser { + suspend fun requestAuthData( + anonymousAuthDataRequestBody: AnonymousAuthDataRequestBody + ) : NetworkResult + + suspend fun requestAuthDataValidation( + anonymousAuthDataValidationRequestBody: AnonymousAuthDataValidationRequestBody + ) : NetworkResult +} + -- GitLab From 44ea3b245b08b78791430bbd1550aa8d5c9d83d9 Mon Sep 17 00:00:00 2001 From: Nishant Dande Date: Thu, 27 Jul 2023 14:58:21 +0530 Subject: [PATCH 14/19] Deleted test files --- .../java/app/lounge/AnonymousUserAPITest.kt | 158 ------------------ 1 file changed, 158 deletions(-) delete mode 100644 modules/src/androidTest/java/app/lounge/AnonymousUserAPITest.kt diff --git a/modules/src/androidTest/java/app/lounge/AnonymousUserAPITest.kt b/modules/src/androidTest/java/app/lounge/AnonymousUserAPITest.kt deleted file mode 100644 index 2651e08db..000000000 --- a/modules/src/androidTest/java/app/lounge/AnonymousUserAPITest.kt +++ /dev/null @@ -1,158 +0,0 @@ -package app.lounge - -import app.lounge.model.AnonymousAuthDataRequestBody -import app.lounge.model.AnonymousAuthDataValidationRequestBody -import app.lounge.model.AuthDataResponse -import app.lounge.model.AuthDataValidationResponse -import app.lounge.networking.NetworkResult -import app.lounge.networking.UserAuthentication -import app.lounge.networking.UserAuthenticationRetrofitAPI -import app.lounge.networking.UserAuthenticationRetrofitImpl -import kotlinx.coroutines.runBlocking -import okhttp3.OkHttpClient -import org.junit.Test -import retrofit2.Retrofit -import retrofit2.converter.gson.GsonConverterFactory -import java.io.InterruptedIOException -import java.util.Properties -import java.util.concurrent.TimeUnit - -class UserAuthenticationAPITest { - - companion object { - var authData: AuthDataResponse? = null - } - - @Test - fun test1OnSuccessReturnsAuthData() = runBlocking { - val response = userAuthentication.requestAuthData( - anonymousAuthDataRequestBody = requestBodyData, - ) - when(response){ - is NetworkResult.Success -> authData = response.data - else -> {} - } - - assert(authData is AuthDataResponse) { "Assert!! Success must return data" } - } - - @Test - fun test2OnSuccessReturnsLoginData() = runBlocking { - var result: AuthDataValidationResponse? = null - authData?.let { authData -> - authData.dfeCookie = "null" - - val response = userAuthentication.requestAuthDataValidation( - anonymousAuthDataValidationRequestBody = AnonymousAuthDataValidationRequestBody( - authDataResponse = authData - ) - ) - when(response){ - is NetworkResult.Success -> result = response.data - else -> {} - } - } - - assert(authData is AuthDataResponse) { "Assert!! AuthData must be present" } - assert(result is AuthDataValidationResponse) { "Assert!! `response` must have data" } - } - - @Test - fun test3OnTimeoutFailureReturnsError(): Unit = runBlocking { - var failure: Throwable = Exception("No Error") - authData?.let { authData -> - authData.dfeCookie = "null" - - try { - val response = userAuthenticationGoogleTimeout.requestAuthDataValidation( - anonymousAuthDataValidationRequestBody = AnonymousAuthDataValidationRequestBody( - authDataResponse = authData - ) - ) - - when(response){ - is NetworkResult.Error -> failure = response.exception - else -> {} - } - } catch (e: InterruptedIOException) { failure = e } - } - assert(authData is AuthDataResponse) { "Assert!! AuthData must be present" } - assert(failure is InterruptedIOException) { "Assert!! Timeout Failure callback must call" } - } - - - private fun retrofitTestConfig( - baseUrl: String, - timeoutInMillisecond: Long = 10000L - ): Retrofit = Retrofit.Builder() - .baseUrl(baseUrl) - .addConverterFactory(GsonConverterFactory.create()) - .client( - OkHttpClient.Builder() - .callTimeout(timeoutInMillisecond, TimeUnit.MILLISECONDS) - .build() - ) - .build() - - private val eCloudTest = retrofitTestConfig(UserAuthenticationRetrofitAPI.tokenBaseURL) - private val googleTest = retrofitTestConfig(UserAuthenticationRetrofitAPI.googlePlayBaseURL) - private val googleTestTimeout = retrofitTestConfig( - UserAuthenticationRetrofitAPI.googlePlayBaseURL, 50L) - - private val userAuthentication: UserAuthentication = UserAuthenticationRetrofitImpl( - eCloud = eCloudTest, - google = googleTest - ) - - private val userAuthenticationGoogleTimeout: UserAuthentication = UserAuthenticationRetrofitImpl( - eCloud = eCloudTest, - google = googleTestTimeout - ) - - private val requestBodyData = AnonymousAuthDataRequestBody( - properties = testSystemProperties, - userAgent = testUserAgent - ) -} - -private const val testUserAgent: String = "{\"package\":\"foundation.e.apps.debug\",\"version\":\"2.5.5.debug\",\"device\":\"coral\",\"api\":32,\"os_version\":\"1.11-s-20230511288805-dev-coral\",\"build_id\":\"319e25cd.20230630224839\"}" - -private val testSystemProperties = Properties().apply { - setProperty("UserReadableName", "coral-default") - setProperty("Build.HARDWARE", "coral") - setProperty("Build.RADIO", "g8150-00123-220402-B-8399852") - setProperty("Build.FINGERPRINT","google/coral/coral:12/SQ3A.220705.003.A1/8672226:user/release-keys") - setProperty("Build.BRAND", "google") - setProperty("Build.DEVICE", "coral") - setProperty("Build.VERSION.SDK_INT", "32") - setProperty("Build.VERSION.RELEASE", "12") - setProperty("Build.MODEL", "Pixel 4 XL") - setProperty("Build.MANUFACTURER", "Google") - setProperty("Build.PRODUCT", "coral") - setProperty("Build.ID", "SQ3A.220705.004") - setProperty("Build.BOOTLOADER", "c2f2-0.4-8351033") - setProperty("TouchScreen", "3") - setProperty("Keyboard", "1") - setProperty("Navigation", "1") - setProperty("ScreenLayout", "2") - setProperty("HasHardKeyboard", "false") - setProperty("HasFiveWayNavigation", "false") - setProperty("Screen.Density", "560") - setProperty("Screen.Width", "1440") - setProperty("Screen.Height", "2984") - setProperty("Platforms", "arm64-v8a,armeabi-v7a,armeabi") - setProperty("Features", "android.hardware.sensor.proximity,com.verizon.hardware.telephony.lte,com.verizon.hardware.telephony.ehrpd,android.hardware.sensor.accelerometer,android.software.controls,android.hardware.faketouch,com.google.android.feature.D2D_CABLE_MIGRATION_FEATURE,android.hardware.telephony.euicc,android.hardware.reboot_escrow,android.hardware.usb.accessory,android.hardware.telephony.cdma,android.software.backup,android.hardware.touchscreen,android.hardware.touchscreen.multitouch,android.software.print,org.lineageos.weather,android.software.activities_on_secondary_displays,android.hardware.wifi.rtt,com.google.android.feature.PIXEL_2017_EXPERIENCE,android.software.voice_recognizers,android.software.picture_in_picture,android.hardware.sensor.gyroscope,android.hardware.audio.low_latency,android.software.vulkan.deqp.level,android.software.cant_save_state,com.google.android.feature.PIXEL_2018_EXPERIENCE,android.hardware.security.model.compatible,com.google.android.feature.PIXEL_2019_EXPERIENCE,android.hardware.opengles.aep,org.lineageos.livedisplay,org.lineageos.profiles,android.hardware.bluetooth,android.hardware.camera.autofocus,android.hardware.telephony.gsm,android.hardware.telephony.ims,android.software.incremental_delivery,android.software.sip.voip,android.hardware.se.omapi.ese,android.software.opengles.deqp.level,android.hardware.usb.host,android.hardware.audio.output,android.software.verified_boot,android.hardware.camera.flash,android.hardware.camera.front,android.hardware.sensor.hifi_sensors,com.google.android.apps.photos.PIXEL_2019_PRELOAD,android.hardware.se.omapi.uicc,android.hardware.strongbox_keystore,android.hardware.screen.portrait,android.hardware.nfc,com.google.android.feature.TURBO_PRELOAD,com.nxp.mifare,android.hardware.sensor.stepdetector,android.software.home_screen,android.hardware.context_hub,android.hardware.microphone,android.software.autofill,org.lineageos.hardware,org.lineageos.globalactions,android.software.securely_removes_users,com.google.android.feature.PIXEL_EXPERIENCE,android.hardware.bluetooth_le,android.hardware.sensor.compass,com.google.android.feature.GOOGLE_FI_BUNDLED,android.hardware.touchscreen.multitouch.jazzhand,android.hardware.sensor.barometer,android.software.app_widgets,android.hardware.telephony.carrierlock,android.software.input_methods,android.hardware.sensor.light,android.hardware.vulkan.version,android.software.companion_device_setup,android.software.device_admin,com.google.android.feature.WELLBEING,android.hardware.wifi.passpoint,android.hardware.camera,org.lineageos.trust,android.hardware.device_unique_attestation,android.hardware.screen.landscape,android.software.device_id_attestation,com.google.android.feature.AER_OPTIMIZED,android.hardware.ram.normal,org.lineageos.android,com.google.android.feature.PIXEL_2019_MIDYEAR_EXPERIENCE,android.software.managed_users,android.software.webview,android.hardware.sensor.stepcounter,android.hardware.camera.capability.manual_post_processing,android.hardware.camera.any,android.hardware.camera.capability.raw,android.hardware.vulkan.compute,android.software.connectionservice,android.hardware.touchscreen.multitouch.distinct,android.hardware.location.network,android.software.cts,android.software.sip,android.hardware.camera.capability.manual_sensor,android.software.app_enumeration,android.hardware.camera.level.full,android.hardware.identity_credential,android.hardware.wifi.direct,android.software.live_wallpaper,android.software.ipsec_tunnels,org.lineageos.settings,android.hardware.sensor.assist,android.hardware.audio.pro,android.hardware.nfc.hcef,android.hardware.nfc.uicc,android.hardware.location.gps,android.sofware.nfc.beam,android.software.midi,android.hardware.nfc.any,android.hardware.nfc.ese,android.hardware.nfc.hce,android.hardware.wifi,android.hardware.location,android.hardware.vulkan.level,android.hardware.wifi.aware,android.software.secure_lock_screen,android.hardware.biometrics.face,android.hardware.telephony,android.software.file_based_encryption") - setProperty("Locales", "af,af_ZA,am,am_ET,ar,ar_EG,ar_XB,as,ast_ES,az,be,bg,bg_BG,bn,bs,ca,ca_ES,cs,cs_CZ,cy,da,da_DK,de,de_DE,el,el_GR,en,en_AU,en_CA,en_GB,en_IN,en_US,en_XA,en_XC,es,es_419,es_ES,es_US,et,eu,fa,fa_IR,fi,fi_FI,fil,fil_PH,fr,fr_CA,fr_FR,gd,gl,gu,hi,hi_IN,hr,hr_HR,hu,hu_HU,hy,in,in_ID,is,it,it_IT,iw,iw_IL,ja,ja_JP,ka,kk,km,kn,ko,ko_KR,ky,lo,lt,lt_LT,lv,lv_LV,mk,ml,mn,mr,ms,ms_MY,my,nb,nb_NO,ne,nl,nl_NL,or,pa,pl,pl_PL,pt,pt_BR,pt_PT,ro,ro_RO,ru,ru_RU,si,sk,sk_SK,sl,sl_SI,sq,sr,sr_Latn,sr_RS,sv,sv_SE,sw,sw_TZ,ta,te,th,th_TH,tr,tr_TR,uk,uk_UA,ur,uz,vi,vi_VN,zh_CN,zh_HK,zh_TW,zu,zu_ZA") - setProperty("SharedLibraries", "android.test.base,android.test.mock,com.vzw.apnlib,android.hidl.manager-V1.0-java,qti-telephony-hidl-wrapper,libfastcvopt.so,google-ril,qti-telephony-utils,com.android.omadm.radioconfig,libcdsprpc.so,android.hidl.base-V1.0-java,com.qualcomm.qmapbridge,libairbrush-pixel.so,com.google.android.camera.experimental2019,libOpenCL-pixel.so,libadsprpc.so,com.android.location.provider,android.net.ipsec.ike,com.android.future.usb.accessory,libsdsprpc.so,android.ext.shared,javax.obex,izat.xt.srv,com.google.android.gms,lib_aion_buffer.so,com.qualcomm.uimremoteclientlibrary,libqdMetaData.so,com.qualcomm.uimremoteserverlibrary,com.qualcomm.qcrilhook,android.test.runner,org.apache.http.legacy,com.google.android.camera.extensions,com.google.android.hardwareinfo,com.android.cts.ctsshim.shared_library,com.android.nfc_extras,com.android.media.remotedisplay,com.android.mediadrm.signer,com.qualcomm.qti.imscmservice-V2.0-java,qti-telephony-hidl-wrapper-prd,com.qualcomm.qti.imscmservice-V2.1-java,com.qualcomm.qti.imscmservice-V2.2-java") - setProperty("GL.Version", "196610") - setProperty("GL.Extensions", ",GL_AMD_compressed_ATC_texture,GL_AMD_performance_monitor,GL_ANDROID_extension_pack_es31a,GL_APPLE_texture_2D_limited_npot,GL_ARB_vertex_buffer_object,GL_ARM_shader_framebuffer_fetch_depth_stencil,GL_EXT_EGL_image_array,GL_EXT_EGL_image_external_wrap_modes,GL_EXT_EGL_image_storage,GL_EXT_YUV_target,GL_EXT_blend_func_extended,GL_EXT_blit_framebuffer_params,GL_EXT_buffer_storage,GL_EXT_clip_control,GL_EXT_clip_cull_distance,GL_EXT_color_buffer_float,GL_EXT_color_buffer_half_float,GL_EXT_copy_image,GL_EXT_debug_label,GL_EXT_debug_marker,GL_EXT_discard_framebuffer,GL_EXT_disjoint_timer_query,GL_EXT_draw_buffers_indexed,GL_EXT_external_buffer,GL_EXT_fragment_invocation_density,GL_EXT_geometry_shader,GL_EXT_gpu_shader5,GL_EXT_memory_object,GL_EXT_memory_object_fd,GL_EXT_multisampled_render_to_texture,GL_EXT_multisampled_render_to_texture2,GL_EXT_primitive_bounding_box,GL_EXT_protected_textures,GL_EXT_read_format_bgra,GL_EXT_robustness,GL_EXT_sRGB,GL_EXT_sRGB_write_control,GL_EXT_shader_framebuffer_fetch,GL_EXT_shader_io_blocks,GL_EXT_shader_non_constant_global_initializers,GL_EXT_tessellation_shader,GL_EXT_texture_border_clamp,GL_EXT_texture_buffer,GL_EXT_texture_cube_map_array,GL_EXT_texture_filter_anisotropic,GL_EXT_texture_format_BGRA8888,GL_EXT_texture_format_sRGB_override,GL_EXT_texture_norm16,GL_EXT_texture_sRGB_R8,GL_EXT_texture_sRGB_decode,GL_EXT_texture_type_2_10_10_10_REV,GL_KHR_blend_equation_advanced,GL_KHR_blend_equation_advanced_coherent,GL_KHR_debug,GL_KHR_no_error,GL_KHR_robust_buffer_access_behavior,GL_KHR_texture_compression_astc_hdr,GL_KHR_texture_compression_astc_ldr,GL_NV_shader_noperspective_interpolation,GL_OES_EGL_image,GL_OES_EGL_image_external,GL_OES_EGL_image_external_essl3,GL_OES_EGL_sync,GL_OES_blend_equation_separate,GL_OES_blend_func_separate,GL_OES_blend_subtract,GL_OES_compressed_ETC1_RGB8_texture,GL_OES_compressed_paletted_texture,GL_OES_depth24,GL_OES_depth_texture,GL_OES_depth_texture_cube_map,GL_OES_draw_texture,GL_OES_element_index_uint,GL_OES_framebuffer_object,GL_OES_get_program_binary,GL_OES_matrix_palette,GL_OES_packed_depth_stencil,GL_OES_point_size_array,GL_OES_point_sprite,GL_OES_read_format,GL_OES_rgb8_rgba8,GL_OES_sample_shading,GL_OES_sample_variables,GL_OES_shader_image_atomic,GL_OES_shader_multisample_interpolation,GL_OES_standard_derivatives,GL_OES_stencil_wrap,GL_OES_surfaceless_context,GL_OES_texture_3D,GL_OES_texture_compression_astc,GL_OES_texture_cube_map,GL_OES_texture_env_crossbar,GL_OES_texture_float,GL_OES_texture_float_linear,GL_OES_texture_half_float,GL_OES_texture_half_float_linear,GL_OES_texture_mirrored_repeat,GL_OES_texture_npot,GL_OES_texture_stencil8,GL_OES_texture_storage_multisample_2d_array,GL_OES_texture_view,GL_OES_vertex_array_object,GL_OES_vertex_half_float,GL_OVR_multiview,GL_OVR_multiview2,GL_OVR_multiview_multisampled_render_to_texture,GL_QCOM_YUV_texture_gather,GL_QCOM_alpha_test,GL_QCOM_extended_get,GL_QCOM_motion_estimation,GL_QCOM_shader_framebuffer_fetch_noncoherent,GL_QCOM_shader_framebuffer_fetch_rate,GL_QCOM_texture_foveated,GL_QCOM_texture_foveated_subsampled_layout,GL_QCOM_tiled_rendering,GL_QCOM_validate_shader_binary") - setProperty("Client", "android-google") - setProperty("GSF.version", "223616055") - setProperty("Vending.version", "82151710") - setProperty("Vending.versionString", "21.5.17-21 [0] [PR] 326734551") - setProperty("Roaming", "mobile-notroaming") - setProperty("TimeZone", "UTC-10") - setProperty("CellOperator", "310") - setProperty("SimOperator", "38") -} - -- GitLab From 3326606c2dfc84a117f409f8ab872fe14760075a Mon Sep 17 00:00:00 2001 From: Nishant Dande Date: Thu, 27 Jul 2023 15:12:43 +0530 Subject: [PATCH 15/19] Refine anonymous user codebase --- .../java/app/lounge/AnonymousUserAPITest.kt | 100 ++++++++++++++++++ .../main/java/app/lounge/di/NetworkModule.kt | 22 +--- .../src/main/java/app/lounge/model/Model.kt | 11 +- .../app/lounge/networking/AnonymousUser.kt | 6 -- ...itImpl.kt => AnonymousUserRetrofitImpl.kt} | 36 +------ 5 files changed, 109 insertions(+), 66 deletions(-) create mode 100644 modules/src/androidTest/java/app/lounge/AnonymousUserAPITest.kt rename modules/src/main/java/app/lounge/networking/{AnonymousAnonymousUserRetrofitImpl.kt => AnonymousUserRetrofitImpl.kt} (69%) diff --git a/modules/src/androidTest/java/app/lounge/AnonymousUserAPITest.kt b/modules/src/androidTest/java/app/lounge/AnonymousUserAPITest.kt new file mode 100644 index 000000000..130bee5b5 --- /dev/null +++ b/modules/src/androidTest/java/app/lounge/AnonymousUserAPITest.kt @@ -0,0 +1,100 @@ +package app.lounge + +import app.lounge.model.AnonymousAuthDataRequestBody +import app.lounge.networking.AnonymousUser +import app.lounge.networking.AnonymousUserRetrofitAPI +import app.lounge.networking.AnonymousUserRetrofitImpl +import app.lounge.networking.NetworkResult +import com.aurora.gplayapi.data.models.AuthData +import kotlinx.coroutines.runBlocking +import okhttp3.OkHttpClient +import org.junit.Test +import retrofit2.Retrofit +import retrofit2.converter.gson.GsonConverterFactory +import java.util.Properties +import java.util.concurrent.TimeUnit + +class AnonymousUserAPITest { + + companion object { + var authData: AuthData? = null + } + + @Test + fun testOnSuccessReturnsAuthData() = runBlocking { + val response = anonymousUser.requestAuthData( + anonymousAuthDataRequestBody = requestBodyData, + ) + when(response){ + is NetworkResult.Success -> authData = response.data + else -> {} + } + + assert(authData is AuthData) { "Assert!! Success must return data" } + } + + + private fun retrofitTestConfig( + baseUrl: String, + timeoutInMillisecond: Long = 10000L + ): Retrofit = Retrofit.Builder() + .baseUrl(baseUrl) + .addConverterFactory(GsonConverterFactory.create()) + .client( + OkHttpClient.Builder() + .callTimeout(timeoutInMillisecond, TimeUnit.MILLISECONDS) + .build() + ) + .build() + + private val eCloudTest = retrofitTestConfig(AnonymousUserRetrofitAPI.tokenBaseURL) + + private val anonymousUser: AnonymousUser = AnonymousUserRetrofitImpl(eCloud = eCloudTest) + + private val requestBodyData = AnonymousAuthDataRequestBody( + properties = testSystemProperties, + userAgent = testUserAgent + ) +} + +private const val testUserAgent: String = "{\"package\":\"foundation.e.apps.debug\",\"version\":\"2.5.5.debug\",\"device\":\"coral\",\"api\":32,\"os_version\":\"1.11-s-20230511288805-dev-coral\",\"build_id\":\"319e25cd.20230630224839\"}" + +private val testSystemProperties = Properties().apply { + setProperty("UserReadableName", "coral-default") + setProperty("Build.HARDWARE", "coral") + setProperty("Build.RADIO", "g8150-00123-220402-B-8399852") + setProperty("Build.FINGERPRINT","google/coral/coral:12/SQ3A.220705.003.A1/8672226:user/release-keys") + setProperty("Build.BRAND", "google") + setProperty("Build.DEVICE", "coral") + setProperty("Build.VERSION.SDK_INT", "32") + setProperty("Build.VERSION.RELEASE", "12") + setProperty("Build.MODEL", "Pixel 4 XL") + setProperty("Build.MANUFACTURER", "Google") + setProperty("Build.PRODUCT", "coral") + setProperty("Build.ID", "SQ3A.220705.004") + setProperty("Build.BOOTLOADER", "c2f2-0.4-8351033") + setProperty("TouchScreen", "3") + setProperty("Keyboard", "1") + setProperty("Navigation", "1") + setProperty("ScreenLayout", "2") + setProperty("HasHardKeyboard", "false") + setProperty("HasFiveWayNavigation", "false") + setProperty("Screen.Density", "560") + setProperty("Screen.Width", "1440") + setProperty("Screen.Height", "2984") + setProperty("Platforms", "arm64-v8a,armeabi-v7a,armeabi") + setProperty("Features", "android.hardware.sensor.proximity,com.verizon.hardware.telephony.lte,com.verizon.hardware.telephony.ehrpd,android.hardware.sensor.accelerometer,android.software.controls,android.hardware.faketouch,com.google.android.feature.D2D_CABLE_MIGRATION_FEATURE,android.hardware.telephony.euicc,android.hardware.reboot_escrow,android.hardware.usb.accessory,android.hardware.telephony.cdma,android.software.backup,android.hardware.touchscreen,android.hardware.touchscreen.multitouch,android.software.print,org.lineageos.weather,android.software.activities_on_secondary_displays,android.hardware.wifi.rtt,com.google.android.feature.PIXEL_2017_EXPERIENCE,android.software.voice_recognizers,android.software.picture_in_picture,android.hardware.sensor.gyroscope,android.hardware.audio.low_latency,android.software.vulkan.deqp.level,android.software.cant_save_state,com.google.android.feature.PIXEL_2018_EXPERIENCE,android.hardware.security.model.compatible,com.google.android.feature.PIXEL_2019_EXPERIENCE,android.hardware.opengles.aep,org.lineageos.livedisplay,org.lineageos.profiles,android.hardware.bluetooth,android.hardware.camera.autofocus,android.hardware.telephony.gsm,android.hardware.telephony.ims,android.software.incremental_delivery,android.software.sip.voip,android.hardware.se.omapi.ese,android.software.opengles.deqp.level,android.hardware.usb.host,android.hardware.audio.output,android.software.verified_boot,android.hardware.camera.flash,android.hardware.camera.front,android.hardware.sensor.hifi_sensors,com.google.android.apps.photos.PIXEL_2019_PRELOAD,android.hardware.se.omapi.uicc,android.hardware.strongbox_keystore,android.hardware.screen.portrait,android.hardware.nfc,com.google.android.feature.TURBO_PRELOAD,com.nxp.mifare,android.hardware.sensor.stepdetector,android.software.home_screen,android.hardware.context_hub,android.hardware.microphone,android.software.autofill,org.lineageos.hardware,org.lineageos.globalactions,android.software.securely_removes_users,com.google.android.feature.PIXEL_EXPERIENCE,android.hardware.bluetooth_le,android.hardware.sensor.compass,com.google.android.feature.GOOGLE_FI_BUNDLED,android.hardware.touchscreen.multitouch.jazzhand,android.hardware.sensor.barometer,android.software.app_widgets,android.hardware.telephony.carrierlock,android.software.input_methods,android.hardware.sensor.light,android.hardware.vulkan.version,android.software.companion_device_setup,android.software.device_admin,com.google.android.feature.WELLBEING,android.hardware.wifi.passpoint,android.hardware.camera,org.lineageos.trust,android.hardware.device_unique_attestation,android.hardware.screen.landscape,android.software.device_id_attestation,com.google.android.feature.AER_OPTIMIZED,android.hardware.ram.normal,org.lineageos.android,com.google.android.feature.PIXEL_2019_MIDYEAR_EXPERIENCE,android.software.managed_users,android.software.webview,android.hardware.sensor.stepcounter,android.hardware.camera.capability.manual_post_processing,android.hardware.camera.any,android.hardware.camera.capability.raw,android.hardware.vulkan.compute,android.software.connectionservice,android.hardware.touchscreen.multitouch.distinct,android.hardware.location.network,android.software.cts,android.software.sip,android.hardware.camera.capability.manual_sensor,android.software.app_enumeration,android.hardware.camera.level.full,android.hardware.identity_credential,android.hardware.wifi.direct,android.software.live_wallpaper,android.software.ipsec_tunnels,org.lineageos.settings,android.hardware.sensor.assist,android.hardware.audio.pro,android.hardware.nfc.hcef,android.hardware.nfc.uicc,android.hardware.location.gps,android.sofware.nfc.beam,android.software.midi,android.hardware.nfc.any,android.hardware.nfc.ese,android.hardware.nfc.hce,android.hardware.wifi,android.hardware.location,android.hardware.vulkan.level,android.hardware.wifi.aware,android.software.secure_lock_screen,android.hardware.biometrics.face,android.hardware.telephony,android.software.file_based_encryption") + setProperty("Locales", "af,af_ZA,am,am_ET,ar,ar_EG,ar_XB,as,ast_ES,az,be,bg,bg_BG,bn,bs,ca,ca_ES,cs,cs_CZ,cy,da,da_DK,de,de_DE,el,el_GR,en,en_AU,en_CA,en_GB,en_IN,en_US,en_XA,en_XC,es,es_419,es_ES,es_US,et,eu,fa,fa_IR,fi,fi_FI,fil,fil_PH,fr,fr_CA,fr_FR,gd,gl,gu,hi,hi_IN,hr,hr_HR,hu,hu_HU,hy,in,in_ID,is,it,it_IT,iw,iw_IL,ja,ja_JP,ka,kk,km,kn,ko,ko_KR,ky,lo,lt,lt_LT,lv,lv_LV,mk,ml,mn,mr,ms,ms_MY,my,nb,nb_NO,ne,nl,nl_NL,or,pa,pl,pl_PL,pt,pt_BR,pt_PT,ro,ro_RO,ru,ru_RU,si,sk,sk_SK,sl,sl_SI,sq,sr,sr_Latn,sr_RS,sv,sv_SE,sw,sw_TZ,ta,te,th,th_TH,tr,tr_TR,uk,uk_UA,ur,uz,vi,vi_VN,zh_CN,zh_HK,zh_TW,zu,zu_ZA") + setProperty("SharedLibraries", "android.test.base,android.test.mock,com.vzw.apnlib,android.hidl.manager-V1.0-java,qti-telephony-hidl-wrapper,libfastcvopt.so,google-ril,qti-telephony-utils,com.android.omadm.radioconfig,libcdsprpc.so,android.hidl.base-V1.0-java,com.qualcomm.qmapbridge,libairbrush-pixel.so,com.google.android.camera.experimental2019,libOpenCL-pixel.so,libadsprpc.so,com.android.location.provider,android.net.ipsec.ike,com.android.future.usb.accessory,libsdsprpc.so,android.ext.shared,javax.obex,izat.xt.srv,com.google.android.gms,lib_aion_buffer.so,com.qualcomm.uimremoteclientlibrary,libqdMetaData.so,com.qualcomm.uimremoteserverlibrary,com.qualcomm.qcrilhook,android.test.runner,org.apache.http.legacy,com.google.android.camera.extensions,com.google.android.hardwareinfo,com.android.cts.ctsshim.shared_library,com.android.nfc_extras,com.android.media.remotedisplay,com.android.mediadrm.signer,com.qualcomm.qti.imscmservice-V2.0-java,qti-telephony-hidl-wrapper-prd,com.qualcomm.qti.imscmservice-V2.1-java,com.qualcomm.qti.imscmservice-V2.2-java") + setProperty("GL.Version", "196610") + setProperty("GL.Extensions", ",GL_AMD_compressed_ATC_texture,GL_AMD_performance_monitor,GL_ANDROID_extension_pack_es31a,GL_APPLE_texture_2D_limited_npot,GL_ARB_vertex_buffer_object,GL_ARM_shader_framebuffer_fetch_depth_stencil,GL_EXT_EGL_image_array,GL_EXT_EGL_image_external_wrap_modes,GL_EXT_EGL_image_storage,GL_EXT_YUV_target,GL_EXT_blend_func_extended,GL_EXT_blit_framebuffer_params,GL_EXT_buffer_storage,GL_EXT_clip_control,GL_EXT_clip_cull_distance,GL_EXT_color_buffer_float,GL_EXT_color_buffer_half_float,GL_EXT_copy_image,GL_EXT_debug_label,GL_EXT_debug_marker,GL_EXT_discard_framebuffer,GL_EXT_disjoint_timer_query,GL_EXT_draw_buffers_indexed,GL_EXT_external_buffer,GL_EXT_fragment_invocation_density,GL_EXT_geometry_shader,GL_EXT_gpu_shader5,GL_EXT_memory_object,GL_EXT_memory_object_fd,GL_EXT_multisampled_render_to_texture,GL_EXT_multisampled_render_to_texture2,GL_EXT_primitive_bounding_box,GL_EXT_protected_textures,GL_EXT_read_format_bgra,GL_EXT_robustness,GL_EXT_sRGB,GL_EXT_sRGB_write_control,GL_EXT_shader_framebuffer_fetch,GL_EXT_shader_io_blocks,GL_EXT_shader_non_constant_global_initializers,GL_EXT_tessellation_shader,GL_EXT_texture_border_clamp,GL_EXT_texture_buffer,GL_EXT_texture_cube_map_array,GL_EXT_texture_filter_anisotropic,GL_EXT_texture_format_BGRA8888,GL_EXT_texture_format_sRGB_override,GL_EXT_texture_norm16,GL_EXT_texture_sRGB_R8,GL_EXT_texture_sRGB_decode,GL_EXT_texture_type_2_10_10_10_REV,GL_KHR_blend_equation_advanced,GL_KHR_blend_equation_advanced_coherent,GL_KHR_debug,GL_KHR_no_error,GL_KHR_robust_buffer_access_behavior,GL_KHR_texture_compression_astc_hdr,GL_KHR_texture_compression_astc_ldr,GL_NV_shader_noperspective_interpolation,GL_OES_EGL_image,GL_OES_EGL_image_external,GL_OES_EGL_image_external_essl3,GL_OES_EGL_sync,GL_OES_blend_equation_separate,GL_OES_blend_func_separate,GL_OES_blend_subtract,GL_OES_compressed_ETC1_RGB8_texture,GL_OES_compressed_paletted_texture,GL_OES_depth24,GL_OES_depth_texture,GL_OES_depth_texture_cube_map,GL_OES_draw_texture,GL_OES_element_index_uint,GL_OES_framebuffer_object,GL_OES_get_program_binary,GL_OES_matrix_palette,GL_OES_packed_depth_stencil,GL_OES_point_size_array,GL_OES_point_sprite,GL_OES_read_format,GL_OES_rgb8_rgba8,GL_OES_sample_shading,GL_OES_sample_variables,GL_OES_shader_image_atomic,GL_OES_shader_multisample_interpolation,GL_OES_standard_derivatives,GL_OES_stencil_wrap,GL_OES_surfaceless_context,GL_OES_texture_3D,GL_OES_texture_compression_astc,GL_OES_texture_cube_map,GL_OES_texture_env_crossbar,GL_OES_texture_float,GL_OES_texture_float_linear,GL_OES_texture_half_float,GL_OES_texture_half_float_linear,GL_OES_texture_mirrored_repeat,GL_OES_texture_npot,GL_OES_texture_stencil8,GL_OES_texture_storage_multisample_2d_array,GL_OES_texture_view,GL_OES_vertex_array_object,GL_OES_vertex_half_float,GL_OVR_multiview,GL_OVR_multiview2,GL_OVR_multiview_multisampled_render_to_texture,GL_QCOM_YUV_texture_gather,GL_QCOM_alpha_test,GL_QCOM_extended_get,GL_QCOM_motion_estimation,GL_QCOM_shader_framebuffer_fetch_noncoherent,GL_QCOM_shader_framebuffer_fetch_rate,GL_QCOM_texture_foveated,GL_QCOM_texture_foveated_subsampled_layout,GL_QCOM_tiled_rendering,GL_QCOM_validate_shader_binary") + setProperty("Client", "android-google") + setProperty("GSF.version", "223616055") + setProperty("Vending.version", "82151710") + setProperty("Vending.versionString", "21.5.17-21 [0] [PR] 326734551") + setProperty("Roaming", "mobile-notroaming") + setProperty("TimeZone", "UTC-10") + setProperty("CellOperator", "310") + setProperty("SimOperator", "38") +} + diff --git a/modules/src/main/java/app/lounge/di/NetworkModule.kt b/modules/src/main/java/app/lounge/di/NetworkModule.kt index 8c11f0d04..c1c7f65cc 100644 --- a/modules/src/main/java/app/lounge/di/NetworkModule.kt +++ b/modules/src/main/java/app/lounge/di/NetworkModule.kt @@ -21,7 +21,7 @@ package app.lounge.di import app.lounge.networking.AnonymousUser import app.lounge.networking.AnonymousUserRetrofitAPI -import app.lounge.networking.AnonymousAnonymousUserRetrofitImpl +import app.lounge.networking.AnonymousUserRetrofitImpl import dagger.Module import dagger.Provides import dagger.hilt.InstallIn @@ -63,18 +63,6 @@ internal object NetworkModule { ) } - @Provides - @Singleton - @Named("GoogleRetrofit") - internal fun provideGoogleRetrofit( - okHttpClient: OkHttpClient - ): Retrofit { - return retrofit( - okHttpClient = okHttpClient, - baseUrl = AnonymousUserRetrofitAPI.googlePlayBaseURL - ) - } - @Provides @Singleton @Named("privateOkHttpClient") @@ -101,12 +89,10 @@ internal object NetworkModule { @Provides @Singleton fun provideNetworkFetching( - @Named("ECloudRetrofit") ecloud: Retrofit, - @Named("GoogleRetrofit") google: Retrofit, + @Named("ECloudRetrofit") ecloud: Retrofit ) : AnonymousUser { - return AnonymousAnonymousUserRetrofitImpl( - eCloud = ecloud, - google = google + return AnonymousUserRetrofitImpl( + eCloud = ecloud ) } diff --git a/modules/src/main/java/app/lounge/model/Model.kt b/modules/src/main/java/app/lounge/model/Model.kt index acb1eb88c..e77a91db4 100644 --- a/modules/src/main/java/app/lounge/model/Model.kt +++ b/modules/src/main/java/app/lounge/model/Model.kt @@ -18,8 +18,6 @@ package app.lounge.model -import com.aurora.gplayapi.data.models.AuthData -import com.aurora.gplayapi.data.providers.HeaderProvider import java.util.Properties @@ -27,11 +25,4 @@ import java.util.Properties data class AnonymousAuthDataRequestBody( val properties: Properties, val userAgent: String -) - -/** AnonymousLoginRequestBody */ -data class AnonymousAuthDataValidationRequestBody( - val authDataResponse: AuthData, -) { - val header = HeaderProvider.getDefaultHeaders(authDataResponse) -} \ No newline at end of file +) \ No newline at end of file diff --git a/modules/src/main/java/app/lounge/networking/AnonymousUser.kt b/modules/src/main/java/app/lounge/networking/AnonymousUser.kt index 00ee7c54d..48acc7f5f 100644 --- a/modules/src/main/java/app/lounge/networking/AnonymousUser.kt +++ b/modules/src/main/java/app/lounge/networking/AnonymousUser.kt @@ -20,17 +20,11 @@ package app.lounge.networking import app.lounge.model.AnonymousAuthDataRequestBody -import app.lounge.model.AnonymousAuthDataValidationRequestBody import com.aurora.gplayapi.data.models.AuthData -import okhttp3.ResponseBody interface AnonymousUser { suspend fun requestAuthData( anonymousAuthDataRequestBody: AnonymousAuthDataRequestBody ) : NetworkResult - - suspend fun requestAuthDataValidation( - anonymousAuthDataValidationRequestBody: AnonymousAuthDataValidationRequestBody - ) : NetworkResult } diff --git a/modules/src/main/java/app/lounge/networking/AnonymousAnonymousUserRetrofitImpl.kt b/modules/src/main/java/app/lounge/networking/AnonymousUserRetrofitImpl.kt similarity index 69% rename from modules/src/main/java/app/lounge/networking/AnonymousAnonymousUserRetrofitImpl.kt rename to modules/src/main/java/app/lounge/networking/AnonymousUserRetrofitImpl.kt index 24e65bb46..967aadaa2 100644 --- a/modules/src/main/java/app/lounge/networking/AnonymousAnonymousUserRetrofitImpl.kt +++ b/modules/src/main/java/app/lounge/networking/AnonymousUserRetrofitImpl.kt @@ -21,13 +21,10 @@ package app.lounge.networking import app.lounge.extension.toByteArray import app.lounge.model.AnonymousAuthDataRequestBody -import app.lounge.model.AnonymousAuthDataValidationRequestBody -import com.aurora.gplayapi.GooglePlayApi import com.aurora.gplayapi.data.models.AuthData import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.RequestBody import okhttp3.RequestBody.Companion.toRequestBody -import okhttp3.ResponseBody import retrofit2.Response import retrofit2.Retrofit import retrofit2.http.Body @@ -40,7 +37,6 @@ interface AnonymousUserRetrofitAPI { companion object { const val tokenBaseURL: String = "https://eu.gtoken.ecloud.global" - const val googlePlayBaseURL: String = GooglePlayApi.URL_BASE } @POST(Path.authData) @@ -49,13 +45,6 @@ interface AnonymousUserRetrofitAPI { @Body requestBody: RequestBody ): Response - @POST(Path.sync) - suspend fun validateAuthentication( - @HeaderMap headers: Map - ): Response - - - object Header { val authData: (() -> String) -> Map = { mapOf(Pair("User-Agent", it.invoke())) @@ -64,26 +53,19 @@ interface AnonymousUserRetrofitAPI { private object Path { const val authData = "/" - const val sync = "/fdfe/apps/contentSync" } } @Singleton -class AnonymousAnonymousUserRetrofitImpl @Inject constructor( - val eCloud: Retrofit, - val google: Retrofit +class AnonymousUserRetrofitImpl @Inject constructor( + val eCloud: Retrofit ) : AnonymousUser { - private val eCloudNetworkFetchingRetrofitAPI = eCloud.create( - AnonymousUserRetrofitAPI::class.java - ) - - private val googleNetworkFetchingRetrofitAPI = google.create( + private val eCloudRetrofitAPI = eCloud.create( AnonymousUserRetrofitAPI::class.java ) - override suspend fun requestAuthData( anonymousAuthDataRequestBody: AnonymousAuthDataRequestBody ): NetworkResult { @@ -96,7 +78,7 @@ class AnonymousAnonymousUserRetrofitImpl @Inject constructor( ) } return fetch { - eCloudNetworkFetchingRetrofitAPI.authDataRequest( + eCloudRetrofitAPI.authDataRequest( requestBody = requestBody, headers = AnonymousUserRetrofitAPI.Header.authData { anonymousAuthDataRequestBody.userAgent @@ -105,14 +87,4 @@ class AnonymousAnonymousUserRetrofitImpl @Inject constructor( } } - override suspend fun requestAuthDataValidation( - anonymousAuthDataValidationRequestBody: AnonymousAuthDataValidationRequestBody - ): NetworkResult { - return fetch { - googleNetworkFetchingRetrofitAPI.validateAuthentication( - headers = anonymousAuthDataValidationRequestBody.header - ) - } - } - } \ No newline at end of file -- GitLab From bbc9afb1e3c4592ea38758c6e191ca2993febb5e Mon Sep 17 00:00:00 2001 From: Nishant Dande Date: Thu, 27 Jul 2023 19:20:16 +0530 Subject: [PATCH 16/19] Move anonymous code to login package --- modules/build.gradle | 5 +++++ .../src/androidTest/java/app/lounge/AnonymousUserAPITest.kt | 6 +++--- modules/src/main/java/app/lounge/di/NetworkModule.kt | 6 +++--- .../lounge/{networking => login/anonymous}/AnonymousUser.kt | 3 ++- .../anonymous}/AnonymousUserRetrofitImpl.kt | 6 ++++-- 5 files changed, 17 insertions(+), 9 deletions(-) rename modules/src/main/java/app/lounge/{networking => login/anonymous}/AnonymousUser.kt (92%) rename modules/src/main/java/app/lounge/{networking => login/anonymous}/AnonymousUserRetrofitImpl.kt (95%) diff --git a/modules/build.gradle b/modules/build.gradle index 48fab303e..9189068ef 100644 --- a/modules/build.gradle +++ b/modules/build.gradle @@ -87,6 +87,11 @@ dependencies { kapt("com.google.dagger:hilt-android-compiler:$dagger_hilt_version") testImplementation 'junit:junit:4.13.2' + testImplementation "androidx.test:core:1.5.0" + testImplementation 'org.mockito:mockito-core:5.0.0' + testImplementation 'com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0' + testImplementation 'org.robolectric:robolectric:4.9' + testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.2" androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' } \ No newline at end of file diff --git a/modules/src/androidTest/java/app/lounge/AnonymousUserAPITest.kt b/modules/src/androidTest/java/app/lounge/AnonymousUserAPITest.kt index 130bee5b5..020dade3d 100644 --- a/modules/src/androidTest/java/app/lounge/AnonymousUserAPITest.kt +++ b/modules/src/androidTest/java/app/lounge/AnonymousUserAPITest.kt @@ -1,9 +1,9 @@ package app.lounge import app.lounge.model.AnonymousAuthDataRequestBody -import app.lounge.networking.AnonymousUser -import app.lounge.networking.AnonymousUserRetrofitAPI -import app.lounge.networking.AnonymousUserRetrofitImpl +import app.lounge.login.anonymous.AnonymousUser +import app.lounge.login.anonymous.AnonymousUserRetrofitAPI +import app.lounge.login.anonymous.AnonymousUserRetrofitImpl import app.lounge.networking.NetworkResult import com.aurora.gplayapi.data.models.AuthData import kotlinx.coroutines.runBlocking diff --git a/modules/src/main/java/app/lounge/di/NetworkModule.kt b/modules/src/main/java/app/lounge/di/NetworkModule.kt index c1c7f65cc..485648920 100644 --- a/modules/src/main/java/app/lounge/di/NetworkModule.kt +++ b/modules/src/main/java/app/lounge/di/NetworkModule.kt @@ -19,9 +19,9 @@ package app.lounge.di -import app.lounge.networking.AnonymousUser -import app.lounge.networking.AnonymousUserRetrofitAPI -import app.lounge.networking.AnonymousUserRetrofitImpl +import app.lounge.login.anonymous.AnonymousUser +import app.lounge.login.anonymous.AnonymousUserRetrofitAPI +import app.lounge.login.anonymous.AnonymousUserRetrofitImpl import dagger.Module import dagger.Provides import dagger.hilt.InstallIn diff --git a/modules/src/main/java/app/lounge/networking/AnonymousUser.kt b/modules/src/main/java/app/lounge/login/anonymous/AnonymousUser.kt similarity index 92% rename from modules/src/main/java/app/lounge/networking/AnonymousUser.kt rename to modules/src/main/java/app/lounge/login/anonymous/AnonymousUser.kt index 48acc7f5f..d02bb05c4 100644 --- a/modules/src/main/java/app/lounge/networking/AnonymousUser.kt +++ b/modules/src/main/java/app/lounge/login/anonymous/AnonymousUser.kt @@ -17,9 +17,10 @@ */ -package app.lounge.networking +package app.lounge.login.anonymous import app.lounge.model.AnonymousAuthDataRequestBody +import app.lounge.networking.NetworkResult import com.aurora.gplayapi.data.models.AuthData interface AnonymousUser { diff --git a/modules/src/main/java/app/lounge/networking/AnonymousUserRetrofitImpl.kt b/modules/src/main/java/app/lounge/login/anonymous/AnonymousUserRetrofitImpl.kt similarity index 95% rename from modules/src/main/java/app/lounge/networking/AnonymousUserRetrofitImpl.kt rename to modules/src/main/java/app/lounge/login/anonymous/AnonymousUserRetrofitImpl.kt index 967aadaa2..0721d8bfd 100644 --- a/modules/src/main/java/app/lounge/networking/AnonymousUserRetrofitImpl.kt +++ b/modules/src/main/java/app/lounge/login/anonymous/AnonymousUserRetrofitImpl.kt @@ -17,10 +17,12 @@ */ -package app.lounge.networking +package app.lounge.login.anonymous import app.lounge.extension.toByteArray import app.lounge.model.AnonymousAuthDataRequestBody +import app.lounge.networking.NetworkResult +import app.lounge.networking.fetch import com.aurora.gplayapi.data.models.AuthData import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.RequestBody @@ -60,7 +62,7 @@ interface AnonymousUserRetrofitAPI { @Singleton class AnonymousUserRetrofitImpl @Inject constructor( val eCloud: Retrofit -) : AnonymousUser { +) : AnonymousUser { private val eCloudRetrofitAPI = eCloud.create( AnonymousUserRetrofitAPI::class.java -- GitLab From 3f23ea0bcec83a42de115b73cd3d59aac966982e Mon Sep 17 00:00:00 2001 From: Nishant Dande Date: Thu, 27 Jul 2023 19:23:40 +0530 Subject: [PATCH 17/19] Remove unwanted dependencies --- modules/build.gradle | 5 ----- 1 file changed, 5 deletions(-) diff --git a/modules/build.gradle b/modules/build.gradle index 9189068ef..48fab303e 100644 --- a/modules/build.gradle +++ b/modules/build.gradle @@ -87,11 +87,6 @@ dependencies { kapt("com.google.dagger:hilt-android-compiler:$dagger_hilt_version") testImplementation 'junit:junit:4.13.2' - testImplementation "androidx.test:core:1.5.0" - testImplementation 'org.mockito:mockito-core:5.0.0' - testImplementation 'com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0' - testImplementation 'org.robolectric:robolectric:4.9' - testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.2" androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' } \ No newline at end of file -- GitLab From b2bfdee79f6914125f35853e1e6c205c40424ce2 Mon Sep 17 00:00:00 2001 From: Nishant Dande Date: Fri, 28 Jul 2023 12:37:06 +0530 Subject: [PATCH 18/19] Rename Anonymous user porvider in NetworkModule --- modules/src/main/java/app/lounge/di/NetworkModule.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/src/main/java/app/lounge/di/NetworkModule.kt b/modules/src/main/java/app/lounge/di/NetworkModule.kt index 485648920..63d354cf1 100644 --- a/modules/src/main/java/app/lounge/di/NetworkModule.kt +++ b/modules/src/main/java/app/lounge/di/NetworkModule.kt @@ -88,7 +88,7 @@ internal object NetworkModule { @Provides @Singleton - fun provideNetworkFetching( + fun provideAnonymousUser( @Named("ECloudRetrofit") ecloud: Retrofit ) : AnonymousUser { return AnonymousUserRetrofitImpl( -- GitLab From 57611451366b4025d735f7098a0465780b6f798c Mon Sep 17 00:00:00 2001 From: Nishant Dande Date: Tue, 8 Aug 2023 09:16:01 +0530 Subject: [PATCH 19/19] Updated codebse as per review comment --- .../java/app/lounge/AnonymousUserAPITest.kt | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/modules/src/androidTest/java/app/lounge/AnonymousUserAPITest.kt b/modules/src/androidTest/java/app/lounge/AnonymousUserAPITest.kt index 020dade3d..494cf0c28 100644 --- a/modules/src/androidTest/java/app/lounge/AnonymousUserAPITest.kt +++ b/modules/src/androidTest/java/app/lounge/AnonymousUserAPITest.kt @@ -1,3 +1,21 @@ +/* + * Copyright MURENA SAS 2023 + * Apps Quickly and easily install Android apps onto your device! + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package app.lounge import app.lounge.model.AnonymousAuthDataRequestBody @@ -27,7 +45,7 @@ class AnonymousUserAPITest { ) when(response){ is NetworkResult.Success -> authData = response.data - else -> {} + is NetworkResult.Error -> { } } assert(authData is AuthData) { "Assert!! Success must return data" } -- GitLab