Snap for 12680993 from 05b9d038de
to 25Q1-release
Change-Id: I379d2c115af0891d302c382330af203aea486e68
This commit is contained in:
@@ -5372,6 +5372,23 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</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. -->
|
<!-- This is the longest AndroidManifest.xml ever. -->
|
||||||
</application>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
@@ -12286,6 +12286,8 @@
|
|||||||
<string name="satellite_warning_dialog_title">Can’t turn on <xliff:g id="function" example="bluetooth">%1$s</xliff:g></string>
|
<string name="satellite_warning_dialog_title">Can’t 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] -->
|
<!-- 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>
|
<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] -->
|
<!-- Title for Apn settings in mobile network settings [CHAR LIMIT=60] -->
|
||||||
|
@@ -204,6 +204,21 @@
|
|||||||
settings:enableCopying="true"
|
settings:enableCopying="true"
|
||||||
settings:controller="com.android.settings.network.telephony.MobileNetworkEidPreferenceController"/>
|
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
|
<PreferenceCategory
|
||||||
android:key="calling_category"
|
android:key="calling_category"
|
||||||
android:title="@string/call_category"
|
android:title="@string/call_category"
|
||||||
@@ -267,14 +282,6 @@
|
|||||||
settings:controller="com.android.settings.network.telephony.gsm.OpenNetworkSelectPagePreferenceController"/>
|
settings:controller="com.android.settings.network.telephony.gsm.OpenNetworkSelectPagePreferenceController"/>
|
||||||
</PreferenceCategory>
|
</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-->
|
<!--We want separate APN setting from reset of settings because we want user to change it with caution-->
|
||||||
<com.android.settingslib.RestrictedPreference
|
<com.android.settingslib.RestrictedPreference
|
||||||
android:key="telephony_apn_key"
|
android:key="telephony_apn_key"
|
||||||
|
@@ -122,24 +122,24 @@ class BiometricsEnvironment(
|
|||||||
FingerprintEnrollStageThresholdInteractor(fingerprintEnrollmentRepository)
|
FingerprintEnrollStageThresholdInteractor(fingerprintEnrollmentRepository)
|
||||||
|
|
||||||
fun createGenerateChallengeInteractor(): GenerateChallengeInteractor =
|
fun createGenerateChallengeInteractor(): GenerateChallengeInteractor =
|
||||||
GenerateChallengeInteractorImpl(fingerprintManager, context.userId, gateKeeperPasswordProvider)
|
GenerateChallengeInteractorImpl(fingerprintManager, userRepo, gateKeeperPasswordProvider)
|
||||||
|
|
||||||
fun createFingerprintEnrollInteractor(): EnrollFingerprintInteractor =
|
fun createFingerprintEnrollInteractor(): EnrollFingerprintInteractor =
|
||||||
EnrollFingerprintInteractorImpl(context.userId, fingerprintManager, Settings)
|
EnrollFingerprintInteractorImpl(userRepo, fingerprintManager, Settings)
|
||||||
|
|
||||||
fun createFingerprintsEnrolledInteractor(): EnrolledFingerprintsInteractorImpl =
|
fun createFingerprintsEnrolledInteractor(): EnrolledFingerprintsInteractorImpl =
|
||||||
EnrolledFingerprintsInteractorImpl(fingerprintEnrollmentRepository)
|
EnrolledFingerprintsInteractorImpl(fingerprintEnrollmentRepository)
|
||||||
|
|
||||||
fun createAuthenticateInteractor(): AuthenitcateInteractor =
|
fun createAuthenticateInteractor(): AuthenitcateInteractor =
|
||||||
AuthenticateInteractorImpl(fingerprintManager, context.userId)
|
AuthenticateInteractorImpl(fingerprintManager, userRepo)
|
||||||
|
|
||||||
fun createUserInteractor(): UserInteractor = UserInteractorImpl(userRepo)
|
fun createUserInteractor(): UserInteractor = UserInteractorImpl(userRepo)
|
||||||
|
|
||||||
fun createRemoveFingerprintInteractor(): RemoveFingerprintInteractor =
|
fun createRemoveFingerprintInteractor(): RemoveFingerprintInteractor =
|
||||||
RemoveFingerprintsInteractorImpl(fingerprintManager, context.userId)
|
RemoveFingerprintsInteractorImpl(fingerprintManager, userRepo)
|
||||||
|
|
||||||
fun createRenameFingerprintInteractor(): RenameFingerprintInteractor =
|
fun createRenameFingerprintInteractor(): RenameFingerprintInteractor =
|
||||||
RenameFingerprintsInteractorImpl(fingerprintManager, context.userId, backgroundDispatcher)
|
RenameFingerprintsInteractorImpl(fingerprintManager, userRepo, backgroundDispatcher)
|
||||||
|
|
||||||
fun createAccessibilityInteractor(): AccessibilityInteractor {
|
fun createAccessibilityInteractor(): AccessibilityInteractor {
|
||||||
return AccessibilityInteractorImpl(context.getSystemService(AccessibilityManager::class.java)!!)
|
return AccessibilityInteractorImpl(context.getSystemService(AccessibilityManager::class.java)!!)
|
||||||
|
@@ -19,19 +19,22 @@ package com.android.settings.biometrics.fingerprint2.domain.interactor
|
|||||||
import android.hardware.fingerprint.FingerprintManager
|
import android.hardware.fingerprint.FingerprintManager
|
||||||
import android.os.CancellationSignal
|
import android.os.CancellationSignal
|
||||||
import android.util.Log
|
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.domain.interactor.AuthenitcateInteractor
|
||||||
import com.android.settings.biometrics.fingerprint2.lib.model.FingerprintAuthAttemptModel
|
import com.android.settings.biometrics.fingerprint2.lib.model.FingerprintAuthAttemptModel
|
||||||
import kotlin.coroutines.resume
|
import kotlin.coroutines.resume
|
||||||
import kotlinx.coroutines.CancellableContinuation
|
import kotlinx.coroutines.CancellableContinuation
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
import kotlinx.coroutines.suspendCancellableCoroutine
|
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||||
|
|
||||||
class AuthenticateInteractorImpl(
|
class AuthenticateInteractorImpl(
|
||||||
private val fingerprintManager: FingerprintManager,
|
private val fingerprintManager: FingerprintManager,
|
||||||
private val userId: Int,
|
private val userRepo: UserRepo,
|
||||||
) : AuthenitcateInteractor {
|
) : AuthenitcateInteractor {
|
||||||
|
|
||||||
override suspend fun authenticate(): FingerprintAuthAttemptModel =
|
override suspend fun authenticate(): FingerprintAuthAttemptModel {
|
||||||
suspendCancellableCoroutine { c: CancellableContinuation<FingerprintAuthAttemptModel> ->
|
val userId = userRepo.currentUser.first()
|
||||||
|
return suspendCancellableCoroutine { c: CancellableContinuation<FingerprintAuthAttemptModel> ->
|
||||||
val authenticationCallback =
|
val authenticationCallback =
|
||||||
object : FingerprintManager.AuthenticationCallback() {
|
object : FingerprintManager.AuthenticationCallback() {
|
||||||
|
|
||||||
@@ -64,6 +67,7 @@ class AuthenticateInteractorImpl(
|
|||||||
userId,
|
userId,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "AuthenticateInteractor"
|
private const val TAG = "AuthenticateInteractor"
|
||||||
|
@@ -22,6 +22,7 @@ import android.os.CancellationSignal
|
|||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.android.settings.biometrics.fingerprint2.conversion.Util.toEnrollError
|
import com.android.settings.biometrics.fingerprint2.conversion.Util.toEnrollError
|
||||||
import com.android.settings.biometrics.fingerprint2.conversion.Util.toOriginalReason
|
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.domain.interactor.EnrollFingerprintInteractor
|
||||||
import com.android.settings.biometrics.fingerprint2.lib.model.EnrollReason
|
import com.android.settings.biometrics.fingerprint2.lib.model.EnrollReason
|
||||||
import com.android.settings.biometrics.fingerprint2.lib.model.FingerEnrollState
|
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.Flow
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.callbackFlow
|
import kotlinx.coroutines.flow.callbackFlow
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
import kotlinx.coroutines.flow.update
|
import kotlinx.coroutines.flow.update
|
||||||
|
|
||||||
class EnrollFingerprintInteractorImpl(
|
class EnrollFingerprintInteractorImpl(
|
||||||
private val userId: Int,
|
private val userRepo: UserRepo,
|
||||||
private val fingerprintManager: FingerprintManager,
|
private val fingerprintManager: FingerprintManager,
|
||||||
private val fingerprintFlow: FingerprintFlow,
|
private val fingerprintFlow: FingerprintFlow,
|
||||||
) : EnrollFingerprintInteractor {
|
) : EnrollFingerprintInteractor {
|
||||||
@@ -47,6 +49,7 @@ class EnrollFingerprintInteractorImpl(
|
|||||||
enrollReason: EnrollReason,
|
enrollReason: EnrollReason,
|
||||||
fingerprintEnrollOptions: FingerprintEnrollOptions,
|
fingerprintEnrollOptions: FingerprintEnrollOptions,
|
||||||
): Flow<FingerEnrollState> = callbackFlow {
|
): Flow<FingerEnrollState> = callbackFlow {
|
||||||
|
val userId = userRepo.currentUser.first()
|
||||||
// TODO (b/308456120) Improve this logic
|
// TODO (b/308456120) Improve this logic
|
||||||
if (enrollRequestOutstanding.value) {
|
if (enrollRequestOutstanding.value) {
|
||||||
Log.d(TAG, "Outstanding enroll request, waiting 150ms")
|
Log.d(TAG, "Outstanding enroll request, waiting 150ms")
|
||||||
|
@@ -19,19 +19,22 @@ package com.android.settings.biometrics.fingerprint2.domain.interactor
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.hardware.fingerprint.FingerprintManager
|
import android.hardware.fingerprint.FingerprintManager
|
||||||
import com.android.settings.biometrics.GatekeeperPasswordProvider
|
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.biometrics.fingerprint2.lib.domain.interactor.GenerateChallengeInteractor
|
||||||
import com.android.settings.password.ChooseLockSettingsHelper
|
import com.android.settings.password.ChooseLockSettingsHelper
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
import kotlin.coroutines.resume
|
import kotlin.coroutines.resume
|
||||||
import kotlin.coroutines.suspendCoroutine
|
import kotlin.coroutines.suspendCoroutine
|
||||||
|
|
||||||
class GenerateChallengeInteractorImpl(
|
class GenerateChallengeInteractorImpl(
|
||||||
private val fingerprintManager: FingerprintManager,
|
private val fingerprintManager: FingerprintManager,
|
||||||
private val userId: Int,
|
private val userRepo: UserRepo,
|
||||||
private val gatekeeperPasswordProvider: GatekeeperPasswordProvider,
|
private val gatekeeperPasswordProvider: GatekeeperPasswordProvider,
|
||||||
) : GenerateChallengeInteractor {
|
) : GenerateChallengeInteractor {
|
||||||
|
|
||||||
override suspend fun generateChallenge(gateKeeperPasswordHandle: Long): Pair<Long, ByteArray> =
|
override suspend fun generateChallenge(gateKeeperPasswordHandle: Long): Pair<Long, ByteArray> {
|
||||||
suspendCoroutine {
|
val userId = userRepo.currentUser.first()
|
||||||
|
return suspendCoroutine {
|
||||||
val callback =
|
val callback =
|
||||||
FingerprintManager.GenerateChallengeCallback { _, userId, challenge ->
|
FingerprintManager.GenerateChallengeCallback { _, userId, challenge ->
|
||||||
val intent = Intent()
|
val intent = Intent()
|
||||||
@@ -45,4 +48,5 @@ class GenerateChallengeInteractorImpl(
|
|||||||
}
|
}
|
||||||
fingerprintManager.generateChallenge(userId, callback)
|
fingerprintManager.generateChallenge(userId, callback)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -18,17 +18,21 @@ package com.android.settings.biometrics.fingerprint2.domain.interactor
|
|||||||
|
|
||||||
import android.hardware.fingerprint.FingerprintManager
|
import android.hardware.fingerprint.FingerprintManager
|
||||||
import android.hardware.fingerprint.FingerprintManager.RemovalCallback
|
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.domain.interactor.RemoveFingerprintInteractor
|
||||||
import com.android.settings.biometrics.fingerprint2.lib.model.FingerprintData
|
import com.android.settings.biometrics.fingerprint2.lib.model.FingerprintData
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
import kotlin.coroutines.resume
|
import kotlin.coroutines.resume
|
||||||
import kotlin.coroutines.suspendCoroutine
|
import kotlin.coroutines.suspendCoroutine
|
||||||
|
|
||||||
class RemoveFingerprintsInteractorImpl(
|
class RemoveFingerprintsInteractorImpl(
|
||||||
private val fingerprintManager: FingerprintManager,
|
private val fingerprintManager: FingerprintManager,
|
||||||
private val userId: Int,
|
private val userRepo: UserRepo,
|
||||||
) : RemoveFingerprintInteractor {
|
) : 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 =
|
val callback =
|
||||||
object : RemovalCallback() {
|
object : RemovalCallback() {
|
||||||
override fun onRemovalError(
|
override fun onRemovalError(
|
||||||
@@ -52,4 +56,5 @@ class RemoveFingerprintsInteractorImpl(
|
|||||||
callback,
|
callback,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,18 +17,21 @@
|
|||||||
package com.android.settings.biometrics.fingerprint2.domain.interactor
|
package com.android.settings.biometrics.fingerprint2.domain.interactor
|
||||||
|
|
||||||
import android.hardware.fingerprint.FingerprintManager
|
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.domain.interactor.RenameFingerprintInteractor
|
||||||
import com.android.settings.biometrics.fingerprint2.lib.model.FingerprintData
|
import com.android.settings.biometrics.fingerprint2.lib.model.FingerprintData
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
class RenameFingerprintsInteractorImpl(
|
class RenameFingerprintsInteractorImpl(
|
||||||
private val fingerprintManager: FingerprintManager,
|
private val fingerprintManager: FingerprintManager,
|
||||||
private val userId: Int,
|
private val userRepo: UserRepo,
|
||||||
private val backgroundDispatcher: CoroutineDispatcher,
|
private val backgroundDispatcher: CoroutineDispatcher,
|
||||||
) : RenameFingerprintInteractor {
|
) : RenameFingerprintInteractor {
|
||||||
|
|
||||||
override suspend fun renameFingerprint(fp: FingerprintData, newName: String) {
|
override suspend fun renameFingerprint(fp: FingerprintData, newName: String) {
|
||||||
|
val userId = userRepo.currentUser.first()
|
||||||
withContext(backgroundDispatcher) { fingerprintManager.rename(fp.fingerId, userId, newName) }
|
withContext(backgroundDispatcher) { fingerprintManager.rename(fp.fingerId, userId, newName) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -150,6 +150,9 @@ public class BluetoothDetailsSpatialAudioController extends BluetoothDetailsCont
|
|||||||
@Override
|
@Override
|
||||||
protected void init(PreferenceScreen screen) {
|
protected void init(PreferenceScreen screen) {
|
||||||
mProfilesContainer = screen.findPreference(getPreferenceKey());
|
mProfilesContainer = screen.findPreference(getPreferenceKey());
|
||||||
|
if (com.android.settings.flags.Flags.enableBluetoothDeviceDetailsPolish()) {
|
||||||
|
mProfilesContainer.setLayoutResource(R.layout.preference_category_bluetooth_no_padding);
|
||||||
|
}
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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)
|
||||||
|
}
|
@@ -32,7 +32,7 @@ class DataSaverMainSwitchPreference(context: Context) :
|
|||||||
private var dataSaverBackendListener: DataSaverBackend.Listener? = null
|
private var dataSaverBackendListener: DataSaverBackend.Listener? = null
|
||||||
|
|
||||||
override val key
|
override val key
|
||||||
get() = "use_data_saver"
|
get() = KEY
|
||||||
|
|
||||||
override val title
|
override val title
|
||||||
get() = R.string.data_saver_switch_title
|
get() = R.string.data_saver_switch_title
|
||||||
@@ -46,7 +46,7 @@ class DataSaverMainSwitchPreference(context: Context) :
|
|||||||
ReadWritePermit.ALLOW
|
ReadWritePermit.ALLOW
|
||||||
|
|
||||||
override fun onStart(context: PreferenceLifecycleContext) {
|
override fun onStart(context: PreferenceLifecycleContext) {
|
||||||
val listener = DataSaverBackend.Listener { context.notifyPreferenceChange(this) }
|
val listener = DataSaverBackend.Listener { context.notifyPreferenceChange(KEY) }
|
||||||
dataSaverBackendListener = listener
|
dataSaverBackendListener = listener
|
||||||
dataSaverBackend.addListener(listener)
|
dataSaverBackend.addListener(listener)
|
||||||
}
|
}
|
||||||
@@ -71,4 +71,8 @@ class DataSaverMainSwitchPreference(context: Context) :
|
|||||||
dataSaverBackend.isDataSaverEnabled = value as Boolean
|
dataSaverBackend.isDataSaverEnabled = value as Boolean
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val KEY = "use_data_saver"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -71,7 +71,7 @@ class DataSaverScreen :
|
|||||||
override fun hasCompleteHierarchy() = false
|
override fun hasCompleteHierarchy() = false
|
||||||
|
|
||||||
override fun onStart(context: PreferenceLifecycleContext) {
|
override fun onStart(context: PreferenceLifecycleContext) {
|
||||||
val listener = DataSaverBackend.Listener { context.notifyPreferenceChange(this) }
|
val listener = DataSaverBackend.Listener { context.notifyPreferenceChange(KEY) }
|
||||||
dataSaverBackendListener = listener
|
dataSaverBackendListener = listener
|
||||||
dataSaverBackend = DataSaverBackend(context).apply { addListener(listener) }
|
dataSaverBackend = DataSaverBackend(context).apply { addListener(listener) }
|
||||||
}
|
}
|
||||||
|
@@ -18,7 +18,10 @@ package com.android.settings.development.linuxterminal;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.os.Process;
|
||||||
|
import android.os.storage.StorageManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.util.DataUnit;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
@@ -28,30 +31,45 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.core.PreferenceControllerMixin;
|
import com.android.settings.core.PreferenceControllerMixin;
|
||||||
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
|
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/** Preference controller for Linux terminal option in developers option */
|
/** Preference controller for Linux terminal option in developers option */
|
||||||
public class LinuxTerminalPreferenceController extends DeveloperOptionsPreferenceController
|
public class LinuxTerminalPreferenceController extends DeveloperOptionsPreferenceController
|
||||||
implements PreferenceControllerMixin {
|
implements PreferenceControllerMixin {
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final int TERMINAL_PACKAGE_NAME_RESID = R.string.config_linux_terminal_app_package_name;
|
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";
|
private static final String LINUX_TERMINAL_KEY = "linux_terminal";
|
||||||
|
|
||||||
@Nullable private final String mTerminalPackageName;
|
@Nullable private final String mTerminalPackageName;
|
||||||
|
private final boolean mIsDeviceCapable;
|
||||||
|
|
||||||
public LinuxTerminalPreferenceController(@NonNull Context context) {
|
public LinuxTerminalPreferenceController(@NonNull Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
String packageName = context.getString(TERMINAL_PACKAGE_NAME_RESID);
|
String packageName = context.getString(TERMINAL_PACKAGE_NAME_RESID);
|
||||||
mTerminalPackageName =
|
mTerminalPackageName =
|
||||||
isPackageInstalled(context.getPackageManager(), packageName) ? packageName : null;
|
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().
|
// Avoid lazy initialization because this may be called before displayPreference().
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
public boolean isAvailable() {
|
||||||
// Returns true only if the terminal app is installed which only happens when the build flag
|
// Check build flag RELEASE_AVF_SUPPORT_CUSTOM_VM_WITH_PARAVIRTUALIZED_DEVICES indirectly
|
||||||
// RELEASE_AVF_SUPPORT_CUSTOM_VM_WITH_PARAVIRTUALIZED_DEVICES is true.
|
// by checking whether the terminal app is installed.
|
||||||
// TODO(b/343795511): Add explicitly check for the flag when it's accessible from Java code.
|
// TODO(b/343795511): Add explicitly check for the flag when it's accessible from Java code.
|
||||||
return mTerminalPackageName != null;
|
return mTerminalPackageName != null && mIsDeviceCapable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -73,4 +91,10 @@ public class LinuxTerminalPreferenceController extends DeveloperOptionsPreferenc
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Can be overridden for test
|
||||||
|
@VisibleForTesting
|
||||||
|
long getTotalMemory() {
|
||||||
|
return Process.getTotalMemory();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -101,7 +101,7 @@ class AdaptiveSleepPreference :
|
|||||||
val receiver =
|
val receiver =
|
||||||
object : BroadcastReceiver() {
|
object : BroadcastReceiver() {
|
||||||
override fun onReceive(receiverContext: Context, intent: Intent) {
|
override fun onReceive(receiverContext: Context, intent: Intent) {
|
||||||
context.notifyPreferenceChange(this@AdaptiveSleepPreference)
|
context.notifyPreferenceChange(KEY)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
context.registerReceiver(
|
context.registerReceiver(
|
||||||
@@ -111,7 +111,7 @@ class AdaptiveSleepPreference :
|
|||||||
broadcastReceiver = receiver
|
broadcastReceiver = receiver
|
||||||
|
|
||||||
val listener = OnSensorPrivacyChangedListener { _, _ ->
|
val listener = OnSensorPrivacyChangedListener { _, _ ->
|
||||||
context.notifyPreferenceChange(this)
|
context.notifyPreferenceChange(KEY)
|
||||||
}
|
}
|
||||||
SensorPrivacyManager.getInstance(context).addSensorPrivacyListener(CAMERA, listener)
|
SensorPrivacyManager.getInstance(context).addSensorPrivacyListener(CAMERA, listener)
|
||||||
sensorPrivacyChangedListener = listener
|
sensorPrivacyChangedListener = listener
|
||||||
|
@@ -58,7 +58,7 @@ class BrightnessLevelPreference :
|
|||||||
private var displayListener: DisplayListener? = null
|
private var displayListener: DisplayListener? = null
|
||||||
|
|
||||||
override val key: String
|
override val key: String
|
||||||
get() = "brightness"
|
get() = KEY
|
||||||
|
|
||||||
override val title: Int
|
override val title: Int
|
||||||
get() = R.string.brightness
|
get() = R.string.brightness
|
||||||
@@ -85,10 +85,7 @@ class BrightnessLevelPreference :
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onStart(context: PreferenceLifecycleContext) {
|
override fun onStart(context: PreferenceLifecycleContext) {
|
||||||
val observer =
|
val observer = KeyedObserver<String> { _, _ -> context.notifyPreferenceChange(KEY) }
|
||||||
KeyedObserver<String> { _, _ ->
|
|
||||||
context.notifyPreferenceChange(this@BrightnessLevelPreference)
|
|
||||||
}
|
|
||||||
brightnessObserver = observer
|
brightnessObserver = observer
|
||||||
SettingsSystemStore.get(context)
|
SettingsSystemStore.get(context)
|
||||||
.addObserver(System.SCREEN_AUTO_BRIGHTNESS_ADJ, observer, HandlerExecutor.main)
|
.addObserver(System.SCREEN_AUTO_BRIGHTNESS_ADJ, observer, HandlerExecutor.main)
|
||||||
@@ -100,7 +97,7 @@ class BrightnessLevelPreference :
|
|||||||
override fun onDisplayRemoved(displayId: Int) {}
|
override fun onDisplayRemoved(displayId: Int) {}
|
||||||
|
|
||||||
override fun onDisplayChanged(displayId: Int) {
|
override fun onDisplayChanged(displayId: Int) {
|
||||||
context.notifyPreferenceChange(this@BrightnessLevelPreference)
|
context.notifyPreferenceChange(KEY)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
displayListener = listener
|
displayListener = listener
|
||||||
@@ -162,5 +159,9 @@ class BrightnessLevelPreference :
|
|||||||
value < GAMMA_SPACE_MIN -> 0.0
|
value < GAMMA_SPACE_MIN -> 0.0
|
||||||
else -> (value - GAMMA_SPACE_MIN) / (GAMMA_SPACE_MAX - GAMMA_SPACE_MIN)
|
else -> (value - GAMMA_SPACE_MIN) / (GAMMA_SPACE_MAX - GAMMA_SPACE_MIN)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val KEY = "brightness"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// LINT.ThenChange(BrightnessLevelPreferenceController.java)
|
// LINT.ThenChange(BrightnessLevelPreferenceController.java)
|
||||||
|
@@ -39,7 +39,7 @@ import kotlin.math.roundToInt
|
|||||||
|
|
||||||
// LINT.IfChange
|
// LINT.IfChange
|
||||||
class PeakRefreshRateSwitchPreference :
|
class PeakRefreshRateSwitchPreference :
|
||||||
SwitchPreference(PEAK_REFRESH_RATE, R.string.peak_refresh_rate_title),
|
SwitchPreference(KEY, R.string.peak_refresh_rate_title),
|
||||||
PreferenceAvailabilityProvider,
|
PreferenceAvailabilityProvider,
|
||||||
PreferenceSummaryProvider,
|
PreferenceSummaryProvider,
|
||||||
PreferenceLifecycleProvider {
|
PreferenceLifecycleProvider {
|
||||||
@@ -69,7 +69,7 @@ class PeakRefreshRateSwitchPreference :
|
|||||||
// KEY_PEAK_REFRESH_RATE_DEFAULT value could be added, changed, removed or
|
// KEY_PEAK_REFRESH_RATE_DEFAULT value could be added, changed, removed or
|
||||||
// unchanged.
|
// unchanged.
|
||||||
// Just force a UI update for any case.
|
// Just force a UI update for any case.
|
||||||
context.notifyPreferenceChange(this)
|
context.notifyPreferenceChange(KEY)
|
||||||
}
|
}
|
||||||
|
|
||||||
propertiesChangedListener = listener
|
propertiesChangedListener = listener
|
||||||
@@ -97,14 +97,13 @@ class PeakRefreshRateSwitchPreference :
|
|||||||
override fun contains(key: String) = settingsStore.contains(key)
|
override fun contains(key: String) = settingsStore.contains(key)
|
||||||
|
|
||||||
override fun <T : Any> getDefaultValue(key: String, valueType: Class<T>): T? {
|
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
|
return context.defaultPeakRefreshRate.refreshRateAsBoolean(context) as T
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun <T : Any> getValue(key: String, valueType: Class<T>): T? {
|
override fun <T : Any> getValue(key: String, valueType: Class<T>): T? {
|
||||||
if (key != PEAK_REFRESH_RATE) return null
|
if (key != KEY) return null
|
||||||
val refreshRate =
|
val refreshRate = settingsStore.getFloat(KEY) ?: context.defaultPeakRefreshRate
|
||||||
settingsStore.getFloat(PEAK_REFRESH_RATE) ?: context.defaultPeakRefreshRate
|
|
||||||
return refreshRate.refreshRateAsBoolean(context) as T
|
return refreshRate.refreshRateAsBoolean(context) as T
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,12 +112,12 @@ class PeakRefreshRateSwitchPreference :
|
|||||||
|
|
||||||
override fun <T : Any> setValue(key: String, valueType: Class<T>, value: T?) =
|
override fun <T : Any> setValue(key: String, valueType: Class<T>, value: T?) =
|
||||||
when {
|
when {
|
||||||
key != PEAK_REFRESH_RATE -> {}
|
key != KEY -> {}
|
||||||
value == null -> settingsStore.setFloat(PEAK_REFRESH_RATE, null)
|
value == null -> settingsStore.setFloat(KEY, null)
|
||||||
else -> {
|
else -> {
|
||||||
val peakRefreshRate =
|
val peakRefreshRate =
|
||||||
if (value as Boolean) context.refreshRateIfON() else DEFAULT_REFRESH_RATE
|
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 {
|
companion object {
|
||||||
|
const val KEY = PEAK_REFRESH_RATE
|
||||||
private const val INVALIDATE_REFRESH_RATE: Float = -1f
|
private const val INVALIDATE_REFRESH_RATE: Float = -1f
|
||||||
|
|
||||||
private val Context.peakRefreshRate: Float
|
private val Context.peakRefreshRate: Float
|
||||||
|
@@ -112,7 +112,7 @@ class DarkModeScreen :
|
|||||||
val broadcastReceiver =
|
val broadcastReceiver =
|
||||||
object : BroadcastReceiver() {
|
object : BroadcastReceiver() {
|
||||||
override fun onReceive(receiverContext: Context, intent: Intent) {
|
override fun onReceive(receiverContext: Context, intent: Intent) {
|
||||||
context.notifyPreferenceChange(this@DarkModeScreen)
|
context.notifyPreferenceChange(KEY)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
context.registerReceiver(
|
context.registerReceiver(
|
||||||
@@ -121,7 +121,7 @@ class DarkModeScreen :
|
|||||||
)
|
)
|
||||||
|
|
||||||
val darkModeObserver = DarkModeObserver(context)
|
val darkModeObserver = DarkModeObserver(context)
|
||||||
darkModeObserver.subscribe { context.notifyPreferenceChange(this@DarkModeScreen) }
|
darkModeObserver.subscribe { context.notifyPreferenceChange(KEY) }
|
||||||
|
|
||||||
fragmentStates[context] = FragmentState(broadcastReceiver, darkModeObserver)
|
fragmentStates[context] = FragmentState(broadcastReceiver, darkModeObserver)
|
||||||
}
|
}
|
||||||
|
@@ -59,13 +59,13 @@ class BatterySaverPreference :
|
|||||||
object : BatterySaverListener {
|
object : BatterySaverListener {
|
||||||
override fun onPowerSaveModeChanged() {
|
override fun onPowerSaveModeChanged() {
|
||||||
handler.postDelayed(
|
handler.postDelayed(
|
||||||
{ context.notifyPreferenceChange(this@BatterySaverPreference) },
|
{ context.notifyPreferenceChange(KEY) },
|
||||||
SWITCH_ANIMATION_DURATION,
|
SWITCH_ANIMATION_DURATION,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBatteryChanged(pluggedIn: Boolean) =
|
override fun onBatteryChanged(pluggedIn: Boolean) =
|
||||||
context.notifyPreferenceChange(this@BatterySaverPreference)
|
context.notifyPreferenceChange(KEY)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
setListening(true)
|
setListening(true)
|
||||||
|
@@ -71,6 +71,7 @@ import java.util.Locale;
|
|||||||
public class LocaleListEditor extends RestrictedSettingsFragment implements View.OnTouchListener {
|
public class LocaleListEditor extends RestrictedSettingsFragment implements View.OnTouchListener {
|
||||||
protected static final String INTENT_LOCALE_KEY = "localeInfo";
|
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_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";
|
protected static final String LOCALE_SUGGESTION = "locale_suggestion";
|
||||||
|
|
||||||
private static final String TAG = LocaleListEditor.class.getSimpleName();
|
private static final String TAG = LocaleListEditor.class.getSimpleName();
|
||||||
|
@@ -21,7 +21,7 @@ import com.android.internal.app.LocaleStore;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/** Interface for when locale list changes in SearchView . */
|
/** Interface for when locale list changes in SearchView. */
|
||||||
public interface LocaleListSearchCallback {
|
public interface LocaleListSearchCallback {
|
||||||
|
|
||||||
/** Callback method for searching changes. */
|
/** Callback method for searching changes. */
|
||||||
|
@@ -16,13 +16,17 @@
|
|||||||
|
|
||||||
package com.android.settings.localepicker;
|
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.content.Context;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.os.LocaleList;
|
import android.os.LocaleList;
|
||||||
import android.provider.Settings;
|
|
||||||
import android.util.ArrayMap;
|
import android.util.ArrayMap;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceCategory;
|
import androidx.preference.PreferenceCategory;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
@@ -30,7 +34,10 @@ import androidx.preference.PreferenceScreen;
|
|||||||
import com.android.internal.app.LocaleCollectorBase;
|
import com.android.internal.app.LocaleCollectorBase;
|
||||||
import com.android.internal.app.LocaleHelper;
|
import com.android.internal.app.LocaleHelper;
|
||||||
import com.android.internal.app.LocaleStore;
|
import com.android.internal.app.LocaleStore;
|
||||||
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.BasePreferenceController;
|
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.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -43,40 +50,27 @@ import java.util.stream.Collectors;
|
|||||||
/** A base controller for handling locale controllers. */
|
/** A base controller for handling locale controllers. */
|
||||||
public abstract class LocalePickerBaseListPreferenceController extends
|
public abstract class LocalePickerBaseListPreferenceController extends
|
||||||
BasePreferenceController implements LocaleListSearchCallback {
|
BasePreferenceController implements LocaleListSearchCallback {
|
||||||
|
|
||||||
private static final String TAG = "LocalePickerBaseListPreference";
|
private static final String TAG = "LocalePickerBaseListPreference";
|
||||||
private static final String KEY_SUGGESTED = "suggested";
|
private static final String KEY_SUGGESTED = "suggested";
|
||||||
|
private static final String KEY_SUPPORTED = "supported";
|
||||||
|
|
||||||
private PreferenceCategory mPreferenceCategory;
|
private PreferenceCategory mPreferenceCategory;
|
||||||
private LocaleList mExplicitLocales;
|
|
||||||
private Set<LocaleStore.LocaleInfo> mLocaleList;
|
private Set<LocaleStore.LocaleInfo> mLocaleList;
|
||||||
private List<LocaleStore.LocaleInfo> mLocaleOptions;
|
private List<LocaleStore.LocaleInfo> mLocaleOptions;
|
||||||
private Map<String, Preference> mPreferences;
|
private Map<String, Preference> mPreferences;
|
||||||
private String mPackageName;
|
private String mPackageName;
|
||||||
private boolean mCountryMode;
|
private boolean mIsCountryMode;
|
||||||
|
@Nullable private LocaleStore.LocaleInfo mParentLocale;
|
||||||
|
|
||||||
public LocalePickerBaseListPreferenceController(@NonNull Context context,
|
public LocalePickerBaseListPreferenceController(@NonNull Context context,
|
||||||
@NonNull String preferenceKey) {
|
@NonNull String preferenceKey) {
|
||||||
super(context, 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,
|
mLocaleList = getLocaleCollectorController(context).getSupportedLocaleList(null,
|
||||||
false, false);
|
false, false);
|
||||||
mLocaleOptions = new ArrayList<>(mLocaleList.size());
|
mLocaleOptions = new ArrayList<>(mLocaleList.size());
|
||||||
mPreferences = new ArrayMap<>();
|
mPreferences = new ArrayMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isDeviceDemoMode() {
|
|
||||||
return Settings.Global.getInt(
|
|
||||||
mContext.getContentResolver(), Settings.Global.DEVICE_DEMO_MODE, 0) == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void displayPreference(@NonNull PreferenceScreen screen) {
|
public void displayPreference(@NonNull PreferenceScreen screen) {
|
||||||
super.displayPreference(screen);
|
super.displayPreference(screen);
|
||||||
@@ -91,8 +85,21 @@ public abstract class LocalePickerBaseListPreferenceController extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<LocaleStore.LocaleInfo> result;
|
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(
|
result = getSortedLocaleList(
|
||||||
getPreferenceCategoryKey().contains(KEY_SUGGESTED) ? getSuggestedLocaleList()
|
getPreferenceCategoryKey().contains(KEY_SUGGESTED)
|
||||||
|
? getSuggestedLocaleList()
|
||||||
: getSupportedLocaleList());
|
: getSupportedLocaleList());
|
||||||
|
|
||||||
final Map<String, Preference> existingPreferences = mPreferences;
|
final Map<String, Preference> existingPreferences = mPreferences;
|
||||||
@@ -113,12 +120,7 @@ public abstract class LocalePickerBaseListPreferenceController extends
|
|||||||
newList = getSortedSuggestedLocaleFromSearchList(
|
newList = getSortedSuggestedLocaleFromSearchList(
|
||||||
newList, getSuggestedLocaleList());
|
newList, getSuggestedLocaleList());
|
||||||
}
|
}
|
||||||
if (!newList.isEmpty()) {
|
|
||||||
mPreferenceCategory.setVisible(true);
|
|
||||||
setupPreference(newList, existingPreferences);
|
setupPreference(newList, existingPreferences);
|
||||||
} else {
|
|
||||||
mPreferenceCategory.setVisible(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<LocaleStore.LocaleInfo> getSortedSuggestedLocaleFromSearchList(
|
private List<LocaleStore.LocaleInfo> getSortedSuggestedLocaleFromSearchList(
|
||||||
@@ -138,6 +140,12 @@ public abstract class LocalePickerBaseListPreferenceController extends
|
|||||||
|
|
||||||
private void setupPreference(List<LocaleStore.LocaleInfo> localeInfoList,
|
private void setupPreference(List<LocaleStore.LocaleInfo> localeInfoList,
|
||||||
Map<String, Preference> existingPreferences) {
|
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 ->
|
localeInfoList.stream().forEach(locale ->
|
||||||
{
|
{
|
||||||
Preference pref = existingPreferences.remove(locale.getId());
|
Preference pref = existingPreferences.remove(locale.getId());
|
||||||
@@ -146,15 +154,16 @@ public abstract class LocalePickerBaseListPreferenceController extends
|
|||||||
mPreferenceCategory.addPreference(pref);
|
mPreferenceCategory.addPreference(pref);
|
||||||
}
|
}
|
||||||
String localeName =
|
String localeName =
|
||||||
mCountryMode ? locale.getFullCountryNameNative() : locale.getFullNameNative();
|
mIsCountryMode ? locale.getFullCountryNameNative() : locale.getFullNameNative();
|
||||||
pref.setTitle(localeName);
|
pref.setTitle(localeName);
|
||||||
pref.setKey(locale.toString());
|
pref.setKey(locale.toString());
|
||||||
pref.setOnPreferenceClickListener(clickedPref -> {
|
pref.setOnPreferenceClickListener(clickedPref -> {
|
||||||
// TODO: Click locale to show region or numbering system page if needed.
|
switchFragment(locale);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
mPreferences.put(locale.getId(), pref);
|
mPreferences.put(locale.getId(), pref);
|
||||||
});
|
});
|
||||||
|
mPreferenceCategory.setVisible(mPreferenceCategory.getPreferenceCount() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -166,14 +175,16 @@ public abstract class LocalePickerBaseListPreferenceController extends
|
|||||||
|
|
||||||
protected abstract LocaleCollectorBase getLocaleCollectorController(Context context);
|
protected abstract LocaleCollectorBase getLocaleCollectorController(Context context);
|
||||||
|
|
||||||
|
@Nullable protected abstract LocaleStore.LocaleInfo getParentLocale();
|
||||||
|
|
||||||
|
protected abstract boolean isNumberingMode();
|
||||||
|
|
||||||
|
@Nullable protected abstract LocaleList getExplicitLocaleList();
|
||||||
|
|
||||||
protected String getPackageName() {
|
protected String getPackageName() {
|
||||||
return mPackageName;
|
return mPackageName;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected LocaleList getExplicitLocaleList() {
|
|
||||||
return mExplicitLocales;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected List<LocaleStore.LocaleInfo> getSuggestedLocaleList() {
|
protected List<LocaleStore.LocaleInfo> getSuggestedLocaleList() {
|
||||||
mLocaleOptions.clear();
|
mLocaleOptions.clear();
|
||||||
if (mLocaleList != null && !mLocaleList.isEmpty()) {
|
if (mLocaleList != null && !mLocaleList.isEmpty()) {
|
||||||
@@ -203,8 +214,46 @@ public abstract class LocalePickerBaseListPreferenceController extends
|
|||||||
List<LocaleStore.LocaleInfo> localeInfos) {
|
List<LocaleStore.LocaleInfo> localeInfos) {
|
||||||
final Locale sortingLocale = Locale.getDefault();
|
final Locale sortingLocale = Locale.getDefault();
|
||||||
final LocaleHelper.LocaleInfoComparator comp =
|
final LocaleHelper.LocaleInfoComparator comp =
|
||||||
new LocaleHelper.LocaleInfoComparator(sortingLocale, mCountryMode);
|
new LocaleHelper.LocaleInfoComparator(sortingLocale, mIsCountryMode);
|
||||||
Collections.sort(localeInfos, comp);
|
Collections.sort(localeInfos, comp);
|
||||||
return localeInfos;
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -55,19 +55,41 @@ import java.util.Set;
|
|||||||
* default locale.</p>
|
* default locale.</p>
|
||||||
*/
|
*/
|
||||||
public class RegionAndNumberingSystemPickerFragment extends DashboardFragment {
|
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 RecyclerView mRecyclerView;
|
||||||
private AppBarLayout mAppBarLayout;
|
private AppBarLayout mAppBarLayout;
|
||||||
private Activity mActivity;
|
private Activity mActivity;
|
||||||
|
private boolean mIsNumberingMode;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@NonNull Bundle icicle) {
|
public void onCreate(@NonNull Bundle icicle) {
|
||||||
super.onCreate(icicle);
|
super.onCreate(icicle);
|
||||||
mActivity = getActivity();
|
mActivity = getActivity();
|
||||||
if (mActivity.isFinishing()) {
|
if (mActivity == null || mActivity.isFinishing()) {
|
||||||
|
Log.d(TAG, "onCreate, no activity or activity is finishing");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mLocaleInfo == null) {
|
||||||
|
Log.d(TAG, "onCreate, can not get localeInfo");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mActivity.setTitle(mLocaleInfo.getFullNameNative());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -102,8 +124,15 @@ public class RegionAndNumberingSystemPickerFragment extends DashboardFragment {
|
|||||||
private List<AbstractPreferenceController> buildPreferenceControllers(
|
private List<AbstractPreferenceController> buildPreferenceControllers(
|
||||||
@NonNull Context context, @Nullable Lifecycle lifecycle) {
|
@NonNull Context context, @Nullable Lifecycle lifecycle) {
|
||||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||||
|
mLocaleInfo = (LocaleStore.LocaleInfo) getArguments().getSerializable(EXTRA_TARGET_LOCALE);
|
||||||
// TODO: b/30358431 - Add preference of region locales.
|
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;
|
return controllers;
|
||||||
}
|
}
|
||||||
|
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
@@ -20,6 +20,8 @@ import android.app.Activity;
|
|||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.LocaleList;
|
||||||
|
import android.provider.Settings;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@@ -48,8 +50,6 @@ import com.android.settingslib.core.lifecycle.Lifecycle;
|
|||||||
|
|
||||||
import com.google.android.material.appbar.AppBarLayout;
|
import com.google.android.material.appbar.AppBarLayout;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -68,12 +68,24 @@ public class SystemLocalePickerFragment extends DashboardFragment implements
|
|||||||
|
|
||||||
private static final String TAG = "SystemLocalePickerFragment";
|
private static final String TAG = "SystemLocalePickerFragment";
|
||||||
private static final String EXTRA_EXPAND_SEARCH_VIEW = "expand_search_view";
|
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
|
||||||
@Nullable private SearchFilter mSearchFilter = null;
|
private SearchView mSearchView = null;
|
||||||
@Nullable private Set<LocaleStore.LocaleInfo> mLocaleList;
|
@Nullable
|
||||||
@Nullable private List<LocaleStore.LocaleInfo> mLocaleOptions;
|
private SearchFilter mSearchFilter = null;
|
||||||
@Nullable private List<LocaleStore.LocaleInfo> mOriginalLocaleInfos;
|
@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 AppBarLayout mAppBarLayout;
|
||||||
private RecyclerView mRecyclerView;
|
private RecyclerView mRecyclerView;
|
||||||
private Activity mActivity;
|
private Activity mActivity;
|
||||||
@@ -138,12 +150,16 @@ public class SystemLocalePickerFragment extends DashboardFragment implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void filterSearch(@Nullable String query) {
|
private void filterSearch(@Nullable String query) {
|
||||||
|
if (mSystemLocaleAllListPreferenceController == null) {
|
||||||
|
Log.d(TAG, "filterSearch(), can not get preference.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (mSearchFilter == null) {
|
if (mSearchFilter == null) {
|
||||||
mSearchFilter = new SearchFilter();
|
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 we haven't load apps list completely, don't filter anything.
|
||||||
if (mOriginalLocaleInfos == null) {
|
if (mOriginalLocaleInfos == null) {
|
||||||
Log.w(TAG, "Locales haven't loaded completely yet, so nothing can be filtered");
|
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
|
@Override
|
||||||
protected void publishResults(CharSequence constraint, FilterResults results) {
|
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;
|
mLocaleOptions = (ArrayList<LocaleStore.LocaleInfo>) results.values;
|
||||||
// Need to scroll to first preference when searching.
|
// Need to scroll to first preference when searching.
|
||||||
if (mRecyclerView != null) {
|
if (mRecyclerView != null) {
|
||||||
mRecyclerView.post(() -> mRecyclerView.scrollToPosition(0));
|
mRecyclerView.post(() -> mRecyclerView.scrollToPosition(0));
|
||||||
}
|
}
|
||||||
// TODO: b/30358431 - Add preference of system locales.
|
mSystemLocaleAllListPreferenceController.onSearchListChanged(mLocaleOptions);
|
||||||
// mSystemLocaleAllListPreferenceController.onSearchListChanged(mLocaleOptions);
|
mSuggestedListPreferenceController.onSearchListChanged(mLocaleOptions);
|
||||||
// mSuggestedListPreferenceController.onSearchListChanged(mLocaleOptions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: decide if this is enough, or we want to use a BreakIterator...
|
// 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(
|
private List<AbstractPreferenceController> buildPreferenceControllers(
|
||||||
@NonNull Context context, @Nullable Lifecycle lifecycle) {
|
@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<>();
|
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||||
// TODO: b/30358431 - Add preference of system locales.
|
controllers.add(mSuggestedListPreferenceController);
|
||||||
|
controllers.add(mSystemLocaleAllListPreferenceController);
|
||||||
|
|
||||||
return controllers;
|
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 =
|
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||||
new BaseSearchIndexProvider(R.xml.system_language_picker);
|
new BaseSearchIndexProvider(R.xml.system_language_picker);
|
||||||
}
|
}
|
||||||
|
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
@@ -277,6 +277,12 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings impleme
|
|||||||
if (roamingPreferenceController != null) {
|
if (roamingPreferenceController != null) {
|
||||||
roamingPreferenceController.init(getParentFragmentManager(), mSubId);
|
roamingPreferenceController.init(getParentFragmentManager(), mSubId);
|
||||||
}
|
}
|
||||||
|
final SatelliteSettingsPreferenceCategoryController
|
||||||
|
satelliteSettingsPreferenceCategoryController =
|
||||||
|
use(SatelliteSettingsPreferenceCategoryController.class);
|
||||||
|
if (satelliteSettingsPreferenceCategoryController != null) {
|
||||||
|
satelliteSettingsPreferenceCategoryController.init(mSubId);
|
||||||
|
}
|
||||||
final SatelliteSettingPreferenceController satelliteSettingPreferenceController = use(
|
final SatelliteSettingPreferenceController satelliteSettingPreferenceController = use(
|
||||||
SatelliteSettingPreferenceController.class);
|
SatelliteSettingPreferenceController.class);
|
||||||
if (satelliteSettingPreferenceController != null) {
|
if (satelliteSettingPreferenceController != null) {
|
||||||
|
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
@@ -465,7 +465,7 @@ public class UserSettings extends SettingsPreferenceFragment
|
|||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
if (!isCurrentUserAdmin() && (canSwitchUserNow() || Flags.newMultiuserSettingsUx())
|
if (!isCurrentUserAdmin() && (canSwitchUserNow() || Flags.newMultiuserSettingsUx())
|
||||||
&& !isCurrentUserGuest()) {
|
&& !isCurrentUserGuest() && !mUserManager.isProfile()) {
|
||||||
String nickname = mUserManager.getUserName();
|
String nickname = mUserManager.getUserName();
|
||||||
MenuItem removeThisUser = menu.add(0, MENU_REMOVE_USER, pos++,
|
MenuItem removeThisUser = menu.add(0, MENU_REMOVE_USER, pos++,
|
||||||
getResources().getString(R.string.user_remove_user_menu, nickname));
|
getResources().getString(R.string.user_remove_user_menu, nickname));
|
||||||
|
@@ -32,6 +32,7 @@ import com.android.settings.widget.SettingsMainSwitchBar.OnBeforeCheckedChangeLi
|
|||||||
import com.android.settingslib.RestrictedPreferenceHelper;
|
import com.android.settingslib.RestrictedPreferenceHelper;
|
||||||
import com.android.settingslib.RestrictedPreferenceHelperProvider;
|
import com.android.settingslib.RestrictedPreferenceHelperProvider;
|
||||||
import com.android.settingslib.core.instrumentation.SettingsJankMonitor;
|
import com.android.settingslib.core.instrumentation.SettingsJankMonitor;
|
||||||
|
import com.android.settingslib.widget.GroupSectionDividerMixin;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -42,7 +43,7 @@ import java.util.List;
|
|||||||
* to enable or disable the preferences on the page.
|
* to enable or disable the preferences on the page.
|
||||||
*/
|
*/
|
||||||
public class SettingsMainSwitchPreference extends TwoStatePreference implements
|
public class SettingsMainSwitchPreference extends TwoStatePreference implements
|
||||||
OnCheckedChangeListener, RestrictedPreferenceHelperProvider {
|
OnCheckedChangeListener, RestrictedPreferenceHelperProvider, GroupSectionDividerMixin {
|
||||||
|
|
||||||
private final List<OnBeforeCheckedChangeListener> mBeforeCheckedChangeListeners =
|
private final List<OnBeforeCheckedChangeListener> mBeforeCheckedChangeListeners =
|
||||||
new ArrayList<>();
|
new ArrayList<>();
|
||||||
|
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package com.android.settings.development.linuxterminal;
|
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.android.settings.development.linuxterminal.LinuxTerminalPreferenceController.TERMINAL_PACKAGE_NAME_RESID;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
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.PackageInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
|
import android.os.storage.StorageManager;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -43,6 +46,7 @@ public class LinuxTerminalPreferenceControllerTest {
|
|||||||
|
|
||||||
@Mock private Context mContext;
|
@Mock private Context mContext;
|
||||||
@Mock private PackageManager mPackageManager;
|
@Mock private PackageManager mPackageManager;
|
||||||
|
@Mock private StorageManager mStorageManager;
|
||||||
@Mock private PackageInfo mPackageInfo;
|
@Mock private PackageInfo mPackageInfo;
|
||||||
|
|
||||||
private String mTerminalPackageName = "com.android.virtualization.terminal";
|
private String mTerminalPackageName = "com.android.virtualization.terminal";
|
||||||
@@ -57,11 +61,30 @@ public class LinuxTerminalPreferenceControllerTest {
|
|||||||
doReturn(mPackageInfo)
|
doReturn(mPackageInfo)
|
||||||
.when(mPackageManager)
|
.when(mPackageManager)
|
||||||
.getPackageInfo(eq(mTerminalPackageName), anyInt());
|
.getPackageInfo(eq(mTerminalPackageName), anyInt());
|
||||||
|
|
||||||
|
doReturn(mStorageManager).when(mContext).getSystemService(StorageManager.class);
|
||||||
|
doReturn(STORAGE_MIN_BYTES).when(mStorageManager).getPrimaryStorageSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAvailable_whenPackageExists_returnsTrue() throws NameNotFoundException {
|
public void isAvailable_whenMemoryInsufficient_returnFalse() {
|
||||||
mController = new LinuxTerminalPreferenceController(mContext);
|
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();
|
assertThat(mController.isAvailable()).isTrue();
|
||||||
}
|
}
|
||||||
@@ -70,7 +93,7 @@ public class LinuxTerminalPreferenceControllerTest {
|
|||||||
public void isAvailable_whenPackageNameIsNull_returnsFalse() {
|
public void isAvailable_whenPackageNameIsNull_returnsFalse() {
|
||||||
doReturn(null).when(mContext).getString(TERMINAL_PACKAGE_NAME_RESID);
|
doReturn(null).when(mContext).getString(TERMINAL_PACKAGE_NAME_RESID);
|
||||||
|
|
||||||
mController = new LinuxTerminalPreferenceController(mContext);
|
mController = createController(mContext);
|
||||||
|
|
||||||
assertThat(mController.isAvailable()).isFalse();
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
}
|
}
|
||||||
@@ -81,8 +104,21 @@ public class LinuxTerminalPreferenceControllerTest {
|
|||||||
.when(mPackageManager)
|
.when(mPackageManager)
|
||||||
.getPackageInfo(eq(mTerminalPackageName), anyInt());
|
.getPackageInfo(eq(mTerminalPackageName), anyInt());
|
||||||
|
|
||||||
mController = new LinuxTerminalPreferenceController(mContext);
|
mController = createController(mContext);
|
||||||
|
|
||||||
assertThat(mController.isAvailable()).isFalse();
|
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;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -152,17 +152,17 @@ class FingerprintManagerInteractorTest {
|
|||||||
enrolledFingerprintsInteractorUnderTest =
|
enrolledFingerprintsInteractorUnderTest =
|
||||||
EnrolledFingerprintsInteractorImpl(fingerprintEnrollRepo)
|
EnrolledFingerprintsInteractorImpl(fingerprintEnrollRepo)
|
||||||
generateChallengeInteractorUnderTest =
|
generateChallengeInteractorUnderTest =
|
||||||
GenerateChallengeInteractorImpl(fingerprintManager, userId, gateKeeperPasswordProvider)
|
GenerateChallengeInteractorImpl(fingerprintManager, userRepo, gateKeeperPasswordProvider)
|
||||||
removeFingerprintsInteractorUnderTest =
|
removeFingerprintsInteractorUnderTest =
|
||||||
RemoveFingerprintsInteractorImpl(fingerprintManager, userId)
|
RemoveFingerprintsInteractorImpl(fingerprintManager, userRepo)
|
||||||
renameFingerprintsInteractorUnderTest =
|
renameFingerprintsInteractorUnderTest =
|
||||||
RenameFingerprintsInteractorImpl(fingerprintManager, userId, backgroundDispatcher)
|
RenameFingerprintsInteractorImpl(fingerprintManager, userRepo, backgroundDispatcher)
|
||||||
authenticateInteractorImplUnderTest = AuthenticateInteractorImpl(fingerprintManager, userId)
|
authenticateInteractorImplUnderTest = AuthenticateInteractorImpl(fingerprintManager, userRepo)
|
||||||
|
|
||||||
canEnrollFingerprintsInteractorUnderTest =
|
canEnrollFingerprintsInteractorUnderTest =
|
||||||
CanEnrollFingerprintsInteractorImpl(fingerprintEnrollRepo)
|
CanEnrollFingerprintsInteractorImpl(fingerprintEnrollRepo)
|
||||||
|
|
||||||
enrollInteractorUnderTest = EnrollFingerprintInteractorImpl(userId, fingerprintManager, flow)
|
enrollInteractorUnderTest = EnrollFingerprintInteractorImpl(userRepo, fingerprintManager, flow)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
@@ -51,6 +51,7 @@ import com.android.settings.privatespace.PrivateSpaceMaintainer.ErrorDeletingPri
|
|||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.Ignore;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -234,6 +235,7 @@ public class PrivateSpaceMaintainerTest {
|
|||||||
* Tests that {@link PrivateSpaceMaintainer#lockPrivateSpace()} when PS exists and is running
|
* Tests that {@link PrivateSpaceMaintainer#lockPrivateSpace()} when PS exists and is running
|
||||||
* locks the private profile.
|
* locks the private profile.
|
||||||
*/
|
*/
|
||||||
|
@Ignore("Flaky pre-submit b/378392936")
|
||||||
@Test
|
@Test
|
||||||
public void lockPrivateSpace_psExistsAndPrivateProfileRunning_locksCreatedPrivateSpace() {
|
public void lockPrivateSpace_psExistsAndPrivateProfileRunning_locksCreatedPrivateSpace() {
|
||||||
mSetFlagsRule.enableFlags(
|
mSetFlagsRule.enableFlags(
|
||||||
@@ -253,6 +255,7 @@ public class PrivateSpaceMaintainerTest {
|
|||||||
* Tests that {@link PrivateSpaceMaintainer#lockPrivateSpace()} when PS exist and private
|
* Tests that {@link PrivateSpaceMaintainer#lockPrivateSpace()} when PS exist and private
|
||||||
* profile not running returns false.
|
* profile not running returns false.
|
||||||
*/
|
*/
|
||||||
|
@Ignore("Flaky pre-submit b/378392936")
|
||||||
@Test
|
@Test
|
||||||
public void lockPrivateSpace_psExistsAndPrivateProfileNotRunning_returnsFalse() {
|
public void lockPrivateSpace_psExistsAndPrivateProfileNotRunning_returnsFalse() {
|
||||||
mSetFlagsRule.enableFlags(
|
mSetFlagsRule.enableFlags(
|
||||||
|
Reference in New Issue
Block a user