forked from 4jy/Source-SnapChat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SCBlackCameraReporter.m
86 lines (71 loc) · 2.54 KB
/
SCBlackCameraReporter.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//
// SCBlackCameraReporter.m
// Snapchat
//
// Created by Derek Wang on 09/01/2018.
//
#import "SCBlackCameraReporter.h"
#import "SCManiphestTicketCreator.h"
#import <SCFoundation/SCAssertWrapper.h>
#import <SCFoundation/SCLog.h>
#import <SCFoundation/SCLogHelper.h>
#import <SCFoundation/SCZeroDependencyExperiments.h>
#import <SCLogger/SCCameraMetrics.h>
#import <SCLogger/SCLogger.h>
@interface SCBlackCameraReporter ()
@property (nonatomic) id<SCManiphestTicketCreator> ticketCreator;
@end
@implementation SCBlackCameraReporter
- (instancetype)initWithTicketCreator:(id<SCManiphestTicketCreator>)ticketCreator
{
if (self = [super init]) {
_ticketCreator = ticketCreator;
}
return self;
}
- (NSString *)causeNameFor:(SCBlackCameraCause)cause
{
switch (cause) {
case SCBlackCameraStartRunningNotCalled:
return @"StartRunningNotCalled";
case SCBlackCameraSessionNotRunning:
return @"SessionNotRunning";
case SCBlackCameraRenderingPaused:
return @"RenderingPause";
case SCBlackCameraPreviewIsHidden:
return @"PreviewIsHidden";
case SCBlackCameraSessionStartRunningBlocked:
return @"SessionStartRunningBlocked";
case SCBlackCameraSessionConfigurationBlocked:
return @"SessionConfigurationBlocked";
case SCBlackCameraNoOutputData:
return @"NoOutputData";
default:
SCAssert(NO, @"illegate cause");
break;
}
return nil;
}
- (void)reportBlackCameraWithCause:(SCBlackCameraCause)cause
{
NSString *causeStr = [self causeNameFor:cause];
SCLogCoreCameraError(@"[BlackCamera] Detected black camera, cause: %@", causeStr);
NSDictionary *parameters = @{ @"type" : @"DETECTED", @"cause" : causeStr };
[_ticketCreator createAndFileBetaReport:JSONStringSerializeObjectForLogging(parameters)];
if (SCExperimentWithBlackCameraReporting()) {
[[SCLogger sharedInstance] logUnsampledEvent:KSCCameraBlackCamera
parameters:parameters
secretParameters:nil
metrics:nil];
}
}
- (void)fileShakeTicketWithCause:(SCBlackCameraCause)cause
{
if (SCExperimentWithBlackCameraExceptionLogging()) {
// Log exception with auto S2R
NSString *errMsg =
[NSString sc_stringWithFormat:@"[BlackCamera] Detected black camera, cause: %@", [self causeNameFor:cause]];
[_ticketCreator createAndFile:nil creationTime:0 description:errMsg email:nil project:@"Camera" subproject:nil];
}
}
@end