diff --git a/ability/ForegroundService/README_en.md b/ability/ForegroundService/README_en.md
new file mode 100644
index 0000000000000000000000000000000000000000..2cc1272a806799a927d8ca9dff11e5dcdc54763e
--- /dev/null
+++ b/ability/ForegroundService/README_en.md
@@ -0,0 +1,24 @@
+# Foreground Service
+
+
+
+##### Introduction
+
+This sample describes how to use a foreground Service ability for a music player.
+
+In certain scenarios, a foreground Service ability is required, for example, when the user expects to keep a music player app running. When a foreground Service ability is running for an app, the status bar shows an icon indicating that the app is running.
+
+##### Usage Guidelines
+
+In this sample, there are three buttons on the home screen:
+
+**Start Play**: starts the foreground Service ability and plays music.
+
+**Pause Play**: pauses music playback, while the foreground Service ability continues to run.
+
+**Stop Play**: stops music playback and closes the foreground Service ability.
+
+##### Constraints
+
+This sample can be run only on the standard system.
+
diff --git a/ability/ForegroundService/README_zh.md b/ability/ForegroundService/README_zh.md
new file mode 100644
index 0000000000000000000000000000000000000000..961ba7fec10d0fb81dbaf13ec10566352865572a
--- /dev/null
+++ b/ability/ForegroundService/README_zh.md
@@ -0,0 +1,23 @@
+# 前台服务
+
+
+
+##### 简介
+
+本示例通过音乐播放器,展示了前台Service的使用方法。
+
+一般情况下Service都是在后台运行的,后台Service优先级都是比较低的,当资源不足时,系统有可能回收
+
+正在运行的后台Service。一些场景下(如:播放音乐),用户希望应用一直运行,此时就需要用到前台
+
+Service。前台Service会使用保持正在运行的图标在系统状态栏显示。
+
+##### 使用说明
+
+本示例主界面分为三个按钮,点击Start Play按钮会启动前台服务并播放音乐,点击Pause Play按钮会暂停
+
+播放音乐,前台服务继续运行,点击Stop Play按钮会停止播放音乐并关闭前台服务。
+
+##### 约束与限制
+
+本示例仅支持在标准系统上运行。
\ No newline at end of file
diff --git a/ability/ForegroundService/build.gradle b/ability/ForegroundService/build.gradle
new file mode 100644
index 0000000000000000000000000000000000000000..9985d7a1fb40679434cae5e9787ab1565b0c9699
--- /dev/null
+++ b/ability/ForegroundService/build.gradle
@@ -0,0 +1,35 @@
+// 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 4
+ }
+}
+
+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/ability/ForegroundService/entry/build.gradle b/ability/ForegroundService/entry/build.gradle
new file mode 100644
index 0000000000000000000000000000000000000000..83f59debbd68242b503a22270f4378d7843ca204
--- /dev/null
+++ b/ability/ForegroundService/entry/build.gradle
@@ -0,0 +1,19 @@
+apply plugin: 'com.huawei.ohos.hap'
+ohos {
+ compileSdkVersion 5
+ defaultConfig {
+ compatibleSdkVersion 4
+ }
+ buildTypes {
+ release {
+ proguardOpt {
+ proguardEnabled false
+ rulesFiles 'proguard-rules.pro'
+ }
+ }
+ }
+}
+
+dependencies {
+ implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
+}
\ No newline at end of file
diff --git a/ability/ForegroundService/entry/src/main/config.json b/ability/ForegroundService/entry/src/main/config.json
new file mode 100644
index 0000000000000000000000000000000000000000..72b0352d21dd462204fb2b7f3683e280a82aae7c
--- /dev/null
+++ b/ability/ForegroundService/entry/src/main/config.json
@@ -0,0 +1,66 @@
+{
+ "app": {
+ "bundleName": "ohos.samples.foregroundservice",
+ "version": {
+ "code": 1000000,
+ "name": "1.0"
+ }
+ },
+ "deviceConfig": {},
+ "module": {
+ "package": "ohos.samples.foregroundservice",
+ "name": ".MyApplication",
+ "deviceType": [
+ "default"
+ ],
+ "distro": {
+ "deliveryWithInstall": true,
+ "moduleName": "entry",
+ "moduleType": "entry"
+ },
+ "abilities": [
+ {
+ "skills": [
+ {
+ "entities": [
+ "entity.system.home"
+ ],
+ "actions": [
+ "action.system.home"
+ ]
+ }
+ ],
+ "orientation": "portrait",
+ "name": "ohos.samples.foregroundservice.MainAbility",
+ "icon": "$media:icon",
+ "description": "$string:mainability_description",
+ "label": "$string:app_name",
+ "type": "page",
+ "launchType": "standard"
+ },
+ {
+ "name": "ohos.samples.foregroundservice.ServiceAbility",
+ "icon": "$media:icon",
+ "description": "$string:serviceability_description",
+ "type": "service",
+ "visible": true,
+ "backgroundModes": [
+ "dataTransfer",
+ "location"
+ ]
+ }
+ ],
+ "reqPermissions": [
+ {
+ "name": "ohos.permission.KEEP_BACKGROUND_RUNNING",
+ "reason": "get right",
+ "usedScene": {
+ "ability": [
+ ".ServiceAbility"
+ ],
+ "when": "inuse"
+ }
+ }
+ ]
+ }
+}
\ No newline at end of file
diff --git a/ability/ForegroundService/entry/src/main/java/ohos/samples/foregroundservice/MainAbility.java b/ability/ForegroundService/entry/src/main/java/ohos/samples/foregroundservice/MainAbility.java
new file mode 100644
index 0000000000000000000000000000000000000000..6c832256416b5cc8a74d0dbd60c88507146be48c
--- /dev/null
+++ b/ability/ForegroundService/entry/src/main/java/ohos/samples/foregroundservice/MainAbility.java
@@ -0,0 +1,33 @@
+/*
+ * 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.foregroundservice;
+
+import ohos.aafwk.ability.Ability;
+import ohos.aafwk.content.Intent;
+import ohos.samples.foregroundservice.slice.MainAbilitySlice;
+
+/**
+ * MainAbility
+ *
+ * @since 2021-05-08
+ */
+public class MainAbility extends Ability {
+ @Override
+ public void onStart(Intent intent) {
+ super.onStart(intent);
+ super.setMainRoute(MainAbilitySlice.class.getName());
+ }
+}
diff --git a/ability/ForegroundService/entry/src/main/java/ohos/samples/foregroundservice/MyApplication.java b/ability/ForegroundService/entry/src/main/java/ohos/samples/foregroundservice/MyApplication.java
new file mode 100644
index 0000000000000000000000000000000000000000..0408c8010bb334856d5332f11ace3ea3c638ecd5
--- /dev/null
+++ b/ability/ForegroundService/entry/src/main/java/ohos/samples/foregroundservice/MyApplication.java
@@ -0,0 +1,30 @@
+/*
+ * 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.foregroundservice;
+
+import ohos.aafwk.ability.AbilityPackage;
+
+/**
+ * MyApplication
+ *
+ * @since 2021-05-08
+ */
+public class MyApplication extends AbilityPackage {
+ @Override
+ public void onInitialize() {
+ super.onInitialize();
+ }
+}
diff --git a/ability/ForegroundService/entry/src/main/java/ohos/samples/foregroundservice/ServiceAbility.java b/ability/ForegroundService/entry/src/main/java/ohos/samples/foregroundservice/ServiceAbility.java
new file mode 100644
index 0000000000000000000000000000000000000000..bacc025e31b41c074c4dbb3e7f7f05fd53317ef9
--- /dev/null
+++ b/ability/ForegroundService/entry/src/main/java/ohos/samples/foregroundservice/ServiceAbility.java
@@ -0,0 +1,244 @@
+/*
+ * 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.foregroundservice;
+
+import static ohos.samples.foregroundservice.slice.MainAbilitySlice.EVENT_ACTION;
+
+import ohos.aafwk.ability.Ability;
+import ohos.aafwk.ability.LocalRemoteObject;
+import ohos.aafwk.content.Intent;
+import ohos.aafwk.content.Operation;
+import ohos.agp.utils.Color;
+import ohos.event.commonevent.CommonEventData;
+import ohos.event.commonevent.CommonEventManager;
+import ohos.event.notification.NotificationHelper;
+import ohos.event.notification.NotificationRequest;
+import ohos.event.notification.NotificationSlot;
+import ohos.global.resource.RawFileDescriptor;
+import ohos.hiviewdfx.HiLog;
+import ohos.hiviewdfx.HiLogLabel;
+import ohos.media.common.Source;
+import ohos.media.player.Player;
+import ohos.rpc.IRemoteObject;
+import ohos.rpc.RemoteException;
+
+import java.io.IOException;
+
+/**
+ * Music Play Service
+ *
+ * @since 2021-05-08
+ */
+public class ServiceAbility extends Ability {
+ /**
+ * Music PlayState
+ */
+ public static final int PLAY_STATE = 0;
+
+ /**
+ * Music PauseState
+ */
+ public static final int PAUSE_STATE = 1;
+
+ /**
+ * Music StopState
+ */
+ public static final int STOP_STATE = 2;
+
+ private static final String TAG = "ServiceAbility";
+
+ private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, 0xD000F00, TAG);
+
+ private int state = STOP_STATE;
+
+ private Player player;
+
+ @Override
+ public void onStart(Intent intent) {
+ super.onStart(intent);
+ }
+
+ @Override
+ public void onCommand(Intent intent, boolean isRestart, int startId) {
+ super.onCommand(intent, isRestart, startId);
+ sendEvent();
+ }
+
+ @Override
+ public IRemoteObject onConnect(Intent intent) {
+ return new MusicRemoteObject(this);
+ }
+
+ @Override
+ public void onDisconnect(Intent intent) {
+ super.onDisconnect(intent);
+ }
+
+ @Override
+ public void onStop() {
+ super.onStop();
+ cancelNotification();
+ if (player != null) {
+ player.release();
+ player = null;
+ }
+ }
+
+ private void sendEvent() {
+ try {
+ Intent intent = new Intent();
+ Operation operation = new Intent.OperationBuilder()
+ .withAction(EVENT_ACTION)
+ .build();
+ intent.setOperation(operation);
+ intent.setParam("state", state);
+ CommonEventData eventData = new CommonEventData(intent);
+ CommonEventManager.publishCommonEvent(eventData);
+ } catch (RemoteException e) {
+ HiLog.error(LABEL_LOG, "Exception occurred during publishCommonEvent invocation.");
+ }
+ }
+
+ private void sendNotification(String str) {
+ String slotId = "foregroundServiceId";
+ String slotName = "foregroundServiceName";
+ NotificationSlot slot = new NotificationSlot(slotId, slotName, NotificationSlot.LEVEL_MIN);
+ slot.setDescription("NotificationSlot Description");
+ slot.setEnableVibration(true);
+ slot.setLockscreenVisibleness(NotificationRequest.VISIBLENESS_TYPE_PUBLIC);
+ slot.setEnableLight(true);
+ slot.setLedLightColor(Color.RED.getValue());
+ try {
+ NotificationHelper.addNotificationSlot(slot);
+ } catch (RemoteException ex) {
+ HiLog.error(LABEL_LOG, "Exception occurred during addNotificationSlot invocation.");
+ }
+ int notificationId = 1;
+ NotificationRequest request = new NotificationRequest(notificationId);
+ request.setSlotId(slot.getId());
+ String title = "Music Player";
+ String text = "The Music Service is in " + str;
+ NotificationRequest.NotificationNormalContent content = new NotificationRequest.NotificationNormalContent();
+ content.setTitle(title)
+ .setText(text);
+ NotificationRequest.NotificationContent notificationContent =
+ new NotificationRequest.NotificationContent(content);
+ request.setContent(notificationContent);
+ keepBackgroundRunning(notificationId, request);
+ }
+
+ private void cancelNotification() {
+ cancelBackgroundRunning();
+ }
+
+ /**
+ * Start Play Music
+ */
+ public void startMusic() {
+ if (state != STOP_STATE) {
+ return;
+ }
+ player = new Player(getContext());
+ try {
+ RawFileDescriptor filDescriptor;
+ filDescriptor = getResourceManager().getRawFileEntry("resources/rawfile/Homey.mp3").openRawFileDescriptor();
+ Source source = new Source(filDescriptor.getFileDescriptor(), filDescriptor.getStartPosition(),
+ filDescriptor.getFileSize());
+ player.setSource(source);
+ player.prepare();
+ player.play();
+ player.enableSingleLooping(true);
+ state = PLAY_STATE;
+ sendNotification("Playing");
+ sendEvent();
+ } catch (IOException e) {
+ HiLog.error(LABEL_LOG, "Exception occurred during openRawFileDescriptor invocation.");
+ }
+ }
+
+ /**
+ * Stop Play Music
+ */
+ public void stopMusic() {
+ if (state == STOP_STATE) {
+ return;
+ }
+ player.stop();
+ player.release();
+ player = null;
+ state = STOP_STATE;
+ cancelNotification();
+ sendEvent();
+ }
+
+ /**
+ * Pause Play Music
+ */
+ public void pauseMusic() {
+ switch (state) {
+ case PAUSE_STATE: {
+ player.play();
+ state = PLAY_STATE;
+ sendNotification("Playing");
+ sendEvent();
+ break;
+ }
+ case PLAY_STATE: {
+ player.pause();
+ state = PAUSE_STATE;
+ sendNotification("Pausing");
+ sendEvent();
+ break;
+ }
+ default:
+ break;
+ }
+ }
+
+ /**
+ * LocalRemoteObject Implementation
+ *
+ * @since 2021-05-08
+ */
+ public static class MusicRemoteObject extends LocalRemoteObject {
+ private final ServiceAbility musicService;
+
+ MusicRemoteObject(ServiceAbility musicService) {
+ this.musicService = musicService;
+ }
+
+ /**
+ * startPlay Music
+ */
+ public void startPlay() {
+ musicService.startMusic();
+ }
+
+ /**
+ * pausePlay Music
+ */
+ public void pausePlay() {
+ musicService.pauseMusic();
+ }
+
+ /**
+ * stopPlay Music
+ */
+ public void stopPlay() {
+ musicService.stopMusic();
+ }
+ }
+}
\ No newline at end of file
diff --git a/ability/ForegroundService/entry/src/main/java/ohos/samples/foregroundservice/slice/MainAbilitySlice.java b/ability/ForegroundService/entry/src/main/java/ohos/samples/foregroundservice/slice/MainAbilitySlice.java
new file mode 100644
index 0000000000000000000000000000000000000000..36a096e08efa7cb654056d7af2ba1d5121e25874
--- /dev/null
+++ b/ability/ForegroundService/entry/src/main/java/ohos/samples/foregroundservice/slice/MainAbilitySlice.java
@@ -0,0 +1,209 @@
+/*
+ * 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.foregroundservice.slice;
+
+import static ohos.samples.foregroundservice.ServiceAbility.PAUSE_STATE;
+import static ohos.samples.foregroundservice.ServiceAbility.PLAY_STATE;
+import static ohos.samples.foregroundservice.ServiceAbility.STOP_STATE;
+
+import ohos.aafwk.ability.AbilitySlice;
+import ohos.aafwk.ability.IAbilityConnection;
+import ohos.aafwk.content.Intent;
+import ohos.aafwk.content.Operation;
+import ohos.agp.components.Button;
+import ohos.agp.components.Component;
+import ohos.bundle.ElementName;
+import ohos.event.commonevent.CommonEventData;
+import ohos.event.commonevent.CommonEventManager;
+import ohos.event.commonevent.CommonEventSubscribeInfo;
+import ohos.event.commonevent.CommonEventSubscriber;
+import ohos.event.commonevent.MatchingSkills;
+import ohos.hiviewdfx.HiLog;
+import ohos.hiviewdfx.HiLogLabel;
+import ohos.rpc.IRemoteObject;
+import ohos.rpc.RemoteException;
+import ohos.samples.foregroundservice.ResourceTable;
+import ohos.samples.foregroundservice.ServiceAbility;
+
+/**
+ * MainAbilitySlice
+ *
+ * @since 2021-05-08
+ */
+public class MainAbilitySlice extends AbilitySlice {
+ /**
+ * Event Action Name
+ */
+ public static final String EVENT_ACTION = "ohos.samples.forgroundservice";
+
+ private static final String BUNDLE_NAME = "ohos.samples.foregroundservice";
+
+ private static final String ABILITY_NAME = "ohos.samples.foregroundservice.ServiceAbility";
+
+ private static final String TAG = "MainAbilitySlice";
+
+ private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, 0xD000F00, TAG);
+
+ private static final int DEFAULT_STATE = -1;
+
+ private Button startPlay;
+
+ private Button pausePlay;
+
+ private Button stopPlay;
+
+ private ServiceAbility.MusicRemoteObject musicRemoteObject;
+
+ private MyCommonEventSubscriber subscriber;
+
+ private int lastState = DEFAULT_STATE;
+
+ private final IAbilityConnection connection = new IAbilityConnection() {
+ @Override
+ public void onAbilityConnectDone(ElementName elementName, IRemoteObject remoteObject, int i) {
+ if (remoteObject instanceof ServiceAbility.MusicRemoteObject) {
+ musicRemoteObject = (ServiceAbility.MusicRemoteObject) remoteObject;
+ }
+ }
+
+ @Override
+ public void onAbilityDisconnectDone(ElementName elementName, int i) {
+ HiLog.info(LABEL_LOG, "onAbilityDisconnectDone.");
+ }
+ };
+
+ @Override
+ public void onStart(Intent intent) {
+ super.onStart(intent);
+ super.setUIContent(ResourceTable.Layout_main_ability_slice);
+ initView();
+ initEventListener();
+ initSubscribeEvent();
+ startService();
+ }
+
+ private void startService() {
+ Intent intent = new Intent();
+ Operation operation = new Intent.OperationBuilder()
+ .withDeviceId("")
+ .withBundleName(BUNDLE_NAME)
+ .withAbilityName(ABILITY_NAME)
+ .build();
+ intent.setOperation(operation);
+ startAbility(intent);
+ connectAbility(intent, connection);
+ }
+
+ @Override
+ protected void onStop() {
+ super.onStop();
+ try {
+ CommonEventManager.unsubscribeCommonEvent(subscriber);
+ } catch (RemoteException e) {
+ HiLog.error(LABEL_LOG, "Exception occurred during unsubscribeCommonEvent invocation.");
+ }
+ disconnectAbility(connection);
+ }
+
+ private void initEventListener() {
+ startPlay.setClickedListener(component -> musicRemoteObject.startPlay());
+ pausePlay.setClickedListener(component -> musicRemoteObject.pausePlay());
+ stopPlay.setClickedListener(component -> musicRemoteObject.stopPlay());
+ }
+
+ private void initView() {
+ Component startPlayComponent = findComponentById(ResourceTable.Id_start);
+ if (startPlayComponent instanceof Button) {
+ startPlay = (Button) startPlayComponent;
+ }
+ Component pausePlayComponent = findComponentById(ResourceTable.Id_pause);
+ if (pausePlayComponent instanceof Button) {
+ pausePlay = (Button) pausePlayComponent;
+ }
+ Component stopPlayComponent = findComponentById(ResourceTable.Id_stop);
+ if (stopPlayComponent instanceof Button) {
+ stopPlay = (Button) stopPlayComponent;
+ }
+ }
+
+ private void initSubscribeEvent() {
+ MatchingSkills matchingSkills = new MatchingSkills();
+ matchingSkills.addEvent(EVENT_ACTION);
+ CommonEventSubscribeInfo subscribeInfo = new CommonEventSubscribeInfo(matchingSkills);
+ subscriber = new MyCommonEventSubscriber(subscribeInfo);
+ try {
+ CommonEventManager.subscribeCommonEvent(subscriber);
+ } catch (RemoteException e) {
+ HiLog.error(LABEL_LOG, "Exception occurred during subscribeCommonEvent invocation.");
+ }
+ }
+
+ private void setState(int state) {
+ switch (state) {
+ case PAUSE_STATE: {
+ handleButtonState(PAUSE_STATE);
+ pausePlay.setText(ResourceTable.String_resume_play);
+ break;
+ }
+ case PLAY_STATE: {
+ handleButtonState(PLAY_STATE);
+ break;
+ }
+ case STOP_STATE: {
+ handleButtonState(STOP_STATE);
+ pausePlay.setText(ResourceTable.String_pause_play);
+ break;
+ }
+ default:
+ }
+ if (state == PLAY_STATE && lastState == PAUSE_STATE) {
+ pausePlay.setText(ResourceTable.String_pause_play);
+ }
+ lastState = state;
+ }
+
+ private void handleButtonState(int status) {
+ if ( status != STOP_STATE) {
+ startPlay.setEnabled(false);
+ pausePlay.setEnabled(true);
+ stopPlay.setEnabled(true);
+ } else {
+ startPlay.setEnabled(true);
+ pausePlay.setEnabled(false);
+ stopPlay.setEnabled(false);
+ }
+ }
+
+ /**
+ * CommonEventSubscriber Implementation
+ *
+ * @since 2021-05-08
+ */
+ class MyCommonEventSubscriber extends CommonEventSubscriber {
+ MyCommonEventSubscriber(CommonEventSubscribeInfo info) {
+ super(info);
+ }
+
+ @Override
+ public void onReceiveEvent(CommonEventData commonEventData) {
+ Intent intent = commonEventData.getIntent();
+ int state = intent.getIntParam("state", DEFAULT_STATE);
+ if (state != DEFAULT_STATE) {
+ setState(state);
+ }
+ }
+ }
+}
diff --git a/ability/ForegroundService/entry/src/main/resources/base/element/color.json b/ability/ForegroundService/entry/src/main/resources/base/element/color.json
new file mode 100644
index 0000000000000000000000000000000000000000..5089608bcc6d1b017367f2370911a4743c972723
--- /dev/null
+++ b/ability/ForegroundService/entry/src/main/resources/base/element/color.json
@@ -0,0 +1,8 @@
+{
+ "color": [
+ {
+ "name": "text_color",
+ "value": "#ffffff"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/ability/ForegroundService/entry/src/main/resources/base/element/float.json b/ability/ForegroundService/entry/src/main/resources/base/element/float.json
new file mode 100644
index 0000000000000000000000000000000000000000..6d427543a6f0726e6183096646a7a1684e078afb
--- /dev/null
+++ b/ability/ForegroundService/entry/src/main/resources/base/element/float.json
@@ -0,0 +1,41 @@
+{
+ "float":[
+ {
+ "name":"text_size",
+ "value":"18fp"
+ },
+ {
+ "name":"left_margin",
+ "value":"10vp"
+ },
+ {
+ "name":"right_margin",
+ "value":"10vp"
+ },
+ {
+ "name":"bottom_margin",
+ "value":"10vp"
+ },
+ {
+ "name":"top_margin",
+ "value":"10vp"
+ },
+ {
+ "name":"left_padding",
+ "value":"10vp"
+ },
+ {
+ "name":"right_padding",
+ "value":"10vp"
+ },
+ {
+ "name": "button_height",
+ "value": "40vp"
+ },
+ {
+ "name": "button_width",
+ "value": "280vp"
+ }
+ ]
+}
+
diff --git a/ability/ForegroundService/entry/src/main/resources/base/element/string.json b/ability/ForegroundService/entry/src/main/resources/base/element/string.json
new file mode 100644
index 0000000000000000000000000000000000000000..a0f9ac29d9fb3e77673c375089ab7eadb1e99463
--- /dev/null
+++ b/ability/ForegroundService/entry/src/main/resources/base/element/string.json
@@ -0,0 +1,32 @@
+{
+ "string": [
+ {
+ "name": "app_name",
+ "value": "ForegroundService"
+ },
+ {
+ "name": "mainability_description",
+ "value": "Java_Phone_Empty Feature Ability"
+ },
+ {
+ "name": "serviceability_description",
+ "value": "hap sample empty service"
+ },
+ {
+ "name": "start_play",
+ "value": "Start Play"
+ },
+ {
+ "name": "pause_play",
+ "value": "Pause Play"
+ },
+ {
+ "name": "stop_play",
+ "value": "Stop Play"
+ },
+ {
+ "name": "resume_play",
+ "value": "Resume Play"
+ }
+ ]
+}
diff --git a/ability/ForegroundService/entry/src/main/resources/base/graphic/background_ability_main.xml b/ability/ForegroundService/entry/src/main/resources/base/graphic/background_ability_main.xml
new file mode 100644
index 0000000000000000000000000000000000000000..1018ca3426c32c9d7ba832131e1ae9bd4f7ac2c6
--- /dev/null
+++ b/ability/ForegroundService/entry/src/main/resources/base/graphic/background_ability_main.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/ability/ForegroundService/entry/src/main/resources/base/graphic/circle_disenable.xml b/ability/ForegroundService/entry/src/main/resources/base/graphic/circle_disenable.xml
new file mode 100644
index 0000000000000000000000000000000000000000..16848b2c1e5db664076349a9d6916b0d5f8d3871
--- /dev/null
+++ b/ability/ForegroundService/entry/src/main/resources/base/graphic/circle_disenable.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
diff --git a/ability/ForegroundService/entry/src/main/resources/base/graphic/circle_enable.xml b/ability/ForegroundService/entry/src/main/resources/base/graphic/circle_enable.xml
new file mode 100644
index 0000000000000000000000000000000000000000..8e19311fb4c4124ebfd23e35b5bd1a75eef49228
--- /dev/null
+++ b/ability/ForegroundService/entry/src/main/resources/base/graphic/circle_enable.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
diff --git a/ability/ForegroundService/entry/src/main/resources/base/graphic/select_button.xml b/ability/ForegroundService/entry/src/main/resources/base/graphic/select_button.xml
new file mode 100644
index 0000000000000000000000000000000000000000..1b3a5d26166380ea2787a1d9933dfae3e9488dad
--- /dev/null
+++ b/ability/ForegroundService/entry/src/main/resources/base/graphic/select_button.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/ability/ForegroundService/entry/src/main/resources/base/layout/main_ability_slice.xml b/ability/ForegroundService/entry/src/main/resources/base/layout/main_ability_slice.xml
new file mode 100644
index 0000000000000000000000000000000000000000..e3ba1e1e4c5a76907304fd635c21723de1db8f33
--- /dev/null
+++ b/ability/ForegroundService/entry/src/main/resources/base/layout/main_ability_slice.xml
@@ -0,0 +1,67 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ability/ForegroundService/entry/src/main/resources/base/media/icon.png b/ability/ForegroundService/entry/src/main/resources/base/media/icon.png
new file mode 100644
index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c
Binary files /dev/null and b/ability/ForegroundService/entry/src/main/resources/base/media/icon.png differ
diff --git a/ability/ForegroundService/entry/src/main/resources/rawfile/Homey.mp3 b/ability/ForegroundService/entry/src/main/resources/rawfile/Homey.mp3
new file mode 100644
index 0000000000000000000000000000000000000000..b4e53978f0080d6532574ba9ea313ee306be1465
Binary files /dev/null and b/ability/ForegroundService/entry/src/main/resources/rawfile/Homey.mp3 differ
diff --git a/ability/ForegroundService/entry/src/main/resources/zh_CN/element/string.json b/ability/ForegroundService/entry/src/main/resources/zh_CN/element/string.json
new file mode 100644
index 0000000000000000000000000000000000000000..02ff877c422e5ba2a633cce7db500186b9620860
--- /dev/null
+++ b/ability/ForegroundService/entry/src/main/resources/zh_CN/element/string.json
@@ -0,0 +1,24 @@
+{
+ "string": [
+ {
+ "name": "app_name",
+ "value": "前台服务"
+ },
+ {
+ "name": "start_play",
+ "value": "开始播放"
+ },
+ {
+ "name": "pause_play",
+ "value": "暂停播放"
+ },
+ {
+ "name": "stop_play",
+ "value": "停止播放"
+ },
+ {
+ "name": "resume_play",
+ "value": "恢复播放"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/ability/ForegroundService/screenshots/device/foregroundService_normal.png b/ability/ForegroundService/screenshots/device/foregroundService_normal.png
new file mode 100644
index 0000000000000000000000000000000000000000..9b3cac4a508cfa50a3baff98139b42f3863b9638
Binary files /dev/null and b/ability/ForegroundService/screenshots/device/foregroundService_normal.png differ
diff --git a/ability/ForegroundService/screenshots/device/foregroundservice_play.png b/ability/ForegroundService/screenshots/device/foregroundservice_play.png
new file mode 100644
index 0000000000000000000000000000000000000000..50e941a1afdf3ad9aa33cb276163a76c5775f778
Binary files /dev/null and b/ability/ForegroundService/screenshots/device/foregroundservice_play.png differ
diff --git a/ability/ForegroundService/settings.gradle b/ability/ForegroundService/settings.gradle
new file mode 100644
index 0000000000000000000000000000000000000000..7dc3285c045cc590e49d231a4280ef52ba646d91
--- /dev/null
+++ b/ability/ForegroundService/settings.gradle
@@ -0,0 +1,15 @@
+/*
+ * 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.
+ */
+include ':entry'