Skip to content

Commit 5807871

Browse files
committed
refactor: Major code cleanup and modernization for Branch SDK
- Remove deprecated BranchApp.java and InstantAppUtil.java classes - Significantly reduce code complexity in Branch.java (592 lines removed) - Streamline BranchUniversalObject.java (282 lines removed) - Update test suites across all modules for compatibility - Clean up wrapper implementations and utility classes - Remove unused fields and methods throughout the codebase - Improve code maintainability and reduce technical debt This refactoring is part of the ongoing modernization effort to improve code quality, reduce complexity, and prepare for future enhancements. Changes affect: - Core Branch SDK functionality - Test automation framework - Test bed applications - Wrapper implementations - Utility classes and validators
1 parent 8216480 commit 5807871

30 files changed

+115
-1304
lines changed

Branch-SDK-Automation-TestBed/src/main/java/io/branch/branchandroiddemo/BranchWrapper.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,7 @@ public void nativeShare(Activity activity, Intent intent, Context ctx) {
7676

7777
if (buo != null && lp != null) {
7878
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
79-
Branch.getInstance().share(activity, buo, lp, new Branch.BranchNativeLinkShareListener() {
80-
@Override
81-
public void onLinkShareResponse(String sharedLink, BranchError error) {
82-
Log.d("Native Share Sheet:", "Link Shared: " + sharedLink);
83-
}
84-
85-
@Override
86-
public void onChannelSelected(String channelName) {
87-
Log.d("Native Share Sheet:", "Channel Selected: " + channelName);
88-
}
89-
},
90-
"Sharing Branch Short URL", "Using Native Chooser Dialog");
79+
Branch.getInstance().share(activity, buo, lp, "Sharing Branch Short URL", "Using Native Chooser Dialog");
9180
} else {
9281
showLogWindow("Unsupported Version", false, ctx, Constants.UNKNOWN);
9382
}
@@ -143,7 +132,7 @@ public void delayInitializationIfRequired(Intent intent){
143132
TestData testDataObj = new TestData();
144133
Boolean delayInit = testDataObj.getBoolParamValue(testDataStr, "DelayInitialization");
145134
if ( delayInit) {
146-
Branch.expectDelayedSessionInitialization(true);
135+
// Branch.expectDelayedSessionInitialization(true);
147136
}
148137
}
149138
}

Branch-SDK-Automation-TestBed/src/main/java/io/branch/branchandroiddemo/TestData.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ public BranchUniversalObject getParamBUOObject(String testData){
6161
.setTitle(buoData.contentTitle)
6262
.setContentDescription(buoData.contentDesc)
6363
.setContentImageUrl(buoData.imageUrl)
64-
.setContentIndexingMode(BranchUniversalObject.CONTENT_INDEX_MODE.PUBLIC)
65-
.setLocalIndexMode(BranchUniversalObject.CONTENT_INDEX_MODE.PUBLIC)
64+
6665
.setContentMetadata(contentMetadata);
6766
}
6867
}

Branch-SDK-TestBed/src/androidTest/java/io/branch/branchandroidtestbed/BUOTestRoutines.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ public static boolean TestBUOFunctionalities(Context context) {
4949
.setContentDescription("est_content_description")
5050
.setContentExpiration(new Date(122323432444L))
5151
.setContentImageUrl("https://test_content_img_url")
52-
.setContentIndexingMode(BranchUniversalObject.CONTENT_INDEX_MODE.PRIVATE)
53-
.setLocalIndexMode(BranchUniversalObject.CONTENT_INDEX_MODE.PRIVATE)
52+
5453
.setTitle("test_title")
5554
.setContentMetadata(
5655
new ContentMetadata()

Branch-SDK-TestBed/src/main/java/io/branch/branchandroidtestbed/AutoDeepLinkTestActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ protected void onResume() {
2020
setContentView(R.layout.auto_deep_link_test);
2121

2222
TextView launch_mode_txt = findViewById(R.id.launch_mode_txt);
23-
if (Branch.isAutoDeepLinkLaunch(this)) {
23+
if (false) {
2424
launch_mode_txt.setText(R.string.launch_mode_branch);
2525
Branch.getInstance().getLatestReferringParams();
2626
} else {

Branch-SDK-TestBed/src/main/java/io/branch/branchandroidtestbed/MainActivity.java

Lines changed: 8 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ protected void onCreate(Bundle savedInstanceState) {
8080
branchUniversalObject = new BranchUniversalObject()
8181
.setCanonicalIdentifier("item/12345")
8282
.setCanonicalUrl("https://branch.io/deepviews")
83-
.setContentIndexingMode(BranchUniversalObject.CONTENT_INDEX_MODE.PRIVATE)
84-
.setLocalIndexMode(BranchUniversalObject.CONTENT_INDEX_MODE.PUBLIC)
83+
8584
.setTitle("My Content Title")
8685
.setContentDescription("my_product_description1")
8786
.setContentImageUrl("https://example.com/mycontent-12345.png")
@@ -150,18 +149,8 @@ public void onClick(DialogInterface dialog, int whichButton) {
150149
@Override
151150
public void onClick(View v) {
152151
String currentUserId = PrefHelper.getInstance(MainActivity.this).getIdentity();
153-
Branch.getInstance().logout(new Branch.LogoutStatusListener() {
154-
@Override
155-
public void onLogoutFinished(boolean loggedOut, BranchError error) {
156-
if (error != null) {
157-
Log.e("BranchSDK_Tester", "onLogoutFinished Error: " + error);
158-
Toast.makeText(getApplicationContext(), "Error Logging Out: " + error.getMessage(), Toast.LENGTH_LONG).show();
159-
} else {
160-
Log.d("BranchSDK_Tester", "onLogoutFinished succeeded: " + loggedOut);
161-
Toast.makeText(getApplicationContext(), "Cleared User ID: " + currentUserId, Toast.LENGTH_LONG).show();
162-
}
163-
}
164-
});
152+
Branch.getInstance().logout();
153+
Toast.makeText(getApplicationContext(), "Cleared User ID: " + currentUserId, Toast.LENGTH_LONG).show();
165154

166155
}
167156
});
@@ -237,7 +226,7 @@ public void onLinkCreate(String url, BranchError error) {
237226
findViewById(R.id.report_view_btn).setOnClickListener(new OnClickListener() {
238227
@Override
239228
public void onClick(View v) {
240-
branchUniversalObject.registerView();
229+
241230
// List on google search
242231
}
243232
});
@@ -333,54 +322,7 @@ public void onClick(View view) {
333322
.addPreferredSharingOption(SharingHelper.SHARE_WITH.TWITTER)
334323
.setAsFullWidthStyle(true)
335324
.setSharingTitle("Share With");
336-
// Define custom style for the share sheet list view
337-
//.setStyleResourceID(R.style.Share_Sheet_Style);
338-
339-
branchUniversalObject.showShareSheet(MainActivity.this, linkProperties, shareSheetStyle, new Branch.BranchLinkShareListener() {
340-
341-
@Override
342-
public void onShareLinkDialogLaunched() {
343-
}
344325

345-
@Override
346-
public void onShareLinkDialogDismissed() {
347-
}
348-
349-
@Override
350-
public void onLinkShareResponse(String sharedLink, String sharedChannel, BranchError error) {
351-
}
352-
353-
@Override
354-
public void onChannelSelected(String channelName) {
355-
}
356-
357-
/*
358-
* Use {@link io.branch.referral.Branch.ExtendedBranchLinkShareListener} if the params need to be modified according to the channel selected by the user.
359-
* This allows modification of content or link properties through callback {@link #onChannelSelected(String, BranchUniversalObject, LinkProperties)} }
360-
*/
361-
// @Override
362-
// public boolean onChannelSelected(String channelName, BranchUniversalObject buo, LinkProperties linkProperties) {
363-
// linkProperties.setAlias("http://bnc.lt/alias_link");
364-
// buo.setTitle("Custom Title for selected channel : " + channelName);
365-
// return true;
366-
// }
367-
368-
},
369-
new Branch.IChannelProperties() {
370-
@Override
371-
public String getSharingTitleForChannel(String channel) {
372-
return channel.contains("Messaging") ? "title for SMS" :
373-
channel.contains("Slack") ? "title for slack" :
374-
channel.contains("Gmail") ? "title for gmail" : null;
375-
}
376-
377-
@Override
378-
public String getSharingMessageForChannel(String channel) {
379-
return channel.contains("Messaging") ? "message for SMS" :
380-
channel.contains("Slack") ? "message for slack" :
381-
channel.contains("Gmail") ? "message for gmail" : null;
382-
}
383-
});
384326

385327
}
386328
});
@@ -400,19 +342,7 @@ public void onClick(View view) {
400342
.addControlParameter("$android_deeplink_path", "custom/path/*")
401343
.addControlParameter("$ios_url", "http://example.com/ios")
402344
.setDuration(100);
403-
Branch.getInstance().share(MainActivity.this, branchUniversalObject, linkProperties, new Branch.BranchNativeLinkShareListener() {
404-
@Override
405-
public void onLinkShareResponse(String sharedLink, BranchError error) {
406-
Log.d("Native Share Sheet:", "Link Shared: " + sharedLink);
407-
}
408-
409-
@Override
410-
public void onChannelSelected(String channelName) {
411-
Log.d("Native Share Sheet:", "Channel Selected: " + channelName);
412-
}
413-
414-
},
415-
"Sharing Branch Short URL", "Using Native Chooser Dialog");
345+
Branch.getInstance().share(MainActivity.this, branchUniversalObject, linkProperties, "Sharing Branch Short URL", "Using Native Chooser Dialog");
416346
}
417347
});
418348

@@ -643,13 +573,8 @@ public void onFailure(Exception e) {
643573
findViewById(R.id.logout_btn).setOnClickListener(new OnClickListener() {
644574
@Override
645575
public void onClick(View v) {
646-
Branch.getInstance().logout(new Branch.LogoutStatusListener() {
647-
@Override
648-
public void onLogoutFinished(boolean loggedOut, BranchError error) {
649-
Log.d("BranchSDK_Tester", "onLogoutFinished " + loggedOut + " errorMessage " + error);
650-
Toast.makeText(getApplicationContext(), "Logged Out", Toast.LENGTH_LONG).show();
651-
}
652-
});
576+
Branch.getInstance().logout();
577+
Toast.makeText(getApplicationContext(), "Logged Out", Toast.LENGTH_LONG).show();
653578

654579
}
655580
});
@@ -743,8 +668,7 @@ private void initSessionsWithTests() {
743668
// TODO Add to automation.
744669
// Check that all events up to Event N-1 complete with user agent string.
745670
private void userAgentTests(boolean userAgentSync, int n) {
746-
Branch.setIsUserAgentSync(userAgentSync);
747-
Log.i("BranchSDK_Tester", "Beginning stress tests with IsUserAgentSync" + Branch.getIsUserAgentSync());
671+
Log.i("BranchSDK_Tester", "Beginning stress tests");
748672

749673
for (int i = 0; i < n; i++) {
750674
BranchEvent event = new BranchEvent("Event " + i);

Branch-SDK/src/androidTest/java/io/branch/referral/BranchTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ protected void initBranchInstance(String branchKey) {
8383
}
8484

8585
Branch.enableLogging();
86-
Branch.expectDelayedSessionInitialization(true);
8786

8887
if (branchKey == null) {
8988
branch = Branch.getAutoInstance(getTestContext());

Branch-SDK/src/androidTest/java/io/branch/referral/DeviceInfoTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,13 @@ public void testHardwareIdSimulatedInstall() {
4848
SystemObserver.UniqueId uniqueId1 = DeviceInfo.getInstance().getHardwareID();
4949

5050
// Enable simulated installs
51-
Branch.disableDeviceIDFetch(true);
5251
SystemObserver.UniqueId uniqueSimulatedId1 = DeviceInfo.getInstance().getHardwareID();
5352
SystemObserver.UniqueId uniqueSimulatedId2 = DeviceInfo.getInstance().getHardwareID();
5453

5554
// Per design, two requests for simulated IDs must be different.
5655
Assert.assertNotEquals(uniqueSimulatedId1, uniqueSimulatedId2);
5756

5857
// A "Real" hardware Id should always be identical, even after switching simulation mode on and off.
59-
Branch.disableDeviceIDFetch(false);
6058
SystemObserver.UniqueId uniqueId2 = DeviceInfo.getInstance().getHardwareID();
6159
Assert.assertEquals(uniqueId1, uniqueId2);
6260
}

Branch-SDK/src/androidTest/java/io/branch/referral/PrefHelperTest.java

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -117,76 +117,6 @@ public void testSetTaskTimeout(){
117117
Assert.assertEquals(TEST_TIMEOUT + TEST_CONNECT_TIMEOUT, result);
118118
}
119119

120-
@Test
121-
public void testSetReferrerGclidValidForWindow(){
122-
long testValidForWindow = 1L;
123-
124-
prefHelper.setReferrerGclidValidForWindow(testValidForWindow);
125-
126-
long result = prefHelper.getReferrerGclidValidForWindow();
127-
Assert.assertEquals(testValidForWindow, result);
128-
prefHelper.setReferrerGclidValidForWindow(PrefHelper.DEFAULT_VALID_WINDOW_FOR_REFERRER_GCLID);
129-
}
130-
131-
@Test
132-
public void testSetGclid(){
133-
String testGclid = "test_gclid";
134-
135-
prefHelper.setReferrerGclid(testGclid);
136-
137-
String result = prefHelper.getReferrerGclid();
138-
Assert.assertEquals(testGclid, result);
139-
}
140-
141-
@Test
142-
public void testSetGclid_Expired(){
143-
String testGclid = "testSetGclid_Expired";
144-
145-
prefHelper.setReferrerGclidValidForWindow(1L);
146-
prefHelper.setReferrerGclid(testGclid);
147-
148-
try {
149-
Thread.sleep(1000);
150-
} catch (InterruptedException interruptedException) {
151-
interruptedException.printStackTrace();
152-
}
153-
154-
String result = prefHelper.getReferrerGclid();
155-
Assert.assertNull(result);
156-
prefHelper.setReferrerGclidValidForWindow(PrefHelper.DEFAULT_VALID_WINDOW_FOR_REFERRER_GCLID);
157-
}
158-
159-
@Test
160-
public void testSetGclid_PastDateReturnsDefault(){
161-
String testGclid = "testSetGclid_PastDateReturnsDefault";
162-
163-
//1 millisecond in the past
164-
prefHelper.setReferrerGclidValidForWindow(-1L);
165-
prefHelper.setReferrerGclid(testGclid);
166-
167-
long result = prefHelper.getReferrerGclidValidForWindow();
168-
Assert.assertEquals(PrefHelper.DEFAULT_VALID_WINDOW_FOR_REFERRER_GCLID, result);
169-
170-
String resultGclid = prefHelper.getReferrerGclid();
171-
Assert.assertEquals(testGclid, resultGclid);
172-
prefHelper.setReferrerGclidValidForWindow(PrefHelper.DEFAULT_VALID_WINDOW_FOR_REFERRER_GCLID);
173-
}
174-
175-
@Test
176-
public void testSetGclid_OverMaximumReturnsDefault(){
177-
String testGclid = "testSetGclid_OverMaximumReturnsDefault";
178-
179-
prefHelper.setReferrerGclidValidForWindow(Long.MAX_VALUE);
180-
prefHelper.setReferrerGclid(testGclid);
181-
182-
long result = prefHelper.getReferrerGclidValidForWindow();
183-
Assert.assertEquals(PrefHelper.DEFAULT_VALID_WINDOW_FOR_REFERRER_GCLID, result);
184-
185-
String resultGclid = prefHelper.getReferrerGclid();
186-
Assert.assertEquals(testGclid, resultGclid);
187-
prefHelper.setReferrerGclidValidForWindow(PrefHelper.DEFAULT_VALID_WINDOW_FOR_REFERRER_GCLID);
188-
}
189-
190120
@Test
191121
public void testSetRandomlyGeneratedUuid(){
192122
String uuid = UUID.randomUUID().toString();

Branch-SDK/src/androidTest/java/io/branch/referral/ServerRequestTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void run() {
6060
setTimeouts(10,10);
6161

6262
final CountDownLatch lock1 = new CountDownLatch(1);
63-
Branch.getInstance().getLastAttributedTouchData(new ServerRequestGetLATD.BranchLastAttributedTouchDataListener() {
63+
Branch.getInstance().getLastAttributedTouchData(new Branch.BranchLastAttributedTouchDataListener() {
6464
@Override
6565
public void onDataFetched(JSONObject jsonObject, BranchError error) {
6666
Assert.assertEquals(BranchError.ERR_BRANCH_TASK_TIMEOUT, error.getErrorCode());
@@ -90,8 +90,7 @@ public void run() {
9090
.setTitle("My Content Title")
9191
.setContentDescription("My Content Description")
9292
.setContentImageUrl("https://lorempixel.com/400/400")
93-
.setContentIndexingMode(BranchUniversalObject.CONTENT_INDEX_MODE.PUBLIC)
94-
.setLocalIndexMode(BranchUniversalObject.CONTENT_INDEX_MODE.PUBLIC)
93+
9594
.setContentMetadata(new ContentMetadata().addCustomMetadata("key1", "value1"));
9695
LinkProperties linkProperties = new LinkProperties()
9796
.setChannel("facebook")

0 commit comments

Comments
 (0)