Skip to content

Commit 7df8af9

Browse files
authored
Merge pull request #2 from dongzhihan1/sig
react-native-get-random-values适配harmony
2 parents 94ece28 + 01e2350 commit 7df8af9

37 files changed

+560
-15
lines changed

android/src/main/java/org/linusu/RNGetRandomValuesModule.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public String getName() {
2828
public String getRandomBase64(int byteLength) throws NoSuchAlgorithmException {
2929
byte[] data = new byte[byteLength];
3030
SecureRandom random = new SecureRandom();
31-
3231
random.nextBytes(data);
3332

3433
return Base64.encodeToString(data, Base64.NO_WRAP);

harmony/get_random_values.har

90.2 KB
Binary file not shown.

harmony/get_random_values/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/node_modules
2+
/oh_modules
3+
/.preview
4+
/build
5+
/.cxx
6+
/.test
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default class BuildProfile {
2+
static readonly HAR_VERSION = '1.11.0-0.0.1';
3+
static readonly BUILD_MODE_NAME = 'debug';
4+
static readonly DEBUG = true;
5+
static readonly TARGET_NAME = 'default';
6+
}

harmony/get_random_values/Index.ets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./ts";
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"apiType": "stageMode",
3+
"buildOption": {
4+
},
5+
"buildOptionSet": [
6+
{
7+
"name": "release",
8+
"arkOptions": {
9+
"obfuscation": {
10+
"ruleOptions": {
11+
"enable": true,
12+
"files": [
13+
"./obfuscation-rules.txt"
14+
]
15+
}
16+
}
17+
}
18+
},
19+
],
20+
"targets": [
21+
{
22+
"name": "default"
23+
},
24+
{
25+
"name": "ohosTest",
26+
}
27+
]
28+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { harTasks } from '@ohos/hvigor-ohos-plugin';
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Define project specific obfuscation rules here.
2+
# You can include the obfuscation configuration files in the current module's build-profile.json5.
3+
#
4+
# For more details, see
5+
# https://gitee.com/openharmony/arkcompiler_ets_frontend/blob/master/arkguard/README.md
6+
7+
# Obfuscation options:
8+
# -disable-obfuscation: disable all obfuscations
9+
# -enable-property-obfuscation: obfuscate the property names
10+
# -enable-toplevel-obfuscation: obfuscate the names in the global scope
11+
# -compact: remove unnecessary blank spaces and all line feeds
12+
# -remove-log: remove all console.* statements
13+
# -print-namecache: print the name cache that contains the mapping from the old names to new names
14+
# -apply-namecache: reuse the given cache file
15+
16+
# Keep options:
17+
# -keep-property-name: specifies property names that you want to keep
18+
# -keep-global-name: specifies names that you want to keep in the global scope
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "@react-native-oh-tpl/react-native-get-random-values",
3+
"version": "1.11.0-0.0.1",
4+
"description": "Please describe the basic information.",
5+
"main": "Index.ets",
6+
"author": "",
7+
"license": "Apache-2.0",
8+
"dependencies": {
9+
"@rnoh/react-native-openharmony": 'file:../react_native_openharmony'
10+
}
11+
}
12+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { RNPackage, TurboModulesFactory } from '@rnoh/react-native-openharmony/ts';
2+
import type { TurboModule, TurboModuleContext } from '@rnoh/react-native-openharmony/ts';
3+
import { TM } from '@rnoh/react-native-openharmony/generated/ts'
4+
import { RNGetRandomValuesTurboModule } from './RNGetRandomValuesTurboModule';
5+
6+
class RNGetRandomValuesTurboModuleFactory extends TurboModulesFactory {
7+
createTurboModule(name: string): TurboModule | null {
8+
if (this.hasTurboModule(name)) {
9+
return new RNGetRandomValuesTurboModule(this.ctx);
10+
}
11+
return null;
12+
}
13+
14+
hasTurboModule(name: string): boolean {
15+
return name === TM.GetRandomValuesNativeModule.NAME;
16+
}
17+
}
18+
19+
export class RNGetRandomValuesPackage extends RNPackage {
20+
createTurboModulesFactory(ctx: TurboModuleContext): TurboModulesFactory {
21+
return new RNGetRandomValuesTurboModuleFactory(ctx);
22+
}
23+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { TurboModule } from '@rnoh/react-native-openharmony/ts';
2+
import { TM } from '@rnoh/react-native-openharmony/generated/ts';
3+
import window from '@ohos.window';
4+
import { util } from '@kit.ArkTS';
5+
6+
7+
export class RNGetRandomValuesTurboModule extends TurboModule implements TM.GetRandomValuesNativeModule.Spec {
8+
windowClass:window.Window| undefined = undefined;
9+
isKeepScreenOn: boolean = true;
10+
unisKeepScreenOn: boolean = false;
11+
12+
constructor(ctx) {
13+
super(ctx);
14+
}
15+
16+
17+
getRandomBase64(byteLength:number){
18+
const randomBytes = new Uint8Array(byteLength)
19+
for(var i = 0 ; i<byteLength;i++){
20+
randomBytes[i] = Math.floor(Math.random()*256)
21+
}
22+
const that = new util.Base64Helper()
23+
const base64String = that.encodeToStringSync(randomBytes);
24+
//将随机字节数组转换为Base64编码的字符串
25+
return base64String
26+
}
27+
28+
29+
30+
}
31+
32+
33+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"module": {
3+
"name": "get_random_values",
4+
"type": "har",
5+
"deviceTypes": [
6+
"default",
7+
"tablet",
8+
"2in1"
9+
]
10+
}
11+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"color": [
3+
{
4+
"name": "start_window_background",
5+
"value": "#FFFFFF"
6+
}
7+
]
8+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"string": [
3+
{
4+
"name": "module_desc",
5+
"value": "module description"
6+
},
7+
{
8+
"name": "Get_random_valuesAbility_desc",
9+
"value": "description"
10+
},
11+
{
12+
"name": "Get_random_valuesAbility_label",
13+
"value": "label"
14+
}
15+
]
16+
}
Loading
Loading
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"layered-image":
3+
{
4+
"background" : "$media:background",
5+
"foreground" : "$media:foreground"
6+
}
7+
}
Loading
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"src": [
3+
"pages/Index"
4+
]
5+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"string": [
3+
{
4+
"name": "module_desc",
5+
"value": "module description"
6+
},
7+
{
8+
"name": "Get_random_valuesAbility_desc",
9+
"value": "description"
10+
},
11+
{
12+
"name": "Get_random_valuesAbility_label",
13+
"value": "label"
14+
}
15+
]
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"string": [
3+
{
4+
"name": "module_desc",
5+
"value": "模块描述"
6+
},
7+
{
8+
"name": "Get_random_valuesAbility_desc",
9+
"value": "description"
10+
},
11+
{
12+
"name": "Get_random_valuesAbility_label",
13+
"value": "label"
14+
}
15+
]
16+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { hilog } from '@kit.PerformanceAnalysisKit';
2+
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
3+
4+
export default function abilityTest() {
5+
describe('ActsAbilityTest', () => {
6+
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
7+
beforeAll(() => {
8+
// Presets an action, which is performed only once before all test cases of the test suite start.
9+
// This API supports only one parameter: preset action function.
10+
})
11+
beforeEach(() => {
12+
// Presets an action, which is performed before each unit test case starts.
13+
// The number of execution times is the same as the number of test cases defined by **it**.
14+
// This API supports only one parameter: preset action function.
15+
})
16+
afterEach(() => {
17+
// Presets a clear action, which is performed after each unit test case ends.
18+
// The number of execution times is the same as the number of test cases defined by **it**.
19+
// This API supports only one parameter: clear action function.
20+
})
21+
afterAll(() => {
22+
// Presets a clear action, which is performed after all test cases of the test suite end.
23+
// This API supports only one parameter: clear action function.
24+
})
25+
it('assertContain', 0, () => {
26+
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
27+
hilog.info(0x0000, 'testTag', '%{public}s', 'it begin');
28+
let a = 'abc';
29+
let b = 'b';
30+
// Defines a variety of assertion methods, which are used to declare expected boolean conditions.
31+
expect(a).assertContain(b);
32+
expect(a).assertEqual(a);
33+
})
34+
})
35+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import abilityTest from './Ability.test';
2+
3+
export default function testsuite() {
4+
abilityTest();
5+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
2+
import { abilityDelegatorRegistry } from '@kit.TestKit';
3+
import { hilog } from '@kit.PerformanceAnalysisKit';
4+
import { window } from '@kit.ArkUI';
5+
import { Hypium } from '@ohos/hypium';
6+
import testsuite from '../test/List.test';
7+
8+
export default class TestAbility extends UIAbility {
9+
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
10+
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate');
11+
hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? '');
12+
hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? '');
13+
let abilityDelegator: abilityDelegatorRegistry.AbilityDelegator;
14+
abilityDelegator = abilityDelegatorRegistry.getAbilityDelegator();
15+
let abilityDelegatorArguments: abilityDelegatorRegistry.AbilityDelegatorArgs;
16+
abilityDelegatorArguments = abilityDelegatorRegistry.getArguments();
17+
hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!');
18+
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite);
19+
}
20+
21+
onDestroy() {
22+
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy');
23+
}
24+
25+
onWindowStageCreate(windowStage: window.WindowStage) {
26+
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate');
27+
windowStage.loadContent('testability/pages/Index', (err) => {
28+
if (err.code) {
29+
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
30+
return;
31+
}
32+
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.');
33+
});
34+
}
35+
36+
onWindowStageDestroy() {
37+
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy');
38+
}
39+
40+
onForeground() {
41+
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground');
42+
}
43+
44+
onBackground() {
45+
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground');
46+
}
47+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@Entry
2+
@Component
3+
struct Index {
4+
@State message: string = 'Hello World';
5+
6+
build() {
7+
Row() {
8+
Column() {
9+
Text(this.message)
10+
.fontSize(50)
11+
.fontWeight(FontWeight.Bold)
12+
}
13+
.width('100%')
14+
}
15+
.height('100%')
16+
}
17+
}

0 commit comments

Comments
 (0)