SDStatusBarOverriderPost10_3.m 8.1 KB

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