summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagdi <magdi@google.com>2023-03-29 20:29:06 +0000
committerMagdi <magdi@google.com>2023-04-05 11:01:30 +0000
commit1b4876fd6aff3f294cfcf94c84635792e8085fbf (patch)
tree0e4ba93198740ebdadba9e8d0bbadfe998711377
parent38c430af65015d22bcd27ae3e3fd27a28fe24948 (diff)
downloadPermission-1b4876fd6aff3f294cfcf94c84635792e8085fbf.tar.gz
Remove HC Privacy Source from PermissionController
Bug: 273175234 Test: manual Change-Id: I922ebcafb9e451d332a88a2ae91f153dcc4eadb2
-rw-r--r--PermissionController/src/com/android/permissioncontroller/privacysources/SafetyCenterReceiver.kt3
-rw-r--r--PermissionController/src/com/android/permissioncontroller/privacysources/v34/HealthConnectPrivacySource.kt126
-rw-r--r--PermissionController/tests/mocking/src/com/android/permissioncontroller/tests/mocking/privacysources/HealthConnectPrivacySourceTest.kt200
-rw-r--r--SafetyCenter/Resources/res/raw-v34/safety_center_config.xml4
4 files changed, 2 insertions, 331 deletions
diff --git a/PermissionController/src/com/android/permissioncontroller/privacysources/SafetyCenterReceiver.kt b/PermissionController/src/com/android/permissioncontroller/privacysources/SafetyCenterReceiver.kt
index 874fe942e..885b8ea86 100644
--- a/PermissionController/src/com/android/permissioncontroller/privacysources/SafetyCenterReceiver.kt
+++ b/PermissionController/src/com/android/permissioncontroller/privacysources/SafetyCenterReceiver.kt
@@ -39,8 +39,6 @@ import com.android.permissioncontroller.permission.utils.Utils
import com.android.permissioncontroller.privacysources.WorkPolicyInfo.Companion.WORK_POLICY_INFO_SOURCE_ID
import com.android.permissioncontroller.privacysources.v34.AppDataSharingUpdatesPrivacySource
import com.android.permissioncontroller.privacysources.v34.AppDataSharingUpdatesPrivacySource.Companion.APP_DATA_SHARING_UPDATES_SOURCE_ID
-import com.android.permissioncontroller.privacysources.v34.HealthConnectPrivacySource
-import com.android.permissioncontroller.privacysources.v34.HealthConnectPrivacySource.Companion.HEALTH_CONNECT_SOURCE_ID
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers.Default
@@ -59,7 +57,6 @@ private fun createMapOfSourceIdsToSources(context: Context): Map<String, Privacy
if (SdkLevel.isAtLeastU()) {
sourceMap[APP_DATA_SHARING_UPDATES_SOURCE_ID] = AppDataSharingUpdatesPrivacySource()
- sourceMap[HEALTH_CONNECT_SOURCE_ID] = HealthConnectPrivacySource()
}
return sourceMap
diff --git a/PermissionController/src/com/android/permissioncontroller/privacysources/v34/HealthConnectPrivacySource.kt b/PermissionController/src/com/android/permissioncontroller/privacysources/v34/HealthConnectPrivacySource.kt
deleted file mode 100644
index f05b061c7..000000000
--- a/PermissionController/src/com/android/permissioncontroller/privacysources/v34/HealthConnectPrivacySource.kt
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Copyright (C) 2023 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.permissioncontroller.privacysources.v34
-
-import android.app.PendingIntent
-import android.app.PendingIntent.FLAG_IMMUTABLE
-import android.app.PendingIntent.FLAG_UPDATE_CURRENT
-import android.content.Context
-import android.content.Intent
-import android.os.Build
-import android.safetycenter.SafetyCenterManager
-import android.safetycenter.SafetyEvent
-import android.safetycenter.SafetyEvent.SAFETY_EVENT_TYPE_DEVICE_REBOOTED
-import android.safetycenter.SafetyEvent.SAFETY_EVENT_TYPE_REFRESH_REQUESTED
-import android.safetycenter.SafetyEvent.SAFETY_EVENT_TYPE_SOURCE_STATE_CHANGED
-import android.safetycenter.SafetySourceData
-import android.safetycenter.SafetySourceData.SEVERITY_LEVEL_UNSPECIFIED
-import android.safetycenter.SafetySourceStatus
-import androidx.annotation.RequiresApi
-import com.android.permissioncontroller.R
-import com.android.permissioncontroller.permission.utils.Utils
-import com.android.permissioncontroller.privacysources.PrivacySource
-import com.android.permissioncontroller.privacysources.SafetyCenterReceiver.RefreshEvent
-import com.android.permissioncontroller.privacysources.SafetyCenterReceiver.RefreshEvent.EVENT_DEVICE_REBOOTED
-import com.android.permissioncontroller.privacysources.SafetyCenterReceiver.RefreshEvent.EVENT_REFRESH_REQUESTED
-import com.android.permissioncontroller.privacysources.SafetyCenterReceiver.RefreshEvent.UNKNOWN
-
-/**
- * Privacy source providing the Health Connect entry to Safety Center.
- *
- * The content of the Health Connect is static, however the entry should only be displayed if the
- * Health Connect Permission UI Enabled feature is enabled.
- */
-@RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
-class HealthConnectPrivacySource : PrivacySource {
-
- override val shouldProcessProfileRequest: Boolean = false
-
- override fun safetyCenterEnabledChanged(context: Context, enabled: Boolean) {
- // Do nothing.
- }
-
- override fun rescanAndPushSafetyCenterData(
- context: Context,
- intent: Intent,
- refreshEvent: RefreshEvent
- ) {
- val safetyCenterManager: SafetyCenterManager =
- Utils.getSystemServiceSafe(context, SafetyCenterManager::class.java)
-
- val safetySourceData =
- if (Utils.isHealthPermissionUiEnabled()) {
- SafetySourceData.Builder()
- .setStatus(
- SafetySourceStatus.Builder(
- context.getString(R.string.health_connect_title),
- context.getString(R.string.health_connect_summary),
- SEVERITY_LEVEL_UNSPECIFIED
- )
- .setPendingIntent(
- PendingIntent.getActivity(
- context,
- /* requestCode= */ 0,
- Intent(HEALTH_CONNECT_INTENT_ACTION),
- FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE
- )
- )
- .build(),
- )
- .build()
- } else {
- null
- }
-
- safetyCenterManager.setSafetySourceData(
- HEALTH_CONNECT_SOURCE_ID,
- safetySourceData,
- createSafetyEventForHealthConnect(refreshEvent, intent)
- )
- }
-
- private fun createSafetyEventForHealthConnect(
- refreshEvent: RefreshEvent,
- intent: Intent
- ): SafetyEvent {
- return when (refreshEvent) {
- EVENT_REFRESH_REQUESTED -> {
- val refreshBroadcastId =
- intent.getStringExtra(
- SafetyCenterManager.EXTRA_REFRESH_SAFETY_SOURCES_BROADCAST_ID
- )
- SafetyEvent.Builder(SAFETY_EVENT_TYPE_REFRESH_REQUESTED)
- .setRefreshBroadcastId(refreshBroadcastId)
- .build()
- }
- EVENT_DEVICE_REBOOTED -> {
- SafetyEvent.Builder(SAFETY_EVENT_TYPE_DEVICE_REBOOTED).build()
- }
- UNKNOWN -> {
- SafetyEvent.Builder(SAFETY_EVENT_TYPE_SOURCE_STATE_CHANGED).build()
- }
- }
- }
-
- /** Companion object for [HealthConnectPrivacySource]. */
- companion object {
- /** Source id for safety center source for health connect. */
- const val HEALTH_CONNECT_SOURCE_ID = "AndroidHealthConnect"
- const val HEALTH_CONNECT_INTENT_ACTION =
- "android.health.connect.action.HEALTH_HOME_SETTINGS"
- }
-}
diff --git a/PermissionController/tests/mocking/src/com/android/permissioncontroller/tests/mocking/privacysources/HealthConnectPrivacySourceTest.kt b/PermissionController/tests/mocking/src/com/android/permissioncontroller/tests/mocking/privacysources/HealthConnectPrivacySourceTest.kt
deleted file mode 100644
index c68f1cc67..000000000
--- a/PermissionController/tests/mocking/src/com/android/permissioncontroller/tests/mocking/privacysources/HealthConnectPrivacySourceTest.kt
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * Copyright (C) 2023 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.permissioncontroller.tests.mocking.privacysources
-
-import android.app.PendingIntent
-import android.app.PendingIntent.FLAG_IMMUTABLE
-import android.app.PendingIntent.FLAG_UPDATE_CURRENT
-import android.content.Context
-import android.content.ContextWrapper
-import android.content.Intent
-import android.os.Build
-import android.provider.DeviceConfig
-import android.provider.DeviceConfig.NAMESPACE_PRIVACY
-import android.safetycenter.SafetyCenterManager
-import android.safetycenter.SafetyCenterManager.ACTION_REFRESH_SAFETY_SOURCES
-import android.safetycenter.SafetyCenterManager.EXTRA_REFRESH_SAFETY_SOURCES_BROADCAST_ID
-import android.safetycenter.SafetyEvent
-import android.safetycenter.SafetyEvent.SAFETY_EVENT_TYPE_REFRESH_REQUESTED
-import android.safetycenter.SafetySourceData
-import android.safetycenter.SafetySourceStatus
-import androidx.test.core.app.ApplicationProvider
-import androidx.test.ext.junit.runners.AndroidJUnit4
-import androidx.test.filters.SdkSuppress
-import com.android.dx.mockito.inline.extended.ExtendedMockito
-import com.android.permissioncontroller.PermissionControllerApplication
-import com.android.permissioncontroller.permission.utils.Utils
-import com.android.permissioncontroller.privacysources.SafetyCenterReceiver.RefreshEvent.EVENT_REFRESH_REQUESTED
-import com.android.permissioncontroller.privacysources.v34.HealthConnectPrivacySource
-import com.android.permissioncontroller.privacysources.v34.HealthConnectPrivacySource.Companion.HEALTH_CONNECT_SOURCE_ID
-import org.junit.After
-import org.junit.Before
-import org.junit.Test
-import org.junit.runner.RunWith
-import org.mockito.ArgumentMatchers.any
-import org.mockito.ArgumentMatchers.anyBoolean
-import org.mockito.ArgumentMatchers.eq
-import org.mockito.Mock
-import org.mockito.Mockito.verify
-import org.mockito.Mockito.verifyZeroInteractions
-import org.mockito.Mockito.`when` as whenever
-import org.mockito.MockitoAnnotations
-import org.mockito.MockitoSession
-import org.mockito.quality.Strictness
-
-/** Tests for [HealthConnectPrivacySource]. */
-@RunWith(AndroidJUnit4::class)
-@SdkSuppress(minSdkVersion = Build.VERSION_CODES.UPSIDE_DOWN_CAKE, codeName = "UpsideDownCake")
-class HealthConnectPrivacySourceTest {
-
- private lateinit var mockitoSession: MockitoSession
- private lateinit var healthConnectPrivacySource: HealthConnectPrivacySource
- private lateinit var context: Context
- @Mock lateinit var mockSafetyCenterManager: SafetyCenterManager
-
- @Before
- fun setup() {
- context = ApplicationProvider.getApplicationContext()
- MockitoAnnotations.initMocks(this)
- mockitoSession =
- ExtendedMockito.mockitoSession()
- .mockStatic(DeviceConfig::class.java)
- .mockStatic(PermissionControllerApplication::class.java)
- .mockStatic(Utils::class.java)
- .strictness(Strictness.LENIENT)
- .startMocking()
- whenever(
- Utils.getSystemServiceSafe(
- any(ContextWrapper::class.java),
- eq(SafetyCenterManager::class.java)
- )
- )
- .thenReturn(mockSafetyCenterManager)
-
- healthConnectPrivacySource = HealthConnectPrivacySource()
- }
-
- @After
- fun cleanup() {
- mockitoSession.finishMocking()
- }
-
- @Test
- fun safetyCenterEnabledChanged_enabled_doesNothing() {
- healthConnectPrivacySource.safetyCenterEnabledChanged(context, true)
-
- verifyZeroInteractions(mockSafetyCenterManager)
- }
-
- @Test
- fun safetyCenterEnabledChanged_disabled_doesNothing() {
- healthConnectPrivacySource.safetyCenterEnabledChanged(context, false)
-
- verifyZeroInteractions(mockSafetyCenterManager)
- }
-
- @Test
- fun rescanAndPushSafetyCenterData_healthPermissionUIEnabled_setsDataWithStatus() {
- val refreshIntent =
- Intent(ACTION_REFRESH_SAFETY_SOURCES)
- .putExtra(EXTRA_REFRESH_SAFETY_SOURCES_BROADCAST_ID, REFRESH_ID)
-
- healthConnectPrivacySource.rescanAndPushSafetyCenterData(
- context,
- refreshIntent,
- EVENT_REFRESH_REQUESTED
- )
-
- val expectedSafetySourceData =
- if (Utils.isHealthPermissionUiEnabled()) {
- SafetySourceData.Builder()
- .setStatus(
- SafetySourceStatus.Builder(
- HEALTH_CONNECT_TITLE,
- HEALTH_CONNECT_SUMMARY,
- SafetySourceData.SEVERITY_LEVEL_UNSPECIFIED
- )
- .setPendingIntent(
- PendingIntent.getActivity(
- context,
- /* requestCode= */ 0,
- Intent(HEALTH_CONNECT_INTENT_ACTION),
- FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE
- )
- )
- .build()
- )
- .build()
- } else {
- null
- }
-
- val expectedSafetyEvent =
- SafetyEvent.Builder(SAFETY_EVENT_TYPE_REFRESH_REQUESTED)
- .setRefreshBroadcastId(REFRESH_ID)
- .build()
- verify(mockSafetyCenterManager)
- .setSafetySourceData(
- HEALTH_CONNECT_SOURCE_ID,
- expectedSafetySourceData,
- expectedSafetyEvent
- )
- }
-
- @Test
- fun rescanAndPushSafetyCenterData_healthPermissionUIDisabled_setsNullData() {
- setHealthPermissionUIEnabled(false)
- val refreshIntent =
- Intent(ACTION_REFRESH_SAFETY_SOURCES)
- .putExtra(EXTRA_REFRESH_SAFETY_SOURCES_BROADCAST_ID, REFRESH_ID)
-
- healthConnectPrivacySource.rescanAndPushSafetyCenterData(
- context,
- refreshIntent,
- EVENT_REFRESH_REQUESTED
- )
-
- val expectedSafetyEvent =
- SafetyEvent.Builder(SAFETY_EVENT_TYPE_REFRESH_REQUESTED)
- .setRefreshBroadcastId(REFRESH_ID)
- .build()
- verify(mockSafetyCenterManager)
- .setSafetySourceData(HEALTH_CONNECT_SOURCE_ID, null, expectedSafetyEvent)
- }
-
- /** Companion object for [HealthConnectPrivacySourceTest]. */
- companion object {
- // Real context, used in order to avoid mocking resources.
- const val HEALTH_CONNECT_TITLE: String = "Health Connect"
- const val HEALTH_CONNECT_SUMMARY: String = "Manage app access to health data"
- const val REFRESH_ID: String = "refresh_id"
- const val HEALTH_CONNECT_INTENT_ACTION =
- "android.health.connect.action.HEALTH_HOME_SETTINGS"
-
- /** Sets the value for the Health Permission feature [DeviceConfig] property. */
- private fun setHealthPermissionUIEnabled(enabled: Boolean) {
- whenever(
- DeviceConfig.getBoolean(
- eq(NAMESPACE_PRIVACY),
- eq("health_permission_ui_enabled"),
- anyBoolean()
- )
- )
- .thenReturn(enabled)
- }
- }
-}
diff --git a/SafetyCenter/Resources/res/raw-v34/safety_center_config.xml b/SafetyCenter/Resources/res/raw-v34/safety_center_config.xml
index 5fbf6e9f2..1c3330c63 100644
--- a/SafetyCenter/Resources/res/raw-v34/safety_center_config.xml
+++ b/SafetyCenter/Resources/res/raw-v34/safety_center_config.xml
@@ -67,9 +67,9 @@
<dynamic-safety-source
id="AndroidHealthConnect"
profile="primary_profile_only"
- packageName="com.android.permissioncontroller"
+ packageName="com.android.healthconnect.controller"
initialDisplayState="hidden"
- refreshOnPageOpenAllowed="true"
+ refreshOnPageOpenAllowed="false"
title="@com.android.safetycenter.resources:string/health_connect_title"
searchTerms="@com.android.safetycenter.resources:string/health_connect_search_terms"/>
<dynamic-safety-source