SDStatusBarOverriderPost12_0.m 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. //
  2. // SDStatusBarOverriderPost12_0.m
  3. // SimulatorStatusMagic
  4. //
  5. // Created by Scott Talbot on 6/6/18.
  6. // Copyright © 2018 Shiny Development. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. #import "SDStatusBarOverriderPost12_0.h"
  10. typedef NS_ENUM(int, StatusBarItem) {
  11. // 0
  12. dateStringIpad = 1,
  13. // 2
  14. // 3
  15. SignalStrengthBars = 4,
  16. SecondarySignalStrengthBars = 5,
  17. SignalStrengthBarsVisibleOnIpad = 6,
  18. // 7
  19. // 8
  20. // 9
  21. // 10
  22. // 11
  23. // 12
  24. BatteryDetail = 13,
  25. // 14
  26. // 15
  27. Bluetooth = 16,
  28. // 17
  29. // 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. // 35
  47. // 36
  48. // 37
  49. // 38
  50. // 39
  51. // 40
  52. };
  53. typedef NS_ENUM(unsigned int, BatteryState) {
  54. BatteryStateUnplugged = 0
  55. };
  56. typedef struct {
  57. bool itemIsEnabled[41];
  58. char timeString[64];
  59. char shortTimeString[64];
  60. char dateString[256];
  61. int gsmSignalStrengthRaw;
  62. int secondaryGsmSignalStrengthRaw;
  63. int gsmSignalStrengthBars;
  64. int secondaryGsmSignalStrengthBars;
  65. char serviceString[100];
  66. char secondaryServiceString[100];
  67. char serviceCrossfadeString[100];
  68. char secondaryServiceCrossfadeString[100];
  69. char serviceImages[2][100];
  70. char operatorDirectory[1024];
  71. unsigned int serviceContentType;
  72. unsigned int secondaryServiceContentType;
  73. int wifiSignalStrengthRaw;
  74. int wifiSignalStrengthBars;
  75. unsigned int dataNetworkType;
  76. unsigned int secondaryDataNetworkType;
  77. int batteryCapacity;
  78. unsigned int batteryState;
  79. char batteryDetailString[150];
  80. int bluetoothBatteryCapacity;
  81. int thermalColor;
  82. unsigned int thermalSunlightMode : 1;
  83. unsigned int slowActivity : 1;
  84. unsigned int syncActivity : 1;
  85. char activityDisplayId[256];
  86. unsigned int bluetoothConnected : 1;
  87. unsigned int displayRawGSMSignal : 1;
  88. unsigned int displayRawWifiSignal : 1;
  89. unsigned int locationIconType : 1;
  90. unsigned int quietModeInactive : 1;
  91. unsigned int tetheringConnectionCount;
  92. unsigned int batterySaverModeActive : 1;
  93. unsigned int deviceIsRTL : 1;
  94. unsigned int lock : 1;
  95. char breadcrumbTitle[256];
  96. char breadcrumbSecondaryTitle[256];
  97. char personName[100];
  98. unsigned int electronicTollCollectionAvailable : 1;
  99. unsigned int wifiLinkWarning : 1;
  100. unsigned int wifiSearching : 1;
  101. double backgroundActivityDisplayStartDate;
  102. unsigned int shouldShowEmergencyOnlyStatus : 1;
  103. unsigned int secondaryCellularConfigured : 1;
  104. char primaryServiceBadgeString[100];
  105. char secondaryServiceBadgeString[100];
  106. } StatusBarRawData;
  107. typedef struct {
  108. bool overrideItemIsEnabled[41];
  109. unsigned int overrideTimeString : 1;
  110. unsigned int overrideDateString : 1;
  111. unsigned int overrideGsmSignalStrengthRaw : 1;
  112. unsigned int overrideSecondaryGsmSignalStrengthRaw : 1;
  113. unsigned int overrideGsmSignalStrengthBars : 1;
  114. unsigned int overrideSecondaryGsmSignalStrengthBars : 1;
  115. unsigned int overrideServiceString : 1;
  116. unsigned int overrideSecondaryServiceString : 1;
  117. unsigned int overrideServiceImages : 2;
  118. unsigned int overrideOperatorDirectory : 1;
  119. unsigned int overrideServiceContentType : 1;
  120. unsigned int overrideSecondaryServiceContentType : 1;
  121. unsigned int overrideWifiSignalStrengthRaw : 1;
  122. unsigned int overrideWifiSignalStrengthBars : 1;
  123. unsigned int overrideDataNetworkType : 1;
  124. unsigned int overrideSecondaryDataNetworkType : 1;
  125. unsigned int disallowsCellularDataNetworkTypes : 1;
  126. unsigned int overrideBatteryCapacity : 1;
  127. unsigned int overrideBatteryState : 1;
  128. unsigned int overrideBatteryDetailString : 1;
  129. unsigned int overrideBluetoothBatteryCapacity : 1;
  130. unsigned int overrideThermalColor : 1;
  131. unsigned int overrideSlowActivity : 1;
  132. unsigned int overrideActivityDisplayId : 1;
  133. unsigned int overrideBluetoothConnected : 1;
  134. unsigned int overrideBreadcrumb : 1;
  135. unsigned int overrideLock;
  136. unsigned int overrideDisplayRawGSMSignal : 1;
  137. unsigned int overrideDisplayRawWifiSignal : 1;
  138. unsigned int overridePersonName : 1;
  139. unsigned int overrideWifiLinkWarning : 1;
  140. unsigned int overrideSecondaryCellularConfigured : 1;
  141. unsigned int overridePrimaryServiceBadgeString : 1;
  142. unsigned int overrideSecondaryServiceBadgeString : 1;
  143. StatusBarRawData values;
  144. } StatusBarOverrideData;
  145. @class UIStatusBarServer;
  146. @protocol UIStatusBarServerClient
  147. @required
  148. - (void)statusBarServer:(UIStatusBarServer *)arg1 didReceiveDoubleHeightStatusString:(NSString *)arg2 forStyle:(long long)arg3;
  149. - (void)statusBarServer:(UIStatusBarServer *)arg1 didReceiveGlowAnimationState:(bool)arg2 forStyle:(long long)arg3;
  150. - (void)statusBarServer:(UIStatusBarServer *)arg1 didReceiveStatusBarData:(const StatusBarRawData *)arg2 withActions:(int)arg3;
  151. - (void)statusBarServer:(UIStatusBarServer *)arg1 didReceiveStyleOverrides:(int)arg2;
  152. @end
  153. @interface UIStatusBarServer : NSObject
  154. @property (nonatomic, strong) id<UIStatusBarServerClient> statusBar;
  155. + (void)postStatusBarOverrideData:(StatusBarOverrideData *)arg1;
  156. + (void)permanentizeStatusBarOverrideData;
  157. + (StatusBarOverrideData *)getStatusBarOverrideData;
  158. @end
  159. @implementation SDStatusBarOverriderPost12_0
  160. @synthesize timeString;
  161. @synthesize dateString;
  162. @synthesize carrierName;
  163. @synthesize bluetoothConnected;
  164. @synthesize bluetoothEnabled;
  165. @synthesize batteryDetailEnabled;
  166. @synthesize networkType;
  167. @synthesize iPadDateEnabled;
  168. @synthesize iPadGsmSignalEnabled;
  169. - (void)enableOverrides {
  170. StatusBarOverrideData *overrides = [UIStatusBarServer getStatusBarOverrideData];
  171. // Set 9:41 time in current localization
  172. strcpy(overrides->values.timeString, [self.timeString cStringUsingEncoding:NSUTF8StringEncoding]);
  173. overrides->overrideTimeString = 1;
  174. // Set Tue Jan 9 in current localization
  175. strcpy(overrides->values.dateString, [self.dateString cStringUsingEncoding:NSUTF8StringEncoding]);
  176. overrides->overrideDateString = 1;
  177. // Show / Hide date on iPad
  178. if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
  179. overrides->overrideItemIsEnabled[dateStringIpad] = 1;
  180. overrides->values.itemIsEnabled[dateStringIpad] = self.iPadDateEnabled ? 1 : 0;
  181. }
  182. // Enable 5 bars of mobile (iPhone only)
  183. if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone) {
  184. overrides->overrideItemIsEnabled[SignalStrengthBars] = 1;
  185. overrides->values.itemIsEnabled[SignalStrengthBars] = 1;
  186. overrides->overrideGsmSignalStrengthBars = 1;
  187. overrides->values.gsmSignalStrengthBars = 5;
  188. }
  189. // Enable / Disable GSM signal bars on iPad
  190. if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
  191. if (self.iPadGsmSignalEnabled) {
  192. overrides->overrideItemIsEnabled[SignalStrengthBars] = 1;
  193. overrides->values.itemIsEnabled[SignalStrengthBars] = 1;
  194. overrides->overrideGsmSignalStrengthBars = 1;
  195. overrides->values.gsmSignalStrengthBars = 5;
  196. } else {
  197. overrides->overrideItemIsEnabled[SignalStrengthBarsVisibleOnIpad] = 1;
  198. overrides->values.itemIsEnabled[SignalStrengthBars] = 0;
  199. }
  200. }
  201. overrides->overrideDataNetworkType = self.networkType != SDStatusBarManagerNetworkTypeWiFi;
  202. overrides->values.dataNetworkType = self.networkType - 1;
  203. // Remove carrier text for iPhone, set it to "iPad" for the iPad
  204. overrides->overrideServiceString = 1;
  205. NSString *carrierText = self.carrierName;
  206. if ([carrierText length] <= 0) {
  207. carrierText = ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone) ? @"" : @"iPad";
  208. }
  209. strcpy(overrides->values.serviceString, [carrierText cStringUsingEncoding:NSUTF8StringEncoding]);
  210. // Battery: 100% and unplugged
  211. overrides->overrideItemIsEnabled[BatteryDetail] = YES;
  212. overrides->values.itemIsEnabled[BatteryDetail] = self.batteryDetailEnabled;
  213. overrides->overrideBatteryCapacity = YES;
  214. overrides->values.batteryCapacity = 100;
  215. overrides->overrideBatteryState = YES;
  216. overrides->values.batteryState = BatteryStateUnplugged;
  217. overrides->overrideBatteryDetailString = YES;
  218. NSString *batteryDetailString = [NSString stringWithFormat:@"%@%%", @(overrides->values.batteryCapacity)];
  219. strcpy(overrides->values.batteryDetailString, [batteryDetailString cStringUsingEncoding:NSUTF8StringEncoding]);
  220. // Bluetooth
  221. overrides->overrideItemIsEnabled[Bluetooth] = !!self.bluetoothEnabled;
  222. overrides->values.itemIsEnabled[Bluetooth] = !!self.bluetoothEnabled;
  223. if (self.bluetoothEnabled) {
  224. overrides->overrideBluetoothConnected = self.bluetoothConnected;
  225. overrides->values.bluetoothConnected = self.bluetoothConnected;
  226. }
  227. // Actually update the status bar
  228. [UIStatusBarServer postStatusBarOverrideData:overrides];
  229. // Lock in the changes, reset simulator will remove this
  230. [UIStatusBarServer permanentizeStatusBarOverrideData];
  231. }
  232. - (void)disableOverrides {
  233. StatusBarOverrideData *overrides = [UIStatusBarServer getStatusBarOverrideData];
  234. // Remove all overrides that use the array of bools
  235. bzero(overrides->overrideItemIsEnabled, sizeof(overrides->overrideItemIsEnabled));
  236. bzero(overrides->values.itemIsEnabled, sizeof(overrides->values.itemIsEnabled));
  237. // Remove specific overrides (separate flags)
  238. overrides->overrideTimeString = 0;
  239. overrides->overrideDateString = 0;
  240. overrides->overrideGsmSignalStrengthBars = 0;
  241. overrides->overrideDataNetworkType = 0;
  242. overrides->overrideBatteryCapacity = 0;
  243. overrides->overrideBatteryState = 0;
  244. overrides->overrideBatteryDetailString = 0;
  245. overrides->overrideBluetoothConnected = 0;
  246. // Carrier text (it's an override to set it back to the default)
  247. overrides->overrideServiceString = 1;
  248. strcpy(overrides->values.serviceString, [NSLocalizedString(@"Carrier", @"Carrier") cStringUsingEncoding:NSUTF8StringEncoding]);
  249. // Actually update the status bar
  250. [UIStatusBarServer postStatusBarOverrideData:overrides];
  251. // Have to call this to remove all the overrides
  252. [UIStatusBarServer permanentizeStatusBarOverrideData];
  253. }
  254. @end