@react-native-ohos/react-native-system-setting 1.7.7-rc.1
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.
- package/API.md +58 -0
- package/LICENSE +21 -0
- package/LICENSE.md +21 -0
- package/RCTSystemSetting.podspec +20 -0
- package/README.OpenSource +11 -0
- package/README.md +15 -0
- package/SystemSetting.d.ts +81 -0
- package/SystemSetting.js +348 -0
- package/Utils.js +11 -0
- package/harmony/react_native_system_setting/BuildProfile.ets +6 -0
- package/harmony/react_native_system_setting/Index.ets +27 -0
- package/harmony/react_native_system_setting/build-profile.json5 +31 -0
- package/harmony/react_native_system_setting/consumer-rules.txt +0 -0
- package/harmony/react_native_system_setting/hvigorfile.ts +6 -0
- package/harmony/react_native_system_setting/obfuscation-rules.txt +18 -0
- package/harmony/react_native_system_setting/oh-package.json5 +11 -0
- package/harmony/react_native_system_setting/src/main/cpp/CMakeLists.txt +7 -0
- package/harmony/react_native_system_setting/src/main/cpp/RNSystemSettingPackage.h +76 -0
- package/harmony/react_native_system_setting/src/main/cpp/ReactNativeSystemSetting.cpp +54 -0
- package/harmony/react_native_system_setting/src/main/cpp/ReactNativeSystemSetting.h +21 -0
- package/harmony/react_native_system_setting/src/main/ets/Logger.ts +64 -0
- package/harmony/react_native_system_setting/src/main/ets/RNSystemSettingPackage.ts +52 -0
- package/harmony/react_native_system_setting/src/main/ets/RNSystemSettingTurboModule.ts +362 -0
- package/harmony/react_native_system_setting/src/main/ets/generated/components/ts.ts +5 -0
- package/harmony/react_native_system_setting/src/main/ets/generated/index.ets +8 -0
- package/harmony/react_native_system_setting/src/main/ets/generated/ts.ts +9 -0
- package/harmony/react_native_system_setting/src/main/ets/generated/turboModules/ReactNativeSystemSetting.ts +86 -0
- package/harmony/react_native_system_setting/src/main/ets/generated/turboModules/ts.ts +8 -0
- package/harmony/react_native_system_setting/src/main/module.json5 +9 -0
- package/harmony/react_native_system_setting/src/main/resources/base/element/string.json +8 -0
- package/harmony/react_native_system_setting/src/main/resources/en_US/element/string.json +8 -0
- package/harmony/react_native_system_setting/src/main/resources/zh_CN/element/string.json +8 -0
- package/harmony/react_native_system_setting/ts.ts +25 -0
- package/harmony/react_native_system_setting.har +0 -0
- package/package.json +47 -0
- package/src/ReactRNSystemSetting.ts +113 -0
|
@@ -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
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@react-native-ohos/react-native-system-setting",
|
|
3
|
+
"version": "1.7.7-rc.1",
|
|
4
|
+
"description": "Please describe the basic information.",
|
|
5
|
+
"main": "Index.ets",
|
|
6
|
+
"author": "",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"@rnoh/react-native-openharmony": 'file:../react_native_openharmony'
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.13)
|
|
2
|
+
set(CMAKE_VERBOSE_MAKEFILE on)
|
|
3
|
+
|
|
4
|
+
file(GLOB RNOH_SYSTEM_SETTING_SRC CONFIGURE_DEPENDS *.cpp)
|
|
5
|
+
add_library(rnoh_system_setting SHARED ${RNOH_SYSTEM_SETTING_SRC})
|
|
6
|
+
target_include_directories(rnoh_system_setting PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
|
7
|
+
target_link_libraries(rnoh_system_setting PUBLIC rnoh)
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was generated by "react-native codegen-harmony"
|
|
3
|
+
*
|
|
4
|
+
* Do not edit this file as changes may cause incorrect behavior and will be
|
|
5
|
+
* lost once the code is regenerated.
|
|
6
|
+
*
|
|
7
|
+
* @generatorVersion: 1
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
#pragma once
|
|
11
|
+
|
|
12
|
+
#include "RNOH/Package.h"
|
|
13
|
+
#include "RNOH/ArkTSTurboModule.h"
|
|
14
|
+
#include "./ReactNativeSystemSetting.h"
|
|
15
|
+
|
|
16
|
+
namespace rnoh {
|
|
17
|
+
|
|
18
|
+
class RNSystemSettingFactoryDelegate : public TurboModuleFactoryDelegate {
|
|
19
|
+
public:
|
|
20
|
+
SharedTurboModule createTurboModule(Context ctx, const std::string &name) const override {
|
|
21
|
+
if (name == "ReactNativeSystemSetting") {
|
|
22
|
+
return std::make_shared<ReactNativeSystemSetting>(ctx, name);
|
|
23
|
+
}
|
|
24
|
+
return nullptr;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
class RNSystemSettingEventEmitRequestHandler : public EventEmitRequestHandler {
|
|
29
|
+
public:
|
|
30
|
+
void handleEvent(Context const &ctx) override {
|
|
31
|
+
auto eventEmitter = ctx.shadowViewRegistry->getEventEmitter<facebook::react::EventEmitter>(ctx.tag);
|
|
32
|
+
auto componentName = ctx.shadowViewRegistry->getComponentName(ctx.tag);
|
|
33
|
+
|
|
34
|
+
if (eventEmitter == nullptr) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
std::vector<std::string> supportedComponentNames = {
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
std::vector<std::string> supportedEventNames = {
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
if (std::find(supportedComponentNames.begin(), supportedComponentNames.end(), componentName) != supportedComponentNames.end() &&
|
|
45
|
+
std::find(supportedEventNames.begin(), supportedEventNames.end(), ctx.eventName) != supportedEventNames.end()) {
|
|
46
|
+
eventEmitter->dispatchEvent(ctx.eventName, ArkJS(ctx.env).getDynamic(ctx.payload));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
class RNSystemSettingPackage : public Package {
|
|
52
|
+
public:
|
|
53
|
+
|
|
54
|
+
RNSystemSettingPackage(Package::Context ctx) : Package(ctx){};
|
|
55
|
+
std::unique_ptr<TurboModuleFactoryDelegate> createTurboModuleFactoryDelegate() override {
|
|
56
|
+
return std::make_unique<RNSystemSettingFactoryDelegate>();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
std::vector<facebook::react::ComponentDescriptorProvider> createComponentDescriptorProviders() override {
|
|
60
|
+
return {
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
ComponentJSIBinderByString createComponentJSIBinderByName() override {
|
|
65
|
+
return {
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
EventEmitRequestHandlers createEventEmitRequestHandlers() override {
|
|
70
|
+
return {
|
|
71
|
+
std::make_shared<RNSystemSettingEventEmitRequestHandler>(),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
} // namespace rnoh
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was generated by "react-native codegen-harmony"
|
|
3
|
+
*
|
|
4
|
+
* Do not edit this file as changes may cause incorrect behavior and will be
|
|
5
|
+
* lost once the code is regenerated.
|
|
6
|
+
*
|
|
7
|
+
* @generatorVersion: 1
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
#include "ReactNativeSystemSetting.h"
|
|
11
|
+
|
|
12
|
+
namespace rnoh {
|
|
13
|
+
using namespace facebook;
|
|
14
|
+
|
|
15
|
+
ReactNativeSystemSetting::ReactNativeSystemSetting(const ArkTSTurboModule::Context ctx, const std::string name) : ArkTSTurboModule(ctx, name) {
|
|
16
|
+
methodMap_ = {
|
|
17
|
+
ARK_ASYNC_METHOD_METADATA(getBrightness, 0),
|
|
18
|
+
ARK_ASYNC_METHOD_METADATA(setBrightness, 1),
|
|
19
|
+
ARK_ASYNC_METHOD_METADATA(setBrightnessForce, 1),
|
|
20
|
+
ARK_ASYNC_METHOD_METADATA(getAppBrightness, 0),
|
|
21
|
+
ARK_ASYNC_METHOD_METADATA(setAppBrightness, 1),
|
|
22
|
+
ARK_METHOD_METADATA(grantWriteSettingPremission, 0),
|
|
23
|
+
ARK_ASYNC_METHOD_METADATA(getScreenMode, 0),
|
|
24
|
+
ARK_ASYNC_METHOD_METADATA(setScreenMode, 1),
|
|
25
|
+
ARK_ASYNC_METHOD_METADATA(saveBrightness, 0),
|
|
26
|
+
ARK_METHOD_METADATA(restoreBrightness, 0),
|
|
27
|
+
ARK_ASYNC_METHOD_METADATA(getVolume, 1),
|
|
28
|
+
ARK_METHOD_METADATA(setVolume, 2),
|
|
29
|
+
ARK_METHOD_METADATA(addVolumeListener, 0),
|
|
30
|
+
ARK_METHOD_METADATA(removeVolumeListener, 1),
|
|
31
|
+
ARK_ASYNC_METHOD_METADATA(isWifiEnabled, 0),
|
|
32
|
+
ARK_METHOD_METADATA(switchWifiSilence, 1),
|
|
33
|
+
ARK_METHOD_METADATA(switchWifi, 1),
|
|
34
|
+
ARK_ASYNC_METHOD_METADATA(isLocationEnabled, 0),
|
|
35
|
+
ARK_ASYNC_METHOD_METADATA(getLocationMode, 0),
|
|
36
|
+
ARK_METHOD_METADATA(switchLocation, 1),
|
|
37
|
+
ARK_ASYNC_METHOD_METADATA(isBluetoothEnabled, 0),
|
|
38
|
+
ARK_METHOD_METADATA(switchBluetooth, 1),
|
|
39
|
+
ARK_METHOD_METADATA(switchBluetoothSilence, 1),
|
|
40
|
+
ARK_ASYNC_METHOD_METADATA(isAirplaneEnabled, 0),
|
|
41
|
+
ARK_METHOD_METADATA(switchAirplane, 1),
|
|
42
|
+
ARK_METHOD_METADATA(openAppSystemSettings, 0),
|
|
43
|
+
ARK_METHOD_METADATA(addBluetoothListener, 0),
|
|
44
|
+
ARK_ASYNC_METHOD_METADATA(addWifiListener, 1),
|
|
45
|
+
ARK_ASYNC_METHOD_METADATA(addLocationListener, 1),
|
|
46
|
+
ARK_ASYNC_METHOD_METADATA(addLocationModeListener, 1),
|
|
47
|
+
ARK_ASYNC_METHOD_METADATA(addAirplaneListener, 1),
|
|
48
|
+
ARK_METHOD_METADATA(removeListener, 1),
|
|
49
|
+
ARK_METHOD_METADATA(addListener, 1),
|
|
50
|
+
ARK_METHOD_METADATA(removeListeners, 1),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
} // namespace rnoh
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was generated by "react-native codegen-harmony"
|
|
3
|
+
*
|
|
4
|
+
* Do not edit this file as changes may cause incorrect behavior and will be
|
|
5
|
+
* lost once the code is regenerated.
|
|
6
|
+
*
|
|
7
|
+
* @generatorVersion: 1
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
#pragma once
|
|
11
|
+
|
|
12
|
+
#include "RNOH/ArkTSTurboModule.h"
|
|
13
|
+
|
|
14
|
+
namespace rnoh {
|
|
15
|
+
|
|
16
|
+
class JSI_EXPORT ReactNativeSystemSetting : public ArkTSTurboModule {
|
|
17
|
+
public:
|
|
18
|
+
ReactNativeSystemSetting(const ArkTSTurboModule::Context ctx, const std::string name);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
} // namespace rnoh
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import hilog from '@ohos.hilog';
|
|
26
|
+
|
|
27
|
+
class Logger {
|
|
28
|
+
private domain : number;
|
|
29
|
+
private prefix : string;
|
|
30
|
+
private format : string = '%{public}s, %{public}s';
|
|
31
|
+
private isDebug : boolean;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* constructor.
|
|
35
|
+
*
|
|
36
|
+
* @param Prefix Identifies the log tag.
|
|
37
|
+
* @param domain Domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFFF.
|
|
38
|
+
*/
|
|
39
|
+
constructor(prefix: string = 'MyApp', domain: number = 0xFF00, isDebug = false) {
|
|
40
|
+
this.prefix = prefix;
|
|
41
|
+
this.domain = domain;
|
|
42
|
+
this.isDebug = isDebug;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
debug(...args: string[]): void {
|
|
46
|
+
if (this.isDebug) {
|
|
47
|
+
hilog.debug(this.domain, this.prefix, this.format, args);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
info(...args: string[]): void {
|
|
52
|
+
hilog.info(this.domain, this.prefix, this.format, args);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
warn(...args: string[]) : void {
|
|
56
|
+
hilog.warn(this.domain, this.prefix, this.format, args);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
error(...args: string[]) : void {
|
|
60
|
+
hilog.error(this.domain, this.prefix, this.format, args);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export default new Logger('RNCSlider', 0xFF00, false)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { RNPackage, TurboModulesFactory } from '@rnoh/react-native-openharmony/ts';
|
|
26
|
+
import type {
|
|
27
|
+
TurboModule,
|
|
28
|
+
TurboModuleContext,
|
|
29
|
+
} from '@rnoh/react-native-openharmony/ts';
|
|
30
|
+
import { TM, RNC } from "./generated/ts"
|
|
31
|
+
import { RNSystemSettingTurboModule } from './RNSystemSettingTurboModule';
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class RNSystemSettingTurboModuleFactory extends TurboModulesFactory {
|
|
35
|
+
createTurboModule(name: string): TurboModule | null {
|
|
36
|
+
if (this.hasTurboModule(name)) {
|
|
37
|
+
globalThis.uiAbilityContext = this.ctx.uiAbilityContext;
|
|
38
|
+
return new RNSystemSettingTurboModule(this.ctx);
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
hasTurboModule(name: string): boolean {
|
|
44
|
+
return name === TM.ReactNativeSystemSetting.NAME;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export class RNSystemSettingPackage extends RNPackage {
|
|
49
|
+
createTurboModulesFactory(ctx: TurboModuleContext): TurboModulesFactory {
|
|
50
|
+
return new RNSystemSettingTurboModuleFactory(ctx);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { TurboModule, TurboModuleContext } from '@rnoh/react-native-openharmony/ts';
|
|
26
|
+
import { TM } from "./generated/ts"
|
|
27
|
+
import window from '@ohos.window';
|
|
28
|
+
import { access } from '@kit.ConnectivityKit';
|
|
29
|
+
import { AbilityLifecycleCallback, common, UIAbility, Want } from '@kit.AbilityKit';
|
|
30
|
+
import { BusinessError } from '@kit.BasicServicesKit';
|
|
31
|
+
import { audio } from '@kit.AudioKit';
|
|
32
|
+
import wifiManager from '@ohos.wifiManager';
|
|
33
|
+
import geoLocationManager from '@ohos.geoLocationManager';
|
|
34
|
+
import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl';
|
|
35
|
+
|
|
36
|
+
export class RNSystemSettingTurboModule extends TurboModule implements TM.ReactNativeSystemSetting.Spec {
|
|
37
|
+
constructor(protected ctx: TurboModuleContext) {
|
|
38
|
+
super(ctx)
|
|
39
|
+
this.setWindowClass()
|
|
40
|
+
this.reqBluetoothPermissions()
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private _windowClass: window.Window | undefined = undefined
|
|
44
|
+
private _context: window.Window | undefined = undefined
|
|
45
|
+
|
|
46
|
+
private async reqBluetoothPermissions(): Promise<void> {
|
|
47
|
+
const permissions: Array<Permissions> = ['ohos.permission.ACCESS_BLUETOOTH'];
|
|
48
|
+
let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager();
|
|
49
|
+
atManager.requestPermissionsFromUser(this.ctx.uiAbilityContext, permissions).catch((err: BusinessError) => {
|
|
50
|
+
console.error(`Failed to request permissions from user. Code is ${err.code}, message is ${err.message}`);
|
|
51
|
+
})
|
|
52
|
+
return
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private async setWindowClass(): Promise<void> {
|
|
56
|
+
let context = this.ctx.uiAbilityContext;
|
|
57
|
+
let promise = await window.getLastWindow(context);
|
|
58
|
+
this._windowClass = promise
|
|
59
|
+
return
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
private startSettingsAppInfoAbilityExplicit(action: string, complete?: () => void) {
|
|
63
|
+
let context = this.ctx.uiAbilityContext;
|
|
64
|
+
let want: Want = {
|
|
65
|
+
bundleName: 'com.huawei.hmos.settings',
|
|
66
|
+
abilityName: 'com.huawei.hmos.settings.MainAbility',
|
|
67
|
+
action: 'action.settings',
|
|
68
|
+
uri: action
|
|
69
|
+
};
|
|
70
|
+
context.startAbility(want)
|
|
71
|
+
.then(() => {
|
|
72
|
+
let applicationContext = context.getApplicationContext();
|
|
73
|
+
let callback: AbilityLifecycleCallback = {
|
|
74
|
+
onWindowStageCreate: (ability: UIAbility, windowStage: window.WindowStage): void => {
|
|
75
|
+
},
|
|
76
|
+
onWindowStageActive: (ability: UIAbility, windowStage: window.WindowStage): void => {
|
|
77
|
+
},
|
|
78
|
+
onWindowStageInactive: (ability: UIAbility, windowStage: window.WindowStage): void => {
|
|
79
|
+
},
|
|
80
|
+
onWindowStageDestroy: (ability: UIAbility, windowStage: window.WindowStage): void => {
|
|
81
|
+
},
|
|
82
|
+
onAbilityDestroy: (ability: UIAbility): void => {
|
|
83
|
+
applicationContext.off('abilityLifecycle', lis)
|
|
84
|
+
},
|
|
85
|
+
onAbilityForeground: (ability: UIAbility): void => {
|
|
86
|
+
console.log('111')
|
|
87
|
+
if (complete) {
|
|
88
|
+
complete()
|
|
89
|
+
}
|
|
90
|
+
console.log('222')
|
|
91
|
+
applicationContext.off('abilityLifecycle', lis)
|
|
92
|
+
},
|
|
93
|
+
onAbilityBackground: (ability: UIAbility): void => {
|
|
94
|
+
},
|
|
95
|
+
onAbilityContinue: (ability: UIAbility): void => {
|
|
96
|
+
},
|
|
97
|
+
onAbilityCreate: (ability: UIAbility): void => {
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const lis = applicationContext.on('abilityLifecycle', callback)
|
|
101
|
+
})
|
|
102
|
+
.catch((err: BusinessError) => {
|
|
103
|
+
console.error(`Failed to startAbility. Code: ${err.code}, message: ${err.message}`);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
getBrightness(): Promise<number> {
|
|
108
|
+
// 待实现
|
|
109
|
+
return
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
setBrightness(val: number): Promise<boolean> {
|
|
113
|
+
// 待实现
|
|
114
|
+
return
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
setBrightnessForce(val: number): Promise<boolean> {
|
|
118
|
+
// 无需实现
|
|
119
|
+
return
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
getAppBrightness(): Promise<number> {
|
|
123
|
+
let properties = this._windowClass.getWindowProperties();
|
|
124
|
+
if (properties.brightness === -1) {
|
|
125
|
+
return Promise.resolve(properties.brightness)
|
|
126
|
+
} else {
|
|
127
|
+
return Promise.resolve(Math.round(255 * properties.brightness))
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
setAppBrightness(val: number): Promise<boolean> {
|
|
132
|
+
if (val === -1) {
|
|
133
|
+
this._windowClass.setWindowBrightness(val)
|
|
134
|
+
.then(() => {
|
|
135
|
+
return Promise.resolve(true)
|
|
136
|
+
})
|
|
137
|
+
.catch(() => {
|
|
138
|
+
return Promise.resolve(false)
|
|
139
|
+
})
|
|
140
|
+
} else {
|
|
141
|
+
const value = val / 255
|
|
142
|
+
this._windowClass.setWindowBrightness(Math.round(value * 1000) / 1000)
|
|
143
|
+
.then(() => {
|
|
144
|
+
return Promise.resolve(true)
|
|
145
|
+
})
|
|
146
|
+
.catch(() => {
|
|
147
|
+
return Promise.resolve(false)
|
|
148
|
+
})
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return Promise.resolve(false)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
grantWriteSettingPremission(): void {
|
|
155
|
+
// 待实现
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
getScreenMode(): Promise<number> {
|
|
159
|
+
// 待实现
|
|
160
|
+
return
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
setScreenMode(val: number): Promise<boolean> {
|
|
164
|
+
this.startSettingsAppInfoAbilityExplicit('display_settings')
|
|
165
|
+
return Promise.resolve(true)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
saveBrightness(): Promise<void> {
|
|
169
|
+
// js层实现
|
|
170
|
+
return
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
restoreBrightness(): number {
|
|
174
|
+
// js层实现
|
|
175
|
+
return
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
getVolume(type: string): Promise<number> {
|
|
179
|
+
let groupid = audio.DEFAULT_VOLUME_GROUP_ID;
|
|
180
|
+
let audioManager = audio.getAudioManager();
|
|
181
|
+
let audioVolumeManager = audioManager.getVolumeManager();
|
|
182
|
+
let audioVolumeGroupManager: audio.AudioVolumeGroupManager;
|
|
183
|
+
const getVolumeGroupManager = async () => {
|
|
184
|
+
audioVolumeGroupManager = await audioVolumeManager.getVolumeGroupManager(groupid);
|
|
185
|
+
let promise
|
|
186
|
+
if (type === 'music' || type === 'system') {
|
|
187
|
+
promise = audioVolumeGroupManager.getVolume(audio.AudioVolumeType.MEDIA)
|
|
188
|
+
} else if (type === 'ring' || type === 'notification') {
|
|
189
|
+
promise = audioVolumeGroupManager.getVolume(audio.AudioVolumeType.RINGTONE);
|
|
190
|
+
} else if (type === 'call') {
|
|
191
|
+
promise = audioVolumeGroupManager.getVolume(audio.AudioVolumeType.VOICE_CALL)
|
|
192
|
+
} else if (type === 'alarm') {
|
|
193
|
+
promise = audioVolumeGroupManager.getVolume(audio.AudioVolumeType.ALARM)
|
|
194
|
+
} else {
|
|
195
|
+
promise = Promise.reject('Argument must be one of "music,system,ring,notification,call,alarm"')
|
|
196
|
+
}
|
|
197
|
+
return promise
|
|
198
|
+
}
|
|
199
|
+
return getVolumeGroupManager();
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
setVolume(value: number, config: Object): void {
|
|
203
|
+
// 待实现
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
addVolumeListener(): void {
|
|
207
|
+
let audioManager = audio.getAudioManager();
|
|
208
|
+
let audioVolumeManager = audioManager.getVolumeManager();
|
|
209
|
+
audioVolumeManager.on('volumeChange', (volumeEvent: audio.VolumeEvent) => {
|
|
210
|
+
if (volumeEvent.volumeType === audio.AudioVolumeType.MEDIA) {
|
|
211
|
+
this.ctx.rnInstance.emitDeviceEvent("EventVolume", {
|
|
212
|
+
value: Math.round(volumeEvent.volume / 15 * 100) / 100,
|
|
213
|
+
system: Math.round(volumeEvent.volume / 15 * 100) / 100,
|
|
214
|
+
music: Math.round(volumeEvent.volume / 15 * 100) / 100,
|
|
215
|
+
})
|
|
216
|
+
} else if (volumeEvent.volumeType === audio.AudioVolumeType.RINGTONE) {
|
|
217
|
+
this.ctx.rnInstance.emitDeviceEvent("EventVolume", {
|
|
218
|
+
value: Math.round(volumeEvent.volume / 15 * 100) / 100,
|
|
219
|
+
ring: Math.round(volumeEvent.volume / 15 * 100) / 100,
|
|
220
|
+
notification: Math.round(volumeEvent.volume / 15 * 100) / 100
|
|
221
|
+
})
|
|
222
|
+
} else if (volumeEvent.volumeType === audio.AudioVolumeType.VOICE_CALL) {
|
|
223
|
+
this.ctx.rnInstance.emitDeviceEvent("EventVolume", {
|
|
224
|
+
value: Math.round(volumeEvent.volume / 15 * 100) / 100,
|
|
225
|
+
call: Math.round(volumeEvent.volume / 15 * 100) / 100
|
|
226
|
+
})
|
|
227
|
+
} else if (volumeEvent.volumeType === audio.AudioVolumeType.ALARM) {
|
|
228
|
+
this.ctx.rnInstance.emitDeviceEvent("EventVolume", {
|
|
229
|
+
value: Math.round(volumeEvent.volume / 15 * 100) / 100,
|
|
230
|
+
alarm: Math.round(volumeEvent.volume / 15 * 100) / 100
|
|
231
|
+
})
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
removeVolumeListener(listener: TM.ReactNativeSystemSetting.EmitterSubscription): void {
|
|
237
|
+
let audioManager = audio.getAudioManager();
|
|
238
|
+
let audioVolumeManager = audioManager.getVolumeManager();
|
|
239
|
+
audioVolumeManager.on('volumeChange', (volumeEvent: audio.VolumeEvent) => {
|
|
240
|
+
// 暂未支持该接口
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
isWifiEnabled(): Promise<boolean> {
|
|
245
|
+
try {
|
|
246
|
+
let isWifiActive = wifiManager.isWifiActive();
|
|
247
|
+
return Promise.resolve(isWifiActive)
|
|
248
|
+
} catch (error) {
|
|
249
|
+
console.error("failed:" + JSON.stringify(error));
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
switchWifiSilence(onComplete: () => void): void {
|
|
255
|
+
// 待实现
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
switchWifi(onComplete: () => void): void {
|
|
259
|
+
if (onComplete) {
|
|
260
|
+
this.startSettingsAppInfoAbilityExplicit('wifi_entry', onComplete)
|
|
261
|
+
} else {
|
|
262
|
+
this.startSettingsAppInfoAbilityExplicit('wifi_entry')
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
isLocationEnabled(): Promise<boolean> {
|
|
267
|
+
let locationEnabled = geoLocationManager.isLocationEnabled();
|
|
268
|
+
return Promise.resolve(locationEnabled)
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
getLocationMode(): Promise<number> {
|
|
272
|
+
throw new Error('Method not implemented.');
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
switchLocation(onComplete: () => void): void {
|
|
276
|
+
if (onComplete) {
|
|
277
|
+
this.startSettingsAppInfoAbilityExplicit('location_manager_settings', onComplete)
|
|
278
|
+
} else {
|
|
279
|
+
this.startSettingsAppInfoAbilityExplicit('location_manager_settings')
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
isBluetoothEnabled(): Promise<boolean> {
|
|
284
|
+
try {
|
|
285
|
+
return Promise.resolve<boolean>(access.getState() === 0 ? false : true)
|
|
286
|
+
} catch (exception) {
|
|
287
|
+
return Promise.reject('Failed to get bluetooth enabled. Cause: ' + JSON.stringify(exception))
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
switchBluetooth(onComplete?: () => void): void {
|
|
292
|
+
if (onComplete) {
|
|
293
|
+
this.startSettingsAppInfoAbilityExplicit('bluetooth_entry', onComplete)
|
|
294
|
+
} else {
|
|
295
|
+
this.startSettingsAppInfoAbilityExplicit('bluetooth_entry')
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
switchBluetoothSilence(onComplete?: () => void): void {
|
|
300
|
+
const bluetoothState = access.getState()
|
|
301
|
+
if (bluetoothState === 0 || bluetoothState === 3) {
|
|
302
|
+
access.enableBluetooth()
|
|
303
|
+
} else if (bluetoothState === 2 || bluetoothState === 1) {
|
|
304
|
+
access.disableBluetooth()
|
|
305
|
+
}
|
|
306
|
+
if (onComplete) {
|
|
307
|
+
onComplete()
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
isAirplaneEnabled(): Promise<boolean> {
|
|
312
|
+
throw new Error('Method not implemented.');
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
switchAirplane(onComplete: () => void): void {
|
|
316
|
+
if (onComplete) {
|
|
317
|
+
this.startSettingsAppInfoAbilityExplicit('mobile_network_entry', onComplete);
|
|
318
|
+
} else {
|
|
319
|
+
this.startSettingsAppInfoAbilityExplicit('mobile_network_entry');
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
openAppSystemSettings(): void {
|
|
324
|
+
this.startSettingsAppInfoAbilityExplicit('application_info_entry');
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
addBluetoothListener(): void {
|
|
328
|
+
access.on('stateChange', e => {
|
|
329
|
+
if (e === 0) {
|
|
330
|
+
this.ctx.rnInstance.emitDeviceEvent("EventBluetooth", false);
|
|
331
|
+
} else if (e === 2) {
|
|
332
|
+
this.ctx.rnInstance.emitDeviceEvent("EventBluetooth", true);
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
addWifiListener(callback: (wifiEnabled: boolean) => void): Promise<TM.ReactNativeSystemSetting.EmitterSubscription | null> {
|
|
338
|
+
throw new Error('Method not implemented.');
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
addLocationListener(callback: (locationEnabled: boolean) => void): Promise<TM.ReactNativeSystemSetting.EmitterSubscription | null> {
|
|
342
|
+
throw new Error('Method not implemented.');
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
addLocationModeListener(callback: (locationMode: number) => void): Promise<TM.ReactNativeSystemSetting.EmitterSubscription | null> {
|
|
346
|
+
throw new Error('Method not implemented.');
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
addAirplaneListener(callback: (airplaneModeEnabled: boolean) => void): Promise<TM.ReactNativeSystemSetting.EmitterSubscription | null> {
|
|
350
|
+
throw new Error('Method not implemented.');
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
removeListener(type): void {
|
|
354
|
+
if (type === 'bluetooth') {
|
|
355
|
+
access.off('stateChange');
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
addListener(eventName: string): void {}
|
|
360
|
+
|
|
361
|
+
removeListeners(count: number): void {}
|
|
362
|
+
}
|