diff --git a/network/DistributedAbility/README.md b/network/DistributedAbility/README.md new file mode 100644 index 0000000000000000000000000000000000000000..6bd402fe58f8c8d31e397a2f44171f73da6ff67c --- /dev/null +++ b/network/DistributedAbility/README.md @@ -0,0 +1,4 @@ +# Device and Service Discovery & Connection + +- This sample demonstrates the discovery and connection of near-field devices and services based on distributed capabilities. + diff --git a/network/DistributedAbility/README_zh.md b/network/DistributedAbility/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..1de5535472ffd18fecf24f860f756349977b221a --- /dev/null +++ b/network/DistributedAbility/README_zh.md @@ -0,0 +1,4 @@ +# 设备和服务的发现 & 连接 + +- 本示例主要通过分布式能力,从而实现近场设备和服务的发现、连接。 + diff --git a/network/DistributedAbility/build.gradle b/network/DistributedAbility/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..264163d3e73fe98369c39d72c4a81e6bfe80d40d --- /dev/null +++ b/network/DistributedAbility/build.gradle @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +apply plugin: 'com.huawei.ohos.app' + +ohos { + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 5 + } +} +buildscript { + repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + jcenter() + } + dependencies { + classpath 'com.huawei.ohos:hap:2.4.4.2' + } +} +allprojects { + repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + jcenter() + } +} \ No newline at end of file diff --git a/network/DistributedAbility/client/build.gradle b/network/DistributedAbility/client/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..1c938769a31cc95b93d64184bc925d2a47d6d8fc --- /dev/null +++ b/network/DistributedAbility/client/build.gradle @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +apply plugin: 'com.huawei.ohos.hap' +ohos { + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 5 + } + buildTypes { + release { + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } + } + } +} +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) +} diff --git a/network/DistributedAbility/client/src/main/config.json b/network/DistributedAbility/client/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..1f9d41aad1ff38b41dd08a9e5b4544570f708850 --- /dev/null +++ b/network/DistributedAbility/client/src/main/config.json @@ -0,0 +1,62 @@ +{ + "app": { + "bundleName": "ohos.samples.distributedclient", + "version": { + "code": 1000000, + "name": "1.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.samples.distributedclient", + "name": ".MainAbility", + "reqCapabilities": [ + "video_support" + ], + "deviceType": [ + "default" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "client", + "moduleType": "entry", + "installationFree":false + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "portrait", + "formsEnabled": false, + "name": ".MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard" + } + ], + "reqPermissions": [ + { + "name": "ohos.permission.DISTRIBUTED_DEVICE_STATE_CHANGE" + }, + { + "name": "ohos.permission.GET_DISTRIBUTED_DEVICE_INFO" + }, + { + "name": "ohos.permission.GET_BUNDLE_INFO" + }, + { + "name": "ohos.permission.DISTRIBUTED_DATASYNC" + } + ] + } +} \ No newline at end of file diff --git a/network/DistributedAbility/client/src/main/idl/ohos/samples/distributedserver/IRemoteAgent.idl b/network/DistributedAbility/client/src/main/idl/ohos/samples/distributedserver/IRemoteAgent.idl new file mode 100644 index 0000000000000000000000000000000000000000..a6545b53883b4895dfac6cb8c7b014c816edabbc --- /dev/null +++ b/network/DistributedAbility/client/src/main/idl/ohos/samples/distributedserver/IRemoteAgent.idl @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// IRemoteAgent.idl + +// Declare any non-default types here with sequenceable or interface statements + +interface ohos.samples.distributedserver.IRemoteAgent { + /* + * Demo service method use some parameters + */ + void setRemoteObject(); +} \ No newline at end of file diff --git a/network/DistributedAbility/client/src/main/java/ohos/samples/distributedclient/DevicePlugin.java b/network/DistributedAbility/client/src/main/java/ohos/samples/distributedclient/DevicePlugin.java new file mode 100644 index 0000000000000000000000000000000000000000..441976ac36b9ad69351f72a82e3b53f09e167c53 --- /dev/null +++ b/network/DistributedAbility/client/src/main/java/ohos/samples/distributedclient/DevicePlugin.java @@ -0,0 +1,183 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos.samples.distributedclient; + +import ohos.samples.distributedclient.interfaces.DeviceListener; +import ohos.samples.distributedclient.utils.LogUtil; +import ohos.samples.distributedserver.RemoteAgentProxy; +import ohos.samples.distributedserver.RemoteAgentStub; + +import ohos.aafwk.ability.IAbilityConnection; +import ohos.aafwk.content.Intent; +import ohos.aafwk.content.Operation; +import ohos.app.Context; +import ohos.bundle.ElementName; +import ohos.distributedschedule.interwork.DeviceInfo; +import ohos.distributedschedule.interwork.DeviceManager; +import ohos.distributedschedule.interwork.IDeviceStateCallback; +import ohos.rpc.IRemoteObject; +import ohos.rpc.RemoteException; + +import java.util.List; + +/** + * Device Plugin class + */ +public class DevicePlugin { + private static final String TAG = DevicePlugin.class.getSimpleName(); + + private static final String REMOTE_BUNDLE_NAME = "ohos.samples.distributedserver"; + + private static final String REMOTE_ABILITY_NAME = "ohos.samples.distributedserver.RemoteAbility"; + + private static volatile DevicePlugin instance = null; + + private List deviceInfoList; + + private Context context; + + private String remoteDeviceId; + + private DeviceListener listener; + + private IAbilityConnection connection = new IAbilityConnection() { + @Override + public void onAbilityConnectDone(ElementName elementName, IRemoteObject iRemoteObject, int resultCode) { + LogUtil.info(TAG, "onAbilityConnectDone resultCode:" + resultCode); + RemoteAgentProxy remoteAgentProxy = new RemoteAgentProxy(iRemoteObject); + try { + remoteAgentProxy.setRemoteObject(); + } catch (RemoteException e) { + LogUtil.error(TAG, "onAbilityConnectDone RemoteException"); + } + listener.updateResult("Connect " + (resultCode == 0 ? "Success" : "Failed")); + } + + @Override + public void onAbilityDisconnectDone(ElementName elementName, int resultCode) { + LogUtil.info(TAG, "ability disconnect done "); + listener.updateResult("Disconnect " + (resultCode == 0 ? "Success" : "Failed")); + } + }; + + private IDeviceStateCallback iDeviceStateCallback = new IDeviceStateCallback() { + @Override + public void onDeviceOffline(String deviceId, int deviceType) { + LogUtil.info(TAG, "onDeviceOffline , deviceId: " + deviceId); + DeviceInfo deviceInfo = DeviceManager.getDeviceInfo(deviceId); + listener.updateResult("Offline : " + (deviceInfo == null ? "Unknown" : deviceInfo.getDeviceName())); + } + + @Override + public void onDeviceOnline(String deviceId, int deviceType) { + LogUtil.info(TAG, "onDeviceOnline , deviceId: " + deviceId); + DeviceInfo deviceInfo = DeviceManager.getDeviceInfo(deviceId); + listener.updateResult("Online : " + (deviceInfo == null ? "Unknown" : deviceInfo.getDeviceName())); + } + }; + + /** + * scan remote ability devices list + * + * @return current distribute net device list + */ + public List scanRemoteAbility() { + deviceInfoList = DeviceManager.getDeviceList(DeviceInfo.FLAG_GET_ALL_DEVICE); + return deviceInfoList; + } + + /** + * connect remote ability + * + * @param deviceInfo remoteAbility device info. + * @param context context. + */ + public void connectAbility(Context context, DeviceInfo deviceInfo) { + remoteDeviceId = deviceInfo.getDeviceId(); + Intent intent = new Intent(); + Operation operation = new Intent.OperationBuilder().withDeviceId(remoteDeviceId) + .withBundleName(REMOTE_BUNDLE_NAME) + .withAbilityName(REMOTE_ABILITY_NAME) + .withFlags(Intent.FLAG_ABILITYSLICE_MULTI_DEVICE) + .build(); + intent.setOperation(operation); + intent.setParam("ClientDeviceName", deviceInfo.getDeviceName()); + context.connectAbility(intent, connection); + } + + /** + * disconnect remote ability + * + * @return connect result + */ + public boolean stopRemoteConnectedAbility() { + if (connection != null) { + context.disconnectAbility(connection); + LogUtil.info(TAG, "stopRemoteConnectAbility"); + } + return true; + } + + /** + * init device listener + * + * @param deviceListener device listener + */ + public void initListener(DeviceListener deviceListener) { + listener = deviceListener; + } + + /** + * register device state listener + */ + public void registerDeviceStateListener() { + boolean registerResult = DeviceManager.registerDeviceStateCallback(iDeviceStateCallback); + listener.updateResult("Register " + (registerResult ? "Success" : "Failed")); + } + + /** + * unregister device state listener + */ + public void unRegisterDeviceStateListener() { + boolean unRegisterResult = DeviceManager.unregisterDeviceStateCallback(iDeviceStateCallback); + listener.updateResult("UnRegister " + (unRegisterResult ? "Success" : "Failed")); + } + + /** + * Register context + * + * @param context context. + */ + public void register(Context context) { + this.context = context; + } + + /** + * Constructor used to create a DeviceManagerPlugin instance. + * + * @return instance of DeviceManagerPlugin + */ + public static DevicePlugin getInstance() { + if (instance == null) { + synchronized (DevicePlugin.class) { + if (instance == null) { + instance = new DevicePlugin(); + } + } + } + return instance; + } +} diff --git a/network/DistributedAbility/client/src/main/java/ohos/samples/distributedclient/MainAbility.java b/network/DistributedAbility/client/src/main/java/ohos/samples/distributedclient/MainAbility.java new file mode 100644 index 0000000000000000000000000000000000000000..80363c44b5dec38bf94e637f771311bacdc320fc --- /dev/null +++ b/network/DistributedAbility/client/src/main/java/ohos/samples/distributedclient/MainAbility.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos.samples.distributedclient; + +import ohos.samples.distributedclient.slice.MainAbilitySlice; + +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; +import ohos.bundle.IBundleManager; +import ohos.security.SystemPermission; + +/** + * MainAbility + */ +public class MainAbility extends Ability { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setMainRoute(MainAbilitySlice.class.getName()); + + requestPermission(); + } + + private void requestPermission() { + if (verifySelfPermission(SystemPermission.DISTRIBUTED_DATASYNC) != IBundleManager.PERMISSION_GRANTED) { + requestPermissionsFromUser(new String[] {SystemPermission.DISTRIBUTED_DATASYNC}, 0); + } + } +} \ No newline at end of file diff --git a/network/DistributedAbility/client/src/main/java/ohos/samples/distributedclient/interfaces/DeviceListener.java b/network/DistributedAbility/client/src/main/java/ohos/samples/distributedclient/interfaces/DeviceListener.java new file mode 100644 index 0000000000000000000000000000000000000000..95e7de4d4330b905ca06bf957ffaf006ba61d400 --- /dev/null +++ b/network/DistributedAbility/client/src/main/java/ohos/samples/distributedclient/interfaces/DeviceListener.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos.samples.distributedclient.interfaces; + +/** + * WifiEventListener + * Handles the callbacks for wifi events + */ +public interface DeviceListener { + void updateResult(String message); +} diff --git a/network/DistributedAbility/client/src/main/java/ohos/samples/distributedclient/provider/DeviceProvider.java b/network/DistributedAbility/client/src/main/java/ohos/samples/distributedclient/provider/DeviceProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..e84cbcc2d4951d8311067c822ed57e954293bdbf --- /dev/null +++ b/network/DistributedAbility/client/src/main/java/ohos/samples/distributedclient/provider/DeviceProvider.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos.samples.distributedclient.provider; + +import ohos.samples.distributedclient.DevicePlugin; +import ohos.samples.distributedclient.ResourceTable; +import ohos.samples.distributedclient.slice.MainAbilitySlice; + +import ohos.agp.components.Component; +import ohos.agp.components.ComponentContainer; +import ohos.agp.components.LayoutScatter; +import ohos.agp.components.RecycleItemProvider; +import ohos.agp.components.Text; +import ohos.app.Context; +import ohos.distributedschedule.interwork.DeviceInfo; + +import java.util.List; + +/** + * DeviceProvider + */ +public class DeviceProvider extends RecycleItemProvider { + private Context context; + + private List deviceInfoList; + + private DevicePlugin devicePlugin; + + public DeviceProvider(MainAbilitySlice mainAbilitySlice, List deviceInfoList, + DevicePlugin devicePlugin) { + this.context = mainAbilitySlice; + this.deviceInfoList = deviceInfoList; + this.devicePlugin = devicePlugin; + } + + @Override + public int getCount() { + return deviceInfoList.size(); + } + + @Override + public Object getItem(int position) { + return deviceInfoList.get(position); + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public Component getComponent(int position, Component component, ComponentContainer componentContainer) { + return getItemComponent(position); + } + + private Component getItemComponent(int position) { + DeviceInfo item = deviceInfoList.get(position); + Component container = LayoutScatter.getInstance(context).parse(ResourceTable.Layout_list_item, null, false); + Text deviceName = (Text) container.findComponentById(ResourceTable.Id_device_name); + Text deviceId = (Text) container.findComponentById(ResourceTable.Id_device_id); + deviceName.setText(item.getDeviceName() == null ? "Unknown" : item.getDeviceName()); + deviceId.setText(item.getDeviceId()); + container.setClickedListener(component -> devicePlugin.connectAbility(context, item)); + return container; + } + + /** + * update provider data + * + * @param data deviceInfo list data + */ + public void updateData(List data) { + this.deviceInfoList = data; + notifyDataChanged(); + } +} + + diff --git a/network/DistributedAbility/client/src/main/java/ohos/samples/distributedclient/slice/MainAbilitySlice.java b/network/DistributedAbility/client/src/main/java/ohos/samples/distributedclient/slice/MainAbilitySlice.java new file mode 100644 index 0000000000000000000000000000000000000000..9326d38bacc1e929ff689c46a102b49180b007e7 --- /dev/null +++ b/network/DistributedAbility/client/src/main/java/ohos/samples/distributedclient/slice/MainAbilitySlice.java @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos.samples.distributedclient.slice; + +import ohos.samples.distributedclient.DevicePlugin; +import ohos.samples.distributedclient.ResourceTable; +import ohos.samples.distributedclient.interfaces.DeviceListener; +import ohos.samples.distributedclient.provider.DeviceProvider; + +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import ohos.agp.components.Button; +import ohos.agp.components.Component; +import ohos.agp.components.LayoutScatter; +import ohos.agp.components.ListContainer; +import ohos.agp.components.Text; +import ohos.agp.window.dialog.CommonDialog; +import ohos.agp.window.dialog.ToastDialog; +import ohos.distributedschedule.interwork.DeviceInfo; +import ohos.eventhandler.EventHandler; +import ohos.eventhandler.EventRunner; +import ohos.eventhandler.InnerEvent; + +import java.util.ArrayList; +import java.util.List; + +/** + * MainAbilitySlice + */ +public class MainAbilitySlice extends AbilitySlice implements DeviceListener { + private static final int DIALOG_WIDTH = 900; + + private static final int DIALOG_HEIGHT = 300; + + private static final int DIALOG_CORNER_RADIUS = 30; + + private static final int UPDATE_RESULT_MESSAGE = 0x1000001; + + private DevicePlugin devicePlugin; + + private List deviceInfoList = new ArrayList<>(); + + private DeviceProvider deviceProvider; + + private String dialogMessage; + + private EventHandler handler = new EventHandler(EventRunner.current()) { + @Override + protected void processEvent(InnerEvent event) { + showDialog(dialogMessage); + scanRemoteAbility(false); + } + }; + + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_main_layout); + + initDevicePlugin(); + initComponents(); + } + + private void initDevicePlugin() { + devicePlugin = DevicePlugin.getInstance(); + devicePlugin.register(this); + devicePlugin.initListener(this); + } + + private void initComponents() { + Component scanBtn = findComponentById(ResourceTable.Id_scan_btn); + Component registerBtn = findComponentById(ResourceTable.Id_register_change_btn); + Component unRegisterBtn = findComponentById(ResourceTable.Id_unregister_btn); + Component unDisconnectBtn = findComponentById(ResourceTable.Id_disconnect_btn); + registerBtn.setClickedListener(component -> devicePlugin.registerDeviceStateListener()); + unRegisterBtn.setClickedListener(component -> devicePlugin.unRegisterDeviceStateListener()); + unDisconnectBtn.setClickedListener(component -> devicePlugin.stopRemoteConnectedAbility()); + scanBtn.setClickedListener(component -> scanRemoteAbility(true)); + deviceProvider = new DeviceProvider(this, deviceInfoList, devicePlugin); + ListContainer listContainer = (ListContainer) findComponentById(ResourceTable.Id_container_list); + listContainer.setItemProvider(deviceProvider); + } + + private void scanRemoteAbility(boolean showToast) { + deviceInfoList = devicePlugin.scanRemoteAbility(); + deviceProvider.updateData(deviceInfoList); + if (showToast) { + showTip("scan deviceInfoList size : " + deviceInfoList.size()); + } + } + + private void showTip(String msg) { + new ToastDialog(this).setContentText(msg).show(); + } + + @Override + public void updateResult(String message) { + dialogMessage = message; + handler.sendEvent(UPDATE_RESULT_MESSAGE); + } + + private void showDialog(String message) { + Component container = LayoutScatter.getInstance(this).parse(ResourceTable.Layout_dialog_layout, null, false); + Text content = (Text) container.findComponentById(ResourceTable.Id_message); + content.setText(message); + CommonDialog commonDialog = new CommonDialog(this); + commonDialog.setSize(DIALOG_WIDTH, DIALOG_HEIGHT); + commonDialog.setCornerRadius(DIALOG_CORNER_RADIUS); + commonDialog.setContentCustomComponent(container); + commonDialog.show(); + Button btnOk = (Button) container.findComponentById(ResourceTable.Id_btn_ok); + btnOk.setClickedListener(component -> commonDialog.hide()); + } +} diff --git a/network/DistributedAbility/client/src/main/java/ohos/samples/distributedclient/utils/LogUtil.java b/network/DistributedAbility/client/src/main/java/ohos/samples/distributedclient/utils/LogUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..2e12978e073fac5615ba19e6b0c33b87cf68613b --- /dev/null +++ b/network/DistributedAbility/client/src/main/java/ohos/samples/distributedclient/utils/LogUtil.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos.samples.distributedclient.utils; + +import ohos.hiviewdfx.HiLog; +import ohos.hiviewdfx.HiLogLabel; + +import java.util.Locale; + +/** + * Log utils + */ +public class LogUtil { + private static final String TAG_LOG = "[DistributedClient] "; + + private static final int DOMAIN_ID = 0xD000F00; + + private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, DOMAIN_ID, LogUtil.TAG_LOG); + + private static final String LOG_FORMAT = "%s: %s"; + + private LogUtil() { + } + /** + * Print info log + * + * @param tag log tag + * @param msg log message + */ + public static void info(String tag, String msg) { + HiLog.info(LABEL_LOG, String.format(Locale.ROOT, LOG_FORMAT, tag, msg)); + } + + /** + * Print error log + * + * @param tag log tag + * @param msg log message + */ + public static void error(String tag, String msg) { + HiLog.error(LABEL_LOG, String.format(Locale.ROOT, LOG_FORMAT, tag, msg)); + } +} diff --git a/network/DistributedAbility/client/src/main/resources/base/element/string.json b/network/DistributedAbility/client/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..e66260c9906c504503edbb044ddeab2c877abde1 --- /dev/null +++ b/network/DistributedAbility/client/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "DistributedAbility" + }, + { + "name": "mainability_description", + "value": "hap sample empty page" + } + ] +} \ No newline at end of file diff --git a/network/DistributedAbility/client/src/main/resources/base/graphic/bg.xml b/network/DistributedAbility/client/src/main/resources/base/graphic/bg.xml new file mode 100644 index 0000000000000000000000000000000000000000..d5138e190734b0fa268ca98ab449e8be012016ac --- /dev/null +++ b/network/DistributedAbility/client/src/main/resources/base/graphic/bg.xml @@ -0,0 +1,25 @@ + + + + + + + \ No newline at end of file diff --git a/network/DistributedAbility/client/src/main/resources/base/layout/dialog_layout.xml b/network/DistributedAbility/client/src/main/resources/base/layout/dialog_layout.xml new file mode 100644 index 0000000000000000000000000000000000000000..23a642962769463c2ce9876cd8b2afd18fee29ba --- /dev/null +++ b/network/DistributedAbility/client/src/main/resources/base/layout/dialog_layout.xml @@ -0,0 +1,49 @@ + + + + + + + + +