-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: saving application context even if activity context was placed #…
…447 Add request to status endpoint when init SDK. Check if previous init context is null when call init SDK. Replace all setApplicationContext SDK calls with new ones.
- Loading branch information
1 parent
ba3e140
commit fc0f441
Showing
17 changed files
with
177 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
...bile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/sdk/StatusRequester.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package org.prebid.mobile.rendering.sdk; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
import org.prebid.mobile.LogUtil; | ||
import org.prebid.mobile.PrebidMobile; | ||
import org.prebid.mobile.rendering.listeners.SdkInitializationListener; | ||
import org.prebid.mobile.rendering.networking.BaseNetworkTask; | ||
import org.prebid.mobile.rendering.networking.ResponseHandler; | ||
import org.prebid.mobile.rendering.networking.tracking.ServerConnection; | ||
|
||
public class StatusRequester { | ||
|
||
private static final String TAG = StatusRequester.class.getSimpleName(); | ||
|
||
public static void makeRequest(@Nullable SdkInitializationListener listener) { | ||
String url = PrebidMobile.getPrebidServerHost().getHostUrl(); | ||
if (url.contains("/openrtb2/auction")) { | ||
String statusUrl = url.replace("/openrtb2/auction", "/status"); | ||
ServerConnection.fireWithResult( | ||
statusUrl, | ||
getResponseHandler(listener) | ||
); | ||
} else if (url.isEmpty()) { | ||
onInitError("Please set host url (PrebidMobile.setPrebidServerHost) and only then run SDK initialization.", listener); | ||
} else { | ||
onInitError("Error, url doesn't contain /openrtb2/auction part", listener); | ||
} | ||
} | ||
|
||
private static ResponseHandler getResponseHandler(@Nullable SdkInitializationListener listener) { | ||
return new ResponseHandler() { | ||
@Override | ||
public void onResponse(BaseNetworkTask.GetUrlResult response) { | ||
if (response.statusCode == 200) { | ||
try { | ||
JSONObject responseJson = new JSONObject(response.responseString); | ||
JSONObject applicationJson = responseJson.optJSONObject("application"); | ||
if (applicationJson != null) { | ||
String status = applicationJson.optString("status"); | ||
if (status.equalsIgnoreCase("ok")) { | ||
onSuccess(); | ||
return; | ||
} | ||
} | ||
} catch (JSONException exception) { | ||
onInitError("JsonException: " + exception.getMessage(), listener); | ||
return; | ||
} | ||
} | ||
onInitError("Server status is not ok!", listener); | ||
} | ||
|
||
@Override | ||
public void onError( | ||
String msg, | ||
long responseTime | ||
) { | ||
onInitError("Exception: " + msg, listener); | ||
} | ||
|
||
@Override | ||
public void onErrorWithException( | ||
Exception exception, | ||
long responseTime | ||
) { | ||
onInitError("Exception: " + exception.getMessage(), listener); | ||
} | ||
}; | ||
} | ||
|
||
private static void onSuccess() { | ||
SdkInitializer.increaseTaskCount(); | ||
} | ||
|
||
private static void onInitError( | ||
@NonNull String message, | ||
@Nullable SdkInitializationListener listener | ||
) { | ||
LogUtil.error(TAG, message); | ||
if (listener != null) { | ||
listener.onSdkFailedToInit(new SdkInitializationListener.InitError(message)); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.