-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1fdad20
commit 98891eb
Showing
14 changed files
with
755 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import Combine | ||
import Foundation | ||
|
||
/* | ||
case 1: return "Memory" | ||
case 2: return "JavaScriptCore" | ||
case 3: return "Fingerprints" | ||
case 4: | ||
return "Cellular Providers" | ||
*/ | ||
|
||
class DeviceInfoModel: ObservableObject { | ||
@Published var sections = [DeviceInfoSectionModel]() | ||
|
||
init() { | ||
Task { @MainActor in | ||
sections.append(UIDeviceInfoModel()) | ||
sections.append(ProcessInfoModel()) | ||
sections.append(MemoryInfoModel()) | ||
sections.append(JavaScriptInfoModel()) | ||
sections.append(CarrierInfoModel()) | ||
sections.append(FingerprintInfoModel()) | ||
self.reload() | ||
} | ||
} | ||
|
||
@MainActor func reload() { | ||
objectWillChange.send() | ||
sections.forEach { section in | ||
section.objectWillChange.send() | ||
section.reload() | ||
} | ||
} | ||
|
||
@MainActor func reloadFingerprints() { | ||
guard let finger = sections.first(where: { $0 as? FingerprintInfoModel != nil }) as? FingerprintInfoModel else { | ||
return | ||
} | ||
objectWillChange.send() | ||
finger.objectWillChange.send() | ||
finger.reload() | ||
} | ||
|
||
@MainActor func attachFingerprint(model: FingerPrintModel) { | ||
guard let finger = sections.first(where: { $0 as? FingerprintInfoModel != nil }) as? FingerprintInfoModel else { | ||
return | ||
} | ||
objectWillChange.send() | ||
model.parent = self | ||
finger.attachModel(model: model) | ||
Task { @MainActor in | ||
try await Task.sleep(nanoseconds: 1000) | ||
reload() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import SwiftUI | ||
|
||
class DeviceInfoSectionModel: ObservableObject, Identifiable { | ||
var title: String = "" | ||
@MainActor @Published var enabled: Bool = false | ||
@MainActor @Published var rows = [CopyCellView]() | ||
|
||
@MainActor func reload() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import CoreTelephony | ||
import SwiftUI | ||
|
||
class CarrierInfoModel: DeviceInfoSectionModel { | ||
private var getProviderTask: Task<Void, Never>? | ||
private var networkInfo: CTTelephonyNetworkInfo? | ||
private var providers: [String: CTCarrier]? | ||
|
||
override init() { | ||
super.init() | ||
title = "Cellular Providers" | ||
|
||
Task { | ||
await reload() | ||
} | ||
|
||
NotificationCenter.default.addObserver(self, selector: #selector(reload), name: NSNotification.Name.CTServiceRadioAccessTechnologyDidChange, object: nil) | ||
} | ||
|
||
@MainActor private func setEnabled(_ completion: (@MainActor() -> Void)? = nil) { | ||
getProviderTask?.cancel() | ||
getProviderTask = Task.detached(priority: .userInitiated) { | ||
self.networkInfo = CTTelephonyNetworkInfo() | ||
self.providers = self.networkInfo?.serviceSubscriberCellularProviders | ||
|
||
Task { @MainActor [weak self] in | ||
self?.objectWillChange.send() | ||
self?.enabled = (self?.providers?.count ?? 0) > 0 | ||
completion?() | ||
} | ||
} | ||
} | ||
|
||
@MainActor private func setRows() { | ||
rows.removeAll() | ||
|
||
guard enabled, let networkInfo = networkInfo, let providers = providers else { | ||
return | ||
} | ||
|
||
if let value = networkInfo.dataServiceIdentifier { | ||
rows.append(CopyCellView(title: "Data Service Identifier", content: value)) | ||
} | ||
|
||
if let value = networkInfo.serviceCurrentRadioAccessTechnology { | ||
for item in value { | ||
rows.append(CopyCellView(title: "Data Service \(item.key) Radio Access Technology", content: item.value)) | ||
} | ||
} | ||
|
||
for (i, carrier) in providers.enumerated() { | ||
if let name = carrier.value.carrierName { | ||
rows.append(CopyCellView(title: "Provider \(i) Carrier Name", content: name)) | ||
} | ||
rows.append(CopyCellView(title: "Provider \(i) Service", content: carrier.key)) | ||
rows.append(CopyCellView(title: "Provider \(i) Allows VOIP", content: carrier.value.allowsVOIP ? "Yes" : "No")) | ||
if let value = carrier.value.isoCountryCode { | ||
rows.append(CopyCellView(title: "Provider \(i) ISO Country Code", content: value)) | ||
} | ||
if let value = carrier.value.mobileCountryCode { | ||
rows.append(CopyCellView(title: "Provider \(i) Mobile Country Code", content: value)) | ||
} | ||
if let value = carrier.value.mobileNetworkCode { | ||
rows.append(CopyCellView(title: "Provider \(i) Mobile Network Code", content: value)) | ||
} | ||
} | ||
} | ||
|
||
@objc @MainActor override func reload() { | ||
setEnabled { [weak self] in | ||
self?.setRows() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import Combine | ||
import DeviceKit | ||
import SwiftUI | ||
|
||
class FingerprintInfoModel: DeviceInfoSectionModel { | ||
var models = [FingerPrintModel]() | ||
|
||
override init() { | ||
super.init() | ||
title = "Fingerprints" | ||
|
||
Task { @MainActor in | ||
reload() | ||
} | ||
} | ||
|
||
@MainActor func attachModel(model: FingerPrintModel) { | ||
if !models.contains(model) { | ||
models.append(model) | ||
reload() | ||
} | ||
} | ||
|
||
@MainActor override func reload() { | ||
enabled = models.count > 0 | ||
rows.removeAll() | ||
|
||
for (i, model) in models.enumerated() { | ||
rows.append(CopyCellView(title: "Fingerprint \(i)", content: model.fingerprint ?? "-")) | ||
} | ||
} | ||
} |
Oops, something went wrong.