Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
1b0c98d
EMT-1963 Add BranchConfigurationController to manage SDK configuratio…
wpinho-branch Jun 6, 2025
a464915
Add coroutines-based request queue implementation and adapter for bac…
wpinho-branch Jun 12, 2025
aef77d0
Complete Phase 2 integration of coroutines-based queue system
wpinho-branch Jun 12, 2025
73b2828
Implement complete compatibility for BranchRequestQueue with ServerRe…
wpinho-branch Jun 12, 2025
e4cae64
Refactor BranchRequestQueue for improved performance and compatibility
wpinho-branch Jun 12, 2025
489617e
Add BranchMigrationTest for comprehensive queue testing
wpinho-branch Jun 12, 2025
eae4847
Enhance BranchMigrationTest and refactor BranchRequestQueue components
wpinho-branch Jun 12, 2025
7b39aa2
Refactor BranchMigrationTest to enhance request handling and prioriti…
wpinho-branch Jun 12, 2025
addecbe
Update BranchMigrationTest to improve request action handling
wpinho-branch Jun 12, 2025
bf63af2
GPTDriver Integration (#1275)
gdeluna-branch Jun 16, 2025
6e9441c
Release 5.18.2 (#1279)
gdeluna-branch Jun 17, 2025
3caf036
INTENG-22685 - Integration validator protected endpoint bugfix (#1269)
rob-gioia-branch Jun 17, 2025
e8d6933
Implement StateFlow-based session state management in Branch SDK
wpinho-branch Jun 17, 2025
3214341
Add StateFlow-based session state management documentation
wpinho-branch Jun 17, 2025
c0dc682
Refactor session state management in Branch SDK to utilize StateFlow
wpinho-branch Jun 17, 2025
37c237f
WIP: Add unit tests for session state management in Branch SDK
wpinho-branch Jun 20, 2025
3a5a50b
Add manual unlock method (#1281)
gdeluna-branch Jun 23, 2025
3d096cf
Release 5.19.0 (#1282)
gdeluna-branch Jun 24, 2025
b68bf86
Add modernization components for Branch SDK API preservation
wpinho-branch Jun 27, 2025
9fe12ef
Remove ApiFilterConfig.kt file
wpinho-branch Jun 30, 2025
74ef3b8
Add migration guide and implementation summary for Branch SDK moderni…
wpinho-branch Jun 30, 2025
05a89a3
Add version configuration and timeline documentation for Branch SDK
wpinho-branch Jun 30, 2025
0b0aa97
feat: Add comprehensive Migration Master Plan documentation
wpinho-branch Jun 30, 2025
e487c1e
refactor: Reorganize documentation structure with improved categoriza…
wpinho-branch Jun 30, 2025
c521be9
build: Update build configuration for modernization components
wpinho-branch Jul 7, 2025
840fe15
refactor: Enhance ModernBranchCore with improved error handling and l…
wpinho-branch Jul 7, 2025
8eec999
feat: Enhance wrapper implementations with improved API preservation
wpinho-branch Jul 7, 2025
6e0b8c8
test: Improve session management test coverage and reliability
wpinho-branch Jul 7, 2025
8216480
test: Add comprehensive test suite for modernization framework
wpinho-branch Jul 7, 2025
5807871
refactor: Major code cleanup and modernization for Branch SDK
wpinho-branch Jul 8, 2025
4e1d2c9
feat: remove getAutoInstance() method and simplify Branch singleton p…
wpinho-branch Jul 8, 2025
02b3710
docs: update migration documentation to reflect getAutoInstance removal
wpinho-branch Jul 8, 2025
902abfc
fix: update validator error messages to reference getInstance() method
wpinho-branch Jul 8, 2025
ac0bd1d
refactor: clean up modernization components and remove unused callbacks
wpinho-branch Jul 8, 2025
c64d5a0
test: update test applications and test cases for singleton pattern c…
wpinho-branch Jul 8, 2025
c85920f
refactor: clean up deprecated API registrations and unused callback a…
wpinho-branch Jul 8, 2025
d0c7c5e
test: update test suites to reflect modernization cleanup changes
wpinho-branch Jul 8, 2025
2d1f83d
refactor: remove deprecated methods and cleanup callback references
wpinho-branch Jul 8, 2025
48b1516
feat: add getInstance(Context) method to Branch class
wpinho-branch Jul 8, 2025
7658eee
fix: update CustomBranchApp to use getInstance(Context) method
wpinho-branch Jul 8, 2025
d1cabe3
refactor: remove deprecated delay initialization check in BranchWrapper
wpinho-branch Jul 8, 2025
8184777
refactor: simplify user agent processing in DeviceInfo
wpinho-branch Jul 15, 2025
f69fed6
refactor: remove processNextQueueItem method and related calls for au…
wpinho-branch Jul 15, 2025
c22fcd0
refactor: update Branch SDK initialization to use init() method
wpinho-branch Jul 24, 2025
90452c2
feat: restore interfaces and methods
wpinho-branch Jul 24, 2025
7b6d39f
eliminate comments and references to the processNextQueueItem method …
wpinho-branch Jul 24, 2025
f2342c1
refactor: remove unnecessary debug comments in BranchUniversalObject
wpinho-branch Jul 24, 2025
08ecbcf
refactor: remove indexMode from BranchUniversalObject
wpinho-branch Jul 24, 2025
790d8b3
feat: log VIEW_ITEM event in MainActivity
wpinho-branch Jul 24, 2025
49f3a49
omitted this for now to avoid questions
wpinho-branch Jul 24, 2025
42e4353
ensure getAutoInstance apply on init and restore NativeShareLinkManager
wpinho-branch Jul 24, 2025
3ae3ebb
refactor: remove unused code in Branch class
wpinho-branch Jul 24, 2025
26e0e57
refactor: simplify intent state check in Branch class
wpinho-branch Jul 24, 2025
8cd6de8
fix: restore sharing functionality in Branch SDK
wpinho-branch Jul 24, 2025
6631223
feat: enhance session management and request queue handling
wpinho-branch Jul 30, 2025
c9b227c
refactor: improve memory management and session handling in BranchReq…
wpinho-branch Jul 30, 2025
22e62fe
Merge branch 'master' into wpinho-branch/EMT-2260
wpinho-branch Jul 31, 2025
cfd250f
refactor: update Branch SDK to use init() method for instance retrieval
wpinho-branch Jul 31, 2025
6e85554
feat: introduce ModernLinkGenerator for improved link generation
wpinho-branch Aug 8, 2025
aacf9d6
refactor: clean up imports in ModernLinkGenerator
wpinho-branch Aug 8, 2025
dcdef48
refactor: streamline link data retrieval in ModernLinkGenerator
wpinho-branch Aug 8, 2025
4920cc9
refactor: update Branch SDK to use getInstance() for instance retrieval
wpinho-branch Aug 11, 2025
2b6976c
Merge branch 'wpinho-branch/EMT-2260' into wpinho-branch/EMT-2274
wpinho-branch Aug 11, 2025
9933734
feat: add legacy link generator for backward compatibility
wpinho-branch Aug 20, 2025
2d0db8a
Merge branch '6.0.0.alpha.0' into wpinho-branch/EMT-2274
wpinho-branch Aug 21, 2025
939380e
refactor: clean up unused imports in Branch class
wpinho-branch Aug 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 79 additions & 26 deletions Branch-SDK/src/main/java/io/branch/referral/Branch.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,10 @@
import org.json.JSONObject;

import java.lang.ref.WeakReference;
import java.net.HttpURLConnection;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import io.branch.indexing.BranchUniversalObject;
import io.branch.interfaces.IBranchLoggingCallbacks;
Expand All @@ -52,6 +48,7 @@
import io.branch.referral.util.DependencyUtilsKt;
import io.branch.referral.util.LinkProperties;


/**
* <p>
* The core object required when using Branch SDK. You should declare an object of this type at
Expand Down Expand Up @@ -226,6 +223,12 @@ public class Branch {

final ConcurrentHashMap<BranchLinkData, String> linkCache_ = new ConcurrentHashMap<>();

/* Modern link generator to replace deprecated AsyncTask pattern */
private ModernLinkGenerator modernLinkGenerator_;

/* Legacy link generator for fallback compatibility */
private BranchLegacyLinkGenerator legacyLinkGenerator_;

/* Set to true when {@link Activity} life cycle callbacks are registered. */
private static boolean isActivityLifeCycleCallbackRegistered_ = false;
private CustomTabsIntent customTabsIntentOverride;
Expand Down Expand Up @@ -336,6 +339,18 @@ private Branch(@NonNull Context context) {
BranchLogger.d("DEBUG: Branch constructor - initializing request queue");
requestQueue_.initialize();
BranchLogger.d("DEBUG: Branch constructor - request queue initialized");

// Initialize modern link generator with default parameters
modernLinkGenerator_ = new ModernLinkGenerator(
context,
branchRemoteInterface_,
prefHelper_
);
BranchLogger.d("DEBUG: Branch constructor - modern link generator initialized");

// Initialize legacy link generator for fallback compatibility
legacyLinkGenerator_ = new BranchLegacyLinkGenerator(prefHelper_, branchRemoteInterface_);
BranchLogger.d("DEBUG: Branch constructor - legacy link generator initialized");
}

/**
Expand Down Expand Up @@ -553,6 +568,13 @@ public boolean isTrackingDisabled() {
// Package Private
// For Unit Testing, we need to reset the Branch state
static void shutDown() {
// Shutdown modern link generator before other components
if (branchReferral_ != null && branchReferral_.modernLinkGenerator_ != null) {
branchReferral_.modernLinkGenerator_.shutdown();
}

// Legacy link generator doesn't need explicit shutdown (no coroutines)

BranchRequestQueueAdapter.shutDown();
BranchRequestQueue.shutDown();
PrefHelper.shutDown();
Expand Down Expand Up @@ -1168,7 +1190,13 @@ String generateShortLinkInternal(ServerRequestCreateUrl req) {
return url;
}
if (req.isAsync()) {
requestQueue_.handleNewRequest(req);
// Use modern link generator for async requests when available
if (modernLinkGenerator_ != null) {
modernLinkGenerator_.generateShortLinkAsyncFromJava(req.getLinkPost(), req.getCallback());
} else {
// Fallback to request queue for backward compatibility
requestQueue_.handleNewRequest(req);
}
} else {
return generateShortLinkSync(req);
}
Expand Down Expand Up @@ -1202,29 +1230,54 @@ public void share(@NonNull Activity activity, @NonNull BranchUniversalObject buo

// PRIVATE FUNCTIONS

/**
* Generate short link synchronously using modern and legacy fallback strategies.
*
* This method serves as a facade for link generation, coordinating between the modern
* coroutine-based approach and legacy fallback implementations to ensure maximum
* compatibility and reliability.
*
* <h3>Generation Strategy</h3>
* <ol>
* <li><strong>Primary</strong>: Modern coroutine-based generation via {@link ModernLinkGenerator}</li>
* <li><strong>Fallback</strong>: Legacy AsyncTask-based generation via {@link BranchLegacyLinkGenerator}</li>
* <li><strong>Final</strong>: Return long URL if configured, or null</li>
* </ol>
*
* <h3>Error Handling</h3>
* <ul>
* <li>Network failures automatically trigger fallback to next strategy</li>
* <li>Timeout exceptions are handled gracefully with appropriate logging</li>
* <li>JSON parsing errors result in fallback behavior</li>
* <li>All exceptions are logged for debugging purposes</li>
* </ul>
*
* <h3>Caching</h3>
* Generated URLs are cached using the {@code linkCache_} to improve performance
* for repeated requests with identical parameters.
*
* @param req The server request containing link generation parameters
* @return Generated short URL, fallback long URL, or null on complete failure
* @since 5.3.0 (refactored to use facade pattern)
* @see ModernLinkGenerator#generateShortLinkSyncFromJava
* @see BranchLegacyLinkGenerator#generateShortLinkSyncLegacy
*/
private String generateShortLinkSync(ServerRequestCreateUrl req) {
ServerResponse response = null;
try {
int timeOut = prefHelper_.getTimeout() + 2000; // Time out is set to slightly more than link creation time to prevent any edge case
response = new GetShortLinkTask().execute(req).get(timeOut, TimeUnit.MILLISECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
BranchLogger.d(e.getMessage());
}
String url = null;
if (req.isDefaultToLongUrl()) {
url = req.getLongUrl();
}
if (response != null && response.getStatusCode() == HttpURLConnection.HTTP_OK) {
try {
url = response.getObject().getString("url");
if (req.getLinkPost() != null) {
linkCache_.put(req.getLinkPost(), url);
}
} catch (JSONException e) {
e.printStackTrace();
}
// Use modern link generator with existing Java-compatible method
if (modernLinkGenerator_ != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we're making changes to implementation, can you move this logic outside of Branch.java to ModernLinkGenerator.kt. Ideally these public functions are just facades for utility classes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjusted: 9933734

return modernLinkGenerator_.generateShortLinkSyncFromJava(
req.getLinkPost(),
req.isDefaultToLongUrl(),
req.getLongUrl(),
prefHelper_.getTimeout()
);
} else if (legacyLinkGenerator_ != null) {
// Fallback to dedicated legacy implementation
return legacyLinkGenerator_.generateShortLinkSyncLegacy(req, linkCache_);
} else {
// Final fallback - return long URL if configured
return req.isDefaultToLongUrl() ? req.getLongUrl() : null;
}
return url;
}

private JSONObject convertParamsStringToDictionary(String paramString) {
Expand Down
Loading