Add role to pregrant permissions to wear health service.
New role approved in b/234458582.
Bug: 250996467
Change-Id: I23099e130ef0c4dad56d2609fea5b8145720c2f7
diff --git a/PermissionController/res/xml/roles.xml b/PermissionController/res/xml/roles.xml
index 7441152..e12c7ff 100644
--- a/PermissionController/res/xml/roles.xml
+++ b/PermissionController/res/xml/roles.xml
@@ -1394,4 +1394,24 @@
<permission name="android.permission.MANAGE_DEVICE_LOCK_STATE" />
</permissions>
</role>
+
+ <!---
+ ~ A role for the wear health service that handles health/fitness tracking features.
+ -->
+ <role
+ name="android.app.role.SYSTEM_WEAR_HEALTH_SERVICE"
+ behavior="SystemWearHealthServiceRoleBehavior"
+ defaultHolders="config_systemWearHealthService"
+ exclusive="true"
+ minSdkVersion="33"
+ static="true"
+ systemOnly="true"
+ visible="false">
+ <permissions>
+ <permission-set name="sensors" />
+ <permission-set name="location" />
+ <permission name="android.permission.ACCESS_BACKGROUND_LOCATION" />
+ <permission name="android.permission.ACTIVITY_RECOGNITION" />
+ </permissions>
+ </role>
</roles>
diff --git a/PermissionController/src/com/android/role/controller/model/SystemWearHealthServiceRoleBehavior.java b/PermissionController/src/com/android/role/controller/model/SystemWearHealthServiceRoleBehavior.java
new file mode 100644
index 0000000..feaf985
--- /dev/null
+++ b/PermissionController/src/com/android/role/controller/model/SystemWearHealthServiceRoleBehavior.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * 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 com.android.role.controller.model;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.os.UserHandle;
+
+import androidx.annotation.NonNull;
+
+/** The role behavior for System Wear Health Service. */
+public class SystemWearHealthServiceRoleBehavior implements RoleBehavior {
+ @Override
+ public boolean isAvailableAsUser(@NonNull Role role, @NonNull UserHandle user,
+ @NonNull Context context) {
+ // Role is only available on Watches.
+ return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH);
+ }
+}