From d735f9a1a88d8efecb7e55a3fed320f3220973a3 Mon Sep 17 00:00:00 2001 From: Chaohui Wang Date: Mon, 19 Dec 2022 16:09:19 +0800 Subject: [PATCH] Set setModeByUid to align with current behavior For the following App Lists, - All Files Access - Media Management Apps Default false, if true, use AppOpsManager#setUidMode instead of #setMode This follows Change: I261953ff88bc049cf0a2f04f8caac00b8cc6f704 Reason: Security related app-ops should be set with AppOpsManager#setUidMode instead of AppOpsManager#setMode. Bug: 235727273 Test: Unit test Change-Id: I953b63c2bf6f3bd94aacc935c8c3579bc8aed199 --- .../spa/app/specialaccess/AllFilesAccess.kt | 1 + .../app/specialaccess/MediaManagementApps.kt | 1 + .../app/specialaccess/AllFilesAccessTest.kt | 65 +++++++++++++++++++ .../specialaccess/MediaManagementAppsTest.kt | 65 +++++++++++++++++++ 4 files changed, 132 insertions(+) create mode 100644 tests/spa_unit/src/com/android/settings/spa/app/specialaccess/AllFilesAccessTest.kt create mode 100644 tests/spa_unit/src/com/android/settings/spa/app/specialaccess/MediaManagementAppsTest.kt diff --git a/src/com/android/settings/spa/app/specialaccess/AllFilesAccess.kt b/src/com/android/settings/spa/app/specialaccess/AllFilesAccess.kt index 5efe3227191..6466e038006 100644 --- a/src/com/android/settings/spa/app/specialaccess/AllFilesAccess.kt +++ b/src/com/android/settings/spa/app/specialaccess/AllFilesAccess.kt @@ -34,4 +34,5 @@ class AllFilesAccessListModel(context: Context) : AppOpPermissionListModel(conte override val footerResId = R.string.allow_manage_external_storage_description override val appOp = AppOpsManager.OP_MANAGE_EXTERNAL_STORAGE override val permission = Manifest.permission.MANAGE_EXTERNAL_STORAGE + override val setModeByUid = true } diff --git a/src/com/android/settings/spa/app/specialaccess/MediaManagementApps.kt b/src/com/android/settings/spa/app/specialaccess/MediaManagementApps.kt index 92e369dd065..6c7678a0629 100644 --- a/src/com/android/settings/spa/app/specialaccess/MediaManagementApps.kt +++ b/src/com/android/settings/spa/app/specialaccess/MediaManagementApps.kt @@ -34,4 +34,5 @@ class MediaManagementAppsListModel(context: Context) : AppOpPermissionListModel( override val footerResId = R.string.media_management_apps_description override val appOp = AppOpsManager.OP_MANAGE_MEDIA override val permission = Manifest.permission.MANAGE_MEDIA + override val setModeByUid = true } \ No newline at end of file diff --git a/tests/spa_unit/src/com/android/settings/spa/app/specialaccess/AllFilesAccessTest.kt b/tests/spa_unit/src/com/android/settings/spa/app/specialaccess/AllFilesAccessTest.kt new file mode 100644 index 00000000000..f5d422dcb94 --- /dev/null +++ b/tests/spa_unit/src/com/android/settings/spa/app/specialaccess/AllFilesAccessTest.kt @@ -0,0 +1,65 @@ +/* + * 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.settings.spa.app.specialaccess + +import android.Manifest +import android.app.AppOpsManager +import android.content.Context +import androidx.test.core.app.ApplicationProvider +import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.android.settings.R +import com.google.common.truth.Truth.assertThat +import org.junit.Test +import org.junit.runner.RunWith + +@RunWith(AndroidJUnit4::class) +class AllFilesAccessTest { + private val context: Context = ApplicationProvider.getApplicationContext() + + private val listModel = AllFilesAccessListModel(context) + + @Test + fun pageTitleResId() { + assertThat(listModel.pageTitleResId).isEqualTo(R.string.manage_external_storage_title) + } + + @Test + fun switchTitleResId() { + assertThat(listModel.switchTitleResId).isEqualTo(R.string.permit_manage_external_storage) + } + + @Test + fun footerResId() { + assertThat(listModel.footerResId) + .isEqualTo(R.string.allow_manage_external_storage_description) + } + + @Test + fun appOp() { + assertThat(listModel.appOp).isEqualTo(AppOpsManager.OP_MANAGE_EXTERNAL_STORAGE) + } + + @Test + fun permission() { + assertThat(listModel.permission).isEqualTo(Manifest.permission.MANAGE_EXTERNAL_STORAGE) + } + + @Test + fun setModeByUid() { + assertThat(listModel.setModeByUid).isTrue() + } +} \ No newline at end of file diff --git a/tests/spa_unit/src/com/android/settings/spa/app/specialaccess/MediaManagementAppsTest.kt b/tests/spa_unit/src/com/android/settings/spa/app/specialaccess/MediaManagementAppsTest.kt new file mode 100644 index 00000000000..b56d9974d66 --- /dev/null +++ b/tests/spa_unit/src/com/android/settings/spa/app/specialaccess/MediaManagementAppsTest.kt @@ -0,0 +1,65 @@ +/* + * 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.settings.spa.app.specialaccess + +import android.Manifest +import android.app.AppOpsManager +import android.content.Context +import androidx.test.core.app.ApplicationProvider +import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.android.settings.R +import com.google.common.truth.Truth.assertThat +import org.junit.Test +import org.junit.runner.RunWith + +@RunWith(AndroidJUnit4::class) +class MediaManagementAppsTest { + private val context: Context = ApplicationProvider.getApplicationContext() + + private val listModel = MediaManagementAppsListModel(context) + + @Test + fun pageTitleResId() { + assertThat(listModel.pageTitleResId).isEqualTo(R.string.media_management_apps_title) + } + + @Test + fun switchTitleResId() { + assertThat(listModel.switchTitleResId) + .isEqualTo(R.string.media_management_apps_toggle_label) + } + + @Test + fun footerResId() { + assertThat(listModel.footerResId).isEqualTo(R.string.media_management_apps_description) + } + + @Test + fun appOp() { + assertThat(listModel.appOp).isEqualTo(AppOpsManager.OP_MANAGE_MEDIA) + } + + @Test + fun permission() { + assertThat(listModel.permission).isEqualTo(Manifest.permission.MANAGE_MEDIA) + } + + @Test + fun setModeByUid() { + assertThat(listModel.setModeByUid).isTrue() + } +} \ No newline at end of file