Skip to content

Add compile time checks to detect Android #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/ParseSwift/Coding/AnyEncodable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ extension _AnyEncodable {
}
}

#if !os(Linux)
#if !os(Linux) && !os(Android)
private func encode(nsnumber: NSNumber, into container: inout SingleValueEncodingContainer) throws { // swiftlint:disable:this cyclomatic_complexity line_length
switch CFNumberGetType(nsnumber) {
case .charType:
Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/Internal/ParseHash.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by Corey Baker on 12/22/20.
// Copyright © 2020 Parse Community. All rights reserved.
//
#if !os(Linux)
#if !os(Linux) && !os(Android)
import Foundation
import CommonCrypto

Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/LiveQuery/LiveQuerySocket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by Corey Baker on 12/31/20.
// Copyright © 2020 Parse Community. All rights reserved.
//
#if !os(Linux)
#if !os(Linux) && !os(Android)
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by Corey Baker on 1/2/21.
// Copyright © 2021 Parse Community. All rights reserved.
//
#if !os(Linux)
#if !os(Linux) && !os(Android)
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by Corey Baker on 1/4/21.
// Copyright © 2021 Parse Community. All rights reserved.
//
#if !os(Linux)
#if !os(Linux) && !os(Android)
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by Corey Baker on 1/4/21.
// Copyright © 2021 Parse Community. All rights reserved.
//
#if !os(Linux)
#if !os(Linux) && !os(Android)
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
Expand Down
9 changes: 4 additions & 5 deletions Sources/ParseSwift/Objects/ParseInstallation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ extension ParseInstallation {
get {
guard let installationInMemory: CurrentInstallationContainer<Self> =
try? ParseStorage.shared.get(valueFor: ParseStorage.Keys.currentInstallation) else {
#if !os(Linux)
#if !os(Linux) && !os(Android)
guard let installationFromKeyChain: CurrentInstallationContainer<Self> =
try? KeychainStore.shared.get(valueFor: ParseStorage.Keys.currentInstallation)
else {
Expand Down Expand Up @@ -169,14 +169,14 @@ extension ParseInstallation {
= try? ParseStorage.shared.get(valueFor: ParseStorage.Keys.currentInstallation) else {
return
}
#if !os(Linux)
#if !os(Linux) && !os(Android)
try? KeychainStore.shared.set(currentInstallationInMemory, for: ParseStorage.Keys.currentInstallation)
#endif
}

internal static func deleteCurrentContainerFromKeychain() {
try? ParseStorage.shared.delete(valueFor: ParseStorage.Keys.currentInstallation)
#if !os(Linux)
#if !os(Linux) && !os(Android)
try? KeychainStore.shared.delete(valueFor: ParseStorage.Keys.currentInstallation)
#endif
}
Expand Down Expand Up @@ -215,7 +215,6 @@ extension ParseInstallation {
}

mutating func updateDeviceTypeFromDevice() {

if deviceType != ParseConstants.deviceType {
deviceType = ParseConstants.deviceType
}
Expand Down Expand Up @@ -255,7 +254,7 @@ extension ParseInstallation {
guard let appInfo = Bundle.main.infoDictionary else {
return
}
#if !os(Linux)
#if !os(Linux) && !os(Android)
#if TARGET_OS_MACCATALYST
// If using an Xcode new enough to know about Mac Catalyst:
// Mac Catalyst Apps use a prefix to the bundle ID. This should not be transmitted
Expand Down
6 changes: 3 additions & 3 deletions Sources/ParseSwift/Objects/ParseUser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ extension ParseUser {
get {
guard let currentUserInMemory: CurrentUserContainer<Self>
= try? ParseStorage.shared.get(valueFor: ParseStorage.Keys.currentUser) else {
#if !os(Linux)
#if !os(Linux) && !os(Android)
return try? KeychainStore.shared.get(valueFor: ParseStorage.Keys.currentUser)
#else
return nil
Expand All @@ -105,14 +105,14 @@ extension ParseUser {
= try? ParseStorage.shared.get(valueFor: ParseStorage.Keys.currentUser) else {
return
}
#if !os(Linux)
#if !os(Linux) && !os(Android)
try? KeychainStore.shared.set(currentUserInMemory, for: ParseStorage.Keys.currentUser)
#endif
}

internal static func deleteCurrentContainerFromKeychain() {
try? ParseStorage.shared.delete(valueFor: ParseStorage.Keys.currentUser)
#if !os(Linux)
#if !os(Linux) && !os(Android)
try? KeychainStore.shared.delete(valueFor: ParseStorage.Keys.currentUser)
#endif
BaseParseUser.currentUserContainer = nil
Expand Down
2 changes: 2 additions & 0 deletions Sources/ParseSwift/ParseConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ enum ParseConstants {
static let deviceType = "applewatch"
#elseif os(Linux)
static let deviceType = "linux"
#elseif os(Android)
static let deviceType = "android"
#endif
}
2 changes: 1 addition & 1 deletion Sources/ParseSwift/Protocols/Objectable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ extension Objectable {

static func createHash(_ object: Encodable) throws -> String {
let encoded = try ParseCoding.parseEncoder().encode(object)
#if !os(Linux)
#if !os(Linux) && !os(Android)
return ParseHash.md5HashFromData(encoded)
#else
guard let hashString = String(data: encoded, encoding: .utf8) else {
Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/Storage/KeychainStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Foundation
import Security
#endif

#if !os(Linux)
#if !os(Linux) && !os(Android)

func getKeychainQueryTemplate(forService service: String) -> [String: String] {
var query = [String: String]()
Expand Down
10 changes: 5 additions & 5 deletions Sources/ParseSwift/Storage/ParseFileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Foundation
internal struct ParseFileManager {

private var defaultDirectoryAttributes: [FileAttributeKey: Any]? {
#if os(macOS) || os(Linux)
#if os(macOS) || os(Linux) || os(Android)
return nil
#else
return [.protectionKey: FileProtectionType.completeUntilFirstUserAuthentication]
Expand All @@ -20,14 +20,14 @@ internal struct ParseFileManager {

private var defaultDataWritingOptions: Data.WritingOptions {
var options = Data.WritingOptions.atomic
#if !os(macOS) && !os(Linux)
#if !os(macOS) && !os(Linux) && !os(Android)
options.insert(.completeFileProtectionUntilFirstUserAuthentication)
#endif
return options
}

private var localSandBoxDataDirectoryPath: URL? {
#if os(macOS) || os(Linux)
#if os(macOS) || os(Linux) || os(Android)
return self.defaultDataDirectoryPath
#else
// swiftlint:disable:next line_length
Expand All @@ -49,7 +49,7 @@ internal struct ParseFileManager {
private let applicationGroupIdentifer: String?

public var defaultDataDirectoryPath: URL? {
#if os(macOS) || os(Linux)
#if os(macOS) || os(Linux) || os(Android)
var directoryPath: String!
let paths = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true)
guard let directory = paths.first else {
Expand Down Expand Up @@ -83,7 +83,7 @@ internal struct ParseFileManager {
}

init?() {
#if os(Linux)
#if os(Linux) || os(Android)
guard let applicationId = ParseConfiguration.applicationId else {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/Storage/ParseKeyValueStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ struct InMemoryKeyValueStore: ParseKeyValueStore {
}
}

#if !os(Linux)
#if !os(Linux) && !os(Android)

// MARK: KeychainStore + ParseKeyValueStore
extension KeychainStore: ParseKeyValueStore {
Expand Down
4 changes: 2 additions & 2 deletions Sources/ParseSwift/Types/ParseACL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ extension ParseACL {

let aclController: DefaultACL?

#if !os(Linux)
#if !os(Linux) && !os(Android)
aclController = try? KeychainStore.shared.get(valueFor: ParseStorage.Keys.defaultACL)
#else
aclController = try? ParseStorage.shared.get(valueFor: ParseStorage.Keys.defaultACL)
Expand Down Expand Up @@ -380,7 +380,7 @@ extension ParseACL {
useCurrentUser: withAccessForCurrentUser)
}

#if !os(Linux)
#if !os(Linux) && !os(Android)
try KeychainStore.shared.set(aclController, for: ParseStorage.Keys.defaultACL)
#else
try ParseStorage.shared.set(aclController, for: ParseStorage.Keys.defaultACL)
Expand Down
6 changes: 3 additions & 3 deletions Sources/ParseSwift/Types/ParseConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ extension ParseConfig {
get {
guard let configInMemory: CurrentConfigContainer<Self> =
try? ParseStorage.shared.get(valueFor: ParseStorage.Keys.currentConfig) else {
#if !os(Linux)
#if !os(Linux) && !os(Android)
return try? KeychainStore.shared.get(valueFor: ParseStorage.Keys.currentConfig)
#else
return nil
Expand Down Expand Up @@ -151,14 +151,14 @@ extension ParseConfig {
= try? ParseStorage.shared.get(valueFor: ParseStorage.Keys.currentConfig) else {
return
}
#if !os(Linux)
#if !os(Linux) && !os(Android)
try? KeychainStore.shared.set(currentConfigInMemory, for: ParseStorage.Keys.currentConfig)
#endif
}

internal static func deleteCurrentContainerFromKeychain() {
try? ParseStorage.shared.delete(valueFor: ParseStorage.Keys.currentConfig)
#if !os(Linux)
#if !os(Linux) && !os(Android)
try? KeychainStore.shared.delete(valueFor: ParseStorage.Keys.currentConfig)
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/ParseSwiftTests/APICommandTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class APICommandTests: XCTestCase {
override func tearDownWithError() throws {
try super.tearDownWithError()
MockURLProtocol.removeAll()
#if !os(Linux)
#if !os(Linux) && !os(Android)
try KeychainStore.shared.deleteAll()
#endif
try ParseStorage.shared.deleteAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class AnyCodableTests: XCTestCase {
}

//Test has objective-c
#if !os(Linux)
#if !os(Linux) && !os(Android)
func testJSONEncoding() {
let dictionary: [String: AnyCodable] = [
"boolean": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import XCTest
@testable import ParseSwift

//Test has objective-c
#if !os(Linux)
#if !os(Linux) && !os(Android)
class AnyEncodableTests: XCTestCase {
func testJSONEncoding() {
let dictionary: [String: AnyEncodable] = [
Expand Down
2 changes: 1 addition & 1 deletion Tests/ParseSwiftTests/HashTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by Corey Baker on 12/22/20.
// Copyright © 2020 Parse Community. All rights reserved.
//
#if !os(Linux)
#if !os(Linux) && !os(Android)
import Foundation
import XCTest
@testable import ParseSwift
Expand Down
2 changes: 1 addition & 1 deletion Tests/ParseSwiftTests/KeychainStoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by Florent Vilmart on 17-09-25.
// Copyright © 2020 Parse Community. All rights reserved.
//
#if !os(Linux)
#if !os(Linux) && !os(Android)
import Foundation
import XCTest
@testable import ParseSwift
Expand Down
2 changes: 1 addition & 1 deletion Tests/ParseSwiftTests/ParseACLTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ParseACLTests: XCTestCase {
override func tearDownWithError() throws {
try super.tearDownWithError()
MockURLProtocol.removeAll()
#if !os(Linux)
#if !os(Linux) && !os(Android)
try KeychainStore.shared.deleteAll()
#endif
try ParseStorage.shared.deleteAll()
Expand Down
2 changes: 1 addition & 1 deletion Tests/ParseSwiftTests/ParseAnonymousCombineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class ParseAnonymousCombineTests: XCTestCase { // swiftlint:disable:this type_bo
override func tearDownWithError() throws {
try super.tearDownWithError()
MockURLProtocol.removeAll()
#if !os(Linux)
#if !os(Linux) && !os(Android)
try KeychainStore.shared.deleteAll()
#endif
try ParseStorage.shared.deleteAll()
Expand Down
4 changes: 2 additions & 2 deletions Tests/ParseSwiftTests/ParseAnonymousTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class ParseAnonymousTests: XCTestCase {
override func tearDownWithError() throws {
try super.tearDownWithError()
MockURLProtocol.removeAll()
#if !os(Linux)
#if !os(Linux) && !os(Android)
try KeychainStore.shared.deleteAll()
#endif
try ParseStorage.shared.deleteAll()
Expand Down Expand Up @@ -430,7 +430,7 @@ class ParseAnonymousTests: XCTestCase {
XCTAssertEqual(User.current?.updatedAt, becomeUpdatedAt)
XCTAssertFalse(User.anonymous.isLinked)

#if !os(Linux)
#if !os(Linux) && !os(Android)
//Should be updated in Keychain
guard let keychainUser: CurrentUserContainer<BaseParseUser>
= try? KeychainStore.shared.get(valueFor: ParseStorage.Keys.currentUser) else {
Expand Down
2 changes: 1 addition & 1 deletion Tests/ParseSwiftTests/ParseAppleCombineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ParseAppleCombineTests: XCTestCase { // swiftlint:disable:this type_body_l
override func tearDownWithError() throws {
try super.tearDownWithError()
MockURLProtocol.removeAll()
#if !os(Linux)
#if !os(Linux) && !os(Android)
try KeychainStore.shared.deleteAll()
#endif
try ParseStorage.shared.deleteAll()
Expand Down
2 changes: 1 addition & 1 deletion Tests/ParseSwiftTests/ParseAppleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class ParseAppleTests: XCTestCase {
override func tearDownWithError() throws {
try super.tearDownWithError()
MockURLProtocol.removeAll()
#if !os(Linux)
#if !os(Linux) && !os(Android)
try KeychainStore.shared.deleteAll()
#endif
try ParseStorage.shared.deleteAll()
Expand Down
2 changes: 1 addition & 1 deletion Tests/ParseSwiftTests/ParseAuthenticationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class ParseAuthenticationTests: XCTestCase {
override func tearDownWithError() throws {
try super.tearDownWithError()
MockURLProtocol.removeAll()
#if !os(Linux)
#if !os(Linux) && !os(Android)
try KeychainStore.shared.deleteAll()
#endif
try ParseStorage.shared.deleteAll()
Expand Down
2 changes: 1 addition & 1 deletion Tests/ParseSwiftTests/ParseCloudCombineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ParseCloudCombineTests: XCTestCase { // swiftlint:disable:this type_body_l
override func tearDownWithError() throws {
try super.tearDownWithError()
MockURLProtocol.removeAll()
#if !os(Linux)
#if !os(Linux) && !os(Android)
try KeychainStore.shared.deleteAll()
#endif
try ParseStorage.shared.deleteAll()
Expand Down
2 changes: 1 addition & 1 deletion Tests/ParseSwiftTests/ParseCloudTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class ParseCloudTests: XCTestCase { // swiftlint:disable:this type_body_length
override func tearDownWithError() throws {
try super.tearDownWithError()
MockURLProtocol.removeAll()
#if !os(Linux)
#if !os(Linux) && !os(Android)
try KeychainStore.shared.deleteAll()
#endif
try ParseStorage.shared.deleteAll()
Expand Down
6 changes: 3 additions & 3 deletions Tests/ParseSwiftTests/ParseConfigCombineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class ParseConfigCombineTests: XCTestCase { // swiftlint:disable:this type_body_
override func tearDownWithError() throws {
try super.tearDownWithError()
MockURLProtocol.removeAll()
#if !os(Linux)
#if !os(Linux) && !os(Android)
try KeychainStore.shared.deleteAll()
#endif
try ParseStorage.shared.deleteAll()
Expand Down Expand Up @@ -147,7 +147,7 @@ class ParseConfigCombineTests: XCTestCase { // swiftlint:disable:this type_body_
XCTAssertEqual(fetched.welcomeMessage, configOnServer.welcomeMessage)
XCTAssertEqual(Config.current?.welcomeMessage, configOnServer.welcomeMessage)

#if !os(Linux)
#if !os(Linux) && !os(Android)
//Should be updated in Keychain
guard let keychainConfig: CurrentConfigContainer<Config>
= try? KeychainStore.shared.get(valueFor: ParseStorage.Keys.currentConfig) else {
Expand Down Expand Up @@ -196,7 +196,7 @@ class ParseConfigCombineTests: XCTestCase { // swiftlint:disable:this type_body_
XCTAssertTrue(saved)
XCTAssertEqual(Config.current?.welcomeMessage, config.welcomeMessage)

#if !os(Linux)
#if !os(Linux) && !os(Android)
//Should be updated in Keychain
guard let keychainConfig: CurrentConfigContainer<Config>
= try? KeychainStore.shared.get(valueFor: ParseStorage.Keys.currentConfig) else {
Expand Down
Loading