SDStatusBarOverriderPost10_0.m 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. // --------------------------------------------------------------------------------
  2. // The MIT License (MIT)
  3. //
  4. // Copyright (c) 2014-2016 Shiny Development
  5. //
  6. // Permission is hereby granted, free of charge, to any person obtaining a copy
  7. // of this software and associated documentation files (the "Software"), to deal
  8. // in the Software without restriction, including without limitation the rights
  9. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. // copies of the Software, and to permit persons to whom the Software is
  11. // furnished to do so, subject to the following conditions:
  12. //
  13. // The above copyright notice and this permission notice shall be included in all
  14. // copies or substantial portions of the Software.
  15. //
  16. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. // SOFTWARE.
  23. // --------------------------------------------------------------------------------
  24. #import <UIKit/UIKit.h>
  25. #import "SDStatusBarOverriderPost10_0.h"
  26. typedef NS_ENUM(int, StatusBarItem10_0) {
  27. DoNotDisturb = 1,
  28. // 2
  29. SignalStrengthBars = 3,
  30. // 4
  31. // 5
  32. // 6
  33. // 7
  34. // 8
  35. BatteryDetail = 9,
  36. // 10
  37. // 11
  38. Bluetooth = 12,
  39. // 13
  40. Alarms = 14,
  41. // 15
  42. // 16
  43. // 17
  44. RotationLock = 18,
  45. // 19
  46. // 20
  47. // 21
  48. // 22
  49. // 23
  50. // 24
  51. // 25
  52. // 26
  53. // 27
  54. // 28
  55. // 29
  56. // 30
  57. // 31
  58. // 32
  59. // 33
  60. };
  61. typedef NS_ENUM(unsigned int, BatteryState) {
  62. BatteryStateUnplugged = 0
  63. };
  64. typedef struct {
  65. _Bool itemIsEnabled[34];
  66. char timeString[64];
  67. int gsmSignalStrengthRaw;
  68. int gsmSignalStrengthBars;
  69. char serviceString[100];
  70. char serviceCrossfadeString[100];
  71. char serviceImages[2][100];
  72. char operatorDirectory[1024];
  73. unsigned int serviceContentType;
  74. int wifiSignalStrengthRaw;
  75. int wifiSignalStrengthBars;
  76. unsigned int dataNetworkType;
  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. char returnToAppBundleIdentifier[100];
  99. unsigned int electronicTollCollectionAvailable:1;
  100. unsigned int wifiLinkWarning:1;
  101. } StatusBarRawData;
  102. typedef struct {
  103. _Bool overrideItemIsEnabled[34];
  104. unsigned int overrideTimeString:1;
  105. unsigned int overrideGsmSignalStrengthRaw:1;
  106. unsigned int overrideGsmSignalStrengthBars:1;
  107. unsigned int overrideServiceString:1;
  108. unsigned int overrideServiceImages:2;
  109. unsigned int overrideOperatorDirectory:1;
  110. unsigned int overrideServiceContentType:1;
  111. unsigned int overrideWifiSignalStrengthRaw:1;
  112. unsigned int overrideWifiSignalStrengthBars:1;
  113. unsigned int overrideDataNetworkType:1;
  114. unsigned int disallowsCellularDataNetworkTypes:1;
  115. unsigned int overrideBatteryCapacity:1;
  116. unsigned int overrideBatteryState:1;
  117. unsigned int overrideBatteryDetailString:1;
  118. unsigned int overrideBluetoothBatteryCapacity:1;
  119. unsigned int overrideThermalColor:1;
  120. unsigned int overrideSlowActivity:1;
  121. unsigned int overrideActivityDisplayId:1;
  122. unsigned int overrideBluetoothConnected:1;
  123. unsigned int overrideBreadcrumb:1;
  124. unsigned int overrideLock;
  125. unsigned int overrideDisplayRawGSMSignal:1;
  126. unsigned int overrideDisplayRawWifiSignal:1;
  127. unsigned int overridePersonName:1;
  128. unsigned int overrideWifiLinkWarning:1;
  129. StatusBarRawData values;
  130. } StatusBarOverrideData;
  131. @class UIStatusBarServer;
  132. // http://localhost:10000/protocols/UIStatusBarServerClient.h (commented some methods, and added structs)
  133. /* Generated by RuntimeBrowser.
  134. */
  135. @protocol UIStatusBarServerClient
  136. @required
  137. - (void)statusBarServer:(UIStatusBarServer *)arg1 didReceiveStatusBarData:(const StatusBarRawData *)data withActions:(int)arg3;
  138. - (void)statusBarServer:(UIStatusBarServer *)arg1 didReceiveStyleOverrides:(int)arg2;
  139. - (void)statusBarServer:(UIStatusBarServer *)arg1 didReceiveGlowAnimationState:(bool)arg2 forStyle:(long long)arg3;
  140. - (void)statusBarServer:(UIStatusBarServer *)arg1 didReceiveDoubleHeightStatusString:(NSString *)arg2 forStyle:(long long)arg3;
  141. @end
  142. // http://localhost:10000/classes/UIStatusBarServer.h (commented some methods, and added structs)
  143. /* Generated by RuntimeBrowser.
  144. */
  145. @interface UIStatusBarServer : NSObject
  146. @property (nonatomic, strong) id<UIStatusBarServerClient> statusBar;
  147. + (void)postStatusBarOverrideData:(StatusBarOverrideData *)arg1;
  148. + (void)permanentizeStatusBarOverrideData;
  149. + (const StatusBarRawData *)getStatusBarData;
  150. + (StatusBarOverrideData *)getStatusBarOverrideData;
  151. @end
  152. @implementation SDStatusBarOverriderPost10_0
  153. @synthesize timeString;
  154. @synthesize dateString;
  155. @synthesize carrierName;
  156. @synthesize bluetoothConnected;
  157. @synthesize bluetoothEnabled;
  158. @synthesize batteryDetailEnabled;
  159. @synthesize networkType;
  160. @synthesize iPadDateEnabled;
  161. @synthesize iPadGsmSignalEnabled;
  162. - (void)enableOverrides
  163. {
  164. StatusBarOverrideData *overrides = [UIStatusBarServer getStatusBarOverrideData];
  165. // Set 9:41 time in current localization
  166. strcpy(overrides->values.timeString, [self.timeString cStringUsingEncoding:NSUTF8StringEncoding]);
  167. overrides->overrideTimeString = 1;
  168. // Enable 5 bars of mobile (iPhone only)
  169. if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone) {
  170. overrides->overrideItemIsEnabled[SignalStrengthBars] = 1;
  171. overrides->values.itemIsEnabled[SignalStrengthBars] = 1;
  172. overrides->overrideGsmSignalStrengthBars = 1;
  173. overrides->values.gsmSignalStrengthBars = 5;
  174. }
  175. overrides->overrideDataNetworkType = self.networkType != SDStatusBarManagerNetworkTypeWiFi;
  176. overrides->values.dataNetworkType = self.networkType - 1;
  177. // Remove carrier text for iPhone, set it to "iPad" for the iPad
  178. overrides->overrideServiceString = 1;
  179. NSString *carrierText = self.carrierName;
  180. if ([carrierText length] <= 0) {
  181. carrierText = ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone) ? @"" : @"iPad";
  182. }
  183. strcpy(overrides->values.serviceString, [carrierText cStringUsingEncoding:NSUTF8StringEncoding]);
  184. // Battery: 100% and unplugged
  185. overrides->overrideItemIsEnabled[BatteryDetail] = YES;
  186. overrides->values.itemIsEnabled[BatteryDetail] = YES;
  187. overrides->overrideBatteryCapacity = YES;
  188. overrides->values.batteryCapacity = 100;
  189. overrides->overrideBatteryState = YES;
  190. overrides->values.batteryState = BatteryStateUnplugged;
  191. overrides->overrideBatteryDetailString = YES;
  192. NSString *batteryDetailString = self.batteryDetailEnabled ? [NSString stringWithFormat:@"%@%%", @(overrides->values.batteryCapacity)] : @" "; // Setting this to an empty string will not work, it needs to be a @" "
  193. strcpy(overrides->values.batteryDetailString, [batteryDetailString cStringUsingEncoding:NSUTF8StringEncoding]);
  194. // Bluetooth
  195. overrides->overrideItemIsEnabled[Bluetooth] = !!self.bluetoothEnabled;
  196. overrides->values.itemIsEnabled[Bluetooth] = !!self.bluetoothEnabled;
  197. if (self.bluetoothEnabled) {
  198. overrides->overrideBluetoothConnected = self.bluetoothConnected;
  199. overrides->values.bluetoothConnected = self.bluetoothConnected;
  200. }
  201. // Actually update the status bar
  202. [UIStatusBarServer postStatusBarOverrideData:overrides];
  203. // Remove the @" " used to trick the battery percentage into not showing, if used
  204. if (!self.batteryDetailEnabled) {
  205. batteryDetailString = @"";
  206. strcpy(overrides->values.batteryDetailString, [batteryDetailString cStringUsingEncoding:NSUTF8StringEncoding]);
  207. [UIStatusBarServer postStatusBarOverrideData:overrides];
  208. }
  209. // Lock in the changes, reset simulator will remove this
  210. [UIStatusBarServer permanentizeStatusBarOverrideData];
  211. }
  212. - (void)disableOverrides
  213. {
  214. StatusBarOverrideData *overrides = [UIStatusBarServer getStatusBarOverrideData];
  215. // Remove all overrides that use the array of bools
  216. bzero(overrides->overrideItemIsEnabled, sizeof(overrides->overrideItemIsEnabled));
  217. bzero(overrides->values.itemIsEnabled, sizeof(overrides->values.itemIsEnabled));
  218. // Remove specific overrides (separate flags)
  219. overrides->overrideTimeString = 0;
  220. overrides->overrideGsmSignalStrengthBars = 0;
  221. overrides->overrideDataNetworkType = 0;
  222. overrides->overrideBatteryCapacity = 0;
  223. overrides->overrideBatteryState = 0;
  224. overrides->overrideBatteryDetailString = 0;
  225. overrides->overrideBluetoothConnected = 0;
  226. // Carrier text (it's an override to set it back to the default)
  227. overrides->overrideServiceString = 1;
  228. strcpy(overrides->values.serviceString, [NSLocalizedString(@"Carrier", @"Carrier") cStringUsingEncoding:NSUTF8StringEncoding]);
  229. // Actually update the status bar
  230. [UIStatusBarServer postStatusBarOverrideData:overrides];
  231. // Have to call this to remove all the overrides
  232. [UIStatusBarServer permanentizeStatusBarOverrideData];
  233. }
  234. @end