1 |
efrain |
1 |
// Copyright 2019 Google
|
|
|
2 |
//
|
|
|
3 |
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
4 |
// you may not use this file except in compliance with the License.
|
|
|
5 |
// You may obtain a copy of the License at
|
|
|
6 |
//
|
|
|
7 |
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
8 |
//
|
|
|
9 |
// Unless required by applicable law or agreed to in writing, software
|
|
|
10 |
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
12 |
// See the License for the specific language governing permissions and
|
|
|
13 |
// limitations under the License.
|
|
|
14 |
|
|
|
15 |
#import "Crashlytics/Crashlytics/Components/FIRCLSApplication.h"
|
|
|
16 |
|
|
|
17 |
#import "Crashlytics/Crashlytics/Components/FIRCLSHost.h"
|
|
|
18 |
#import "Crashlytics/Crashlytics/Helpers/FIRCLSUtility.h"
|
|
|
19 |
|
|
|
20 |
#import <GoogleUtilities/GULAppEnvironmentUtil.h>
|
|
|
21 |
|
|
|
22 |
#if CLS_TARGET_OS_OSX
|
|
|
23 |
#import <AppKit/AppKit.h>
|
|
|
24 |
#endif
|
|
|
25 |
|
|
|
26 |
#if CLS_TARGET_OS_HAS_UIKIT
|
|
|
27 |
#import <UIKit/UIKit.h>
|
|
|
28 |
#endif
|
|
|
29 |
|
|
|
30 |
NSString* FIRCLSApplicationGetBundleIdentifier(void) {
|
|
|
31 |
return [[[NSBundle mainBundle] bundleIdentifier] stringByReplacingOccurrencesOfString:@"/"
|
|
|
32 |
withString:@"_"];
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
NSString* FIRCLSApplicationGetSDKBundleID(void) {
|
|
|
36 |
return
|
|
|
37 |
[@"com.google.firebase.crashlytics." stringByAppendingString:FIRCLSApplicationGetPlatform()];
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
NSString* FIRCLSApplicationGetPlatform(void) {
|
|
|
41 |
#if defined(TARGET_OS_MACCATALYST) && TARGET_OS_MACCATALYST
|
|
|
42 |
return @"mac";
|
|
|
43 |
#elif TARGET_OS_IOS
|
|
|
44 |
return @"ios";
|
|
|
45 |
#elif TARGET_OS_OSX
|
|
|
46 |
return @"mac";
|
|
|
47 |
#elif TARGET_OS_TV
|
|
|
48 |
return @"tvos";
|
|
|
49 |
#elif TARGET_OS_WATCH
|
|
|
50 |
return @"ios"; // TODO: temporarily use iOS until Firebase can add watchos to the backend
|
|
|
51 |
#endif
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
NSString* FIRCLSApplicationGetFirebasePlatform(void) {
|
|
|
55 |
NSString* firebasePlatform = [GULAppEnvironmentUtil applePlatform];
|
|
|
56 |
#if TARGET_OS_IOS
|
|
|
57 |
// This check is necessary because iOS-only apps running on iPad
|
|
|
58 |
// will report UIUserInterfaceIdiomPhone via UI_USER_INTERFACE_IDIOM().
|
|
|
59 |
if ([firebasePlatform isEqualToString:@"ios"] &&
|
|
|
60 |
([[UIDevice currentDevice].model.lowercaseString containsString:@"ipad"] ||
|
|
|
61 |
[[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)) {
|
|
|
62 |
return @"ipados";
|
|
|
63 |
}
|
|
|
64 |
#endif
|
|
|
65 |
|
|
|
66 |
return firebasePlatform;
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
// these defaults match the FIRCLSInfoPlist helper in FIRCLSIDEFoundation
|
|
|
70 |
NSString* FIRCLSApplicationGetBundleVersion(void) {
|
|
|
71 |
return [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
NSString* FIRCLSApplicationGetShortBundleVersion(void) {
|
|
|
75 |
return [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
NSString* FIRCLSApplicationGetName(void) {
|
|
|
79 |
NSString* name;
|
|
|
80 |
NSBundle* mainBundle;
|
|
|
81 |
|
|
|
82 |
mainBundle = [NSBundle mainBundle];
|
|
|
83 |
|
|
|
84 |
name = [mainBundle objectForInfoDictionaryKey:@"CFBundleDisplayName"];
|
|
|
85 |
if (name) {
|
|
|
86 |
return name;
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
name = [mainBundle objectForInfoDictionaryKey:@"CFBundleName"];
|
|
|
90 |
if (name) {
|
|
|
91 |
return name;
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
return FIRCLSApplicationGetBundleVersion();
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
BOOL FIRCLSApplicationHasAppStoreReceipt(void) {
|
|
|
98 |
NSURL* url = NSBundle.mainBundle.appStoreReceiptURL;
|
|
|
99 |
return [NSFileManager.defaultManager fileExistsAtPath:[url path]];
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
FIRCLSApplicationInstallationSourceType FIRCLSApplicationInstallationSource(void) {
|
|
|
103 |
if (FIRCLSApplicationHasAppStoreReceipt()) {
|
|
|
104 |
return FIRCLSApplicationInstallationSourceTypeAppStore;
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
return FIRCLSApplicationInstallationSourceTypeDeveloperInstall;
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
BOOL FIRCLSApplicationIsExtension(void) {
|
|
|
111 |
return FIRCLSApplicationExtensionPointIdentifier() != nil;
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
NSString* FIRCLSApplicationExtensionPointIdentifier(void) {
|
|
|
115 |
id extensionDict = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"NSExtension"];
|
|
|
116 |
|
|
|
117 |
if (!extensionDict) {
|
|
|
118 |
return nil;
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
if (![extensionDict isKindOfClass:[NSDictionary class]]) {
|
|
|
122 |
FIRCLSSDKLog("Error: NSExtension Info.plist entry is mal-formed\n");
|
|
|
123 |
return nil;
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
id typeValue = [(NSDictionary*)extensionDict objectForKey:@"NSExtensionPointIdentifier"];
|
|
|
127 |
|
|
|
128 |
if (![typeValue isKindOfClass:[NSString class]]) {
|
|
|
129 |
FIRCLSSDKLog("Error: NSExtensionPointIdentifier Info.plist entry is mal-formed\n");
|
|
|
130 |
return nil;
|
|
|
131 |
}
|
|
|
132 |
|
|
|
133 |
return typeValue;
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
#if CLS_TARGET_OS_HAS_UIKIT
|
|
|
137 |
UIApplication* FIRCLSApplicationSharedInstance(void) {
|
|
|
138 |
if (FIRCLSApplicationIsExtension()) {
|
|
|
139 |
return nil;
|
|
|
140 |
}
|
|
|
141 |
|
|
|
142 |
return [[UIApplication class] performSelector:@selector(sharedApplication)];
|
|
|
143 |
}
|
|
|
144 |
#elif CLS_TARGET_OS_OSX
|
|
|
145 |
id FIRCLSApplicationSharedInstance(void) {
|
|
|
146 |
return [NSClassFromString(@"NSApplication") sharedApplication];
|
|
|
147 |
}
|
|
|
148 |
#else
|
|
|
149 |
id FIRCLSApplicationSharedInstance(void) {
|
|
|
150 |
return nil; // FIXME: what do we actually return for watch?
|
|
|
151 |
}
|
|
|
152 |
#endif
|
|
|
153 |
|
|
|
154 |
void FIRCLSApplicationOpenURL(NSURL* url,
|
|
|
155 |
NSExtensionContext* extensionContext,
|
|
|
156 |
void (^completionBlock)(BOOL success)) {
|
|
|
157 |
if (extensionContext) {
|
|
|
158 |
[extensionContext openURL:url completionHandler:completionBlock];
|
|
|
159 |
return;
|
|
|
160 |
}
|
|
|
161 |
|
|
|
162 |
BOOL result = NO;
|
|
|
163 |
|
|
|
164 |
#if TARGET_OS_IOS
|
|
|
165 |
// What's going on here is the value returned is a scalar, but we really need an object to
|
|
|
166 |
// call this dynamically. Hoops must be jumped.
|
|
|
167 |
NSInvocationOperation* op =
|
|
|
168 |
[[NSInvocationOperation alloc] initWithTarget:FIRCLSApplicationSharedInstance()
|
|
|
169 |
selector:@selector(openURL:)
|
|
|
170 |
object:url];
|
|
|
171 |
[op start];
|
|
|
172 |
[op.result getValue:&result];
|
|
|
173 |
#elif CLS_TARGET_OS_OSX
|
|
|
174 |
result = [[NSClassFromString(@"NSWorkspace") sharedWorkspace] openURL:url];
|
|
|
175 |
#endif
|
|
|
176 |
|
|
|
177 |
completionBlock(result);
|
|
|
178 |
}
|
|
|
179 |
|
|
|
180 |
id<NSObject> FIRCLSApplicationBeginActivity(NSActivityOptions options, NSString* reason) {
|
|
|
181 |
if ([[NSProcessInfo processInfo] respondsToSelector:@selector(beginActivityWithOptions:
|
|
|
182 |
reason:)]) {
|
|
|
183 |
return [[NSProcessInfo processInfo] beginActivityWithOptions:options reason:reason];
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
#if CLS_TARGET_OS_OSX
|
|
|
187 |
if (options & NSActivitySuddenTerminationDisabled) {
|
|
|
188 |
[[NSProcessInfo processInfo] disableSuddenTermination];
|
|
|
189 |
}
|
|
|
190 |
|
|
|
191 |
if (options & NSActivityAutomaticTerminationDisabled) {
|
|
|
192 |
[[NSProcessInfo processInfo] disableAutomaticTermination:reason];
|
|
|
193 |
}
|
|
|
194 |
#endif
|
|
|
195 |
|
|
|
196 |
// encode the options, so we can undo our work later
|
|
|
197 |
return @{@"options" : @(options), @"reason" : reason};
|
|
|
198 |
}
|
|
|
199 |
|
|
|
200 |
void FIRCLSApplicationEndActivity(id<NSObject> activity) {
|
|
|
201 |
if (!activity) {
|
|
|
202 |
return;
|
|
|
203 |
}
|
|
|
204 |
|
|
|
205 |
if ([[NSProcessInfo processInfo] respondsToSelector:@selector(endActivity:)]) {
|
|
|
206 |
[[NSProcessInfo processInfo] endActivity:activity];
|
|
|
207 |
return;
|
|
|
208 |
}
|
|
|
209 |
|
|
|
210 |
#if CLS_TARGET_OS_OSX
|
|
|
211 |
NSInteger options = [[(NSDictionary*)activity objectForKey:@"options"] integerValue];
|
|
|
212 |
|
|
|
213 |
if (options & NSActivitySuddenTerminationDisabled) {
|
|
|
214 |
[[NSProcessInfo processInfo] enableSuddenTermination];
|
|
|
215 |
}
|
|
|
216 |
|
|
|
217 |
if (options & NSActivityAutomaticTerminationDisabled) {
|
|
|
218 |
[[NSProcessInfo processInfo]
|
|
|
219 |
enableAutomaticTermination:[(NSDictionary*)activity objectForKey:@"reason"]];
|
|
|
220 |
}
|
|
|
221 |
#endif
|
|
|
222 |
}
|
|
|
223 |
|
|
|
224 |
void FIRCLSApplicationActivity(NSActivityOptions options, NSString* reason, void (^block)(void)) {
|
|
|
225 |
id<NSObject> activity = FIRCLSApplicationBeginActivity(options, reason);
|
|
|
226 |
|
|
|
227 |
block();
|
|
|
228 |
|
|
|
229 |
FIRCLSApplicationEndActivity(activity);
|
|
|
230 |
}
|