Snap for 10186302 from 3168137798 to udc-qpr1-release

Change-Id: I695a57b7c2b936aeda91aa5183550aa86e4441ae
This commit is contained in:
Android Build Coastguard Worker
2023-05-24 03:19:38 +00:00
6 changed files with 127 additions and 10 deletions

View File

@@ -131,6 +131,8 @@ public final class AccessibilityStatsLogUtils {
return FrameworkStatsLog.HEARING_AID_INFO_REPORTED__BOND_ENTRY__ACCESSIBILITY_HEARING_AID_PAIR_ANOTHER;
case SettingsStatsLog.SETTINGS_UICHANGED__PAGE_ID__BLUETOOTH_FRAGMENT:
return FrameworkStatsLog.HEARING_AID_INFO_REPORTED__BOND_ENTRY__BLUETOOTH;
case SettingsStatsLog.SETTINGS_UICHANGED__PAGE_ID__ACCESSIBILITY_HEARING_AID_SETTINGS:
return FrameworkStatsLog.HEARING_AID_INFO_REPORTED__BOND_ENTRY__ACCESSIBILITY_HEARING_AID_SETTINGS;
default:
return FrameworkStatsLog.HEARING_AID_INFO_REPORTED__BOND_ENTRY__PAGE_UNKNOWN;
}

View File

@@ -22,8 +22,6 @@ import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.icu.text.MeasureFormat;
import android.icu.util.MeasureUnit;
import android.net.NetworkPolicy;
import android.net.NetworkTemplate;
import android.os.Bundle;
@@ -322,14 +320,10 @@ public class BillingCycleSettings extends DataUsageBaseFragment implements
final boolean isLimit = getArguments().getBoolean(EXTRA_LIMIT);
final long bytes = isLimit ? editor.getPolicyLimitBytes(template)
: editor.getPolicyWarningBytes(template);
final long limitDisabled = isLimit ? LIMIT_DISABLED : WARNING_DISABLED;
final MeasureFormat formatter = MeasureFormat.getInstance(
getContext().getResources().getConfiguration().locale,
MeasureFormat.FormatWidth.SHORT);
final String[] unitNames = new String[] {
formatter.getUnitDisplayName(MeasureUnit.MEGABYTE),
formatter.getUnitDisplayName(MeasureUnit.GIGABYTE)
DataUsageFormatter.INSTANCE.getBytesDisplayUnit(getResources(), MIB_IN_BYTES),
DataUsageFormatter.INSTANCE.getBytesDisplayUnit(getResources(), GIB_IN_BYTES),
};
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(
getContext(), android.R.layout.simple_spinner_item, unitNames);

View File

@@ -0,0 +1,32 @@
/*
* 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.datausage
import android.content.res.Resources
import android.text.format.Formatter
object DataUsageFormatter {
/**
* Gets the display unit of the given bytes.
*
* Similar to MeasureFormat.getUnitDisplayName(), but with the expected result for the bytes in
* Settings, and align with other places in Settings.
*/
fun Resources.getBytesDisplayUnit(bytes: Long): String =
Formatter.formatBytes(this, bytes, Formatter.FLAG_IEC_UNITS).units
}

View File

@@ -17,6 +17,9 @@
package com.android.settings.dream;
import android.content.Context;
import android.provider.Settings;
import androidx.preference.Preference;
import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.R;
@@ -46,12 +49,21 @@ public class DreamHomeControlsPreferenceController extends TogglePreferenceContr
final boolean supported =
mBackend.getSupportedComplications()
.contains(DreamBackend.COMPLICATION_TYPE_HOME_CONTROLS);
return supported ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
return controlsEnabledOnLockscreen() ? (supported ? AVAILABLE : CONDITIONALLY_UNAVAILABLE)
: DISABLED_DEPENDENT_SETTING;
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
preference.setEnabled(getAvailabilityStatus() == AVAILABLE);
refreshSummary(preference);
}
@Override
public boolean isChecked() {
return mBackend.getEnabledComplications().contains(
return controlsEnabledOnLockscreen() && mBackend.getEnabledComplications().contains(
DreamBackend.COMPLICATION_TYPE_HOME_CONTROLS);
}
@@ -61,6 +73,12 @@ public class DreamHomeControlsPreferenceController extends TogglePreferenceContr
return true;
}
private boolean controlsEnabledOnLockscreen() {
return Settings.Secure.getInt(
mContext.getContentResolver(),
Settings.Secure.LOCKSCREEN_SHOW_CONTROLS, 0) != 0;
}
@Override
public int getSliceHighlightMenuRes() {
return R.string.menu_key_display;

View File

@@ -23,6 +23,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.provider.Settings;
import android.util.ArraySet;
import androidx.preference.PreferenceScreen;
@@ -80,6 +81,7 @@ public class DreamHomeControlsPreferenceControllerTest {
@Test
public void testSetChecked_setTrue_enablesSetting() {
setControlsEnabledOnLockscreen(true);
mBackend.setHomeControlsEnabled(false);
assertThat(mBackend.getEnabledComplications())
.doesNotContain(COMPLICATION_TYPE_HOME_CONTROLS);
@@ -91,6 +93,7 @@ public class DreamHomeControlsPreferenceControllerTest {
@Test
public void testSetChecked_setFalse_disablesSetting() {
setControlsEnabledOnLockscreen(true);
mBackend.setHomeControlsEnabled(true);
assertThat(mBackend.getEnabledComplications())
.contains(COMPLICATION_TYPE_HOME_CONTROLS);
@@ -102,15 +105,33 @@ public class DreamHomeControlsPreferenceControllerTest {
@Test
public void testIsChecked_returnsFalse() {
setControlsEnabledOnLockscreen(true);
mBackend.setHomeControlsEnabled(false);
assertThat(mController.isChecked()).isFalse();
}
@Test
public void testIsChecked_returnsTrue() {
setControlsEnabledOnLockscreen(true);
mBackend.setHomeControlsEnabled(true);
assertThat(mBackend.getEnabledComplications())
.contains(COMPLICATION_TYPE_HOME_CONTROLS);
assertThat(mController.isChecked()).isTrue();
}
@Test
public void testIsChecked_lockScreenDisabled_returnsFalse() {
setControlsEnabledOnLockscreen(false);
mBackend.setHomeControlsEnabled(true);
assertThat(mBackend.getEnabledComplications())
.doesNotContain(COMPLICATION_TYPE_HOME_CONTROLS);
assertThat(mController.isChecked()).isFalse();
}
private void setControlsEnabledOnLockscreen(boolean enabled) {
Settings.Secure.putInt(
mContext.getContentResolver(),
Settings.Secure.LOCKSCREEN_SHOW_CONTROLS,
enabled ? 1 : 0);
}
}

View File

@@ -0,0 +1,50 @@
/*
* 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.datausage
import android.content.Context
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.android.settings.datausage.DataUsageFormatter.getBytesDisplayUnit
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class DataUsageFormatterTest {
private val context: Context = ApplicationProvider.getApplicationContext()
@Test
fun getUnitDisplayName_megaByte() {
val displayName = context.resources.getBytesDisplayUnit(ONE_MEGA_BYTE_IN_BYTES)
assertThat(displayName).isEqualTo("MB")
}
@Test
fun getUnitDisplayName_gigaByte() {
val displayName = context.resources.getBytesDisplayUnit(ONE_GIGA_BYTE_IN_BYTES)
assertThat(displayName).isEqualTo("GB")
}
private companion object {
const val ONE_MEGA_BYTE_IN_BYTES = 1024L * 1024
const val ONE_GIGA_BYTE_IN_BYTES = 1024L * 1024 * 1024
}
}