Просмотр исходного кода

Merge pull request #743 from adotkhan/mac-support

Add macOS support to PsiphonTunnel framework
Rod Hynes 8 месяцев назад
Родитель
Сommit
b0694f3562

+ 4 - 2
MobileLibrary/iOS/PsiphonTunnel/PsiphonTunnel.xcodeproj/project.pbxproj

@@ -620,8 +620,9 @@
 				LIBRARY_SEARCH_PATHS = "$(inherited)";
 				PRODUCT_BUNDLE_IDENTIFIER = com.psiphon3.ios.PsiphonTunnel;
 				PRODUCT_NAME = "$(TARGET_NAME)";
+				REGISTER_APP_GROUPS = NO;
 				SKIP_INSTALL = YES;
-				SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
+				SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx";
 				SUPPORTS_MACCATALYST = YES;
 				TARGETED_DEVICE_FAMILY = "1,2";
 			};
@@ -650,8 +651,9 @@
 				LIBRARY_SEARCH_PATHS = "$(inherited)";
 				PRODUCT_BUNDLE_IDENTIFIER = com.psiphon3.ios.PsiphonTunnel;
 				PRODUCT_NAME = "$(TARGET_NAME)";
+				REGISTER_APP_GROUPS = NO;
 				SKIP_INSTALL = YES;
-				SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
+				SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx";
 				SUPPORTS_MACCATALYST = YES;
 				TARGETED_DEVICE_FAMILY = "1,2";
 			};

+ 10 - 2
MobileLibrary/iOS/PsiphonTunnel/PsiphonTunnel/JailbreakCheck/JailbreakCheck.m

@@ -25,14 +25,17 @@
 
 
 #import <Foundation/Foundation.h>
-#import "UIKit/UIKit.h"
-#import <sys/stat.h>
 #import "JailbreakCheck.h"
+#if TARGET_OS_IPHONE
+#import <UIKit/UIKit.h>
+#import <sys/stat.h>
+#endif
 
 
 @implementation JailbreakCheck
 
 
+#if TARGET_OS_IPHONE
 BOOL checkReadWritePermissions()
 {
     // UIApplication:sharedApplication is disallowed in an application exetension
@@ -124,13 +127,18 @@ BOOL checkJailbreakFiles()
     
     return FALSE;
 }
+#endif
 
 + (BOOL)isDeviceJailbroken
 {
+#if TARGET_OS_IPHONE
     return
         checkJailbreakSymlinks()
         || checkJailbreakFiles()
         || checkReadWritePermissions();
+#else
+    return FALSE;
+#endif
 }
 
 @end

+ 18 - 0
MobileLibrary/iOS/PsiphonTunnel/PsiphonTunnel/Network/NetworkID.m

@@ -49,6 +49,21 @@
     NSMutableString *networkID = [NSMutableString stringWithString:@"UNKNOWN"];
     if (currentNetworkStatus == NetworkReachabilityReachableViaWiFi) {
         [networkID setString:@"WIFI"];
+#if TARGET_OS_MAC && !TARGET_OS_IPHONE
+        NSError *err;
+        NSString *activeInterfaceAddress =
+            [NetworkInterface getActiveInterfaceAddressWithReachability:reachability
+                                                andCurrentNetworkStatus:currentNetworkStatus
+                                                                  error:&err];
+        if (err != nil) {
+            NSString *localizedDescription = [NSString stringWithFormat:@"error getting active interface address %@", err.localizedDescription];
+            *outWarn = [[NSError alloc] initWithDomain:@"PsiphonTunnelError"
+                                                  code:1
+                                              userInfo:@{NSLocalizedDescriptionKey:localizedDescription}];
+            return networkID;
+        }
+        [networkID appendFormat:@"-%@", activeInterfaceAddress];
+#else
         NSArray *networkInterfaceNames = (__bridge_transfer id)CNCopySupportedInterfaces();
         for (NSString *networkInterfaceName in networkInterfaceNames) {
             NSDictionary *networkInterfaceInfo = (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)networkInterfaceName);
@@ -56,9 +71,11 @@
                 [networkID appendFormat:@"-%@", networkInterfaceInfo[(__bridge NSString*)kCNNetworkInfoKeyBSSID]];
             }
         }
+#endif
     } else if (currentNetworkStatus == NetworkReachabilityReachableViaCellular) {
         [networkID setString:@"MOBILE"];
 
+#if TARGET_OS_IOS
         if (@available(iOS 16.0, *)) {
             // Testing showed that the IP address of the active interface uniquely identified the
             // corresponding network and did not change over long periods of time, which makes it a
@@ -87,6 +104,7 @@
                 [networkID appendFormat:@"-%@-%@", mcc, mnc];
             }
         }
+#endif
     } else if (currentNetworkStatus == NetworkReachabilityReachableViaWired) {
         [networkID setString:@"WIRED"];
 

+ 10 - 1
MobileLibrary/iOS/PsiphonTunnel/PsiphonTunnel/Network/Reachability/Reachability.m

@@ -174,6 +174,7 @@ static void ReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReach
         }
     }
 
+#if TARGET_OS_IOS
 	if ((flags & kSCNetworkReachabilityFlagsIsWWAN) == kSCNetworkReachabilityFlagsIsWWAN)
 	{
 		/*
@@ -181,6 +182,7 @@ static void ReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReach
          */
 		returnValue = ReachableViaWWAN;
 	}
+#endif
     
 	return returnValue;
 }
@@ -218,10 +220,17 @@ static void ReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReach
 {
 	NSAssert(_reachabilityRef != NULL, @"currentReachabilityFlags called with NULL SCNetworkReachabilityRef");
 	SCNetworkReachabilityFlags flags;
+    
 
 	if (SCNetworkReachabilityGetFlags(_reachabilityRef, &flags)) {
+#if TARGET_OS_IOS
+        BOOL isWWAN = flags & kSCNetworkReachabilityFlagsIsWWAN;
+#else
+        BOOL isWWAN = FALSE;
+#endif
+        
 		return [NSString stringWithFormat:@"%c%c %c%c%c%c%c%c%c",
-				(flags & kSCNetworkReachabilityFlagsIsWWAN)               ? 'W' : '-',
+                (isWWAN)                                                  ? 'W' : '-',
 				(flags & kSCNetworkReachabilityFlagsReachable)            ? 'R' : '-',
 
 				(flags & kSCNetworkReachabilityFlagsTransientConnection)  ? 't' : '-',

Разница между файлами не показана из-за своего большого размера
+ 0 - 0
MobileLibrary/iOS/PsiphonTunnel/PsiphonTunnel/PsiphonTunnel.m


+ 38 - 6
MobileLibrary/iOS/PsiphonTunnel/PsiphonTunnel/Utils/PsiphonClientPlatform.m

@@ -18,7 +18,11 @@
  */
 
 #import "PsiphonClientPlatform.h"
+#if TARGET_OS_IOS
 #import <UIKit/UIKit.h>
+#elif TARGET_OS_OSX
+#import <AppKit/AppKit.h>
+#endif
 #import "JailbreakCheck.h"
 
 @implementation PsiphonClientPlatform
@@ -43,9 +47,20 @@
     }
 
     // Like "10.2.1"
-    NSString *systemVersion = [[[[UIDevice currentDevice]systemVersion]
-                                stringByReplacingOccurrencesOfString:@"_" withString:@"-"]
-                               stringByReplacingOccurrencesOfString:@" " withString:@"-"];
+    NSString *systemVersion;
+#if TARGET_OS_IOS
+    systemVersion = [[[[UIDevice currentDevice]systemVersion]
+                      stringByReplacingOccurrencesOfString:@"_" withString:@"-"]
+                     stringByReplacingOccurrencesOfString:@" " withString:@"-"];
+#elif TARGET_OS_OSX
+    NSOperatingSystemVersion osVersion = [[NSProcessInfo processInfo] operatingSystemVersion];
+    systemVersion = [NSString stringWithFormat:@"%ld.%ld.%ld", 
+                    (long)osVersion.majorVersion, 
+                    (long)osVersion.minorVersion, 
+                    (long)osVersion.patchVersion];
+#else
+    systemVersion = @"unknown";
+#endif
 
     // Like "com.psiphon3.browser"
     NSString *bundleIdentifier = [[[[NSBundle mainBundle] bundleIdentifier]
@@ -76,20 +91,26 @@
 
     } else {
 
+        NSString *systemName;
+#if TARGET_OS_IOS
         // iOS build running on iOS device.
-
         // Like "iOS". Older iOS reports "iPhone OS", which we will convert.
-        NSString *systemName = [[UIDevice currentDevice] systemName];
-
+        systemName = [[UIDevice currentDevice] systemName];
         if ([systemName isEqual: @"iPhone OS"]) {
             systemName = @"iOS";
         }
+#elif TARGET_OS_OSX
+        systemName = @"macOS";
+#else
+        systemName = @"unknown";
+#endif
         systemName = [[systemName
                        stringByReplacingOccurrencesOfString:@"_" withString:@"-"]
                       stringByReplacingOccurrencesOfString:@" " withString:@"-"];
 
         // Note that on Macs, users have root access, unlike iOS, where
         // the user has to jailbreak the device to get root access.
+#if TARGET_OS_IOS
         NSString *jailbroken = nil;
         if ([JailbreakCheck isDeviceJailbroken] == TRUE) {
             jailbroken = @"jailbroken";
@@ -102,6 +123,17 @@
                 systemVersion,
                 jailbroken,
                 bundleIdentifier];
+#elif TARGET_OS_OSX
+        return [NSString stringWithFormat:@"%@_%@_%@",
+                systemName,
+                systemVersion,
+                bundleIdentifier];
+#else
+        return [NSString stringWithFormat:@"%@_%@_%@",
+                systemName,
+                systemVersion,
+                bundleIdentifier];
+#endif
 
     }
 

+ 5 - 2
MobileLibrary/iOS/build-psiphon-framework.sh

@@ -209,11 +209,12 @@ function xcodebuild_for_platform() {
 }
 
 #
-# Build the PsiphonTunnel.framework for iOS, iOS Simulator, and Mac Catalyst.
+# Build the PsiphonTunnel.framework for iOS, iOS Simulator, Mac Catalyst and macOS.
 #
 
-gomobile_build_for_platform "-target 'ios,iossimulator' -iosversion '10.0'"
+gomobile_build_for_platform "-target 'macos,ios,iossimulator' -iosversion '10.0'"
 xcodebuild_for_platform "ios.xcarchive" " -destination 'generic/platform=iOS' EXCLUDED_ARCHS='armv7'"  # Excludes 32-bit ARM: EXCLUDED_ARCHS="armv7"
+xcodebuild_for_platform "macos.xcarchive" "-sdk macosx EXCLUDED_ARCHS='i386'"
 
 # While Network Extension doesn't work on a simulator, adding the simulator build
 # allows the framework users to build and run on simulators.
@@ -232,6 +233,8 @@ xcodebuild -create-xcframework \
 -debug-symbols "${BUILD_DIR}/iossimulator.xcarchive/dSYMs/PsiphonTunnel.framework.dSYM" \
 -framework "${BUILD_DIR}/maccatalyst.xcarchive/Products/Library/Frameworks/PsiphonTunnel.framework" \
 -debug-symbols "${BUILD_DIR}/maccatalyst.xcarchive/dSYMs/PsiphonTunnel.framework.dSYM" \
+-framework "${BUILD_DIR}/macos.xcarchive/Products/Library/Frameworks/PsiphonTunnel.framework" \
+-debug-symbols "${BUILD_DIR}/macos.xcarchive/dSYMs/PsiphonTunnel.framework.dSYM" \
 -output "${BUILD_DIR}/PsiphonTunnel.xcframework"
 
 # Jenkins loses symlinks from the framework directory, which results in a build

Некоторые файлы не были показаны из-за большого количества измененных файлов