Skip to content

Commit dc040df

Browse files
author
Ali Abdelfattah
authored
Merge pull request #635 from Instabug/feature/end-app-launch
[MOB-6471] Add APM.endAppLaunch API
2 parents 39e7d28 + 58d552a commit dc040df

File tree

10 files changed

+64
-0
lines changed

10 files changed

+64
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## master
2+
* Adds APM.endAppLaunch API
3+
14
## 10.9.1 (2021-10-13)
25

36
* Bumps Instabug Android SDK to v10.9.1

InstabugSample/ios/InstabugSampleTests/InstabugAPMTests.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ - (void) testSetAppLaunchEnabled {
7777
OCMVerify([mock setAppLaunchEnabled:isEnabled]);
7878
}
7979

80+
- (void) testEndAppLaunch {
81+
id mock = OCMClassMock([IBGAPM class]);
82+
83+
OCMStub([mock endAppLaunch]);
84+
[self.instabugBridge endAppLaunch];
85+
OCMVerify([mock endAppLaunch]);
86+
}
87+
8088
- (void) testSetAutoUITraceEnabled {
8189
id mock = OCMClassMock([IBGAPM class]);
8290
BOOL isEnabled = YES;

__tests__/apm.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ describe("APM Module", () => {
2121
const endExecutionTrace = sinon.spy(NativeModules.IBGAPM, "endExecutionTrace");
2222
const startUITrace = sinon.spy(NativeModules.IBGAPM, "startUITrace");
2323
const endUITrace = sinon.spy(NativeModules.IBGAPM, "endUITrace");
24+
const endAppLaunch = sinon.spy(NativeModules.IBGAPM, "endAppLaunch");
2425

2526
beforeEach(() => {
2627
IBGEventEmitter.removeAllListeners();
@@ -38,6 +39,12 @@ describe("APM Module", () => {
3839
expect(setAppLaunchEnabled.calledOnceWithExactly(true)).toBe(true);
3940
});
4041

42+
it("should call the native method endAppLaunch", () => {
43+
APM.endAppLaunch();
44+
45+
expect(endAppLaunch.calledOnceWithExactly()).toBe(true);
46+
});
47+
4148
it("should call the native method setAutoUITraceEnabled", () => {
4249
APM.setAutoUITraceEnabled(true);
4350

android/src/main/java/com/instabug/reactlibrary/RNInstabugAPMModule.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,23 @@ public void run() {
107107
});
108108
}
109109

110+
/**
111+
* Ends app launch
112+
*/
113+
@ReactMethod
114+
public void endAppLaunch() {
115+
MainThreadHandler.runOnMainThread(new Runnable() {
116+
@Override
117+
public void run() {
118+
try {
119+
APM.endAppLaunch();
120+
} catch (Exception e) {
121+
e.printStackTrace();
122+
}
123+
}
124+
});
125+
}
126+
110127
/**
111128
* Enables or disables auto UI tracing
112129
* @param isEnabled boolean indicating enabled or disabled.

android/src/test/java/com/instabug/reactlibrary/RNInstabugAPMModuleTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@ public void givenTruesetEnabled_whenQuery_thenShouldCallNativeApiWithEnabled() {
104104
APM.setAppLaunchEnabled(true);
105105
}
106106

107+
@Test
108+
public void given$endAppLaunch_whenQuery_thenShouldCallNativeApiWithEnabled() {
109+
// given
110+
PowerMockito.mockStatic(APM.class);
111+
// when
112+
apmModule.endAppLaunch();
113+
// then
114+
PowerMockito.verifyStatic(VerificationModeFactory.times(1));
115+
APM.endAppLaunch();
116+
}
117+
107118
@Test
108119
public void givenString$startExecutionTrace_whenQuery_thenShouldCallNativeApi() {
109120

index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,11 @@ export namespace APM {
557557
* @param {boolean} isEnabled
558558
*/
559559
function setAppLaunchEnabled(isEnabled: boolean): void;
560+
/**
561+
* Ends the current session’s App Launch. Calling this API is optional, App Launches will still be captured and ended automatically by the SDK;
562+
* this API just allows you to change when an App Launch actually ends.
563+
*/
564+
function endAppLaunch(): void;
560565
/**
561566
* Enables or disables APM Network Metric
562567
* @param {boolean} isEnabled

ios/RNInstabug/InstabugAPMBridge.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- (void)setLogLevel:(IBGLogLevel)_logLevel;
1515
- (void)setEnabled:(BOOL)isEnabled;
1616
- (void)setAppLaunchEnabled:(BOOL)isEnabled;
17+
- (void)endAppLaunch;
1718
- (void)setAutoUITraceEnabled:(BOOL)isEnabled;
1819
- (void)startExecutionTrace:(NSString *)name:(NSString *)id
1920
:(RCTResponseSenderBlock)callBack;

ios/RNInstabug/InstabugAPMBridge.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ - (id) init
5858
IBGAPM.appLaunchEnabled = isEnabled;
5959
}
6060

61+
RCT_EXPORT_METHOD(endAppLaunch) {
62+
[IBGAPM endAppLaunch];
63+
}
64+
6165
RCT_EXPORT_METHOD(setAutoUITraceEnabled:(BOOL)isEnabled) {
6266
IBGAPM.autoUITraceEnabled = isEnabled;
6367
}

jest/mockAPM.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ jest.mock("NativeModules", () => {
1010
endExecutionTrace: jest.fn(),
1111
startUITrace: jest.fn(),
1212
endUITrace: jest.fn(),
13+
endAppLaunch: jest.fn(),
1314
},
1415
Instabug: {},
1516
};

modules/APM.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ export default {
5555
IBGAPM.setAppLaunchEnabled(isEnabled);
5656
},
5757

58+
/**
59+
* Ends app launch
60+
*/
61+
endAppLaunch() {
62+
IBGAPM.endAppLaunch();
63+
},
64+
5865
/**
5966
* Enables or disables APM Network Metric
6067
* @param {boolean} isEnabled

0 commit comments

Comments
 (0)