Merge "[Safety Labels] Filter out auto, wear and tv" into udc-dev am: 4d5ac5a89f
am: d8ca8de897
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/22562077 Change-Id: I85b75d9707a673c56add33f61c8533e85d9a312a Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -19,6 +19,7 @@ package com.android.settings.privacy;
|
|||||||
import static android.safetylabel.SafetyLabelConstants.SAFETY_LABEL_CHANGE_NOTIFICATIONS_ENABLED;
|
import static android.safetylabel.SafetyLabelConstants.SAFETY_LABEL_CHANGE_NOTIFICATIONS_ENABLED;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.provider.DeviceConfig;
|
import android.provider.DeviceConfig;
|
||||||
|
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
@@ -28,7 +29,6 @@ import com.android.settings.core.BasePreferenceController;
|
|||||||
* TODO b/264939792: Add tests
|
* TODO b/264939792: Add tests
|
||||||
*/
|
*/
|
||||||
public class AppDataSharingUpdatesPreferenceController extends BasePreferenceController {
|
public class AppDataSharingUpdatesPreferenceController extends BasePreferenceController {
|
||||||
|
|
||||||
public AppDataSharingUpdatesPreferenceController(Context context,
|
public AppDataSharingUpdatesPreferenceController(Context context,
|
||||||
String preferenceKey) {
|
String preferenceKey) {
|
||||||
super(context, preferenceKey);
|
super(context, preferenceKey);
|
||||||
@@ -36,8 +36,16 @@ public class AppDataSharingUpdatesPreferenceController extends BasePreferenceCon
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus() {
|
public int getAvailabilityStatus() {
|
||||||
return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_PRIVACY,
|
return isPrivacySafetyLabelChangeNotificationsEnabled(mContext)
|
||||||
SAFETY_LABEL_CHANGE_NOTIFICATIONS_ENABLED, false)
|
|
||||||
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isPrivacySafetyLabelChangeNotificationsEnabled(Context context) {
|
||||||
|
PackageManager packageManager = context.getPackageManager();
|
||||||
|
return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_PRIVACY,
|
||||||
|
SAFETY_LABEL_CHANGE_NOTIFICATIONS_ENABLED, false)
|
||||||
|
&& !packageManager.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE)
|
||||||
|
&& !packageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)
|
||||||
|
&& !packageManager.hasSystemFeature(PackageManager.FEATURE_WATCH);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,116 @@
|
|||||||
|
/*
|
||||||
|
* 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.settings.privacy;
|
||||||
|
|
||||||
|
import static android.content.pm.PackageManager.FEATURE_AUTOMOTIVE;
|
||||||
|
import static android.content.pm.PackageManager.FEATURE_LEANBACK;
|
||||||
|
import static android.content.pm.PackageManager.FEATURE_WATCH;
|
||||||
|
|
||||||
|
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||||
|
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.provider.DeviceConfig;
|
||||||
|
import android.provider.Settings;
|
||||||
|
import android.safetylabel.SafetyLabelConstants;
|
||||||
|
|
||||||
|
import com.android.settings.testutils.shadow.ShadowDeviceConfig;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
import org.mockito.MockitoSession;
|
||||||
|
import org.mockito.quality.Strictness;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@Config(shadows = {ShadowDeviceConfig.class})
|
||||||
|
public class AppDataSharingUpdatesPreferenceControllerTest {
|
||||||
|
|
||||||
|
public static final String PREFERENCE_KEY = "PREFERENCE_KEY";
|
||||||
|
private static final List<String> sUnsupportedFormFactors =
|
||||||
|
Arrays.asList(FEATURE_AUTOMOTIVE, FEATURE_LEANBACK, FEATURE_WATCH);
|
||||||
|
private MockitoSession mMockitoSession;
|
||||||
|
@Mock
|
||||||
|
private PackageManager mPackageManager;
|
||||||
|
@Mock
|
||||||
|
private Context mContext;
|
||||||
|
private AppDataSharingUpdatesPreferenceController mController;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
mMockitoSession = Mockito.mockitoSession()
|
||||||
|
.initMocks(this)
|
||||||
|
.strictness(Strictness.WARN)
|
||||||
|
.startMocking();
|
||||||
|
doReturn(mPackageManager).when(mContext).getPackageManager();
|
||||||
|
mController = new AppDataSharingUpdatesPreferenceController(mContext, PREFERENCE_KEY);
|
||||||
|
for (String formFactor : sUnsupportedFormFactors) {
|
||||||
|
doReturn(false).when(mPackageManager).hasSystemFeature(eq(formFactor));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
mMockitoSession.finishMocking();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSafetyLabelsDisabled_thenPreferenceUnavailable()
|
||||||
|
throws Exception {
|
||||||
|
setSafetyLabelsDeviceConfigEnabled(false);
|
||||||
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSafetyLabelsEnabled_andSupportedFormFactor_thenPreferenceAvailable()
|
||||||
|
throws Exception {
|
||||||
|
setSafetyLabelsDeviceConfigEnabled(true);
|
||||||
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSafetyLabelsEnabled_andUnsupportedFormFactor_thenPreferenceUnavailable()
|
||||||
|
throws Exception {
|
||||||
|
setSafetyLabelsDeviceConfigEnabled(true);
|
||||||
|
for (String formFactor : sUnsupportedFormFactors) {
|
||||||
|
doReturn(true).when(mPackageManager).hasSystemFeature(eq(formFactor));
|
||||||
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
|
||||||
|
doReturn(false).when(mPackageManager).hasSystemFeature(eq(formFactor));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setSafetyLabelsDeviceConfigEnabled(boolean newValue)
|
||||||
|
throws Settings.SettingNotFoundException {
|
||||||
|
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_PRIVACY,
|
||||||
|
SafetyLabelConstants.SAFETY_LABEL_CHANGE_NOTIFICATIONS_ENABLED,
|
||||||
|
((Boolean) newValue).toString(), /* makeDefault */ false);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user