@amazon-devices/expo-application 2.0.1758683737

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 (49) hide show
  1. package/.eslintrc.js +2 -0
  2. package/CHANGELOG.md +176 -0
  3. package/CMakeLists.txt +46 -0
  4. package/LICENSE +7 -0
  5. package/README.kepler.md +103 -0
  6. package/README.md +25 -0
  7. package/THIRD_PARTY_NOTICES.txt +24 -0
  8. package/android/build.gradle +115 -0
  9. package/android/src/main/AndroidManifest.xml +2 -0
  10. package/android/src/main/java/expo/modules/application/ApplicationModule.kt +125 -0
  11. package/build/Application.d.ts +126 -0
  12. package/build/Application.d.ts.map +1 -0
  13. package/build/Application.js +184 -0
  14. package/build/Application.js.map +1 -0
  15. package/build/Application.types.d.ts +13 -0
  16. package/build/Application.types.d.ts.map +1 -0
  17. package/build/Application.types.js +11 -0
  18. package/build/Application.types.js.map +1 -0
  19. package/build/ExpoApplication.d.ts +3 -0
  20. package/build/ExpoApplication.d.ts.map +1 -0
  21. package/build/ExpoApplication.js +3 -0
  22. package/build/ExpoApplication.js.map +1 -0
  23. package/build/ExpoApplication.kepler.d.ts +11 -0
  24. package/build/ExpoApplication.kepler.d.ts.map +1 -0
  25. package/build/ExpoApplication.kepler.js +26 -0
  26. package/build/ExpoApplication.kepler.js.map +1 -0
  27. package/build/ExpoApplication.web.d.ts +11 -0
  28. package/build/ExpoApplication.web.d.ts.map +1 -0
  29. package/build/ExpoApplication.web.js +24 -0
  30. package/build/ExpoApplication.web.js.map +1 -0
  31. package/expo-module.config.json +10 -0
  32. package/ios/ApplicationExceptions.swift +19 -0
  33. package/ios/ApplicationModule.swift +48 -0
  34. package/ios/ApplicationModuleProvisioningProfile.swift +75 -0
  35. package/ios/ExpoApplication.podspec +32 -0
  36. package/kepler/ExpoApplication.cpp +78 -0
  37. package/kepler/ExpoApplication.h +44 -0
  38. package/kepler/KeplerInit.cpp +28 -0
  39. package/kepler/test/ExpoApplication.cpp +94 -0
  40. package/package.json +1 -0
  41. package/react-native.config.js +21 -0
  42. package/src/.gitkeep +0 -0
  43. package/src/Application.ts +196 -0
  44. package/src/Application.types.ts +14 -0
  45. package/src/ExpoApplication.kepler.ts +46 -0
  46. package/src/ExpoApplication.ts +3 -0
  47. package/src/ExpoApplication.web.ts +23 -0
  48. package/tsconfig.json +9 -0
  49. package/unimodule.json +4 -0
package/.eslintrc.js ADDED
@@ -0,0 +1,2 @@
1
+ // @generated by expo-module-scripts
2
+ module.exports = require('expo-module-scripts/eslintrc.base.js');
package/CHANGELOG.md ADDED
@@ -0,0 +1,176 @@
1
+ # Changelog
2
+
3
+ ## Unpublished
4
+
5
+ ### 🛠 Breaking changes
6
+
7
+ ### 🎉 New features
8
+
9
+ ### 🐛 Bug fixes
10
+
11
+ ### 💡 Others
12
+
13
+ ## 5.6.0 — 2023-10-17
14
+
15
+ ### 🛠 Breaking changes
16
+
17
+ - Dropped support for Android SDK 21 and 22. ([#24201](https://github.com/expo/expo/pull/24201) by [@behenate](https://github.com/behenate))
18
+ - Removed `androidId` constant in favor of a method (`getAndroidId`) to comply with Huawei and Xiaomi's app store policies. ([#22585](https://github.com/expo/expo/pull/22585) by [@fobos531](https://github.com/fobos531))
19
+
20
+ ### 🎉 New features
21
+
22
+ - Migrate iOS module to Expo modules API. ([#24871](https://github.com/expo/expo/pull/24871) by [@reichhartd](https://github.com/reichhartd))
23
+ - Android module is now written using the Sweet API. ([#22395](https://github.com/expo/expo/pull/22585) by [@fobos531](https://github.com/fobos531))
24
+
25
+ ## 5.5.0 — 2023-09-15
26
+
27
+ ### 🎉 New features
28
+
29
+ - Added support for Apple tvOS. ([#24329](https://github.com/expo/expo/pull/24329) by [@douglowder](https://github.com/douglowder))
30
+
31
+ ## 5.4.0 — 2023-09-04
32
+
33
+ ### 🎉 New features
34
+
35
+ - Added support for React Native 0.73. ([#24018](https://github.com/expo/expo/pull/24018) by [@kudo](https://github.com/kudo))
36
+
37
+ ## 5.3.1 — 2023-08-02
38
+
39
+ _This version does not introduce any user-facing changes._
40
+
41
+ ## 5.3.0 — 2023-06-13
42
+
43
+ ### 📚 3rd party library updates
44
+
45
+ - Updated `robolectric` to `4.10` and `junit` to `4.13.2`. ([#22395](https://github.com/expo/expo/pull/22395) by [@josephyanks](https://github.com/josephyanks))
46
+
47
+ ### 🐛 Bug fixes
48
+
49
+ - Fixed Android build warnings for Gradle version 8. ([#22537](https://github.com/expo/expo/pull/22537), [#22609](https://github.com/expo/expo/pull/22609) by [@kudo](https://github.com/kudo))
50
+
51
+ ## 5.2.0 — 2023-05-08
52
+
53
+ _This version does not introduce any user-facing changes._
54
+
55
+ ## 5.1.1 — 2023-02-09
56
+
57
+ _This version does not introduce any user-facing changes._
58
+
59
+ ## 5.1.0 — 2023-02-03
60
+
61
+ ### 💡 Others
62
+
63
+ - On Android bump `compileSdkVersion` and `targetSdkVersion` to `33`. ([#20721](https://github.com/expo/expo/pull/20721) by [@lukmccall](https://github.com/lukmccall))
64
+
65
+ ## 5.0.1 — 2022-10-28
66
+
67
+ _This version does not introduce any user-facing changes._
68
+
69
+ ## 5.0.0 — 2022-10-06
70
+
71
+ ### 🛠 Breaking changes
72
+
73
+ - Bumped iOS deployment target to 13.0 and deprecated support for iOS 12. ([#18873](https://github.com/expo/expo/pull/18873) by [@tsapeta](https://github.com/tsapeta))
74
+
75
+ ## 4.2.2 — 2022-07-19
76
+
77
+ _This version does not introduce any user-facing changes._
78
+
79
+ ## 4.2.1 — 2022-07-18
80
+
81
+ ### 💡 Others
82
+
83
+ - Clarify that `getIosPushNotificationServiceEnvironmentAsync` returns `null` on the simulator. ([#18282](https://github.com/expo/expo/pull/18282) by [@tsapeta](https://github.com/tsapeta))
84
+
85
+ ## 4.2.0 — 2022-07-07
86
+
87
+ _This version does not introduce any user-facing changes._
88
+
89
+ ## 4.1.0 — 2022-04-18
90
+
91
+ ### ⚠️ Notices
92
+
93
+ - On Android bump `compileSdkVersion` to `31`, `targetSdkVersion` to `31` and `Java` version to `11`. ([#16941](https://github.com/expo/expo/pull/16941) by [@bbarthec](https://github.com/bbarthec))
94
+
95
+ ## 4.0.2 - 2022-02-01
96
+
97
+ ### 🐛 Bug fixes
98
+
99
+ - Fix `Plugin with id 'maven' not found` build error from Android Gradle 7. ([#16080](https://github.com/expo/expo/pull/16080) by [@kudo](https://github.com/kudo))
100
+
101
+ ## 4.0.1 — 2021-11-17
102
+
103
+ _This version does not introduce any user-facing changes._
104
+
105
+ ## 4.0.0 — 2021-09-28
106
+
107
+ ### 🛠 Breaking changes
108
+
109
+ - Dropped support for iOS 11.0 ([#14383](https://github.com/expo/expo/pull/14383) by [@cruzach](https://github.com/cruzach))
110
+
111
+ ### 🐛 Bug fixes
112
+
113
+ - Fix building errors from use_frameworks! in Podfile. ([#14523](https://github.com/expo/expo/pull/14523) by [@kudo](https://github.com/kudo))
114
+
115
+ ## 3.3.0 — 2021-09-08
116
+
117
+ ### 💡 Others
118
+
119
+ - Rewrite android code to Kotlin ([#13792](https://github.com/expo/expo/pull/13792) by [@kkafar](https://github.com/kkafar))
120
+ - Add basic unit tests to Kotlin. ([#13792](https://github.com/expo/expo/pull/13792) by [@kkafar](https://github.com/kkafar))
121
+
122
+ ## 3.2.0 — 2021-06-16
123
+
124
+ ### 🐛 Bug fixes
125
+
126
+ - Enable kotlin in all modules. ([#12716](https://github.com/expo/expo/pull/12716) by [@wschurman](https://github.com/wschurman))
127
+
128
+ ### 💡 Others
129
+
130
+ - Build Android code using Java 8 to fix Android instrumented test build error. ([#12939](https://github.com/expo/expo/pull/12939) by [@kudo](https://github.com/kudo))
131
+
132
+ ## 3.1.2 — 2021-04-13
133
+
134
+ _This version does not introduce any user-facing changes._
135
+
136
+ ## 3.1.1 — 2021-04-09
137
+
138
+ _This version does not introduce any user-facing changes._
139
+
140
+ ## 3.1.0 — 2021-03-10
141
+
142
+ ### 🎉 New features
143
+
144
+ - Updated Android build configuration to target Android 11 (added support for Android SDK 30). ([#11647](https://github.com/expo/expo/pull/11647) by [@bbarthec](https://github.com/bbarthec))
145
+
146
+ ### 🐛 Bug fixes
147
+
148
+ - Remove peerDependencies and unimodulePeerDependencies from Expo modules. ([#11980](https://github.com/expo/expo/pull/11980) by [@brentvatne](https://github.com/brentvatne))
149
+
150
+ ## 3.0.0 — 2021-01-15
151
+
152
+ ### 🛠 Breaking changes
153
+
154
+ - Dropped support for iOS 10.0 ([#11344](https://github.com/expo/expo/pull/11344) by [@tsapeta](https://github.com/tsapeta))
155
+
156
+ ## 2.4.1 — 2020-11-25
157
+
158
+ ### 🐛 Bug fixes
159
+
160
+ - Fixed return type of `getIosIdForVendorAsync` to include possible `null` value which can be returned if the device hasn't been unlocked yet (for more information consult the [Apple documentation for `identifierForVendor`](https://developer.apple.com/documentation/uikit/uidevice/1620059-identifierforvendor?language=objc)). ([#10997](https://github.com/expo/expo/pull/10997) by [@sjchmiela](https://github.com/sjchmiela))
161
+
162
+ ## 2.4.0 — 2020-11-17
163
+
164
+ _This version does not introduce any user-facing changes._
165
+
166
+ ## 2.3.0 — 2020-08-18
167
+
168
+ _This version does not introduce any user-facing changes._
169
+
170
+ ## 2.2.1 — 2020-05-28
171
+
172
+ _This version does not introduce any user-facing changes._
173
+
174
+ ## 2.2.0 — 2020-05-27
175
+
176
+ _This version does not introduce any user-facing changes._
package/CMakeLists.txt ADDED
@@ -0,0 +1,46 @@
1
+ #
2
+ # Copyright 2023 Amazon.com, Inc. or its affiliates. All rights reserved.
3
+ #
4
+ # AMAZON PROPRIETARY/CONFIDENTIAL
5
+ #
6
+ # You may not use this file except in compliance with the terms and conditions
7
+ # set forth in the accompanying LICENSE.TXT file.
8
+ #
9
+ # THESE MATERIALS ARE PROVIDED ON AN "AS IS" BASIS. AMAZON SPECIFICALLY
10
+ # DISCLAIMS, WITH RESPECT TO THESE MATERIALS, ALL WARRANTIES, EXPRESS,
11
+ # IMPLIED, OR STATUTORY, INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
12
+ # FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
13
+ #
14
+ set(PACKAGE_NAME "expo-application")
15
+ set(AUTO_LINK_PACKAGE_NAME "${PACKAGE_NAME}-${KEPLER_REACT_NATIVE_MAJOR_VERSION}")
16
+ set(SOURCES_KEPLER kepler/ExpoApplication.cpp)
17
+
18
+ add_library(${PACKAGE_NAME} STATIC ${SOURCES_KEPLER})
19
+
20
+ target_link_libraries(
21
+ ${PACKAGE_NAME}
22
+ PUBLIC
23
+ keplerui::keplerscript-${KEPLER_REACT_NATIVE_MAJOR_VERSION}
24
+ )
25
+
26
+ add_library(${AUTO_LINK_PACKAGE_NAME} SHARED kepler/KeplerInit.cpp)
27
+
28
+ set_target_properties(${AUTO_LINK_PACKAGE_NAME} PROPERTIES SOVERSION ${KEPLER_REACT_NATIVE_MAJOR_VERSION}.${KEPLER_REACT_NATIVE_MINOR_VERSION})
29
+
30
+ target_link_libraries(
31
+ ${AUTO_LINK_PACKAGE_NAME}
32
+ PRIVATE
33
+ ${PACKAGE_NAME}
34
+ )
35
+
36
+ # Helps in checking undefined references
37
+ add_executable(${AUTO_LINK_PACKAGE_NAME}_exe kepler/KeplerInit.cpp)
38
+ target_link_libraries(${AUTO_LINK_PACKAGE_NAME}_exe
39
+ PRIVATE
40
+ ${AUTO_LINK_PACKAGE_NAME}
41
+ keplerui::keplerscript-${KEPLER_REACT_NATIVE_MAJOR_VERSION}
42
+ )
43
+
44
+ install(TARGETS ${AUTO_LINK_PACKAGE_NAME}
45
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
46
+ )
package/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2025 Amazon.com, Inc. or its affiliates. All rights reserved.
2
+
3
+ These materials are licensed as "Program Materials" under the Program Materials License Agreement (the "Agreement"). The Agreement is available at https://developer.amazon.com/support/legal/pml. See the Agreement for the specific terms and conditions of the Agreement. Capitalized terms not defined in this file have the meanings given to them in the Agreement.
4
+
5
+ If you do not agree to the above terms and conditions, you may not use any file in this package.
6
+
7
+ YOUR USE OF THE PROGRAM MATERIALS IN OR ASSOCIATED WITH THIS PACKAGE IS AT YOUR SOLE RISK. IN NO EVENT WILL AMAZON BE LIABLE FOR ANY DAMAGES, INCLUDING WITHOUT LIMITATION ANY DIRECT, INDIRECT, CONSEQUENTIAL, SPECIAL, INCIDENTAL, OR PUNITIVE DAMAGES (INCLUDING FOR ANY LOSS OF GOODWILL, BUSINESS INTERRUPTION, LOST PROFITS OR DATA, OR COMPUTER FAILURE OR MALFUNCTION) ARISING FROM OR RELATING TO SUCH PROGRAM MATERIALS, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, EVEN IF AMAZON HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS AND DISCLAIMERS APPLY EXCEPT TO THE EXTENT PROHIBITED BY APPLICABLE LAW.
@@ -0,0 +1,103 @@
1
+ # @amazon-devices/expo-application
2
+
3
+ ## Getting Started
4
+
5
+ `@amazon-devices/expo-application` retrieves native application information such as its ID, app name, and build version at runtime.
6
+
7
+ ### Installation
8
+
9
+ 1. Add the JavaScript library dependency in the `package.json` file:
10
+ ```json
11
+ dependencies: {
12
+ ...
13
+ "@amazon-devices/expo-application": "~2.0.0",
14
+ ...
15
+ }
16
+ ```
17
+
18
+ 2. Reinstall dependencies using `npm install` command.
19
+
20
+ ## Usage Examples
21
+
22
+ ```js
23
+ import * as Application from '@amazon-devices/expo-application';
24
+ import React, {useEffect, useState} from 'react';
25
+ import {StyleSheet, Text, View} from 'react-native';
26
+
27
+ export const App = () => {
28
+ const [installationTime, setInstallationTime] = useState<Date>();
29
+ const [updateTime, setUpdateTime] = useState<Date>();
30
+
31
+ useEffect(() => {
32
+ Application.getInstallationTimeAsync().then(setInstallationTime);
33
+ Application.getLastUpdateTimeAsync().then(setUpdateTime);
34
+ }, []);
35
+
36
+ return (
37
+ <View style={styles.container}>
38
+ <Text style={styles.text}>
39
+ applicationId: {Application.applicationId}
40
+ </Text>
41
+ <Text style={styles.text}>
42
+ applicationName: {Application.applicationName}
43
+ </Text>
44
+ <Text style={styles.text}>
45
+ nativeApplicationVersion: {Application.nativeApplicationVersion}
46
+ </Text>
47
+ <Text style={styles.text}>
48
+ nativeBuildVersion: {Application.nativeBuildVersion}
49
+ </Text>
50
+ <Text style={styles.text}>
51
+ getInstallationTimeAsync: {installationTime?.toLocaleString()}
52
+ </Text>
53
+ <Text style={styles.text}>
54
+ getLastUpdateTimeAsync: {updateTime?.toLocaleString()}
55
+ </Text>
56
+ </View>
57
+ );
58
+ };
59
+
60
+ const styles = StyleSheet.create({
61
+ container: {
62
+ flex: 1,
63
+ backgroundColor: 'white',
64
+ },
65
+ text: {
66
+ fontSize: 32,
67
+ color: 'black',
68
+ },
69
+ });
70
+
71
+
72
+ ```
73
+
74
+ ## API Reference
75
+
76
+ Check out the dedicated documentation page for info about this library, API reference and more: [Official Expo documentation for expo-application](https://github.com/expo/expo/blob/sdk-49/docs/pages/versions/v49.0.0/sdk/application.mdx).
77
+
78
+ ### Constants
79
+
80
+ | Constant | Description | Platform support |
81
+ | -------- | ----------- | ---------------- |
82
+ | androidId | The value of `Settings.Secure.ANDROID_ID` | Android |
83
+ | applicationId | The ID of the application | All |
84
+ | applicationName | The human-readable name of the application that is displayed with the app's icon on the device's home screen or desktop | All |
85
+ | nativeApplicationVersion | The human-readable version of the native application that may be displayed in the app store | All |
86
+ | nativeBuildVersion | The internal build version of the native application that the app store may use to distinguish between different binaries | All |
87
+
88
+ ### Methods
89
+
90
+ | Method | Description | Platform support |
91
+ | ------ | ----------- | ---------------- |
92
+ | getInstallReferrerAsync | Gets the referrer URL of the installed app with the Install Referrer API from the Google Play Store | Android |
93
+ | getInstallationTimeAsync | Gets the time the app was installed onto the device, not counting subsequent updates | All |
94
+ | getIosApplicationReleaseTypeAsync | Gets the iOS application release type | iOS |
95
+ | getIosIdForVendorAsync | Gets the iOS "identifier for vendor" (IDFV) value, a string ID that uniquely identifies a device to the app’s vendor | iOS |
96
+ | getIosPushNotificationServiceEnvironmentAsync | Gets the current Apple Push Notification (APN) service environment | iOS |
97
+ | getLastUpdateTimeAsync | Gets the last time the app was updated | Android and Kepler |
98
+
99
+ ## Supported Versions
100
+
101
+ | Package version | Based on | @amazon-devices/react-native-kepler version |
102
+ | ---------------- | -------- | --------------------------------- |
103
+ | 2.0.x | expo-application v5.6.0 | 2.0.x |
package/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # expo-application
2
+
3
+ Gets native application information such as its ID, app name, and build version at runtime.
4
+
5
+ # API documentation
6
+
7
+ - [Documentation for the main branch](https://github.com/expo/expo/blob/main/docs/pages/versions/unversioned/sdk/application.md)
8
+
9
+ # Installation in managed Expo projects
10
+
11
+ For [managed](https://docs.expo.dev/archive/managed-vs-bare/) Expo projects, please follow the installation instructions in the [API documentation for the latest stable release](#https://docs.expo.dev/versions/latest/sdk/application/).
12
+
13
+ # Installation in bare React Native projects
14
+
15
+ For bare React Native projects, you must ensure that you have [installed and configured the `expo` package](https://docs.expo.dev/bare/installing-expo-modules/) before continuing.
16
+
17
+ ### Add the package to your npm dependencies
18
+
19
+ ```
20
+ npx expo install expo-application
21
+ ```
22
+
23
+ # Contributing
24
+
25
+ Contributions are very welcome! Please refer to guidelines described in the [contributing guide](https://github.com/expo/expo#contributing).
@@ -0,0 +1,24 @@
1
+ License from package.json:
2
+ ==============================
3
+
4
+ The MIT License (MIT)
5
+
6
+ Copyright (c) 2015-present 650 Industries, Inc. (aka Expo)
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in all
16
+ copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ SOFTWARE.
@@ -0,0 +1,115 @@
1
+ apply plugin: 'com.android.library'
2
+ apply plugin: 'kotlin-android'
3
+ apply plugin: 'maven-publish'
4
+
5
+ group = 'host.exp.exponent'
6
+ version = '5.6.0'
7
+
8
+ def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
9
+ if (expoModulesCorePlugin.exists()) {
10
+ apply from: expoModulesCorePlugin
11
+ applyKotlinExpoModulesCorePlugin()
12
+ // Remove this check, but keep the contents after SDK49 support is dropped
13
+ if (safeExtGet("expoProvidesDefaultConfig", false)) {
14
+ useExpoPublishing()
15
+ useCoreDependencies()
16
+ }
17
+ }
18
+
19
+ buildscript {
20
+ // Simple helper that allows the root project to override versions declared by this library.
21
+ ext.safeExtGet = { prop, fallback ->
22
+ rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
23
+ }
24
+
25
+ // Ensures backward compatibility
26
+ ext.getKotlinVersion = {
27
+ if (ext.has("kotlinVersion")) {
28
+ ext.kotlinVersion()
29
+ } else {
30
+ ext.safeExtGet("kotlinVersion", "1.8.10")
31
+ }
32
+ }
33
+
34
+ repositories {
35
+ mavenCentral()
36
+ }
37
+
38
+ dependencies {
39
+ classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${getKotlinVersion()}")
40
+ }
41
+ }
42
+
43
+ // Remove this if and it's contents, when support for SDK49 is dropped
44
+ if (!safeExtGet("expoProvidesDefaultConfig", false)) {
45
+ afterEvaluate {
46
+ publishing {
47
+ publications {
48
+ release(MavenPublication) {
49
+ from components.release
50
+ }
51
+ }
52
+ repositories {
53
+ maven {
54
+ url = mavenLocal().url
55
+ }
56
+ }
57
+ }
58
+ }
59
+ }
60
+
61
+ android {
62
+ // Remove this if and it's contents, when support for SDK49 is dropped
63
+ if (!safeExtGet("expoProvidesDefaultConfig", false)) {
64
+ compileSdkVersion safeExtGet("compileSdkVersion", 33)
65
+
66
+ defaultConfig {
67
+ minSdkVersion safeExtGet("minSdkVersion", 23)
68
+ targetSdkVersion safeExtGet("targetSdkVersion", 33)
69
+ }
70
+
71
+ publishing {
72
+ singleVariant("release") {
73
+ withSourcesJar()
74
+ }
75
+ }
76
+
77
+ lintOptions {
78
+ abortOnError false
79
+ }
80
+ }
81
+
82
+ def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
83
+ if (agpVersion.tokenize('.')[0].toInteger() < 8) {
84
+ compileOptions {
85
+ sourceCompatibility JavaVersion.VERSION_11
86
+ targetCompatibility JavaVersion.VERSION_11
87
+ }
88
+
89
+ kotlinOptions {
90
+ jvmTarget = JavaVersion.VERSION_11.majorVersion
91
+ }
92
+ }
93
+
94
+ namespace "expo.modules.application"
95
+ defaultConfig {
96
+ versionCode 12
97
+ versionName '5.6.0'
98
+ }
99
+ }
100
+
101
+ dependencies {
102
+ // Remove this if and it's contents, when support for SDK49 is dropped
103
+ if (!safeExtGet("expoProvidesDefaultConfig", false)) {
104
+ implementation project(':expo-modules-core')
105
+ implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
106
+ }
107
+
108
+ implementation 'com.android.installreferrer:installreferrer:1.0'
109
+
110
+ if (project.findProject(':expo-modules-test-core')) {
111
+ testImplementation project(':expo-modules-test-core')
112
+ }
113
+ testImplementation "org.robolectric:robolectric:4.10"
114
+ testImplementation 'junit:junit:4.13.2'
115
+ }
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>
@@ -0,0 +1,125 @@
1
+ package expo.modules.application
2
+
3
+ import android.content.Context
4
+ import android.content.pm.PackageInfo
5
+ import android.content.pm.PackageManager
6
+ import android.os.Build
7
+ import android.os.RemoteException
8
+ import android.provider.Settings
9
+ import com.android.installreferrer.api.InstallReferrerClient
10
+ import com.android.installreferrer.api.InstallReferrerStateListener
11
+ import expo.modules.kotlin.Promise
12
+ import expo.modules.kotlin.exception.CodedException
13
+ import expo.modules.kotlin.exception.Exceptions
14
+ import expo.modules.kotlin.modules.Module
15
+ import expo.modules.kotlin.modules.ModuleDefinition
16
+
17
+ class ApplicationPackageNameNotFoundException(cause: PackageManager.NameNotFoundException) :
18
+ CodedException(message = "Unable to get install time of this application. Could not get package info or package name.", cause = cause)
19
+
20
+ class ApplicationModule : Module() {
21
+ private val context: Context
22
+ get() = appContext.reactContext ?: throw Exceptions.ReactContextLost()
23
+
24
+ override fun definition() = ModuleDefinition {
25
+ Name("ExpoApplication")
26
+
27
+ Constants {
28
+ return@Constants mapOf(
29
+ "applicationName" to applicationName,
30
+ "applicationId" to packageName,
31
+ "nativeApplicationVersion" to versionName,
32
+ "nativeBuildVersion" to versionCode.toString(),
33
+ )
34
+ }
35
+
36
+ Property("androidId") {
37
+ Settings.Secure.getString(context.contentResolver, Settings.Secure.ANDROID_ID)
38
+ }
39
+
40
+ AsyncFunction("getInstallationTimeAsync") {
41
+ val packageManager = context.packageManager
42
+ val packageName = context.packageName
43
+ packageManager
44
+ .getPackageInfoCompat(packageName, 0)
45
+ .firstInstallTime
46
+ .toDouble()
47
+ }
48
+
49
+ AsyncFunction("getLastUpdateTimeAsync") {
50
+ val packageManager = context.packageManager
51
+ val packageName = context.packageName
52
+ packageManager
53
+ .getPackageInfoCompat(packageName, 0)
54
+ .lastUpdateTime
55
+ .toDouble()
56
+ }
57
+
58
+ AsyncFunction("getInstallReferrerAsync") { promise: Promise ->
59
+ val installReferrer = StringBuilder()
60
+
61
+ val referrerClient = InstallReferrerClient.newBuilder(context).build()
62
+
63
+ referrerClient.startConnection(object : InstallReferrerStateListener {
64
+ override fun onInstallReferrerSetupFinished(responseCode: Int) {
65
+ when (responseCode) {
66
+ InstallReferrerClient.InstallReferrerResponse.OK -> {
67
+ // Connection established and response received
68
+ try {
69
+ val response = referrerClient.installReferrer
70
+ installReferrer.append(response.installReferrer)
71
+ } catch (e: RemoteException) {
72
+ promise.reject("ERR_APPLICATION_INSTALL_REFERRER_REMOTE_EXCEPTION", "RemoteException getting install referrer information. This may happen if the process hosting the remote object is no longer available.", e)
73
+ return
74
+ }
75
+ promise.resolve(installReferrer.toString())
76
+ }
77
+
78
+ InstallReferrerClient.InstallReferrerResponse.FEATURE_NOT_SUPPORTED -> // API not available in the current Play Store app
79
+ promise.reject("ERR_APPLICATION_INSTALL_REFERRER_UNAVAILABLE", "The current Play Store app doesn't provide the installation referrer API, or the Play Store may not be installed.", null)
80
+
81
+ InstallReferrerClient.InstallReferrerResponse.SERVICE_UNAVAILABLE -> // Connection could not be established
82
+ promise.reject("ERR_APPLICATION_INSTALL_REFERRER", "General error retrieving the install referrer: response code $responseCode", null)
83
+
84
+ else -> promise.reject("ERR_APPLICATION_INSTALL_REFERRER", "General error retrieving the install referrer: response code $responseCode", null)
85
+ }
86
+ referrerClient.endConnection()
87
+ }
88
+
89
+ override fun onInstallReferrerServiceDisconnected() {
90
+ promise.reject("ERR_APPLICATION_INSTALL_REFERRER_SERVICE_DISCONNECTED", "Connection to install referrer service was lost.", null)
91
+ }
92
+ })
93
+ }
94
+ }
95
+
96
+ private val applicationName
97
+ get() = context.applicationInfo.loadLabel(context.packageManager).toString()
98
+ private val packageName
99
+ get() = context.packageName
100
+ private val packageManager
101
+ get() = context.packageManager
102
+ private val versionName
103
+ get() = packageManager.getPackageInfoCompat(packageName, 0).versionName
104
+ private val versionCode
105
+ get() = getLongVersionCode(packageManager.getPackageInfoCompat(packageName, 0)).toInt()
106
+ }
107
+
108
+ private fun PackageManager.getPackageInfoCompat(packageName: String, flags: Int = 0): PackageInfo =
109
+ try {
110
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
111
+ getPackageInfo(packageName, PackageManager.PackageInfoFlags.of(flags.toLong()))
112
+ } else {
113
+ @Suppress("DEPRECATION") getPackageInfo(packageName, flags)
114
+ }
115
+ } catch (e: PackageManager.NameNotFoundException) {
116
+ throw ApplicationPackageNameNotFoundException(e)
117
+ }
118
+
119
+ private fun getLongVersionCode(info: PackageInfo): Long {
120
+ return if (Build.VERSION.SDK_INT >= 28) {
121
+ info.longVersionCode
122
+ } else {
123
+ @Suppress("DEPRECATION") info.versionCode.toLong()
124
+ }
125
+ }