Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 03ba1ed

Browse files
committed
CodePushStatusReport -> CodePushTelemetryManager
1 parent 0500545 commit 03ba1ed

File tree

7 files changed

+87
-95
lines changed

7 files changed

+87
-95
lines changed

CodePush.h

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,11 @@ failCallback:(void (^)(NSError *err))failCallback;
8888

8989
@end
9090

91-
@interface CodePushStatusReport : NSObject
92-
93-
+ (NSString *)getDeploymentKeyFromStatusReportIdentifier:(NSString *)statusReportIdentifier;
94-
+ (NSDictionary *)getFailedUpdateStatusReport:(NSDictionary *)lastFailedPackage;
95-
+ (NSDictionary *)getNewPackageStatusReport:(NSDictionary *)currentPackage;
96-
+ (NSDictionary *)getNewAppVersionStatusReport:(NSString *)appVersion;
97-
+ (NSString *)getPackageStatusReportIdentifier:(NSDictionary *)package;
98-
+ (NSString *)getPreviousStatusReportIdentifier;
99-
+ (NSString *)getVersionLabelFromStatusReportIdentifier:(NSString *)statusReportIdentifier;
100-
+ (BOOL)isStatusReportIdentifierCodePushLabel:(NSString *)statusReportIdentifier;
101-
+ (void)recordDeploymentStatusReported:(NSString *)appVersionOrPackageIdentifier;
91+
@interface CodePushTelemetryManager : NSObject
92+
93+
+ (NSDictionary *)getBinaryUpdateReport:(NSString *)appVersion;
94+
+ (NSDictionary *)getUpdateReport:(NSDictionary *)currentPackage;
95+
+ (NSDictionary *)getRollbackReport:(NSDictionary *)lastFailedPackage;
10296

10397
@end
10498

CodePush.m

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -504,29 +504,27 @@ - (void)savePendingUpdate:(NSString *)packageHash
504504
rejecter:(RCTPromiseRejectBlock)reject)
505505
{
506506
if (needToReportRollback) {
507-
// Check if there was a rollback that was not yet reported
508507
needToReportRollback = NO;
509508
NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
510509
NSMutableArray *failedUpdates = [preferences objectForKey:FailedUpdatesKey];
511510
if (failedUpdates) {
512511
NSDictionary *lastFailedPackage = [failedUpdates lastObject];
513512
if (lastFailedPackage) {
514-
resolve([CodePushStatusReport getFailedUpdateStatusReport:lastFailedPackage]);
513+
resolve([CodePushTelemetryManager getRollbackReport:lastFailedPackage]);
515514
return;
516515
}
517516
}
518517
} else if (_isFirstRunAfterUpdate) {
519-
// Check if the current CodePush package has been reported
520518
NSError *error;
521519
NSDictionary *currentPackage = [CodePushPackage getCurrentPackage:&error];
522520
if (!error && currentPackage) {
523-
resolve([CodePushStatusReport getNewPackageStatusReport:currentPackage]);
521+
resolve([CodePushTelemetryManager getUpdateReport:currentPackage]);
524522
return;
525523
}
526524
} else if (isRunningBinaryVersion || [_bridge.bundleURL.scheme hasPrefix:@"http"]) {
527525
// Check if the current appVersion has been reported.
528526
NSString *appVersion = [[CodePushConfig current] appVersion];
529-
resolve([CodePushStatusReport getNewAppVersionStatusReport:appVersion]);
527+
resolve([CodePushTelemetryManager getBinaryUpdateReport:appVersion]);
530528
return;
531529
}
532530

CodePush.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/* Begin PBXBuildFile section */
1010
13BE3DEE1AC21097009241FE /* CodePush.m in Sources */ = {isa = PBXBuildFile; fileRef = 13BE3DED1AC21097009241FE /* CodePush.m */; };
1111
1B23B9141BF9267B000BB2F0 /* RCTConvert+CodePushInstallMode.m in Sources */ = {isa = PBXBuildFile; fileRef = 1B23B9131BF9267B000BB2F0 /* RCTConvert+CodePushInstallMode.m */; };
12-
5421FE311C58AD5A00986A55 /* CodePushStatusReport.m in Sources */ = {isa = PBXBuildFile; fileRef = 5421FE301C58AD5A00986A55 /* CodePushStatusReport.m */; };
12+
5421FE311C58AD5A00986A55 /* CodePushTelemetryManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 5421FE301C58AD5A00986A55 /* CodePushTelemetryManager.m */; };
1313
54A0026C1C0E2880004C3CEC /* aescrypt.c in Sources */ = {isa = PBXBuildFile; fileRef = 54A0024C1C0E2880004C3CEC /* aescrypt.c */; };
1414
54A0026D1C0E2880004C3CEC /* aeskey.c in Sources */ = {isa = PBXBuildFile; fileRef = 54A0024D1C0E2880004C3CEC /* aeskey.c */; };
1515
54A0026E1C0E2880004C3CEC /* aestab.c in Sources */ = {isa = PBXBuildFile; fileRef = 54A0024F1C0E2880004C3CEC /* aestab.c */; };
@@ -46,7 +46,7 @@
4646
13BE3DEC1AC21097009241FE /* CodePush.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CodePush.h; sourceTree = "<group>"; };
4747
13BE3DED1AC21097009241FE /* CodePush.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CodePush.m; sourceTree = "<group>"; };
4848
1B23B9131BF9267B000BB2F0 /* RCTConvert+CodePushInstallMode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RCTConvert+CodePushInstallMode.m"; sourceTree = "<group>"; };
49-
5421FE301C58AD5A00986A55 /* CodePushStatusReport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CodePushStatusReport.m; sourceTree = "<group>"; };
49+
5421FE301C58AD5A00986A55 /* CodePushTelemetryManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CodePushTelemetryManager.m; sourceTree = "<group>"; };
5050
54A0024A1C0E2880004C3CEC /* aes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = aes.h; sourceTree = "<group>"; };
5151
54A0024B1C0E2880004C3CEC /* aes_via_ace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = aes_via_ace.h; sourceTree = "<group>"; };
5252
54A0024C1C0E2880004C3CEC /* aescrypt.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = aescrypt.c; sourceTree = "<group>"; };
@@ -167,7 +167,7 @@
167167
1B23B9131BF9267B000BB2F0 /* RCTConvert+CodePushInstallMode.m */,
168168
54FFEDDF1BF550630061DD23 /* CodePushDownloadHandler.m */,
169169
810D4E6C1B96935000B397E9 /* CodePushPackage.m */,
170-
5421FE301C58AD5A00986A55 /* CodePushStatusReport.m */,
170+
5421FE301C58AD5A00986A55 /* CodePushTelemetryManager.m */,
171171
81D51F391B6181C2000DA084 /* CodePushConfig.m */,
172172
13BE3DEC1AC21097009241FE /* CodePush.h */,
173173
13BE3DED1AC21097009241FE /* CodePush.m */,
@@ -242,7 +242,7 @@
242242
54FFEDE01BF550630061DD23 /* CodePushDownloadHandler.m in Sources */,
243243
54A002711C0E2880004C3CEC /* hmac.c in Sources */,
244244
54A002721C0E2880004C3CEC /* prng.c in Sources */,
245-
5421FE311C58AD5A00986A55 /* CodePushStatusReport.m in Sources */,
245+
5421FE311C58AD5A00986A55 /* CodePushTelemetryManager.m in Sources */,
246246
54A002731C0E2880004C3CEC /* pwd2key.c in Sources */,
247247
54A002751C0E2880004C3CEC /* ioapi.c in Sources */,
248248
54A002771C0E2880004C3CEC /* unzip.c in Sources */,

CodePushStatusReport.m renamed to CodePushTelemetryManager.m

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,45 @@
66
static NSString *const LabelKey = @"label";
77
static NSString *const LastDeploymentReportKey = @"CODE_PUSH_LAST_DEPLOYMENT_REPORT";
88

9-
@implementation CodePushStatusReport
9+
@implementation CodePushTelemetryManager
1010

11-
+ (NSString *)getDeploymentKeyFromStatusReportIdentifier:(NSString *)statusReportIdentifier
11+
+ (NSDictionary *)getBinaryUpdateReport:(NSString *)appVersion
1212
{
13-
return [[statusReportIdentifier componentsSeparatedByString:@":"] firstObject];
13+
NSString *previousStatusReportIdentifier = [self getPreviousStatusReportIdentifier];
14+
if (previousStatusReportIdentifier == nil) {
15+
[self recordDeploymentStatusReported:appVersion];
16+
return @{ @"appVersion": appVersion };
17+
} else if (![previousStatusReportIdentifier isEqualToString:appVersion]) {
18+
[self recordDeploymentStatusReported:appVersion];
19+
if ([self isStatusReportIdentifierCodePushLabel:previousStatusReportIdentifier]) {
20+
NSString *previousDeploymentKey = [self getDeploymentKeyFromStatusReportIdentifier:previousStatusReportIdentifier];
21+
NSString *previousLabel = [self getVersionLabelFromStatusReportIdentifier:previousStatusReportIdentifier];
22+
return @{
23+
@"appVersion": appVersion,
24+
@"previousDeploymentKey": previousDeploymentKey,
25+
@"previousLabelOrAppVersion": previousLabel
26+
};
27+
} else {
28+
// Previous status report was with a binary app version.
29+
return @{
30+
@"appVersion": appVersion,
31+
@"previousLabelOrAppVersion": previousStatusReportIdentifier
32+
};
33+
}
34+
}
35+
36+
return nil;
1437
}
1538

16-
+ (NSDictionary *)getFailedUpdateStatusReport:(NSDictionary *)lastFailedPackage
39+
+ (NSDictionary *)getRollbackReport:(NSDictionary *)lastFailedPackage
1740
{
1841
return @{
1942
@"package": lastFailedPackage,
2043
@"status": DeploymentFailed
2144
};
2245
}
2346

24-
+ (NSDictionary *)getNewPackageStatusReport:(NSDictionary *)currentPackage
47+
+ (NSDictionary *)getUpdateReport:(NSDictionary *)currentPackage
2548
{
2649
NSString *currentPackageIdentifier = [self getPackageStatusReportIdentifier:currentPackage];
2750
NSString *previousStatusReportIdentifier = [self getPreviousStatusReportIdentifier];
@@ -57,32 +80,9 @@ + (NSDictionary *)getNewPackageStatusReport:(NSDictionary *)currentPackage
5780
return nil;
5881
}
5982

60-
+ (NSDictionary *)getNewAppVersionStatusReport:(NSString *)appVersion
83+
+ (NSString *)getDeploymentKeyFromStatusReportIdentifier:(NSString *)statusReportIdentifier
6184
{
62-
NSString *previousStatusReportIdentifier = [self getPreviousStatusReportIdentifier];
63-
if (previousStatusReportIdentifier == nil) {
64-
[self recordDeploymentStatusReported:appVersion];
65-
return @{ @"appVersion": appVersion };
66-
} else if (![previousStatusReportIdentifier isEqualToString:appVersion]) {
67-
[self recordDeploymentStatusReported:appVersion];
68-
if ([self isStatusReportIdentifierCodePushLabel:previousStatusReportIdentifier]) {
69-
NSString *previousDeploymentKey = [self getDeploymentKeyFromStatusReportIdentifier:previousStatusReportIdentifier];
70-
NSString *previousLabel = [self getVersionLabelFromStatusReportIdentifier:previousStatusReportIdentifier];
71-
return @{
72-
@"appVersion": appVersion,
73-
@"previousDeploymentKey": previousDeploymentKey,
74-
@"previousLabelOrAppVersion": previousLabel
75-
};
76-
} else {
77-
// Previous status report was with a binary app version.
78-
return @{
79-
@"appVersion": appVersion,
80-
@"previousLabelOrAppVersion": previousStatusReportIdentifier
81-
};
82-
}
83-
}
84-
85-
return nil;
85+
return [[statusReportIdentifier componentsSeparatedByString:@":"] firstObject];
8686
}
8787

8888
+ (NSString *)getPackageStatusReportIdentifier:(NSDictionary *)package

android/app/src/main/java/com/microsoft/codepush/react/CodePush.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public class CodePush {
6565
// Helper classes.
6666
private CodePushPackage codePushPackage;
6767
private CodePushReactPackage codePushReactPackage;
68-
private CodePushStatusReport codePushStatusReport;
68+
private CodePushTelemetryManager codePushTelemetryManager;
6969
private CodePushNativeModule codePushNativeModule;
7070

7171
// Config properties.
@@ -86,7 +86,7 @@ public CodePush(String deploymentKey, Activity mainActivity, boolean isDebugMode
8686
SoLoader.init(mainActivity, false);
8787
this.applicationContext = mainActivity.getApplicationContext();
8888
this.codePushPackage = new CodePushPackage(mainActivity.getFilesDir().getAbsolutePath());
89-
this.codePushStatusReport = new CodePushStatusReport(this.applicationContext, CODE_PUSH_PREFERENCES);
89+
this.codePushTelemetryManager = new CodePushTelemetryManager(this.applicationContext, CODE_PUSH_PREFERENCES);
9090
this.deploymentKey = deploymentKey;
9191
this.isDebugMode = isDebugMode;
9292
this.mainActivity = mainActivity;
@@ -433,7 +433,7 @@ public void getNewStatusReport(Promise promise) {
433433
try {
434434
JSONObject lastFailedPackageJSON = failedUpdates.getJSONObject(failedUpdates.length() - 1);
435435
WritableMap lastFailedPackage = CodePushUtils.convertJsonObjectToWriteable(lastFailedPackageJSON);
436-
WritableMap failedStatusReport = codePushStatusReport.getFailedUpdateStatusReport(lastFailedPackage);
436+
WritableMap failedStatusReport = codePushTelemetryManager.getRollbackReport(lastFailedPackage);
437437
if (failedStatusReport != null) {
438438
promise.resolve(failedStatusReport);
439439
return;
@@ -445,14 +445,14 @@ public void getNewStatusReport(Promise promise) {
445445
} else if (didUpdate) {
446446
WritableMap currentPackage = codePushPackage.getCurrentPackage();
447447
if (currentPackage != null) {
448-
WritableMap newPackageStatusReport = codePushStatusReport.getNewPackageStatusReport(currentPackage);
448+
WritableMap newPackageStatusReport = codePushTelemetryManager.getUpdateReport(currentPackage);
449449
if (newPackageStatusReport != null) {
450450
promise.resolve(newPackageStatusReport);
451451
return;
452452
}
453453
}
454454
} else if (isRunningBinaryVersion) {
455-
WritableMap newAppVersionStatusReport = codePushStatusReport.getNewAppVersionStatusReport(appVersion);
455+
WritableMap newAppVersionStatusReport = codePushTelemetryManager.getBinaryUpdateReport(appVersion);
456456
if (newAppVersionStatusReport != null) {
457457
promise.resolve(newAppVersionStatusReport);
458458
return;

0 commit comments

Comments
 (0)