SDStatusBarOverriderPost11_0.m 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. //
  2. // SDStatusBarOverriderPost11_0.m
  3. // SimulatorStatusMagic
  4. //
  5. // Created by Craig Siemens on 2017-07-11.
  6. // Copyright © 2017 Shiny Development. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. #import "SDStatusBarOverriderPost11_0.h"
  10. typedef NS_ENUM(int, StatusBarItem) {
  11. // 0
  12. DoNotDisturb = 1,
  13. // 2
  14. SignalStrengthBars = 3,
  15. // 4
  16. // 5
  17. // 6
  18. // 7
  19. // 8
  20. BatteryDetail = 9,
  21. // 10
  22. // 11
  23. Bluetooth = 12,
  24. // 13
  25. Alarms = 14,
  26. // 15
  27. // 16
  28. // 17
  29. RotationLock = 18,
  30. // 19
  31. // 20
  32. // 21
  33. // 22
  34. // 23
  35. // 24
  36. // 25
  37. // 26
  38. // 27
  39. // 28
  40. // 29
  41. // 30
  42. // 31
  43. // 32
  44. // 33
  45. // 34
  46. };
  47. typedef NS_ENUM(unsigned int, BatteryState) {
  48. BatteryStateUnplugged = 0
  49. };
  50. typedef struct {
  51. bool itemIsEnabled[35];
  52. char timeString[64];
  53. char shortTimeString[64];
  54. int gsmSignalStrengthRaw;
  55. int gsmSignalStrengthBars;
  56. char serviceString[100];
  57. char serviceCrossfadeString[100];
  58. char serviceImages[2][100];
  59. char operatorDirectory[1024];
  60. unsigned int serviceContentType;
  61. int wifiSignalStrengthRaw;
  62. int wifiSignalStrengthBars;
  63. unsigned int dataNetworkType;
  64. int batteryCapacity;
  65. unsigned int batteryState;
  66. char batteryDetailString[150];
  67. int bluetoothBatteryCapacity;
  68. int thermalColor;
  69. unsigned int thermalSunlightMode : 1;
  70. unsigned int slowActivity : 1;
  71. unsigned int syncActivity : 1;
  72. char activityDisplayId[256];
  73. unsigned int bluetoothConnected : 1;
  74. unsigned int displayRawGSMSignal : 1;
  75. unsigned int displayRawWifiSignal : 1;
  76. unsigned int locationIconType : 1;
  77. unsigned int quietModeInactive : 1;
  78. unsigned int tetheringConnectionCount;
  79. unsigned int batterySaverModeActive : 1;
  80. unsigned int deviceIsRTL : 1;
  81. unsigned int lock : 1;
  82. char breadcrumbTitle[256];
  83. char breadcrumbSecondaryTitle[256];
  84. char personName[100];
  85. unsigned int electronicTollCollectionAvailable : 1;
  86. unsigned int wifiLinkWarning : 1;
  87. unsigned int wifiSearching : 1;
  88. double backgroundActivityDisplayStartDate;
  89. unsigned int shouldShowEmergencyOnlyStatus : 1;
  90. } StatusBarRawData;
  91. typedef struct {
  92. bool overrideItemIsEnabled[35];
  93. unsigned int overrideTimeString : 1;
  94. unsigned int overrideGsmSignalStrengthRaw : 1;
  95. unsigned int overrideGsmSignalStrengthBars : 1;
  96. unsigned int overrideServiceString : 1;
  97. unsigned int overrideServiceImages : 2;
  98. unsigned int overrideOperatorDirectory : 1;
  99. unsigned int overrideServiceContentType : 1;
  100. unsigned int overrideWifiSignalStrengthRaw : 1;
  101. unsigned int overrideWifiSignalStrengthBars : 1;
  102. unsigned int overrideDataNetworkType : 1;
  103. unsigned int disallowsCellularDataNetworkTypes : 1;
  104. unsigned int overrideBatteryCapacity : 1;
  105. unsigned int overrideBatteryState : 1;
  106. unsigned int overrideBatteryDetailString : 1;
  107. unsigned int overrideBluetoothBatteryCapacity : 1;
  108. unsigned int overrideThermalColor : 1;
  109. unsigned int overrideSlowActivity : 1;
  110. unsigned int overrideActivityDisplayId : 1;
  111. unsigned int overrideBluetoothConnected : 1;
  112. unsigned int overrideBreadcrumb : 1;
  113. unsigned int overrideLock;
  114. unsigned int overrideDisplayRawGSMSignal : 1;
  115. unsigned int overrideDisplayRawWifiSignal : 1;
  116. unsigned int overridePersonName : 1;
  117. unsigned int overrideWifiLinkWarning : 1;
  118. StatusBarRawData values;
  119. } StatusBarOverrideData;
  120. @class UIStatusBarServer;
  121. @protocol UIStatusBarServerClient
  122. @required
  123. - (void)statusBarServer:(UIStatusBarServer *)arg1 didReceiveDoubleHeightStatusString:(NSString *)arg2 forStyle:(long long)arg3;
  124. - (void)statusBarServer:(UIStatusBarServer *)arg1 didReceiveGlowAnimationState:(bool)arg2 forStyle:(long long)arg3;
  125. - (void)statusBarServer:(UIStatusBarServer *)arg1 didReceiveStatusBarData:(const StatusBarRawData *)arg2 withActions:(int)arg3;
  126. - (void)statusBarServer:(UIStatusBarServer *)arg1 didReceiveStyleOverrides:(int)arg2;
  127. @end
  128. @interface UIStatusBarServer : NSObject
  129. @property (nonatomic, strong) id<UIStatusBarServerClient> statusBar;
  130. + (void)postStatusBarOverrideData:(StatusBarOverrideData *)arg1;
  131. + (void)permanentizeStatusBarOverrideData;
  132. + (const StatusBarRawData *)getStatusBarData;
  133. + (StatusBarOverrideData *)getStatusBarOverrideData;
  134. @end
  135. @implementation SDStatusBarOverriderPost11_0
  136. @synthesize timeString;
  137. @synthesize dateString;
  138. @synthesize carrierName;
  139. @synthesize bluetoothConnected;
  140. @synthesize bluetoothEnabled;
  141. @synthesize batteryDetailEnabled;
  142. @synthesize networkType;
  143. @synthesize iPadDateEnabled;
  144. @synthesize iPadGsmSignalEnabled;
  145. - (void)enableOverrides {
  146. StatusBarOverrideData *overrides = [UIStatusBarServer getStatusBarOverrideData];
  147. // Set 9:41 time in current localization
  148. strcpy(overrides->values.timeString, [self.timeString cStringUsingEncoding:NSUTF8StringEncoding]);
  149. overrides->overrideTimeString = 1;
  150. // Enable 5 bars of mobile (iPhone only)
  151. if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone) {
  152. overrides->overrideItemIsEnabled[SignalStrengthBars] = 1;
  153. overrides->values.itemIsEnabled[SignalStrengthBars] = 1;
  154. overrides->overrideGsmSignalStrengthBars = 1;
  155. overrides->values.gsmSignalStrengthBars = 5;
  156. }
  157. overrides->overrideDataNetworkType = self.networkType != SDStatusBarManagerNetworkTypeWiFi;
  158. overrides->values.dataNetworkType = self.networkType - 1;
  159. // Remove carrier text for iPhone, set it to "iPad" for the iPad
  160. overrides->overrideServiceString = 1;
  161. NSString *carrierText = self.carrierName;
  162. if ([carrierText length] <= 0) {
  163. carrierText = ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone) ? @"" : @"iPad";
  164. }
  165. strcpy(overrides->values.serviceString, [carrierText cStringUsingEncoding:NSUTF8StringEncoding]);
  166. // Battery: 100% and unplugged
  167. overrides->overrideItemIsEnabled[BatteryDetail] = YES;
  168. overrides->values.itemIsEnabled[BatteryDetail] = YES;
  169. overrides->overrideBatteryCapacity = YES;
  170. overrides->values.batteryCapacity = 100;
  171. overrides->overrideBatteryState = YES;
  172. overrides->values.batteryState = BatteryStateUnplugged;
  173. overrides->overrideBatteryDetailString = YES;
  174. NSString *batteryDetailString = self.batteryDetailEnabled ? [NSString stringWithFormat:@"%@%%", @(overrides->values.batteryCapacity)] : @" ";
  175. // Setting this to an empty string will not work, it needs to be a @" "
  176. strcpy(overrides->values.batteryDetailString, [batteryDetailString cStringUsingEncoding:NSUTF8StringEncoding]);
  177. // Bluetooth
  178. overrides->overrideItemIsEnabled[Bluetooth] = !!self.bluetoothEnabled;
  179. overrides->values.itemIsEnabled[Bluetooth] = !!self.bluetoothEnabled;
  180. if (self.bluetoothEnabled) {
  181. overrides->overrideBluetoothConnected = self.bluetoothConnected;
  182. overrides->values.bluetoothConnected = self.bluetoothConnected;
  183. }
  184. // Actually update the status bar
  185. [UIStatusBarServer postStatusBarOverrideData:overrides];
  186. // Remove the @" " used to trick the battery percentage into not showing, if used
  187. if (!self.batteryDetailEnabled) {
  188. batteryDetailString = @"";
  189. strcpy(overrides->values.batteryDetailString, [batteryDetailString cStringUsingEncoding:NSUTF8StringEncoding]);
  190. [UIStatusBarServer postStatusBarOverrideData:overrides];
  191. }
  192. // Lock in the changes, reset simulator will remove this
  193. [UIStatusBarServer permanentizeStatusBarOverrideData];
  194. }
  195. - (void)disableOverrides {
  196. StatusBarOverrideData *overrides = [UIStatusBarServer getStatusBarOverrideData];
  197. // Remove all overrides that use the array of bools
  198. bzero(overrides->overrideItemIsEnabled, sizeof(overrides->overrideItemIsEnabled));
  199. bzero(overrides->values.itemIsEnabled, sizeof(overrides->values.itemIsEnabled));
  200. // Remove specific overrides (separate flags)
  201. overrides->overrideTimeString = 0;
  202. overrides->overrideGsmSignalStrengthBars = 0;
  203. overrides->overrideDataNetworkType = 0;
  204. overrides->overrideBatteryCapacity = 0;
  205. overrides->overrideBatteryState = 0;
  206. overrides->overrideBatteryDetailString = 0;
  207. overrides->overrideBluetoothConnected = 0;
  208. // Carrier text (it's an override to set it back to the default)
  209. overrides->overrideServiceString = 1;
  210. strcpy(overrides->values.serviceString, [NSLocalizedString(@"Carrier", @"Carrier") cStringUsingEncoding:NSUTF8StringEncoding]);
  211. // Actually update the status bar
  212. [UIStatusBarServer postStatusBarOverrideData:overrides];
  213. // Have to call this to remove all the overrides
  214. [UIStatusBarServer permanentizeStatusBarOverrideData];
  215. }
  216. @end