2014 snapchat source code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.5 KiB

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