From 5bfa68dddcf7cea1ffb50a54ae967ef00274909b Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Sat, 28 Feb 2026 13:53:57 -0500 Subject: [PATCH 1/7] Add documentation and availability annotations --- .../AndroidOS/BadParcelableException.swift | 4 + Sources/AndroidOS/BaseBundle.swift | 54 ++++++++ Sources/AndroidOS/BatteryManager.swift | 10 ++ Sources/AndroidOS/Binder.swift | 86 +++++++++++++ .../BugreportManager+BugreportCallback.swift | 10 ++ Sources/AndroidOS/BugreportManager.swift | 8 ++ Sources/AndroidOS/Build+Partition.swift | 8 ++ Sources/AndroidOS/Build+VERSION.swift | 34 +++++ Sources/AndroidOS/Build+VERSION_CODES.swift | 40 ++++++ Sources/AndroidOS/Build.swift | 75 +++++++++++ Sources/AndroidOS/Bundle.swift | 107 ++++++++++++++++ .../CancellationSignal+OnCancelListener.swift | 12 +- Sources/AndroidOS/CancellationSignal.swift | 22 ++++ .../AndroidOS/CleartextNetworkViolation.swift | 4 + ...ombinedVibration+ParallelCombination.swift | 14 +++ Sources/AndroidOS/CombinedVibration.swift | 13 ++ Sources/AndroidOS/ConditionVariable.swift | 14 +++ ...ContentUriWithoutPermissionViolation.swift | 4 + Sources/AndroidOS/CountDownTimer.swift | 16 +++ Sources/AndroidOS/CpuUsageInfo.swift | 7 ++ ...dentialProtectedWhileLockedViolation.swift | 4 + Sources/AndroidOS/CustomViolation.swift | 4 + Sources/AndroidOS/DeadObjectException.swift | 4 + Sources/AndroidOS/DeadSystemException.swift | 5 + .../AndroidOS/Debug+InstructionCount.swift | 5 + Sources/AndroidOS/Debug+MemoryInfo.swift | 7 ++ Sources/AndroidOS/Debug.swift | 6 + Sources/AndroidOS/DiskReadViolation.swift | 4 + Sources/AndroidOS/DiskWriteViolation.swift | 4 + Sources/AndroidOS/DropBoxManager+Entry.swift | 18 +++ Sources/AndroidOS/DropBoxManager.swift | 14 +++ Sources/AndroidOS/Environment.swift | 38 ++++++ Sources/AndroidOS/FileObserver.swift | 22 ++++ .../AndroidOS/FileUriExposedException.swift | 5 + .../AndroidOS/FileUriExposedViolation.swift | 4 + Sources/AndroidOS/FileUtils.swift | 9 ++ Sources/AndroidOS/Handler+Callback.swift | 7 ++ Sources/AndroidOS/Handler.swift | 115 +++++++++++++++++ Sources/AndroidOS/HandlerThread.swift | 4 + .../AndroidOS/HardwarePropertiesManager.swift | 14 +++ Sources/AndroidOS/HealthStats.swift | 7 ++ .../AndroidOS/IBinder+DeathRecipient.swift | 5 + Sources/AndroidOS/IBinder.swift | 73 +++++++++++ Sources/AndroidOS/IInterface.swift | 8 ++ .../ImplicitDirectBootViolation.swift | 4 + .../IncorrectContextUseViolation.swift | 5 + .../AndroidOS/InstanceCountViolation.swift | 6 + .../IntentReceiverLeakedViolation.swift | 4 + .../AndroidOS/LeakedClosableViolation.swift | 4 + .../AndroidOS/LimitExceededException.swift | 5 + Sources/AndroidOS/LocaleList.swift | 20 +++ Sources/AndroidOS/Looper.swift | 44 +++++++ Sources/AndroidOS/MemoryFile.swift | 16 +++ Sources/AndroidOS/Message.swift | 68 ++++++++++ .../AndroidOS/MessageQueue+IdleHandler.swift | 7 ++ ...eQueue+OnFileDescriptorEventListener.swift | 12 ++ Sources/AndroidOS/MessageQueue.swift | 30 +++++ Sources/AndroidOS/Messenger.swift | 7 ++ .../NetworkOnMainThreadException.swift | 5 + Sources/AndroidOS/NetworkViolation.swift | 4 + .../AndroidOS/NonSdkApiUsedViolation.swift | 4 + .../AndroidOS/OnObbStateChangeListener.swift | 9 ++ .../OperationCanceledException.swift | 5 + Sources/AndroidOS/OutcomeReceiver.swift | 9 ++ Sources/AndroidOS/PackageHealthStats.swift | 7 ++ Sources/AndroidOS/Parcel.swift | 19 +++ ...lFileDescriptor+AutoCloseInputStream.swift | 5 + ...FileDescriptor+AutoCloseOutputStream.swift | 5 + ...ptor+FileDescriptorDetachedException.swift | 4 + ...ParcelFileDescriptor+OnCloseListener.swift | 7 ++ Sources/AndroidOS/ParcelFileDescriptor.swift | 30 +++++ Sources/AndroidOS/ParcelFormatException.swift | 4 + .../Parcelable+ClassLoaderCreator.swift | 11 ++ Sources/AndroidOS/Parcelable+Creator.swift | 13 ++ Sources/AndroidOS/Parcelable.swift | 47 +++++++ Sources/AndroidOS/PatternMatcher.swift | 9 ++ .../PerformanceHintManager+Session.swift | 7 ++ .../AndroidOS/PerformanceHintManager.swift | 9 ++ Sources/AndroidOS/PersistableBundle.swift | 22 ++++ Sources/AndroidOS/PidHealthStats.swift | 7 ++ ...nager+OnThermalStatusChangedListener.swift | 8 ++ Sources/AndroidOS/PowerManager+WakeLock.swift | 27 ++++ .../PowerManager+WakeLockStateListener.swift | 8 ++ Sources/AndroidOS/PowerManager.swift | 119 ++++++++++++++++++ Sources/AndroidOS/Process.swift | 79 ++++++++++++ Sources/AndroidOS/ProcessHealthStats.swift | 7 ++ .../RecoverySystem+ProgressListener.swift | 7 ++ Sources/AndroidOS/RecoverySystem.swift | 10 ++ Sources/AndroidOS/RemoteException.swift | 8 ++ .../AndroidOS/ResourceMismatchViolation.swift | 4 + Sources/AndroidOS/ResultReceiver.swift | 17 +++ Sources/AndroidOS/SdkExtensions.swift | 11 ++ .../ServiceConnectionLeakedViolation.swift | 4 + Sources/AndroidOS/ServiceHealthStats.swift | 7 ++ Sources/AndroidOS/SharedMemory.swift | 5 + .../SqliteObjectLeakedViolation.swift | 4 + Sources/AndroidOS/StatFs.swift | 15 +++ ...StorageManager+StorageVolumeCallback.swift | 5 + Sources/AndroidOS/StorageManager.swift | 30 +++++ Sources/AndroidOS/StorageVolume.swift | 13 ++ ...StrictMode+OnThreadViolationListener.swift | 5 + .../StrictMode+OnVmViolationListener.swift | 5 + .../StrictMode+ThreadPolicy+Builder.swift | 28 +++++ .../AndroidOS/StrictMode+ThreadPolicy.swift | 6 + .../StrictMode+VmPolicy+Builder.swift | 30 +++++ Sources/AndroidOS/StrictMode+VmPolicy.swift | 6 + Sources/AndroidOS/StrictMode.swift | 13 ++ Sources/AndroidOS/SystemClock.swift | 51 ++++++++ Sources/AndroidOS/SystemHealthManager.swift | 6 + Sources/AndroidOS/TimerStat.swift | 7 ++ Sources/AndroidOS/TokenWatcher.swift | 17 +++ Sources/AndroidOS/Trace.swift | 43 +++++++ .../TransactionTooLargeException.swift | 6 + Sources/AndroidOS/UidHealthStats.swift | 7 ++ Sources/AndroidOS/UnbufferedIoViolation.swift | 4 + .../UnsafeIntentLaunchViolation.swift | 4 + .../AndroidOS/UntaggedSocketViolation.swift | 4 + Sources/AndroidOS/UserHandle.swift | 11 ++ .../VibrationAttributes+Builder.swift | 18 +++ Sources/AndroidOS/VibrationAttributes.swift | 38 ++++++ .../VibrationEffect+Composition.swift | 35 ++++++ Sources/AndroidOS/VibrationEffect.swift | 48 +++++++ Sources/AndroidOS/Vibrator.swift | 65 ++++++++++ Sources/AndroidOS/VibratorManager.swift | 24 ++++ Sources/AndroidOS/Violation.swift | 7 ++ ...ewMethodCalledOnWrongThreadViolation.swift | 4 + Sources/AndroidOS/WorkSource.swift | 6 + 127 files changed, 2286 insertions(+), 2 deletions(-) diff --git a/Sources/AndroidOS/BadParcelableException.swift b/Sources/AndroidOS/BadParcelableException.swift index 4f10635b..243e791d 100644 --- a/Sources/AndroidOS/BadParcelableException.swift +++ b/Sources/AndroidOS/BadParcelableException.swift @@ -2,6 +2,10 @@ import SwiftJava import CSwiftJavaJNI +/// Thrown when a `Parcelable` encounters an error during marshalling or unmarshalling, +/// such as when a class cannot be found or data is malformed. +/// +/// See also: [android.os.BadParcelableException](https://developer.android.com/reference/android/os/BadParcelableException) @JavaClass("android.os.BadParcelableException") open class BadParcelableException: RuntimeException { @JavaMethod diff --git a/Sources/AndroidOS/BaseBundle.swift b/Sources/AndroidOS/BaseBundle.swift index 55a0326f..b5c2a60c 100644 --- a/Sources/AndroidOS/BaseBundle.swift +++ b/Sources/AndroidOS/BaseBundle.swift @@ -2,104 +2,158 @@ import SwiftJava import CSwiftJavaJNI +/// A mapping from String keys to values of various types. The only types currently supported +/// are: Boolean, Int, Long, Double, String, and arrays of each of these types. +/// +/// This is the base class for `Bundle` and `PersistableBundle`. +/// +/// See also: [android.os.BaseBundle](https://developer.android.com/reference/android/os/BaseBundle) +@available(Android 21, *) @JavaClass("android.os.BaseBundle") open class BaseBundle: JavaObject { + /// Inserts a String value into the mapping, replacing any existing value for the given key. @JavaMethod open func putString(_ arg0: String, _ arg1: String) + /// Inserts a boolean array value into the mapping. @JavaMethod open func putBooleanArray(_ arg0: String, _ arg1: [Bool]) + /// Inserts an int array value into the mapping. @JavaMethod open func putIntArray(_ arg0: String, _ arg1: [Int32]) + /// Inserts a long array value into the mapping. @JavaMethod open func putLongArray(_ arg0: String, _ arg1: [Int64]) + /// Inserts a double array value into the mapping. @JavaMethod open func putDoubleArray(_ arg0: String, _ arg1: [Double]) + /// Inserts a String array value into the mapping. @JavaMethod open func putStringArray(_ arg0: String, _ arg1: [String]) + /// Returns the value associated with the given key, or nil if no mapping of the desired type + /// exists for the given key. @JavaMethod open func getBooleanArray(_ arg0: String) -> [Bool] + /// Returns the value associated with the given key, or nil if no mapping of the desired type + /// exists for the given key. @JavaMethod open func getIntArray(_ arg0: String) -> [Int32] + /// Returns the value associated with the given key, or nil if no mapping of the desired type + /// exists for the given key. @JavaMethod open func getLongArray(_ arg0: String) -> [Int64] + /// Returns the value associated with the given key, or nil if no mapping of the desired type + /// exists for the given key. @JavaMethod open func getDoubleArray(_ arg0: String) -> [Double] + /// Removes any entry with the given key from the mapping. @JavaMethod open func remove(_ arg0: String) + /// Returns the number of mappings contained in this Bundle. @JavaMethod open func size() -> Int32 + /// Returns the entry with the given key as an object. @JavaMethod open func get(_ arg0: String) -> JavaObject! + /// Returns the value associated with the given key, or `false` if no mapping of the desired type + /// exists for the given key. @JavaMethod open func getBoolean(_ arg0: String) -> Bool + /// Returns the value associated with the given key, or `arg1` if no mapping of the desired type + /// exists for the given key. @JavaMethod open func getBoolean(_ arg0: String, _ arg1: Bool) -> Bool + /// Inserts a Boolean value into the mapping. @JavaMethod open func putBoolean(_ arg0: String, _ arg1: Bool) + /// Returns the value associated with the given key, or `0` if no mapping of the desired type + /// exists for the given key. @JavaMethod open func getInt(_ arg0: String) -> Int32 + /// Returns the value associated with the given key, or `arg1` if no mapping of the desired type + /// exists for the given key. @JavaMethod open func getInt(_ arg0: String, _ arg1: Int32) -> Int32 + /// Inserts an int value into the mapping. @JavaMethod open func putInt(_ arg0: String, _ arg1: Int32) + /// Returns the value associated with the given key, or `arg1` if no mapping of the desired type + /// exists for the given key. @JavaMethod open func getLong(_ arg0: String, _ arg1: Int64) -> Int64 + /// Returns the value associated with the given key, or `0L` if no mapping of the desired type + /// exists for the given key. @JavaMethod open func getLong(_ arg0: String) -> Int64 + /// Inserts a long value into the mapping. @JavaMethod open func putLong(_ arg0: String, _ arg1: Int64) + /// Returns the value associated with the given key, or `arg1` if no mapping of the desired type + /// exists for the given key. @JavaMethod open func getDouble(_ arg0: String, _ arg1: Double) -> Double + /// Returns the value associated with the given key, or `0.0` if no mapping of the desired type + /// exists for the given key. @JavaMethod open func getDouble(_ arg0: String) -> Double + /// Inserts a double value into the mapping. @JavaMethod open func putDouble(_ arg0: String, _ arg1: Double) + /// Removes all elements from the mapping. @JavaMethod open func clear() + /// Returns true if the mapping is empty, false otherwise. @JavaMethod open func isEmpty() -> Bool + /// Inserts all mappings from the given `PersistableBundle` into this Bundle. @JavaMethod open func putAll(_ arg0: PersistableBundle?) + /// Returns a Set containing the Strings used as keys in this Bundle. @JavaMethod open func keySet() -> JavaSet! + /// Returns true if the given key is contained in the mapping. @JavaMethod open func containsKey(_ arg0: String) -> Bool + /// Returns the value associated with the given key, or nil if no mapping exists. @JavaMethod open func getStringArray(_ arg0: String) -> [String] + /// Returns the value associated with the given key, or nil if no mapping of the desired type + /// exists for the given key. @JavaMethod open func getString(_ arg0: String) -> String + /// Returns the value associated with the given key, or `arg1` if no mapping of the desired type + /// exists for the given key. @JavaMethod open func getString(_ arg0: String, _ arg1: String) -> String } diff --git a/Sources/AndroidOS/BatteryManager.swift b/Sources/AndroidOS/BatteryManager.swift index 666da593..8e5c461b 100644 --- a/Sources/AndroidOS/BatteryManager.swift +++ b/Sources/AndroidOS/BatteryManager.swift @@ -2,17 +2,27 @@ import SwiftJava import CSwiftJavaJNI +/// Provides information about battery state and charging status. +/// +/// Obtain an instance via `Context.getSystemService(Context.BATTERY_SERVICE)`. +/// +/// See [android.os.BatteryManager](https://developer.android.com/reference/android/os/BatteryManager) +@available(Android 21, *) @JavaClass("android.os.BatteryManager") open class BatteryManager: JavaObject { + /// Returns whether the device is currently charging. @JavaMethod open func isCharging() -> Bool + /// Returns an estimate of how long until the battery is fully charged, in milliseconds, or `-1` if unknown. @JavaMethod open func computeChargeTimeRemaining() -> Int64 + /// Returns the value of the given integer battery property (e.g., `BATTERY_PROPERTY_CAPACITY`). @JavaMethod open func getIntProperty(_ arg0: Int32) -> Int32 + /// Returns the value of the given long battery property (e.g., `BATTERY_PROPERTY_ENERGY_COUNTER`). @JavaMethod open func getLongProperty(_ arg0: Int32) -> Int64 } diff --git a/Sources/AndroidOS/Binder.swift b/Sources/AndroidOS/Binder.swift index f2ccdeae..8420b51e 100644 --- a/Sources/AndroidOS/Binder.swift +++ b/Sources/AndroidOS/Binder.swift @@ -4,47 +4,87 @@ import JavaLangIO import SwiftJava import CSwiftJavaJNI +/// Base class for a remotable object, the core part of a lightweight remote procedure call +/// mechanism defined by `IBinder`. This class is an implementation of IBinder that provides +/// standard local implementation of such an object. +/// +/// Most developers will not implement this class directly, instead using the aidl tool to +/// describe the desired interface, having it generate the appropriate Binder subclass. +/// +/// To use this class, create a subclass and implement `onTransact(int, Parcel, Parcel, int)`. +/// You can then send the object to another process and receive calls through the `transact()` +/// method, dispatching them to the appropriate action in `onTransact()`. +/// +/// See also: [android.os.Binder](https://developer.android.com/reference/android/os/Binder) @JavaClass("android.os.Binder", implements: IBinder.self) open class Binder: JavaObject { + /// Create a new Binder object with an interface descriptor. + @available(Android 29, *) @JavaMethod @_nonoverride public convenience init(_ arg0: String, environment: JNIEnvironment? = nil) + /// Create a new Binder object. @JavaMethod @_nonoverride public convenience init(environment: JNIEnvironment? = nil) + /// Convenience method for associating a specific interface with the Binder. After calling, + /// `queryLocalInterface(String)` will be implemented for you to return the given owner IInterface + /// when the corresponding descriptor is requested. @JavaMethod open func attachInterface(_ arg0: IInterface?, _ arg1: String) + /// Return the binder's interface descriptor. @JavaMethod open func getInterfaceDescriptor() -> String + /// Check to see if the object still exists. @JavaMethod open func pingBinder() -> Bool + /// Check to see if the process that the binder is in is still alive. @JavaMethod open func isBinderAlive() -> Bool + /// Use information supplied to `attachInterface()` to return the associated IInterface if it + /// matches the requested descriptor. @JavaMethod open func queryLocalInterface(_ arg0: String) -> IInterface! + /// Override this to perform the transaction. The default implementation returns false for + /// any code that is not recognized. You can also call the default implementation for any + /// code that is not handled by the subclass. + /// + /// - Parameter arg0: The action to perform. This should be a number between + /// `FIRST_CALL_TRANSACTION` and `LAST_CALL_TRANSACTION`. + /// - Parameter arg1: Marshalled data to read from. Must not be nil. + /// - Parameter arg2: Marshalled data to write to. May be nil if the caller does not expect a result. + /// - Parameter arg3: Additional operation flags. @JavaMethod open func onTransact(_ arg0: Int32, _ arg1: Parcel?, _ arg2: Parcel?, _ arg3: Int32) throws -> Bool + /// Implemented to call `dump(FileDescriptor, PrintWriter, String[])` asynchronously on a new thread. @JavaMethod open func dumpAsync(_ arg0: FileDescriptor?, _ arg1: [String]) + /// Default implementation reinterprets the flags argument, and if the `FLAG_ONEWAY` bit is set, + /// calls `onTransact(int, Parcel, Parcel, int)` for `INTERFACE_TRANSACTION`, otherwise calls + /// `onTransact(int, Parcel, Parcel, int)`. @JavaMethod open func transact(_ arg0: Int32, _ arg1: Parcel?, _ arg2: Parcel?, _ arg3: Int32) throws -> Bool + /// Local implementation is a no-op. @JavaMethod open func linkToDeath(_ arg0: IBinder.DeathRecipient?, _ arg1: Int32) + /// Local implementation is a no-op. @JavaMethod open func unlinkToDeath(_ arg0: IBinder.DeathRecipient?, _ arg1: Int32) -> Bool + /// Implemented to call `dump(FileDescriptor, String[])`. @JavaMethod open func dump(_ arg0: FileDescriptor?, _ arg1: PrintWriter?, _ arg2: [String]) + /// Print the object's state into the given stream. @JavaMethod open func dump(_ arg0: FileDescriptor?, _ arg1: [String]) } @@ -73,39 +113,85 @@ extension JavaClass { @JavaStaticField(isFinal: true) public var TWEET_TRANSACTION: Int32 + /// Return the PID of the process that sent you the current transaction that is being processed. + /// This is only available for calls into a Binder; it will be -1 for the initiating process. @JavaStaticMethod public func getCallingPid() -> Int32 + /// Return the Linux UID assigned to the process that sent you the current transaction that is + /// being processed. This is only available for calls into a Binder; it will be the UID of the + /// current process for the initiating process. @JavaStaticMethod public func getCallingUid() -> Int32 + /// Return the Linux UID assigned to the process that sent the current transaction being processed. + /// Unlike `getCallingUid()`, this throws `SecurityException` if the call is not being processed. + @available(Android 29, *) @JavaStaticMethod public func getCallingUidOrThrow() -> Int32 + /// Return the UserHandle assigned to the process that sent you the current transaction that is + /// being processed. + @available(Android 17, *) @JavaStaticMethod public func getCallingUserHandle() -> UserHandle! + /// Reset the identity of the incoming IPC on the current thread. + /// + /// This can be useful if, while handling an incoming call, you will be making outgoing calls + /// on other Binders and want your identity (and not the identity of the caller) to be used for + /// those calls. You can use `restoreCallingIdentity(long)` to restore the original identity + /// after making your calls. + /// + /// - Returns: A token that can be passed to `restoreCallingIdentity(long)` to restore the + /// previous identity. @JavaStaticMethod public func clearCallingIdentity() -> Int64 + /// Restore the identity of the incoming IPC on the current thread back to a previously identity + /// that was returned by `clearCallingIdentity()`. + /// + /// - Parameter arg0: The token returned by `clearCallingIdentity()`. @JavaStaticMethod public func restoreCallingIdentity(_ arg0: Int64) + /// Sets the work source for this thread. Any IPC made after this call will be attributed to the + /// given UID. + /// + /// - Returns: A token that can be passed to `restoreCallingWorkSource(long)` to restore the + /// previous work source. + @available(Android 29, *) @JavaStaticMethod public func setCallingWorkSourceUid(_ arg0: Int32) -> Int64 + /// Returns the work source set by the caller. + /// + /// Unlike `getCallingUid()`, this can be used from any thread. + @available(Android 29, *) @JavaStaticMethod public func getCallingWorkSourceUid() -> Int32 + /// Resets the work source, and returns a token to restore it later. + @available(Android 29, *) @JavaStaticMethod public func clearCallingWorkSource() -> Int64 + /// Restores the work source on this thread using a token previously returned by + /// `setCallingWorkSourceUid(int)` or `clearCallingWorkSource()`. + @available(Android 29, *) @JavaStaticMethod public func restoreCallingWorkSource(_ arg0: Int64) + /// Flush any Binder commands pending in the current thread to the kernel driver. + /// + /// This can be useful to call before performing an operation that may block for a long time, + /// to ensure that any pending object references have been released in order to prevent the + /// process from holding on to objects longer than it needs to. @JavaStaticMethod public func flushPendingCommands() + /// Add the calling thread to the IPC thread pool. This function does not return until the + /// current process is exiting. @JavaStaticMethod public func joinThreadPool() } diff --git a/Sources/AndroidOS/BugreportManager+BugreportCallback.swift b/Sources/AndroidOS/BugreportManager+BugreportCallback.swift index 2bec3131..c9425a0a 100644 --- a/Sources/AndroidOS/BugreportManager+BugreportCallback.swift +++ b/Sources/AndroidOS/BugreportManager+BugreportCallback.swift @@ -3,20 +3,30 @@ import SwiftJava import CSwiftJavaJNI extension BugreportManager { + /// Callback for receiving progress and completion notifications during bug report collection. + /// + /// See [android.os.BugreportManager.BugreportCallback](https://developer.android.com/reference/android/os/BugreportManager.BugreportCallback) + @available(Android 29, *) @JavaClass("android.os.BugreportManager$BugreportCallback") open class BugreportCallback: JavaObject { @JavaMethod @_nonoverride public convenience init(environment: JNIEnvironment? = nil) + /// Called periodically to report collection progress as a percentage from 0 to 100. @JavaMethod open func onProgress(_ arg0: Float) + /// Called if an error occurs during bug report collection. + /// + /// - Parameter arg0: One of the `BUGREPORT_ERROR_*` constants indicating the failure reason. @JavaMethod open func onError(_ arg0: Int32) + /// Called when the bug report has been successfully collected. @JavaMethod open func onFinished() + /// Called when the early section of the bug report (e.g., critical data) has been collected. @JavaMethod open func onEarlyReportFinished() } diff --git a/Sources/AndroidOS/BugreportManager.swift b/Sources/AndroidOS/BugreportManager.swift index 4244c5bb..c1145e15 100644 --- a/Sources/AndroidOS/BugreportManager.swift +++ b/Sources/AndroidOS/BugreportManager.swift @@ -2,8 +2,16 @@ import SwiftJava import CSwiftJavaJNI +/// Manages the collection of bug reports on the device. +/// +/// Obtain an instance via `Context.getSystemService(Context.BUGREPORT_SERVICE)`. +/// Callers must hold the `DUMP` permission. +/// +/// See [android.os.BugreportManager](https://developer.android.com/reference/android/os/BugreportManager) +@available(Android 29, *) @JavaClass("android.os.BugreportManager") open class BugreportManager: JavaObject { + /// Cancels any bug report currently in progress. @JavaMethod open func cancelBugreport() } diff --git a/Sources/AndroidOS/Build+Partition.swift b/Sources/AndroidOS/Build+Partition.swift index dd794c1d..e6b7546a 100644 --- a/Sources/AndroidOS/Build+Partition.swift +++ b/Sources/AndroidOS/Build+Partition.swift @@ -3,14 +3,21 @@ import SwiftJava import CSwiftJavaJNI extension Build { + /// Contains information about a partition that has a separate build fingerprint. + /// + /// See also: [android.os.Build.Partition](https://developer.android.com/reference/android/os/Build.Partition) + @available(Android 29, *) @JavaClass("android.os.Build$Partition") open class Partition: JavaObject { + /// Returns the fingerprint of the partition. @JavaMethod open func getFingerprint() -> String + /// Returns the time (in milliseconds since the UNIX epoch) at which this partition was built. @JavaMethod open func getBuildTimeMillis() -> Int64 + /// Returns the name of this partition, e.g. "system" or "vendor". @JavaMethod open func getName() -> String @@ -22,6 +29,7 @@ extension Build { } } extension JavaClass { + /// The name of the system partition. @JavaStaticField(isFinal: true) public var PARTITION_NAME_SYSTEM: String } diff --git a/Sources/AndroidOS/Build+VERSION.swift b/Sources/AndroidOS/Build+VERSION.swift index c7bbd31b..fa0566f6 100644 --- a/Sources/AndroidOS/Build+VERSION.swift +++ b/Sources/AndroidOS/Build+VERSION.swift @@ -3,6 +3,9 @@ import SwiftJava import CSwiftJavaJNI extension Build { + /// Various version strings for the current build. + /// + /// See also: [android.os.Build.VERSION](https://developer.android.com/reference/android/os/Build.VERSION) @JavaClass("android.os.Build$VERSION") open class VERSION: JavaObject { @JavaMethod @@ -10,36 +13,67 @@ extension Build { } } extension JavaClass { + /// The base OS build the product is based on. + @available(Android 23, *) @JavaStaticField(isFinal: true) public var BASE_OS: String + /// The current development codename, or the string "REL" if this is a release build. + @available(Android 4, *) @JavaStaticField(isFinal: true) public var CODENAME: String + /// The internal value used by the underlying source control to represent this build. @JavaStaticField(isFinal: true) public var INCREMENTAL: String + /// The media performance class of the device or 0 if none. + /// + /// If this value is not 0, the device conforms to the media performance class definition + /// of the SDK version that corresponds to this value. Possible values can be + /// `Build.VERSION_CODES.R` (30), `Build.VERSION_CODES.S` (31), or higher. + @available(Android 31, *) @JavaStaticField(isFinal: true) public var MEDIA_PERFORMANCE_CLASS: Int32 + /// The developer preview revision of a pre-release SDK. + /// + /// This field is always 0 on production platform builds/devices. If you're trying to detect + /// if you're running on a pre-release platform you should use `CODENAME` instead. + @available(Android 23, *) @JavaStaticField(isFinal: true) public var PREVIEW_SDK_INT: Int32 + /// The user-visible version string. For example, "1.0" or "3.4b5" or "XYZ". @JavaStaticField(isFinal: true) public var RELEASE: String + /// The version string we show to the user; can be the release version ("1.0") or the codename + /// for a development build. + @available(Android 30, *) @JavaStaticField(isFinal: true) public var RELEASE_OR_CODENAME: String + /// The version string shown to the user. May be a combination of `RELEASE` and `PREVIEW_SDK_INT`. + @available(Android 33, *) @JavaStaticField(isFinal: true) public var RELEASE_OR_PREVIEW_DISPLAY: String + /// The user-visible SDK version of the framework in its raw String representation. + /// + /// - Note: Deprecated since API 15. Use `SDK_INT` instead. @JavaStaticField(isFinal: true) public var SDK: String + /// The user-visible SDK version of the framework; its possible values are defined in + /// `Build.VERSION_CODES`. + @available(Android 4, *) @JavaStaticField(isFinal: true) public var SDK_INT: Int32 + /// The user-visible security patch level. This value represents the date when the device's + /// security patch was last updated, in the form "YYYY-MM-DD" (for example "2021-11-05"). + @available(Android 23, *) @JavaStaticField(isFinal: true) public var SECURITY_PATCH: String } diff --git a/Sources/AndroidOS/Build+VERSION_CODES.swift b/Sources/AndroidOS/Build+VERSION_CODES.swift index 3cdf3dba..4b5a8ae6 100644 --- a/Sources/AndroidOS/Build+VERSION_CODES.swift +++ b/Sources/AndroidOS/Build+VERSION_CODES.swift @@ -3,6 +3,11 @@ import SwiftJava import CSwiftJavaJNI extension Build { + /// Enumeration of the currently known SDK version codes. These are the values that can be found + /// in `Build.VERSION.SDK_INT`. Version numbers increment monotonically with each official + /// platform release. + /// + /// See also: [android.os.Build.VERSION_CODES](https://developer.android.com/reference/android/os/Build.VERSION_CODES) @JavaClass("android.os.Build$VERSION_CODES") open class VERSION_CODES: JavaObject { @JavaMethod @@ -10,105 +15,140 @@ extension Build { } } extension JavaClass { + /// April 2009: The original, first, version of Android. Yay! @JavaStaticField(isFinal: true) public var BASE: Int32 + /// February 2009: First Android update, officially called 1.1. @JavaStaticField(isFinal: true) public var BASE_1_1: Int32 + /// May 2009: Android 1.5, Cupcake. @JavaStaticField(isFinal: true) public var CUPCAKE: Int32 + /// Magic version number for a current development build, which has not yet turned into an + /// official release. Use this value to test against future API levels. @JavaStaticField(isFinal: true) public var CUR_DEVELOPMENT: Int32 + /// September 2009: Android 1.6, Donut. @JavaStaticField(isFinal: true) public var DONUT: Int32 + /// November 2009: Android 2.0, Eclair. @JavaStaticField(isFinal: true) public var ECLAIR: Int32 + /// December 2009: Android 2.0.1, Eclair. @JavaStaticField(isFinal: true) public var ECLAIR_0_1: Int32 + /// January 2010: Android 2.1, Eclair. @JavaStaticField(isFinal: true) public var ECLAIR_MR1: Int32 + /// May 2010: Android 2.2, Froyo. @JavaStaticField(isFinal: true) public var FROYO: Int32 + /// November 2010: Android 2.3, Gingerbread. @JavaStaticField(isFinal: true) public var GINGERBREAD: Int32 + /// February 2011: Android 2.3.3, Gingerbread MR1. @JavaStaticField(isFinal: true) public var GINGERBREAD_MR1: Int32 + /// February 2011: Android 3.0, Honeycomb. @JavaStaticField(isFinal: true) public var HONEYCOMB: Int32 + /// May 2011: Android 3.1, Honeycomb MR1. @JavaStaticField(isFinal: true) public var HONEYCOMB_MR1: Int32 + /// June 2011: Android 3.2, Honeycomb MR2. @JavaStaticField(isFinal: true) public var HONEYCOMB_MR2: Int32 + /// October 2011: Android 4.0, Ice Cream Sandwich. @JavaStaticField(isFinal: true) public var ICE_CREAM_SANDWICH: Int32 + /// December 2011: Android 4.0.3, Ice Cream Sandwich MR1. @JavaStaticField(isFinal: true) public var ICE_CREAM_SANDWICH_MR1: Int32 + /// June 2012: Android 4.1, Jelly Bean. @JavaStaticField(isFinal: true) public var JELLY_BEAN: Int32 + /// November 2012: Android 4.2, Jelly Bean MR1. @JavaStaticField(isFinal: true) public var JELLY_BEAN_MR1: Int32 + /// July 2013: Android 4.3, Jelly Bean MR2. @JavaStaticField(isFinal: true) public var JELLY_BEAN_MR2: Int32 + /// October 2013: Android 4.4, KitKat. @JavaStaticField(isFinal: true) public var KITKAT: Int32 + /// June 2014: Android 4.4W, KitKat for Wearables (Android Wear). @JavaStaticField(isFinal: true) public var KITKAT_WATCH: Int32 + /// November 2014: Android 5.0, Lollipop. @JavaStaticField(isFinal: true) public var LOLLIPOP: Int32 + /// March 2015: Android 5.1, Lollipop MR1. @JavaStaticField(isFinal: true) public var LOLLIPOP_MR1: Int32 + /// October 2015: Android 6.0, Marshmallow. @JavaStaticField(isFinal: true) public var M: Int32 + /// August 2016: Android 7.0, Nougat. @JavaStaticField(isFinal: true) public var N: Int32 + /// October 2016: Android 7.1, Nougat MR1. @JavaStaticField(isFinal: true) public var N_MR1: Int32 + /// August 2017: Android 8.0, Oreo. @JavaStaticField(isFinal: true) public var O: Int32 + /// December 2017: Android 8.1, Oreo MR1. @JavaStaticField(isFinal: true) public var O_MR1: Int32 + /// August 2018: Android 9, Pie. @JavaStaticField(isFinal: true) public var P: Int32 + /// September 2019: Android 10, Q. @JavaStaticField(isFinal: true) public var Q: Int32 + /// September 2020: Android 11, R. @JavaStaticField(isFinal: true) public var R: Int32 + /// October 2021: Android 12, S. @JavaStaticField(isFinal: true) public var S: Int32 + /// March 2022: Android 12L, S_V2 (also known as Sv2). @JavaStaticField(isFinal: true) public var S_V2: Int32 + /// August 2022: Android 13, Tiramisu. @JavaStaticField(isFinal: true) public var TIRAMISU: Int32 } diff --git a/Sources/AndroidOS/Build.swift b/Sources/AndroidOS/Build.swift index a22fe396..664c3896 100644 --- a/Sources/AndroidOS/Build.swift +++ b/Sources/AndroidOS/Build.swift @@ -2,102 +2,177 @@ import SwiftJava import CSwiftJavaJNI +/// Information about the current build, extracted from system properties. +/// +/// See also: [android.os.Build](https://developer.android.com/reference/android/os/Build) @JavaClass("android.os.Build") open class Build: JavaObject { @JavaMethod @_nonoverride public convenience init(environment: JNIEnvironment? = nil) } extension JavaClass { + /// The name of the underlying board, like "goldfish". @JavaStaticField(isFinal: true) public var BOARD: String + /// The system bootloader version number. + @available(Android 8, *) @JavaStaticField(isFinal: true) public var BOOTLOADER: String + /// The consumer-visible brand with which the product/hardware will be associated, if any. @JavaStaticField(isFinal: true) public var BRAND: String + /// The name of the instruction set (CPU type + ABI convention) of native code. + /// + /// - Note: Deprecated since API 21. Use `SUPPORTED_ABIS` instead. + @available(Android 4, *) @JavaStaticField(isFinal: true) public var CPU_ABI: String + /// The name of the second instruction set (CPU type + ABI convention) of native code. + /// + /// - Note: Deprecated since API 21. Use `SUPPORTED_ABIS` instead. + @available(Android 8, *) @JavaStaticField(isFinal: true) public var CPU_ABI2: String + /// The name of the industrial design. @JavaStaticField(isFinal: true) public var DEVICE: String + /// A build ID string meant for displaying to the user. @JavaStaticField(isFinal: true) public var DISPLAY: String + /// A string that uniquely identifies this build. @JavaStaticField(isFinal: true) public var FINGERPRINT: String + /// The name of the hardware (from the kernel command line or /proc). + @available(Android 8, *) @JavaStaticField(isFinal: true) public var HARDWARE: String + /// A string that uniquely identifies the host that produced the build. @JavaStaticField(isFinal: true) public var HOST: String + /// Either a changelist number, or a label like "M4-rc20". @JavaStaticField(isFinal: true) public var ID: String + /// The manufacturer of the product/hardware. + @available(Android 4, *) @JavaStaticField(isFinal: true) public var MANUFACTURER: String + /// The end-user-visible name for the end product. @JavaStaticField(isFinal: true) public var MODEL: String + /// The SKU of the hardware as defined by the original design manufacturer (ODM). + @available(Android 31, *) @JavaStaticField(isFinal: true) public var ODM_SKU: String + /// The name of the overall product. @JavaStaticField(isFinal: true) public var PRODUCT: String + /// The radio firmware version number. + /// + /// - Note: Deprecated since API 15. Use `getRadioVersion()` instead. @JavaStaticField(isFinal: true) public var RADIO: String + /// A hardware serial number, if available. Alphanumeric only, case-insensitive. + /// + /// - Note: Deprecated since API 26. Use `getSerial()` instead. + @available(Android 9, *) @JavaStaticField(isFinal: true) public var SERIAL: String + /// The SKU of the hardware as defined by the original design manufacturer (ODM) for Google. + @available(Android 31, *) @JavaStaticField(isFinal: true) public var SKU: String + /// The manufacturer of the System-on-Chip (SoC). + @available(Android 31, *) @JavaStaticField(isFinal: true) public var SOC_MANUFACTURER: String + /// The model of the System-on-Chip (SoC). + @available(Android 31, *) @JavaStaticField(isFinal: true) public var SOC_MODEL: String + /// An ordered list of **32 bit** ABIs supported by this device. + /// + /// The most preferred ABI is the first element in the list. + @available(Android 21, *) @JavaStaticField(isFinal: true) public var SUPPORTED_32_BIT_ABIS: [String] + /// An ordered list of **64 bit** ABIs supported by this device. + /// + /// The most preferred ABI is the first element in the list. + @available(Android 21, *) @JavaStaticField(isFinal: true) public var SUPPORTED_64_BIT_ABIS: [String] + /// An ordered list of ABIs supported by this device. + /// + /// The most preferred ABI is the first element in the list. + @available(Android 21, *) @JavaStaticField(isFinal: true) public var SUPPORTED_ABIS: [String] + /// Comma-separated tags describing the build, like "unsigned,debug". @JavaStaticField(isFinal: true) public var TAGS: String + /// The time at which the build was produced, given in milliseconds since the UNIX epoch. @JavaStaticField(isFinal: true) public var TIME: Int64 + /// The type of build, like "user" or "eng". @JavaStaticField(isFinal: true) public var TYPE: String + /// Value used for when a build property is unknown. @JavaStaticField(isFinal: true) public var UNKNOWN: String + /// The username that produced the build. @JavaStaticField(isFinal: true) public var USER: String + /// Gets the hardware serial number, if available. + /// + /// Requires the `READ_PRIVILEGED_PHONE_STATE` permission, or for the calling app to be the device + /// or profile owner and have the `READ_PHONE_STATE` permission. + /// + /// - Returns: The hardware serial number if available, `UNKNOWN` otherwise. + @available(Android 26, *) @JavaStaticMethod public func getSerial() -> String + /// Returns information about the partitions that have a separate fingerprint defined. + /// + /// - Returns: A list of `Build.Partition` objects for all partitions with fingerprints. + @available(Android 29, *) @JavaStaticMethod public func getFingerprintedPartitions() -> List! + /// Returns the version string for the radio firmware. + /// + /// May return `nil`. (Replaces the deprecated `RADIO` constant.) + /// + /// - Returns: The radio firmware version, or `nil` if not available. + @available(Android 14, *) @JavaStaticMethod public func getRadioVersion() -> String } diff --git a/Sources/AndroidOS/Bundle.swift b/Sources/AndroidOS/Bundle.swift index 63678a4d..c8c287ca 100644 --- a/Sources/AndroidOS/Bundle.swift +++ b/Sources/AndroidOS/Bundle.swift @@ -7,140 +7,223 @@ import JavaLangUtil import SwiftJava import CSwiftJavaJNI +/// A mapping from String keys to various Parcelable values. This is the primary method for +/// transferring data between Activities and between Activities and Services. +/// +/// `Bundle` extends `BaseBundle` and adds support for `Parcelable` values, IBinder objects, and +/// various other Android-specific types. +/// +/// See also: [android.os.Bundle](https://developer.android.com/reference/android/os/Bundle) @JavaClass("android.os.Bundle", implements: Cloneable.self, Parcelable.self) open class Bundle: BaseBundle { + /// Constructs a new, empty Bundle that is optimized for a given number of key/value pairs. @JavaMethod @_nonoverride public convenience init(_ arg0: Int32, environment: JNIEnvironment? = nil) + /// Constructs a Bundle containing a copy of the mappings from the given ClassLoader. @JavaMethod @_nonoverride public convenience init(_ arg0: JavaClassLoader?, environment: JNIEnvironment? = nil) + /// Constructs a new, empty Bundle. @JavaMethod @_nonoverride public convenience init(environment: JNIEnvironment? = nil) + /// Constructs a Bundle containing a copy of the mappings from the given Bundle. @JavaMethod @_nonoverride public convenience init(_ arg0: Bundle?, environment: JNIEnvironment? = nil) + /// Constructs a Bundle containing a copy of the mappings from the given PersistableBundle. + @available(Android 21, *) @JavaMethod @_nonoverride public convenience init(_ arg0: PersistableBundle?, environment: JNIEnvironment? = nil) @JavaMethod open func describeContents() -> Int32 + /// Writes the Bundle contents to a Parcel, typically in order for it to be passed through + /// an IBinder connection. @JavaMethod open func writeToParcel(_ arg0: Parcel?, _ arg1: Int32) + /// Changes the ClassLoader this Bundle uses when unparcelling data. @JavaMethod open func setClassLoader(_ arg0: JavaClassLoader?) + /// Makes a deep copy of the given bundle. + @available(Android 26, *) @JavaMethod open func deepCopy() -> Bundle! + /// Reports whether the bundle contains any parcelled file descriptors. @JavaMethod open func hasFileDescriptors() -> Bool + /// Inserts a CharSequence value into the mapping. @JavaMethod open func putCharSequence(_ arg0: String, _ arg1: CharSequence?) + /// Inserts a Parcelable value into the mapping. @JavaMethod open func putParcelable(_ arg0: String, _ arg1: Parcelable?) + /// Inserts an array of Parcelable values into the mapping. @JavaMethod open func putParcelableArray(_ arg0: String, _ arg1: [Parcelable?]) + /// Inserts a List of Parcelable values into the mapping. @JavaMethod open func putParcelableArrayList(_ arg0: String, _ arg1: ArrayList?) + /// Inserts an ArrayList of Integer values into the mapping. @JavaMethod open func putIntegerArrayList(_ arg0: String, _ arg1: ArrayList?) + /// Inserts an ArrayList of String values into the mapping. @JavaMethod open func putStringArrayList(_ arg0: String, _ arg1: ArrayList?) + /// Inserts an ArrayList of CharSequence values into the mapping. @JavaMethod open func putCharSequenceArrayList(_ arg0: String, _ arg1: ArrayList?) + /// Inserts a Serializable value into the mapping. @JavaMethod open func putSerializable(_ arg0: String, _ arg1: Serializable?) + /// Inserts a byte array value into the mapping. @JavaMethod open func putByteArray(_ arg0: String, _ arg1: [Int8]) + /// Inserts a short array value into the mapping. @JavaMethod open func putShortArray(_ arg0: String, _ arg1: [Int16]) + /// Inserts a char array value into the mapping. @JavaMethod open func putCharArray(_ arg0: String, _ arg1: [UInt16]) + /// Inserts a float array value into the mapping. @JavaMethod open func putFloatArray(_ arg0: String, _ arg1: [Float]) + /// Inserts a CharSequence array value into the mapping. @JavaMethod open func putCharSequenceArray(_ arg0: String, _ arg1: [CharSequence?]) + /// Inserts a Bundle value into the mapping. @JavaMethod open func putBundle(_ arg0: String, _ arg1: Bundle?) + /// Inserts an IBinder value into the mapping. + @available(Android 18, *) @JavaMethod open func putBinder(_ arg0: String, _ arg1: IBinder?) + /// Returns the value associated with the given key, or nil if no mapping of the desired type + /// exists for the given key. @JavaMethod open func getCharSequence(_ arg0: String) -> CharSequence! + /// Returns the value associated with the given key, or `arg1` if no mapping of the desired type + /// exists for the given key. @JavaMethod open func getCharSequence(_ arg0: String, _ arg1: CharSequence?) -> CharSequence! + /// Returns the value associated with the given key, cast to the given class, or nil if no + /// mapping of the desired type exists for the given key. + @available(Android 33, *) @JavaMethod open func getParcelable(_ arg0: String, _ arg1: JavaClass?) -> JavaObject! + /// Returns the value associated with the given key, or nil if no mapping of the desired type + /// exists for the given key. + /// + /// - Note: Deprecated since API 33. Use `getParcelable(String, Class)` instead. @JavaMethod open func getParcelable(_ arg0: String) -> Parcelable! + /// Returns the value associated with the given key, or nil if no mapping of the desired type + /// exists for the given key. + @available(Android 33, *) @JavaMethod open func getParcelableArray(_ arg0: String, _ arg1: JavaClass?) -> [JavaObject?] + /// Returns the value associated with the given key, or nil if no mapping of the desired type + /// exists for the given key. + /// + /// - Note: Deprecated since API 33. Use `getParcelableArray(String, Class)` instead. @JavaMethod open func getParcelableArray(_ arg0: String) -> [Parcelable?] + /// Returns the value associated with the given key, or nil if no mapping of the desired type + /// exists for the given key. + @available(Android 33, *) @JavaMethod open func getParcelableArrayList(_ arg0: String, _ arg1: JavaClass?) -> ArrayList! + /// Returns the value associated with the given key, or nil if no mapping of the desired type + /// exists for the given key. + /// + /// - Note: Deprecated since API 33. Use `getParcelableArrayList(String, Class)` instead. @JavaMethod open func getParcelableArrayList(_ arg0: String) -> ArrayList! + /// Returns the value associated with the given key, or nil if no mapping of the desired type + /// exists for the given key. + /// + /// - Note: Deprecated since API 33. Use `getSerializable(String, Class)` instead. @JavaMethod open func getSerializable(_ arg0: String) -> Serializable! + /// Returns the value associated with the given key, cast to the given class, or nil if no + /// mapping of the desired type exists for the given key. + @available(Android 33, *) @JavaMethod open func getSerializable(_ arg0: String, _ arg1: JavaClass?) -> Serializable! + /// Returns the value associated with the given key, or nil if no mapping of the desired type + /// exists for the given key. @JavaMethod open func getIntegerArrayList(_ arg0: String) -> ArrayList! + /// Returns the value associated with the given key, or nil if no mapping of the desired type + /// exists for the given key. @JavaMethod open func getStringArrayList(_ arg0: String) -> ArrayList! + /// Returns the value associated with the given key, or nil if no mapping of the desired type + /// exists for the given key. @JavaMethod open func getCharSequenceArrayList(_ arg0: String) -> ArrayList! + /// Returns the value associated with the given key, or nil if no mapping exists. @JavaMethod open func getByteArray(_ arg0: String) -> [Int8] + /// Returns the value associated with the given key, or nil if no mapping exists. @JavaMethod open func getShortArray(_ arg0: String) -> [Int16] + /// Returns the value associated with the given key, or nil if no mapping exists. @JavaMethod open func getCharArray(_ arg0: String) -> [UInt16] + /// Returns the value associated with the given key, or nil if no mapping exists. @JavaMethod open func getFloatArray(_ arg0: String) -> [Float] + /// Returns the value associated with the given key, or nil if no mapping exists. @JavaMethod open func getCharSequenceArray(_ arg0: String) -> [CharSequence?] + /// Returns the value associated with the given key, or nil if no mapping of the desired type + /// exists for the given key. + @available(Android 18, *) @JavaMethod open func getBinder(_ arg0: String) -> IBinder! + /// Reads the Parcel contents into this Bundle, typically in order for it to be passed through + /// an IBinder connection. @JavaMethod open func readFromParcel(_ arg0: Parcel?) @@ -153,51 +236,74 @@ open class Bundle: BaseBundle { @JavaMethod open override func clone() -> JavaObject! + /// Returns the value associated with the given key, or `arg1` if no mapping of the desired type + /// exists for the given key. @JavaMethod open func getByte(_ arg0: String, _ arg1: Int8) -> JavaByte! + /// Returns the value associated with the given key, or 0 if no mapping of the desired type + /// exists for the given key. @JavaMethod open func getByte(_ arg0: String) -> Int8 + /// Inserts a byte value into the mapping. @JavaMethod open func putByte(_ arg0: String, _ arg1: Int8) + /// Returns the value associated with the given key, or `arg1` if no mapping of the desired type + /// exists for the given key. @JavaMethod open func getShort(_ arg0: String, _ arg1: Int16) -> Int16 + /// Returns the value associated with the given key, or 0 if no mapping of the desired type + /// exists for the given key. @JavaMethod open func getShort(_ arg0: String) -> Int16 + /// Inserts a short value into the mapping. @JavaMethod open func putShort(_ arg0: String, _ arg1: Int16) + /// Returns the value associated with the given key, or 0 if no mapping of the desired type + /// exists for the given key. @JavaMethod open func getChar(_ arg0: String) -> UInt16 + /// Returns the value associated with the given key, or `arg1` if no mapping of the desired type + /// exists for the given key. @JavaMethod open func getChar(_ arg0: String, _ arg1: UInt16) -> UInt16 + /// Inserts a char value into the mapping. @JavaMethod open func putChar(_ arg0: String, _ arg1: UInt16) + /// Returns the value associated with the given key, or `arg1` if no mapping of the desired type + /// exists for the given key. @JavaMethod open func getFloat(_ arg0: String, _ arg1: Float) -> Float + /// Returns the value associated with the given key, or 0.0f if no mapping of the desired type + /// exists for the given key. @JavaMethod open func getFloat(_ arg0: String) -> Float + /// Inserts a float value into the mapping. @JavaMethod open func putFloat(_ arg0: String, _ arg1: Float) @JavaMethod open override func clear() + /// Returns the ClassLoader currently associated with this Bundle. @JavaMethod open func getClassLoader() -> JavaClassLoader! + /// Inserts all mappings from the given Bundle into this Bundle. @JavaMethod open func putAll(_ arg0: Bundle?) + /// Returns the value associated with the given key, or nil if no mapping exists. @JavaMethod open func getBundle(_ arg0: String) -> Bundle! } @@ -205,6 +311,7 @@ extension JavaClass { @JavaStaticField(isFinal: true) public var CREATOR: Parcelable.Creator! + /// An unmodifiable Bundle that is always empty. @JavaStaticField(isFinal: true) public var EMPTY: Bundle! diff --git a/Sources/AndroidOS/CancellationSignal+OnCancelListener.swift b/Sources/AndroidOS/CancellationSignal+OnCancelListener.swift index da89c287..f0a2c644 100644 --- a/Sources/AndroidOS/CancellationSignal+OnCancelListener.swift +++ b/Sources/AndroidOS/CancellationSignal+OnCancelListener.swift @@ -3,9 +3,17 @@ import SwiftJava import CSwiftJavaJNI extension CancellationSignal { + /// A listener that is notified when a `CancellationSignal` is canceled. + /// + /// Implement this interface and register it via `CancellationSignal.setOnCancelListener(_:)` + /// to receive a callback when the associated operation is canceled. + /// + /// See also: [android.os.CancellationSignal.OnCancelListener](https://developer.android.com/reference/android/os/CancellationSignal.OnCancelListener) + @available(Android 16, *) @JavaInterface("android.os.CancellationSignal$OnCancelListener") public struct OnCancelListener { - @JavaMethod - public func onCancel() + /// Called when the associated `CancellationSignal` has been canceled. + @JavaMethod + public func onCancel() } } diff --git a/Sources/AndroidOS/CancellationSignal.swift b/Sources/AndroidOS/CancellationSignal.swift index 70d8b4c4..66552f82 100644 --- a/Sources/AndroidOS/CancellationSignal.swift +++ b/Sources/AndroidOS/CancellationSignal.swift @@ -2,20 +2,42 @@ import SwiftJava import CSwiftJavaJNI +/// Provides the ability to cancel an operation in progress. +/// +/// A `CancellationSignal` is associated with a particular operation. The `cancel()` method can +/// be called at any time to cancel the operation. If the operation has already completed normally, +/// canceling it has no effect. +/// +/// See also: [android.os.CancellationSignal](https://developer.android.com/reference/android/os/CancellationSignal) +@available(Android 16, *) @JavaClass("android.os.CancellationSignal") open class CancellationSignal: JavaObject { @JavaMethod @_nonoverride public convenience init(environment: JNIEnvironment? = nil) + /// Returns true if the operation has been canceled. @JavaMethod open func isCanceled() -> Bool + /// Throws `OperationCanceledException` if the operation has been canceled. @JavaMethod open func throwIfCanceled() + /// Sets the cancellation listener to be called when the operation is canceled. + /// + /// This method is intended to be used by the recipient of a cancellation signal such as a + /// database or a content provider to handle cancellation requests while performing a + /// long-running operation. + /// + /// If `cancel()` has already been called, then the provided listener is invoked immediately. + /// + /// - Parameter arg0: The cancellation listener, or nil to remove the current listener. @JavaMethod open func setOnCancelListener(_ arg0: CancellationSignal.OnCancelListener?) + /// Cancels the operation and signals the cancellation listener. + /// + /// If the operation has not yet started, then it will be canceled as soon as it does. @JavaMethod open func cancel() } diff --git a/Sources/AndroidOS/CleartextNetworkViolation.swift b/Sources/AndroidOS/CleartextNetworkViolation.swift index 0c6c4b3f..a2c98c07 100644 --- a/Sources/AndroidOS/CleartextNetworkViolation.swift +++ b/Sources/AndroidOS/CleartextNetworkViolation.swift @@ -2,6 +2,10 @@ import SwiftJava import CSwiftJavaJNI +/// Violation raised when cleartext network traffic is detected. +/// +/// See also: [android.os.strictmode.CleartextNetworkViolation](https://developer.android.com/reference/android/os/strictmode/CleartextNetworkViolation) +@available(Android 28, *) @JavaClass("android.os.strictmode.CleartextNetworkViolation") open class CleartextNetworkViolation: Violation { diff --git a/Sources/AndroidOS/CombinedVibration+ParallelCombination.swift b/Sources/AndroidOS/CombinedVibration+ParallelCombination.swift index c39231d8..f84053b1 100644 --- a/Sources/AndroidOS/CombinedVibration+ParallelCombination.swift +++ b/Sources/AndroidOS/CombinedVibration+ParallelCombination.swift @@ -3,11 +3,25 @@ import SwiftJava import CSwiftJavaJNI extension CombinedVibration { + /// A combination of vibration effects that are performed by different vibrators in parallel. + /// + /// To create a ParallelCombination, use `CombinedVibration.startParallel()`. + /// + /// See also: [android.os.CombinedVibration.ParallelCombination](https://developer.android.com/reference/android/os/CombinedVibration.ParallelCombination) + @available(Android 31, *) @JavaClass("android.os.CombinedVibration$ParallelCombination") open class ParallelCombination: JavaObject { + /// Adds a `VibrationEffect` for a specific vibrator to this combination. + /// + /// - Parameter arg0: The ID of the vibrator to use. + /// - Parameter arg1: The `VibrationEffect` to perform on the specified vibrator. + /// - Returns: This `ParallelCombination` to allow chaining of calls. @JavaMethod open func addVibrator(_ arg0: Int32, _ arg1: VibrationEffect?) -> CombinedVibration.ParallelCombination! + /// Combines all added effects into a single `CombinedVibration`. + /// + /// - Returns: The `CombinedVibration` representing this parallel combination. @JavaMethod open func combine() -> CombinedVibration! } diff --git a/Sources/AndroidOS/CombinedVibration.swift b/Sources/AndroidOS/CombinedVibration.swift index f1aa4862..1688ce4a 100644 --- a/Sources/AndroidOS/CombinedVibration.swift +++ b/Sources/AndroidOS/CombinedVibration.swift @@ -2,6 +2,13 @@ import SwiftJava import CSwiftJavaJNI +/// A `CombinedVibration` describes a haptic effect to be performed by one or more `Vibrator`s. +/// +/// These effects may be performed by a `VibratorManager` for a synchronized multi-vibrator effect. +/// Use the factory methods `createParallel()` or `startParallel()` to construct an instance. +/// +/// See also: [android.os.CombinedVibration](https://developer.android.com/reference/android/os/CombinedVibration) +@available(Android 31, *) @JavaClass("android.os.CombinedVibration", implements: Parcelable.self) open class CombinedVibration: JavaObject { @JavaMethod @@ -17,9 +24,15 @@ extension JavaClass { @JavaStaticField(isFinal: true) public var PARCELABLE_WRITE_RETURN_VALUE: Int32 + /// Creates a `CombinedVibration` that plays the same effect on all vibrators simultaneously. + /// + /// - Parameter arg0: The `VibrationEffect` to play on all vibrators. @JavaStaticMethod public func createParallel(_ arg0: VibrationEffect?) -> CombinedVibration! + /// Start building a parallel `CombinedVibration` with different effects per vibrator. + /// + /// - Returns: A `ParallelCombination` builder. @JavaStaticMethod public func startParallel() -> CombinedVibration.ParallelCombination! } diff --git a/Sources/AndroidOS/ConditionVariable.swift b/Sources/AndroidOS/ConditionVariable.swift index b9f6a982..afb36801 100644 --- a/Sources/AndroidOS/ConditionVariable.swift +++ b/Sources/AndroidOS/ConditionVariable.swift @@ -2,23 +2,37 @@ import SwiftJava import CSwiftJavaJNI +/// A synchronization primitive that allows threads to wait until a condition becomes true. +/// +/// Threads call `block()` to wait until another thread calls `open()` to release them. +/// The condition can be reset to the closed state by calling `close()`. +/// +/// See also: [android.os.ConditionVariable](https://developer.android.com/reference/android/os/ConditionVariable) @JavaClass("android.os.ConditionVariable") open class ConditionVariable: JavaObject { + /// Creates a `ConditionVariable` in the closed (blocking) state. @JavaMethod @_nonoverride public convenience init(environment: JNIEnvironment? = nil) + /// Creates a `ConditionVariable` with the specified initial state. + /// Pass `true` to start in the open state, `false` to start closed. @JavaMethod @_nonoverride public convenience init(_ arg0: Bool, environment: JNIEnvironment? = nil) + /// Sets the condition to the closed state, causing subsequent calls to `block()` to wait. @JavaMethod open func close() + /// Sets the condition to the open state, releasing all threads currently blocked in `block()`. @JavaMethod open func open() + /// Blocks the calling thread indefinitely until `open()` is called. @JavaMethod open func block() + /// Blocks the calling thread for up to the given number of milliseconds, or until `open()` is called. + /// Returns `true` if the condition was opened, `false` if the timeout expired. @JavaMethod open func block(_ arg0: Int64) -> Bool } diff --git a/Sources/AndroidOS/ContentUriWithoutPermissionViolation.swift b/Sources/AndroidOS/ContentUriWithoutPermissionViolation.swift index 215634c0..496e2f73 100644 --- a/Sources/AndroidOS/ContentUriWithoutPermissionViolation.swift +++ b/Sources/AndroidOS/ContentUriWithoutPermissionViolation.swift @@ -2,6 +2,10 @@ import SwiftJava import CSwiftJavaJNI +/// Violation raised when a content URI is accessed without the required permissions. +/// +/// See also: [android.os.strictmode.ContentUriWithoutPermissionViolation](https://developer.android.com/reference/android/os/strictmode/ContentUriWithoutPermissionViolation) +@available(Android 28, *) @JavaClass("android.os.strictmode.ContentUriWithoutPermissionViolation") open class ContentUriWithoutPermissionViolation: Violation { diff --git a/Sources/AndroidOS/CountDownTimer.swift b/Sources/AndroidOS/CountDownTimer.swift index 65edd87f..87d14ebd 100644 --- a/Sources/AndroidOS/CountDownTimer.swift +++ b/Sources/AndroidOS/CountDownTimer.swift @@ -2,20 +2,36 @@ import SwiftJava import CSwiftJavaJNI +/// A convenient base class for scheduling a countdown timer with periodic tick callbacks. +/// +/// Subclass and implement `onTick(_:)` to receive regular callbacks and `onFinish()` to +/// be notified when the countdown completes. Call `start()` to begin the timer and +/// `cancel()` to stop it before it finishes. +/// +/// See also: [android.os.CountDownTimer](https://developer.android.com/reference/android/os/CountDownTimer) @JavaClass("android.os.CountDownTimer") open class CountDownTimer: JavaObject { + /// Creates a new `CountDownTimer`. + /// + /// - Parameters: + /// - arg0: The total countdown duration in milliseconds. + /// - arg1: The interval in milliseconds between `onTick(_:)` callbacks. @JavaMethod @_nonoverride public convenience init(_ arg0: Int64, _ arg1: Int64, environment: JNIEnvironment? = nil) + /// Called at each tick interval with the number of milliseconds remaining until the countdown finishes. @JavaMethod open func onTick(_ arg0: Int64) + /// Called when the countdown has finished. @JavaMethod open func onFinish() + /// Starts the countdown timer and returns `self` for chaining. @JavaMethod open func start() -> CountDownTimer! + /// Cancels the countdown timer. `onFinish()` will not be called after cancellation. @JavaMethod open func cancel() } diff --git a/Sources/AndroidOS/CpuUsageInfo.swift b/Sources/AndroidOS/CpuUsageInfo.swift index 77f2a3b6..8e50de78 100644 --- a/Sources/AndroidOS/CpuUsageInfo.swift +++ b/Sources/AndroidOS/CpuUsageInfo.swift @@ -2,6 +2,13 @@ import SwiftJava import CSwiftJavaJNI +/// CPU usage information for a single CPU core, as returned by `HardwarePropertiesManager`. +/// +/// Contains both active (non-idle) CPU time and total CPU time for use in calculating +/// utilization percentages. +/// +/// See also: [android.os.CpuUsageInfo](https://developer.android.com/reference/android/os/CpuUsageInfo) +@available(Android 24, *) @JavaClass("android.os.CpuUsageInfo", implements: Parcelable.self) open class CpuUsageInfo: JavaObject { @JavaMethod diff --git a/Sources/AndroidOS/CredentialProtectedWhileLockedViolation.swift b/Sources/AndroidOS/CredentialProtectedWhileLockedViolation.swift index 48d15e8a..5693dc6e 100644 --- a/Sources/AndroidOS/CredentialProtectedWhileLockedViolation.swift +++ b/Sources/AndroidOS/CredentialProtectedWhileLockedViolation.swift @@ -2,6 +2,10 @@ import SwiftJava import CSwiftJavaJNI +/// Violation raised when credential-protected storage is accessed while the device is locked. +/// +/// See also: [android.os.strictmode.CredentialProtectedWhileLockedViolation](https://developer.android.com/reference/android/os/strictmode/CredentialProtectedWhileLockedViolation) +@available(Android 28, *) @JavaClass("android.os.strictmode.CredentialProtectedWhileLockedViolation") open class CredentialProtectedWhileLockedViolation: Violation { diff --git a/Sources/AndroidOS/CustomViolation.swift b/Sources/AndroidOS/CustomViolation.swift index 0ee64c94..030aeac6 100644 --- a/Sources/AndroidOS/CustomViolation.swift +++ b/Sources/AndroidOS/CustomViolation.swift @@ -2,6 +2,10 @@ import SwiftJava import CSwiftJavaJNI +/// Violation raised when `StrictMode.noteSlowCall` is used to flag a custom slow call. +/// +/// See also: [android.os.strictmode.CustomViolation](https://developer.android.com/reference/android/os/strictmode/CustomViolation) +@available(Android 28, *) @JavaClass("android.os.strictmode.CustomViolation") open class CustomViolation: Violation { diff --git a/Sources/AndroidOS/DeadObjectException.swift b/Sources/AndroidOS/DeadObjectException.swift index 38473576..2d1d674a 100644 --- a/Sources/AndroidOS/DeadObjectException.swift +++ b/Sources/AndroidOS/DeadObjectException.swift @@ -2,6 +2,10 @@ import SwiftJava import CSwiftJavaJNI +/// Thrown when an operation is attempted on a dead remote object, typically because +/// the remote process hosting the binder has terminated. +/// +/// See also: [android.os.DeadObjectException](https://developer.android.com/reference/android/os/DeadObjectException) @JavaClass("android.os.DeadObjectException") open class DeadObjectException: RemoteException { @JavaMethod diff --git a/Sources/AndroidOS/DeadSystemException.swift b/Sources/AndroidOS/DeadSystemException.swift index 8b7852e3..d92a6822 100644 --- a/Sources/AndroidOS/DeadSystemException.swift +++ b/Sources/AndroidOS/DeadSystemException.swift @@ -2,6 +2,11 @@ import SwiftJava import CSwiftJavaJNI +/// Thrown when the system server process has died, indicating that the Android system +/// itself is no longer available and the device may be restarting. +/// +/// See also: [android.os.DeadSystemException](https://developer.android.com/reference/android/os/DeadSystemException) +@available(Android 23, *) @JavaClass("android.os.DeadSystemException") open class DeadSystemException: DeadObjectException { @JavaMethod diff --git a/Sources/AndroidOS/Debug+InstructionCount.swift b/Sources/AndroidOS/Debug+InstructionCount.swift index 8bd2ddc6..cf1271cc 100644 --- a/Sources/AndroidOS/Debug+InstructionCount.swift +++ b/Sources/AndroidOS/Debug+InstructionCount.swift @@ -3,6 +3,11 @@ import SwiftJava import CSwiftJavaJNI extension Debug { + /// Tracks global VM instruction counts for profiling purposes. + /// + /// Note: This class was deprecated in API level 23. + /// + /// See also: [android.os.Debug.InstructionCount](https://developer.android.com/reference/android/os/Debug.InstructionCount) @JavaClass("android.os.Debug$InstructionCount") open class InstructionCount: JavaObject { @JavaMethod diff --git a/Sources/AndroidOS/Debug+MemoryInfo.swift b/Sources/AndroidOS/Debug+MemoryInfo.swift index b9a30c46..ddccaace 100644 --- a/Sources/AndroidOS/Debug+MemoryInfo.swift +++ b/Sources/AndroidOS/Debug+MemoryInfo.swift @@ -5,6 +5,11 @@ import SwiftJava import CSwiftJavaJNI extension Debug { + /// Memory usage statistics for a process, broken down by category (Dalvik, native, other). + /// + /// Obtain an instance by calling `Debug.getMemoryInfo(_:)`. + /// + /// See also: [android.os.Debug.MemoryInfo](https://developer.android.com/reference/android/os/Debug.MemoryInfo) @JavaClass("android.os.Debug$MemoryInfo", implements: Parcelable.self) open class MemoryInfo: JavaObject { @JavaField(isFinal: false) @@ -55,9 +60,11 @@ extension Debug { @JavaMethod open func getTotalSharedClean() -> Int32 + @available(Android 23, *) @JavaMethod open func getMemoryStat(_ arg0: String) -> String + @available(Android 23, *) @JavaMethod open func getMemoryStats() -> Map! diff --git a/Sources/AndroidOS/Debug.swift b/Sources/AndroidOS/Debug.swift index 27da0e3f..f94d3012 100644 --- a/Sources/AndroidOS/Debug.swift +++ b/Sources/AndroidOS/Debug.swift @@ -5,6 +5,12 @@ import JavaLangUtil import SwiftJava import CSwiftJavaJNI +/// Provides debugging and diagnostics utility methods. +/// +/// Includes tools for method tracing, allocation tracking, heap profiling, and connecting +/// with a Java debugger. +/// +/// See also: [android.os.Debug](https://developer.android.com/reference/android/os/Debug) @JavaClass("android.os.Debug") open class Debug: JavaObject { diff --git a/Sources/AndroidOS/DiskReadViolation.swift b/Sources/AndroidOS/DiskReadViolation.swift index 63bd63ce..097d210d 100644 --- a/Sources/AndroidOS/DiskReadViolation.swift +++ b/Sources/AndroidOS/DiskReadViolation.swift @@ -2,6 +2,10 @@ import SwiftJava import CSwiftJavaJNI +/// Violation raised when a disk read occurs on a thread that has forbidden disk reads. +/// +/// See also: [android.os.strictmode.DiskReadViolation](https://developer.android.com/reference/android/os/strictmode/DiskReadViolation) +@available(Android 28, *) @JavaClass("android.os.strictmode.DiskReadViolation") open class DiskReadViolation: Violation { diff --git a/Sources/AndroidOS/DiskWriteViolation.swift b/Sources/AndroidOS/DiskWriteViolation.swift index 3250876b..1b39696c 100644 --- a/Sources/AndroidOS/DiskWriteViolation.swift +++ b/Sources/AndroidOS/DiskWriteViolation.swift @@ -2,6 +2,10 @@ import SwiftJava import CSwiftJavaJNI +/// Violation raised when a disk write occurs on a thread that has forbidden disk writes. +/// +/// See also: [android.os.strictmode.DiskWriteViolation](https://developer.android.com/reference/android/os/strictmode/DiskWriteViolation) +@available(Android 28, *) @JavaClass("android.os.strictmode.DiskWriteViolation") open class DiskWriteViolation: Violation { diff --git a/Sources/AndroidOS/DropBoxManager+Entry.swift b/Sources/AndroidOS/DropBoxManager+Entry.swift index 02ae2c08..3462d729 100644 --- a/Sources/AndroidOS/DropBoxManager+Entry.swift +++ b/Sources/AndroidOS/DropBoxManager+Entry.swift @@ -5,26 +5,40 @@ import SwiftJava import CSwiftJavaJNI extension DropBoxManager { + /// A single diagnostic log entry stored in the drop box. + /// + /// Entries are timestamped and carry a tag, optional text or binary content, and a set of flags + /// (e.g., `IS_TEXT`, `IS_GZIPPED`). Always call `close()` when finished with an entry. + /// + /// See [android.os.DropBoxManager.Entry](https://developer.android.com/reference/android/os/DropBoxManager.Entry) + @available(Android 8, *) @JavaClass("android.os.DropBoxManager$Entry", implements: Parcelable.self, Closeable.self) open class Entry: JavaObject { + /// Creates an empty entry with the given tag and timestamp. @JavaMethod @_nonoverride public convenience init(_ arg0: String, _ arg1: Int64, environment: JNIEnvironment? = nil) + /// Creates a text entry with the given tag, timestamp, and text content. @JavaMethod @_nonoverride public convenience init(_ arg0: String, _ arg1: Int64, _ arg2: String, environment: JNIEnvironment? = nil) + /// Creates a binary entry with the given tag, timestamp, data, and flags. @JavaMethod @_nonoverride public convenience init(_ arg0: String, _ arg1: Int64, _ arg2: [Int8], _ arg3: Int32, environment: JNIEnvironment? = nil) + /// Creates a file-backed entry with the given tag, timestamp, file, and flags. @JavaMethod @_nonoverride public convenience init(_ arg0: String, _ arg1: Int64, _ arg2: File?, _ arg3: Int32, environment: JNIEnvironment? = nil) throws + /// Creates an entry backed by a `ParcelFileDescriptor` with the given tag, timestamp, and flags. @JavaMethod @_nonoverride public convenience init(_ arg0: String, _ arg1: Int64, _ arg2: ParcelFileDescriptor?, _ arg3: Int32, environment: JNIEnvironment? = nil) + /// Returns the tag associated with this entry. @JavaMethod open func getTag() -> String + /// Returns the time at which this entry was created, in milliseconds since the epoch. @JavaMethod open func getTimeMillis() -> Int64 @@ -34,15 +48,19 @@ extension DropBoxManager { @JavaMethod open func writeToParcel(_ arg0: Parcel?, _ arg1: Int32) + /// Closes this entry and releases any underlying resources. @JavaMethod open func close() + /// Returns an `InputStream` for reading this entry's contents, or `nil` if the entry is empty. @JavaMethod open func getInputStream() throws -> InputStream! + /// Returns up to `arg0` bytes of this entry's content as a `String`, or `nil` if not text. @JavaMethod open func getText(_ arg0: Int32) -> String + /// Returns the flags for this entry (e.g., `IS_TEXT`, `IS_GZIPPED`, `IS_EMPTY`). @JavaMethod open func getFlags() -> Int32 } diff --git a/Sources/AndroidOS/DropBoxManager.swift b/Sources/AndroidOS/DropBoxManager.swift index 7760058c..80b57316 100644 --- a/Sources/AndroidOS/DropBoxManager.swift +++ b/Sources/AndroidOS/DropBoxManager.swift @@ -4,20 +4,34 @@ import JavaLangIO import SwiftJava import CSwiftJavaJNI +/// Stores and retrieves diagnostic log entries (text, binary, or file-based) organised by tag. +/// +/// Entries are retained by the system for diagnostic and bug-reporting purposes. Obtain an instance +/// via `Context.getSystemService(Context.DROPBOX_SERVICE)`. +/// +/// See [android.os.DropBoxManager](https://developer.android.com/reference/android/os/DropBoxManager) +@available(Android 8, *) @JavaClass("android.os.DropBoxManager") open class DropBoxManager: JavaObject { + /// Adds a plain-text entry with the given tag. @JavaMethod open func addText(_ arg0: String, _ arg1: String) + /// Adds a binary entry with the given tag and flags. @JavaMethod open func addData(_ arg0: String, _ arg1: [Int8], _ arg2: Int32) + /// Returns whether entries with the given tag will be stored (i.e., the tag is not disabled). @JavaMethod open func isTagEnabled(_ arg0: String) -> Bool + /// Returns the next entry after the given time (in milliseconds) with the given tag, or `nil` if none. + /// + /// The caller is responsible for closing the returned `Entry`. @JavaMethod open func getNextEntry(_ arg0: String, _ arg1: Int64) -> DropBoxManager.Entry! + /// Adds a file-based entry with the given tag and flags. @JavaMethod open func addFile(_ arg0: String, _ arg1: File?, _ arg2: Int32) throws } diff --git a/Sources/AndroidOS/Environment.swift b/Sources/AndroidOS/Environment.swift index 132ade99..e0a6cebb 100644 --- a/Sources/AndroidOS/Environment.swift +++ b/Sources/AndroidOS/Environment.swift @@ -4,81 +4,119 @@ import JavaLangIO import SwiftJava import CSwiftJavaJNI +/// Provides access to environment variables. Contains the path to external storage (SD card), +/// and the state of the external storage. +/// +/// See also: [android.os.Environment](https://developer.android.com/reference/android/os/Environment) @JavaClass("android.os.Environment") open class Environment: JavaObject { @JavaMethod @_nonoverride public convenience init(environment: JNIEnvironment? = nil) } extension JavaClass { + /// Standard directory in which to place any audio files that should be in the list of alarms + /// that the user can select (not as regular music). @JavaStaticField(isFinal: false) public var DIRECTORY_ALARMS: String + /// Standard directory in which to place audiobooks that are purchased or downloaded by the user. + @available(Android 29, *) @JavaStaticField(isFinal: false) public var DIRECTORY_AUDIOBOOKS: String + /// The traditional location for pictures and videos when mounting the device as a camera. @JavaStaticField(isFinal: false) public var DIRECTORY_DCIM: String + /// Standard directory in which to place documents that have been created by the user. + @available(Android 19, *) @JavaStaticField(isFinal: false) public var DIRECTORY_DOCUMENTS: String + /// Standard directory in which to place files that have been downloaded by the user. @JavaStaticField(isFinal: false) public var DIRECTORY_DOWNLOADS: String + /// Standard directory in which to place movies that are available to the user. @JavaStaticField(isFinal: false) public var DIRECTORY_MOVIES: String + /// Standard directory in which to place any audio files that should be in the regular list + /// of music for the user. @JavaStaticField(isFinal: false) public var DIRECTORY_MUSIC: String + /// Standard directory in which to place any audio files that should be in the list of + /// notifications that the user can select (not as regular music). @JavaStaticField(isFinal: false) public var DIRECTORY_NOTIFICATIONS: String + /// Standard directory in which to place pictures that are available to the user. @JavaStaticField(isFinal: false) public var DIRECTORY_PICTURES: String + /// Standard directory in which to place any audio files that should be in the list of + /// podcasts that the user can select (not as regular music). @JavaStaticField(isFinal: false) public var DIRECTORY_PODCASTS: String + /// Standard directory in which to place any audio files that should be in the list of + /// audio recordings made by the user (not as regular music). + @available(Android 31, *) @JavaStaticField(isFinal: false) public var DIRECTORY_RECORDINGS: String + /// Standard directory in which to place any audio files that should be in the list of + /// ringtones that the user can select (not as regular music). @JavaStaticField(isFinal: false) public var DIRECTORY_RINGTONES: String + /// Standard directory for storing screenshots captured by the user. + @available(Android 29, *) @JavaStaticField(isFinal: false) public var DIRECTORY_SCREENSHOTS: String + /// getExternalStorageState() if the media was removed before it was unmounted. @JavaStaticField(isFinal: true) public var MEDIA_BAD_REMOVAL: String + /// getExternalStorageState() if the media is present and being disk-checked. @JavaStaticField(isFinal: true) public var MEDIA_CHECKING: String + /// getExternalStorageState() if the media is in the process of being ejected. @JavaStaticField(isFinal: true) public var MEDIA_EJECTING: String + /// getExternalStorageState() if the media is present and mounted at its mount point with read/write access. @JavaStaticField(isFinal: true) public var MEDIA_MOUNTED: String + /// getExternalStorageState() if the media is present and mounted at its mount point with read-only access. @JavaStaticField(isFinal: true) public var MEDIA_MOUNTED_READ_ONLY: String + /// getExternalStorageState() if the media is present but is blank or is using an unsupported filesystem. @JavaStaticField(isFinal: true) public var MEDIA_NOFS: String + /// getExternalStorageState() if the media is not present. @JavaStaticField(isFinal: true) public var MEDIA_REMOVED: String + /// getExternalStorageState() if the media is present not mounted, and shared via USB mass storage. @JavaStaticField(isFinal: true) public var MEDIA_SHARED: String + /// getExternalStorageState() if the state is unknown. @JavaStaticField(isFinal: true) public var MEDIA_UNKNOWN: String + /// getExternalStorageState() if the media is present but cannot be mounted. Typically this is because the file system on the media is corrupt. @JavaStaticField(isFinal: true) public var MEDIA_UNMOUNTABLE: String + /// getExternalStorageState() if the media is present but not mounted. @JavaStaticField(isFinal: true) public var MEDIA_UNMOUNTED: String diff --git a/Sources/AndroidOS/FileObserver.swift b/Sources/AndroidOS/FileObserver.swift index 8ee278b6..a534d07a 100644 --- a/Sources/AndroidOS/FileObserver.swift +++ b/Sources/AndroidOS/FileObserver.swift @@ -4,32 +4,54 @@ import JavaLangIO import SwiftJava import CSwiftJavaJNI +/// Monitors a file or directory for filesystem events such as creation, modification, and deletion. +/// +/// Subclass and override `onEvent(_:_:)` to receive event notifications. Call `startWatching()` to +/// begin monitoring and `stopWatching()` to cease it. +/// +/// See [android.os.FileObserver](https://developer.android.com/reference/android/os/FileObserver) @JavaClass("android.os.FileObserver") open class FileObserver: JavaObject { + /// Creates a `FileObserver` that watches the given path for all events. @JavaMethod @_nonoverride public convenience init(_ arg0: String, environment: JNIEnvironment? = nil) + /// Creates a `FileObserver` that watches the given list of files for the specified event mask. @JavaMethod @_nonoverride public convenience init(_ arg0: List?, _ arg1: Int32, environment: JNIEnvironment? = nil) + /// Creates a `FileObserver` that watches the given `File` for all events. + @available(Android 29, *) @JavaMethod @_nonoverride public convenience init(_ arg0: File?, environment: JNIEnvironment? = nil) + /// Creates a `FileObserver` that watches the given list of files for all events. + @available(Android 29, *) @JavaMethod @_nonoverride public convenience init(_ arg0: List?, environment: JNIEnvironment? = nil) + /// Creates a `FileObserver` that watches the given path for the specified event mask. @JavaMethod @_nonoverride public convenience init(_ arg0: String, _ arg1: Int32, environment: JNIEnvironment? = nil) + /// Creates a `FileObserver` that watches the given `File` for the specified event mask. + @available(Android 29, *) @JavaMethod @_nonoverride public convenience init(_ arg0: File?, _ arg1: Int32, environment: JNIEnvironment? = nil) + /// Starts watching for filesystem events. Has no effect if already watching. @JavaMethod open func startWatching() + /// Stops watching for filesystem events. Has no effect if not currently watching. @JavaMethod open func stopWatching() + /// Called when a filesystem event occurs on the observed path. + /// + /// - Parameters: + /// - arg0: The type of event (one of the event constants, e.g., `CREATE`, `MODIFY`, `DELETE`). + /// - arg1: The name of the file or directory affected, relative to the observed path, or `nil` if not applicable. @JavaMethod open func onEvent(_ arg0: Int32, _ arg1: String) diff --git a/Sources/AndroidOS/FileUriExposedException.swift b/Sources/AndroidOS/FileUriExposedException.swift index 2fcb714f..e80253e0 100644 --- a/Sources/AndroidOS/FileUriExposedException.swift +++ b/Sources/AndroidOS/FileUriExposedException.swift @@ -2,6 +2,11 @@ import SwiftJava import CSwiftJavaJNI +/// Thrown when an app exposes a `file://` URI to another app via an `Intent`, which is +/// unsafe on Android 24 and above. Use `FileProvider` to share files via `content://` URIs instead. +/// +/// See also: [android.os.FileUriExposedException](https://developer.android.com/reference/android/os/FileUriExposedException) +@available(Android 24, *) @JavaClass("android.os.FileUriExposedException") open class FileUriExposedException: RuntimeException { @JavaMethod diff --git a/Sources/AndroidOS/FileUriExposedViolation.swift b/Sources/AndroidOS/FileUriExposedViolation.swift index 4124d91a..eb2fb9dd 100644 --- a/Sources/AndroidOS/FileUriExposedViolation.swift +++ b/Sources/AndroidOS/FileUriExposedViolation.swift @@ -2,6 +2,10 @@ import SwiftJava import CSwiftJavaJNI +/// Violation raised when a `file://` URI is exposed to another app via an `Intent`. +/// +/// See also: [android.os.strictmode.FileUriExposedViolation](https://developer.android.com/reference/android/os/strictmode/FileUriExposedViolation) +@available(Android 28, *) @JavaClass("android.os.strictmode.FileUriExposedViolation") open class FileUriExposedViolation: Violation { diff --git a/Sources/AndroidOS/FileUtils.swift b/Sources/AndroidOS/FileUtils.swift index bf842984..91ee0d01 100644 --- a/Sources/AndroidOS/FileUtils.swift +++ b/Sources/AndroidOS/FileUtils.swift @@ -4,20 +4,29 @@ import JavaLang import SwiftJava import CSwiftJavaJNI +/// Provides static utility methods for common file operations. +/// +/// This is an internal system API and is not intended for use by third-party applications. +/// +/// See [android.os.FileUtils](https://developer.android.com/reference/android/os/FileUtils) @JavaClass("android.os.FileUtils") open class FileUtils: JavaObject { } extension JavaClass { + /// Copies all bytes from one file descriptor to another, returning the number of bytes copied. @JavaStaticMethod public func copy(_ arg0: FileDescriptor?, _ arg1: FileDescriptor?) throws -> Int64 + /// Copies all bytes from an `InputStream` to an `OutputStream`, returning the number of bytes copied. @JavaStaticMethod public func copy(_ arg0: InputStream?, _ arg1: OutputStream?) throws -> Int64 + /// Closes the given `FileDescriptor`, silently ignoring any errors. @JavaStaticMethod public func closeQuietly(_ arg0: FileDescriptor?) + /// Closes the given `AutoCloseable`, silently ignoring any errors. @JavaStaticMethod public func closeQuietly(_ arg0: AutoCloseable?) } diff --git a/Sources/AndroidOS/Handler+Callback.swift b/Sources/AndroidOS/Handler+Callback.swift index 48a0d5f3..7aa2c7e5 100644 --- a/Sources/AndroidOS/Handler+Callback.swift +++ b/Sources/AndroidOS/Handler+Callback.swift @@ -3,8 +3,15 @@ import SwiftJava import CSwiftJavaJNI extension Handler { + /// Callback interface you can use when instantiating a Handler to avoid having to implement + /// your own subclass of Handler. + /// + /// See also: [android.os.Handler.Callback](https://developer.android.com/reference/android/os/Handler.Callback) @JavaInterface("android.os.Handler$Callback") public struct Callback { + /// Handle a message sent to this handler. + /// + /// - Returns: `true` if no further handling is desired. @JavaMethod public func handleMessage(_ arg0: Message?) -> Bool } diff --git a/Sources/AndroidOS/Handler.swift b/Sources/AndroidOS/Handler.swift index 78418d75..3dfed0e8 100644 --- a/Sources/AndroidOS/Handler.swift +++ b/Sources/AndroidOS/Handler.swift @@ -3,117 +3,232 @@ import JavaLang import SwiftJava import CSwiftJavaJNI +/// A Handler allows you to send and process `Message` and `Runnable` objects associated with a +/// thread's `MessageQueue`. Each Handler instance is associated with a single thread and that +/// thread's message queue. When you create a new Handler it is bound to a `Looper`. +/// +/// There are two main uses for a Handler: (1) to schedule messages and runnables to be executed +/// at some point in the future; and (2) to enqueue an action to be performed on a different thread +/// than your own. +/// +/// - Note: The no-argument constructor is deprecated since API 30. Use a constructor that +/// accepts a `Looper` to make sure your Handler is bound to the right thread. +/// +/// See also: [android.os.Handler](https://developer.android.com/reference/android/os/Handler) @JavaClass("android.os.Handler") open class Handler: JavaObject { + /// Creates a new Handler using the `Looper` for the current thread and the specified callback. @JavaMethod @_nonoverride public convenience init(_ arg0: Handler.Callback?, environment: JNIEnvironment? = nil) + /// Uses the provided `Looper` instead of the default one. @JavaMethod @_nonoverride public convenience init(_ arg0: Looper?, environment: JNIEnvironment? = nil) + /// Uses the provided `Looper` instead of the default one and takes a callback interface in which + /// you can handle messages. @JavaMethod @_nonoverride public convenience init(_ arg0: Looper?, _ arg1: Handler.Callback?, environment: JNIEnvironment? = nil) + /// Default constructor associates this handler with the `Looper` for the current thread. + /// + /// - Note: Deprecated since API 30. Use `Handler(Looper)` instead. @JavaMethod @_nonoverride public convenience init(environment: JNIEnvironment? = nil) + /// Subclasses must implement this to receive messages. @JavaMethod open func handleMessage(_ arg0: Message?) + /// Handle system messages here. @JavaMethod open func dispatchMessage(_ arg0: Message?) + /// Returns a string representing the name of the specified message. + /// + /// The default implementation will either return the class name of the message callback if any, + /// or the hexadecimal representation of the message's `what` field. @JavaMethod open func getMessageName(_ arg0: Message?) -> String + /// Returns a new `Message` from the global message pool. + /// + /// Allows us to avoid allocating new objects in many cases. @JavaMethod open func obtainMessage() -> Message! + /// Same as `obtainMessage()`, except that it also sets the what member of the returned Message. @JavaMethod open func obtainMessage(_ arg0: Int32) -> Message! + /// Same as `obtainMessage()`, except that it also sets the what, arg1, arg2 and obj members. @JavaMethod open func obtainMessage(_ arg0: Int32, _ arg1: Int32, _ arg2: Int32, _ arg3: JavaObject?) -> Message! + /// Same as `obtainMessage()`, except that it also sets the what, arg1 and arg2 members. @JavaMethod open func obtainMessage(_ arg0: Int32, _ arg1: Int32, _ arg2: Int32) -> Message! + /// Same as `obtainMessage()`, except that it also sets the what and obj members. @JavaMethod open func obtainMessage(_ arg0: Int32, _ arg1: JavaObject?) -> Message! + /// Causes the Runnable `arg0` to be added to the message queue, to be run at a specific time + /// given by `arg1`. The time-base is `SystemClock.uptimeMillis`. + /// + /// - Returns: `true` if the Runnable was successfully placed in to the message queue. @JavaMethod open func postAtTime(_ arg0: Runnable?, _ arg1: Int64) -> Bool + /// Causes the Runnable `arg0` to be added to the message queue, to be run at a specific time + /// given by `arg2`. The time-base is `SystemClock.uptimeMillis`. + /// + /// - Parameter arg1: An optional token to associate with the runnable (used for cancellation). + /// - Returns: `true` if the Runnable was successfully placed in to the message queue. @JavaMethod open func postAtTime(_ arg0: Runnable?, _ arg1: JavaObject?, _ arg2: Int64) -> Bool + /// Causes the Runnable `arg0` to be added to the message queue, to be run after the specified + /// amount of time elapses. + /// + /// - Parameter arg1: An optional token to associate with the runnable (used for cancellation). + /// - Parameter arg2: The delay in milliseconds. + /// - Returns: `true` if the Runnable was successfully placed in to the message queue. + @available(Android 28, *) @JavaMethod open func postDelayed(_ arg0: Runnable?, _ arg1: JavaObject?, _ arg2: Int64) -> Bool + /// Causes the Runnable `arg0` to be added to the message queue, to be run after the specified + /// amount of time elapses. + /// + /// - Parameter arg1: The delay in milliseconds. + /// - Returns: `true` if the Runnable was successfully placed in to the message queue. @JavaMethod open func postDelayed(_ arg0: Runnable?, _ arg1: Int64) -> Bool + /// Posts a runnable to the front of the message queue. Use with care. + /// + /// - Returns: `true` if the Runnable was successfully placed in to the message queue. @JavaMethod open func postAtFrontOfQueue(_ arg0: Runnable?) -> Bool + /// Remove any pending posts of Runnable `arg0` that are in the message queue, + /// filtered by the given token. @JavaMethod open func removeCallbacks(_ arg0: Runnable?, _ arg1: JavaObject?) + /// Remove any pending posts of Runnable `arg0` that are in the message queue. @JavaMethod open func removeCallbacks(_ arg0: Runnable?) + /// Push a message onto the end of the message queue after all pending messages + /// before the current time. It will be received in `handleMessage(Message)`, in the + /// thread attached to this handler. + /// + /// - Returns: `true` if the message was successfully placed in to the message queue. @JavaMethod open func sendMessage(_ arg0: Message?) -> Bool + /// Sends a Message containing only the `what` value. + /// + /// - Returns: `true` if the message was successfully placed in to the message queue. @JavaMethod open func sendEmptyMessage(_ arg0: Int32) -> Bool + /// Sends a Message containing only the `what` value, to be delivered after the specified + /// amount of time elapses. + /// + /// - Returns: `true` if the message was successfully placed in to the message queue. @JavaMethod open func sendEmptyMessageDelayed(_ arg0: Int32, _ arg1: Int64) -> Bool + /// Sends a Message containing only the `what` value, to be delivered at a specific time. + /// + /// - Returns: `true` if the message was successfully placed in to the message queue. @JavaMethod open func sendEmptyMessageAtTime(_ arg0: Int32, _ arg1: Int64) -> Bool + /// Enqueue a message into the message queue after all pending messages before + /// (current time + `arg1`) milliseconds. + /// + /// - Returns: `true` if the message was successfully placed in to the message queue. @JavaMethod open func sendMessageDelayed(_ arg0: Message?, _ arg1: Int64) -> Bool + /// Enqueue a message into the message queue after all pending messages + /// before the absolute time (in milliseconds) `arg1`. + /// + /// - Returns: `true` if the message was successfully placed in to the message queue. @JavaMethod open func sendMessageAtTime(_ arg0: Message?, _ arg1: Int64) -> Bool + /// Enqueue a message at the front of the message queue. Use with care. + /// + /// - Returns: `true` if the message was successfully placed in to the message queue. @JavaMethod open func sendMessageAtFrontOfQueue(_ arg0: Message?) -> Bool + /// Remove any pending posts of messages with code `arg0` that are in the message queue. @JavaMethod open func removeMessages(_ arg0: Int32) + /// Remove any pending posts of messages with code `arg0` and whose `obj` is `arg1` that are in + /// the message queue. If `arg1` is nil, all messages with code `arg0` are removed. @JavaMethod open func removeMessages(_ arg0: Int32, _ arg1: JavaObject?) + /// Remove any pending posts of callbacks and sent messages whose `obj` is `arg0`. + /// If `arg0` is nil, all callbacks and messages will be removed. @JavaMethod open func removeCallbacksAndMessages(_ arg0: JavaObject?) + /// Check if there are any pending posts of messages with the specified runnable in the + /// message queue. + @available(Android 29, *) @JavaMethod open func hasCallbacks(_ arg0: Runnable?) -> Bool + /// Returns the `Looper` object associated with this handler. @JavaMethod open func getLooper() -> Looper! + /// Check if there are any pending posts of messages with code `arg0` and whose `obj` + /// is `arg1` in the message queue. @JavaMethod open func hasMessages(_ arg0: Int32, _ arg1: JavaObject?) -> Bool + /// Check if there are any pending posts of messages with code `arg0` in the message queue. @JavaMethod open func hasMessages(_ arg0: Int32) -> Bool @JavaMethod open override func toString() -> String + /// Causes the Runnable `arg0` to be added to the message queue. + /// + /// - Returns: `true` if the Runnable was successfully placed in to the message queue. @JavaMethod open func post(_ arg0: Runnable?) -> Bool } extension JavaClass { + /// Creates a handler with callbacks to handle messages without deriving from the Handler class. + /// + /// This handler ignores any messages for which the callback returns `true`. + /// + /// - Parameter arg0: The `Looper` to use. + /// - Returns: A new async `Handler`. + @available(Android 28, *) @JavaStaticMethod public func createAsync(_ arg0: Looper?) -> Handler! + /// Creates a handler with callbacks to handle messages without deriving from the Handler class. + /// + /// This is an async handler, allowing longer work to be done without stopping the event processing. + /// + /// - Parameter arg0: The `Looper` to use. + /// - Parameter arg1: The callback to handle messages. + /// - Returns: A new async `Handler`. + @available(Android 28, *) @JavaStaticMethod public func createAsync(_ arg0: Looper?, _ arg1: Handler.Callback?) -> Handler! } diff --git a/Sources/AndroidOS/HandlerThread.swift b/Sources/AndroidOS/HandlerThread.swift index ab727805..4b237b19 100644 --- a/Sources/AndroidOS/HandlerThread.swift +++ b/Sources/AndroidOS/HandlerThread.swift @@ -3,6 +3,10 @@ import JavaLang import SwiftJava import CSwiftJavaJNI +/// A `Thread` that has a `Looper`. The looper can then be used to create handler classes. +/// Note that `start()` must still be called. +/// +/// See also: [android.os.HandlerThread](https://developer.android.com/reference/android/os/HandlerThread) @JavaClass("android.os.HandlerThread") open class HandlerThread: Thread { @JavaMethod diff --git a/Sources/AndroidOS/HardwarePropertiesManager.swift b/Sources/AndroidOS/HardwarePropertiesManager.swift index 4b64281a..2a86f6a5 100644 --- a/Sources/AndroidOS/HardwarePropertiesManager.swift +++ b/Sources/AndroidOS/HardwarePropertiesManager.swift @@ -2,14 +2,28 @@ import SwiftJava import CSwiftJavaJNI +/// Provides access to hardware sensor data such as device temperatures, CPU usage, and fan speeds. +/// +/// Obtain an instance via `Context.getSystemService(Context.HARDWARE_PROPERTIES_SERVICE)`. +/// Requires the `DEVICE_POWER` permission. +/// +/// See [android.os.HardwarePropertiesManager](https://developer.android.com/reference/android/os/HardwarePropertiesManager) +@available(Android 24, *) @JavaClass("android.os.HardwarePropertiesManager") open class HardwarePropertiesManager: JavaObject { + /// Returns the temperatures (in degrees Celsius) of the given device component type and temperature type. + /// + /// - Parameters: + /// - arg0: One of the `DEVICE_TEMPERATURE_*` constants specifying the component (e.g., CPU, GPU, battery). + /// - arg1: One of the `TEMPERATURE_*` constants specifying the reading type (e.g., current, throttling, shutdown). @JavaMethod open func getDeviceTemperatures(_ arg0: Int32, _ arg1: Int32) -> [Float] + /// Returns per-CPU-core usage information. @JavaMethod open func getCpuUsages() -> [CpuUsageInfo?] + /// Returns the speeds (in RPM) of the device's fans, or an empty array if none are present. @JavaMethod open func getFanSpeeds() -> [Float] } diff --git a/Sources/AndroidOS/HealthStats.swift b/Sources/AndroidOS/HealthStats.swift index 8b3af0f1..170aba0f 100644 --- a/Sources/AndroidOS/HealthStats.swift +++ b/Sources/AndroidOS/HealthStats.swift @@ -4,6 +4,13 @@ import JavaLangUtil import SwiftJava import CSwiftJavaJNI +/// A map of health stats data collected for a uid, package, pid, process, or service. +/// +/// Keys are defined in the concrete subclasses: `UidHealthStats`, `PackageHealthStats`, +/// `PidHealthStats`, `ProcessHealthStats`, and `ServiceHealthStats`. +/// +/// See also: [android.os.health.HealthStats](https://developer.android.com/reference/android/os/health/HealthStats) +@available(Android 24, *) @JavaClass("android.os.health.HealthStats") open class HealthStats: JavaObject { @JavaMethod diff --git a/Sources/AndroidOS/IBinder+DeathRecipient.swift b/Sources/AndroidOS/IBinder+DeathRecipient.swift index f700aeec..59c3c2ac 100644 --- a/Sources/AndroidOS/IBinder+DeathRecipient.swift +++ b/Sources/AndroidOS/IBinder+DeathRecipient.swift @@ -3,8 +3,13 @@ import SwiftJava import CSwiftJavaJNI extension IBinder { + /// Interface for receiving a callback when the process hosting an IBinder has gone away. + /// + /// See also: [android.os.IBinder.DeathRecipient](https://developer.android.com/reference/android/os/IBinder.DeathRecipient) @JavaInterface("android.os.IBinder$DeathRecipient") public struct DeathRecipient { + /// Called when the process containing this binder has unexpectedly gone away (typically because + /// its hosting process has been killed). @JavaMethod public func binderDied() } diff --git a/Sources/AndroidOS/IBinder.swift b/Sources/AndroidOS/IBinder.swift index 58200aa6..45f31e77 100644 --- a/Sources/AndroidOS/IBinder.swift +++ b/Sources/AndroidOS/IBinder.swift @@ -4,60 +4,133 @@ import JavaLangIO import SwiftJava import CSwiftJavaJNI +/// Base interface for a remotable object, the core part of a lightweight remote procedure call +/// mechanism designed for high performance when performing in-process and cross-process calls. +/// This interface describes the abstract protocol for interacting with a remotable object. +/// +/// Do not implement this interface directly, instead extend from `Binder`. +/// +/// The key IBinder API is `transact()` matched with `Binder.onTransact()`. These methods allow +/// you to send a call to an IBinder object and receive a call coming in to a Binder object, +/// respectively. This transaction API is synchronous, such that a call to `transact()` does not +/// return until the target has returned from `Binder.onTransact()`; this is the expected behavior +/// when calling an object that exists in the local process, and the underlying inter-process +/// communication (IPC) mechanism also provides this behavior. +/// +/// See also: [android.os.IBinder](https://developer.android.com/reference/android/os/IBinder) @JavaInterface("android.os.IBinder") public struct IBinder { + /// Get the canonical name of the interface supported by this binder. @JavaMethod public func getInterfaceDescriptor() throws -> String + /// Check to see if the object still exists. + /// + /// - Returns: `true` if the process in which the binder is running still exists, + /// and `false` if not. Note that if `false` is returned, this does not tell you that the + /// binder has completely died; it is possible that the binder is running in a remote + /// process but there is a transient problem preventing communication. @JavaMethod public func pingBinder() -> Bool + /// Check to see if the process that the binder is in is still alive. + /// + /// - Returns: `false` if the process is not alive. Note that if it returns `true`, the process + /// may have died while the call was in progress if you're not holding a reference count on the + /// binder in the remote process. @JavaMethod public func isBinderAlive() -> Bool + /// Attempt to retrieve a local implementation of an interface for this Binder object. + /// + /// If null is returned, you will need to instantiate a proxy class to marshal calls through + /// the transact() method. @JavaMethod public func queryLocalInterface(_ arg0: String) -> IInterface! + /// Implemented to provide to dump() the output to the given file descriptor, asynchronously. @JavaMethod public func dumpAsync(_ arg0: FileDescriptor?, _ arg1: [String]) throws + /// Perform a generic operation with the object. + /// + /// - Parameter arg0: The action to perform. This should be a number between + /// `FIRST_CALL_TRANSACTION` and `LAST_CALL_TRANSACTION`. + /// - Parameter arg1: Marshalled data to send to the target. Must not be nil. + /// If you are not sending any data, you must create an empty Parcel that is given here. + /// - Parameter arg2: Marshalled data to be received from the target. May be nil if you are + /// not interested in the return value. + /// - Parameter arg3: Additional operation flags. Either 0 for a normal RPC, or `FLAG_ONEWAY` + /// for a one-way RPC. + /// + /// - Returns: Returns the result from calling `Binder.onTransact()`. A successful call generally + /// returns `true`; `false` generally means the transaction code was not understood. @JavaMethod public func transact(_ arg0: Int32, _ arg1: Parcel?, _ arg2: Parcel?, _ arg3: Int32) throws -> Bool + /// Register the recipient for a notification if this binder goes away. + /// + /// If this binder object unexpectedly goes away (typically because its hosting process + /// has been killed), then the given `DeathRecipient`'s `binderDied()` method will be called. + /// + /// - Parameter arg0: The object to be called when the binder's process dies. + /// - Parameter arg1: Reserved, should be 0. @JavaMethod public func linkToDeath(_ arg0: IBinder.DeathRecipient?, _ arg1: Int32) throws + /// Remove a previously registered death notification. + /// + /// The recipient will no longer be called if this object dies. + /// + /// - Returns: `true` if the given death recipient was previously registered with + /// `linkToDeath()`, `false` otherwise. @JavaMethod public func unlinkToDeath(_ arg0: IBinder.DeathRecipient?, _ arg1: Int32) -> Bool + /// Print the object's state into the given stream. @JavaMethod public func dump(_ arg0: FileDescriptor?, _ arg1: [String]) throws } extension JavaClass { + /// IBinder protocol transaction code: `dump` the object. @JavaStaticField(isFinal: true) public var DUMP_TRANSACTION: Int32 + /// The first transaction code available for user commands. @JavaStaticField(isFinal: true) public var FIRST_CALL_TRANSACTION: Int32 + /// Flag to `transact()`: this is a one-way call, meaning that the caller returns immediately, + /// without waiting for a result from the callee. Applies only if the caller and callee are in + /// different processes. @JavaStaticField(isFinal: true) public var FLAG_ONEWAY: Int32 + /// IBinder protocol transaction code: interrogate the recipient side of the transaction for its + /// canonical interface descriptor. @JavaStaticField(isFinal: true) public var INTERFACE_TRANSACTION: Int32 + /// The last transaction code available for user commands (inclusive). @JavaStaticField(isFinal: true) public var LAST_CALL_TRANSACTION: Int32 + /// IBinder protocol transaction code: tell an app process that the caller likes it. @JavaStaticField(isFinal: true) public var LIKE_TRANSACTION: Int32 + /// IBinder protocol transaction code: `pingBinder()`. @JavaStaticField(isFinal: true) public var PING_TRANSACTION: Int32 + /// IBinder protocol transaction code: send a tweet to the target object. @JavaStaticField(isFinal: true) public var TWEET_TRANSACTION: Int32 + /// Returns the maximum suggested IPC payload size for a bulk data transfer. + /// + /// - Returns: The recommended maximum IPC payload size in bytes. + @available(Android 30, *) @JavaStaticMethod public func getSuggestedMaxIpcSizeBytes() -> Int32 } diff --git a/Sources/AndroidOS/IInterface.swift b/Sources/AndroidOS/IInterface.swift index dab84ac6..245f2df7 100644 --- a/Sources/AndroidOS/IInterface.swift +++ b/Sources/AndroidOS/IInterface.swift @@ -2,8 +2,16 @@ import SwiftJava import CSwiftJavaJNI +/// Base class for Binder interfaces. When defining a new interface, you must derive it from +/// IInterface. +/// +/// See also: [android.os.IInterface](https://developer.android.com/reference/android/os/IInterface) @JavaInterface("android.os.IInterface") public struct IInterface { + /// Retrieve the Binder object associated with this interface. + /// + /// You must use this instead of a plain cast, so that proxy objects can return the correct + /// result. @JavaMethod public func asBinder() -> IBinder! } diff --git a/Sources/AndroidOS/ImplicitDirectBootViolation.swift b/Sources/AndroidOS/ImplicitDirectBootViolation.swift index 49c87a5d..0cfed199 100644 --- a/Sources/AndroidOS/ImplicitDirectBootViolation.swift +++ b/Sources/AndroidOS/ImplicitDirectBootViolation.swift @@ -2,6 +2,10 @@ import SwiftJava import CSwiftJavaJNI +/// Violation raised when a direct-boot unaware component is implicitly accessed before the user unlocks the device. +/// +/// See also: [android.os.strictmode.ImplicitDirectBootViolation](https://developer.android.com/reference/android/os/strictmode/ImplicitDirectBootViolation) +@available(Android 28, *) @JavaClass("android.os.strictmode.ImplicitDirectBootViolation") open class ImplicitDirectBootViolation: Violation { diff --git a/Sources/AndroidOS/IncorrectContextUseViolation.swift b/Sources/AndroidOS/IncorrectContextUseViolation.swift index 48c3449e..711de98a 100644 --- a/Sources/AndroidOS/IncorrectContextUseViolation.swift +++ b/Sources/AndroidOS/IncorrectContextUseViolation.swift @@ -2,8 +2,13 @@ import SwiftJava import CSwiftJavaJNI +/// Violation raised when a `Context` is used in an incorrect way, such as using an Activity context where an Application context is required. +/// +/// See also: [android.os.strictmode.IncorrectContextUseViolation](https://developer.android.com/reference/android/os/strictmode/IncorrectContextUseViolation) +@available(Android 31, *) @JavaClass("android.os.strictmode.IncorrectContextUseViolation") open class IncorrectContextUseViolation: Violation { + /// Creates a new violation with the given message and optional cause. @JavaMethod @_nonoverride public convenience init(_ arg0: String, _ arg1: Throwable?, environment: JNIEnvironment? = nil) } diff --git a/Sources/AndroidOS/InstanceCountViolation.swift b/Sources/AndroidOS/InstanceCountViolation.swift index 529634f1..11532711 100644 --- a/Sources/AndroidOS/InstanceCountViolation.swift +++ b/Sources/AndroidOS/InstanceCountViolation.swift @@ -2,8 +2,14 @@ import SwiftJava import CSwiftJavaJNI +/// Violation raised when the number of live instances of a class exceeds the limit set by +/// `StrictMode.VmPolicy.Builder.setClassInstanceLimit`. +/// +/// See also: [android.os.strictmode.InstanceCountViolation](https://developer.android.com/reference/android/os/strictmode/InstanceCountViolation) +@available(Android 28, *) @JavaClass("android.os.strictmode.InstanceCountViolation") open class InstanceCountViolation: Violation { + /// Returns the number of live instances of the class that triggered this violation. @JavaMethod open func getNumberOfInstances() -> Int64 } diff --git a/Sources/AndroidOS/IntentReceiverLeakedViolation.swift b/Sources/AndroidOS/IntentReceiverLeakedViolation.swift index 21042149..5cb4ab78 100644 --- a/Sources/AndroidOS/IntentReceiverLeakedViolation.swift +++ b/Sources/AndroidOS/IntentReceiverLeakedViolation.swift @@ -2,6 +2,10 @@ import SwiftJava import CSwiftJavaJNI +/// Violation raised when a `BroadcastReceiver` is leaked (registered but not unregistered). +/// +/// See also: [android.os.strictmode.IntentReceiverLeakedViolation](https://developer.android.com/reference/android/os/strictmode/IntentReceiverLeakedViolation) +@available(Android 28, *) @JavaClass("android.os.strictmode.IntentReceiverLeakedViolation") open class IntentReceiverLeakedViolation: Violation { diff --git a/Sources/AndroidOS/LeakedClosableViolation.swift b/Sources/AndroidOS/LeakedClosableViolation.swift index 935060f9..bb031ef4 100644 --- a/Sources/AndroidOS/LeakedClosableViolation.swift +++ b/Sources/AndroidOS/LeakedClosableViolation.swift @@ -2,6 +2,10 @@ import SwiftJava import CSwiftJavaJNI +/// Violation raised when a `Closeable` object is finalized without being closed first. +/// +/// See also: [android.os.strictmode.LeakedClosableViolation](https://developer.android.com/reference/android/os/strictmode/LeakedClosableViolation) +@available(Android 28, *) @JavaClass("android.os.strictmode.LeakedClosableViolation") open class LeakedClosableViolation: Violation { diff --git a/Sources/AndroidOS/LimitExceededException.swift b/Sources/AndroidOS/LimitExceededException.swift index cde96523..ba4ca334 100644 --- a/Sources/AndroidOS/LimitExceededException.swift +++ b/Sources/AndroidOS/LimitExceededException.swift @@ -3,6 +3,11 @@ import JavaLang import SwiftJava import CSwiftJavaJNI +/// Thrown when a caller has exceeded a resource or rate limit imposed by the system or a service. +/// The specific limit that was exceeded is typically described in the exception message. +/// +/// See also: [android.os.LimitExceededException](https://developer.android.com/reference/android/os/LimitExceededException) +@available(Android 31, *) @JavaClass("android.os.LimitExceededException") open class LimitExceededException: IllegalStateException { @JavaMethod diff --git a/Sources/AndroidOS/LocaleList.swift b/Sources/AndroidOS/LocaleList.swift index 54c86cfd..a45d8a9a 100644 --- a/Sources/AndroidOS/LocaleList.swift +++ b/Sources/AndroidOS/LocaleList.swift @@ -4,6 +4,13 @@ import JavaLangUtil import SwiftJava import CSwiftJavaJNI +/// An immutable, ordered list of locales that can be used to express language preferences. +/// +/// Used by the system to determine the best locale for the user's language settings. +/// Instances are parcelable and can be constructed from BCP 47 language tags. +/// +/// See also: [android.os.LocaleList](https://developer.android.com/reference/android/os/LocaleList) +@available(Android 24, *) @JavaClass("android.os.LocaleList", implements: Parcelable.self) open class LocaleList: JavaObject { @JavaMethod @@ -15,15 +22,20 @@ open class LocaleList: JavaObject { @JavaMethod open func writeToParcel(_ arg0: Parcel?, _ arg1: Int32) + /// Returns a comma-separated BCP 47 language tag string representing all locales in this list. @JavaMethod open func toLanguageTags() -> String + /// Returns the first locale from this list that appears in the given array of supported locales, + /// or `nil` if none match. @JavaMethod open func getFirstMatch(_ arg0: [String]) -> Locale! + /// Returns the number of locales in this list. @JavaMethod open func size() -> Int32 + /// Returns the locale at the given index. @JavaMethod open func get(_ arg0: Int32) -> Locale! @@ -36,9 +48,11 @@ open class LocaleList: JavaObject { @JavaMethod open override func hashCode() -> Int32 + /// Returns the index of the given locale in this list, or `-1` if not found. @JavaMethod open func indexOf(_ arg0: Locale?) -> Int32 + /// Returns `true` if this list contains no locales. @JavaMethod open func isEmpty() -> Bool } @@ -52,21 +66,27 @@ extension JavaClass { @JavaStaticField(isFinal: true) public var PARCELABLE_WRITE_RETURN_VALUE: Int32 + /// Returns an empty `LocaleList`. @JavaStaticMethod public func getEmptyLocaleList() -> LocaleList! + /// Constructs a `LocaleList` from a comma-separated BCP 47 language tag string. @JavaStaticMethod public func forLanguageTags(_ arg0: String) -> LocaleList! @JavaStaticMethod public func matchesLanguageAndScript(_ arg0: Locale?, _ arg1: Locale?) -> Bool + /// Returns the locale list that best represents the current user's preferences, + /// adjusted for the default locale overrides. @JavaStaticMethod public func getAdjustedDefault() -> LocaleList! + /// Returns the system default `LocaleList`. @JavaStaticMethod public func getDefault() -> LocaleList! + /// Sets the system default `LocaleList`. Requires appropriate system permissions. @JavaStaticMethod public func setDefault(_ arg0: LocaleList?) } diff --git a/Sources/AndroidOS/Looper.swift b/Sources/AndroidOS/Looper.swift index 3e2bb432..079f6b1a 100644 --- a/Sources/AndroidOS/Looper.swift +++ b/Sources/AndroidOS/Looper.swift @@ -3,42 +3,86 @@ import JavaLang import SwiftJava import CSwiftJavaJNI +/// Class used to run a message loop for a thread. Threads by default do not have a message loop +/// associated with them; to create one, call `prepare()` in the thread that is to run the loop, +/// and then `loop()` to have it process messages until the loop is stopped. +/// +/// Most interaction with a message loop is through the `Handler` class. +/// +/// See also: [android.os.Looper](https://developer.android.com/reference/android/os/Looper) @JavaClass("android.os.Looper") open class Looper: JavaObject { + /// Returns true if the current thread is this looper's thread. + @available(Android 19, *) @JavaMethod open func isCurrentThread() -> Bool + /// Quits the looper. + /// + /// Causes the `loop()` method to terminate without processing any more messages in the + /// message queue. Any attempt to post messages to the queue after the looper is asked to quit + /// will fail. Any messages that have already been dispatched will continue to be processed. + /// + /// - Note: Using this method may be unsafe because some messages may not be delivered before + /// the looper terminates. Consider using `quitSafely()` instead. @JavaMethod open func quit() + /// Quits the looper safely. + /// + /// Causes the `loop()` method to terminate as soon as all remaining messages in the message queue + /// that are already due to be delivered have been handled. However, pending delayed messages + /// whose due time has not come will not be delivered before the loop terminates. + @available(Android 18, *) @JavaMethod open func quitSafely() + /// Gets the Thread associated with this Looper. @JavaMethod open func getThread() -> Thread! @JavaMethod open override func toString() -> String + /// Gets the message queue associated with this looper. @JavaMethod open func getQueue() -> MessageQueue! } extension JavaClass { + /// Initialize the current thread as a looper, marking it as an application's main looper. + /// + /// The main looper for your application is created by the Android environment, so you should + /// never need to call this function yourself. + /// + /// - Note: Deprecated since API 33. @JavaStaticMethod public func prepareMainLooper() + /// Returns the application's main looper, which lives in the main thread of the application. @JavaStaticMethod public func getMainLooper() -> Looper! + /// Return the Looper object associated with the current thread. + /// + /// - Returns: `nil` if the calling thread is not associated with a Looper. @JavaStaticMethod public func myLooper() -> Looper! + /// Return the `MessageQueue` object associated with the current thread. + /// + /// - Returns: The MessageQueue for the current thread. @JavaStaticMethod public func myQueue() -> MessageQueue! + /// Initialize the current thread as a looper. + /// + /// This gives you a chance to create handlers that then reference this looper, before actually + /// starting the loop. Be sure to call `loop()` after calling this method, and to stop the loop + /// by calling `quit()`. @JavaStaticMethod public func prepare() + /// Run the message queue in this thread. Be sure to call `quit()` to end the loop. @JavaStaticMethod public func loop() } diff --git a/Sources/AndroidOS/MemoryFile.swift b/Sources/AndroidOS/MemoryFile.swift index 6ca01852..923e347a 100644 --- a/Sources/AndroidOS/MemoryFile.swift +++ b/Sources/AndroidOS/MemoryFile.swift @@ -4,32 +4,48 @@ import JavaLangIO import SwiftJava import CSwiftJavaJNI +/// An anonymous shared memory file backed by a file descriptor, allowing data to be shared between processes. +/// +/// See [android.os.MemoryFile](https://developer.android.com/reference/android/os/MemoryFile) @JavaClass("android.os.MemoryFile") open class MemoryFile: JavaObject { + /// Creates a new `MemoryFile` with the given name and size in bytes. + /// + /// The name is for debugging purposes only and does not affect behavior. @JavaMethod @_nonoverride public convenience init(_ arg0: String, _ arg1: Int32, environment: JNIEnvironment? = nil) throws + /// Returns whether the memory file's pages may be released by the kernel under memory pressure. @JavaMethod open func isPurgingAllowed() -> Bool + /// Sets whether the memory file's pages may be purged under memory pressure. + /// + /// Returns the previous value of the purging-allowed flag. @JavaMethod open func allowPurging(_ arg0: Bool) throws -> Bool + /// Returns an `OutputStream` that writes to this memory file. @JavaMethod open func getOutputStream() -> OutputStream! + /// Returns the size of this memory file in bytes. @JavaMethod open func length() -> Int32 + /// Closes this memory file, releasing its underlying resources. @JavaMethod open func close() + /// Returns an `InputStream` that reads from this memory file. @JavaMethod open func getInputStream() -> InputStream! + /// Reads up to `arg3` bytes from this memory file starting at `arg2` into `arg0` starting at `arg1`. @JavaMethod open func readBytes(_ arg0: [Int8], _ arg1: Int32, _ arg2: Int32, _ arg3: Int32) throws -> Int32 + /// Writes `arg3` bytes to this memory file starting at `arg2` from `arg0` starting at `arg1`. @JavaMethod open func writeBytes(_ arg0: [Int8], _ arg1: Int32, _ arg2: Int32, _ arg3: Int32) throws } diff --git a/Sources/AndroidOS/Message.swift b/Sources/AndroidOS/Message.swift index 6b4d1813..c288cd1f 100644 --- a/Sources/AndroidOS/Message.swift +++ b/Sources/AndroidOS/Message.swift @@ -3,23 +3,46 @@ import JavaLang import SwiftJava import CSwiftJavaJNI +/// Defines a message containing a description and arbitrary data object that can be sent to a +/// `Handler`. This object contains two extra int fields and an extra object field that allow you +/// to not do allocations in many cases. +/// +/// While the constructor of Message is public, the best way to get one of these is to call +/// `Message.obtain()` or one of the `Handler.obtainMessage()` methods, which will pull them from +/// a pool of recycled objects. +/// +/// See also: [android.os.Message](https://developer.android.com/reference/android/os/Message) @JavaClass("android.os.Message", implements: Parcelable.self) open class Message: JavaObject { + /// `arg1` and `arg2` are lower-cost alternatives to using `setData()` if you only need to store + /// a few integer values. @JavaField(isFinal: false) public var arg1: Int32 + /// `arg1` and `arg2` are lower-cost alternatives to using `setData()` if you only need to store + /// a few integer values. @JavaField(isFinal: false) public var arg2: Int32 + /// An arbitrary object to send to the recipient. When using Messenger to send the message + /// across processes this can only be non-nil if it contains a Parcelable of a framework class + /// (not one implemented by the application). @JavaField(isFinal: false) public var obj: JavaObject! + /// Optional Messenger where replies to this message can be sent. @JavaField(isFinal: false) public var replyTo: Messenger! + /// Optional field indicating the uid that sent the message. Only valid for messages posted by + /// a Messenger; otherwise, it will be -1. + @available(Android 21, *) @JavaField(isFinal: false) public var sendingUid: Int32 + /// User-defined message code so that the recipient can identify what this message is about. + /// Each `Handler` has its own name-space for message codes, so you do not need to worry about + /// yours conflicting with other handlers. @JavaField(isFinal: false) public var what: Int32 @@ -32,42 +55,76 @@ open class Message: JavaObject { @JavaMethod open func writeToParcel(_ arg0: Parcel?, _ arg1: Int32) + /// Returns the targeted delivery time of this message, in milliseconds. @JavaMethod open func getWhen() -> Int64 + /// Retrieves a callback object that will be executed if this message is dispatched. @JavaMethod open func getCallback() -> Runnable! + /// Like `getData()`, but does not lazily create the Bundle. + /// + /// A null is returned if the Bundle does not already exist. See `getData()` for further + /// information on a Bundle's contents. @JavaMethod open func peekData() -> Bundle! + /// Sets a Bundle of arbitrary data values. Use the `arg1` and `arg2` members as a lower cost + /// way to send a few simple integer values, if you can. @JavaMethod open func setData(_ arg0: Bundle?) + /// Sends this Message to the Handler specified by `getTarget()`. + /// + /// Throws a null pointer exception if this field has not been set. @JavaMethod open func sendToTarget() + /// Returns true if the message is asynchronous, meaning that it is not subject to Looper + /// synchronization barriers. + @available(Android 22, *) @JavaMethod open func isAsynchronous() -> Bool + /// Sets whether the message is asynchronous, meaning that it is not subject to Looper + /// synchronization barriers. + @available(Android 22, *) @JavaMethod open func setAsynchronous(_ arg0: Bool) + /// Return a Message instance to the global pool. + /// + /// You MUST NOT touch the Message after calling this function because it has effectively been + /// freed. It is an error to recycle a message that is currently enqueued or that is in the + /// process of being delivered to a Handler. @JavaMethod open func recycle() @JavaMethod open override func toString() -> String + /// Retrieve the target Handler implementation that will receive this message. @JavaMethod open func getTarget() -> Handler! + /// Sets the Handler implementation that will receive this message object. + /// + /// - Note: Deprecated since API 33. @JavaMethod open func setTarget(_ arg0: Handler?) + /// Make this message like `arg0`. Performs a shallow copy of the data field. + /// Does not copy the linked list fields, nor the timestamp or target/callback of the original message. @JavaMethod open func copyFrom(_ arg0: Message?) + /// Obtains a Bundle of arbitrary data associated with this event, lazily creating it if necessary. + /// Set this value by calling `setData(Bundle)`. + /// + /// - Note: When transferring data across processes via `Messenger`, you will need to set your + /// class loader on the Bundle via `Bundle.setClassLoader()` so that it can instantiate your + /// objects when you retrieve them. @JavaMethod open func getData() -> Bundle! } @@ -81,27 +138,38 @@ extension JavaClass { @JavaStaticField(isFinal: true) public var PARCELABLE_WRITE_RETURN_VALUE: Int32 + /// Return a new Message instance from the global pool by copying the fields of the provided + /// source message. @JavaStaticMethod public func obtain(_ arg0: Message?) -> Message! + /// Return a new Message instance from the global pool. + /// + /// Allows us to avoid allocating new objects in many cases. @JavaStaticMethod public func obtain() -> Message! + /// Same as `obtain()`, but sets the values of the target, what, arg1, arg2, and obj members. @JavaStaticMethod public func obtain(_ arg0: Handler?, _ arg1: Int32, _ arg2: Int32, _ arg3: Int32, _ arg4: JavaObject?) -> Message! + /// Same as `obtain()`, but sets the values of the target, what, arg1, and arg2 members. @JavaStaticMethod public func obtain(_ arg0: Handler?, _ arg1: Int32, _ arg2: Int32, _ arg3: Int32) -> Message! + /// Same as `obtain()`, but sets the values of the target, what, and obj members. @JavaStaticMethod public func obtain(_ arg0: Handler?, _ arg1: Int32, _ arg2: JavaObject?) -> Message! + /// Same as `obtain()`, but sets the values of the target and what members. @JavaStaticMethod public func obtain(_ arg0: Handler?, _ arg1: Int32) -> Message! + /// Same as `obtain()`, but sets the values of the target and callback members. @JavaStaticMethod public func obtain(_ arg0: Handler?, _ arg1: Runnable?) -> Message! + /// Same as `obtain()`, but sets the value of the target member. @JavaStaticMethod public func obtain(_ arg0: Handler?) -> Message! } diff --git a/Sources/AndroidOS/MessageQueue+IdleHandler.swift b/Sources/AndroidOS/MessageQueue+IdleHandler.swift index 36c11bd0..92a014f9 100644 --- a/Sources/AndroidOS/MessageQueue+IdleHandler.swift +++ b/Sources/AndroidOS/MessageQueue+IdleHandler.swift @@ -3,8 +3,15 @@ import SwiftJava import CSwiftJavaJNI extension MessageQueue { + /// Callback interface for discovering when a thread is going to block waiting for more messages. + /// + /// See also: [android.os.MessageQueue.IdleHandler](https://developer.android.com/reference/android/os/MessageQueue.IdleHandler) @JavaInterface("android.os.MessageQueue$IdleHandler") public struct IdleHandler { + /// Called when the message queue has run out of messages and will now wait for more. + /// + /// - Returns: `true` to keep your idle handler active, `false` to have it removed. Returning + /// `false` is the same as calling `removeIdleHandler(IdleHandler)`. @JavaMethod public func queueIdle() -> Bool } diff --git a/Sources/AndroidOS/MessageQueue+OnFileDescriptorEventListener.swift b/Sources/AndroidOS/MessageQueue+OnFileDescriptorEventListener.swift index 0b47223c..ca145e8e 100644 --- a/Sources/AndroidOS/MessageQueue+OnFileDescriptorEventListener.swift +++ b/Sources/AndroidOS/MessageQueue+OnFileDescriptorEventListener.swift @@ -5,19 +5,31 @@ import SwiftJava import CSwiftJavaJNI extension MessageQueue { + /// A listener which is invoked when file descriptor related events occur. + /// + /// See also: [android.os.MessageQueue.OnFileDescriptorEventListener](https://developer.android.com/reference/android/os/MessageQueue.OnFileDescriptorEventListener) + @available(Android 23, *) @JavaInterface("android.os.MessageQueue$OnFileDescriptorEventListener") public struct OnFileDescriptorEventListener { + /// Called when a file descriptor receives events. + /// + /// - Parameter arg0: The file descriptor. + /// - Parameter arg1: The set of events that occurred: a combination of `EVENT_INPUT`, `EVENT_OUTPUT`, and `EVENT_ERROR`. + /// - Returns: The new set of events to watch, or `0` to unregister the listener. @JavaMethod public func onFileDescriptorEvents(_ arg0: FileDescriptor?, _ arg1: Int32) -> Int32 } } extension JavaClass { + /// File descriptor event: indicates that the file descriptor is ready for input operations. @JavaStaticField(isFinal: true) public var EVENT_ERROR: Int32 + /// File descriptor event: indicates that an error occurred on the file descriptor. @JavaStaticField(isFinal: true) public var EVENT_INPUT: Int32 + /// File descriptor event: indicates that the file descriptor is ready for output operations. @JavaStaticField(isFinal: true) public var EVENT_OUTPUT: Int32 } diff --git a/Sources/AndroidOS/MessageQueue.swift b/Sources/AndroidOS/MessageQueue.swift index f6409183..6cb4588c 100644 --- a/Sources/AndroidOS/MessageQueue.swift +++ b/Sources/AndroidOS/MessageQueue.swift @@ -4,20 +4,50 @@ import JavaLangIO import SwiftJava import CSwiftJavaJNI +/// Low-level class holding the list of messages to be dispatched by a `Looper`. +/// Messages are not added directly to a `MessageQueue`, but rather through `Handler` objects +/// associated with the Looper. +/// +/// You can retrieve the `MessageQueue` for the current thread with `Looper.myQueue()`. +/// +/// See also: [android.os.MessageQueue](https://developer.android.com/reference/android/os/MessageQueue) @JavaClass("android.os.MessageQueue") open class MessageQueue: JavaObject { + /// Returns true if the looper has no pending messages which are due to be processed. + /// + /// This is a transient state; the looper may not remain idle for long. If the caller intends + /// to perform work based on this state it should use `addIdleHandler()` instead. @JavaMethod open func isIdle() -> Bool + /// Add a new `IdleHandler` to this message queue. This may be removed automatically for you by + /// returning false from `IdleHandler.queueIdle()` when it is invoked, or explicitly removing it + /// with `removeIdleHandler(MessageQueue.IdleHandler)`. + /// + /// This method is safe to call from any thread. @JavaMethod open func addIdleHandler(_ arg0: MessageQueue.IdleHandler?) + /// Remove an `IdleHandler` that was previously added with `addIdleHandler(MessageQueue.IdleHandler)`. + /// + /// This method is safe to call from any thread. @JavaMethod open func removeIdleHandler(_ arg0: MessageQueue.IdleHandler?) + /// Adds a file descriptor listener to receive notification when file descriptor + /// related events occur. + /// + /// - Parameter arg0: The file descriptor for which a listener is to be registered. + /// - Parameter arg1: A combination of the `EVENT_INPUT`, `EVENT_OUTPUT`, or `EVENT_ERROR` event masks. + /// - Parameter arg2: The listener to invoke when file descriptor events occur. + @available(Android 23, *) @JavaMethod open func addOnFileDescriptorEventListener(_ arg0: FileDescriptor?, _ arg1: Int32, _ arg2: MessageQueue.OnFileDescriptorEventListener?) + /// Removes a file descriptor listener. + /// + /// - Parameter arg0: The file descriptor whose listener will be unregistered. + @available(Android 23, *) @JavaMethod open func removeOnFileDescriptorEventListener(_ arg0: FileDescriptor?) diff --git a/Sources/AndroidOS/Messenger.swift b/Sources/AndroidOS/Messenger.swift index 89a72e38..5fc78618 100644 --- a/Sources/AndroidOS/Messenger.swift +++ b/Sources/AndroidOS/Messenger.swift @@ -2,6 +2,13 @@ import SwiftJava import CSwiftJavaJNI +/// Reference to a Handler, which others can use to send messages to it. +/// +/// This allows for the implementation of message-based communication across processes, by +/// creating a Messenger pointing to a Handler in one process, and handing that Messenger to +/// another process. +/// +/// See also: [android.os.Messenger](https://developer.android.com/reference/android/os/Messenger) @JavaClass("android.os.Messenger", implements: Parcelable.self) open class Messenger: JavaObject { @JavaMethod diff --git a/Sources/AndroidOS/NetworkOnMainThreadException.swift b/Sources/AndroidOS/NetworkOnMainThreadException.swift index 7092524d..524a896d 100644 --- a/Sources/AndroidOS/NetworkOnMainThreadException.swift +++ b/Sources/AndroidOS/NetworkOnMainThreadException.swift @@ -2,6 +2,11 @@ import SwiftJava import CSwiftJavaJNI +/// Thrown when an application attempts to perform a network operation on the main thread. +/// Network I/O must be performed on a background thread to avoid blocking the UI. +/// +/// See also: [android.os.NetworkOnMainThreadException](https://developer.android.com/reference/android/os/NetworkOnMainThreadException) +@available(Android 11, *) @JavaClass("android.os.NetworkOnMainThreadException") open class NetworkOnMainThreadException: RuntimeException { @JavaMethod diff --git a/Sources/AndroidOS/NetworkViolation.swift b/Sources/AndroidOS/NetworkViolation.swift index f80f4278..852d60f2 100644 --- a/Sources/AndroidOS/NetworkViolation.swift +++ b/Sources/AndroidOS/NetworkViolation.swift @@ -2,6 +2,10 @@ import SwiftJava import CSwiftJavaJNI +/// Violation raised when a network operation occurs on a thread that has forbidden network access. +/// +/// See also: [android.os.strictmode.NetworkViolation](https://developer.android.com/reference/android/os/strictmode/NetworkViolation) +@available(Android 28, *) @JavaClass("android.os.strictmode.NetworkViolation") open class NetworkViolation: Violation { diff --git a/Sources/AndroidOS/NonSdkApiUsedViolation.swift b/Sources/AndroidOS/NonSdkApiUsedViolation.swift index 03b4d197..f7cfaf18 100644 --- a/Sources/AndroidOS/NonSdkApiUsedViolation.swift +++ b/Sources/AndroidOS/NonSdkApiUsedViolation.swift @@ -2,6 +2,10 @@ import SwiftJava import CSwiftJavaJNI +/// Violation raised when a private, non-SDK API is accessed. +/// +/// See also: [android.os.strictmode.NonSdkApiUsedViolation](https://developer.android.com/reference/android/os/strictmode/NonSdkApiUsedViolation) +@available(Android 28, *) @JavaClass("android.os.strictmode.NonSdkApiUsedViolation") open class NonSdkApiUsedViolation: Violation { diff --git a/Sources/AndroidOS/OnObbStateChangeListener.swift b/Sources/AndroidOS/OnObbStateChangeListener.swift index b42eb844..33873158 100644 --- a/Sources/AndroidOS/OnObbStateChangeListener.swift +++ b/Sources/AndroidOS/OnObbStateChangeListener.swift @@ -2,11 +2,20 @@ import SwiftJava import CSwiftJavaJNI +/// Listener for receiving notifications when the mount state of an OBB file changes. +/// +/// See [android.os.storage.OnObbStateChangeListener](https://developer.android.com/reference/android/os/storage/OnObbStateChangeListener) +@available(Android 9, *) @JavaClass("android.os.storage.OnObbStateChangeListener") open class OnObbStateChangeListener: JavaObject { @JavaMethod @_nonoverride public convenience init(environment: JNIEnvironment? = nil) + /// Called when the mount state of an OBB has changed. + /// + /// - Parameters: + /// - arg0: The path of the OBB file whose state changed. + /// - arg1: The new state, one of the constants defined on this class (e.g., `MOUNTED`, `UNMOUNTED`, or an error code). @JavaMethod open func onObbStateChange(_ arg0: String, _ arg1: Int32) } diff --git a/Sources/AndroidOS/OperationCanceledException.swift b/Sources/AndroidOS/OperationCanceledException.swift index c36aba3e..d25731a4 100644 --- a/Sources/AndroidOS/OperationCanceledException.swift +++ b/Sources/AndroidOS/OperationCanceledException.swift @@ -2,6 +2,11 @@ import SwiftJava import CSwiftJavaJNI +/// Thrown when an operation in progress is canceled, typically via a `CancellationSignal`. +/// Callers should handle this exception to respond gracefully to user- or system-initiated cancellation. +/// +/// See also: [android.os.OperationCanceledException](https://developer.android.com/reference/android/os/OperationCanceledException) +@available(Android 16, *) @JavaClass("android.os.OperationCanceledException") open class OperationCanceledException: RuntimeException { @JavaMethod diff --git a/Sources/AndroidOS/OutcomeReceiver.swift b/Sources/AndroidOS/OutcomeReceiver.swift index 8f3b3996..e80eb43a 100644 --- a/Sources/AndroidOS/OutcomeReceiver.swift +++ b/Sources/AndroidOS/OutcomeReceiver.swift @@ -2,11 +2,20 @@ import SwiftJava import CSwiftJavaJNI +/// A callback interface for receiving the result of an asynchronous operation that can +/// either succeed with a result value or fail with an error. +/// +/// Implement `onResult(_:)` to handle success and `onError(_:)` to handle failure. +/// +/// See also: [android.os.OutcomeReceiver](https://developer.android.com/reference/android/os/OutcomeReceiver) +@available(Android 31, *) @JavaInterface("android.os.OutcomeReceiver") public struct OutcomeReceiver { + /// Called when the asynchronous operation completes successfully with the given result. @JavaMethod public func onResult(_ arg0: JavaObject?) + /// Called when the asynchronous operation fails with the given error. @JavaMethod public func onError(_ arg0: Throwable?) } diff --git a/Sources/AndroidOS/PackageHealthStats.swift b/Sources/AndroidOS/PackageHealthStats.swift index 4f420b51..17901161 100644 --- a/Sources/AndroidOS/PackageHealthStats.swift +++ b/Sources/AndroidOS/PackageHealthStats.swift @@ -2,6 +2,13 @@ import SwiftJava import CSwiftJavaJNI +/// Keys for health statistics about a Java package within a UID. +/// +/// Use these keys with `HealthStats` to retrieve per-package battery attribution data, +/// such as wakeup alarm counts and bound services. +/// +/// See also: [android.os.health.PackageHealthStats](https://developer.android.com/reference/android/os/health/PackageHealthStats) +@available(Android 24, *) @JavaClass("android.os.health.PackageHealthStats") open class PackageHealthStats: JavaObject { diff --git a/Sources/AndroidOS/Parcel.swift b/Sources/AndroidOS/Parcel.swift index ab6992e4..b19852af 100644 --- a/Sources/AndroidOS/Parcel.swift +++ b/Sources/AndroidOS/Parcel.swift @@ -7,6 +7,19 @@ import SwiftJava import JavaUtilFunction import CSwiftJavaJNI +/// Container for a message (data and object references) that can be sent through an IBinder. +/// A Parcel can contain both flattened data that will be unflattened on the other side of the +/// IPC (using the various methods here for writing specific types, or the general +/// `Parcelable` interface), and references to live `IBinder` objects that will result in the +/// other side receiving a proxy IBinder connected with the original IBinder in the Parcel. +/// +/// Parcel is **not** a general-purpose serialization mechanism. This class (and the corresponding +/// `Parcelable` API for placing arbitrary objects into a Parcel) is designed as a high-performance +/// IPC transport. As such, it is not appropriate to place any Parcel data in to persistent storage: +/// changes in the underlying implementation of any of the data in the Parcel can render older data +/// unreadable. +/// +/// See also: [android.os.Parcel](https://developer.android.com/reference/android/os/Parcel) @JavaClass("android.os.Parcel") open class Parcel: JavaObject { @JavaMethod @@ -415,12 +428,18 @@ open class Parcel: JavaObject { open func createByteArray() -> [Int8] } extension JavaClass { + /// A `Parcelable.Creator` that can be used to create `String` objects from a Parcel. @JavaStaticField(isFinal: true) public var STRING_CREATOR: Parcelable.Creator! + /// Retrieve a new Parcel object from the pool. @JavaStaticMethod public func obtain() -> Parcel! + /// Retrieve a new Parcel object from the pool, bound to a specific IBinder for IPC. + /// + /// - Parameter arg0: The IBinder to associate with this Parcel. + @available(Android 33, *) @JavaStaticMethod public func obtain(_ arg0: IBinder?) -> Parcel! } diff --git a/Sources/AndroidOS/ParcelFileDescriptor+AutoCloseInputStream.swift b/Sources/AndroidOS/ParcelFileDescriptor+AutoCloseInputStream.swift index be5e2ba5..7bf2b857 100644 --- a/Sources/AndroidOS/ParcelFileDescriptor+AutoCloseInputStream.swift +++ b/Sources/AndroidOS/ParcelFileDescriptor+AutoCloseInputStream.swift @@ -5,11 +5,16 @@ import SwiftJava import CSwiftJavaJNI extension ParcelFileDescriptor { + /// An `InputStream` that automatically closes its underlying `ParcelFileDescriptor` when the stream is closed. + /// + /// See [android.os.ParcelFileDescriptor.AutoCloseInputStream](https://developer.android.com/reference/android/os/ParcelFileDescriptor.AutoCloseInputStream) @JavaClass("android.os.ParcelFileDescriptor$AutoCloseInputStream") open class AutoCloseInputStream: FileInputStream { + /// Creates an `AutoCloseInputStream` reading from the given `ParcelFileDescriptor`. @JavaMethod @_nonoverride public convenience init(_ arg0: ParcelFileDescriptor?, environment: JNIEnvironment? = nil) + /// Closes this stream and the underlying `ParcelFileDescriptor`. @JavaMethod open override func close() throws diff --git a/Sources/AndroidOS/ParcelFileDescriptor+AutoCloseOutputStream.swift b/Sources/AndroidOS/ParcelFileDescriptor+AutoCloseOutputStream.swift index b7861c8b..bd93b0dd 100644 --- a/Sources/AndroidOS/ParcelFileDescriptor+AutoCloseOutputStream.swift +++ b/Sources/AndroidOS/ParcelFileDescriptor+AutoCloseOutputStream.swift @@ -5,11 +5,16 @@ import SwiftJava import CSwiftJavaJNI extension ParcelFileDescriptor { + /// An `OutputStream` that automatically closes its underlying `ParcelFileDescriptor` when the stream is closed. + /// + /// See [android.os.ParcelFileDescriptor.AutoCloseOutputStream](https://developer.android.com/reference/android/os/ParcelFileDescriptor.AutoCloseOutputStream) @JavaClass("android.os.ParcelFileDescriptor$AutoCloseOutputStream") open class AutoCloseOutputStream: FileOutputStream { + /// Creates an `AutoCloseOutputStream` writing to the given `ParcelFileDescriptor`. @JavaMethod @_nonoverride public convenience init(_ arg0: ParcelFileDescriptor?, environment: JNIEnvironment? = nil) + /// Closes this stream and the underlying `ParcelFileDescriptor`. @JavaMethod open override func close() throws } diff --git a/Sources/AndroidOS/ParcelFileDescriptor+FileDescriptorDetachedException.swift b/Sources/AndroidOS/ParcelFileDescriptor+FileDescriptorDetachedException.swift index 1651eaff..0174e76c 100644 --- a/Sources/AndroidOS/ParcelFileDescriptor+FileDescriptorDetachedException.swift +++ b/Sources/AndroidOS/ParcelFileDescriptor+FileDescriptorDetachedException.swift @@ -5,6 +5,10 @@ import SwiftJava import CSwiftJavaJNI extension ParcelFileDescriptor { + /// Exception thrown when a file descriptor has already been detached and cannot be used again. + /// + /// See [android.os.ParcelFileDescriptor.FileDescriptorDetachedException](https://developer.android.com/reference/android/os/ParcelFileDescriptor.FileDescriptorDetachedException) + @available(Android 12, *) @JavaClass("android.os.ParcelFileDescriptor$FileDescriptorDetachedException") open class FileDescriptorDetachedException: IOException { @JavaMethod diff --git a/Sources/AndroidOS/ParcelFileDescriptor+OnCloseListener.swift b/Sources/AndroidOS/ParcelFileDescriptor+OnCloseListener.swift index 35b01607..3b8134fd 100644 --- a/Sources/AndroidOS/ParcelFileDescriptor+OnCloseListener.swift +++ b/Sources/AndroidOS/ParcelFileDescriptor+OnCloseListener.swift @@ -5,8 +5,15 @@ import SwiftJava import CSwiftJavaJNI extension ParcelFileDescriptor { + /// Listener invoked when a `ParcelFileDescriptor` created with `wrap(_:_:_:)` is closed. + /// + /// See [android.os.ParcelFileDescriptor.OnCloseListener](https://developer.android.com/reference/android/os/ParcelFileDescriptor.OnCloseListener) + @available(Android 19, *) @JavaInterface("android.os.ParcelFileDescriptor$OnCloseListener") public struct OnCloseListener { + /// Called when the associated `ParcelFileDescriptor` is closed. + /// + /// - Parameter arg0: Any `IOException` that caused the close, or `nil` if the descriptor was closed normally. @JavaMethod public func onClose(_ arg0: IOException?) } diff --git a/Sources/AndroidOS/ParcelFileDescriptor.swift b/Sources/AndroidOS/ParcelFileDescriptor.swift index 6b23973f..acbc1d57 100644 --- a/Sources/AndroidOS/ParcelFileDescriptor.swift +++ b/Sources/AndroidOS/ParcelFileDescriptor.swift @@ -4,26 +4,42 @@ import JavaLangIO import SwiftJava import CSwiftJavaJNI +/// A file descriptor that can be passed between processes via Binder IPC. +/// +/// Wraps a Unix file descriptor and implements `Parcelable`, enabling it to be written to a +/// `Parcel` and sent to another process. The receiver obtains a duplicate file descriptor +/// referring to the same underlying open file description. +/// +/// See [android.os.ParcelFileDescriptor](https://developer.android.com/reference/android/os/ParcelFileDescriptor) @JavaClass("android.os.ParcelFileDescriptor", implements: Parcelable.self, Closeable.self) open class ParcelFileDescriptor: JavaObject { + /// Creates a new `ParcelFileDescriptor` that is a copy of the given descriptor. @JavaMethod @_nonoverride public convenience init(_ arg0: ParcelFileDescriptor?, environment: JNIEnvironment? = nil) + /// Returns the underlying `FileDescriptor`. @JavaMethod open func getFileDescriptor() -> FileDescriptor! + /// Returns the total size in bytes of the file backing this descriptor, or `-1` if unknown. @JavaMethod open func getStatSize() -> Int64 + /// Returns the raw native file descriptor integer. @JavaMethod open func getFd() -> Int32 + /// Detaches the native file descriptor from this object and returns it. + /// + /// After calling this, the caller is responsible for closing the file descriptor. @JavaMethod open func detachFd() -> Int32 + /// Closes this descriptor with an associated error message delivered to any `OnCloseListener`. @JavaMethod open func closeWithError(_ arg0: String) throws + /// Returns whether this descriptor can detect remote-side errors via `checkError()`. @JavaMethod open func canDetectErrors() -> Bool @@ -39,12 +55,15 @@ open class ParcelFileDescriptor: JavaObject { @JavaMethod open override func toString() -> String + /// Closes this `ParcelFileDescriptor` and its underlying file descriptor. @JavaMethod open func close() throws + /// Checks for and throws any error that occurred on the remote side of a pipe. @JavaMethod open func checkError() throws + /// Returns a new `ParcelFileDescriptor` that is a duplicate of this one. @JavaMethod open func dup() throws -> ParcelFileDescriptor! } @@ -82,36 +101,47 @@ extension JavaClass { @JavaStaticField(isFinal: true) public var PARCELABLE_WRITE_RETURN_VALUE: Int32 + /// Opens the given file with the specified mode flags and returns a `ParcelFileDescriptor`. @JavaStaticMethod public func fromFd(_ arg0: Int32) throws -> ParcelFileDescriptor! + /// Adopts the given raw file descriptor, taking ownership without duplicating it. @JavaStaticMethod public func adoptFd(_ arg0: Int32) -> ParcelFileDescriptor! + /// Creates a pair of `ParcelFileDescriptor`s connected by an anonymous pipe. @JavaStaticMethod public func createPipe() throws -> [ParcelFileDescriptor?] + /// Creates a reliable pipe pair that can propagate errors back to the write end. @JavaStaticMethod public func createReliablePipe() throws -> [ParcelFileDescriptor?] + /// Creates a pair of `ParcelFileDescriptor`s connected by a socket pair. @JavaStaticMethod public func createSocketPair() throws -> [ParcelFileDescriptor?] + /// Creates a reliable socket pair that can propagate errors back to the write end. @JavaStaticMethod public func createReliableSocketPair() throws -> [ParcelFileDescriptor?] + /// Parses a mode string such as `"r"`, `"w"`, or `"rw"` into the corresponding `MODE_*` flags. @JavaStaticMethod public func parseMode(_ arg0: String) -> Int32 + /// Wraps an existing `ParcelFileDescriptor`, routing close notifications to the given listener. @JavaStaticMethod public func wrap(_ arg0: ParcelFileDescriptor?, _ arg1: Handler?, _ arg2: ParcelFileDescriptor.OnCloseListener?) throws -> ParcelFileDescriptor! + /// Opens the given file with the specified mode flags, routing close notifications to the listener. @JavaStaticMethod public func open(_ arg0: File?, _ arg1: Int32, _ arg2: Handler?, _ arg3: ParcelFileDescriptor.OnCloseListener?) throws -> ParcelFileDescriptor! + /// Opens the given file with the specified mode flags. @JavaStaticMethod public func open(_ arg0: File?, _ arg1: Int32) throws -> ParcelFileDescriptor! + /// Duplicates the given `FileDescriptor` into a new `ParcelFileDescriptor`. @JavaStaticMethod public func dup(_ arg0: FileDescriptor?) throws -> ParcelFileDescriptor! } diff --git a/Sources/AndroidOS/ParcelFormatException.swift b/Sources/AndroidOS/ParcelFormatException.swift index f9579927..bd52daed 100644 --- a/Sources/AndroidOS/ParcelFormatException.swift +++ b/Sources/AndroidOS/ParcelFormatException.swift @@ -2,6 +2,10 @@ import SwiftJava import CSwiftJavaJNI +/// Thrown when a `Parcel` contains data in an unexpected or invalid format that cannot +/// be correctly deserialized. +/// +/// See also: [android.os.ParcelFormatException](https://developer.android.com/reference/android/os/ParcelFormatException) @JavaClass("android.os.ParcelFormatException") open class ParcelFormatException: RuntimeException { @JavaMethod diff --git a/Sources/AndroidOS/Parcelable+ClassLoaderCreator.swift b/Sources/AndroidOS/Parcelable+ClassLoaderCreator.swift index f7a7c958..e27e8e5d 100644 --- a/Sources/AndroidOS/Parcelable+ClassLoaderCreator.swift +++ b/Sources/AndroidOS/Parcelable+ClassLoaderCreator.swift @@ -3,8 +3,19 @@ import SwiftJava import CSwiftJavaJNI extension Parcelable { + /// Specialization of `Parcelable.Creator` that allows you to receive the ClassLoader the + /// object is being created in. + /// + /// See also: [android.os.Parcelable.ClassLoaderCreator](https://developer.android.com/reference/android/os/Parcelable.ClassLoaderCreator) + @available(Android 13, *) @JavaInterface("android.os.Parcelable$ClassLoaderCreator", extends: Parcelable.Creator.self) public struct ClassLoaderCreator { + /// Create a new instance of the Parcelable class, instantiating it from the given Parcel + /// whose data had previously been written by `Parcelable.writeToParcel()`. + /// + /// - Parameter arg0: The Parcel to read the object's data from. + /// - Parameter arg1: The ClassLoader that this object is being created in. + /// - Returns: A new instance of the Parcelable class. @JavaMethod public func createFromParcel(_ arg0: Parcel?, _ arg1: JavaClassLoader?) -> JavaObject! diff --git a/Sources/AndroidOS/Parcelable+Creator.swift b/Sources/AndroidOS/Parcelable+Creator.swift index bbdf6e65..d0d54763 100644 --- a/Sources/AndroidOS/Parcelable+Creator.swift +++ b/Sources/AndroidOS/Parcelable+Creator.swift @@ -3,11 +3,24 @@ import SwiftJava import CSwiftJavaJNI extension Parcelable { + /// Interface that must be implemented and provided as a public `CREATOR` field that generates + /// instances of your Parcelable class from a Parcel. + /// + /// See also: [android.os.Parcelable.Creator](https://developer.android.com/reference/android/os/Parcelable.Creator) @JavaInterface("android.os.Parcelable$Creator") public struct Creator { + /// Create a new instance of the Parcelable class, instantiating it from the given Parcel + /// whose data had previously been written by `Parcelable.writeToParcel()`. + /// + /// - Parameter arg0: The Parcel to read the object's data from. + /// - Returns: A new instance of the Parcelable class. @JavaMethod public func createFromParcel(_ arg0: Parcel?) -> JavaObject! + /// Create a new array of the Parcelable class. + /// + /// - Parameter arg0: The size of the array. + /// - Returns: An array of the Parcelable class, with every entry initialized to nil. @JavaMethod public func newArray(_ arg0: Int32) -> [JavaObject?] } diff --git a/Sources/AndroidOS/Parcelable.swift b/Sources/AndroidOS/Parcelable.swift index 599a839f..b9093986 100644 --- a/Sources/AndroidOS/Parcelable.swift +++ b/Sources/AndroidOS/Parcelable.swift @@ -2,18 +2,65 @@ import SwiftJava import CSwiftJavaJNI +/// Interface for classes whose instances can be written to and restored from a `Parcel`. +/// Classes implementing the Parcelable interface must also have a non-nil static field called +/// `CREATOR` of a type that implements the `Parcelable.Creator` interface. +/// +/// A typical implementation of Parcelable is: +/// ```java +/// public class MyParcelable implements Parcelable { +/// private int mData; +/// +/// public int describeContents() { +/// return 0; +/// } +/// +/// public void writeToParcel(Parcel out, int flags) { +/// out.writeInt(mData); +/// } +/// +/// public static final Parcelable.Creator CREATOR +/// = new Parcelable.Creator() { +/// public MyParcelable createFromParcel(Parcel in) { +/// return new MyParcelable(in); +/// } +/// +/// public MyParcelable[] newArray(int size) { +/// return new MyParcelable[size]; +/// } +/// }; +/// } +/// ``` +/// +/// See also: [android.os.Parcelable](https://developer.android.com/reference/android/os/Parcelable) @JavaInterface("android.os.Parcelable") public struct Parcelable { + /// Describe the kinds of special objects contained in this Parcelable instance's marshaled + /// representation. For example, if the object will include a file descriptor in the output of + /// `writeToParcel(Parcel, int)`, the return value of this method must include the + /// `CONTENTS_FILE_DESCRIPTOR` bit. + /// + /// - Returns: A bitmask indicating the set of special object types marshaled by this Parcelable object instance. @JavaMethod public func describeContents() -> Int32 + /// Flatten this object in to a Parcel. + /// + /// - Parameter arg0: The Parcel in which the object should be written. + /// - Parameter arg1: Additional flags about how the object should be written. May be 0 or + /// `PARCELABLE_WRITE_RETURN_VALUE`. @JavaMethod public func writeToParcel(_ arg0: Parcel?, _ arg1: Int32) } extension JavaClass { + /// Descriptor bit used with `describeContents()`: the Parcelable object's flattened + /// representation includes a file descriptor. @JavaStaticField(isFinal: true) public var CONTENTS_FILE_DESCRIPTOR: Int32 + /// Flag for use with `writeToParcel(Parcel, int)`: the object being written is a return value, + /// that is the result of a function such as `writeToParcel`. The implementation of + /// Parcelable may release resources once they know their data has been sent away. @JavaStaticField(isFinal: true) public var PARCELABLE_WRITE_RETURN_VALUE: Int32 } diff --git a/Sources/AndroidOS/PatternMatcher.swift b/Sources/AndroidOS/PatternMatcher.swift index c816e982..7d947244 100644 --- a/Sources/AndroidOS/PatternMatcher.swift +++ b/Sources/AndroidOS/PatternMatcher.swift @@ -2,6 +2,12 @@ import SwiftJava import CSwiftJavaJNI +/// A simple pattern matcher that supports literal string matching, prefix matching, +/// simple glob patterns, advanced glob patterns, and suffix matching against strings. +/// +/// Use the `PATTERN_*` constants to select the matching strategy when constructing an instance. +/// +/// See also: [android.os.PatternMatcher](https://developer.android.com/reference/android/os/PatternMatcher) @JavaClass("android.os.PatternMatcher", implements: Parcelable.self) open class PatternMatcher: JavaObject { @JavaMethod @@ -19,12 +25,15 @@ open class PatternMatcher: JavaObject { @JavaMethod open override func toString() -> String + /// Returns `true` if the given string matches this pattern. @JavaMethod open func match(_ arg0: String) -> Bool + /// Returns the pattern type constant (one of the `PATTERN_*` values). @JavaMethod open func getType() -> Int32 + /// Returns the pattern string used for matching. @JavaMethod open func getPath() -> String } diff --git a/Sources/AndroidOS/PerformanceHintManager+Session.swift b/Sources/AndroidOS/PerformanceHintManager+Session.swift index 9b9c72cb..c806273b 100644 --- a/Sources/AndroidOS/PerformanceHintManager+Session.swift +++ b/Sources/AndroidOS/PerformanceHintManager+Session.swift @@ -5,6 +5,13 @@ import SwiftJava import CSwiftJavaJNI extension PerformanceHintManager { + /// A hint session for a set of threads, used to report work durations to the system. + /// + /// Call `updateTargetWorkDuration(_:)` to inform the system of your target frame time, + /// and `reportActualWorkDuration(_:)` after each frame to allow the CPU governor to adapt. + /// + /// See also: [android.os.PerformanceHintManager.Session](https://developer.android.com/reference/android/os/PerformanceHintManager.Session) + @available(Android 31, *) @JavaClass("android.os.PerformanceHintManager$Session", implements: Closeable.self) open class Session: JavaObject { @JavaMethod diff --git a/Sources/AndroidOS/PerformanceHintManager.swift b/Sources/AndroidOS/PerformanceHintManager.swift index a877494c..f8b8a043 100644 --- a/Sources/AndroidOS/PerformanceHintManager.swift +++ b/Sources/AndroidOS/PerformanceHintManager.swift @@ -2,6 +2,15 @@ import SwiftJava import CSwiftJavaJNI +/// Lets apps communicate performance requirements to the Android system. +/// +/// Use `createHintSession(_:_:)` to create a `Session` for a set of threads, +/// then report actual work durations to allow the system to scale CPU frequency accordingly. +/// +/// Obtain an instance via `Context.getSystemService(PerformanceHintManager.class)`. +/// +/// See also: [android.os.PerformanceHintManager](https://developer.android.com/reference/android/os/PerformanceHintManager) +@available(Android 31, *) @JavaClass("android.os.PerformanceHintManager") open class PerformanceHintManager: JavaObject { @JavaMethod diff --git a/Sources/AndroidOS/PersistableBundle.swift b/Sources/AndroidOS/PersistableBundle.swift index 0e94027a..15345516 100644 --- a/Sources/AndroidOS/PersistableBundle.swift +++ b/Sources/AndroidOS/PersistableBundle.swift @@ -4,23 +4,40 @@ import JavaLang import SwiftJava import CSwiftJavaJNI +/// A mapping from String keys to values of various types. The set of types supported by this +/// class is purposefully restricted to simple objects that can safely be persisted to and +/// restored from disk. +/// +/// Unlike `Bundle`, values stored in a `PersistableBundle` can be saved to persistent storage, +/// such as an `Activity`'s saved instance state. +/// +/// See also: [android.os.PersistableBundle](https://developer.android.com/reference/android/os/PersistableBundle) +@available(Android 21, *) @JavaClass("android.os.PersistableBundle", implements: Cloneable.self, Parcelable.self) open class PersistableBundle: BaseBundle { + /// Constructs a new, empty PersistableBundle that is optimized for a given number of key/value pairs. @JavaMethod @_nonoverride public convenience init(_ arg0: Int32, environment: JNIEnvironment? = nil) + /// Constructs a PersistableBundle containing a copy of the mappings from the given PersistableBundle. @JavaMethod @_nonoverride public convenience init(_ arg0: PersistableBundle?, environment: JNIEnvironment? = nil) + /// Constructs a new, empty PersistableBundle. @JavaMethod @_nonoverride public convenience init(environment: JNIEnvironment? = nil) + /// Inserts a PersistableBundle value into the mapping. @JavaMethod open func putPersistableBundle(_ arg0: String, _ arg1: PersistableBundle?) + /// Writes the PersistableBundle contents to a stream, typically in order for it to be saved + /// to persistent storage. @JavaMethod open func writeToStream(_ arg0: OutputStream?) throws + /// Returns the value associated with the given key, or nil if no mapping of the desired type + /// exists for the given key. @JavaMethod open func getPersistableBundle(_ arg0: String) -> PersistableBundle! @@ -30,6 +47,8 @@ open class PersistableBundle: BaseBundle { @JavaMethod open func writeToParcel(_ arg0: Parcel?, _ arg1: Int32) + /// Makes a deep copy of the given PersistableBundle. + @available(Android 26, *) @JavaMethod open func deepCopy() -> PersistableBundle! @@ -43,6 +62,7 @@ extension JavaClass { @JavaStaticField(isFinal: true) public var CREATOR: Parcelable.Creator! + /// An unmodifiable PersistableBundle that is always empty. @JavaStaticField(isFinal: true) public var EMPTY: PersistableBundle! @@ -52,6 +72,8 @@ extension JavaClass { @JavaStaticField(isFinal: true) public var PARCELABLE_WRITE_RETURN_VALUE: Int32 + /// Reads a PersistableBundle from a stream that was previously written by + /// `writeToStream(OutputStream)`. @JavaStaticMethod public func readFromStream(_ arg0: InputStream?) throws -> PersistableBundle! } diff --git a/Sources/AndroidOS/PidHealthStats.swift b/Sources/AndroidOS/PidHealthStats.swift index 032b282a..d37ade58 100644 --- a/Sources/AndroidOS/PidHealthStats.swift +++ b/Sources/AndroidOS/PidHealthStats.swift @@ -2,6 +2,13 @@ import SwiftJava import CSwiftJavaJNI +/// Keys for health statistics about a process ID (PID) within a UID. +/// +/// Use these keys with `HealthStats` to retrieve per-PID battery attribution data, +/// such as wake lock nesting counts and wake durations. +/// +/// See also: [android.os.health.PidHealthStats](https://developer.android.com/reference/android/os/health/PidHealthStats) +@available(Android 24, *) @JavaClass("android.os.health.PidHealthStats") open class PidHealthStats: JavaObject { diff --git a/Sources/AndroidOS/PowerManager+OnThermalStatusChangedListener.swift b/Sources/AndroidOS/PowerManager+OnThermalStatusChangedListener.swift index 5380600c..27ec4680 100644 --- a/Sources/AndroidOS/PowerManager+OnThermalStatusChangedListener.swift +++ b/Sources/AndroidOS/PowerManager+OnThermalStatusChangedListener.swift @@ -3,8 +3,16 @@ import SwiftJava import CSwiftJavaJNI extension PowerManager { + /// Listener passed to `addThermalStatusListener(PowerManager.OnThermalStatusChangedListener)` + /// to be notified of thermal status changes. + /// + /// See also: [android.os.PowerManager.OnThermalStatusChangedListener](https://developer.android.com/reference/android/os/PowerManager.OnThermalStatusChangedListener) + @available(Android 29, *) @JavaInterface("android.os.PowerManager$OnThermalStatusChangedListener") public struct OnThermalStatusChangedListener { + /// Called when the thermal status changes. + /// + /// - Parameter arg0: The new thermal status, one of the `THERMAL_STATUS_*` constants. @JavaMethod public func onThermalStatusChanged(_ arg0: Int32) } diff --git a/Sources/AndroidOS/PowerManager+WakeLock.swift b/Sources/AndroidOS/PowerManager+WakeLock.swift index b52467f7..5503f7f0 100644 --- a/Sources/AndroidOS/PowerManager+WakeLock.swift +++ b/Sources/AndroidOS/PowerManager+WakeLock.swift @@ -3,14 +3,31 @@ import SwiftJava import CSwiftJavaJNI extension PowerManager { + /// A wake lock is a mechanism to indicate that your application needs to have the device stay on. + /// + /// Any application using a WakeLock must request the `android.permission.WAKE_LOCK` permission + /// in an `` element of the application's manifest. + /// + /// Call `release()` when you are done and don't need the lock anymore. It is very important to + /// do this as soon as possible to avoid running down the user's battery excessively. + /// + /// See also: [android.os.PowerManager.WakeLock](https://developer.android.com/reference/android/os/PowerManager.WakeLock) @JavaClass("android.os.PowerManager$WakeLock") open class WakeLock: JavaObject { + /// Returns true if the wake lock is currently held. @JavaMethod open func isHeld() -> Bool + /// Sets whether this WakeLock is reference counted. + /// + /// Wake locks are reference counted by default. If a wake lock is reference counted, then + /// each call to `acquire()` must be balanced by an equal number of calls to `release()`. + /// If a wake lock is not reference counted, then one call to `release()` is sufficient to + /// undo the effect of all previous calls to `acquire()`. @JavaMethod open func setReferenceCounted(_ arg0: Bool) + /// Sets the work source associated with the wake lock. @JavaMethod open func setWorkSource(_ arg0: WorkSource?) @@ -20,15 +37,25 @@ extension PowerManager { @JavaMethod open override func toString() -> String + /// Releases the wake lock. The CPU is allowed to sleep as soon as all wake locks have been released. @JavaMethod open func release() + /// Releases the wake lock with optional flags. + /// + /// - Parameter arg0: Combination of flag values to modify the release behavior. @JavaMethod open func release(_ arg0: Int32) + /// Acquires the wake lock. Ensures the device is on at the level requested when the wake lock + /// was created. @JavaMethod open func acquire() + /// Acquires the wake lock with a timeout. The lock will be released automatically after + /// the timeout. + /// + /// - Parameter arg0: The number of milliseconds to hold the wake lock before automatically releasing. @JavaMethod open func acquire(_ arg0: Int64) } diff --git a/Sources/AndroidOS/PowerManager+WakeLockStateListener.swift b/Sources/AndroidOS/PowerManager+WakeLockStateListener.swift index c54af887..c9b7fd85 100644 --- a/Sources/AndroidOS/PowerManager+WakeLockStateListener.swift +++ b/Sources/AndroidOS/PowerManager+WakeLockStateListener.swift @@ -3,8 +3,16 @@ import SwiftJava import CSwiftJavaJNI extension PowerManager { + /// Listener passed to observe changes in the state of a `WakeLock`. + /// + /// See also: [android.os.PowerManager.WakeLockStateListener](https://developer.android.com/reference/android/os/PowerManager.WakeLockStateListener) + @available(Android 31, *) @JavaInterface("android.os.PowerManager$WakeLockStateListener") public struct WakeLockStateListener { + /// Called when the state of the wake lock changes. + /// + /// - Parameter arg0: `true` if the wake lock has been acquired (is held), + /// `false` if it has been released. @JavaMethod public func onStateChanged(_ arg0: Bool) } diff --git a/Sources/AndroidOS/PowerManager.swift b/Sources/AndroidOS/PowerManager.swift index bd6d22bb..a14e2867 100644 --- a/Sources/AndroidOS/PowerManager.swift +++ b/Sources/AndroidOS/PowerManager.swift @@ -3,135 +3,254 @@ import JavaTime import SwiftJava import CSwiftJavaJNI +/// This class lets you query and request control of aspects of the device's power state. +/// +/// **Power save mode and low power mode** +/// +/// Devices can enter a low-power mode to conserve battery. When in this mode, the device may +/// limit or disable features such as sync, Wi-Fi, and other services. Use `isPowerSaveMode()` +/// to check. +/// +/// **Wake locks** +/// +/// Wake locks are mechanisms by which applications can request that the CPU continue running +/// even when the screen goes dark. Use `newWakeLock(int, String)` to create a wake lock and +/// the `WakeLock` class to manage it. +/// +/// > **Warning**: Wake locks held for too long reduce battery life significantly. Use them sparingly. +/// +/// See also: [android.os.PowerManager](https://developer.android.com/reference/android/os/PowerManager) @JavaClass("android.os.PowerManager") open class PowerManager: JavaObject { + /// Creates a new wake lock with the specified level and tag. + /// + /// - Parameter arg0: Combination of wake lock level and optional flags. + /// - Parameter arg1: Your class name (or other tag) for debugging purposes. + /// - Returns: A new `WakeLock` object. @JavaMethod open func newWakeLock(_ arg0: Int32, _ arg1: String) -> PowerManager.WakeLock! + /// Returns true if the device supports the given wake lock level. + @available(Android 21, *) @JavaMethod open func isWakeLockLevelSupported(_ arg0: Int32) -> Bool + /// Returns true if the screen is currently on. + /// + /// - Note: Deprecated since API 20. Use `isInteractive()` instead. @JavaMethod open func isScreenOn() -> Bool + /// Returns true if the device is in an interactive state (screen on or similar). + @available(Android 20, *) @JavaMethod open func isInteractive() -> Bool + /// Returns true if the device supports rebooting userspace. + @available(Android 30, *) @JavaMethod open func isRebootingUserspaceSupported() -> Bool + /// Reboot the device. Requires the `REBOOT` permission. + /// + /// - Parameter arg0: The reason for the reboot, or nil. @JavaMethod open func reboot(_ arg0: String) + /// Returns true if the device is currently in power save mode. + @available(Android 21, *) @JavaMethod open func isPowerSaveMode() -> Bool + /// Returns the estimated remaining time until the battery is fully discharged. + /// + /// - Returns: A `Duration` representing the remaining battery life, or `nil` if unavailable. + @available(Android 31, *) @JavaMethod open func getBatteryDischargePrediction() -> Duration! + /// Returns true if the current battery discharge prediction is personalized based on usage history. + @available(Android 31, *) @JavaMethod open func isBatteryDischargePredictionPersonalized() -> Bool + /// Returns how location features should behave when battery saver is on. + /// + /// - Returns: One of the `LOCATION_MODE_*` constants. + @available(Android 28, *) @JavaMethod open func getLocationPowerSaveMode() -> Int32 + /// Returns true if the device is currently in idle (Doze) mode. + @available(Android 23, *) @JavaMethod open func isDeviceIdleMode() -> Bool + /// Returns true if the device is currently in light idle mode. + @available(Android 33, *) @JavaMethod open func isDeviceLightIdleMode() -> Bool + /// Returns true if Low Power Standby is enabled. + @available(Android 33, *) @JavaMethod open func isLowPowerStandbyEnabled() -> Bool + /// Returns true if the given application package name is on the device's power allowlist + /// (i.e., ignoring battery optimizations). + @available(Android 23, *) @JavaMethod open func isIgnoringBatteryOptimizations(_ arg0: String) -> Bool + /// Returns true if the device supports Sustained Performance Mode. + @available(Android 24, *) @JavaMethod open func isSustainedPerformanceModeSupported() -> Bool + /// Returns the current thermal status of the device. + /// + /// - Returns: One of the `THERMAL_STATUS_*` constants. + @available(Android 29, *) @JavaMethod open func getCurrentThermalStatus() -> Int32 + /// Adds a listener for thermal status change notifications. + @available(Android 29, *) @JavaMethod open func addThermalStatusListener(_ arg0: PowerManager.OnThermalStatusChangedListener?) + /// Removes a previously added thermal status listener. + @available(Android 29, *) @JavaMethod open func removeThermalStatusListener(_ arg0: PowerManager.OnThermalStatusChangedListener?) + /// Provides an estimate of how much thermal headroom remains before throttling. + /// + /// - Parameter arg0: How many seconds in the future to forecast (0–10 seconds). + /// - Returns: A value between 0.0 (no throttling) and 1.0 (at critical threshold). + @available(Android 31, *) @JavaMethod open func getThermalHeadroom(_ arg0: Int32) -> Float } extension JavaClass { + /// Flag for `newWakeLock(int, String)`: turn the screen on when the wake lock is acquired. @JavaStaticField(isFinal: true) public var ACQUIRE_CAUSES_WAKEUP: Int32 + /// Broadcast Action: Sent when the device wakes up from idle (Doze) mode. + @available(Android 23, *) @JavaStaticField(isFinal: true) public var ACTION_DEVICE_IDLE_MODE_CHANGED: String + /// Broadcast Action: Sent when the device enters or exits light idle mode. + @available(Android 33, *) @JavaStaticField(isFinal: true) public var ACTION_DEVICE_LIGHT_IDLE_MODE_CHANGED: String + /// Broadcast Action: Sent when the Low Power Standby policy changes. + @available(Android 33, *) @JavaStaticField(isFinal: true) public var ACTION_LOW_POWER_STANDBY_ENABLED_CHANGED: String + /// Broadcast Action: Sent when the device's power save mode changes. + @available(Android 21, *) @JavaStaticField(isFinal: true) public var ACTION_POWER_SAVE_MODE_CHANGED: String + /// Wake lock level: Ensures that the screen and keyboard backlight are on at full brightness. + /// + /// - Note: Deprecated since API 17. @JavaStaticField(isFinal: true) public var FULL_WAKE_LOCK: Int32 + /// Constant for `getLocationPowerSaveMode()`: all location providers disabled while in power save mode. + @available(Android 28, *) @JavaStaticField(isFinal: true) public var LOCATION_MODE_ALL_DISABLED_WHEN_SCREEN_OFF: Int32 + /// Constant for `getLocationPowerSaveMode()`: only the foreground app may use location. + @available(Android 28, *) @JavaStaticField(isFinal: true) public var LOCATION_MODE_FOREGROUND_ONLY: Int32 + /// Constant for `getLocationPowerSaveMode()`: GPS-based location disabled while in power save mode. + @available(Android 28, *) @JavaStaticField(isFinal: true) public var LOCATION_MODE_GPS_DISABLED_WHEN_SCREEN_OFF: Int32 + /// Constant for `getLocationPowerSaveMode()`: location mode is unchanged when power saving is on. + @available(Android 28, *) @JavaStaticField(isFinal: true) public var LOCATION_MODE_NO_CHANGE: Int32 + /// Constant for `getLocationPowerSaveMode()`: location may be throttled while in power save mode. + @available(Android 28, *) @JavaStaticField(isFinal: true) public var LOCATION_MODE_THROTTLE_REQUESTS_WHEN_SCREEN_OFF: Int32 + /// Flag for `WakeLock.release()`: keep the screen on briefly after releasing the wake lock. @JavaStaticField(isFinal: true) public var ON_AFTER_RELEASE: Int32 + /// Wake lock level: Ensures that the CPU is running while allowing the screen and keyboard + /// backlight to go off. @JavaStaticField(isFinal: true) public var PARTIAL_WAKE_LOCK: Int32 + /// Wake lock level: Turns the screen off when the device is held face-down (uses proximity sensor). @JavaStaticField(isFinal: true) public var PROXIMITY_SCREEN_OFF_WAKE_LOCK: Int32 + /// Flag for `WakeLock.release(int)`: Defer releasing until the proximity sensor reports the + /// user is not holding the device close to their face. + @available(Android 21, *) @JavaStaticField(isFinal: true) public var RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY: Int32 + /// Wake lock level: Ensures that the screen is on at full brightness; keyboard backlight may go off. + /// + /// - Note: Deprecated since API 15. @JavaStaticField(isFinal: true) public var SCREEN_BRIGHT_WAKE_LOCK: Int32 + /// Wake lock level: Ensures that the screen is on (but may be dimmed); keyboard backlight may go off. + /// + /// - Note: Deprecated since API 17. @JavaStaticField(isFinal: true) public var SCREEN_DIM_WAKE_LOCK: Int32 + /// Thermal status: the device is close to a critical thermal threshold. + @available(Android 29, *) @JavaStaticField(isFinal: true) public var THERMAL_STATUS_CRITICAL: Int32 + /// Thermal status: the device is close to an emergency thermal threshold. + @available(Android 29, *) @JavaStaticField(isFinal: true) public var THERMAL_STATUS_EMERGENCY: Int32 + /// Thermal status: light thermal throttling is occurring. + @available(Android 29, *) @JavaStaticField(isFinal: true) public var THERMAL_STATUS_LIGHT: Int32 + /// Thermal status: moderate thermal throttling is occurring. + @available(Android 29, *) @JavaStaticField(isFinal: true) public var THERMAL_STATUS_MODERATE: Int32 + /// Thermal status: no throttling. + @available(Android 29, *) @JavaStaticField(isFinal: true) public var THERMAL_STATUS_NONE: Int32 + /// Thermal status: severe thermal throttling is occurring. + @available(Android 29, *) @JavaStaticField(isFinal: true) public var THERMAL_STATUS_SEVERE: Int32 + /// Thermal status: the device needs to shut down immediately due to thermal conditions. + @available(Android 29, *) @JavaStaticField(isFinal: true) public var THERMAL_STATUS_SHUTDOWN: Int32 } diff --git a/Sources/AndroidOS/Process.swift b/Sources/AndroidOS/Process.swift index 450c3738..c1c3b9d6 100644 --- a/Sources/AndroidOS/Process.swift +++ b/Sources/AndroidOS/Process.swift @@ -2,147 +2,226 @@ import SwiftJava import CSwiftJavaJNI +/// Tools for managing OS processes. +/// +/// See also: [android.os.Process](https://developer.android.com/reference/android/os/Process) @JavaClass("android.os.Process") open class Process: JavaObject { @JavaMethod @_nonoverride public convenience init(environment: JNIEnvironment? = nil) } extension JavaClass { + /// Defines the UID/GID under which Bluetooth code runs. @JavaStaticField(isFinal: true) public var BLUETOOTH_UID: Int32 + /// Defines the start of a range of UIDs (and GIDs), going from this number to + /// `LAST_APPLICATION_UID` that are reserved for assigning to applications. @JavaStaticField(isFinal: true) public var FIRST_APPLICATION_UID: Int32 + /// An invalid UID value. @JavaStaticField(isFinal: true) public var INVALID_UID: Int32 + /// Last of application-specific UIDs starting at `FIRST_APPLICATION_UID`. @JavaStaticField(isFinal: true) public var LAST_APPLICATION_UID: Int32 + /// Defines the UID/GID for the Phone application. @JavaStaticField(isFinal: true) public var PHONE_UID: Int32 + /// Defines the UID/GID under which the root code runs. @JavaStaticField(isFinal: true) public var ROOT_UID: Int32 + /// Defines the UID/GID under which the shell code runs. @JavaStaticField(isFinal: true) public var SHELL_UID: Int32 + /// Standard Linux SIGKILL signal. @JavaStaticField(isFinal: true) public var SIGNAL_KILL: Int32 + /// Standard Linux SIGQUIT signal. @JavaStaticField(isFinal: true) public var SIGNAL_QUIT: Int32 + /// Standard Linux SIGUSR1 signal. @JavaStaticField(isFinal: true) public var SIGNAL_USR1: Int32 + /// Defines the UID/GID under which system code runs. @JavaStaticField(isFinal: true) public var SYSTEM_UID: Int32 + /// Priority we give to the main thread of an audio app. This is the minimum amount + /// of fatigue to make audio work properly. @JavaStaticField(isFinal: true) public var THREAD_PRIORITY_AUDIO: Int32 + /// Standard priority background threads, is set to the lowest priority. @JavaStaticField(isFinal: true) public var THREAD_PRIORITY_BACKGROUND: Int32 + /// Standard priority of application threads. Use with `setThreadPriority(int)` and + /// `setThreadPriority(int, int)`. @JavaStaticField(isFinal: true) public var THREAD_PRIORITY_DEFAULT: Int32 + /// Standard priority of threads that are currently running a user interface that the user + /// is interacting with. Applications can not normally change to this priority. @JavaStaticField(isFinal: true) public var THREAD_PRIORITY_DISPLAY: Int32 + /// Standard priority of threads that are currently running a user interface. Applications + /// can not normally change to this priority. @JavaStaticField(isFinal: true) public var THREAD_PRIORITY_FOREGROUND: Int32 + /// Adjustment used to move threads slightly more favorable than its parent process's priority. @JavaStaticField(isFinal: true) public var THREAD_PRIORITY_LESS_FAVORABLE: Int32 + /// Minimum increment to make a priority less favorable. @JavaStaticField(isFinal: true) public var THREAD_PRIORITY_LOWEST: Int32 + /// Adjustment used to move threads slightly more favorable than its parent process's priority. @JavaStaticField(isFinal: true) public var THREAD_PRIORITY_MORE_FAVORABLE: Int32 + /// Standard priority of the most important audio threads. @JavaStaticField(isFinal: true) public var THREAD_PRIORITY_URGENT_AUDIO: Int32 + /// Standard priority of threads that are currently running a user interface that the user + /// is interacting with. Applications can not normally change to this priority. @JavaStaticField(isFinal: true) public var THREAD_PRIORITY_URGENT_DISPLAY: Int32 + /// Standard priority of video threads. Applications can not normally change to this priority. @JavaStaticField(isFinal: true) public var THREAD_PRIORITY_VIDEO: Int32 + /// Defines the UID/GID for the WiFi supplicant process. @JavaStaticField(isFinal: true) public var WIFI_UID: Int32 + /// Returns elapsed milliseconds of the time this process has run. + /// + /// - Returns: Returns the number of milliseconds this process has return. @JavaStaticMethod public func getElapsedCpuTime() -> Int64 + /// Returns the time, in milliseconds, since the start of the process, measured using the + /// elapsed realtime clock. + @available(Android 24, *) @JavaStaticMethod public func getStartElapsedRealtime() -> Int64 + /// Returns the time, in milliseconds, since the start of the process, measured using the + /// uptime clock. + @available(Android 24, *) @JavaStaticMethod public func getStartUptimeMillis() -> Int64 + /// Returns the time spent in the system call (in milliseconds), since the process was started. + @available(Android 33, *) @JavaStaticMethod public func getStartRequestedElapsedRealtime() -> Int64 + /// Returns true if the current process is a 64-bit runtime. + @available(Android 23, *) @JavaStaticMethod public func is64Bit() -> Bool + /// Returns the time, in milliseconds, that the process was requested to start. + @available(Android 33, *) @JavaStaticMethod public func getStartRequestedUptimeMillis() -> Int64 + /// Returns the identifier of this process, which can be used with `killProcess(int)` and + /// `sendSignal(int, int)`. @JavaStaticMethod public func myPid() -> Int32 + /// Returns the identifier of the calling thread, which be used with `setThreadPriority(int, int)`. @JavaStaticMethod public func myTid() -> Int32 + /// Returns the identifier of this process's uid. This is the kernel uid that the process is + /// running under, which is the identity of its app-specific sandbox. @JavaStaticMethod public func myUid() -> Int32 + /// Returns this process's user handle. This is the user the process is running under. + @available(Android 17, *) @JavaStaticMethod public func myUserHandle() -> UserHandle! + /// Returns whether the given uid belongs to an application. + @available(Android 24, *) @JavaStaticMethod public func isApplicationUid(_ arg0: Int32) -> Bool + /// Returns whether the current process is in an isolated sandbox. + @available(Android 16, *) @JavaStaticMethod public func isIsolated() -> Bool + /// Returns whether the current process is running inside an SDK sandbox. + @available(Android 33, *) @JavaStaticMethod public func isSdkSandbox() -> Bool + /// Returns the UID assigned to a particular user name, or -1 if there is none. @JavaStaticMethod public func getUidForName(_ arg0: String) -> Int32 + /// Returns the GID assigned to a particular user name, or -1 if there is none. @JavaStaticMethod public func getGidForName(_ arg0: String) -> Int32 + /// Sets the priority of the calling thread. This is effectively the same as calling the + /// `setThreadPriority(int, int)` static method with your own thread's tid. @JavaStaticMethod public func setThreadPriority(_ arg0: Int32) throws + /// Sets the priority of a thread. Note that only the process that created a thread can change + /// its priority; the calling process must have the same UID as the specified thread, or it must + /// be the init or root process. @JavaStaticMethod public func setThreadPriority(_ arg0: Int32, _ arg1: Int32) throws + /// Return the list of CPU core IDs that are reserved exclusively for the calling process. + @available(Android 24, *) @JavaStaticMethod public func getExclusiveCores() -> [Int32] + /// Returns the current priority of a thread, based on Linux priorities. @JavaStaticMethod public func getThreadPriority(_ arg0: Int32) throws -> Int32 + /// Determine whether the current environment supports multiple processes. + /// + /// - Note: Deprecated since API 8. Always returns true. @JavaStaticMethod public func supportsProcesses() -> Bool + /// Returns the name of the process. This is the same as the package name. + @available(Android 28, *) @JavaStaticMethod public func myProcessName() -> String + /// Kill the process with the given PID. Note that, though this API allows us to request to kill + /// any process based on its PID, the kernel will still impose standard restrictions on which + /// PIDs you are actually able to kill. @JavaStaticMethod public func killProcess(_ arg0: Int32) + /// Send a signal to the given process. @JavaStaticMethod public func sendSignal(_ arg0: Int32, _ arg1: Int32) } diff --git a/Sources/AndroidOS/ProcessHealthStats.swift b/Sources/AndroidOS/ProcessHealthStats.swift index a54a4364..a462a5b7 100644 --- a/Sources/AndroidOS/ProcessHealthStats.swift +++ b/Sources/AndroidOS/ProcessHealthStats.swift @@ -2,6 +2,13 @@ import SwiftJava import CSwiftJavaJNI +/// Keys for health statistics about a process within a UID. +/// +/// Use these keys with `HealthStats` to retrieve per-process battery attribution data, +/// such as crash counts, ANR counts, and foreground time. +/// +/// See also: [android.os.health.ProcessHealthStats](https://developer.android.com/reference/android/os/health/ProcessHealthStats) +@available(Android 24, *) @JavaClass("android.os.health.ProcessHealthStats") open class ProcessHealthStats: JavaObject { diff --git a/Sources/AndroidOS/RecoverySystem+ProgressListener.swift b/Sources/AndroidOS/RecoverySystem+ProgressListener.swift index bd7ea531..01e75da0 100644 --- a/Sources/AndroidOS/RecoverySystem+ProgressListener.swift +++ b/Sources/AndroidOS/RecoverySystem+ProgressListener.swift @@ -3,8 +3,15 @@ import SwiftJava import CSwiftJavaJNI extension RecoverySystem { + /// Listener for receiving progress updates during OTA package verification. + /// + /// See [android.os.RecoverySystem.ProgressListener](https://developer.android.com/reference/android/os/RecoverySystem.ProgressListener) + @available(Android 8, *) @JavaInterface("android.os.RecoverySystem$ProgressListener") public struct ProgressListener { + /// Called periodically during package verification with the current progress. + /// + /// - Parameter arg0: The verification progress as a percentage from 0 to 100. @JavaMethod public func onProgress(_ arg0: Int32) } diff --git a/Sources/AndroidOS/RecoverySystem.swift b/Sources/AndroidOS/RecoverySystem.swift index 110b5f0c..3d22f4b1 100644 --- a/Sources/AndroidOS/RecoverySystem.swift +++ b/Sources/AndroidOS/RecoverySystem.swift @@ -4,11 +4,21 @@ import JavaLangIO import SwiftJava import CSwiftJavaJNI +/// Provides utilities for interacting with the device's recovery system, including OTA package verification. +/// +/// See [android.os.RecoverySystem](https://developer.android.com/reference/android/os/RecoverySystem) +@available(Android 8, *) @JavaClass("android.os.RecoverySystem") open class RecoverySystem: JavaObject { } extension JavaClass { + /// Verifies the cryptographic signature of an OTA update package. + /// + /// - Parameters: + /// - arg0: The update package file to verify. + /// - arg1: An optional `ProgressListener` to receive verification progress updates. + /// - arg2: An optional file containing trusted public keys; uses the system default if `nil`. @JavaStaticMethod public func verifyPackage(_ arg0: File?, _ arg1: RecoverySystem.ProgressListener?, _ arg2: File?) throws } diff --git a/Sources/AndroidOS/RemoteException.swift b/Sources/AndroidOS/RemoteException.swift index 0013b9bc..d159a2dd 100644 --- a/Sources/AndroidOS/RemoteException.swift +++ b/Sources/AndroidOS/RemoteException.swift @@ -2,6 +2,10 @@ import SwiftJava import CSwiftJavaJNI +/// The parent exception for a set of errors that may occur during remote procedure calls via Binder. +/// Subclasses include `DeadObjectException` and `TransactionTooLargeException`. +/// +/// See also: [android.os.RemoteException](https://developer.android.com/reference/android/os/RemoteException) @JavaClass("android.os.RemoteException") open class RemoteException: Exception { @JavaMethod @@ -10,9 +14,13 @@ open class RemoteException: Exception { @JavaMethod @_nonoverride public convenience init(environment: JNIEnvironment? = nil) + /// Converts this `RemoteException` to a `RuntimeException`, suitable for rethrowing + /// in contexts where checked exceptions are not expected. @JavaMethod open func rethrowAsRuntimeException() -> RuntimeException! + /// Rethrows this exception as a `RuntimeException`, intended for use in system server code + /// to propagate remote errors across process boundaries. @JavaMethod open func rethrowFromSystemServer() -> RuntimeException! } diff --git a/Sources/AndroidOS/ResourceMismatchViolation.swift b/Sources/AndroidOS/ResourceMismatchViolation.swift index 587c379e..f5340b6d 100644 --- a/Sources/AndroidOS/ResourceMismatchViolation.swift +++ b/Sources/AndroidOS/ResourceMismatchViolation.swift @@ -2,6 +2,10 @@ import SwiftJava import CSwiftJavaJNI +/// Violation raised when a resource is accessed with a type that does not match its definition. +/// +/// See also: [android.os.strictmode.ResourceMismatchViolation](https://developer.android.com/reference/android/os/strictmode/ResourceMismatchViolation) +@available(Android 28, *) @JavaClass("android.os.strictmode.ResourceMismatchViolation") open class ResourceMismatchViolation: Violation { diff --git a/Sources/AndroidOS/ResultReceiver.swift b/Sources/AndroidOS/ResultReceiver.swift index 5409cc2e..fa7e414d 100644 --- a/Sources/AndroidOS/ResultReceiver.swift +++ b/Sources/AndroidOS/ResultReceiver.swift @@ -2,14 +2,31 @@ import SwiftJava import CSwiftJavaJNI +/// A generic interface for receiving a result from another process or component. +/// +/// Pass a `ResultReceiver` to an API that performs work asynchronously; the API will call +/// `send(_:_:)` when it has a result. Override `onReceiveResult(_:_:)` in a subclass to +/// handle the incoming result code and optional data bundle. +/// +/// See also: [android.os.ResultReceiver](https://developer.android.com/reference/android/os/ResultReceiver) @JavaClass("android.os.ResultReceiver", implements: Parcelable.self) open class ResultReceiver: JavaObject { @JavaMethod @_nonoverride public convenience init(_ arg0: Handler?, environment: JNIEnvironment? = nil) + /// Delivers a result to this receiver. May be called from any process. + /// + /// - Parameters: + /// - arg0: An integer result code to identify the outcome. + /// - arg1: An optional `Bundle` carrying additional result data. @JavaMethod open func send(_ arg0: Int32, _ arg1: Bundle?) + /// Called when a result is delivered via `send(_:_:)`. Override in subclasses to process results. + /// + /// - Parameters: + /// - arg0: The result code supplied by the sender. + /// - arg1: The optional data bundle supplied by the sender. @JavaMethod open func onReceiveResult(_ arg0: Int32, _ arg1: Bundle?) diff --git a/Sources/AndroidOS/SdkExtensions.swift b/Sources/AndroidOS/SdkExtensions.swift index 4b420287..99710fea 100644 --- a/Sources/AndroidOS/SdkExtensions.swift +++ b/Sources/AndroidOS/SdkExtensions.swift @@ -4,14 +4,25 @@ import JavaLangUtil import SwiftJava import CSwiftJavaJNI +/// Provides information about the extension SDK versions present on the device. +/// +/// Extension SDKs allow certain Android API surfaces to be updated independently of the +/// platform release. Use `getExtensionVersion(_:)` to query the version of a specific +/// extension by its SDK integer identifier. +/// +/// See also: [android.os.ext.SdkExtensions](https://developer.android.com/reference/android/os/ext/SdkExtensions) +@available(Android 30, *) @JavaClass("android.os.ext.SdkExtensions") open class SdkExtensions: JavaObject { } extension JavaClass { + /// Returns the extension version for the given SDK integer, or `0` if the extension + /// is not present on this device. @JavaStaticMethod public func getExtensionVersion(_ arg0: Int32) -> Int32 + /// Returns a map of all extension SDK identifiers to their version numbers on this device. @JavaStaticMethod public func getAllExtensionVersions() -> Map! } diff --git a/Sources/AndroidOS/ServiceConnectionLeakedViolation.swift b/Sources/AndroidOS/ServiceConnectionLeakedViolation.swift index 1e431d08..c95ea4c4 100644 --- a/Sources/AndroidOS/ServiceConnectionLeakedViolation.swift +++ b/Sources/AndroidOS/ServiceConnectionLeakedViolation.swift @@ -2,6 +2,10 @@ import SwiftJava import CSwiftJavaJNI +/// Violation raised when a `ServiceConnection` is leaked (bound but not unbound). +/// +/// See also: [android.os.strictmode.ServiceConnectionLeakedViolation](https://developer.android.com/reference/android/os/strictmode/ServiceConnectionLeakedViolation) +@available(Android 28, *) @JavaClass("android.os.strictmode.ServiceConnectionLeakedViolation") open class ServiceConnectionLeakedViolation: Violation { diff --git a/Sources/AndroidOS/ServiceHealthStats.swift b/Sources/AndroidOS/ServiceHealthStats.swift index 220841c0..34d95e85 100644 --- a/Sources/AndroidOS/ServiceHealthStats.swift +++ b/Sources/AndroidOS/ServiceHealthStats.swift @@ -2,6 +2,13 @@ import SwiftJava import CSwiftJavaJNI +/// Keys for health statistics about a bound Service within a UID. +/// +/// Use these keys with `HealthStats` to retrieve per-service battery attribution data, +/// such as launch counts and start-service invocation counts. +/// +/// See also: [android.os.health.ServiceHealthStats](https://developer.android.com/reference/android/os/health/ServiceHealthStats) +@available(Android 24, *) @JavaClass("android.os.health.ServiceHealthStats") open class ServiceHealthStats: JavaObject { diff --git a/Sources/AndroidOS/SharedMemory.swift b/Sources/AndroidOS/SharedMemory.swift index 4a564872..5d69ecb2 100644 --- a/Sources/AndroidOS/SharedMemory.swift +++ b/Sources/AndroidOS/SharedMemory.swift @@ -4,6 +4,11 @@ import JavaLangIO import SwiftJava import CSwiftJavaJNI +/// Provides access to a raw block of memory. Useful for sharing large amounts of data between +/// processes without going through the Parcel buffer size limit. +/// +/// See also: [android.os.SharedMemory](https://developer.android.com/reference/android/os/SharedMemory) +@available(Android 27, *) @JavaClass("android.os.SharedMemory", implements: Parcelable.self, Closeable.self) open class SharedMemory: JavaObject { @JavaMethod diff --git a/Sources/AndroidOS/SqliteObjectLeakedViolation.swift b/Sources/AndroidOS/SqliteObjectLeakedViolation.swift index 5fd5118b..24e42a9f 100644 --- a/Sources/AndroidOS/SqliteObjectLeakedViolation.swift +++ b/Sources/AndroidOS/SqliteObjectLeakedViolation.swift @@ -2,6 +2,10 @@ import SwiftJava import CSwiftJavaJNI +/// Violation raised when a SQLite object (cursor or database) is finalized without being closed. +/// +/// See also: [android.os.strictmode.SqliteObjectLeakedViolation](https://developer.android.com/reference/android/os/strictmode/SqliteObjectLeakedViolation) +@available(Android 28, *) @JavaClass("android.os.strictmode.SqliteObjectLeakedViolation") open class SqliteObjectLeakedViolation: Violation { diff --git a/Sources/AndroidOS/StatFs.swift b/Sources/AndroidOS/StatFs.swift index 95313f96..aa0ae07c 100644 --- a/Sources/AndroidOS/StatFs.swift +++ b/Sources/AndroidOS/StatFs.swift @@ -2,44 +2,59 @@ import SwiftJava import CSwiftJavaJNI +/// Retrieves file system statistics such as total, free, and available space for a given path. +/// +/// Wraps the Unix `statvfs` system call. Prefer the `Long`-returning variants (e.g., +/// `getBlockSizeLong()`, `getFreeBytes()`) over the deprecated `Int32` variants for +/// accurate results on large file systems. +/// +/// See also: [android.os.StatFs](https://developer.android.com/reference/android/os/StatFs) @JavaClass("android.os.StatFs") open class StatFs: JavaObject { @JavaMethod @_nonoverride public convenience init(_ arg0: String, environment: JNIEnvironment? = nil) + /// Re-reads the file system statistics for the path provided at construction time. @JavaMethod open func restat(_ arg0: String) @JavaMethod open func getBlockSize() -> Int32 + /// Returns the size in bytes of a single block on the file system. @JavaMethod open func getBlockSizeLong() -> Int64 @JavaMethod open func getBlockCount() -> Int32 + /// Returns the total number of blocks on the file system. @JavaMethod open func getBlockCountLong() -> Int64 @JavaMethod open func getFreeBlocks() -> Int32 + /// Returns the total number of free blocks, including those reserved for the super-user. @JavaMethod open func getFreeBlocksLong() -> Int64 + /// Returns the number of free bytes available on the file system, including reserved blocks. @JavaMethod open func getFreeBytes() -> Int64 @JavaMethod open func getAvailableBlocks() -> Int32 + /// Returns the number of blocks available to non-privileged processes. @JavaMethod open func getAvailableBlocksLong() -> Int64 + /// Returns the number of bytes available to non-privileged processes. @JavaMethod open func getAvailableBytes() -> Int64 + /// Returns the total size of the file system in bytes. @JavaMethod open func getTotalBytes() -> Int64 } diff --git a/Sources/AndroidOS/StorageManager+StorageVolumeCallback.swift b/Sources/AndroidOS/StorageManager+StorageVolumeCallback.swift index 6236c26b..9204fcdf 100644 --- a/Sources/AndroidOS/StorageManager+StorageVolumeCallback.swift +++ b/Sources/AndroidOS/StorageManager+StorageVolumeCallback.swift @@ -3,11 +3,16 @@ import SwiftJava import CSwiftJavaJNI extension StorageManager { + /// Callback invoked when the state of a `StorageVolume` changes. + /// + /// See [android.os.storage.StorageManager.StorageVolumeCallback](https://developer.android.com/reference/android/os/storage/StorageManager.StorageVolumeCallback) + @available(Android 30, *) @JavaClass("android.os.storage.StorageManager$StorageVolumeCallback") open class StorageVolumeCallback: JavaObject { @JavaMethod @_nonoverride public convenience init(environment: JNIEnvironment? = nil) + /// Called when the state of the associated `StorageVolume` has changed. @JavaMethod open func onStateChanged(_ arg0: StorageVolume?) } diff --git a/Sources/AndroidOS/StorageManager.swift b/Sources/AndroidOS/StorageManager.swift index 53e19a6c..e4ae35dc 100644 --- a/Sources/AndroidOS/StorageManager.swift +++ b/Sources/AndroidOS/StorageManager.swift @@ -5,77 +5,107 @@ import JavaLangUtil import SwiftJava import CSwiftJavaJNI +/// Provides access to device storage functions such as OBB management, storage volume enumeration, and cache quota queries. +/// +/// See [android.os.storage.StorageManager](https://developer.android.com/reference/android/os/storage/StorageManager) +@available(Android 9, *) @JavaClass("android.os.storage.StorageManager") open class StorageManager: JavaObject { + /// Unregisters a previously registered `StorageVolumeCallback`. @JavaMethod open func unregisterStorageVolumeCallback(_ arg0: StorageManager.StorageVolumeCallback?) + /// Mounts an OBB file using the provided key, notifying the listener of state changes. @JavaMethod open func mountObb(_ arg0: String, _ arg1: String, _ arg2: OnObbStateChangeListener?) -> Bool + /// Unmounts a previously mounted OBB file, notifying the listener of state changes. @JavaMethod open func unmountObb(_ arg0: String, _ arg1: Bool, _ arg2: OnObbStateChangeListener?) -> Bool + /// Returns whether the given OBB path is currently mounted. @JavaMethod open func isObbMounted(_ arg0: String) -> Bool + /// Returns the filesystem path at which the given OBB is mounted, or `nil` if not mounted. @JavaMethod open func getMountedObbPath(_ arg0: String) -> String + /// Returns the UUID for the storage volume that contains the given path. @JavaMethod open func getUuidForPath(_ arg0: File?) throws -> UUID! + /// Returns whether low-level space allocation is supported for the given file descriptor. @JavaMethod open func isAllocationSupported(_ arg0: FileDescriptor?) -> Bool + /// Returns the `StorageVolume` that contains the given file, or `nil` if none. + @available(Android 24, *) @JavaMethod open func getStorageVolume(_ arg0: File?) -> StorageVolume! + /// Returns all storage volumes currently visible to the calling user. + @available(Android 24, *) @JavaMethod open func getStorageVolumes() -> List! + /// Returns all storage volumes visible to the calling user, including those from shared profiles. @JavaMethod open func getStorageVolumesIncludingSharedProfiles() -> List! + /// Returns storage volumes that have been recently made available. @JavaMethod open func getRecentStorageVolumes() -> List! + /// Returns the primary shared/external storage volume. @JavaMethod open func getPrimaryStorageVolume() -> StorageVolume! + /// Returns whether the given file resides on an encrypted storage volume. @JavaMethod open func isEncrypted(_ arg0: File?) -> Bool + /// Opens a file descriptor backed by a `ProxyFileDescriptorCallback` on the given handler. @JavaMethod open func openProxyFileDescriptor(_ arg0: Int32, _ arg1: ProxyFileDescriptorCallback?, _ arg2: Handler?) throws -> ParcelFileDescriptor! + /// Returns the cache quota in bytes allocated to the caller for the given storage UUID. @JavaMethod open func getCacheQuotaBytes(_ arg0: UUID?) throws -> Int64 + /// Returns the total cache bytes currently used by the caller for the given storage UUID. @JavaMethod open func getCacheSizeBytes(_ arg0: UUID?) throws -> Int64 + /// Returns the number of bytes that can be allocated for the given storage UUID. @JavaMethod open func getAllocatableBytes(_ arg0: UUID?) throws -> Int64 + /// Allocates the given number of bytes on the filesystem backing the given file descriptor. @JavaMethod open func allocateBytes(_ arg0: FileDescriptor?, _ arg1: Int64) throws + /// Allocates the given number of bytes on the storage volume with the given UUID. @JavaMethod open func allocateBytes(_ arg0: UUID?, _ arg1: Int64) throws + /// Sets whether the given directory's contents should be treated as a cache group. @JavaMethod open func setCacheBehaviorGroup(_ arg0: File?, _ arg1: Bool) throws + /// Returns whether the given directory is configured as a cache group. @JavaMethod open func isCacheBehaviorGroup(_ arg0: File?) throws -> Bool + /// Sets whether deleted files under the given directory should leave behind a tombstone. @JavaMethod open func setCacheBehaviorTombstone(_ arg0: File?, _ arg1: Bool) throws + /// Returns whether tombstone cache behavior is enabled for the given directory. @JavaMethod open func isCacheBehaviorTombstone(_ arg0: File?) throws -> Bool + /// Returns whether the underlying filesystem supports checkpoint operations. @JavaMethod open func isCheckpointSupported() -> Bool } diff --git a/Sources/AndroidOS/StorageVolume.swift b/Sources/AndroidOS/StorageVolume.swift index 3ebdb1b9..71080a78 100644 --- a/Sources/AndroidOS/StorageVolume.swift +++ b/Sources/AndroidOS/StorageVolume.swift @@ -5,23 +5,33 @@ import JavaLangUtil import SwiftJava import CSwiftJavaJNI +/// Represents a storage volume on the device, such as internal storage or a removable SD card. +/// +/// See [android.os.storage.StorageVolume](https://developer.android.com/reference/android/os/storage/StorageVolume) +@available(Android 14, *) @JavaClass("android.os.storage.StorageVolume", implements: Parcelable.self) open class StorageVolume: JavaObject { + /// Returns the directory of this storage volume, or `nil` if not currently mounted. @JavaMethod open func getDirectory() -> File! + /// Returns whether this volume is the device's primary shared storage. @JavaMethod open func isPrimary() -> Bool + /// Returns whether this volume is removable (e.g., an SD card). @JavaMethod open func isRemovable() -> Bool + /// Returns whether this volume is emulated (backed by internal storage). @JavaMethod open func isEmulated() -> Bool + /// Returns the UUID uniquely identifying this storage volume, or `nil` if unavailable. @JavaMethod open func getStorageUuid() -> UUID! + /// Returns the MediaStore volume name associated with this storage volume. @JavaMethod open func getMediaStoreVolumeName() -> String @@ -31,6 +41,7 @@ open class StorageVolume: JavaObject { @JavaMethod open func writeToParcel(_ arg0: Parcel?, _ arg1: Int32) + /// Returns the filesystem UUID of this volume as a string, or `nil` if unavailable. @JavaMethod open func getUuid() -> String @@ -43,9 +54,11 @@ open class StorageVolume: JavaObject { @JavaMethod open override func hashCode() -> Int32 + /// Returns the current mount state of this volume (e.g., `Environment.MEDIA_MOUNTED`). @JavaMethod open func getState() -> String + /// Returns the `UserHandle` that owns this storage volume. @JavaMethod open func getOwner() -> UserHandle! } diff --git a/Sources/AndroidOS/StrictMode+OnThreadViolationListener.swift b/Sources/AndroidOS/StrictMode+OnThreadViolationListener.swift index 21e2d965..0b1e673b 100644 --- a/Sources/AndroidOS/StrictMode+OnThreadViolationListener.swift +++ b/Sources/AndroidOS/StrictMode+OnThreadViolationListener.swift @@ -3,8 +3,13 @@ import SwiftJava import CSwiftJavaJNI extension StrictMode { + /// Listener interface for thread policy violations, invoked on the thread that caused the violation. + /// + /// See also: [android.os.StrictMode.OnThreadViolationListener](https://developer.android.com/reference/android/os/StrictMode.OnThreadViolationListener) + @available(Android 28, *) @JavaInterface("android.os.StrictMode$OnThreadViolationListener") public struct OnThreadViolationListener { + /// Called when a thread policy violation is detected. @JavaMethod public func onThreadViolation(_ arg0: Violation?) } diff --git a/Sources/AndroidOS/StrictMode+OnVmViolationListener.swift b/Sources/AndroidOS/StrictMode+OnVmViolationListener.swift index fa5e8afb..3a44eb2d 100644 --- a/Sources/AndroidOS/StrictMode+OnVmViolationListener.swift +++ b/Sources/AndroidOS/StrictMode+OnVmViolationListener.swift @@ -3,8 +3,13 @@ import SwiftJava import CSwiftJavaJNI extension StrictMode { + /// Listener interface for VM policy violations. + /// + /// See also: [android.os.StrictMode.OnVmViolationListener](https://developer.android.com/reference/android/os/StrictMode.OnVmViolationListener) + @available(Android 28, *) @JavaInterface("android.os.StrictMode$OnVmViolationListener") public struct OnVmViolationListener { + /// Called when a VM policy violation is detected. @JavaMethod public func onVmViolation(_ arg0: Violation?) } diff --git a/Sources/AndroidOS/StrictMode+ThreadPolicy+Builder.swift b/Sources/AndroidOS/StrictMode+ThreadPolicy+Builder.swift index 63b860bb..71da68a7 100644 --- a/Sources/AndroidOS/StrictMode+ThreadPolicy+Builder.swift +++ b/Sources/AndroidOS/StrictMode+ThreadPolicy+Builder.swift @@ -3,74 +3,102 @@ import SwiftJava import CSwiftJavaJNI extension StrictMode.ThreadPolicy { + /// Builder for ``StrictMode/ThreadPolicy``. Combine detection methods and penalty methods, + /// then call ``build()`` to obtain the policy. + /// + /// See also: [android.os.StrictMode.ThreadPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.ThreadPolicy.Builder) + @available(Android 9, *) @JavaClass("android.os.StrictMode$ThreadPolicy$Builder") open class Builder: JavaObject { + /// Creates a Builder with no violations detected and no penalties set. @JavaMethod @_nonoverride public convenience init(environment: JNIEnvironment? = nil) + /// Creates a Builder based on an existing ThreadPolicy, copying all detection and penalty settings. @JavaMethod @_nonoverride public convenience init(_ arg0: StrictMode.ThreadPolicy?, environment: JNIEnvironment? = nil) + /// Detects all violations that are detectable on this thread. @JavaMethod open func detectAll() -> StrictMode.ThreadPolicy.Builder! + /// Permits all policy violations on this thread. @JavaMethod open func permitAll() -> StrictMode.ThreadPolicy.Builder! + /// Enables detection of network operations on the thread. @JavaMethod open func detectNetwork() -> StrictMode.ThreadPolicy.Builder! + /// Permits network operations on the thread. @JavaMethod open func permitNetwork() -> StrictMode.ThreadPolicy.Builder! + /// Enables detection of disk reads on the thread. @JavaMethod open func detectDiskReads() -> StrictMode.ThreadPolicy.Builder! + /// Permits disk reads on the thread. @JavaMethod open func permitDiskReads() -> StrictMode.ThreadPolicy.Builder! + /// Enables detection of custom slow calls via `noteSlowCall`. @JavaMethod open func detectCustomSlowCalls() -> StrictMode.ThreadPolicy.Builder! + /// Permits custom slow calls on the thread. @JavaMethod open func permitCustomSlowCalls() -> StrictMode.ThreadPolicy.Builder! + /// Permits resource ID mismatch mismatches on the thread. @JavaMethod open func permitResourceMismatches() -> StrictMode.ThreadPolicy.Builder! + /// Enables detection of unbuffered input/output operations on the thread. @JavaMethod open func detectUnbufferedIo() -> StrictMode.ThreadPolicy.Builder! + /// Permits unbuffered input/output operations on the thread. @JavaMethod open func permitUnbufferedIo() -> StrictMode.ThreadPolicy.Builder! + /// Enables detection of mismatches between defined resource types. @JavaMethod open func detectResourceMismatches() -> StrictMode.ThreadPolicy.Builder! + /// Enables detection of disk writes on the thread. @JavaMethod open func detectDiskWrites() -> StrictMode.ThreadPolicy.Builder! + /// Permits disk writes on the thread. @JavaMethod open func permitDiskWrites() -> StrictMode.ThreadPolicy.Builder! + /// Shows a dialog on a policy violation. @JavaMethod open func penaltyDialog() -> StrictMode.ThreadPolicy.Builder! + /// Crashes the whole process on a policy violation. @JavaMethod open func penaltyDeath() -> StrictMode.ThreadPolicy.Builder! + /// Crashes the whole process when a network operation is performed on the thread. @JavaMethod open func penaltyDeathOnNetwork() -> StrictMode.ThreadPolicy.Builder! + /// Flashes the screen when a policy violation occurs. @JavaMethod open func penaltyFlashScreen() -> StrictMode.ThreadPolicy.Builder! + /// Logs the policy violation to the system log. @JavaMethod open func penaltyLog() -> StrictMode.ThreadPolicy.Builder! + /// Sends a violation report to the DropBox system service. @JavaMethod open func penaltyDropBox() -> StrictMode.ThreadPolicy.Builder! + /// Constructs and returns the ``StrictMode/ThreadPolicy`` with the settings applied. @JavaMethod open func build() -> StrictMode.ThreadPolicy! } diff --git a/Sources/AndroidOS/StrictMode+ThreadPolicy.swift b/Sources/AndroidOS/StrictMode+ThreadPolicy.swift index 0c21f8d5..9f144bc1 100644 --- a/Sources/AndroidOS/StrictMode+ThreadPolicy.swift +++ b/Sources/AndroidOS/StrictMode+ThreadPolicy.swift @@ -3,6 +3,11 @@ import SwiftJava import CSwiftJavaJNI extension StrictMode { + /// Describes what the current thread is allowed to do and the penalty if it does something it + /// is not supposed to. Build instances with ``StrictMode/ThreadPolicy/Builder``. + /// + /// See also: [android.os.StrictMode.ThreadPolicy](https://developer.android.com/reference/android/os/StrictMode.ThreadPolicy) + @available(Android 9, *) @JavaClass("android.os.StrictMode$ThreadPolicy") open class ThreadPolicy: JavaObject { @JavaMethod @@ -10,6 +15,7 @@ extension StrictMode { } } extension JavaClass { + /// The default, lax thread policy that does not detect any violations. @JavaStaticField(isFinal: true) public var LAX: StrictMode.ThreadPolicy! } diff --git a/Sources/AndroidOS/StrictMode+VmPolicy+Builder.swift b/Sources/AndroidOS/StrictMode+VmPolicy+Builder.swift index 07f28f0a..eb09722c 100644 --- a/Sources/AndroidOS/StrictMode+VmPolicy+Builder.swift +++ b/Sources/AndroidOS/StrictMode+VmPolicy+Builder.swift @@ -3,80 +3,110 @@ import SwiftJava import CSwiftJavaJNI extension StrictMode.VmPolicy { + /// Builder for ``StrictMode/VmPolicy``. Combine detection methods and penalty methods, + /// then call ``build()`` to obtain the policy. + /// + /// See also: [android.os.StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) + @available(Android 9, *) @JavaClass("android.os.StrictMode$VmPolicy$Builder") open class Builder: JavaObject { + /// Creates a Builder with no violations detected and no penalties set. @JavaMethod @_nonoverride public convenience init(environment: JNIEnvironment? = nil) + /// Creates a Builder based on an existing VmPolicy, copying all detection and penalty settings. @JavaMethod @_nonoverride public convenience init(_ arg0: StrictMode.VmPolicy?, environment: JNIEnvironment? = nil) + /// Detects all violations that are detectable in the VM. @JavaMethod open func detectAll() -> StrictMode.VmPolicy.Builder! + /// Crashes the whole process on a policy violation. @JavaMethod open func penaltyDeath() -> StrictMode.VmPolicy.Builder! + /// Logs the policy violation to the system log. @JavaMethod open func penaltyLog() -> StrictMode.VmPolicy.Builder! + /// Sends a violation report to the DropBox system service. @JavaMethod open func penaltyDropBox() -> StrictMode.VmPolicy.Builder! + /// Sets the maximum number of allowed instances of a class; violations are reported when exceeded. @JavaMethod open func setClassInstanceLimit(_ arg0: JavaClass?, _ arg1: Int32) -> StrictMode.VmPolicy.Builder! + /// Enables detection of Activity instances left in memory after they have been destroyed. @JavaMethod open func detectActivityLeaks() -> StrictMode.VmPolicy.Builder! + /// Enables detection of usage of private non-SDK APIs. @JavaMethod open func detectNonSdkApiUsage() -> StrictMode.VmPolicy.Builder! + /// Permits usage of private non-SDK APIs without triggering a violation. @JavaMethod open func permitNonSdkApiUsage() -> StrictMode.VmPolicy.Builder! + /// Enables detection of leaked SQLite cursors and databases. @JavaMethod open func detectLeakedSqlLiteObjects() -> StrictMode.VmPolicy.Builder! + /// Enables detection of objects that implement `Closeable` and are not closed after use. @JavaMethod open func detectLeakedClosableObjects() -> StrictMode.VmPolicy.Builder! + /// Enables detection of BroadcastReceivers or ServiceConnections that are registered but not unregistered. @JavaMethod open func detectLeakedRegistrationObjects() -> StrictMode.VmPolicy.Builder! + /// Enables detection of `file://` URIs being exposed across process boundaries. @JavaMethod open func detectFileUriExposure() -> StrictMode.VmPolicy.Builder! + /// Enables detection of cleartext network traffic. @JavaMethod open func detectCleartextNetwork() -> StrictMode.VmPolicy.Builder! + /// Enables detection of content URIs accessed without the appropriate permission. @JavaMethod open func detectContentUriWithoutPermission() -> StrictMode.VmPolicy.Builder! + /// Enables detection of network sockets that are not tagged with `TrafficStats.setThreadStatsTag`. @JavaMethod open func detectUntaggedSockets() -> StrictMode.VmPolicy.Builder! + /// Enables detection of implicit direct-boot unaware calls. @JavaMethod open func detectImplicitDirectBoot() -> StrictMode.VmPolicy.Builder! + /// Enables detection of credential-protected data storage access while the device is locked. @JavaMethod open func detectCredentialProtectedWhileLocked() -> StrictMode.VmPolicy.Builder! + /// Enables detection of incorrect context use, such as using the wrong Context for UI operations. @JavaMethod open func detectIncorrectContextUse() -> StrictMode.VmPolicy.Builder! + /// Enables detection of unsafe intent launches. @JavaMethod open func detectUnsafeIntentLaunch() -> StrictMode.VmPolicy.Builder! + /// Permits unsafe intent launches without triggering a violation. @JavaMethod open func permitUnsafeIntentLaunch() -> StrictMode.VmPolicy.Builder! + /// Crashes the whole process when cleartext network traffic is detected. @JavaMethod open func penaltyDeathOnCleartextNetwork() -> StrictMode.VmPolicy.Builder! + /// Crashes the whole process when a `file://` URI is exposed. @JavaMethod open func penaltyDeathOnFileUriExposure() -> StrictMode.VmPolicy.Builder! + /// Constructs and returns the ``StrictMode/VmPolicy`` with the settings applied. @JavaMethod open func build() -> StrictMode.VmPolicy! } diff --git a/Sources/AndroidOS/StrictMode+VmPolicy.swift b/Sources/AndroidOS/StrictMode+VmPolicy.swift index a979c389..333230e4 100644 --- a/Sources/AndroidOS/StrictMode+VmPolicy.swift +++ b/Sources/AndroidOS/StrictMode+VmPolicy.swift @@ -3,6 +3,11 @@ import SwiftJava import CSwiftJavaJNI extension StrictMode { + /// Describes what the virtual machine should detect and the penalty if it detects a violation. + /// Build instances with ``StrictMode/VmPolicy/Builder``. + /// + /// See also: [android.os.StrictMode.VmPolicy](https://developer.android.com/reference/android/os/StrictMode.VmPolicy) + @available(Android 9, *) @JavaClass("android.os.StrictMode$VmPolicy") open class VmPolicy: JavaObject { @JavaMethod @@ -10,6 +15,7 @@ extension StrictMode { } } extension JavaClass { + /// The default, lax VM policy that does not detect any violations. @JavaStaticField(isFinal: true) public var LAX: StrictMode.VmPolicy! } diff --git a/Sources/AndroidOS/StrictMode.swift b/Sources/AndroidOS/StrictMode.swift index e02fdb6e..945cd56a 100644 --- a/Sources/AndroidOS/StrictMode.swift +++ b/Sources/AndroidOS/StrictMode.swift @@ -2,32 +2,45 @@ import SwiftJava import CSwiftJavaJNI +/// A class that lets you impose stricter coding practices on yourself and catch things you might +/// otherwise overlook. Thread policy and VM policy can be configured independently. +/// +/// See also: [android.os.StrictMode](https://developer.android.com/reference/android/os/StrictMode) +@available(Android 9, *) @JavaClass("android.os.StrictMode") open class StrictMode: JavaObject { } extension JavaClass { + /// Sets the policy for what actions on the current thread should be detected and penalized. @JavaStaticMethod public func setThreadPolicy(_ arg0: StrictMode.ThreadPolicy?) + /// Returns the current thread's policy. @JavaStaticMethod public func getThreadPolicy() -> StrictMode.ThreadPolicy! + /// Temporarily permits disk writes on the current thread and returns the old policy to restore when done. @JavaStaticMethod public func allowThreadDiskWrites() -> StrictMode.ThreadPolicy! + /// Temporarily permits disk reads on the current thread and returns the old policy to restore when done. @JavaStaticMethod public func allowThreadDiskReads() -> StrictMode.ThreadPolicy! + /// Sets the policy for what actions in the VM process should be detected and penalized. @JavaStaticMethod public func setVmPolicy(_ arg0: StrictMode.VmPolicy?) + /// Returns the current VM policy. @JavaStaticMethod public func getVmPolicy() -> StrictMode.VmPolicy! + /// Enables the recommended defaults for a client application. @JavaStaticMethod public func enableDefaults() + /// For code to note that it's doing work that should be done on a different thread. @JavaStaticMethod public func noteSlowCall(_ arg0: String) } diff --git a/Sources/AndroidOS/SystemClock.swift b/Sources/AndroidOS/SystemClock.swift index c8ecdddc..40c380e9 100644 --- a/Sources/AndroidOS/SystemClock.swift +++ b/Sources/AndroidOS/SystemClock.swift @@ -3,32 +3,83 @@ import JavaTime import SwiftJava import CSwiftJavaJNI +/// Core timekeeping facilities. +/// +/// Three different clocks are available, and they should not be confused: +/// - `System.currentTimeMillis()` is the standard "wall" clock (time and date), expressing +/// milliseconds since the epoch. The wall clock can be set by the user or the phone network, +/// so the time may jump backwards or forwards unpredictably. Use for correspondence with +/// real-world dates and times. +/// - `uptimeMillis()` is counted in milliseconds since the system was booted. This clock stops +/// when the system enters deep sleep, but is not affected by clock scaling, idle, or other +/// power saving mechanisms. +/// - `elapsedRealtime()` and `elapsedRealtimeNanos()` return the time since the system was +/// booted, and include deep sleep. This clock is guaranteed to be monotonic, and continues +/// to tick even when the CPU is in power saving modes. +/// +/// See also: [android.os.SystemClock](https://developer.android.com/reference/android/os/SystemClock) @JavaClass("android.os.SystemClock") open class SystemClock: JavaObject { } extension JavaClass { + /// Returns milliseconds since boot, not counting time spent in deep sleep. + /// + /// Note that this value may get reset occasionally (before it would otherwise wrap around) + /// when the phone is powered down and restarted. + /// + /// - Returns: Milliseconds of non-sleep uptime since boot. @JavaStaticMethod public func uptimeMillis() -> Int64 + /// Sets the current wall time, in milliseconds. Requires the calling process to have appropriate + /// permissions. + /// + /// - Returns: If the clock was successfully set to the specified time. @JavaStaticMethod public func setCurrentTimeMillis(_ arg0: Int64) -> Bool + /// Returns milliseconds since boot, including time spent in sleep. + /// + /// - Returns: Elapsed milliseconds since boot. @JavaStaticMethod public func elapsedRealtime() -> Int64 + /// Returns nanoseconds since boot, including time spent in sleep. + /// + /// - Returns: Elapsed nanoseconds since boot. + @available(Android 17, *) @JavaStaticMethod public func elapsedRealtimeNanos() -> Int64 + /// Returns milliseconds running in the current thread. + /// + /// - Returns: Milliseconds of CPU time used by the current thread. @JavaStaticMethod public func currentThreadTimeMillis() -> Int64 + /// Returns a `Clock` backed by `currentNetworkTimeClock()`. + /// + /// Throws `DateTimeException` if the network time is not available. + @available(Android 33, *) @JavaStaticMethod public func currentNetworkTimeClock() -> Clock! + /// Returns a `Clock` backed by `elapsedRealtime()` that, when queried, provides an estimate + /// of the current epoch time using the GNSS-provided time. + /// + /// Throws `DateTimeException` if the GNSS time is not available. + @available(Android 34, *) @JavaStaticMethod public func currentGnssTimeClock() -> Clock! + /// Waits a given number of milliseconds (of uptimeMillis) before returning. + /// + /// Similar to `Thread.sleep(long)`, but does not throw `InterruptedException`; `interrupt()` + /// events are deferred until the next interruptible operation. Does not return until at least + /// the specified number of milliseconds has elapsed. + /// + /// - Parameter arg0: Time to sleep in milliseconds. @JavaStaticMethod public func sleep(_ arg0: Int64) } diff --git a/Sources/AndroidOS/SystemHealthManager.swift b/Sources/AndroidOS/SystemHealthManager.swift index 560ca4e3..f02c47a6 100644 --- a/Sources/AndroidOS/SystemHealthManager.swift +++ b/Sources/AndroidOS/SystemHealthManager.swift @@ -2,6 +2,12 @@ import SwiftJava import CSwiftJavaJNI +/// Provides access to system health (battery/power) statistics for UIDs. +/// +/// Obtain an instance via `Context.getSystemService(SystemHealthManager.class)`. +/// +/// See also: [android.os.health.SystemHealthManager](https://developer.android.com/reference/android/os/health/SystemHealthManager) +@available(Android 24, *) @JavaClass("android.os.health.SystemHealthManager") open class SystemHealthManager: JavaObject { @JavaMethod diff --git a/Sources/AndroidOS/TimerStat.swift b/Sources/AndroidOS/TimerStat.swift index d2788d06..ce95e694 100644 --- a/Sources/AndroidOS/TimerStat.swift +++ b/Sources/AndroidOS/TimerStat.swift @@ -2,6 +2,13 @@ import SwiftJava import CSwiftJavaJNI +/// Holds the count and total duration for a timed event in health statistics. +/// +/// Used with `HealthStats` to represent events that have both a count (number of occurrences) +/// and a time duration (total elapsed time in milliseconds). +/// +/// See also: [android.os.health.TimerStat](https://developer.android.com/reference/android/os/health/TimerStat) +@available(Android 24, *) @JavaClass("android.os.health.TimerStat", implements: Parcelable.self) open class TimerStat: JavaObject { @JavaMethod diff --git a/Sources/AndroidOS/TokenWatcher.swift b/Sources/AndroidOS/TokenWatcher.swift index 763ed830..ab11b9d0 100644 --- a/Sources/AndroidOS/TokenWatcher.swift +++ b/Sources/AndroidOS/TokenWatcher.swift @@ -4,32 +4,49 @@ import JavaLangIO import SwiftJava import CSwiftJavaJNI +/// Watches a set of `IBinder` tokens and notifies subclasses when the set transitions +/// between empty and non-empty. +/// +/// Callers acquire tokens via `acquire(_:_:)` and release them via `release(_:)`. +/// Override `acquired()` and `released()` to respond when the watched set becomes +/// non-empty or empties, respectively. +/// +/// See also: [android.os.TokenWatcher](https://developer.android.com/reference/android/os/TokenWatcher) @JavaClass("android.os.TokenWatcher") open class TokenWatcher: JavaObject { @JavaMethod @_nonoverride public convenience init(_ arg0: Handler?, _ arg1: String, environment: JNIEnvironment? = nil) + /// Called when the set of held tokens transitions from non-empty to empty. + /// Override to respond to the released state. @JavaMethod open func released() + /// Returns `true` if at least one token is currently held. @JavaMethod open func isAcquired() -> Bool + /// Dumps a summary of currently held tokens to the log. @JavaMethod open func dump() + /// Dumps a summary of currently held tokens to the given `PrintWriter`. @JavaMethod open func dump(_ arg0: PrintWriter?) + /// Releases the token associated with the given `IBinder`, removing it from the watched set. @JavaMethod open func release(_ arg0: IBinder?) @JavaMethod open func cleanup(_ arg0: IBinder?, _ arg1: Bool) + /// Adds the given `IBinder` token to the watched set with the specified display name. @JavaMethod open func acquire(_ arg0: IBinder?, _ arg1: String) + /// Called when the set of held tokens transitions from empty to non-empty. + /// Override to respond to the acquired state. @JavaMethod open func acquired() } diff --git a/Sources/AndroidOS/Trace.swift b/Sources/AndroidOS/Trace.swift index 0f72cc2e..83b059e6 100644 --- a/Sources/AndroidOS/Trace.swift +++ b/Sources/AndroidOS/Trace.swift @@ -2,26 +2,69 @@ import SwiftJava import CSwiftJavaJNI +/// Writes trace events to the system trace buffer. These trace events can be collected and +/// visualized using the Perfetto tool. +/// +/// This tracing mechanism is independent of the method tracing mechanism offered by `Debug.startMethodTracing()`. +/// In particular, it enables tracing of events that occur across multiple processes. +/// +/// For information about using the Perfetto tool, read +/// [Capture a system trace on the command line](https://developer.android.com/topic/performance/tracing/command-line). +/// +/// See also: [android.os.Trace](https://developer.android.com/reference/android/os/Trace) +@available(Android 18, *) @JavaClass("android.os.Trace") open class Trace: JavaObject { } extension JavaClass { + /// Writes a trace message to indicate that a given section of code has begun. + /// + /// This call must be followed by a corresponding call to `endSection()` on the same thread. + /// + /// - Parameter arg0: The name of the code section to appear in the trace. The name may + /// be at most 127 Unicode code units long. @JavaStaticMethod public func beginSection(_ arg0: String) + /// Writes a trace message to indicate that a given section of code has ended. + /// + /// This call must be preceded by a corresponding call to `beginSection(String)`. + /// Calling this method will mark the end of the most recently begun section of code, + /// so care must be taken to ensure that `beginSection` / `endSection` pairs are + /// properly nested and called from the same thread. @JavaStaticMethod public func endSection() + /// Writes a trace message to indicate that a given section of code has begun. Unlike + /// `beginSection(String)` and `endSection()`, asynchronous events do not need to be + /// nested. The cookie can be used to distinguish simultaneous events. + /// + /// - Parameter arg0: The name of the code section to appear in the trace. + /// - Parameter arg1: An identifier for distinguishing simultaneous events with the same name. + @available(Android 29, *) @JavaStaticMethod public func beginAsyncSection(_ arg0: String, _ arg1: Int32) + /// Writes a trace message to indicate that the current method has ended. Must be called from + /// the same thread as the corresponding `beginAsyncSection(String, int)`. + /// + /// - Parameter arg0: The name of the code section to appear in the trace. + /// - Parameter arg1: An identifier for distinguishing simultaneous events with the same name. + @available(Android 29, *) @JavaStaticMethod public func endAsyncSection(_ arg0: String, _ arg1: Int32) + /// Writes trace message to indicate the value of a given counter. + /// + /// - Parameter arg0: The counter's name. + /// - Parameter arg1: The counter's value. + @available(Android 29, *) @JavaStaticMethod public func setCounter(_ arg0: String, _ arg1: Int64) + /// Returns true if the app tracing is currently enabled. + @available(Android 29, *) @JavaStaticMethod public func isEnabled() -> Bool } diff --git a/Sources/AndroidOS/TransactionTooLargeException.swift b/Sources/AndroidOS/TransactionTooLargeException.swift index df11d75e..6d91e814 100644 --- a/Sources/AndroidOS/TransactionTooLargeException.swift +++ b/Sources/AndroidOS/TransactionTooLargeException.swift @@ -2,6 +2,12 @@ import SwiftJava import CSwiftJavaJNI +/// Thrown when a Binder transaction fails because the data being transferred is too large. +/// The Binder transaction buffer has a fixed, limited size shared across all active transactions +/// for the process; payloads should be reduced or transferred via alternative means such as files. +/// +/// See also: [android.os.TransactionTooLargeException](https://developer.android.com/reference/android/os/TransactionTooLargeException) +@available(Android 15, *) @JavaClass("android.os.TransactionTooLargeException") open class TransactionTooLargeException: RemoteException { @JavaMethod diff --git a/Sources/AndroidOS/UidHealthStats.swift b/Sources/AndroidOS/UidHealthStats.swift index 78ba8cb8..85e344da 100644 --- a/Sources/AndroidOS/UidHealthStats.swift +++ b/Sources/AndroidOS/UidHealthStats.swift @@ -2,6 +2,13 @@ import SwiftJava import CSwiftJavaJNI +/// Keys for health statistics about a UID (app or shared UID). +/// +/// Use these keys with `HealthStats` to retrieve per-UID battery attribution data, +/// including CPU time, network activity, sensor usage, wake locks, and more. +/// +/// See also: [android.os.health.UidHealthStats](https://developer.android.com/reference/android/os/health/UidHealthStats) +@available(Android 24, *) @JavaClass("android.os.health.UidHealthStats") open class UidHealthStats: JavaObject { diff --git a/Sources/AndroidOS/UnbufferedIoViolation.swift b/Sources/AndroidOS/UnbufferedIoViolation.swift index bc2fe91c..89ea8acc 100644 --- a/Sources/AndroidOS/UnbufferedIoViolation.swift +++ b/Sources/AndroidOS/UnbufferedIoViolation.swift @@ -2,6 +2,10 @@ import SwiftJava import CSwiftJavaJNI +/// Violation raised when unbuffered input/output is performed on a thread that has forbidden it. +/// +/// See also: [android.os.strictmode.UnbufferedIoViolation](https://developer.android.com/reference/android/os/strictmode/UnbufferedIoViolation) +@available(Android 28, *) @JavaClass("android.os.strictmode.UnbufferedIoViolation") open class UnbufferedIoViolation: Violation { diff --git a/Sources/AndroidOS/UnsafeIntentLaunchViolation.swift b/Sources/AndroidOS/UnsafeIntentLaunchViolation.swift index 7207c3c8..dc708acb 100644 --- a/Sources/AndroidOS/UnsafeIntentLaunchViolation.swift +++ b/Sources/AndroidOS/UnsafeIntentLaunchViolation.swift @@ -2,6 +2,10 @@ import SwiftJava import CSwiftJavaJNI +/// Violation raised when an `Intent` with mutable extras is passed to `startActivity` or similar methods in an unsafe way. +/// +/// See also: [android.os.strictmode.UnsafeIntentLaunchViolation](https://developer.android.com/reference/android/os/strictmode/UnsafeIntentLaunchViolation) +@available(Android 31, *) @JavaClass("android.os.strictmode.UnsafeIntentLaunchViolation") open class UnsafeIntentLaunchViolation: Violation { diff --git a/Sources/AndroidOS/UntaggedSocketViolation.swift b/Sources/AndroidOS/UntaggedSocketViolation.swift index f343413a..2b0d06ef 100644 --- a/Sources/AndroidOS/UntaggedSocketViolation.swift +++ b/Sources/AndroidOS/UntaggedSocketViolation.swift @@ -2,6 +2,10 @@ import SwiftJava import CSwiftJavaJNI +/// Violation raised when a network socket is used without being tagged via `TrafficStats.setThreadStatsTag`. +/// +/// See also: [android.os.strictmode.UntaggedSocketViolation](https://developer.android.com/reference/android/os/strictmode/UntaggedSocketViolation) +@available(Android 28, *) @JavaClass("android.os.strictmode.UntaggedSocketViolation") open class UntaggedSocketViolation: Violation { diff --git a/Sources/AndroidOS/UserHandle.swift b/Sources/AndroidOS/UserHandle.swift index efd2dda0..63e5a1d2 100644 --- a/Sources/AndroidOS/UserHandle.swift +++ b/Sources/AndroidOS/UserHandle.swift @@ -2,6 +2,13 @@ import SwiftJava import CSwiftJavaJNI +/// Represents a specific user on the device. Supports equality checking and parceling. +/// +/// On a multi-user device, each user has their own isolated set of data. A `UserHandle` +/// identifies a specific user and is used in places where the API operates on a per-user basis. +/// +/// See also: [android.os.UserHandle](https://developer.android.com/reference/android/os/UserHandle) +@available(Android 17, *) @JavaClass("android.os.UserHandle", implements: Parcelable.self) open class UserHandle: JavaObject { @JavaMethod @@ -32,12 +39,16 @@ extension JavaClass { @JavaStaticField(isFinal: true) public var PARCELABLE_WRITE_RETURN_VALUE: Int32 + /// Write a UserHandle to a Parcel, handling null values. @JavaStaticMethod public func writeToParcel(_ arg0: UserHandle?, _ arg1: Parcel?) + /// Returns the UserHandle for a given UID. + @available(Android 23, *) @JavaStaticMethod public func getUserHandleForUid(_ arg0: Int32) -> UserHandle! + /// Reads a UserHandle from a Parcel previously written with `writeToParcel(UserHandle, Parcel)`. @JavaStaticMethod public func readFromParcel(_ arg0: Parcel?) -> UserHandle! } diff --git a/Sources/AndroidOS/VibrationAttributes+Builder.swift b/Sources/AndroidOS/VibrationAttributes+Builder.swift index 55f03fc0..a86ddf1d 100644 --- a/Sources/AndroidOS/VibrationAttributes+Builder.swift +++ b/Sources/AndroidOS/VibrationAttributes+Builder.swift @@ -3,20 +3,38 @@ import SwiftJava import CSwiftJavaJNI extension VibrationAttributes { + /// Builder class for `VibrationAttributes` objects. + /// + /// See also: [android.os.VibrationAttributes.Builder](https://developer.android.com/reference/android/os/VibrationAttributes.Builder) + @available(Android 30, *) @JavaClass("android.os.VibrationAttributes$Builder") open class Builder: JavaObject { + /// Constructs a new Builder with no attributes set. @JavaMethod @_nonoverride public convenience init(environment: JNIEnvironment? = nil) + /// Constructs a new Builder with attributes copied from an existing `VibrationAttributes`. @JavaMethod @_nonoverride public convenience init(_ arg0: VibrationAttributes?, environment: JNIEnvironment? = nil) + /// Sets the attribute describing the type of the corresponding vibration. + /// + /// - Parameter arg0: One of the `VibrationAttributes.USAGE_*` constants. + /// - Returns: This Builder to allow chaining of calls. @JavaMethod open func setUsage(_ arg0: Int32) -> VibrationAttributes.Builder! + /// Creates a `VibrationAttributes` with the given parameters and the current settings. + /// + /// - Returns: The new `VibrationAttributes`. @JavaMethod open func build() -> VibrationAttributes! + /// Replaces flags with the given flags, filtered by the mask. + /// + /// - Parameter arg0: The flags to set. + /// - Parameter arg1: The mask for the flags. + /// - Returns: This Builder to allow chaining of calls. @JavaMethod open func setFlags(_ arg0: Int32, _ arg1: Int32) -> VibrationAttributes.Builder! } diff --git a/Sources/AndroidOS/VibrationAttributes.swift b/Sources/AndroidOS/VibrationAttributes.swift index 8cfd0a72..736614a4 100644 --- a/Sources/AndroidOS/VibrationAttributes.swift +++ b/Sources/AndroidOS/VibrationAttributes.swift @@ -2,6 +2,16 @@ import SwiftJava import CSwiftJavaJNI +/// Encapsulates a collection of attributes describing information about a vibration effect. +/// +/// These attributes are used to describe the reason a vibration is occurring, and may be used +/// to apply system-level policies for how the vibration should be performed, or whether it should +/// be allowed to perform at all. +/// +/// Use `VibrationAttributes.Builder` to construct an instance. +/// +/// See also: [android.os.VibrationAttributes](https://developer.android.com/reference/android/os/VibrationAttributes) +@available(Android 30, *) @JavaClass("android.os.VibrationAttributes", implements: Parcelable.self) open class VibrationAttributes: JavaObject { @JavaMethod @@ -10,12 +20,19 @@ open class VibrationAttributes: JavaObject { @JavaMethod open func writeToParcel(_ arg0: Parcel?, _ arg1: Int32) + /// Returns the usage class for these vibration attributes. + /// + /// - Returns: One of the `USAGE_CLASS_*` constants. @JavaMethod open func getUsageClass() -> Int32 + /// Returns the usage for these vibration attributes. + /// + /// - Returns: One of the `USAGE_*` constants. @JavaMethod open func getUsage() -> Int32 + /// Returns whether the given flag is set. @JavaMethod open func isFlagSet(_ arg0: Int32) -> Bool @@ -28,6 +45,7 @@ open class VibrationAttributes: JavaObject { @JavaMethod open override func hashCode() -> Int32 + /// Returns the flags for these vibration attributes. @JavaMethod open func getFlags() -> Int32 } @@ -35,51 +53,68 @@ extension JavaClass { @JavaStaticField(isFinal: true) public var CREATOR: Parcelable.Creator! + /// Flag requesting vibration effect to be played even under limited conditions. @JavaStaticField(isFinal: true) public var FLAG_BYPASS_INTERRUPTION_POLICY: Int32 + /// Usage value to use for accessibility vibrations, such as feedback when navigating + /// on screen or activating accessibility features. @JavaStaticField(isFinal: true) public var USAGE_ACCESSIBILITY: Int32 + /// Usage value to use for alarm vibrations. @JavaStaticField(isFinal: true) public var USAGE_ALARM: Int32 + /// Usage class value to use when the vibration is related to an alarm. @JavaStaticField(isFinal: true) public var USAGE_CLASS_ALARM: Int32 + /// Usage class value to use when the vibration is feedback in response to a user action. @JavaStaticField(isFinal: true) public var USAGE_CLASS_FEEDBACK: Int32 + /// Mask for vibration usage class constants. @JavaStaticField(isFinal: true) public var USAGE_CLASS_MASK: Int32 + /// Usage class value to use when the vibration is part of audio/media playback. @JavaStaticField(isFinal: true) public var USAGE_CLASS_MEDIA: Int32 + /// Usage class value to use when the vibration usage class is unknown. @JavaStaticField(isFinal: true) public var USAGE_CLASS_UNKNOWN: Int32 + /// Usage value to use for incoming communication request vibrations. @JavaStaticField(isFinal: true) public var USAGE_COMMUNICATION_REQUEST: Int32 + /// Usage value to use for hardware feedback vibrations. @JavaStaticField(isFinal: true) public var USAGE_HARDWARE_FEEDBACK: Int32 + /// Usage value to use for vibrations that are part of audio/media playback. @JavaStaticField(isFinal: true) public var USAGE_MEDIA: Int32 + /// Usage value to use for notification vibrations. @JavaStaticField(isFinal: true) public var USAGE_NOTIFICATION: Int32 + /// Usage value to use for physical emulation vibrations. @JavaStaticField(isFinal: true) public var USAGE_PHYSICAL_EMULATION: Int32 + /// Usage value to use for ringtone vibrations. @JavaStaticField(isFinal: true) public var USAGE_RINGTONE: Int32 + /// Usage value to use for touch vibrations (e.g., when the user touches a UI element). @JavaStaticField(isFinal: true) public var USAGE_TOUCH: Int32 + /// Usage value to use when usage is unknown. @JavaStaticField(isFinal: true) public var USAGE_UNKNOWN: Int32 @@ -89,6 +124,9 @@ extension JavaClass { @JavaStaticField(isFinal: true) public var PARCELABLE_WRITE_RETURN_VALUE: Int32 + /// Creates a `VibrationAttributes` object with the given usage. + /// + /// - Parameter arg0: One of the `USAGE_*` constants. @JavaStaticMethod public func createForUsage(_ arg0: Int32) -> VibrationAttributes! } diff --git a/Sources/AndroidOS/VibrationEffect+Composition.swift b/Sources/AndroidOS/VibrationEffect+Composition.swift index efaffe67..5c377d88 100644 --- a/Sources/AndroidOS/VibrationEffect+Composition.swift +++ b/Sources/AndroidOS/VibrationEffect+Composition.swift @@ -3,43 +3,78 @@ import SwiftJava import CSwiftJavaJNI extension VibrationEffect { + /// A composition of haptic primitives that, when combined, create more complex haptic patterns. + /// + /// To create a Composition, use `VibrationEffect.startComposition()`. + /// + /// See also: [android.os.VibrationEffect.Composition](https://developer.android.com/reference/android/os/VibrationEffect.Composition) + @available(Android 30, *) @JavaClass("android.os.VibrationEffect$Composition") open class Composition: JavaObject { + /// Add a haptic primitive to the end of the current composition, with a specific scale factor + /// applied to it. + /// + /// - Parameter arg0: The primitive to add (a `PRIMITIVE_*` constant). + /// - Parameter arg1: The scale to apply to the amplitude (0.0 to 1.0). + /// - Returns: This Composition to allow chaining of calls. @JavaMethod open func addPrimitive(_ arg0: Int32, _ arg1: Float) -> VibrationEffect.Composition! + /// Add a haptic primitive to the end of the current composition with default scale. + /// + /// - Parameter arg0: The primitive to add (a `PRIMITIVE_*` constant). + /// - Returns: This Composition to allow chaining of calls. @JavaMethod open func addPrimitive(_ arg0: Int32) -> VibrationEffect.Composition! + /// Add a haptic primitive to the end of the current composition with scale and delay. + /// + /// - Parameter arg0: The primitive to add (a `PRIMITIVE_*` constant). + /// - Parameter arg1: The scale to apply to the amplitude (0.0 to 1.0). + /// - Parameter arg2: The delay in milliseconds to wait before playing this primitive. + /// - Returns: This Composition to allow chaining of calls. @JavaMethod open func addPrimitive(_ arg0: Int32, _ arg1: Float, _ arg2: Int32) -> VibrationEffect.Composition! + /// Compose all of the added primitives together into a single `VibrationEffect`. + /// + /// - Returns: The `VibrationEffect` representing the composition. @JavaMethod open func compose() -> VibrationEffect! } } extension JavaClass { + /// Primitive: a brief, standard feedback effect (click). @JavaStaticField(isFinal: true) public var PRIMITIVE_CLICK: Int32 + /// Primitive: a very weak, short tick sensation. + @available(Android 31, *) @JavaStaticField(isFinal: true) public var PRIMITIVE_LOW_TICK: Int32 + /// Primitive: a quick downward ramp in amplitude. @JavaStaticField(isFinal: true) public var PRIMITIVE_QUICK_FALL: Int32 + /// Primitive: a quick upward ramp in amplitude. @JavaStaticField(isFinal: true) public var PRIMITIVE_QUICK_RISE: Int32 + /// Primitive: a slow upward ramp in amplitude. @JavaStaticField(isFinal: true) public var PRIMITIVE_SLOW_RISE: Int32 + /// Primitive: a spinning sensation. + @available(Android 31, *) @JavaStaticField(isFinal: true) public var PRIMITIVE_SPIN: Int32 + /// Primitive: a strong, heavy impact. @JavaStaticField(isFinal: true) public var PRIMITIVE_THUD: Int32 + /// Primitive: a very short, light sensation. @JavaStaticField(isFinal: true) public var PRIMITIVE_TICK: Int32 } diff --git a/Sources/AndroidOS/VibrationEffect.swift b/Sources/AndroidOS/VibrationEffect.swift index a7e32ca1..ed5636a2 100644 --- a/Sources/AndroidOS/VibrationEffect.swift +++ b/Sources/AndroidOS/VibrationEffect.swift @@ -2,6 +2,16 @@ import SwiftJava import CSwiftJavaJNI +/// A VibrationEffect describes a haptic effect to be performed by a `Vibrator`. +/// +/// These effects may be performed on any Vibrator that supports them, however devices may not +/// support all effects. Some devices may not support haptics at all. +/// +/// Use the static factory methods (`createOneShot()`, `createWaveform()`, `createPredefined()`, +/// or `startComposition()`) to create a `VibrationEffect`. +/// +/// See also: [android.os.VibrationEffect](https://developer.android.com/reference/android/os/VibrationEffect) +@available(Android 26, *) @JavaClass("android.os.VibrationEffect", implements: Parcelable.self) open class VibrationEffect: JavaObject { @JavaMethod @@ -11,18 +21,28 @@ extension JavaClass { @JavaStaticField(isFinal: true) public var CREATOR: Parcelable.Creator! + /// The default amplitude for `createOneShot(long, int)`. This is device-specific and may not + /// produce consistent results across devices. @JavaStaticField(isFinal: true) public var DEFAULT_AMPLITUDE: Int32 + /// A click effect. Use this effect as a baseline, as it's the most common type of haptic feedback. + @available(Android 29, *) @JavaStaticField(isFinal: true) public var EFFECT_CLICK: Int32 + /// A double-click effect. + @available(Android 29, *) @JavaStaticField(isFinal: true) public var EFFECT_DOUBLE_CLICK: Int32 + /// A heavy click effect. This effect is stronger than `EFFECT_CLICK`. + @available(Android 29, *) @JavaStaticField(isFinal: true) public var EFFECT_HEAVY_CLICK: Int32 + /// A tick effect. This effect is weaker than `EFFECT_CLICK`. + @available(Android 29, *) @JavaStaticField(isFinal: true) public var EFFECT_TICK: Int32 @@ -32,18 +52,46 @@ extension JavaClass { @JavaStaticField(isFinal: true) public var PARCELABLE_WRITE_RETURN_VALUE: Int32 + /// Creates a predefined vibration effect. + /// + /// Predefined effects are a set of standard vibration effects that should be identical, + /// regardless of the app requesting them. + /// + /// - Parameter arg0: The ID of the effect to perform, one of the `EFFECT_*` constants. + /// - Returns: A `VibrationEffect` for the predefined effect. + @available(Android 29, *) @JavaStaticMethod public func createPredefined(_ arg0: Int32) -> VibrationEffect! + /// Start composing a haptic effect. + /// + /// - Returns: A `VibrationEffect.Composition` builder. + @available(Android 30, *) @JavaStaticMethod public func startComposition() -> VibrationEffect.Composition! + /// Creates a one-shot vibration. + /// + /// One-shot vibrations will vibrate constantly for the specified period of time at the + /// specified amplitude, and then stop. + /// + /// - Parameter arg0: The number of milliseconds to vibrate. Must be positive. + /// - Parameter arg1: The strength of the vibration. Must be between 1 and 255, or `DEFAULT_AMPLITUDE`. @JavaStaticMethod public func createOneShot(_ arg0: Int64, _ arg1: Int32) -> VibrationEffect! + /// Create a waveform vibration with amplitudes. + /// + /// - Parameter arg0: Timing values for turning the vibrator on and off (in milliseconds). + /// - Parameter arg1: Amplitude values, one per timing segment. + /// - Parameter arg2: The index into the timings array at which to repeat, or `-1` for no repeat. @JavaStaticMethod public func createWaveform(_ arg0: [Int64], _ arg1: [Int32], _ arg2: Int32) -> VibrationEffect! + /// Create a waveform vibration. + /// + /// - Parameter arg0: Timing values for turning the vibrator on and off (in milliseconds). + /// - Parameter arg1: The index into the timings array at which to repeat, or `-1` for no repeat. @JavaStaticMethod public func createWaveform(_ arg0: [Int64], _ arg1: Int32) -> VibrationEffect! } diff --git a/Sources/AndroidOS/Vibrator.swift b/Sources/AndroidOS/Vibrator.swift index ea841759..e8056cf1 100644 --- a/Sources/AndroidOS/Vibrator.swift +++ b/Sources/AndroidOS/Vibrator.swift @@ -2,54 +2,119 @@ import SwiftJava import CSwiftJavaJNI +/// Class that operates the vibrator on the device. +/// +/// If your process exits, any vibrations you started will stop. +/// +/// To obtain an instance of the system vibrator, call +/// `Context.getSystemService(Context.VIBRATOR_SERVICE)`. +/// +/// See also: [android.os.Vibrator](https://developer.android.com/reference/android/os/Vibrator) @JavaClass("android.os.Vibrator") open class Vibrator: JavaObject { + /// Check whether the hardware has a vibrator. + /// + /// - Returns: `true` if the hardware has a vibrator, `false` otherwise. @JavaMethod open func hasVibrator() -> Bool + /// Check whether the vibrator has amplitude control. + /// + /// - Returns: `true` if the hardware can control the amplitude of vibrations, `false` otherwise. + @available(Android 26, *) @JavaMethod open func hasAmplitudeControl() -> Bool + /// Vibrate with a repeating pattern. + /// + /// - Parameter arg0: Timing values for turning the vibrator on and off. + /// - Parameter arg1: The index into the timings array at which to repeat, or `-1` for no repeat. + /// + /// - Note: Deprecated since API 26. Use `vibrate(VibrationEffect)` instead. @JavaMethod open func vibrate(_ arg0: [Int64], _ arg1: Int32) + /// Vibrate with a given `VibrationEffect` and `VibrationAttributes`. + @available(Android 33, *) @JavaMethod open func vibrate(_ arg0: VibrationEffect?, _ arg1: VibrationAttributes?) + /// Vibrate with a given `VibrationEffect`. + @available(Android 26, *) @JavaMethod open func vibrate(_ arg0: VibrationEffect?) + /// Vibrate constantly for the specified period of time. + /// + /// - Parameter arg0: The number of milliseconds to vibrate. + /// + /// - Note: Deprecated since API 26. Use `vibrate(VibrationEffect)` instead. @JavaMethod open func vibrate(_ arg0: Int64) + /// Query whether the vibrator supports the given predefined effects. + /// + /// - Parameter arg0: An array of `VibrationEffect.EFFECT_*` constants to query. + /// - Returns: An array of support status codes, one per queried effect. + @available(Android 30, *) @JavaMethod open func areEffectsSupported(_ arg0: [Int32]) -> [Int32] + /// Query whether the vibrator supports all of the given effects. + /// + /// - Returns: `VIBRATION_EFFECT_SUPPORT_YES`, `VIBRATION_EFFECT_SUPPORT_NO`, or + /// `VIBRATION_EFFECT_SUPPORT_UNKNOWN`. + @available(Android 30, *) @JavaMethod open func areAllEffectsSupported(_ arg0: [Int32]) -> Int32 + /// Query whether the vibrator supports the given composition primitives. + /// + /// - Parameter arg0: An array of `VibrationEffect.Composition.PRIMITIVE_*` constants to query. + /// - Returns: An array of booleans indicating support for each primitive. + @available(Android 30, *) @JavaMethod open func arePrimitivesSupported(_ arg0: [Int32]) -> [Bool] + /// Query whether the vibrator supports all of the given composition primitives. + /// + /// - Returns: `true` if all primitives are supported, `false` otherwise. + @available(Android 30, *) @JavaMethod open func areAllPrimitivesSupported(_ arg0: [Int32]) -> Bool + /// Query the estimated durations of the given composition primitives. + /// + /// - Parameter arg0: An array of `VibrationEffect.Composition.PRIMITIVE_*` constants. + /// - Returns: An array of estimated durations in milliseconds. + @available(Android 31, *) @JavaMethod open func getPrimitiveDurations(_ arg0: [Int32]) -> [Int32] + /// Gets the ID of this vibrator. + /// + /// - Returns: The vibrator ID, or `-1` if this is the default vibrator. + @available(Android 31, *) @JavaMethod open func getId() -> Int32 + /// Turn the vibrator off. @JavaMethod open func cancel() } extension JavaClass { + /// Vibration effect support: the effect is not supported by this vibrator. + @available(Android 30, *) @JavaStaticField(isFinal: true) public var VIBRATION_EFFECT_SUPPORT_NO: Int32 + /// Vibration effect support: support for the effect is not known. + @available(Android 30, *) @JavaStaticField(isFinal: true) public var VIBRATION_EFFECT_SUPPORT_UNKNOWN: Int32 + /// Vibration effect support: the effect is supported by this vibrator. + @available(Android 30, *) @JavaStaticField(isFinal: true) public var VIBRATION_EFFECT_SUPPORT_YES: Int32 } diff --git a/Sources/AndroidOS/VibratorManager.swift b/Sources/AndroidOS/VibratorManager.swift index 49e780e8..6f8e84e3 100644 --- a/Sources/AndroidOS/VibratorManager.swift +++ b/Sources/AndroidOS/VibratorManager.swift @@ -2,23 +2,47 @@ import SwiftJava import CSwiftJavaJNI +/// VibratorManager is used to access all the vibrators available on the device, to vibrate +/// in a synchronized manner, or to perform complex vibration effects using multiple vibrators +/// simultaneously. +/// +/// To obtain an instance of the vibrator manager, call +/// `Context.getSystemService(Context.VIBRATOR_MANAGER_SERVICE)`. +/// +/// See also: [android.os.VibratorManager](https://developer.android.com/reference/android/os/VibratorManager) +@available(Android 31, *) @JavaClass("android.os.VibratorManager") open class VibratorManager: JavaObject { + /// Vibrate with a given `CombinedVibration`. + /// + /// - Parameter arg0: The `CombinedVibration` to perform. @JavaMethod open func vibrate(_ arg0: CombinedVibration?) + /// Vibrate with a given `CombinedVibration` and `VibrationAttributes`. + /// + /// - Parameter arg0: The `CombinedVibration` to perform. + /// - Parameter arg1: Attributes to describe the reason and properties of the vibration. @JavaMethod open func vibrate(_ arg0: CombinedVibration?, _ arg1: VibrationAttributes?) + /// Retrieve a specific vibrator by its ID. + /// + /// - Parameter arg0: The ID of the vibrator to retrieve. + /// - Returns: The `Vibrator` with the given ID, or `nil` if not found. @JavaMethod open func getVibrator(_ arg0: Int32) -> Vibrator! + /// Returns the default vibrator (the first vibrator on the device, or a virtual one if + /// no physical vibrators are available). @JavaMethod open func getDefaultVibrator() -> Vibrator! + /// Returns a list of all available vibrator IDs. @JavaMethod open func getVibratorIds() -> [Int32] + /// Turns all the vibrators off. @JavaMethod open func cancel() } diff --git a/Sources/AndroidOS/Violation.swift b/Sources/AndroidOS/Violation.swift index 85d21086..f0fb0213 100644 --- a/Sources/AndroidOS/Violation.swift +++ b/Sources/AndroidOS/Violation.swift @@ -3,11 +3,18 @@ import JavaLang import SwiftJava import CSwiftJavaJNI +/// Base class for all StrictMode violation objects, which extend `Throwable` so they carry a stack +/// trace identifying where the violation occurred. +/// +/// See also: [android.os.strictmode.Violation](https://developer.android.com/reference/android/os/strictmode/Violation) +@available(Android 28, *) @JavaClass("android.os.strictmode.Violation") open class Violation: Throwable { + /// Records the current stack trace into this violation for later inspection. @JavaMethod open override func fillInStackTrace() -> Throwable! + /// Sets the cause of this violation. @JavaMethod open override func initCause(_ arg0: Throwable?) -> Throwable! diff --git a/Sources/AndroidOS/WebViewMethodCalledOnWrongThreadViolation.swift b/Sources/AndroidOS/WebViewMethodCalledOnWrongThreadViolation.swift index 12e7f583..af090361 100644 --- a/Sources/AndroidOS/WebViewMethodCalledOnWrongThreadViolation.swift +++ b/Sources/AndroidOS/WebViewMethodCalledOnWrongThreadViolation.swift @@ -2,6 +2,10 @@ import SwiftJava import CSwiftJavaJNI +/// Violation raised when a `WebView` method is called from a thread other than the main thread. +/// +/// See also: [android.os.strictmode.WebViewMethodCalledOnWrongThreadViolation](https://developer.android.com/reference/android/os/strictmode/WebViewMethodCalledOnWrongThreadViolation) +@available(Android 28, *) @JavaClass("android.os.strictmode.WebViewMethodCalledOnWrongThreadViolation") open class WebViewMethodCalledOnWrongThreadViolation: Violation { diff --git a/Sources/AndroidOS/WorkSource.swift b/Sources/AndroidOS/WorkSource.swift index 33a0d47c..a3c92b9d 100644 --- a/Sources/AndroidOS/WorkSource.swift +++ b/Sources/AndroidOS/WorkSource.swift @@ -2,6 +2,12 @@ import SwiftJava import CSwiftJavaJNI +/// Describes the source of some work that may be done by someone else. +/// +/// Includes sources of wakeups and other types of work, in order to attribute battery usage +/// correctly when doing work on behalf of another app. +/// +/// See also: [android.os.WorkSource](https://developer.android.com/reference/android/os/WorkSource) @JavaClass("android.os.WorkSource", implements: Parcelable.self) open class WorkSource: JavaObject { @JavaMethod From c60cb4320d3bcdf3d6499cf2ab470474f6b8bc88 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Sat, 28 Feb 2026 13:57:52 -0500 Subject: [PATCH 2/7] Update stubs --- Sources/AndroidInput/Syscalls.swift | 682 ++++++++++++++-------------- 1 file changed, 341 insertions(+), 341 deletions(-) diff --git a/Sources/AndroidInput/Syscalls.swift b/Sources/AndroidInput/Syscalls.swift index 51eb4c76..a23d8a6a 100644 --- a/Sources/AndroidInput/Syscalls.swift +++ b/Sources/AndroidInput/Syscalls.swift @@ -169,353 +169,353 @@ let AINPUT_SOURCE_ANY: UInt32 = 0xFFFFFFFF // MARK: - AKeyEvent Constants -let AKEY_EVENT_ACTION_DOWN: Int32 = 0 -let AKEY_EVENT_ACTION_UP: Int32 = 1 -let AKEY_EVENT_ACTION_MULTIPLE: Int32 = 2 +let AKEY_EVENT_ACTION_DOWN: Int = 0 +let AKEY_EVENT_ACTION_UP: Int = 1 +let AKEY_EVENT_ACTION_MULTIPLE: Int = 2 // MARK: - AMotionEvent Constants -let AMOTION_EVENT_ACTION_DOWN: Int32 = 0 -let AMOTION_EVENT_ACTION_UP: Int32 = 1 -let AMOTION_EVENT_ACTION_MOVE: Int32 = 2 -let AMOTION_EVENT_ACTION_CANCEL: Int32 = 3 -let AMOTION_EVENT_ACTION_OUTSIDE: Int32 = 4 -let AMOTION_EVENT_ACTION_POINTER_DOWN: Int32 = 5 -let AMOTION_EVENT_ACTION_POINTER_UP: Int32 = 6 -let AMOTION_EVENT_ACTION_HOVER_MOVE: Int32 = 7 -let AMOTION_EVENT_ACTION_SCROLL: Int32 = 8 -let AMOTION_EVENT_ACTION_HOVER_ENTER: Int32 = 9 -let AMOTION_EVENT_ACTION_HOVER_EXIT: Int32 = 10 -let AMOTION_EVENT_ACTION_BUTTON_PRESS: Int32 = 11 -let AMOTION_EVENT_ACTION_BUTTON_RELEASE: Int32 = 12 - -let AMOTION_EVENT_TOOL_TYPE_UNKNOWN: Int32 = 0 -let AMOTION_EVENT_TOOL_TYPE_FINGER: Int32 = 1 -let AMOTION_EVENT_TOOL_TYPE_STYLUS: Int32 = 2 -let AMOTION_EVENT_TOOL_TYPE_MOUSE: Int32 = 3 -let AMOTION_EVENT_TOOL_TYPE_ERASER: Int32 = 4 +let AMOTION_EVENT_ACTION_DOWN: Int = 0 +let AMOTION_EVENT_ACTION_UP: Int = 1 +let AMOTION_EVENT_ACTION_MOVE: Int = 2 +let AMOTION_EVENT_ACTION_CANCEL: Int = 3 +let AMOTION_EVENT_ACTION_OUTSIDE: Int = 4 +let AMOTION_EVENT_ACTION_POINTER_DOWN: Int = 5 +let AMOTION_EVENT_ACTION_POINTER_UP: Int = 6 +let AMOTION_EVENT_ACTION_HOVER_MOVE: Int = 7 +let AMOTION_EVENT_ACTION_SCROLL: Int = 8 +let AMOTION_EVENT_ACTION_HOVER_ENTER: Int = 9 +let AMOTION_EVENT_ACTION_HOVER_EXIT: Int = 10 +let AMOTION_EVENT_ACTION_BUTTON_PRESS: Int = 11 +let AMOTION_EVENT_ACTION_BUTTON_RELEASE: Int = 12 + +let AMOTION_EVENT_TOOL_TYPE_UNKNOWN: Int = 0 +let AMOTION_EVENT_TOOL_TYPE_FINGER: Int = 1 +let AMOTION_EVENT_TOOL_TYPE_STYLUS: Int = 2 +let AMOTION_EVENT_TOOL_TYPE_MOUSE: Int = 3 +let AMOTION_EVENT_TOOL_TYPE_ERASER: Int = 4 // MARK: - AKEYCODE Constants -let AKEYCODE_UNKNOWN: Int32 = 0 -let AKEYCODE_SOFT_LEFT: Int32 = 1 -let AKEYCODE_SOFT_RIGHT: Int32 = 2 -let AKEYCODE_HOME: Int32 = 3 -let AKEYCODE_BACK: Int32 = 4 -let AKEYCODE_CALL: Int32 = 5 -let AKEYCODE_ENDCALL: Int32 = 6 -let AKEYCODE_0: Int32 = 7 -let AKEYCODE_1: Int32 = 8 -let AKEYCODE_2: Int32 = 9 -let AKEYCODE_3: Int32 = 10 -let AKEYCODE_4: Int32 = 11 -let AKEYCODE_5: Int32 = 12 -let AKEYCODE_6: Int32 = 13 -let AKEYCODE_7: Int32 = 14 -let AKEYCODE_8: Int32 = 15 -let AKEYCODE_9: Int32 = 16 -let AKEYCODE_STAR: Int32 = 17 -let AKEYCODE_POUND: Int32 = 18 -let AKEYCODE_DPAD_UP: Int32 = 19 -let AKEYCODE_DPAD_DOWN: Int32 = 20 -let AKEYCODE_DPAD_LEFT: Int32 = 21 -let AKEYCODE_DPAD_RIGHT: Int32 = 22 -let AKEYCODE_DPAD_CENTER: Int32 = 23 -let AKEYCODE_VOLUME_UP: Int32 = 24 -let AKEYCODE_VOLUME_DOWN: Int32 = 25 -let AKEYCODE_POWER: Int32 = 26 -let AKEYCODE_CAMERA: Int32 = 27 -let AKEYCODE_CLEAR: Int32 = 28 -let AKEYCODE_A: Int32 = 29 -let AKEYCODE_B: Int32 = 30 -let AKEYCODE_C: Int32 = 31 -let AKEYCODE_D: Int32 = 32 -let AKEYCODE_E: Int32 = 33 -let AKEYCODE_F: Int32 = 34 -let AKEYCODE_G: Int32 = 35 -let AKEYCODE_H: Int32 = 36 -let AKEYCODE_I: Int32 = 37 -let AKEYCODE_J: Int32 = 38 -let AKEYCODE_K: Int32 = 39 -let AKEYCODE_L: Int32 = 40 -let AKEYCODE_M: Int32 = 41 -let AKEYCODE_N: Int32 = 42 -let AKEYCODE_O: Int32 = 43 -let AKEYCODE_P: Int32 = 44 -let AKEYCODE_Q: Int32 = 45 -let AKEYCODE_R: Int32 = 46 -let AKEYCODE_S: Int32 = 47 -let AKEYCODE_T: Int32 = 48 -let AKEYCODE_U: Int32 = 49 -let AKEYCODE_V: Int32 = 50 -let AKEYCODE_W: Int32 = 51 -let AKEYCODE_X: Int32 = 52 -let AKEYCODE_Y: Int32 = 53 -let AKEYCODE_Z: Int32 = 54 -let AKEYCODE_COMMA: Int32 = 55 -let AKEYCODE_PERIOD: Int32 = 56 -let AKEYCODE_ALT_LEFT: Int32 = 57 -let AKEYCODE_ALT_RIGHT: Int32 = 58 -let AKEYCODE_SHIFT_LEFT: Int32 = 59 -let AKEYCODE_SHIFT_RIGHT: Int32 = 60 -let AKEYCODE_TAB: Int32 = 61 -let AKEYCODE_SPACE: Int32 = 62 -let AKEYCODE_SYM: Int32 = 63 -let AKEYCODE_EXPLORER: Int32 = 64 -let AKEYCODE_ENVELOPE: Int32 = 65 -let AKEYCODE_ENTER: Int32 = 66 -let AKEYCODE_DEL: Int32 = 67 -let AKEYCODE_GRAVE: Int32 = 68 -let AKEYCODE_MINUS: Int32 = 69 -let AKEYCODE_EQUALS: Int32 = 70 -let AKEYCODE_LEFT_BRACKET: Int32 = 71 -let AKEYCODE_RIGHT_BRACKET: Int32 = 72 -let AKEYCODE_BACKSLASH: Int32 = 73 -let AKEYCODE_SEMICOLON: Int32 = 74 -let AKEYCODE_APOSTROPHE: Int32 = 75 -let AKEYCODE_SLASH: Int32 = 76 -let AKEYCODE_AT: Int32 = 77 -let AKEYCODE_NUM: Int32 = 78 -let AKEYCODE_HEADSETHOOK: Int32 = 79 -let AKEYCODE_FOCUS: Int32 = 80 -let AKEYCODE_PLUS: Int32 = 81 -let AKEYCODE_MENU: Int32 = 82 -let AKEYCODE_NOTIFICATION: Int32 = 83 -let AKEYCODE_SEARCH: Int32 = 84 -let AKEYCODE_MEDIA_PLAY_PAUSE: Int32 = 85 -let AKEYCODE_MEDIA_STOP: Int32 = 86 -let AKEYCODE_MEDIA_NEXT: Int32 = 87 -let AKEYCODE_MEDIA_PREVIOUS: Int32 = 88 -let AKEYCODE_MEDIA_REWIND: Int32 = 89 -let AKEYCODE_MEDIA_FAST_FORWARD: Int32 = 90 -let AKEYCODE_MUTE: Int32 = 91 -let AKEYCODE_PAGE_UP: Int32 = 92 -let AKEYCODE_PAGE_DOWN: Int32 = 93 -let AKEYCODE_PICTSYMBOLS: Int32 = 94 -let AKEYCODE_SWITCH_CHARSET: Int32 = 95 -let AKEYCODE_BUTTON_A: Int32 = 96 -let AKEYCODE_BUTTON_B: Int32 = 97 -let AKEYCODE_BUTTON_C: Int32 = 98 -let AKEYCODE_BUTTON_X: Int32 = 99 -let AKEYCODE_BUTTON_Y: Int32 = 100 -let AKEYCODE_BUTTON_Z: Int32 = 101 -let AKEYCODE_BUTTON_L1: Int32 = 102 -let AKEYCODE_BUTTON_R1: Int32 = 103 -let AKEYCODE_BUTTON_L2: Int32 = 104 -let AKEYCODE_BUTTON_R2: Int32 = 105 -let AKEYCODE_BUTTON_THUMBL: Int32 = 106 -let AKEYCODE_BUTTON_THUMBR: Int32 = 107 -let AKEYCODE_BUTTON_START: Int32 = 108 -let AKEYCODE_BUTTON_SELECT: Int32 = 109 -let AKEYCODE_BUTTON_MODE: Int32 = 110 -let AKEYCODE_ESCAPE: Int32 = 111 -let AKEYCODE_FORWARD_DEL: Int32 = 112 -let AKEYCODE_CTRL_LEFT: Int32 = 113 -let AKEYCODE_CTRL_RIGHT: Int32 = 114 -let AKEYCODE_CAPS_LOCK: Int32 = 115 -let AKEYCODE_SCROLL_LOCK: Int32 = 116 -let AKEYCODE_META_LEFT: Int32 = 117 -let AKEYCODE_META_RIGHT: Int32 = 118 -let AKEYCODE_FUNCTION: Int32 = 119 -let AKEYCODE_SYSRQ: Int32 = 120 -let AKEYCODE_BREAK: Int32 = 121 -let AKEYCODE_MOVE_HOME: Int32 = 122 -let AKEYCODE_MOVE_END: Int32 = 123 -let AKEYCODE_INSERT: Int32 = 124 -let AKEYCODE_FORWARD: Int32 = 125 -let AKEYCODE_MEDIA_PLAY: Int32 = 126 -let AKEYCODE_MEDIA_PAUSE: Int32 = 127 -let AKEYCODE_MEDIA_CLOSE: Int32 = 128 -let AKEYCODE_MEDIA_EJECT: Int32 = 129 -let AKEYCODE_MEDIA_RECORD: Int32 = 130 -let AKEYCODE_F1: Int32 = 131 -let AKEYCODE_F2: Int32 = 132 -let AKEYCODE_F3: Int32 = 133 -let AKEYCODE_F4: Int32 = 134 -let AKEYCODE_F5: Int32 = 135 -let AKEYCODE_F6: Int32 = 136 -let AKEYCODE_F7: Int32 = 137 -let AKEYCODE_F8: Int32 = 138 -let AKEYCODE_F9: Int32 = 139 -let AKEYCODE_F10: Int32 = 140 -let AKEYCODE_F11: Int32 = 141 -let AKEYCODE_F12: Int32 = 142 -let AKEYCODE_NUM_LOCK: Int32 = 143 -let AKEYCODE_NUMPAD_0: Int32 = 144 -let AKEYCODE_NUMPAD_1: Int32 = 145 -let AKEYCODE_NUMPAD_2: Int32 = 146 -let AKEYCODE_NUMPAD_3: Int32 = 147 -let AKEYCODE_NUMPAD_4: Int32 = 148 -let AKEYCODE_NUMPAD_5: Int32 = 149 -let AKEYCODE_NUMPAD_6: Int32 = 150 -let AKEYCODE_NUMPAD_7: Int32 = 151 -let AKEYCODE_NUMPAD_8: Int32 = 152 -let AKEYCODE_NUMPAD_9: Int32 = 153 -let AKEYCODE_NUMPAD_DIVIDE: Int32 = 154 -let AKEYCODE_NUMPAD_MULTIPLY: Int32 = 155 -let AKEYCODE_NUMPAD_SUBTRACT: Int32 = 156 -let AKEYCODE_NUMPAD_ADD: Int32 = 157 -let AKEYCODE_NUMPAD_DOT: Int32 = 158 -let AKEYCODE_NUMPAD_COMMA: Int32 = 159 -let AKEYCODE_NUMPAD_ENTER: Int32 = 160 -let AKEYCODE_NUMPAD_EQUALS: Int32 = 161 -let AKEYCODE_NUMPAD_LEFT_PAREN: Int32 = 162 -let AKEYCODE_NUMPAD_RIGHT_PAREN: Int32 = 163 -let AKEYCODE_VOLUME_MUTE: Int32 = 164 -let AKEYCODE_INFO: Int32 = 165 -let AKEYCODE_CHANNEL_UP: Int32 = 166 -let AKEYCODE_CHANNEL_DOWN: Int32 = 167 -let AKEYCODE_ZOOM_IN: Int32 = 168 -let AKEYCODE_ZOOM_OUT: Int32 = 169 -let AKEYCODE_TV: Int32 = 170 -let AKEYCODE_WINDOW: Int32 = 171 -let AKEYCODE_GUIDE: Int32 = 172 -let AKEYCODE_DVR: Int32 = 173 -let AKEYCODE_BOOKMARK: Int32 = 174 -let AKEYCODE_CAPTIONS: Int32 = 175 -let AKEYCODE_SETTINGS: Int32 = 176 -let AKEYCODE_TV_POWER: Int32 = 177 -let AKEYCODE_TV_INPUT: Int32 = 178 -let AKEYCODE_STB_POWER: Int32 = 179 -let AKEYCODE_STB_INPUT: Int32 = 180 -let AKEYCODE_AVR_POWER: Int32 = 181 -let AKEYCODE_AVR_INPUT: Int32 = 182 -let AKEYCODE_PROG_RED: Int32 = 183 -let AKEYCODE_PROG_GREEN: Int32 = 184 -let AKEYCODE_PROG_YELLOW: Int32 = 185 -let AKEYCODE_PROG_BLUE: Int32 = 186 -let AKEYCODE_APP_SWITCH: Int32 = 187 -let AKEYCODE_BUTTON_1: Int32 = 188 -let AKEYCODE_BUTTON_2: Int32 = 189 -let AKEYCODE_BUTTON_3: Int32 = 190 -let AKEYCODE_BUTTON_4: Int32 = 191 -let AKEYCODE_BUTTON_5: Int32 = 192 -let AKEYCODE_BUTTON_6: Int32 = 193 -let AKEYCODE_BUTTON_7: Int32 = 194 -let AKEYCODE_BUTTON_8: Int32 = 195 -let AKEYCODE_BUTTON_9: Int32 = 196 -let AKEYCODE_BUTTON_10: Int32 = 197 -let AKEYCODE_BUTTON_11: Int32 = 198 -let AKEYCODE_BUTTON_12: Int32 = 199 -let AKEYCODE_BUTTON_13: Int32 = 200 -let AKEYCODE_BUTTON_14: Int32 = 201 -let AKEYCODE_BUTTON_15: Int32 = 202 -let AKEYCODE_BUTTON_16: Int32 = 203 -let AKEYCODE_LANGUAGE_SWITCH: Int32 = 204 -let AKEYCODE_MANNER_MODE: Int32 = 205 -let AKEYCODE_3D_MODE: Int32 = 206 -let AKEYCODE_CONTACTS: Int32 = 207 -let AKEYCODE_CALENDAR: Int32 = 208 -let AKEYCODE_MUSIC: Int32 = 209 -let AKEYCODE_CALCULATOR: Int32 = 210 -let AKEYCODE_ZENKAKU_HANKAKU: Int32 = 211 -let AKEYCODE_EISU: Int32 = 212 -let AKEYCODE_MUHENKAN: Int32 = 213 -let AKEYCODE_HENKAN: Int32 = 214 -let AKEYCODE_KATAKANA_HIRAGANA: Int32 = 215 -let AKEYCODE_YEN: Int32 = 216 -let AKEYCODE_RO: Int32 = 217 -let AKEYCODE_KANA: Int32 = 218 -let AKEYCODE_ASSIST: Int32 = 219 -let AKEYCODE_BRIGHTNESS_DOWN: Int32 = 220 -let AKEYCODE_BRIGHTNESS_UP: Int32 = 221 -let AKEYCODE_MEDIA_AUDIO_TRACK: Int32 = 222 -let AKEYCODE_SLEEP: Int32 = 223 -let AKEYCODE_WAKEUP: Int32 = 224 -let AKEYCODE_PAIRING: Int32 = 225 -let AKEYCODE_MEDIA_TOP_MENU: Int32 = 226 -let AKEYCODE_11: Int32 = 227 -let AKEYCODE_12: Int32 = 228 -let AKEYCODE_LAST_CHANNEL: Int32 = 229 -let AKEYCODE_TV_DATA_SERVICE: Int32 = 230 -let AKEYCODE_VOICE_ASSIST: Int32 = 231 -let AKEYCODE_TV_RADIO_SERVICE: Int32 = 232 -let AKEYCODE_TV_TELETEXT: Int32 = 233 -let AKEYCODE_TV_NUMBER_ENTRY: Int32 = 234 -let AKEYCODE_TV_TERRESTRIAL_ANALOG: Int32 = 235 -let AKEYCODE_TV_TERRESTRIAL_DIGITAL: Int32 = 236 -let AKEYCODE_TV_SATELLITE: Int32 = 237 -let AKEYCODE_TV_SATELLITE_BS: Int32 = 238 -let AKEYCODE_TV_SATELLITE_CS: Int32 = 239 -let AKEYCODE_TV_SATELLITE_SERVICE: Int32 = 240 -let AKEYCODE_TV_NETWORK: Int32 = 241 -let AKEYCODE_TV_ANTENNA_CABLE: Int32 = 242 -let AKEYCODE_TV_INPUT_HDMI_1: Int32 = 243 -let AKEYCODE_TV_INPUT_HDMI_2: Int32 = 244 -let AKEYCODE_TV_INPUT_HDMI_3: Int32 = 245 -let AKEYCODE_TV_INPUT_HDMI_4: Int32 = 246 -let AKEYCODE_TV_INPUT_COMPOSITE_1: Int32 = 247 -let AKEYCODE_TV_INPUT_COMPOSITE_2: Int32 = 248 -let AKEYCODE_TV_INPUT_COMPONENT_1: Int32 = 249 -let AKEYCODE_TV_INPUT_COMPONENT_2: Int32 = 250 -let AKEYCODE_TV_INPUT_VGA_1: Int32 = 251 -let AKEYCODE_TV_AUDIO_DESCRIPTION: Int32 = 252 -let AKEYCODE_TV_AUDIO_DESCRIPTION_MIX_UP: Int32 = 253 -let AKEYCODE_TV_AUDIO_DESCRIPTION_MIX_DOWN: Int32 = 254 -let AKEYCODE_TV_ZOOM_MODE: Int32 = 255 -let AKEYCODE_TV_CONTENTS_MENU: Int32 = 256 -let AKEYCODE_TV_MEDIA_CONTEXT_MENU: Int32 = 257 -let AKEYCODE_TV_TIMER_PROGRAMMING: Int32 = 258 -let AKEYCODE_HELP: Int32 = 259 -let AKEYCODE_NAVIGATE_PREVIOUS: Int32 = 260 -let AKEYCODE_NAVIGATE_NEXT: Int32 = 261 -let AKEYCODE_NAVIGATE_IN: Int32 = 262 -let AKEYCODE_NAVIGATE_OUT: Int32 = 263 -let AKEYCODE_STEM_PRIMARY: Int32 = 264 -let AKEYCODE_STEM_1: Int32 = 265 -let AKEYCODE_STEM_2: Int32 = 266 -let AKEYCODE_STEM_3: Int32 = 267 -let AKEYCODE_DPAD_UP_LEFT: Int32 = 268 -let AKEYCODE_DPAD_DOWN_LEFT: Int32 = 269 -let AKEYCODE_DPAD_UP_RIGHT: Int32 = 270 -let AKEYCODE_DPAD_DOWN_RIGHT: Int32 = 271 -let AKEYCODE_MEDIA_SKIP_FORWARD: Int32 = 272 -let AKEYCODE_MEDIA_SKIP_BACKWARD: Int32 = 273 -let AKEYCODE_MEDIA_STEP_FORWARD: Int32 = 274 -let AKEYCODE_MEDIA_STEP_BACKWARD: Int32 = 275 -let AKEYCODE_SOFT_SLEEP: Int32 = 276 -let AKEYCODE_CUT: Int32 = 277 -let AKEYCODE_COPY: Int32 = 278 -let AKEYCODE_PASTE: Int32 = 279 -let AKEYCODE_SYSTEM_NAVIGATION_UP: Int32 = 280 -let AKEYCODE_SYSTEM_NAVIGATION_DOWN: Int32 = 281 -let AKEYCODE_SYSTEM_NAVIGATION_LEFT: Int32 = 282 -let AKEYCODE_SYSTEM_NAVIGATION_RIGHT: Int32 = 283 -let AKEYCODE_ALL_APPS: Int32 = 284 -let AKEYCODE_REFRESH: Int32 = 285 -let AKEYCODE_THUMBS_UP: Int32 = 286 -let AKEYCODE_THUMBS_DOWN: Int32 = 287 -let AKEYCODE_PROFILE_SWITCH: Int32 = 288 -let AKEYCODE_VIDEO_APP_1: Int32 = 289 -let AKEYCODE_VIDEO_APP_2: Int32 = 290 -let AKEYCODE_VIDEO_APP_3: Int32 = 291 -let AKEYCODE_VIDEO_APP_4: Int32 = 292 -let AKEYCODE_VIDEO_APP_5: Int32 = 293 -let AKEYCODE_VIDEO_APP_6: Int32 = 294 -let AKEYCODE_VIDEO_APP_7: Int32 = 295 -let AKEYCODE_VIDEO_APP_8: Int32 = 296 -let AKEYCODE_FEATURED_APP_1: Int32 = 297 -let AKEYCODE_FEATURED_APP_2: Int32 = 298 -let AKEYCODE_FEATURED_APP_3: Int32 = 299 -let AKEYCODE_FEATURED_APP_4: Int32 = 300 -let AKEYCODE_DEMO_APP_1: Int32 = 301 -let AKEYCODE_DEMO_APP_2: Int32 = 302 -let AKEYCODE_DEMO_APP_3: Int32 = 303 -let AKEYCODE_DEMO_APP_4: Int32 = 304 -let AKEYCODE_KEYBOARD_BACKLIGHT_DOWN: Int32 = 305 -let AKEYCODE_KEYBOARD_BACKLIGHT_UP: Int32 = 306 -let AKEYCODE_KEYBOARD_BACKLIGHT_TOGGLE: Int32 = 307 -let AKEYCODE_STYLUS_BUTTON_PRIMARY: Int32 = 308 -let AKEYCODE_STYLUS_BUTTON_SECONDARY: Int32 = 309 -let AKEYCODE_STYLUS_BUTTON_TERTIARY: Int32 = 310 -let AKEYCODE_STYLUS_BUTTON_TAIL: Int32 = 311 -let AKEYCODE_RECENT_APPS: Int32 = 312 -let AKEYCODE_MACRO_1: Int32 = 313 -let AKEYCODE_MACRO_2: Int32 = 314 -let AKEYCODE_MACRO_3: Int32 = 315 -let AKEYCODE_MACRO_4: Int32 = 316 -let AKEYCODE_EMOJI_PICKER: Int32 = 317 -let AKEYCODE_SCREENSHOT: Int32 = 318 +let AKEYCODE_UNKNOWN: Int = 0 +let AKEYCODE_SOFT_LEFT: Int = 1 +let AKEYCODE_SOFT_RIGHT: Int = 2 +let AKEYCODE_HOME: Int = 3 +let AKEYCODE_BACK: Int = 4 +let AKEYCODE_CALL: Int = 5 +let AKEYCODE_ENDCALL: Int = 6 +let AKEYCODE_0: Int = 7 +let AKEYCODE_1: Int = 8 +let AKEYCODE_2: Int = 9 +let AKEYCODE_3: Int = 10 +let AKEYCODE_4: Int = 11 +let AKEYCODE_5: Int = 12 +let AKEYCODE_6: Int = 13 +let AKEYCODE_7: Int = 14 +let AKEYCODE_8: Int = 15 +let AKEYCODE_9: Int = 16 +let AKEYCODE_STAR: Int = 17 +let AKEYCODE_POUND: Int = 18 +let AKEYCODE_DPAD_UP: Int = 19 +let AKEYCODE_DPAD_DOWN: Int = 20 +let AKEYCODE_DPAD_LEFT: Int = 21 +let AKEYCODE_DPAD_RIGHT: Int = 22 +let AKEYCODE_DPAD_CENTER: Int = 23 +let AKEYCODE_VOLUME_UP: Int = 24 +let AKEYCODE_VOLUME_DOWN: Int = 25 +let AKEYCODE_POWER: Int = 26 +let AKEYCODE_CAMERA: Int = 27 +let AKEYCODE_CLEAR: Int = 28 +let AKEYCODE_A: Int = 29 +let AKEYCODE_B: Int = 30 +let AKEYCODE_C: Int = 31 +let AKEYCODE_D: Int = 32 +let AKEYCODE_E: Int = 33 +let AKEYCODE_F: Int = 34 +let AKEYCODE_G: Int = 35 +let AKEYCODE_H: Int = 36 +let AKEYCODE_I: Int = 37 +let AKEYCODE_J: Int = 38 +let AKEYCODE_K: Int = 39 +let AKEYCODE_L: Int = 40 +let AKEYCODE_M: Int = 41 +let AKEYCODE_N: Int = 42 +let AKEYCODE_O: Int = 43 +let AKEYCODE_P: Int = 44 +let AKEYCODE_Q: Int = 45 +let AKEYCODE_R: Int = 46 +let AKEYCODE_S: Int = 47 +let AKEYCODE_T: Int = 48 +let AKEYCODE_U: Int = 49 +let AKEYCODE_V: Int = 50 +let AKEYCODE_W: Int = 51 +let AKEYCODE_X: Int = 52 +let AKEYCODE_Y: Int = 53 +let AKEYCODE_Z: Int = 54 +let AKEYCODE_COMMA: Int = 55 +let AKEYCODE_PERIOD: Int = 56 +let AKEYCODE_ALT_LEFT: Int = 57 +let AKEYCODE_ALT_RIGHT: Int = 58 +let AKEYCODE_SHIFT_LEFT: Int = 59 +let AKEYCODE_SHIFT_RIGHT: Int = 60 +let AKEYCODE_TAB: Int = 61 +let AKEYCODE_SPACE: Int = 62 +let AKEYCODE_SYM: Int = 63 +let AKEYCODE_EXPLORER: Int = 64 +let AKEYCODE_ENVELOPE: Int = 65 +let AKEYCODE_ENTER: Int = 66 +let AKEYCODE_DEL: Int = 67 +let AKEYCODE_GRAVE: Int = 68 +let AKEYCODE_MINUS: Int = 69 +let AKEYCODE_EQUALS: Int = 70 +let AKEYCODE_LEFT_BRACKET: Int = 71 +let AKEYCODE_RIGHT_BRACKET: Int = 72 +let AKEYCODE_BACKSLASH: Int = 73 +let AKEYCODE_SEMICOLON: Int = 74 +let AKEYCODE_APOSTROPHE: Int = 75 +let AKEYCODE_SLASH: Int = 76 +let AKEYCODE_AT: Int = 77 +let AKEYCODE_NUM: Int = 78 +let AKEYCODE_HEADSETHOOK: Int = 79 +let AKEYCODE_FOCUS: Int = 80 +let AKEYCODE_PLUS: Int = 81 +let AKEYCODE_MENU: Int = 82 +let AKEYCODE_NOTIFICATION: Int = 83 +let AKEYCODE_SEARCH: Int = 84 +let AKEYCODE_MEDIA_PLAY_PAUSE: Int = 85 +let AKEYCODE_MEDIA_STOP: Int = 86 +let AKEYCODE_MEDIA_NEXT: Int = 87 +let AKEYCODE_MEDIA_PREVIOUS: Int = 88 +let AKEYCODE_MEDIA_REWIND: Int = 89 +let AKEYCODE_MEDIA_FAST_FORWARD: Int = 90 +let AKEYCODE_MUTE: Int = 91 +let AKEYCODE_PAGE_UP: Int = 92 +let AKEYCODE_PAGE_DOWN: Int = 93 +let AKEYCODE_PICTSYMBOLS: Int = 94 +let AKEYCODE_SWITCH_CHARSET: Int = 95 +let AKEYCODE_BUTTON_A: Int = 96 +let AKEYCODE_BUTTON_B: Int = 97 +let AKEYCODE_BUTTON_C: Int = 98 +let AKEYCODE_BUTTON_X: Int = 99 +let AKEYCODE_BUTTON_Y: Int = 100 +let AKEYCODE_BUTTON_Z: Int = 101 +let AKEYCODE_BUTTON_L1: Int = 102 +let AKEYCODE_BUTTON_R1: Int = 103 +let AKEYCODE_BUTTON_L2: Int = 104 +let AKEYCODE_BUTTON_R2: Int = 105 +let AKEYCODE_BUTTON_THUMBL: Int = 106 +let AKEYCODE_BUTTON_THUMBR: Int = 107 +let AKEYCODE_BUTTON_START: Int = 108 +let AKEYCODE_BUTTON_SELECT: Int = 109 +let AKEYCODE_BUTTON_MODE: Int = 110 +let AKEYCODE_ESCAPE: Int = 111 +let AKEYCODE_FORWARD_DEL: Int = 112 +let AKEYCODE_CTRL_LEFT: Int = 113 +let AKEYCODE_CTRL_RIGHT: Int = 114 +let AKEYCODE_CAPS_LOCK: Int = 115 +let AKEYCODE_SCROLL_LOCK: Int = 116 +let AKEYCODE_META_LEFT: Int = 117 +let AKEYCODE_META_RIGHT: Int = 118 +let AKEYCODE_FUNCTION: Int = 119 +let AKEYCODE_SYSRQ: Int = 120 +let AKEYCODE_BREAK: Int = 121 +let AKEYCODE_MOVE_HOME: Int = 122 +let AKEYCODE_MOVE_END: Int = 123 +let AKEYCODE_INSERT: Int = 124 +let AKEYCODE_FORWARD: Int = 125 +let AKEYCODE_MEDIA_PLAY: Int = 126 +let AKEYCODE_MEDIA_PAUSE: Int = 127 +let AKEYCODE_MEDIA_CLOSE: Int = 128 +let AKEYCODE_MEDIA_EJECT: Int = 129 +let AKEYCODE_MEDIA_RECORD: Int = 130 +let AKEYCODE_F1: Int = 131 +let AKEYCODE_F2: Int = 132 +let AKEYCODE_F3: Int = 133 +let AKEYCODE_F4: Int = 134 +let AKEYCODE_F5: Int = 135 +let AKEYCODE_F6: Int = 136 +let AKEYCODE_F7: Int = 137 +let AKEYCODE_F8: Int = 138 +let AKEYCODE_F9: Int = 139 +let AKEYCODE_F10: Int = 140 +let AKEYCODE_F11: Int = 141 +let AKEYCODE_F12: Int = 142 +let AKEYCODE_NUM_LOCK: Int = 143 +let AKEYCODE_NUMPAD_0: Int = 144 +let AKEYCODE_NUMPAD_1: Int = 145 +let AKEYCODE_NUMPAD_2: Int = 146 +let AKEYCODE_NUMPAD_3: Int = 147 +let AKEYCODE_NUMPAD_4: Int = 148 +let AKEYCODE_NUMPAD_5: Int = 149 +let AKEYCODE_NUMPAD_6: Int = 150 +let AKEYCODE_NUMPAD_7: Int = 151 +let AKEYCODE_NUMPAD_8: Int = 152 +let AKEYCODE_NUMPAD_9: Int = 153 +let AKEYCODE_NUMPAD_DIVIDE: Int = 154 +let AKEYCODE_NUMPAD_MULTIPLY: Int = 155 +let AKEYCODE_NUMPAD_SUBTRACT: Int = 156 +let AKEYCODE_NUMPAD_ADD: Int = 157 +let AKEYCODE_NUMPAD_DOT: Int = 158 +let AKEYCODE_NUMPAD_COMMA: Int = 159 +let AKEYCODE_NUMPAD_ENTER: Int = 160 +let AKEYCODE_NUMPAD_EQUALS: Int = 161 +let AKEYCODE_NUMPAD_LEFT_PAREN: Int = 162 +let AKEYCODE_NUMPAD_RIGHT_PAREN: Int = 163 +let AKEYCODE_VOLUME_MUTE: Int = 164 +let AKEYCODE_INFO: Int = 165 +let AKEYCODE_CHANNEL_UP: Int = 166 +let AKEYCODE_CHANNEL_DOWN: Int = 167 +let AKEYCODE_ZOOM_IN: Int = 168 +let AKEYCODE_ZOOM_OUT: Int = 169 +let AKEYCODE_TV: Int = 170 +let AKEYCODE_WINDOW: Int = 171 +let AKEYCODE_GUIDE: Int = 172 +let AKEYCODE_DVR: Int = 173 +let AKEYCODE_BOOKMARK: Int = 174 +let AKEYCODE_CAPTIONS: Int = 175 +let AKEYCODE_SETTINGS: Int = 176 +let AKEYCODE_TV_POWER: Int = 177 +let AKEYCODE_TV_INPUT: Int = 178 +let AKEYCODE_STB_POWER: Int = 179 +let AKEYCODE_STB_INPUT: Int = 180 +let AKEYCODE_AVR_POWER: Int = 181 +let AKEYCODE_AVR_INPUT: Int = 182 +let AKEYCODE_PROG_RED: Int = 183 +let AKEYCODE_PROG_GREEN: Int = 184 +let AKEYCODE_PROG_YELLOW: Int = 185 +let AKEYCODE_PROG_BLUE: Int = 186 +let AKEYCODE_APP_SWITCH: Int = 187 +let AKEYCODE_BUTTON_1: Int = 188 +let AKEYCODE_BUTTON_2: Int = 189 +let AKEYCODE_BUTTON_3: Int = 190 +let AKEYCODE_BUTTON_4: Int = 191 +let AKEYCODE_BUTTON_5: Int = 192 +let AKEYCODE_BUTTON_6: Int = 193 +let AKEYCODE_BUTTON_7: Int = 194 +let AKEYCODE_BUTTON_8: Int = 195 +let AKEYCODE_BUTTON_9: Int = 196 +let AKEYCODE_BUTTON_10: Int = 197 +let AKEYCODE_BUTTON_11: Int = 198 +let AKEYCODE_BUTTON_12: Int = 199 +let AKEYCODE_BUTTON_13: Int = 200 +let AKEYCODE_BUTTON_14: Int = 201 +let AKEYCODE_BUTTON_15: Int = 202 +let AKEYCODE_BUTTON_16: Int = 203 +let AKEYCODE_LANGUAGE_SWITCH: Int = 204 +let AKEYCODE_MANNER_MODE: Int = 205 +let AKEYCODE_3D_MODE: Int = 206 +let AKEYCODE_CONTACTS: Int = 207 +let AKEYCODE_CALENDAR: Int = 208 +let AKEYCODE_MUSIC: Int = 209 +let AKEYCODE_CALCULATOR: Int = 210 +let AKEYCODE_ZENKAKU_HANKAKU: Int = 211 +let AKEYCODE_EISU: Int = 212 +let AKEYCODE_MUHENKAN: Int = 213 +let AKEYCODE_HENKAN: Int = 214 +let AKEYCODE_KATAKANA_HIRAGANA: Int = 215 +let AKEYCODE_YEN: Int = 216 +let AKEYCODE_RO: Int = 217 +let AKEYCODE_KANA: Int = 218 +let AKEYCODE_ASSIST: Int = 219 +let AKEYCODE_BRIGHTNESS_DOWN: Int = 220 +let AKEYCODE_BRIGHTNESS_UP: Int = 221 +let AKEYCODE_MEDIA_AUDIO_TRACK: Int = 222 +let AKEYCODE_SLEEP: Int = 223 +let AKEYCODE_WAKEUP: Int = 224 +let AKEYCODE_PAIRING: Int = 225 +let AKEYCODE_MEDIA_TOP_MENU: Int = 226 +let AKEYCODE_11: Int = 227 +let AKEYCODE_12: Int = 228 +let AKEYCODE_LAST_CHANNEL: Int = 229 +let AKEYCODE_TV_DATA_SERVICE: Int = 230 +let AKEYCODE_VOICE_ASSIST: Int = 231 +let AKEYCODE_TV_RADIO_SERVICE: Int = 232 +let AKEYCODE_TV_TELETEXT: Int = 233 +let AKEYCODE_TV_NUMBER_ENTRY: Int = 234 +let AKEYCODE_TV_TERRESTRIAL_ANALOG: Int = 235 +let AKEYCODE_TV_TERRESTRIAL_DIGITAL: Int = 236 +let AKEYCODE_TV_SATELLITE: Int = 237 +let AKEYCODE_TV_SATELLITE_BS: Int = 238 +let AKEYCODE_TV_SATELLITE_CS: Int = 239 +let AKEYCODE_TV_SATELLITE_SERVICE: Int = 240 +let AKEYCODE_TV_NETWORK: Int = 241 +let AKEYCODE_TV_ANTENNA_CABLE: Int = 242 +let AKEYCODE_TV_INPUT_HDMI_1: Int = 243 +let AKEYCODE_TV_INPUT_HDMI_2: Int = 244 +let AKEYCODE_TV_INPUT_HDMI_3: Int = 245 +let AKEYCODE_TV_INPUT_HDMI_4: Int = 246 +let AKEYCODE_TV_INPUT_COMPOSITE_1: Int = 247 +let AKEYCODE_TV_INPUT_COMPOSITE_2: Int = 248 +let AKEYCODE_TV_INPUT_COMPONENT_1: Int = 249 +let AKEYCODE_TV_INPUT_COMPONENT_2: Int = 250 +let AKEYCODE_TV_INPUT_VGA_1: Int = 251 +let AKEYCODE_TV_AUDIO_DESCRIPTION: Int = 252 +let AKEYCODE_TV_AUDIO_DESCRIPTION_MIX_UP: Int = 253 +let AKEYCODE_TV_AUDIO_DESCRIPTION_MIX_DOWN: Int = 254 +let AKEYCODE_TV_ZOOM_MODE: Int = 255 +let AKEYCODE_TV_CONTENTS_MENU: Int = 256 +let AKEYCODE_TV_MEDIA_CONTEXT_MENU: Int = 257 +let AKEYCODE_TV_TIMER_PROGRAMMING: Int = 258 +let AKEYCODE_HELP: Int = 259 +let AKEYCODE_NAVIGATE_PREVIOUS: Int = 260 +let AKEYCODE_NAVIGATE_NEXT: Int = 261 +let AKEYCODE_NAVIGATE_IN: Int = 262 +let AKEYCODE_NAVIGATE_OUT: Int = 263 +let AKEYCODE_STEM_PRIMARY: Int = 264 +let AKEYCODE_STEM_1: Int = 265 +let AKEYCODE_STEM_2: Int = 266 +let AKEYCODE_STEM_3: Int = 267 +let AKEYCODE_DPAD_UP_LEFT: Int = 268 +let AKEYCODE_DPAD_DOWN_LEFT: Int = 269 +let AKEYCODE_DPAD_UP_RIGHT: Int = 270 +let AKEYCODE_DPAD_DOWN_RIGHT: Int = 271 +let AKEYCODE_MEDIA_SKIP_FORWARD: Int = 272 +let AKEYCODE_MEDIA_SKIP_BACKWARD: Int = 273 +let AKEYCODE_MEDIA_STEP_FORWARD: Int = 274 +let AKEYCODE_MEDIA_STEP_BACKWARD: Int = 275 +let AKEYCODE_SOFT_SLEEP: Int = 276 +let AKEYCODE_CUT: Int = 277 +let AKEYCODE_COPY: Int = 278 +let AKEYCODE_PASTE: Int = 279 +let AKEYCODE_SYSTEM_NAVIGATION_UP: Int = 280 +let AKEYCODE_SYSTEM_NAVIGATION_DOWN: Int = 281 +let AKEYCODE_SYSTEM_NAVIGATION_LEFT: Int = 282 +let AKEYCODE_SYSTEM_NAVIGATION_RIGHT: Int = 283 +let AKEYCODE_ALL_APPS: Int = 284 +let AKEYCODE_REFRESH: Int = 285 +let AKEYCODE_THUMBS_UP: Int = 286 +let AKEYCODE_THUMBS_DOWN: Int = 287 +let AKEYCODE_PROFILE_SWITCH: Int = 288 +let AKEYCODE_VIDEO_APP_1: Int = 289 +let AKEYCODE_VIDEO_APP_2: Int = 290 +let AKEYCODE_VIDEO_APP_3: Int = 291 +let AKEYCODE_VIDEO_APP_4: Int = 292 +let AKEYCODE_VIDEO_APP_5: Int = 293 +let AKEYCODE_VIDEO_APP_6: Int = 294 +let AKEYCODE_VIDEO_APP_7: Int = 295 +let AKEYCODE_VIDEO_APP_8: Int = 296 +let AKEYCODE_FEATURED_APP_1: Int = 297 +let AKEYCODE_FEATURED_APP_2: Int = 298 +let AKEYCODE_FEATURED_APP_3: Int = 299 +let AKEYCODE_FEATURED_APP_4: Int = 300 +let AKEYCODE_DEMO_APP_1: Int = 301 +let AKEYCODE_DEMO_APP_2: Int = 302 +let AKEYCODE_DEMO_APP_3: Int = 303 +let AKEYCODE_DEMO_APP_4: Int = 304 +let AKEYCODE_KEYBOARD_BACKLIGHT_DOWN: Int = 305 +let AKEYCODE_KEYBOARD_BACKLIGHT_UP: Int = 306 +let AKEYCODE_KEYBOARD_BACKLIGHT_TOGGLE: Int = 307 +let AKEYCODE_STYLUS_BUTTON_PRIMARY: Int = 308 +let AKEYCODE_STYLUS_BUTTON_SECONDARY: Int = 309 +let AKEYCODE_STYLUS_BUTTON_TERTIARY: Int = 310 +let AKEYCODE_STYLUS_BUTTON_TAIL: Int = 311 +let AKEYCODE_RECENT_APPS: Int = 312 +let AKEYCODE_MACRO_1: Int = 313 +let AKEYCODE_MACRO_2: Int = 314 +let AKEYCODE_MACRO_3: Int = 315 +let AKEYCODE_MACRO_4: Int = 316 +let AKEYCODE_EMOJI_PICKER: Int = 317 +let AKEYCODE_SCREENSHOT: Int = 318 // MARK: - JNI Types From 24763eea9970ec6a7b3915791139420c3217560b Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Sat, 28 Feb 2026 14:22:20 -0500 Subject: [PATCH 3/7] Add deprecated annotations --- Sources/AndroidOS/Build+VERSION.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/AndroidOS/Build+VERSION.swift b/Sources/AndroidOS/Build+VERSION.swift index fa0566f6..6772968a 100644 --- a/Sources/AndroidOS/Build+VERSION.swift +++ b/Sources/AndroidOS/Build+VERSION.swift @@ -62,6 +62,7 @@ extension JavaClass { /// The user-visible SDK version of the framework in its raw String representation. /// /// - Note: Deprecated since API 15. Use `SDK_INT` instead. + @available(*, deprecated, message: "Use `SDK_INT` instead.") @JavaStaticField(isFinal: true) public var SDK: String From b00623db718c395ceb5b67d75ce7be4f008fee1c Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Sat, 28 Feb 2026 14:23:20 -0500 Subject: [PATCH 4/7] Add availability annotations --- Sources/AndroidOS/AndroidAPI.swift | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/Sources/AndroidOS/AndroidAPI.swift b/Sources/AndroidOS/AndroidAPI.swift index 3a2349ce..bd0d3bb4 100644 --- a/Sources/AndroidOS/AndroidAPI.swift +++ b/Sources/AndroidOS/AndroidAPI.swift @@ -34,16 +34,27 @@ public extension AndroidAPI { internal extension AndroidAPI { - static func deviceAPILevel() throws -> Int32 { - #if os(Android) && canImport(CAndroidNDK) - try ndkValue().get() - #else - try jniValue() - #endif + /** + Returns the targetSdkVersion of the caller, or __ANDROID_API_FUTURE__ if there is no known target SDK version (for code not running in the context of an app). + + The returned value is the same as the AndroidManifest.xml targetSdkVersion. This is mostly useful for the OS to decide what behavior an app is expecting. See also android_get_device_api_level(). + + Available since API level 24. Returns the API level of the device we're actually running on, or -1 on failure. + + The returned value is the same as the Java Build.VERSION.SDK_INT. This is mostly useful for an app to work out what version of the OS it's running on. See also android_get_application_target_sdk_version(). + + Available since API level 29. + */ + static func deviceAPILevel() throws(Throwable) -> Int32 { + if #available(Android 24, *) { + try ndkValue().get() + } else { + try jniValue() + } } /// `Build.VERSION.SDK_INT` - static func jniValue() throws -> Int32 { + static func jniValue() throws(Throwable) -> Int32 { do { let javaClass = try JavaClass.init() return javaClass.SDK_INT From 0a41cd8d2c20122abb45eda3fc4279fa0df9101d Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Sat, 28 Feb 2026 14:40:51 -0500 Subject: [PATCH 5/7] Add availability annotations --- Sources/AndroidOS/BugreportManager+BugreportCallback.swift | 3 +++ Sources/AndroidOS/Build+Partition.swift | 2 ++ Sources/AndroidOS/CombinedVibration+ParallelCombination.swift | 1 + Sources/AndroidOS/CombinedVibration.swift | 2 ++ Sources/AndroidOS/PerformanceHintManager+Session.swift | 1 + Sources/AndroidOS/SdkExtensions.swift | 2 ++ Sources/AndroidOS/StorageManager.swift | 1 + Sources/AndroidOS/VibrationAttributes+Builder.swift | 1 + 8 files changed, 13 insertions(+) diff --git a/Sources/AndroidOS/BugreportManager+BugreportCallback.swift b/Sources/AndroidOS/BugreportManager+BugreportCallback.swift index c9425a0a..b4b9a716 100644 --- a/Sources/AndroidOS/BugreportManager+BugreportCallback.swift +++ b/Sources/AndroidOS/BugreportManager+BugreportCallback.swift @@ -2,6 +2,7 @@ import SwiftJava import CSwiftJavaJNI +@available(Android 29, *) extension BugreportManager { /// Callback for receiving progress and completion notifications during bug report collection. /// @@ -31,6 +32,8 @@ extension BugreportManager { open func onEarlyReportFinished() } } + +@available(Android 29, *) extension JavaClass { @JavaStaticField(isFinal: true) public var BUGREPORT_ERROR_ANOTHER_REPORT_IN_PROGRESS: Int32 diff --git a/Sources/AndroidOS/Build+Partition.swift b/Sources/AndroidOS/Build+Partition.swift index e6b7546a..784d0cc0 100644 --- a/Sources/AndroidOS/Build+Partition.swift +++ b/Sources/AndroidOS/Build+Partition.swift @@ -28,6 +28,8 @@ extension Build { open override func hashCode() -> Int32 } } + +@available(Android 29, *) extension JavaClass { /// The name of the system partition. @JavaStaticField(isFinal: true) diff --git a/Sources/AndroidOS/CombinedVibration+ParallelCombination.swift b/Sources/AndroidOS/CombinedVibration+ParallelCombination.swift index f84053b1..c24cf6e8 100644 --- a/Sources/AndroidOS/CombinedVibration+ParallelCombination.swift +++ b/Sources/AndroidOS/CombinedVibration+ParallelCombination.swift @@ -2,6 +2,7 @@ import SwiftJava import CSwiftJavaJNI +@available(Android 31, *) extension CombinedVibration { /// A combination of vibration effects that are performed by different vibrators in parallel. /// diff --git a/Sources/AndroidOS/CombinedVibration.swift b/Sources/AndroidOS/CombinedVibration.swift index 1688ce4a..d1d1287d 100644 --- a/Sources/AndroidOS/CombinedVibration.swift +++ b/Sources/AndroidOS/CombinedVibration.swift @@ -14,6 +14,8 @@ open class CombinedVibration: JavaObject { @JavaMethod open func describeContents() -> Int32 } + +@available(Android 31, *) extension JavaClass { @JavaStaticField(isFinal: true) public var CREATOR: Parcelable.Creator! diff --git a/Sources/AndroidOS/PerformanceHintManager+Session.swift b/Sources/AndroidOS/PerformanceHintManager+Session.swift index c806273b..fe966f99 100644 --- a/Sources/AndroidOS/PerformanceHintManager+Session.swift +++ b/Sources/AndroidOS/PerformanceHintManager+Session.swift @@ -4,6 +4,7 @@ import JavaLangIO import SwiftJava import CSwiftJavaJNI +@available(Android 31, *) extension PerformanceHintManager { /// A hint session for a set of threads, used to report work durations to the system. /// diff --git a/Sources/AndroidOS/SdkExtensions.swift b/Sources/AndroidOS/SdkExtensions.swift index 99710fea..5ab76529 100644 --- a/Sources/AndroidOS/SdkExtensions.swift +++ b/Sources/AndroidOS/SdkExtensions.swift @@ -16,6 +16,8 @@ import CSwiftJavaJNI open class SdkExtensions: JavaObject { } + +@available(Android 30, *) extension JavaClass { /// Returns the extension version for the given SDK integer, or `0` if the extension /// is not present on this device. diff --git a/Sources/AndroidOS/StorageManager.swift b/Sources/AndroidOS/StorageManager.swift index e4ae35dc..7214cc06 100644 --- a/Sources/AndroidOS/StorageManager.swift +++ b/Sources/AndroidOS/StorageManager.swift @@ -12,6 +12,7 @@ import CSwiftJavaJNI @JavaClass("android.os.storage.StorageManager") open class StorageManager: JavaObject { /// Unregisters a previously registered `StorageVolumeCallback`. + @available(Android 30, *) @JavaMethod open func unregisterStorageVolumeCallback(_ arg0: StorageManager.StorageVolumeCallback?) diff --git a/Sources/AndroidOS/VibrationAttributes+Builder.swift b/Sources/AndroidOS/VibrationAttributes+Builder.swift index a86ddf1d..b144dcef 100644 --- a/Sources/AndroidOS/VibrationAttributes+Builder.swift +++ b/Sources/AndroidOS/VibrationAttributes+Builder.swift @@ -2,6 +2,7 @@ import SwiftJava import CSwiftJavaJNI +@available(Android 30, *) extension VibrationAttributes { /// Builder class for `VibrationAttributes` objects. /// From 64660892d57b585a8271517b67e9c9cf8cacb3c1 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Sat, 28 Feb 2026 14:41:04 -0500 Subject: [PATCH 6/7] Fix compilation error --- Sources/AndroidOS/AndroidAPI.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/AndroidOS/AndroidAPI.swift b/Sources/AndroidOS/AndroidAPI.swift index bd0d3bb4..bef2548a 100644 --- a/Sources/AndroidOS/AndroidAPI.swift +++ b/Sources/AndroidOS/AndroidAPI.swift @@ -45,7 +45,7 @@ internal extension AndroidAPI { Available since API level 29. */ - static func deviceAPILevel() throws(Throwable) -> Int32 { + static func deviceAPILevel() throws -> Int32 { if #available(Android 24, *) { try ndkValue().get() } else { @@ -54,7 +54,7 @@ internal extension AndroidAPI { } /// `Build.VERSION.SDK_INT` - static func jniValue() throws(Throwable) -> Int32 { + static func jniValue() throws -> Int32 { do { let javaClass = try JavaClass.init() return javaClass.SDK_INT From 5aea2d0509761b9ff9d3e415aa0472294a274682 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Sat, 28 Feb 2026 14:45:21 -0500 Subject: [PATCH 7/7] Add availability annotations --- Sources/AndroidOS/VibrationAttributes.swift | 2 ++ Sources/AndroidOS/VibrationEffect+Composition.swift | 3 +++ Sources/AndroidView/InputDevice.swift | 1 + 3 files changed, 6 insertions(+) diff --git a/Sources/AndroidOS/VibrationAttributes.swift b/Sources/AndroidOS/VibrationAttributes.swift index 736614a4..d3218f46 100644 --- a/Sources/AndroidOS/VibrationAttributes.swift +++ b/Sources/AndroidOS/VibrationAttributes.swift @@ -49,6 +49,8 @@ open class VibrationAttributes: JavaObject { @JavaMethod open func getFlags() -> Int32 } + +@available(Android 30, *) extension JavaClass { @JavaStaticField(isFinal: true) public var CREATOR: Parcelable.Creator! diff --git a/Sources/AndroidOS/VibrationEffect+Composition.swift b/Sources/AndroidOS/VibrationEffect+Composition.swift index 5c377d88..905ab335 100644 --- a/Sources/AndroidOS/VibrationEffect+Composition.swift +++ b/Sources/AndroidOS/VibrationEffect+Composition.swift @@ -2,6 +2,7 @@ import SwiftJava import CSwiftJavaJNI +@available(Android 30, *) extension VibrationEffect { /// A composition of haptic primitives that, when combined, create more complex haptic patterns. /// @@ -43,6 +44,8 @@ extension VibrationEffect { open func compose() -> VibrationEffect! } } + +@available(Android 30, *) extension JavaClass { /// Primitive: a brief, standard feedback effect (click). @JavaStaticField(isFinal: true) diff --git a/Sources/AndroidView/InputDevice.swift b/Sources/AndroidView/InputDevice.swift index 2c19cda5..1a73a8e7 100644 --- a/Sources/AndroidView/InputDevice.swift +++ b/Sources/AndroidView/InputDevice.swift @@ -53,6 +53,7 @@ open class InputDevice: JavaObject { @JavaMethod open func getVibrator() -> Vibrator! + @available(Android 31, *) @JavaMethod open func getVibratorManager() -> VibratorManager!