react-native-device-secure-info 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +175 -0
  2. package/android/app/build.gradle +119 -0
  3. package/android/app/debug.keystore +0 -0
  4. package/android/app/proguard-rules.pro +10 -0
  5. package/android/app/src/debug/AndroidManifest.xml +9 -0
  6. package/android/app/src/main/AndroidManifest.xml +26 -0
  7. package/android/app/src/main/java/com/reactnativedevicesecureinfo/DeviceSecureInfoModule.kt +167 -0
  8. package/android/app/src/main/java/com/reactnativedevicesecureinfo/DeviceSecureInfoPackage.kt +22 -0
  9. package/android/app/src/main/java/com/reactnativedevicesecureinfo/DeviceSecureInfoTurboModule.kt +169 -0
  10. package/android/app/src/main/java/com/reactnativedevicesecureinfo/DeviceSecureInfoTurboPackage.kt +46 -0
  11. package/android/app/src/main/java/com/reactnativedevicesecureinfo/MainActivity.kt +22 -0
  12. package/android/app/src/main/java/com/reactnativedevicesecureinfo/MainApplication.kt +49 -0
  13. package/android/app/src/main/res/drawable/rn_edit_text_material.xml +37 -0
  14. package/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
  15. package/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
  16. package/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
  17. package/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
  18. package/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
  19. package/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
  20. package/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
  21. package/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
  22. package/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
  23. package/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
  24. package/android/app/src/main/res/values/strings.xml +3 -0
  25. package/android/app/src/main/res/values/styles.xml +9 -0
  26. package/android/build.gradle +21 -0
  27. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  28. package/android/gradle/wrapper/gradle-wrapper.properties +7 -0
  29. package/android/gradle.properties +39 -0
  30. package/android/gradlew +251 -0
  31. package/android/gradlew.bat +94 -0
  32. package/android/settings.gradle +6 -0
  33. package/ios/.xcode.env +11 -0
  34. package/ios/.xcode.env.local +1 -0
  35. package/ios/DeviceSecureInfoModule.h +7 -0
  36. package/ios/DeviceSecureInfoModule.m +217 -0
  37. package/ios/DeviceSecureInfoTurboModule.h +19 -0
  38. package/ios/DeviceSecureInfoTurboModule.mm +230 -0
  39. package/ios/Podfile +35 -0
  40. package/ios/ReactNativeDeviceSecureInfo/AppDelegate.swift +30 -0
  41. package/ios/ReactNativeDeviceSecureInfo/Images.xcassets/AppIcon.appiconset/Contents.json +53 -0
  42. package/ios/ReactNativeDeviceSecureInfo/Images.xcassets/Contents.json +6 -0
  43. package/ios/ReactNativeDeviceSecureInfo/Info.plist +52 -0
  44. package/ios/ReactNativeDeviceSecureInfo/LaunchScreen.storyboard +47 -0
  45. package/ios/ReactNativeDeviceSecureInfo/PrivacyInfo.xcprivacy +37 -0
  46. package/ios/ReactNativeDeviceSecureInfo-Bridging-Header.h +4 -0
  47. package/ios/ReactNativeDeviceSecureInfo.xcodeproj/project.pbxproj +504 -0
  48. package/ios/ReactNativeDeviceSecureInfo.xcodeproj/xcshareddata/xcschemes/ReactNativeDeviceSecureInfo.xcscheme +88 -0
  49. package/ios/ReactNativeDeviceSecureInfo.xcworkspace/contents.xcworkspacedata +10 -0
  50. package/ios/ReactNativeDeviceSecureInfo.xcworkspace/xcuserdata/dengbin.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  51. package/package.json +77 -0
  52. package/react-native-device-secure-info.podspec +20 -0
  53. package/react-native.config.js +13 -0
  54. package/src/NativeDeviceSecureInfo.ts +67 -0
  55. package/src/assets/image.png +0 -0
  56. package/src/index.ts +90 -0
@@ -0,0 +1,20 @@
1
+ require 'json'
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = "react-native-device-secure-info"
7
+ s.version = package['version']
8
+ s.summary = package['description']
9
+ s.homepage = package['repository']['url']
10
+ s.license = package['license']
11
+ s.authors = package['author']
12
+ s.platforms = { ios: '13.4' }
13
+ s.source = { git: package['repository']['url'], tag: s.version.to_s }
14
+
15
+ # 源文件路径
16
+ s.source_files = "ios/**/*.{h,m,mm,swift}"
17
+
18
+ # 如果新架构启用,安装 codegen 相关依赖
19
+ install_modules_dependencies(s)
20
+ end
@@ -0,0 +1,13 @@
1
+ module.exports = {
2
+ dependency: {
3
+ platforms: {
4
+ android: {
5
+ sourceDir: './android',
6
+ packageImportPath: 'import com.reactnativedevicesecureinfo.DeviceSecureInfoPackage;',
7
+ },
8
+ ios: {
9
+ podspecPath: './react-native-device-secure-info.podspec',
10
+ },
11
+ },
12
+ },
13
+ };
@@ -0,0 +1,67 @@
1
+ // NativeDeviceSecureInfo.ts
2
+ // RN 新架构 TurboModule Spec 定义
3
+ // 文件名必须以 Native 开头,用于 Codegen 自动生成接口代码
4
+
5
+ import type { TurboModule } from 'react-native';
6
+ import { TurboModuleRegistry } from 'react-native';
7
+
8
+ /**
9
+ * 设备安全信息接口(Codegen 要求返回类型必须显式定义)
10
+ */
11
+ export interface DeviceSecureInfo {
12
+ // ---- 基础设备信息 ----
13
+ /** 设备名称(如 "iPhone 15 Pro") */
14
+ deviceName: string;
15
+ /** 系统版本号(如 "17.4.1" / "14") */
16
+ systemVersion: string;
17
+ /** 设备品牌(如 "Apple" / "Samsung") */
18
+ brand: string;
19
+ /** 制造商(如 "Apple" / "Xiaomi") */
20
+ manufacturer: string;
21
+ /** 设备唯一标识(iOS: identifierForVendor, Android: ANDROID_ID) */
22
+ deviceId: string;
23
+ /** 运营商名称(如 "中国移动") */
24
+ carrierName: string;
25
+ /** SDK 版本号 */
26
+ sdkVersion: number;
27
+ /** 设备型号(如 "iPhone14,2" / "oriole") */
28
+ deviceModel: string;
29
+ /** 系统名称(如 "iOS" / "Android") */
30
+ systemName: string;
31
+
32
+ // ---- 内存信息 ----
33
+ /** 总内存(字节) */
34
+ totalMemory: number;
35
+ /** 可用内存(字节) */
36
+ availableMemory: number;
37
+ /** 已使用内存(字节) */
38
+ usedMemory: number;
39
+ /** 内存使用百分比 */
40
+ memoryUsagePercent: number;
41
+
42
+ // ---- CPU 信息 ----
43
+ /** CPU 架构(如 "arm64-v8a"、"arm64e"、"arm64") */
44
+ cpuArchitecture: string;
45
+ /** CPU 核心数 */
46
+ cpuCores: number;
47
+ /** CPU 使用率百分比 */
48
+ cpuUsagePercent: number;
49
+
50
+ // ---- 电池信息 ----
51
+ /** 电池电量百分比(0-100,-1 表示未知) */
52
+ batteryLevel: number;
53
+ /** 电池状态("charging" / "discharging" / "full" / "unknown") */
54
+ batteryState: string;
55
+ /** 是否正在充电 */
56
+ isCharging: boolean;
57
+ }
58
+
59
+ /**
60
+ * TurboModule 规范接口
61
+ * 新架构下由 Codegen 生成对应的原生接口
62
+ */
63
+ export interface Spec extends TurboModule {
64
+ getDeviceInfo(): Promise<DeviceSecureInfo>;
65
+ }
66
+
67
+ export default TurboModuleRegistry.getEnforcing<Spec>('DeviceSecureInfoModule');
Binary file
package/src/index.ts ADDED
@@ -0,0 +1,90 @@
1
+ /**
2
+ * react-native-device-secure-info
3
+ *
4
+ * 获取设备安全信息的 React Native 原生模块
5
+ * 同时支持新架构(TurboModule)和旧架构(Bridge)
6
+ *
7
+ * 使用方式:
8
+ * ```ts
9
+ * import { getDeviceInfo } from 'react-native-device-secure-info';
10
+ *
11
+ * const info = await getDeviceInfo();
12
+ * console.log(info.deviceName, info.batteryLevel);
13
+ * ```
14
+ */
15
+
16
+ import { NativeModules, Platform } from 'react-native';
17
+ import type { DeviceSecureInfo } from './NativeDeviceSecureInfo';
18
+
19
+ // 导出类型供外部使用
20
+ export type { DeviceSecureInfo } from './NativeDeviceSecureInfo';
21
+
22
+ // ===================================================================
23
+ // 自动选择模块:优先新架构 TurboModule,回退旧架构 Bridge
24
+ // ===================================================================
25
+
26
+ const isTurboModuleEnabled = !!(global as any).__turboModuleProxy;
27
+
28
+ /**
29
+ * 获取原生模块实例
30
+ * - 新架构:通过 TurboModuleRegistry 获取(import 时自动触发)
31
+ * - 旧架构:通过 NativeModules.DeviceSecureInfoModule 获取
32
+ */
33
+ function getDeviceSecureInfoModule() {
34
+ if (isTurboModuleEnabled) {
35
+ // 新架构:使用 TurboModule
36
+ try {
37
+ return require('./NativeDeviceSecureInfo').default;
38
+ } catch (e) {
39
+ console.warn(
40
+ '[react-native-device-secure-info] TurboModule not available, falling back to Bridge module',
41
+ );
42
+ }
43
+ }
44
+
45
+ // 旧架构:使用 NativeModules (Bridge)
46
+ const { DeviceSecureInfoModule } = NativeModules;
47
+ if (!DeviceSecureInfoModule) {
48
+ throw new Error(
49
+ '[react-native-device-secure-info] Native module not found. ' +
50
+ 'Please make sure the native module is properly linked:\n' +
51
+ ' - Android: Check MainApplication.kt/MainApplication.java\n' +
52
+ ' - iOS: Run `cd ios && pod install`\n' +
53
+ ` - Platform: ${Platform.OS}`,
54
+ );
55
+ }
56
+ return DeviceSecureInfoModule;
57
+ }
58
+
59
+ // 缓存模块实例
60
+ const DeviceSecureInfoNativeModule = getDeviceSecureInfoModule();
61
+
62
+ /**
63
+ * 获取设备安全信息
64
+ *
65
+ * 返回设备的基础信息、内存信息、CPU 信息和电池信息
66
+ *
67
+ * @returns {Promise<DeviceSecureInfo>} 设备信息对象
68
+ *
69
+ * @example
70
+ * ```tsx
71
+ * import { getDeviceInfo } from 'react-native-device-secure-info';
72
+ *
73
+ * async function fetchInfo() {
74
+ * const info = await getDeviceInfo();
75
+ * console.log('设备名:', info.deviceName);
76
+ * console.log('系统:', info.systemName, info.systemVersion);
77
+ * console.log('电量:', info.batteryLevel + '%');
78
+ * console.log('内存使用:', info.memoryUsagePercent + '%');
79
+ * console.log('CPU核心:', info.cpuCores);
80
+ * }
81
+ * ```
82
+ */
83
+ export function getDeviceInfo(): Promise<DeviceSecureInfo> {
84
+ return DeviceSecureInfoNativeModule.getDeviceInfo();
85
+ }
86
+
87
+ /**
88
+ * 默认导出模块实例(高级用法)
89
+ */
90
+ export default DeviceSecureInfoNativeModule;