Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
#	package.json
  • Loading branch information
odemolliens committed Apr 25, 2022
2 parents 13617da + fa6ea80 commit 9769098
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ public class SimCardsManagerModule extends ReactContextBaseJavaModule {
public SimCardsManagerModule(ReactApplicationContext reactContext) {
super(reactContext);
mReactContext = reactContext;
mgr = (EuiccManager) mReactContext.getSystemService(EUICC_SERVICE);
}

@RequiresApi(api = Build.VERSION_CODES.P)
private void initMgr() {
if(mgr == null) {
mgr = (EuiccManager) mReactContext.getSystemService(EUICC_SERVICE);
}
}

@Override
Expand Down Expand Up @@ -104,6 +110,7 @@ public void getSimCards(Promise promise) {
@RequiresApi(api = Build.VERSION_CODES.P)
@ReactMethod
public void isEsimSupported(Promise promise) {
initMgr();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && mgr != null) {
promise.resolve(mgr.isEnabled());
} else {
Expand All @@ -115,7 +122,7 @@ public void isEsimSupported(Promise promise) {
@RequiresApi(api = Build.VERSION_CODES.P)
@ReactMethod
public void setupEsim(ReadableMap config, Promise promise) {

initMgr();
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP_MR1) {
promise.reject("0", "EuiccManager is not available or before Android 9 (API 28)");
}
Expand Down
106 changes: 56 additions & 50 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,66 +22,72 @@ export default function App() {
const scrollViewRef = useRef<any>();

const getSimCards = () => {
SimCardsManagerModule.getSimCards().then((array: Array<any>)=>{
setLogs([
...logs,
{
command: 'getSimCards',
result: JSON.stringify(array, null, 5),
},
]);
}).catch((error)=>{
setLogs([
...logs,
{
command: 'getSimCardsError',
result: JSON.stringify(error, null, 5),
},
]);
})
SimCardsManagerModule.getSimCards()
.then((array: Array<any>) => {
setLogs([
...logs,
{
command: 'getSimCards',
result: JSON.stringify(array, null, 5),
},
]);
})
.catch((error: any) => {
setLogs([
...logs,
{
command: 'getSimCardsError',
result: JSON.stringify(error, null, 5),
},
]);
});
};

const isEsimSupported = () => {
SimCardsManagerModule.isEsimSupported().then((isSupported: boolean)=>{
setLogs([
...logs,
{
command: 'isEsimSupported',
result: JSON.stringify(isSupported, null, 5),
},
]);
}).catch((error)=>{
setLogs([
...logs,
{
command: 'isEsimSupportedError',
result: JSON.stringify(error, null, 5),
},
]);
})
SimCardsManagerModule.isEsimSupported()
.then((isSupported: boolean) => {
setLogs([
...logs,
{
command: 'isEsimSupported',
result: JSON.stringify(isSupported, null, 5),
},
]);
})
.catch((error: any) => {
setLogs([
...logs,
{
command: 'isEsimSupportedError',
result: JSON.stringify(error, null, 5),
},
]);
});
};

const setupEsim = () => {
SimCardsManagerModule.setupEsim({
confirmationCode,
address: '',
}).then((isPlanAdded: boolean)=>{
setLogs([
...logs,
{
command: 'setupEsim',
result: JSON.stringify(isPlanAdded, null, 5),
},
]);
}).catch((error)=>{
setLogs([
...logs,
{
command: 'setupEsimError',
result: JSON.stringify(error, null, 5),
},
]);
})
.then((isPlanAdded: boolean) => {
setLogs([
...logs,
{
command: 'setupEsim',
result: JSON.stringify(isPlanAdded, null, 5),
},
]);
})
.catch((error: any) => {
setLogs([
...logs,
{
command: 'setupEsimError',
result: JSON.stringify(error, null, 5),
},
]);
});
};

return (
Expand Down
18 changes: 9 additions & 9 deletions example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1024,9 +1024,9 @@ ansi-fragments@^0.2.1:
strip-ansi "^5.0.0"

ansi-regex@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-4.1.0.tgz#8b9f8f08cf1acb843756a839ca8c7e3168c51997"
integrity sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==
version "4.1.1"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-4.1.1.tgz#164daac87ab2d6f6db3a29875e2d1766582dabed"
integrity sha512-ILlv4k/3f6vfQ4OoP2AGvirOktlQ98ZEL1k9FaQjxa3L1abBgbuTDAdPOpvbGncC0BTVQrl+OM8xZGK6tWXt7g==

ansi-regex@^5.0.0, ansi-regex@^5.0.1:
version "5.0.1"
Expand Down Expand Up @@ -2938,9 +2938,9 @@ minimatch@^3.0.2, minimatch@^3.0.4:
brace-expansion "^1.1.7"

minimist@^1.1.1, minimist@^1.2.0, minimist@^1.2.5:
version "1.2.5"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602"
integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==
version "1.2.6"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.6.tgz#8637a5b759ea0d6e98702cfb3a9283323c93af44"
integrity sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==

mixin-deep@^1.2.0:
version "1.3.2"
Expand Down Expand Up @@ -3274,9 +3274,9 @@ pkg-up@^3.1.0:
find-up "^3.0.0"

plist@^3.0.2, plist@^3.0.4:
version "3.0.4"
resolved "https://registry.yarnpkg.com/plist/-/plist-3.0.4.tgz#a62df837e3aed2bb3b735899d510c4f186019cbe"
integrity sha512-ksrr8y9+nXOxQB2osVNqrgvX/XQPOXaU4BQMKjYq8PvaY1U18mo+fKgBSwzK+luSyinOuPae956lSVcBwxlAMg==
version "3.0.5"
resolved "https://registry.yarnpkg.com/plist/-/plist-3.0.5.tgz#2cbeb52d10e3cdccccf0c11a63a85d830970a987"
integrity sha512-83vX4eYdQp3vP9SxuYgEM/G/pJQqLUz/V/xzPrzruLs7fz7jxGQ1msZ/mg1nwZxUSuOp4sb+/bEIbRrbzZRxDA==
dependencies:
base64-js "^1.5.1"
xmlbuilder "^9.0.7"
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"baseUrl": "./",
"paths": {
"react-native-sim-cards-manager": ["./src/index"]
},
Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1725,9 +1725,9 @@ ansi-fragments@^0.2.1:
strip-ansi "^5.0.0"

ansi-regex@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-4.1.0.tgz#8b9f8f08cf1acb843756a839ca8c7e3168c51997"
integrity sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==
version "4.1.1"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-4.1.1.tgz#164daac87ab2d6f6db3a29875e2d1766582dabed"
integrity sha512-ILlv4k/3f6vfQ4OoP2AGvirOktlQ98ZEL1k9FaQjxa3L1abBgbuTDAdPOpvbGncC0BTVQrl+OM8xZGK6tWXt7g==

ansi-regex@^5.0.0, ansi-regex@^5.0.1:
version "5.0.1"
Expand Down Expand Up @@ -5201,9 +5201,9 @@ [email protected]:
kind-of "^6.0.3"

minimist@^1.1.1, minimist@^1.2.0, minimist@^1.2.5:
version "1.2.5"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602"
integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==
version "1.2.6"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.6.tgz#8637a5b759ea0d6e98702cfb3a9283323c93af44"
integrity sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==

mixin-deep@^1.2.0:
version "1.3.2"
Expand Down Expand Up @@ -5708,9 +5708,9 @@ pkg-dir@^4.2.0:
find-up "^4.0.0"

plist@^3.0.2, plist@^3.0.4:
version "3.0.4"
resolved "https://registry.yarnpkg.com/plist/-/plist-3.0.4.tgz#a62df837e3aed2bb3b735899d510c4f186019cbe"
integrity sha512-ksrr8y9+nXOxQB2osVNqrgvX/XQPOXaU4BQMKjYq8PvaY1U18mo+fKgBSwzK+luSyinOuPae956lSVcBwxlAMg==
version "3.0.5"
resolved "https://registry.yarnpkg.com/plist/-/plist-3.0.5.tgz#2cbeb52d10e3cdccccf0c11a63a85d830970a987"
integrity sha512-83vX4eYdQp3vP9SxuYgEM/G/pJQqLUz/V/xzPrzruLs7fz7jxGQ1msZ/mg1nwZxUSuOp4sb+/bEIbRrbzZRxDA==
dependencies:
base64-js "^1.5.1"
xmlbuilder "^9.0.7"
Expand Down

0 comments on commit 9769098

Please sign in to comment.