Snap for 12680993 from 05b9d038de to 25Q1-release

Change-Id: I379d2c115af0891d302c382330af203aea486e68
This commit is contained in:
Android Build Coastguard Worker
2024-11-20 00:18:37 +00:00
35 changed files with 993 additions and 130 deletions

View File

@@ -5372,6 +5372,23 @@
</intent-filter>
</receiver>
<activity
android:name="Settings$ChangeNfcTagAppsActivity"
android:exported="true"
android:label="@string/change_nfc_tag_apps_title">
<intent-filter android:priority="1">
<action android:name="android.nfc.action.CHANGE_TAG_INTENT_PREFERENCE" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.applications.manageapplications.ManageApplications" />
<meta-data android:name="com.android.settings.HIGHLIGHT_MENU_KEY"
android:value="@string/menu_key_apps"/>
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" />
</activity>
<!-- This is the longest AndroidManifest.xml ever. -->
</application>
</manifest>

View File

@@ -12286,6 +12286,8 @@
<string name="satellite_warning_dialog_title">Cant turn on <xliff:g id="function" example="bluetooth">%1$s</xliff:g></string>
<!-- Content for satellite warning dialog to avoid user using wifi/bluetooth/airplane mode [CHAR_LIMIT=NONE] -->
<string name="satellite_warning_dialog_content">To turn on <xliff:g id="function" example="bluetooth">%1$s</xliff:g>, first end the satellite connection</string>
<!-- Category title for satellite functions in mobile network settings [CHAR LIMIT=60] -->
<string name="category_title_satellite_connectivity">Satellite connectivity</string>
<!-- Title for Apn settings in mobile network settings [CHAR LIMIT=60] -->

View File

@@ -204,6 +204,21 @@
settings:enableCopying="true"
settings:controller="com.android.settings.network.telephony.MobileNetworkEidPreferenceController"/>
<PreferenceCategory
android:key="telephony_satellite_settings_category_key"
android:title="@string/category_title_satellite_connectivity"
settings:controller="com.android.settings.network.telephony.SatelliteSettingsPreferenceCategoryController">
<com.android.settingslib.RestrictedPreference
android:key="telephony_satellite_setting_key"
android:persistent="false"
android:title="@string/satellite_setting_title"
settings:keywords="@string/keywords_satellite_setting"
settings:controller=
"com.android.settings.network.telephony.SatelliteSettingPreferenceController"/>
</PreferenceCategory>
<PreferenceCategory
android:key="calling_category"
android:title="@string/call_category"
@@ -267,14 +282,6 @@
settings:controller="com.android.settings.network.telephony.gsm.OpenNetworkSelectPagePreferenceController"/>
</PreferenceCategory>
<com.android.settingslib.RestrictedPreference
android:key="telephony_satellite_setting_key"
android:persistent="false"
android:title="@string/satellite_setting_title"
settings:keywords="@string/keywords_satellite_setting"
settings:controller=
"com.android.settings.network.telephony.SatelliteSettingPreferenceController"/>
<!--We want separate APN setting from reset of settings because we want user to change it with caution-->
<com.android.settingslib.RestrictedPreference
android:key="telephony_apn_key"

View File

@@ -122,24 +122,24 @@ class BiometricsEnvironment(
FingerprintEnrollStageThresholdInteractor(fingerprintEnrollmentRepository)
fun createGenerateChallengeInteractor(): GenerateChallengeInteractor =
GenerateChallengeInteractorImpl(fingerprintManager, context.userId, gateKeeperPasswordProvider)
GenerateChallengeInteractorImpl(fingerprintManager, userRepo, gateKeeperPasswordProvider)
fun createFingerprintEnrollInteractor(): EnrollFingerprintInteractor =
EnrollFingerprintInteractorImpl(context.userId, fingerprintManager, Settings)
EnrollFingerprintInteractorImpl(userRepo, fingerprintManager, Settings)
fun createFingerprintsEnrolledInteractor(): EnrolledFingerprintsInteractorImpl =
EnrolledFingerprintsInteractorImpl(fingerprintEnrollmentRepository)
fun createAuthenticateInteractor(): AuthenitcateInteractor =
AuthenticateInteractorImpl(fingerprintManager, context.userId)
AuthenticateInteractorImpl(fingerprintManager, userRepo)
fun createUserInteractor(): UserInteractor = UserInteractorImpl(userRepo)
fun createRemoveFingerprintInteractor(): RemoveFingerprintInteractor =
RemoveFingerprintsInteractorImpl(fingerprintManager, context.userId)
RemoveFingerprintsInteractorImpl(fingerprintManager, userRepo)
fun createRenameFingerprintInteractor(): RenameFingerprintInteractor =
RenameFingerprintsInteractorImpl(fingerprintManager, context.userId, backgroundDispatcher)
RenameFingerprintsInteractorImpl(fingerprintManager, userRepo, backgroundDispatcher)
fun createAccessibilityInteractor(): AccessibilityInteractor {
return AccessibilityInteractorImpl(context.getSystemService(AccessibilityManager::class.java)!!)

View File

@@ -19,19 +19,22 @@ package com.android.settings.biometrics.fingerprint2.domain.interactor
import android.hardware.fingerprint.FingerprintManager
import android.os.CancellationSignal
import android.util.Log
import com.android.settings.biometrics.fingerprint2.data.repository.UserRepo
import com.android.settings.biometrics.fingerprint2.lib.domain.interactor.AuthenitcateInteractor
import com.android.settings.biometrics.fingerprint2.lib.model.FingerprintAuthAttemptModel
import kotlin.coroutines.resume
import kotlinx.coroutines.CancellableContinuation
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.suspendCancellableCoroutine
class AuthenticateInteractorImpl(
private val fingerprintManager: FingerprintManager,
private val userId: Int,
private val userRepo: UserRepo,
) : AuthenitcateInteractor {
override suspend fun authenticate(): FingerprintAuthAttemptModel =
suspendCancellableCoroutine { c: CancellableContinuation<FingerprintAuthAttemptModel> ->
override suspend fun authenticate(): FingerprintAuthAttemptModel {
val userId = userRepo.currentUser.first()
return suspendCancellableCoroutine { c: CancellableContinuation<FingerprintAuthAttemptModel> ->
val authenticationCallback =
object : FingerprintManager.AuthenticationCallback() {
@@ -64,6 +67,7 @@ class AuthenticateInteractorImpl(
userId,
)
}
}
companion object {
private const val TAG = "AuthenticateInteractor"

View File

@@ -22,6 +22,7 @@ import android.os.CancellationSignal
import android.util.Log
import com.android.settings.biometrics.fingerprint2.conversion.Util.toEnrollError
import com.android.settings.biometrics.fingerprint2.conversion.Util.toOriginalReason
import com.android.settings.biometrics.fingerprint2.data.repository.UserRepo
import com.android.settings.biometrics.fingerprint2.lib.domain.interactor.EnrollFingerprintInteractor
import com.android.settings.biometrics.fingerprint2.lib.model.EnrollReason
import com.android.settings.biometrics.fingerprint2.lib.model.FingerEnrollState
@@ -33,10 +34,11 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.update
class EnrollFingerprintInteractorImpl(
private val userId: Int,
private val userRepo: UserRepo,
private val fingerprintManager: FingerprintManager,
private val fingerprintFlow: FingerprintFlow,
) : EnrollFingerprintInteractor {
@@ -47,6 +49,7 @@ class EnrollFingerprintInteractorImpl(
enrollReason: EnrollReason,
fingerprintEnrollOptions: FingerprintEnrollOptions,
): Flow<FingerEnrollState> = callbackFlow {
val userId = userRepo.currentUser.first()
// TODO (b/308456120) Improve this logic
if (enrollRequestOutstanding.value) {
Log.d(TAG, "Outstanding enroll request, waiting 150ms")

View File

@@ -19,19 +19,22 @@ package com.android.settings.biometrics.fingerprint2.domain.interactor
import android.content.Intent
import android.hardware.fingerprint.FingerprintManager
import com.android.settings.biometrics.GatekeeperPasswordProvider
import com.android.settings.biometrics.fingerprint2.data.repository.UserRepo
import com.android.settings.biometrics.fingerprint2.lib.domain.interactor.GenerateChallengeInteractor
import com.android.settings.password.ChooseLockSettingsHelper
import kotlinx.coroutines.flow.first
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
class GenerateChallengeInteractorImpl(
private val fingerprintManager: FingerprintManager,
private val userId: Int,
private val userRepo: UserRepo,
private val gatekeeperPasswordProvider: GatekeeperPasswordProvider,
) : GenerateChallengeInteractor {
override suspend fun generateChallenge(gateKeeperPasswordHandle: Long): Pair<Long, ByteArray> =
suspendCoroutine {
override suspend fun generateChallenge(gateKeeperPasswordHandle: Long): Pair<Long, ByteArray> {
val userId = userRepo.currentUser.first()
return suspendCoroutine {
val callback =
FingerprintManager.GenerateChallengeCallback { _, userId, challenge ->
val intent = Intent()
@@ -45,4 +48,5 @@ class GenerateChallengeInteractorImpl(
}
fingerprintManager.generateChallenge(userId, callback)
}
}
}

View File

@@ -18,17 +18,21 @@ package com.android.settings.biometrics.fingerprint2.domain.interactor
import android.hardware.fingerprint.FingerprintManager
import android.hardware.fingerprint.FingerprintManager.RemovalCallback
import com.android.settings.biometrics.fingerprint2.data.repository.UserRepo
import com.android.settings.biometrics.fingerprint2.lib.domain.interactor.RemoveFingerprintInteractor
import com.android.settings.biometrics.fingerprint2.lib.model.FingerprintData
import kotlinx.coroutines.flow.first
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
class RemoveFingerprintsInteractorImpl(
private val fingerprintManager: FingerprintManager,
private val userId: Int,
private val userRepo: UserRepo,
) : RemoveFingerprintInteractor {
override suspend fun removeFingerprint(fp: FingerprintData): Boolean = suspendCoroutine {
override suspend fun removeFingerprint(fp: FingerprintData): Boolean {
val userId = userRepo.currentUser.first()
return suspendCoroutine {
val callback =
object : RemovalCallback() {
override fun onRemovalError(
@@ -52,4 +56,5 @@ class RemoveFingerprintsInteractorImpl(
callback,
)
}
}
}

View File

@@ -17,18 +17,21 @@
package com.android.settings.biometrics.fingerprint2.domain.interactor
import android.hardware.fingerprint.FingerprintManager
import com.android.settings.biometrics.fingerprint2.data.repository.UserRepo
import com.android.settings.biometrics.fingerprint2.lib.domain.interactor.RenameFingerprintInteractor
import com.android.settings.biometrics.fingerprint2.lib.model.FingerprintData
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.withContext
class RenameFingerprintsInteractorImpl(
private val fingerprintManager: FingerprintManager,
private val userId: Int,
private val userRepo: UserRepo,
private val backgroundDispatcher: CoroutineDispatcher,
) : RenameFingerprintInteractor {
override suspend fun renameFingerprint(fp: FingerprintData, newName: String) {
val userId = userRepo.currentUser.first()
withContext(backgroundDispatcher) { fingerprintManager.rename(fp.fingerId, userId, newName) }
}
}

View File

@@ -150,6 +150,9 @@ public class BluetoothDetailsSpatialAudioController extends BluetoothDetailsCont
@Override
protected void init(PreferenceScreen screen) {
mProfilesContainer = screen.findPreference(getPreferenceKey());
if (com.android.settings.flags.Flags.enableBluetoothDeviceDetailsPolish()) {
mProfilesContainer.setLayoutResource(R.layout.preference_category_bluetooth_no_padding);
}
refresh();
}

View File

@@ -0,0 +1,111 @@
/*
* Copyright (C) 2024 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.connecteddevice.display
import android.graphics.RectF
import kotlin.math.hypot
// Unfortunately, in the world of IEEE 32-bit floats, A + X - X is not always == A
// For example: A = 1075.4271f
// C = 1249.2203f
// For example: - A - 173.79326f = - C
// However: - C + A = - 173.79321f
// So we need to keep track of how the movingDisplay block is attaching to otherDisplays throughout
// the calculations below. We cannot use the rect.left with its width as a proxy for rect.right. We
// have to save the "inner" or attached side and use the width or height to calculate the "external"
// side.
/** A potential X position for the display to clamp at. */
private class XCoor(
val left : Float, val right : Float,
/**
* If present, the position of the display being attached to. If absent, indicates the X
* position is derived from the exact drag position.
*/
val attaching : RectF?,
)
/** A potential Y position for the display to clamp at. */
private class YCoor(
val top : Float, val bottom : Float,
/**
* If present, the position of the display being attached to. If absent, indicates the Y
* position is derived from the exact drag position.
*/
val attaching : RectF?,
)
/**
* Finds the optimal clamp position assuming the user has dragged the block to `movingDisplay`.
*
* @param otherDisplays positions of the stationary displays (every one not being dragged)
* @param movingDisplay the position the user is current holding the block during a drag
*
* @return the clamp position as a RectF, whose dimensions will match that of `movingDisplay`
*/
fun clampPosition(otherDisplays : Iterable<RectF>, movingDisplay : RectF) : RectF {
val xCoors = otherDisplays.flatMap {
listOf(
// Attaching to left edge of `it`
XCoor(it.left - movingDisplay.width(), it.left, it),
// Attaching to right edge of `it`
XCoor(it.right, it.right + movingDisplay.width(), it),
)
}.plusElement(XCoor(movingDisplay.left, movingDisplay.right, null))
val yCoors = otherDisplays.flatMap {
listOf(
// Attaching to the top edge of `it`
YCoor(it.top - movingDisplay.height(), it.top, it),
// Attaching to the bottom edge of `it`
YCoor(it.bottom, it.bottom + movingDisplay.height(), it),
)
}.plusElement(YCoor(movingDisplay.top, movingDisplay.bottom, null))
class Cand(val x : XCoor, val y : YCoor)
val candidateGrid = xCoors.flatMap { x -> yCoors.map { y -> Cand(x, y) }}
val hasAttachInRange = candidateGrid.filter {
if (it.x.attaching != null) {
// Attaching to a vertical (left or right) edge. The y range of dragging and
// stationary blocks must overlap.
it.y.top <= it.x.attaching.bottom && it.y.bottom >= it.x.attaching.top
} else if (it.y.attaching != null) {
// Attaching to a horizontal (top or bottom) edge. The x range of dragging and
// stationary blocks must overlap.
it.x.left <= it.y.attaching.right && it.x.right >= it.y.attaching.left
} else {
// Not attaching to another display's edge at all, so not a valid clamp position.
false
}
}
// Clamp positions closest to the user's drag position are best. Sort by increasing distance
// from it, so the best will be first.
val prioritized = hasAttachInRange.sortedBy {
hypot(it.x.left - movingDisplay.left, it.y.top - movingDisplay.top)
}
val notIntersectingAny = prioritized.asSequence()
.map { RectF(it.x.left, it.y.top, it.x.right, it.y.bottom) }
.filter { p -> otherDisplays.all { !RectF.intersects(p, it) } }
// Note we return a copy of `movingDisplay` if there is no valid clamp position, which will only
// happen if `otherDisplays` is empty or has no valid rectangles. It may not be wise to rely on
// this behavior.
return notIntersectingAny.firstOrNull() ?: RectF(movingDisplay)
}

View File

@@ -32,7 +32,7 @@ class DataSaverMainSwitchPreference(context: Context) :
private var dataSaverBackendListener: DataSaverBackend.Listener? = null
override val key
get() = "use_data_saver"
get() = KEY
override val title
get() = R.string.data_saver_switch_title
@@ -46,7 +46,7 @@ class DataSaverMainSwitchPreference(context: Context) :
ReadWritePermit.ALLOW
override fun onStart(context: PreferenceLifecycleContext) {
val listener = DataSaverBackend.Listener { context.notifyPreferenceChange(this) }
val listener = DataSaverBackend.Listener { context.notifyPreferenceChange(KEY) }
dataSaverBackendListener = listener
dataSaverBackend.addListener(listener)
}
@@ -71,4 +71,8 @@ class DataSaverMainSwitchPreference(context: Context) :
dataSaverBackend.isDataSaverEnabled = value as Boolean
}
}
companion object {
const val KEY = "use_data_saver"
}
}

View File

@@ -71,7 +71,7 @@ class DataSaverScreen :
override fun hasCompleteHierarchy() = false
override fun onStart(context: PreferenceLifecycleContext) {
val listener = DataSaverBackend.Listener { context.notifyPreferenceChange(this) }
val listener = DataSaverBackend.Listener { context.notifyPreferenceChange(KEY) }
dataSaverBackendListener = listener
dataSaverBackend = DataSaverBackend(context).apply { addListener(listener) }
}

View File

@@ -18,7 +18,10 @@ package com.android.settings.development.linuxterminal;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Process;
import android.os.storage.StorageManager;
import android.text.TextUtils;
import android.util.DataUnit;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -28,30 +31,45 @@ import com.android.settings.R;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
import java.util.Objects;
/** Preference controller for Linux terminal option in developers option */
public class LinuxTerminalPreferenceController extends DeveloperOptionsPreferenceController
implements PreferenceControllerMixin {
@VisibleForTesting
static final int TERMINAL_PACKAGE_NAME_RESID = R.string.config_linux_terminal_app_package_name;
@VisibleForTesting
static final long MEMORY_MIN_BYTES = DataUnit.GIGABYTES.toBytes(4); // 4_000_000_000
@VisibleForTesting
static final long STORAGE_MIN_BYTES = DataUnit.GIBIBYTES.toBytes(128); // 128 * 2^30
private static final String LINUX_TERMINAL_KEY = "linux_terminal";
@Nullable private final String mTerminalPackageName;
private final boolean mIsDeviceCapable;
public LinuxTerminalPreferenceController(@NonNull Context context) {
super(context);
String packageName = context.getString(TERMINAL_PACKAGE_NAME_RESID);
mTerminalPackageName =
isPackageInstalled(context.getPackageManager(), packageName) ? packageName : null;
StorageManager storageManager =
Objects.requireNonNull(context.getSystemService(StorageManager.class));
mIsDeviceCapable =
getTotalMemory() >= MEMORY_MIN_BYTES
&& storageManager.getPrimaryStorageSize() >= STORAGE_MIN_BYTES;
}
// Avoid lazy initialization because this may be called before displayPreference().
@Override
public boolean isAvailable() {
// Returns true only if the terminal app is installed which only happens when the build flag
// RELEASE_AVF_SUPPORT_CUSTOM_VM_WITH_PARAVIRTUALIZED_DEVICES is true.
// Check build flag RELEASE_AVF_SUPPORT_CUSTOM_VM_WITH_PARAVIRTUALIZED_DEVICES indirectly
// by checking whether the terminal app is installed.
// TODO(b/343795511): Add explicitly check for the flag when it's accessible from Java code.
return mTerminalPackageName != null;
return mTerminalPackageName != null && mIsDeviceCapable;
}
@Override
@@ -73,4 +91,10 @@ public class LinuxTerminalPreferenceController extends DeveloperOptionsPreferenc
return false;
}
}
// Can be overridden for test
@VisibleForTesting
long getTotalMemory() {
return Process.getTotalMemory();
}
}

View File

@@ -101,7 +101,7 @@ class AdaptiveSleepPreference :
val receiver =
object : BroadcastReceiver() {
override fun onReceive(receiverContext: Context, intent: Intent) {
context.notifyPreferenceChange(this@AdaptiveSleepPreference)
context.notifyPreferenceChange(KEY)
}
}
context.registerReceiver(
@@ -111,7 +111,7 @@ class AdaptiveSleepPreference :
broadcastReceiver = receiver
val listener = OnSensorPrivacyChangedListener { _, _ ->
context.notifyPreferenceChange(this)
context.notifyPreferenceChange(KEY)
}
SensorPrivacyManager.getInstance(context).addSensorPrivacyListener(CAMERA, listener)
sensorPrivacyChangedListener = listener

View File

@@ -58,7 +58,7 @@ class BrightnessLevelPreference :
private var displayListener: DisplayListener? = null
override val key: String
get() = "brightness"
get() = KEY
override val title: Int
get() = R.string.brightness
@@ -85,10 +85,7 @@ class BrightnessLevelPreference :
}
override fun onStart(context: PreferenceLifecycleContext) {
val observer =
KeyedObserver<String> { _, _ ->
context.notifyPreferenceChange(this@BrightnessLevelPreference)
}
val observer = KeyedObserver<String> { _, _ -> context.notifyPreferenceChange(KEY) }
brightnessObserver = observer
SettingsSystemStore.get(context)
.addObserver(System.SCREEN_AUTO_BRIGHTNESS_ADJ, observer, HandlerExecutor.main)
@@ -100,7 +97,7 @@ class BrightnessLevelPreference :
override fun onDisplayRemoved(displayId: Int) {}
override fun onDisplayChanged(displayId: Int) {
context.notifyPreferenceChange(this@BrightnessLevelPreference)
context.notifyPreferenceChange(KEY)
}
}
displayListener = listener
@@ -162,5 +159,9 @@ class BrightnessLevelPreference :
value < GAMMA_SPACE_MIN -> 0.0
else -> (value - GAMMA_SPACE_MIN) / (GAMMA_SPACE_MAX - GAMMA_SPACE_MIN)
}
companion object {
const val KEY = "brightness"
}
}
// LINT.ThenChange(BrightnessLevelPreferenceController.java)

View File

@@ -39,7 +39,7 @@ import kotlin.math.roundToInt
// LINT.IfChange
class PeakRefreshRateSwitchPreference :
SwitchPreference(PEAK_REFRESH_RATE, R.string.peak_refresh_rate_title),
SwitchPreference(KEY, R.string.peak_refresh_rate_title),
PreferenceAvailabilityProvider,
PreferenceSummaryProvider,
PreferenceLifecycleProvider {
@@ -69,7 +69,7 @@ class PeakRefreshRateSwitchPreference :
// KEY_PEAK_REFRESH_RATE_DEFAULT value could be added, changed, removed or
// unchanged.
// Just force a UI update for any case.
context.notifyPreferenceChange(this)
context.notifyPreferenceChange(KEY)
}
propertiesChangedListener = listener
@@ -97,14 +97,13 @@ class PeakRefreshRateSwitchPreference :
override fun contains(key: String) = settingsStore.contains(key)
override fun <T : Any> getDefaultValue(key: String, valueType: Class<T>): T? {
if (key != PEAK_REFRESH_RATE) return super.getDefaultValue(key, valueType)
if (key != KEY) return super.getDefaultValue(key, valueType)
return context.defaultPeakRefreshRate.refreshRateAsBoolean(context) as T
}
override fun <T : Any> getValue(key: String, valueType: Class<T>): T? {
if (key != PEAK_REFRESH_RATE) return null
val refreshRate =
settingsStore.getFloat(PEAK_REFRESH_RATE) ?: context.defaultPeakRefreshRate
if (key != KEY) return null
val refreshRate = settingsStore.getFloat(KEY) ?: context.defaultPeakRefreshRate
return refreshRate.refreshRateAsBoolean(context) as T
}
@@ -113,12 +112,12 @@ class PeakRefreshRateSwitchPreference :
override fun <T : Any> setValue(key: String, valueType: Class<T>, value: T?) =
when {
key != PEAK_REFRESH_RATE -> {}
value == null -> settingsStore.setFloat(PEAK_REFRESH_RATE, null)
key != KEY -> {}
value == null -> settingsStore.setFloat(KEY, null)
else -> {
val peakRefreshRate =
if (value as Boolean) context.refreshRateIfON() else DEFAULT_REFRESH_RATE
settingsStore.setFloat(PEAK_REFRESH_RATE, peakRefreshRate)
settingsStore.setFloat(KEY, peakRefreshRate)
}
}
@@ -130,6 +129,7 @@ class PeakRefreshRateSwitchPreference :
}
companion object {
const val KEY = PEAK_REFRESH_RATE
private const val INVALIDATE_REFRESH_RATE: Float = -1f
private val Context.peakRefreshRate: Float

View File

@@ -112,7 +112,7 @@ class DarkModeScreen :
val broadcastReceiver =
object : BroadcastReceiver() {
override fun onReceive(receiverContext: Context, intent: Intent) {
context.notifyPreferenceChange(this@DarkModeScreen)
context.notifyPreferenceChange(KEY)
}
}
context.registerReceiver(
@@ -121,7 +121,7 @@ class DarkModeScreen :
)
val darkModeObserver = DarkModeObserver(context)
darkModeObserver.subscribe { context.notifyPreferenceChange(this@DarkModeScreen) }
darkModeObserver.subscribe { context.notifyPreferenceChange(KEY) }
fragmentStates[context] = FragmentState(broadcastReceiver, darkModeObserver)
}

View File

@@ -59,13 +59,13 @@ class BatterySaverPreference :
object : BatterySaverListener {
override fun onPowerSaveModeChanged() {
handler.postDelayed(
{ context.notifyPreferenceChange(this@BatterySaverPreference) },
{ context.notifyPreferenceChange(KEY) },
SWITCH_ANIMATION_DURATION,
)
}
override fun onBatteryChanged(pluggedIn: Boolean) =
context.notifyPreferenceChange(this@BatterySaverPreference)
context.notifyPreferenceChange(KEY)
}
)
setListening(true)

View File

@@ -71,6 +71,7 @@ import java.util.Locale;
public class LocaleListEditor extends RestrictedSettingsFragment implements View.OnTouchListener {
protected static final String INTENT_LOCALE_KEY = "localeInfo";
protected static final String EXTRA_SYSTEM_LOCALE_DIALOG_TYPE = "system_locale_dialog_type";
protected static final String EXTRA_RESULT_LOCALE = "result_locale";
protected static final String LOCALE_SUGGESTION = "locale_suggestion";
private static final String TAG = LocaleListEditor.class.getSimpleName();

View File

@@ -21,7 +21,7 @@ import com.android.internal.app.LocaleStore;
import java.util.List;
/** Interface for when locale list changes in SearchView . */
/** Interface for when locale list changes in SearchView. */
public interface LocaleListSearchCallback {
/** Callback method for searching changes. */

View File

@@ -16,13 +16,17 @@
package com.android.settings.localepicker;
import static com.android.settings.localepicker.LocaleListEditor.EXTRA_RESULT_LOCALE;
import static com.android.settings.localepicker.RegionAndNumberingSystemPickerFragment.EXTRA_IS_NUMBERING_SYSTEM;
import android.content.Context;
import android.os.Bundle;
import android.os.LocaleList;
import android.provider.Settings;
import android.util.ArrayMap;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
@@ -30,7 +34,10 @@ import androidx.preference.PreferenceScreen;
import com.android.internal.app.LocaleCollectorBase;
import com.android.internal.app.LocaleHelper;
import com.android.internal.app.LocaleStore;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.SubSettingLauncher;
import com.android.settingslib.core.instrumentation.Instrumentable;
import java.util.ArrayList;
import java.util.Collections;
@@ -43,40 +50,27 @@ import java.util.stream.Collectors;
/** A base controller for handling locale controllers. */
public abstract class LocalePickerBaseListPreferenceController extends
BasePreferenceController implements LocaleListSearchCallback {
private static final String TAG = "LocalePickerBaseListPreference";
private static final String KEY_SUGGESTED = "suggested";
private static final String KEY_SUPPORTED = "supported";
private PreferenceCategory mPreferenceCategory;
private LocaleList mExplicitLocales;
private Set<LocaleStore.LocaleInfo> mLocaleList;
private List<LocaleStore.LocaleInfo> mLocaleOptions;
private Map<String, Preference> mPreferences;
private String mPackageName;
private boolean mCountryMode;
private boolean mIsCountryMode;
@Nullable private LocaleStore.LocaleInfo mParentLocale;
public LocalePickerBaseListPreferenceController(@NonNull Context context,
@NonNull String preferenceKey) {
super(context, preferenceKey);
// TODO: Should get extra from fragment.
// if (isDeviceDemoMode()) {
// Bundle bundle = preference.getExtras();
// mExplicitLocales = bundle == null
// ? null
// : bundle.getParcelable(Settings.EXTRA_EXPLICIT_LOCALES, LocaleList.class);
// Log.d(TAG, "Has explicit locales : " + mExplicitLocales);
// }
mLocaleList = getLocaleCollectorController(context).getSupportedLocaleList(null,
false, false);
mLocaleOptions = new ArrayList<>(mLocaleList.size());
mPreferences = new ArrayMap<>();
}
private boolean isDeviceDemoMode() {
return Settings.Global.getInt(
mContext.getContentResolver(), Settings.Global.DEVICE_DEMO_MODE, 0) == 1;
}
@Override
public void displayPreference(@NonNull PreferenceScreen screen) {
super.displayPreference(screen);
@@ -91,8 +85,21 @@ public abstract class LocalePickerBaseListPreferenceController extends
}
List<LocaleStore.LocaleInfo> result;
mParentLocale = getParentLocale();
if (mParentLocale != null) {
mIsCountryMode = true;
mLocaleList = getLocaleCollectorController(mContext).getSupportedLocaleList(
mParentLocale, false, mIsCountryMode);
mLocaleOptions = new ArrayList<>(mLocaleList.size());
if (!getPreferenceCategoryKey().contains(KEY_SUGGESTED)) {
mPreferenceCategory.setTitle(
mContext.getString(R.string.all_supported_locales_regions_title));
}
}
result = getSortedLocaleList(
getPreferenceCategoryKey().contains(KEY_SUGGESTED) ? getSuggestedLocaleList()
getPreferenceCategoryKey().contains(KEY_SUGGESTED)
? getSuggestedLocaleList()
: getSupportedLocaleList());
final Map<String, Preference> existingPreferences = mPreferences;
@@ -113,12 +120,7 @@ public abstract class LocalePickerBaseListPreferenceController extends
newList = getSortedSuggestedLocaleFromSearchList(
newList, getSuggestedLocaleList());
}
if (!newList.isEmpty()) {
mPreferenceCategory.setVisible(true);
setupPreference(newList, existingPreferences);
} else {
mPreferenceCategory.setVisible(false);
}
}
private List<LocaleStore.LocaleInfo> getSortedSuggestedLocaleFromSearchList(
@@ -138,6 +140,12 @@ public abstract class LocalePickerBaseListPreferenceController extends
private void setupPreference(List<LocaleStore.LocaleInfo> localeInfoList,
Map<String, Preference> existingPreferences) {
Log.d(TAG, "setupPreference: isNumberingMode = " + isNumberingMode());
if (isNumberingMode() && getPreferenceCategoryKey().contains(KEY_SUPPORTED)) {
mPreferenceCategory.setTitle(
mContext.getString(R.string.all_supported_numbering_system_title));
}
localeInfoList.stream().forEach(locale ->
{
Preference pref = existingPreferences.remove(locale.getId());
@@ -146,15 +154,16 @@ public abstract class LocalePickerBaseListPreferenceController extends
mPreferenceCategory.addPreference(pref);
}
String localeName =
mCountryMode ? locale.getFullCountryNameNative() : locale.getFullNameNative();
mIsCountryMode ? locale.getFullCountryNameNative() : locale.getFullNameNative();
pref.setTitle(localeName);
pref.setKey(locale.toString());
pref.setOnPreferenceClickListener(clickedPref -> {
// TODO: Click locale to show region or numbering system page if needed.
switchFragment(locale);
return true;
});
mPreferences.put(locale.getId(), pref);
});
mPreferenceCategory.setVisible(mPreferenceCategory.getPreferenceCount() > 0);
}
@Override
@@ -166,14 +175,16 @@ public abstract class LocalePickerBaseListPreferenceController extends
protected abstract LocaleCollectorBase getLocaleCollectorController(Context context);
@Nullable protected abstract LocaleStore.LocaleInfo getParentLocale();
protected abstract boolean isNumberingMode();
@Nullable protected abstract LocaleList getExplicitLocaleList();
protected String getPackageName() {
return mPackageName;
}
protected LocaleList getExplicitLocaleList() {
return mExplicitLocales;
}
protected List<LocaleStore.LocaleInfo> getSuggestedLocaleList() {
mLocaleOptions.clear();
if (mLocaleList != null && !mLocaleList.isEmpty()) {
@@ -203,8 +214,46 @@ public abstract class LocalePickerBaseListPreferenceController extends
List<LocaleStore.LocaleInfo> localeInfos) {
final Locale sortingLocale = Locale.getDefault();
final LocaleHelper.LocaleInfoComparator comp =
new LocaleHelper.LocaleInfoComparator(sortingLocale, mCountryMode);
new LocaleHelper.LocaleInfoComparator(sortingLocale, mIsCountryMode);
Collections.sort(localeInfos, comp);
return localeInfos;
}
private void switchFragment(LocaleStore.LocaleInfo localeInfo) {
boolean shouldShowLocaleEditor = shouldShowLocaleEditor(localeInfo);
String extraKey = shouldShowLocaleEditor ? LocaleListEditor.INTENT_LOCALE_KEY
: RegionAndNumberingSystemPickerFragment.EXTRA_TARGET_LOCALE;
String fragmentName = shouldShowLocaleEditor ? LocaleListEditor.class.getCanonicalName()
: RegionAndNumberingSystemPickerFragment.class.getCanonicalName();
final Bundle extra = new Bundle();
extra.putSerializable(extraKey, localeInfo);
extra.putBoolean(EXTRA_IS_NUMBERING_SYSTEM, localeInfo.hasNumberingSystems());
if (shouldShowLocaleEditor) {
extra.putBoolean(EXTRA_RESULT_LOCALE, true);
}
new SubSettingLauncher(mContext)
.setDestination(fragmentName)
.setSourceMetricsCategory(Instrumentable.METRICS_CATEGORY_UNKNOWN)
.setArguments(extra)
.launch();
}
private boolean shouldShowLocaleEditor(LocaleStore.LocaleInfo localeInfo) {
boolean isSystemLocale = localeInfo.isSystemLocale();
boolean isRegionLocale = localeInfo.getParent() != null;
boolean mayHaveDifferentNumberingSystem = localeInfo.hasNumberingSystems();
mLocaleList = getLocaleCollectorController(mContext).getSupportedLocaleList(localeInfo,
false, localeInfo != null);
Log.d(TAG,
"shouldShowLocaleEditor: isSystemLocale = " + isSystemLocale + ", isRegionLocale = "
+ isRegionLocale + ", mayHaveDifferentNumberingSystem = "
+ mayHaveDifferentNumberingSystem + ", isSuggested = "
+ localeInfo.isSuggested() + ", isNumberingMode = " + isNumberingMode());
return mLocaleList.size() == 1 || isSystemLocale || localeInfo.isSuggested()
|| (isRegionLocale && !mayHaveDifferentNumberingSystem)
|| isNumberingMode();
}
}

View File

@@ -55,19 +55,41 @@ import java.util.Set;
* default locale.</p>
*/
public class RegionAndNumberingSystemPickerFragment extends DashboardFragment {
private static final String TAG = "RegionAndNumberingSystemPickerFragment";
public static final String EXTRA_TARGET_LOCALE = "extra_target_locale";
public static final String EXTRA_IS_NUMBERING_SYSTEM = "extra_is_numbering_system";
private static final String TAG = "RegionAndNumberingSystemPickerFragment";
private static final String KEY_PREFERENCE_SYSTEM_LOCALE_LIST = "system_locale_list";
private static final String KEY_PREFERENCE_SYSTEM_LOCALE_SUGGESTED_LIST =
"system_locale_suggested_list";
@Nullable
private SystemLocaleAllListPreferenceController mSystemLocaleAllListPreferenceController;
@Nullable
private SystemLocaleSuggestedListPreferenceController mSuggestedListPreferenceController;
@Nullable
private LocaleStore.LocaleInfo mLocaleInfo;
private RecyclerView mRecyclerView;
private AppBarLayout mAppBarLayout;
private Activity mActivity;
private boolean mIsNumberingMode;
@Override
public void onCreate(@NonNull Bundle icicle) {
super.onCreate(icicle);
mActivity = getActivity();
if (mActivity.isFinishing()) {
if (mActivity == null || mActivity.isFinishing()) {
Log.d(TAG, "onCreate, no activity or activity is finishing");
return;
}
if (mLocaleInfo == null) {
Log.d(TAG, "onCreate, can not get localeInfo");
return;
}
mActivity.setTitle(mLocaleInfo.getFullNameNative());
}
@Override
@@ -102,8 +124,15 @@ public class RegionAndNumberingSystemPickerFragment extends DashboardFragment {
private List<AbstractPreferenceController> buildPreferenceControllers(
@NonNull Context context, @Nullable Lifecycle lifecycle) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
// TODO: b/30358431 - Add preference of region locales.
mLocaleInfo = (LocaleStore.LocaleInfo) getArguments().getSerializable(EXTRA_TARGET_LOCALE);
mIsNumberingMode = getArguments().getBoolean(EXTRA_IS_NUMBERING_SYSTEM);
mSuggestedListPreferenceController = new SystemLocaleSuggestedListPreferenceController(
context, KEY_PREFERENCE_SYSTEM_LOCALE_SUGGESTED_LIST, mLocaleInfo,
mIsNumberingMode);
mSystemLocaleAllListPreferenceController = new SystemLocaleAllListPreferenceController(
context, KEY_PREFERENCE_SYSTEM_LOCALE_LIST, mLocaleInfo, mIsNumberingMode);
controllers.add(mSuggestedListPreferenceController);
controllers.add(mSystemLocaleAllListPreferenceController);
return controllers;
}

View File

@@ -0,0 +1,87 @@
/**
* Copyright (C) 2024 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.localepicker;
import android.content.Context;
import android.os.LocaleList;
import com.android.internal.app.LocaleCollectorBase;
import com.android.internal.app.LocaleStore;
import com.android.internal.app.SystemLocaleCollector;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
public class SystemLocaleAllListPreferenceController extends
LocalePickerBaseListPreferenceController {
private static final String KEY_PREFERENCE_CATEGORY_ADD_LANGUAGE_ALL_SUPPORTED =
"system_language_all_supported_category";
private static final String KEY_PREFERENCE_SYSTEM_LOCALE_LIST = "system_locale_list";
private boolean mIsNumberingSystemMode;
@Nullable private LocaleStore.LocaleInfo mLocaleInfo;
@Nullable private LocaleList mExplicitLocales;
public SystemLocaleAllListPreferenceController(@NonNull Context context,
@NonNull String preferenceKey) {
super(context, preferenceKey);
}
public SystemLocaleAllListPreferenceController(@NonNull Context context,
@NonNull String preferenceKey, @NonNull LocaleStore.LocaleInfo parentLocale,
boolean isNumberingSystemMode) {
super(context, preferenceKey);
mLocaleInfo = parentLocale;
mIsNumberingSystemMode = isNumberingSystemMode;
}
public SystemLocaleAllListPreferenceController(@NonNull Context context,
@NonNull String preferenceKey, @Nullable LocaleList explicitLocales) {
super(context, preferenceKey);
mExplicitLocales = explicitLocales;
}
@Override
protected String getPreferenceCategoryKey() {
return KEY_PREFERENCE_CATEGORY_ADD_LANGUAGE_ALL_SUPPORTED;
}
@Override
public @NonNull String getPreferenceKey() {
return KEY_PREFERENCE_SYSTEM_LOCALE_LIST;
}
@Override
protected LocaleCollectorBase getLocaleCollectorController(Context context) {
return new SystemLocaleCollector(context, getExplicitLocaleList());
}
@Override
protected @Nullable LocaleStore.LocaleInfo getParentLocale() {
return mLocaleInfo;
}
@Override
protected boolean isNumberingMode() {
return mIsNumberingSystemMode;
}
@Override
protected @Nullable LocaleList getExplicitLocaleList() {
return mExplicitLocales;
}
}

View File

@@ -20,6 +20,8 @@ import android.app.Activity;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.os.Bundle;
import android.os.LocaleList;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
@@ -48,8 +50,6 @@ import com.android.settingslib.core.lifecycle.Lifecycle;
import com.google.android.material.appbar.AppBarLayout;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -68,12 +68,24 @@ public class SystemLocalePickerFragment extends DashboardFragment implements
private static final String TAG = "SystemLocalePickerFragment";
private static final String EXTRA_EXPAND_SEARCH_VIEW = "expand_search_view";
private static final String KEY_PREFERENCE_SYSTEM_LOCALE_LIST = "system_locale_list";
private static final String KEY_PREFERENCE_SYSTEM_LOCALE_SUGGESTED_LIST =
"system_locale_suggested_list";
@Nullable private SearchView mSearchView = null;
@Nullable private SearchFilter mSearchFilter = null;
@Nullable private Set<LocaleStore.LocaleInfo> mLocaleList;
@Nullable private List<LocaleStore.LocaleInfo> mLocaleOptions;
@Nullable private List<LocaleStore.LocaleInfo> mOriginalLocaleInfos;
@Nullable
private SearchView mSearchView = null;
@Nullable
private SearchFilter mSearchFilter = null;
@Nullable
private Set<LocaleStore.LocaleInfo> mLocaleList;
@Nullable
private List<LocaleStore.LocaleInfo> mLocaleOptions;
@Nullable
private List<LocaleStore.LocaleInfo> mOriginalLocaleInfos;
@Nullable
private SystemLocaleAllListPreferenceController mSystemLocaleAllListPreferenceController;
@Nullable
private SystemLocaleSuggestedListPreferenceController mSuggestedListPreferenceController;
private AppBarLayout mAppBarLayout;
private RecyclerView mRecyclerView;
private Activity mActivity;
@@ -138,12 +150,16 @@ public class SystemLocalePickerFragment extends DashboardFragment implements
}
private void filterSearch(@Nullable String query) {
if (mSystemLocaleAllListPreferenceController == null) {
Log.d(TAG, "filterSearch(), can not get preference.");
return;
}
if (mSearchFilter == null) {
mSearchFilter = new SearchFilter();
}
// TODO: b/30358431 - Add preference of system locales.
// mOriginalLocaleInfos = mSystemLocaleAllListPreferenceController.getSupportedLocaleList();
mOriginalLocaleInfos = mSystemLocaleAllListPreferenceController.getSupportedLocaleList();
// If we haven't load apps list completely, don't filter anything.
if (mOriginalLocaleInfos == null) {
Log.w(TAG, "Locales haven't loaded completely yet, so nothing can be filtered");
@@ -195,14 +211,19 @@ public class SystemLocalePickerFragment extends DashboardFragment implements
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
if (mSystemLocaleAllListPreferenceController == null
|| mSuggestedListPreferenceController == null) {
Log.d(TAG, "publishResults(), can not get preference.");
return;
}
mLocaleOptions = (ArrayList<LocaleStore.LocaleInfo>) results.values;
// Need to scroll to first preference when searching.
if (mRecyclerView != null) {
mRecyclerView.post(() -> mRecyclerView.scrollToPosition(0));
}
// TODO: b/30358431 - Add preference of system locales.
// mSystemLocaleAllListPreferenceController.onSearchListChanged(mLocaleOptions);
// mSuggestedListPreferenceController.onSearchListChanged(mLocaleOptions);
mSystemLocaleAllListPreferenceController.onSearchListChanged(mLocaleOptions);
mSuggestedListPreferenceController.onSearchListChanged(mLocaleOptions);
}
// TODO: decide if this is enough, or we want to use a BreakIterator...
@@ -271,11 +292,31 @@ public class SystemLocalePickerFragment extends DashboardFragment implements
private List<AbstractPreferenceController> buildPreferenceControllers(
@NonNull Context context, @Nullable Lifecycle lifecycle) {
LocaleList explicitLocales = null;
if (isDeviceDemoMode()) {
Bundle bundle = getIntent().getExtras();
explicitLocales = bundle == null
? null
: bundle.getParcelable(Settings.EXTRA_EXPLICIT_LOCALES, LocaleList.class);
Log.i(TAG, "Has explicit locales : " + explicitLocales);
}
mSuggestedListPreferenceController =
new SystemLocaleSuggestedListPreferenceController(context,
KEY_PREFERENCE_SYSTEM_LOCALE_SUGGESTED_LIST);
mSystemLocaleAllListPreferenceController = new SystemLocaleAllListPreferenceController(
context, KEY_PREFERENCE_SYSTEM_LOCALE_LIST, explicitLocales);
final List<AbstractPreferenceController> controllers = new ArrayList<>();
// TODO: b/30358431 - Add preference of system locales.
controllers.add(mSuggestedListPreferenceController);
controllers.add(mSystemLocaleAllListPreferenceController);
return controllers;
}
private boolean isDeviceDemoMode() {
return Settings.Global.getInt(
getContentResolver(), Settings.Global.DEVICE_DEMO_MODE, 0) == 1;
}
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider(R.xml.system_language_picker);
}

View File

@@ -0,0 +1,81 @@
/**
* Copyright (C) 2024 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.localepicker;
import android.content.Context;
import android.os.LocaleList;
import com.android.internal.app.LocaleCollectorBase;
import com.android.internal.app.LocaleStore;
import com.android.internal.app.SystemLocaleCollector;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
public class SystemLocaleSuggestedListPreferenceController extends
LocalePickerBaseListPreferenceController {
private static final String KEY_PREFERENCE_CATEGORY_ADD_A_LANGUAGE_SUGGESTED =
"system_language_suggested_category";
private static final String KEY_PREFERENCE_SYSTEM_LOCALE_SUGGESTED_LIST =
"system_locale_suggested_list";
@Nullable private LocaleStore.LocaleInfo mLocaleInfo;
private boolean mIsNumberingSystemMode;
public SystemLocaleSuggestedListPreferenceController(@NonNull Context context,
@NonNull String preferenceKey) {
super(context, preferenceKey);
}
public SystemLocaleSuggestedListPreferenceController(@NonNull Context context,
@NonNull String preferenceKey,
@NonNull LocaleStore.LocaleInfo parentLocale, boolean isNumberingSystemMode) {
super(context, preferenceKey);
mLocaleInfo = parentLocale;
mIsNumberingSystemMode = isNumberingSystemMode;
}
@Override
protected @NonNull String getPreferenceCategoryKey() {
return KEY_PREFERENCE_CATEGORY_ADD_A_LANGUAGE_SUGGESTED;
}
@Override
public @NonNull String getPreferenceKey() {
return KEY_PREFERENCE_SYSTEM_LOCALE_SUGGESTED_LIST;
}
@Override
protected LocaleCollectorBase getLocaleCollectorController(Context context) {
return new SystemLocaleCollector(context, getExplicitLocaleList());
}
@Override
protected @Nullable LocaleStore.LocaleInfo getParentLocale() {
return mLocaleInfo;
}
@Override
protected boolean isNumberingMode() {
return mIsNumberingSystemMode;
}
@Override
protected @Nullable LocaleList getExplicitLocaleList() {
return null;
}
}

View File

@@ -277,6 +277,12 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings impleme
if (roamingPreferenceController != null) {
roamingPreferenceController.init(getParentFragmentManager(), mSubId);
}
final SatelliteSettingsPreferenceCategoryController
satelliteSettingsPreferenceCategoryController =
use(SatelliteSettingsPreferenceCategoryController.class);
if (satelliteSettingsPreferenceCategoryController != null) {
satelliteSettingsPreferenceCategoryController.init(mSubId);
}
final SatelliteSettingPreferenceController satelliteSettingPreferenceController = use(
SatelliteSettingPreferenceController.class);
if (satelliteSettingPreferenceController != null) {

View File

@@ -0,0 +1,70 @@
/*
* Copyright (C) 2024 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.network.telephony;
import android.content.Context;
import android.os.PersistableBundle;
import android.telephony.CarrierConfigManager;
import android.telephony.satellite.SatelliteManager;
import android.util.Log;
import com.android.internal.telephony.flags.Flags;
import com.android.settings.network.CarrierConfigCache;
/** Preference controller for Satellite functions in mobile network settings.*/
public class SatelliteSettingsPreferenceCategoryController
extends TelephonyBasePreferenceController {
private static final String TAG = "SatelliteSettingsPrefCategoryCon";
private CarrierConfigCache mCarrierConfigCache;
private SatelliteManager mSatelliteManager;
public SatelliteSettingsPreferenceCategoryController(Context context, String key) {
super(context, key);
mCarrierConfigCache = CarrierConfigCache.getInstance(context);
mSatelliteManager = context.getSystemService(SatelliteManager.class);
}
/**
* Set subId for Satellite Settings category .
* @param subId subscription ID.
*/
public void init(int subId) {
Log.d(TAG, "init(), subId=" + subId);
mSubId = subId;
}
@Override
public int getAvailabilityStatus(int subId) {
if (!Flags.carrierEnabledSatelliteFlag()) {
Log.d(TAG, "getAvailabilityStatus(" + subId + ") : carrierEnabledSatelliteFlag "
+ "is disabled");
return UNSUPPORTED_ON_DEVICE;
}
if (mSatelliteManager == null) {
Log.d(TAG, "getAvailabilityStatus(" + subId + ") : SatelliteManager is null");
return UNSUPPORTED_ON_DEVICE;
}
final PersistableBundle carrierConfig = mCarrierConfigCache.getConfigForSubId(subId);
final boolean isSatelliteAttachSupported = carrierConfig.getBoolean(
CarrierConfigManager.KEY_SATELLITE_ATTACH_SUPPORTED_BOOL);
return isSatelliteAttachSupported ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
}
}

View File

@@ -465,7 +465,7 @@ public class UserSettings extends SettingsPreferenceFragment
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
int pos = 0;
if (!isCurrentUserAdmin() && (canSwitchUserNow() || Flags.newMultiuserSettingsUx())
&& !isCurrentUserGuest()) {
&& !isCurrentUserGuest() && !mUserManager.isProfile()) {
String nickname = mUserManager.getUserName();
MenuItem removeThisUser = menu.add(0, MENU_REMOVE_USER, pos++,
getResources().getString(R.string.user_remove_user_menu, nickname));

View File

@@ -32,6 +32,7 @@ import com.android.settings.widget.SettingsMainSwitchBar.OnBeforeCheckedChangeLi
import com.android.settingslib.RestrictedPreferenceHelper;
import com.android.settingslib.RestrictedPreferenceHelperProvider;
import com.android.settingslib.core.instrumentation.SettingsJankMonitor;
import com.android.settingslib.widget.GroupSectionDividerMixin;
import java.util.ArrayList;
import java.util.List;
@@ -42,7 +43,7 @@ import java.util.List;
* to enable or disable the preferences on the page.
*/
public class SettingsMainSwitchPreference extends TwoStatePreference implements
OnCheckedChangeListener, RestrictedPreferenceHelperProvider {
OnCheckedChangeListener, RestrictedPreferenceHelperProvider, GroupSectionDividerMixin {
private final List<OnBeforeCheckedChangeListener> mBeforeCheckedChangeListeners =
new ArrayList<>();

View File

@@ -0,0 +1,144 @@
/*
* Copyright (C) 2024 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.connecteddevice.display
import android.graphics.PointF
import android.graphics.RectF
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
@RunWith(RobolectricTestRunner::class)
class TopologyClampTest {
@Test
fun clampToSides() {
val start = RectF(6f, 0f, 16f, 10f)
val clamp1 = clampPosition(listOf(RectF(0f, 0f, 10f, 10f)), start)
assertEquals(RectF(10f, 0f, 20f, 10f), clamp1)
val clamp2 = clampPosition(listOf(RectF(18f, 0f, 28f, 10f)), start)
assertEquals(RectF(8f, 0f, 18f, 10f), clamp2)
}
@Test
fun clampToTopOrBottom() {
val start = RectF(0f, 6f, 10f, 16f)
val clamp1 = clampPosition(listOf(RectF(0f, 0f, 10f, 10f)), start)
assertEquals(RectF(0f, 10f, 10f, 20f), clamp1)
val clamp2 = clampPosition(listOf(RectF(0f, 18f, 10f, 28f)), start)
assertEquals(RectF(0f, 8f, 10f, 18f), clamp2)
}
@Test
fun clampToCloserSide() {
// Shift one pixel right.
val start = RectF(9f, 8f, 19f, 18f)
val clamp1 = clampPosition(listOf(RectF(0f, 0f, 10f, 10f)), start)
assertEquals(RectF(10f, 8f, 20f, 18f), clamp1)
// Shift two pixels down.
start.set(7f, 8f, 17f, 18f)
val clamp2 = clampPosition(listOf(RectF(0f, 0f, 10f, 10f)), start)
assertEquals(RectF(7f, 10f, 17f, 20f), clamp2)
// Shift three pixels left.
start.set(-7f, -6f, 3f, 4f);
val s3 = clampPosition(listOf(RectF(0f, 0f, 10f, 10f)), start)
assertEquals(RectF(-10f, -6f, 0f, 4f), s3)
}
@Test
fun clampToCloserDisplayInCorner() {
val start = RectF(9f, 6f, 19f, 16f)
val clamp1 = clampPosition(listOf(RectF(0f, 0f, 8f, 8f), RectF(8f, 0f, 16f, 4f)), start)
assertEquals(RectF(8f, 6f, 18f, 16f), clamp1)
start.set(10f, 5f, 20f, 15f)
val clamp2 = clampPosition(listOf(RectF(0f, 0f, 8f, 8f), RectF(8f, 0f, 16f, 4f)), start)
assertEquals(RectF(10f, 4f, 20f, 14f), clamp2)
}
@Test
fun clampToSecondDisplayToAvoidOverlap() {
val start = RectF(8f, 3f, 18f, 13f)
val clamp = clampPosition(listOf(RectF(0f, 0f, 8f, 8f), RectF(8f, 0f, 16f, 4f)), start)
assertEquals(RectF(8f, 4f, 18f, 14f), clamp)
}
@Test
fun clampToInnerCorner() {
val start = RectF(4f, 4f, 14f, 14f)
val clamp = clampPosition(listOf(RectF(5f, 0f, 10f, 5f), RectF(0f, 5f, 5f, 10f)), start)
assertEquals(RectF(5f, 5f, 15f, 15f), clamp)
}
@Test
fun mustBeAdjacent() {
val start = RectF(9f, 10f, 14f, 15f)
// Have candidate X, Y pair that is not adjacent to any display.
val clamp = clampPosition(listOf(RectF(5f, 0f, 10f, 5f), RectF(0f, 5f, 5f, 10f)), start)
assertEquals(RectF(5f, 10f, 10f, 15f), clamp)
}
@Test
fun mustNotIntersect() {
// 1 and 2 are attached with 1/3 of their respective sides. Attempt to drag the other
// display to 1's lower-right corner. It should be forced to the right side of 2.
//111
//111
//111
// 222
// 222
// 222
val start = RectF(30f, 30f, 60f, 60f)
val clamp = clampPosition(listOf(RectF(0f, 0f, 30f, 30f), RectF(20f, 30f, 50f, 60f)), start)
assertEquals(RectF(50f, 30f, 80f, 60f), clamp)
}
@Test
fun attachingToTwoRectsAtOnce() {
// 2 is being dragged and starts out overlapping 0 and 1, then it is
// clamped to the right side of 0 and the bottom of 1 at the same time.
//
//00
//002
// 2
// 11
// 11
val clamp = clampPosition(
listOf(RectF(0f, 0f, 20f, 20f), RectF(10f, 30f, 30f, 50f)),
RectF(10f, 11f, 20f, 31f))
assertEquals(RectF(20f, 10f, 30f, 30f), clamp)
}
@Test
fun attachingToTwoRectsAtOnceAxisSwapped() {
// Same as previous but with x and y swapped.
val clamp = clampPosition(
listOf(RectF(0f, 0f, 20f, 20f), RectF(30f, 10f, 50f, 30f)),
RectF(11f, 10f, 31f, 20f))
assertEquals(RectF(10f, 20f, 30f, 30f), clamp)
}
}

View File

@@ -16,6 +16,8 @@
package com.android.settings.development.linuxterminal;
import static com.android.settings.development.linuxterminal.LinuxTerminalPreferenceController.MEMORY_MIN_BYTES;
import static com.android.settings.development.linuxterminal.LinuxTerminalPreferenceController.STORAGE_MIN_BYTES;
import static com.android.settings.development.linuxterminal.LinuxTerminalPreferenceController.TERMINAL_PACKAGE_NAME_RESID;
import static com.google.common.truth.Truth.assertThat;
@@ -29,6 +31,7 @@ import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.storage.StorageManager;
import org.junit.Before;
import org.junit.Test;
@@ -43,6 +46,7 @@ public class LinuxTerminalPreferenceControllerTest {
@Mock private Context mContext;
@Mock private PackageManager mPackageManager;
@Mock private StorageManager mStorageManager;
@Mock private PackageInfo mPackageInfo;
private String mTerminalPackageName = "com.android.virtualization.terminal";
@@ -57,11 +61,30 @@ public class LinuxTerminalPreferenceControllerTest {
doReturn(mPackageInfo)
.when(mPackageManager)
.getPackageInfo(eq(mTerminalPackageName), anyInt());
doReturn(mStorageManager).when(mContext).getSystemService(StorageManager.class);
doReturn(STORAGE_MIN_BYTES).when(mStorageManager).getPrimaryStorageSize();
}
@Test
public void isAvailable_whenPackageExists_returnsTrue() throws NameNotFoundException {
mController = new LinuxTerminalPreferenceController(mContext);
public void isAvailable_whenMemoryInsufficient_returnFalse() {
mController = createController(mContext, MEMORY_MIN_BYTES / 2);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void isAvailable_whenDeviceStorageInsufficient_returnFalse() {
doReturn(STORAGE_MIN_BYTES / 2).when(mStorageManager).getPrimaryStorageSize();
mController = createController(mContext);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void isAvailable_whenPackageExists_returnsTrue() {
mController = createController(mContext);
assertThat(mController.isAvailable()).isTrue();
}
@@ -70,7 +93,7 @@ public class LinuxTerminalPreferenceControllerTest {
public void isAvailable_whenPackageNameIsNull_returnsFalse() {
doReturn(null).when(mContext).getString(TERMINAL_PACKAGE_NAME_RESID);
mController = new LinuxTerminalPreferenceController(mContext);
mController = createController(mContext);
assertThat(mController.isAvailable()).isFalse();
}
@@ -81,8 +104,21 @@ public class LinuxTerminalPreferenceControllerTest {
.when(mPackageManager)
.getPackageInfo(eq(mTerminalPackageName), anyInt());
mController = new LinuxTerminalPreferenceController(mContext);
mController = createController(mContext);
assertThat(mController.isAvailable()).isFalse();
}
private LinuxTerminalPreferenceController createController(Context context) {
return createController(context, MEMORY_MIN_BYTES);
}
private LinuxTerminalPreferenceController createController(Context context, long totalMemory) {
return new LinuxTerminalPreferenceController(context) {
@Override
public long getTotalMemory() {
return totalMemory;
}
};
}
}

View File

@@ -152,17 +152,17 @@ class FingerprintManagerInteractorTest {
enrolledFingerprintsInteractorUnderTest =
EnrolledFingerprintsInteractorImpl(fingerprintEnrollRepo)
generateChallengeInteractorUnderTest =
GenerateChallengeInteractorImpl(fingerprintManager, userId, gateKeeperPasswordProvider)
GenerateChallengeInteractorImpl(fingerprintManager, userRepo, gateKeeperPasswordProvider)
removeFingerprintsInteractorUnderTest =
RemoveFingerprintsInteractorImpl(fingerprintManager, userId)
RemoveFingerprintsInteractorImpl(fingerprintManager, userRepo)
renameFingerprintsInteractorUnderTest =
RenameFingerprintsInteractorImpl(fingerprintManager, userId, backgroundDispatcher)
authenticateInteractorImplUnderTest = AuthenticateInteractorImpl(fingerprintManager, userId)
RenameFingerprintsInteractorImpl(fingerprintManager, userRepo, backgroundDispatcher)
authenticateInteractorImplUnderTest = AuthenticateInteractorImpl(fingerprintManager, userRepo)
canEnrollFingerprintsInteractorUnderTest =
CanEnrollFingerprintsInteractorImpl(fingerprintEnrollRepo)
enrollInteractorUnderTest = EnrollFingerprintInteractorImpl(userId, fingerprintManager, flow)
enrollInteractorUnderTest = EnrollFingerprintInteractorImpl(userRepo, fingerprintManager, flow)
}
@Test

View File

@@ -0,0 +1,127 @@
/*
* Copyright (C) 2024 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.network.telephony;
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.os.Looper;
import android.os.PersistableBundle;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.telephony.CarrierConfigManager;
import android.telephony.satellite.SatelliteManager;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.android.internal.telephony.flags.Flags;
import com.android.settings.network.CarrierConfigCache;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
@RunWith(AndroidJUnit4.class)
public class SatelliteSettingsPreferenceCategoryControllerTest {
private static final String KEY = "key";
private static final int TEST_SUB_ID = 0;
@Rule
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
@Rule
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
@Mock
private CarrierConfigCache mCarrierConfigCache;
private Context mContext = null;
private SatelliteManager mSatelliteManager = null;
private SatelliteSettingsPreferenceCategoryController mController = null;
private PersistableBundle mCarrierConfig = new PersistableBundle();
@Before
public void setUp() {
if (Looper.myLooper() == null) {
Looper.prepare();
}
mContext = spy(ApplicationProvider.getApplicationContext());
mSatelliteManager = new SatelliteManager(mContext);
CarrierConfigCache.setTestInstance(mContext, mCarrierConfigCache);
when(mContext.getSystemService(SatelliteManager.class)).thenReturn(mSatelliteManager);
mController = new SatelliteSettingsPreferenceCategoryController(mContext, KEY);
}
@Test
@DisableFlags(Flags.FLAG_CARRIER_ENABLED_SATELLITE_FLAG)
public void getAvailabilityStatus_featureDisabled_returnUnsupport() {
int result = mController.getAvailabilityStatus(TEST_SUB_ID);
assertThat(result).isEqualTo(UNSUPPORTED_ON_DEVICE);
}
@Test
@EnableFlags(Flags.FLAG_CARRIER_ENABLED_SATELLITE_FLAG)
public void getAvailabilityStatus_noSatellite_returnUnsupport() {
when(mContext.getSystemService(SatelliteManager.class)).thenReturn(null);
mController = new SatelliteSettingsPreferenceCategoryController(mContext, KEY);
int result = mController.getAvailabilityStatus(TEST_SUB_ID);
assertThat(result).isEqualTo(UNSUPPORTED_ON_DEVICE);
}
@Test
@EnableFlags(Flags.FLAG_CARRIER_ENABLED_SATELLITE_FLAG)
public void getAvailabilityStatus_carrierIsNotSupport_returnUnavailable() {
when(mContext.getSystemService(SatelliteManager.class)).thenReturn(null);
mCarrierConfig.putBoolean(
CarrierConfigManager.KEY_SATELLITE_ATTACH_SUPPORTED_BOOL,
false);
when(mCarrierConfigCache.getConfigForSubId(TEST_SUB_ID)).thenReturn(mCarrierConfig);
int result = mController.getAvailabilityStatus(TEST_SUB_ID);
assertThat(result).isEqualTo(CONDITIONALLY_UNAVAILABLE);
}
@Test
@EnableFlags(Flags.FLAG_CARRIER_ENABLED_SATELLITE_FLAG)
public void getAvailabilityStatus_carrierIsSupport_returnAvailable() {
when(mContext.getSystemService(SatelliteManager.class)).thenReturn(null);
mCarrierConfig.putBoolean(
CarrierConfigManager.KEY_SATELLITE_ATTACH_SUPPORTED_BOOL,
true);
when(mCarrierConfigCache.getConfigForSubId(TEST_SUB_ID)).thenReturn(mCarrierConfig);
int result = mController.getAvailabilityStatus(TEST_SUB_ID);
assertThat(result).isEqualTo(AVAILABLE);
}
}

View File

@@ -51,6 +51,7 @@ import com.android.settings.privatespace.PrivateSpaceMaintainer.ErrorDeletingPri
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -234,6 +235,7 @@ public class PrivateSpaceMaintainerTest {
* Tests that {@link PrivateSpaceMaintainer#lockPrivateSpace()} when PS exists and is running
* locks the private profile.
*/
@Ignore("Flaky pre-submit b/378392936")
@Test
public void lockPrivateSpace_psExistsAndPrivateProfileRunning_locksCreatedPrivateSpace() {
mSetFlagsRule.enableFlags(
@@ -253,6 +255,7 @@ public class PrivateSpaceMaintainerTest {
* Tests that {@link PrivateSpaceMaintainer#lockPrivateSpace()} when PS exist and private
* profile not running returns false.
*/
@Ignore("Flaky pre-submit b/378392936")
@Test
public void lockPrivateSpace_psExistsAndPrivateProfileNotRunning_returnsFalse() {
mSetFlagsRule.enableFlags(