Snap for 9966400 from e346dc6779 to udc-release
Change-Id: Iac2001e454b90d1e67a38063b59781098ead6312
This commit is contained in:
@@ -26,29 +26,35 @@
|
||||
android:layoutDirection="locale"
|
||||
android:textDirection="locale">
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/checkbox"
|
||||
style="@style/LanguageCheckboxAndLabel"
|
||||
android:paddingStart="24dp"
|
||||
android:layout_toStartOf="@+id/dragHandle"
|
||||
android:layout_alignTop="@+id/miniLabel"
|
||||
android:layout_alignBottom="@+id/miniLabel" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/miniLabel"
|
||||
style="@style/LanguageCheckboxAndLabel"
|
||||
<LinearLayout
|
||||
android:id="@+id/numberLayout"
|
||||
android:layout_width="wrap_content"
|
||||
android:textColor="?android:attr/colorAccent"
|
||||
android:minWidth="24sp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:gravity="center_vertical|center_horizontal"
|
||||
android:layout_centerVertical="true"/>
|
||||
android:paddingStart="?android:attr/listPreferredItemPaddingStart">
|
||||
<CheckBox
|
||||
android:id="@+id/checkbox"
|
||||
style="@style/LanguageCheckboxAndLabel"
|
||||
android:layout_marginRight="0dp"
|
||||
android:minWidth="24dp"
|
||||
android:paddingEnd="-8dp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/miniLabel"
|
||||
style="@style/LanguageCheckboxAndLabel"
|
||||
android:textColor="?android:attr/colorAccent"
|
||||
android:minWidth="24dp"
|
||||
android:gravity="center_vertical|center_horizontal"/>
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="?android:listPreferredItemHeight"
|
||||
android:paddingStart="56dp"
|
||||
android:layout_toStartOf="@+id/dragHandle">
|
||||
android:layout_toStartOf="@+id/dragHandle"
|
||||
android:layout_toEndOf="@+id/numberLayout"
|
||||
android:paddingStart="32dp">
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -59,7 +65,7 @@
|
||||
app:layout_constraintBottom_toBottomOf="parent">
|
||||
<TextView
|
||||
android:id="@+id/label"
|
||||
style="@style/LanguageCheckboxAndLabel" />
|
||||
style="@style/LanguageCheckboxAndLabel"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/l10nWarn"
|
||||
@@ -86,7 +92,6 @@
|
||||
android:layout_height="match_parent"
|
||||
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
|
||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:src="@drawable/drag_handle"
|
||||
android:importantForAccessibility="no"
|
||||
android:layout_alignParentEnd="true"
|
||||
|
||||
@@ -658,7 +658,7 @@
|
||||
<bool name="default_allow_sensitive_lockscreen_content">true</bool>
|
||||
|
||||
<!-- Whether to enable the app battery usage list page feature. -->
|
||||
<bool name="config_app_battery_usage_list_enabled">false</bool>
|
||||
<bool name="config_app_battery_usage_list_enabled">true</bool>
|
||||
|
||||
<!-- Whether sim related information is visible to the end user. -->
|
||||
<bool name="config_show_sim_info">true</bool>
|
||||
|
||||
@@ -431,8 +431,8 @@
|
||||
<string name="title_regional_pref_footer">If an app doesn’t support regional preferences, the app will use its default locale settings.</string>
|
||||
<!-- Description for text in regional preference footer. [CHAR LIMIT=NONE] -->
|
||||
<string name="desc_regional_pref_footer_learn_more">Learn more about language preferences.</string>
|
||||
<!-- TODO(b/277573274): Update the learn more url in the regional preference. -->
|
||||
<string name="regional_pref_footer_learn_more_link" translatable="false">https://support.google.com/android</string>
|
||||
<!-- Support link for the regional preference page. [CHAR LIMIT=NONE]-->
|
||||
<string name="regional_pref_footer_learn_more_link" translatable="false">https://support.google.com/android?p=regional_preferences</string>
|
||||
|
||||
<!-- The title of the confirmation dialog shown when the user selects one / several languages and tries to remove them [CHAR LIMIT=60] -->
|
||||
<string name="dlg_remove_locales_title">{count, plural,
|
||||
|
||||
@@ -319,9 +319,8 @@
|
||||
</style>
|
||||
|
||||
<style name="LanguageCheckboxAndLabel">
|
||||
<item name="android:layout_width">match_parent</item>
|
||||
<item name="android:layout_width">wrap_content</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:layout_marginStart">?android:attr/listPreferredItemPaddingStart</item>
|
||||
<item name="android:textAppearance">?android:attr/textAppearanceListItem</item>
|
||||
<item name="android:gravity">center_vertical</item>
|
||||
</style>
|
||||
|
||||
@@ -26,11 +26,11 @@
|
||||
android:key="device_control_category"
|
||||
android:title="@string/accessibility_found_all_devices">
|
||||
<com.android.settingslib.RestrictedPreference
|
||||
android:key="add_bt_devices"
|
||||
android:key="list_bt_devices"
|
||||
android:title="@string/accessibility_list_all_devices_title"
|
||||
android:fragment="com.android.settings.bluetooth.BluetoothPairingDetail"
|
||||
settings:userRestriction="no_config_bluetooth"
|
||||
settings:useAdminDisabledSummary="true" />
|
||||
settings:useAdminDisabledSummary="true"
|
||||
settings:controller="com.android.settings.accessibility.ViewAllBluetoothDevicesPreferenceController"/>
|
||||
</PreferenceCategory>
|
||||
|
||||
<com.android.settings.accessibility.AccessibilityFooterPreference
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2021 The Android Open Source Project
|
||||
<!-- Copyright (C) 2023 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -51,13 +51,6 @@
|
||||
settings:keywords="@string/keywords_battery_saver"
|
||||
settings:controller="com.android.settings.fuelgauge.BatterySaverController" />
|
||||
|
||||
<Preference
|
||||
android:fragment="com.android.settings.fuelgauge.SmartBatterySettings"
|
||||
android:key="smart_battery_manager"
|
||||
android:title="@string/smart_battery_manager_title"
|
||||
settings:controller="com.android.settings.fuelgauge.batterytip.BatteryManagerPreferenceController"
|
||||
settings:keywords="@string/keywords_battery_adaptive_preferences" />
|
||||
|
||||
<SwitchPreference
|
||||
android:key="battery_percentage"
|
||||
android:title="@string/battery_percentage"
|
||||
|
||||
@@ -20,6 +20,7 @@ import android.app.settings.SettingsEnums;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothUuid;
|
||||
import android.bluetooth.le.ScanFilter;
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
@@ -47,6 +48,12 @@ public class HearingDevicePairingDetail extends BluetoothDevicePairingDetailBase
|
||||
setFilter(Collections.singletonList(filter));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
use(ViewAllBluetoothDevicesPreferenceController.class).init(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.bluetooth.BluetoothPairingDetail;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
/** Preference controller for all bluetooth device preference. */
|
||||
public class ViewAllBluetoothDevicesPreferenceController extends BasePreferenceController implements
|
||||
PreferenceManager.OnActivityResultListener {
|
||||
|
||||
private static final int REQUEST_CODE_BONDED_DEVICE = 270;
|
||||
private DashboardFragment mFragment;
|
||||
|
||||
public ViewAllBluetoothDevicesPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes objects in this controller. Needs to call this before using the controller.
|
||||
*
|
||||
* @param fragment The {@link DashboardFragment} uses the controller
|
||||
*/
|
||||
public void init(DashboardFragment fragment) {
|
||||
mFragment = fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
if (TextUtils.equals(preference.getKey(), getPreferenceKey())) {
|
||||
launchBluetoothPairingDetail();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
// If back from BONDED device page, then no need to show scan result again.
|
||||
// Finish the fragment.
|
||||
if (requestCode == REQUEST_CODE_BONDED_DEVICE && resultCode == RESULT_OK) {
|
||||
mFragment.finish();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void launchBluetoothPairingDetail() {
|
||||
new SubSettingLauncher(mContext)
|
||||
.setDestination(BluetoothPairingDetail.class.getName())
|
||||
.setSourceMetricsCategory(mFragment.getMetricsCategory())
|
||||
.setResultListener(mFragment, REQUEST_CODE_BONDED_DEVICE)
|
||||
.launch();
|
||||
}
|
||||
}
|
||||
@@ -219,7 +219,13 @@ public class FingerprintEnrollEnrollingSfpsFragment extends Fragment {
|
||||
super.onStart();
|
||||
startEnrollment();
|
||||
updateProgress(false /* animate */, mProgressViewModel.getProgressLiveData().getValue());
|
||||
updateTitleAndDescription();
|
||||
final EnrollmentStatusMessage msg = mProgressViewModel.getHelpMessageLiveData().getValue();
|
||||
if (msg != null) {
|
||||
onEnrollmentHelp(msg);
|
||||
} else {
|
||||
clearError();
|
||||
updateTitleAndDescription();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -373,7 +379,7 @@ public class FingerprintEnrollEnrollingSfpsFragment extends Fragment {
|
||||
mView.setHeaderText(error);
|
||||
mView.getHeaderTextView().setContentDescription(error);
|
||||
new GlifLayoutHelper(getActivity(), mView).setDescriptionText("");
|
||||
if (!mHelpAnimation.isRunning()) {
|
||||
if (isResumed() && !mHelpAnimation.isRunning()) {
|
||||
mHelpAnimation.start();
|
||||
}
|
||||
applySfpsErrorDynamicColors(true);
|
||||
|
||||
@@ -105,7 +105,7 @@ public class FingerprintEnrollEnrollingUdfpsFragment extends Fragment {
|
||||
};
|
||||
private final Observer<EnrollmentStatusMessage> mHelpMessageObserver = helpMessage -> {
|
||||
if (helpMessage != null) {
|
||||
onEnrollmentHelp(helpMessage.getStr());
|
||||
onEnrollmentHelp(helpMessage);
|
||||
}
|
||||
};
|
||||
private final Observer<EnrollmentStatusMessage> mErrorMessageObserver = errorMessage -> {
|
||||
@@ -198,7 +198,12 @@ public class FingerprintEnrollEnrollingUdfpsFragment extends Fragment {
|
||||
super.onStart();
|
||||
startEnrollment();
|
||||
updateProgress(false /* animate */, mProgressViewModel.getProgressLiveData().getValue());
|
||||
updateTitleAndDescription();
|
||||
final EnrollmentStatusMessage msg = mProgressViewModel.getHelpMessageLiveData().getValue();
|
||||
if (msg != null) {
|
||||
onEnrollmentHelp(msg);
|
||||
} else {
|
||||
updateTitleAndDescription();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -484,13 +489,13 @@ public class FingerprintEnrollEnrollingUdfpsFragment extends Fragment {
|
||||
|
||||
}
|
||||
|
||||
private void onEnrollmentHelp(CharSequence helpString) {
|
||||
if (!TextUtils.isEmpty(helpString)) {
|
||||
showError(helpString);
|
||||
private void onEnrollmentHelp(@NonNull EnrollmentStatusMessage helpMessage) {
|
||||
final CharSequence helpStr = helpMessage.getStr();
|
||||
if (!TextUtils.isEmpty(helpStr)) {
|
||||
showError(helpStr);
|
||||
mUdfpsEnrollView.onEnrollmentHelp();
|
||||
}
|
||||
}
|
||||
|
||||
private void onEnrollmentError(@NonNull EnrollmentStatusMessage errorMessage) {
|
||||
removeEnrollmentObservers();
|
||||
|
||||
|
||||
@@ -77,6 +77,7 @@ public class FingerprintEnrollProgressViewModel extends AndroidViewModel {
|
||||
Log.d(TAG, "onEnrollmentProgress(" + remaining + "), steps: " + currentSteps
|
||||
+ ", post progress as " + progress);
|
||||
}
|
||||
mHelpMessageLiveData.setValue(null);
|
||||
mProgressLiveData.postValue(progress);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
@@ -93,6 +94,7 @@ public abstract class BluetoothDevicePairingDetailBase extends DeviceListPrefere
|
||||
public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) {
|
||||
if (bondState == BluetoothDevice.BOND_BONDED) {
|
||||
// If one device is connected(bonded), then close this fragment.
|
||||
setResult(RESULT_OK);
|
||||
finish();
|
||||
return;
|
||||
} else if (bondState == BluetoothDevice.BOND_BONDING) {
|
||||
@@ -124,6 +126,7 @@ public abstract class BluetoothDevicePairingDetailBase extends DeviceListPrefere
|
||||
if (cachedDevice != null && cachedDevice.isConnected()) {
|
||||
final BluetoothDevice device = cachedDevice.getDevice();
|
||||
if (device != null && mSelectedList.contains(device)) {
|
||||
setResult(RESULT_OK);
|
||||
finish();
|
||||
} else if (mDevicePreferenceMap.containsKey(cachedDevice)) {
|
||||
onDeviceDeleted(cachedDevice);
|
||||
|
||||
@@ -117,16 +117,6 @@ public interface PowerUsageFeatureProvider {
|
||||
*/
|
||||
boolean isChartGraphSlotsEnabled(Context context);
|
||||
|
||||
/**
|
||||
* Checks whether adaptive charging feature is supported in this device
|
||||
*/
|
||||
boolean isAdaptiveChargingSupported();
|
||||
|
||||
/**
|
||||
* Checks whether battery manager feature is supported in this device
|
||||
*/
|
||||
boolean isBatteryManagerSupported();
|
||||
|
||||
/**
|
||||
* Returns {@code true} if current defender mode is extra defend
|
||||
*/
|
||||
|
||||
@@ -139,16 +139,6 @@ public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAdaptiveChargingSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBatteryManagerSupported() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Intent getResumeChargeIntent(boolean isDockDefender) {
|
||||
return null;
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.fuelgauge.batterytip;
|
||||
|
||||
import android.app.AppOpsManager;
|
||||
import android.content.Context;
|
||||
import android.os.UserManager;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.utils.StringUtil;
|
||||
|
||||
/** Preference controller to control the battery manager */
|
||||
public class BatteryManagerPreferenceController extends BasePreferenceController {
|
||||
private static final String KEY_BATTERY_MANAGER = "smart_battery_manager";
|
||||
|
||||
private PowerUsageFeatureProvider mPowerUsageFeatureProvider;
|
||||
private AppOpsManager mAppOpsManager;
|
||||
private UserManager mUserManager;
|
||||
private boolean mEnableAppBatteryUsagePage;
|
||||
|
||||
public BatteryManagerPreferenceController(Context context) {
|
||||
super(context, KEY_BATTERY_MANAGER);
|
||||
mPowerUsageFeatureProvider = FeatureFactory.getFactory(
|
||||
context).getPowerUsageFeatureProvider(context);
|
||||
mAppOpsManager = context.getSystemService(AppOpsManager.class);
|
||||
mUserManager = context.getSystemService(UserManager.class);
|
||||
mEnableAppBatteryUsagePage =
|
||||
mContext.getResources().getBoolean(R.bool.config_app_battery_usage_list_enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
if (!mPowerUsageFeatureProvider.isBatteryManagerSupported()) {
|
||||
return UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
if (!mContext.getResources().getBoolean(R.bool.config_battery_manager_consider_ac)) {
|
||||
return AVAILABLE_UNSEARCHABLE;
|
||||
}
|
||||
return mPowerUsageFeatureProvider.isAdaptiveChargingSupported()
|
||||
? AVAILABLE_UNSEARCHABLE : UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
if (!mEnableAppBatteryUsagePage) {
|
||||
final int num = BatteryTipUtils.getRestrictedAppsList(mAppOpsManager,
|
||||
mUserManager).size();
|
||||
updateSummary(preference, num);
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void updateSummary(Preference preference, int num) {
|
||||
if (num > 0) {
|
||||
preference.setSummary(StringUtil.getIcuPluralsString(mContext, num,
|
||||
R.string.battery_manager_app_restricted));
|
||||
} else {
|
||||
preference.setSummary(
|
||||
mPowerUsageFeatureProvider.isAdaptiveChargingSupported()
|
||||
? R.string.battery_manager_summary
|
||||
: R.string.battery_manager_summary_unsupported);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,13 +63,7 @@ class LocaleDragCell extends RelativeLayout {
|
||||
|
||||
public void setShowCheckbox(boolean showCheckbox) {
|
||||
// "Opposite" visibility for label / checkbox
|
||||
if (showCheckbox) {
|
||||
mCheckbox.setVisibility(VISIBLE);
|
||||
mLabel.setVisibility(INVISIBLE);
|
||||
} else {
|
||||
mCheckbox.setVisibility(INVISIBLE);
|
||||
mLabel.setVisibility(VISIBLE);
|
||||
}
|
||||
mCheckbox.setVisibility(showCheckbox ? VISIBLE : GONE);
|
||||
invalidate();
|
||||
requestLayout();
|
||||
}
|
||||
@@ -91,9 +85,7 @@ class LocaleDragCell extends RelativeLayout {
|
||||
|
||||
public void setLabelAndDescription(String labelText, String description) {
|
||||
mLabel.setText(labelText);
|
||||
mCheckbox.setText(labelText);
|
||||
mLabel.setContentDescription(description);
|
||||
mCheckbox.setContentDescription(description);
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@@ -114,6 +106,10 @@ class LocaleDragCell extends RelativeLayout {
|
||||
return mDragHandle;
|
||||
}
|
||||
|
||||
public TextView getLabelView() {
|
||||
return mLabel;
|
||||
}
|
||||
|
||||
public CheckBox getCheckbox() {
|
||||
return mCheckbox;
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ public class LocaleLinearLayoutManager extends LinearLayoutManager {
|
||||
// any language can handle it. And we want the position to be part of it.
|
||||
// So we use something like "2, French (France)"
|
||||
final String description =
|
||||
(position + 1) + ", " + dragCell.getCheckbox().getContentDescription();
|
||||
(position + 1) + ", " + dragCell.getLabelView().getContentDescription();
|
||||
info.setContentDescription(description);
|
||||
|
||||
if (mAdapter.isRemoveMode()) { // We don't move things around in remove mode
|
||||
|
||||
@@ -32,9 +32,11 @@ import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -96,6 +98,10 @@ public class WifiHotspotRepository {
|
||||
protected String mCurrentCountryCode;
|
||||
protected ActiveCountryCodeChangedCallback mActiveCountryCodeChangedCallback;
|
||||
|
||||
@VisibleForTesting
|
||||
Boolean mIsConfigShowSpeed;
|
||||
private Boolean mIsSpeedFeatureAvailable;
|
||||
|
||||
public WifiHotspotRepository(@NonNull Context appContext, @NonNull WifiManager wifiManager) {
|
||||
mAppContext = appContext;
|
||||
mWifiManager = wifiManager;
|
||||
@@ -314,6 +320,7 @@ public class WifiHotspotRepository {
|
||||
|
||||
/**
|
||||
* Return whether Wi-Fi Dual Band is supported or not.
|
||||
*
|
||||
* @return {@code true} if Wi-Fi Dual Band is supported
|
||||
*/
|
||||
public boolean isDualBand() {
|
||||
@@ -326,6 +333,7 @@ public class WifiHotspotRepository {
|
||||
|
||||
/**
|
||||
* Return whether Wi-Fi 5 GHz band is supported or not.
|
||||
*
|
||||
* @return {@code true} if Wi-Fi 5 GHz Band is supported
|
||||
*/
|
||||
public boolean is5GHzBandSupported() {
|
||||
@@ -338,6 +346,7 @@ public class WifiHotspotRepository {
|
||||
|
||||
/**
|
||||
* Return whether Wi-Fi Hotspot 5 GHz band is available or not.
|
||||
*
|
||||
* @return {@code true} if Wi-Fi Hotspot 5 GHz Band is available
|
||||
*/
|
||||
public boolean is5gAvailable() {
|
||||
@@ -371,6 +380,7 @@ public class WifiHotspotRepository {
|
||||
|
||||
/**
|
||||
* Return whether Wi-Fi 6 GHz band is supported or not.
|
||||
*
|
||||
* @return {@code true} if Wi-Fi 6 GHz Band is supported
|
||||
*/
|
||||
public boolean is6GHzBandSupported() {
|
||||
@@ -383,6 +393,7 @@ public class WifiHotspotRepository {
|
||||
|
||||
/**
|
||||
* Return whether Wi-Fi Hotspot 6 GHz band is available or not.
|
||||
*
|
||||
* @return {@code true} if Wi-Fi Hotspot 6 GHz Band is available
|
||||
*/
|
||||
public boolean is6gAvailable() {
|
||||
@@ -432,9 +443,63 @@ public class WifiHotspotRepository {
|
||||
// This is expected on some hardware.
|
||||
Log.e(TAG, "Querying usable SAP channels is unsupported, band:" + band);
|
||||
}
|
||||
// Disable Wi-Fi hotspot speed feature if an error occurs while getting usable channels.
|
||||
mIsSpeedFeatureAvailable = false;
|
||||
Log.w(TAG, "isChannelAvailable(): Wi-Fi hotspot speed feature disabled");
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
private boolean isConfigShowSpeed() {
|
||||
if (mIsConfigShowSpeed == null) {
|
||||
mIsConfigShowSpeed = mAppContext.getResources()
|
||||
.getBoolean(R.bool.config_show_wifi_hotspot_speed);
|
||||
log("isConfigShowSpeed():" + mIsConfigShowSpeed);
|
||||
}
|
||||
return mIsConfigShowSpeed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether Wi-Fi Hotspot Speed Feature is available or not.
|
||||
*
|
||||
* @return {@code true} if Wi-Fi Hotspot Speed Feature is available
|
||||
*/
|
||||
public boolean isSpeedFeatureAvailable() {
|
||||
if (mIsSpeedFeatureAvailable != null) {
|
||||
return mIsSpeedFeatureAvailable;
|
||||
}
|
||||
|
||||
// Check config to show Wi-Fi hotspot speed feature
|
||||
if (!isConfigShowSpeed()) {
|
||||
mIsSpeedFeatureAvailable = false;
|
||||
log("isSpeedFeatureAvailable():false, isConfigShowSpeed():false");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if 5 GHz band is not supported
|
||||
if (!is5GHzBandSupported()) {
|
||||
mIsSpeedFeatureAvailable = false;
|
||||
log("isSpeedFeatureAvailable():false, 5 GHz band is not supported on this device");
|
||||
return false;
|
||||
}
|
||||
// Check if 5 GHz band SAP channel is not ready
|
||||
isChannelAvailable(WifiScanner.WIFI_BAND_5_GHZ_WITH_DFS, true /* defaultValue */);
|
||||
if (mIsSpeedFeatureAvailable != null && !mIsSpeedFeatureAvailable) {
|
||||
log("isSpeedFeatureAvailable():false, error occurred while getting 5 GHz SAP channel");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if 6 GHz band SAP channel is not ready
|
||||
isChannelAvailable(WifiScanner.WIFI_BAND_6_GHZ, false /* defaultValue */);
|
||||
if (mIsSpeedFeatureAvailable != null && !mIsSpeedFeatureAvailable) {
|
||||
log("isSpeedFeatureAvailable():false, error occurred while getting 6 GHz SAP channel");
|
||||
return false;
|
||||
}
|
||||
|
||||
mIsSpeedFeatureAvailable = true;
|
||||
log("isSpeedFeatureAvailable():true");
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void purgeRefreshData() {
|
||||
mIs5gAvailable = null;
|
||||
mIs6gAvailable = null;
|
||||
|
||||
@@ -25,6 +25,7 @@ import androidx.preference.Preference;
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
/**
|
||||
* This controller helps to manage the state of maximize compatibility switch preference.
|
||||
@@ -36,13 +37,30 @@ public class WifiTetherMaximizeCompatibilityPreferenceController extends
|
||||
public static final String PREF_KEY = "wifi_tether_maximize_compatibility";
|
||||
|
||||
private boolean mIsChecked;
|
||||
@VisibleForTesting
|
||||
boolean mShouldHidePreference;
|
||||
|
||||
public WifiTetherMaximizeCompatibilityPreferenceController(Context context,
|
||||
WifiTetherBasePreferenceController.OnTetherConfigUpdateListener listener) {
|
||||
super(context, listener);
|
||||
// If the Wi-Fi Hotspot Speed Feature available, then hide this controller.
|
||||
mShouldHidePreference = FeatureFactory.getFactory(context)
|
||||
.getWifiFeatureProvider().getWifiHotspotRepository().isSpeedFeatureAvailable();
|
||||
Log.d(TAG, "mShouldHidePreference:" + mShouldHidePreference);
|
||||
if (mShouldHidePreference) {
|
||||
return;
|
||||
}
|
||||
mIsChecked = isMaximizeCompatibilityEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
if (mShouldHidePreference) {
|
||||
return false;
|
||||
}
|
||||
return super.isAvailable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return PREF_KEY;
|
||||
|
||||
@@ -32,6 +32,7 @@ import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.FeatureFlags;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
@@ -48,10 +49,19 @@ public class WifiTetherSecurityPreferenceController extends WifiTetherBasePrefer
|
||||
private int mSecurityValue;
|
||||
@VisibleForTesting
|
||||
boolean mIsWpa3Supported = true;
|
||||
@VisibleForTesting
|
||||
boolean mShouldHidePreference;
|
||||
|
||||
public WifiTetherSecurityPreferenceController(Context context,
|
||||
OnTetherConfigUpdateListener listener) {
|
||||
super(context, listener);
|
||||
// If the Wi-Fi Hotspot Speed Feature available, then hide this controller.
|
||||
mShouldHidePreference = FeatureFactory.getFactory(context)
|
||||
.getWifiFeatureProvider().getWifiHotspotRepository().isSpeedFeatureAvailable();
|
||||
Log.d(TAG, "shouldHidePreference():" + mShouldHidePreference);
|
||||
if (mShouldHidePreference) {
|
||||
return;
|
||||
}
|
||||
final String[] securityNames = mContext.getResources().getStringArray(
|
||||
R.array.wifi_tether_security);
|
||||
final String[] securityValues = mContext.getResources().getStringArray(
|
||||
@@ -62,6 +72,14 @@ public class WifiTetherSecurityPreferenceController extends WifiTetherBasePrefer
|
||||
mWifiManager.registerSoftApCallback(context.getMainExecutor(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
if (mShouldHidePreference) {
|
||||
return false;
|
||||
}
|
||||
return super.isAvailable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return FeatureFlagUtils.isEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE)
|
||||
|
||||
@@ -136,12 +136,22 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
|
||||
|
||||
mWifiTetherViewModel = FeatureFactory.getFactory(getContext()).getWifiFeatureProvider()
|
||||
.getWifiTetherViewModel(this);
|
||||
mWifiHotspotSecurity = findPreference(KEY_WIFI_HOTSPOT_SECURITY);
|
||||
if (mWifiHotspotSecurity != null && mWifiHotspotSecurity.isVisible()) {
|
||||
mWifiTetherViewModel.getSecuritySummary().observe(this, this::onSecuritySummaryChanged);
|
||||
if (mWifiTetherViewModel != null) {
|
||||
setupSpeedFeature(mWifiTetherViewModel.isSpeedFeatureAvailable());
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void setupSpeedFeature(boolean isSpeedFeatureAvailable) {
|
||||
mWifiHotspotSecurity = findPreference(KEY_WIFI_HOTSPOT_SECURITY);
|
||||
mWifiHotspotSpeed = findPreference(KEY_WIFI_HOTSPOT_SPEED);
|
||||
if (mWifiHotspotSpeed != null && mWifiHotspotSpeed.isVisible()) {
|
||||
if (mWifiHotspotSecurity == null || mWifiHotspotSpeed == null) {
|
||||
return;
|
||||
}
|
||||
mWifiHotspotSecurity.setVisible(isSpeedFeatureAvailable);
|
||||
mWifiHotspotSpeed.setVisible(isSpeedFeatureAvailable);
|
||||
if (isSpeedFeatureAvailable) {
|
||||
mWifiTetherViewModel.getSecuritySummary().observe(this, this::onSecuritySummaryChanged);
|
||||
mWifiTetherViewModel.getSpeedSummary().observe(this, this::onSpeedSummaryChanged);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,8 +83,21 @@ public class WifiTetherViewModel extends AndroidViewModel {
|
||||
|
||||
@Override
|
||||
protected void onCleared() {
|
||||
mWifiHotspotRepository.getSecurityType().removeObserver(mSecurityTypeObserver);
|
||||
mWifiHotspotRepository.getSpeedType().removeObserver(mSpeedTypeObserver);
|
||||
if (mSecuritySummary != null) {
|
||||
mWifiHotspotRepository.getSecurityType().removeObserver(mSecurityTypeObserver);
|
||||
}
|
||||
if (mSpeedSummary != null) {
|
||||
mWifiHotspotRepository.getSpeedType().removeObserver(mSpeedTypeObserver);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether Wi-Fi Hotspot Speed Feature is available or not.
|
||||
*
|
||||
* @return {@code true} if Wi-Fi Hotspot Speed Feature is available
|
||||
*/
|
||||
public boolean isSpeedFeatureAvailable() {
|
||||
return mWifiHotspotRepository.isSpeedFeatureAvailable();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
/** Tests for {@link ViewAllBluetoothDevicesPreferenceController}. */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class ViewAllBluetoothDevicesPreferenceControllerTest {
|
||||
|
||||
@Rule
|
||||
public MockitoRule mocks = MockitoJUnit.rule();
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
private final Preference mPreference = new Preference(mContext);
|
||||
private final String TEST_KEY = "test_key";
|
||||
|
||||
@Spy
|
||||
private HearingDevicePairingDetail mFragment = new HearingDevicePairingDetail();
|
||||
private FragmentActivity mActivity;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
private ViewAllBluetoothDevicesPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mActivity = Robolectric.setupActivity(FragmentActivity.class);
|
||||
when(mFragment.getContext()).thenReturn(mContext);
|
||||
when(mFragment.getActivity()).thenReturn(mActivity);
|
||||
|
||||
mController = spy(new ViewAllBluetoothDevicesPreferenceController(mActivity, TEST_KEY));
|
||||
mController.init(mFragment);
|
||||
mController.displayPreference(mScreen);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_expectedPreference_launchBluetoothPairingDetail() {
|
||||
doNothing().when(mController).launchBluetoothPairingDetail();
|
||||
mPreference.setKey(TEST_KEY);
|
||||
|
||||
boolean status = mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
verify(mController).launchBluetoothPairingDetail();
|
||||
assertThat(status).isTrue();
|
||||
}
|
||||
}
|
||||
@@ -126,11 +126,6 @@ public class PowerUsageFeatureProviderImplTest {
|
||||
assertThat(mPowerFeatureProvider.isSmartBatterySupported()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAdaptiveChargingSupported_returnFalse() {
|
||||
assertThat(mPowerFeatureProvider.isAdaptiveChargingSupported()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetResumeChargeIntentWithoutDockDefender_returnNull() {
|
||||
assertThat(mPowerFeatureProvider.getResumeChargeIntent(false)).isNull();
|
||||
|
||||
@@ -1,130 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.fuelgauge.batterytip;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.AppOpsManager;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = SettingsShadowResources.class)
|
||||
public class BatteryManagerPreferenceControllerTest {
|
||||
private static final int ON = 1;
|
||||
private static final int OFF = 0;
|
||||
|
||||
@Mock
|
||||
private AppOpsManager mAppOpsManager;
|
||||
|
||||
|
||||
private Context mContext;
|
||||
private Preference mPreference;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
private PowerUsageFeatureProvider mPowerUsageFeatureProvider;
|
||||
private BatteryManagerPreferenceController mController;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
when(mContext.getSystemService(AppOpsManager.class)).thenReturn(mAppOpsManager);
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
mPreference = new Preference(mContext);
|
||||
mController = new BatteryManagerPreferenceController(mContext);
|
||||
mPowerUsageFeatureProvider = mFeatureFactory.powerUsageFeatureProvider;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_smartBatteryWithRestrictApps_showSummary() {
|
||||
mController.updateSummary(mPreference, 2);
|
||||
|
||||
assertThat(mPreference.getSummary()).isEqualTo("2 apps restricted");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_smartBatteryWithoutRestriction_showSummary() {
|
||||
when(mPowerUsageFeatureProvider.isSmartBatterySupported()).thenReturn(true);
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.ADAPTIVE_BATTERY_MANAGEMENT_ENABLED, ON);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.getSummary()).isEqualTo("Detecting when apps drain battery");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_supportBatteryManager_showPrefPage() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
R.bool.config_battery_manager_consider_ac, true);
|
||||
when(mPowerUsageFeatureProvider.isBatteryManagerSupported()).thenReturn(true);
|
||||
when(mPowerUsageFeatureProvider.isAdaptiveChargingSupported()).thenReturn(true);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BatteryManagerPreferenceController.AVAILABLE_UNSEARCHABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_notSupportBatteryManager_notShowPrefPage() {
|
||||
when(mPowerUsageFeatureProvider.isBatteryManagerSupported()).thenReturn(false);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BatteryManagerPreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_supportBatteryManagerWithoutAC_notShowPrefPage() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
R.bool.config_battery_manager_consider_ac, true);
|
||||
when(mPowerUsageFeatureProvider.isBatteryManagerSupported()).thenReturn(true);
|
||||
when(mPowerUsageFeatureProvider.isAdaptiveChargingSupported()).thenReturn(false);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BatteryManagerPreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_ignoreBatteryManagerWithoutAC_showPrefPage() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
R.bool.config_battery_manager_consider_ac, false);
|
||||
when(mPowerUsageFeatureProvider.isBatteryManagerSupported()).thenReturn(true);
|
||||
when(mPowerUsageFeatureProvider.isAdaptiveChargingSupported()).thenReturn(false);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BatteryManagerPreferenceController.AVAILABLE_UNSEARCHABLE);
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,8 @@
|
||||
package com.android.settings.wifi.tether;
|
||||
|
||||
import static com.android.settings.wifi.WifiUtils.setCanShowWifiHotspotCached;
|
||||
import static com.android.settings.wifi.tether.WifiTetherSettings.KEY_WIFI_HOTSPOT_SECURITY;
|
||||
import static com.android.settings.wifi.tether.WifiTetherSettings.KEY_WIFI_HOTSPOT_SPEED;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@@ -26,6 +28,7 @@ import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -41,6 +44,7 @@ import android.util.FeatureFlagUtils;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.ViewModelStoreOwner;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
@@ -79,7 +83,7 @@ public class WifiTetherSettingsTest {
|
||||
@Rule
|
||||
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||
@Spy
|
||||
Context mContext = ApplicationProvider.getApplicationContext();
|
||||
private Context mContext = ApplicationProvider.getApplicationContext();
|
||||
@Mock
|
||||
private WifiManager mWifiManager;
|
||||
@Mock
|
||||
@@ -95,11 +99,19 @@ public class WifiTetherSettingsTest {
|
||||
@Mock
|
||||
private TextView mEmptyTextView;
|
||||
@Mock
|
||||
WifiTetherViewModel mWifiTetherViewModel;
|
||||
private WifiTetherViewModel mWifiTetherViewModel;
|
||||
@Mock
|
||||
WifiHotspotRepository mWifiHotspotRepository;
|
||||
private WifiHotspotRepository mWifiHotspotRepository;
|
||||
@Mock
|
||||
private Preference mWifiHotspotSecurity;
|
||||
@Mock
|
||||
private LiveData<Integer> mSecuritySummary;
|
||||
@Mock
|
||||
private Preference mWifiHotspotSpeed;
|
||||
@Mock
|
||||
private LiveData<Integer> mSpeedSummary;
|
||||
|
||||
private WifiTetherSettings mWifiTetherSettings;
|
||||
private WifiTetherSettings mSettings;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -118,19 +130,25 @@ public class WifiTetherSettingsTest {
|
||||
when(provider.getWifiHotspotRepository()).thenReturn(mWifiHotspotRepository);
|
||||
when(provider.getWifiTetherViewModel(mock(ViewModelStoreOwner.class)))
|
||||
.thenReturn(mWifiTetherViewModel);
|
||||
when(mWifiTetherViewModel.isSpeedFeatureAvailable()).thenReturn(false);
|
||||
when(mWifiTetherViewModel.getSecuritySummary()).thenReturn(mSecuritySummary);
|
||||
when(mWifiTetherViewModel.getSpeedSummary()).thenReturn(mSpeedSummary);
|
||||
|
||||
mWifiTetherSettings = new WifiTetherSettings(mWifiRestriction);
|
||||
mSettings = spy(new WifiTetherSettings(mWifiRestriction));
|
||||
mSettings.mWifiTetherViewModel = mWifiTetherViewModel;
|
||||
when(mSettings.findPreference(KEY_WIFI_HOTSPOT_SECURITY)).thenReturn(mWifiHotspotSecurity);
|
||||
when(mSettings.findPreference(KEY_WIFI_HOTSPOT_SPEED)).thenReturn(mWifiHotspotSpeed);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowRestrictedDashboardFragment.class)
|
||||
public void onCreate_canNotShowWifiHotspot_shouldFinish() {
|
||||
setCanShowWifiHotspotCached(false);
|
||||
mWifiTetherSettings = spy(new WifiTetherSettings(mWifiRestriction));
|
||||
mSettings = spy(new WifiTetherSettings(mWifiRestriction));
|
||||
|
||||
mWifiTetherSettings.onCreate(null);
|
||||
mSettings.onCreate(null);
|
||||
|
||||
verify(mWifiTetherSettings).finish();
|
||||
verify(mSettings).finish();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -138,7 +156,7 @@ public class WifiTetherSettingsTest {
|
||||
public void onStart_uiIsRestricted_removeAllPreferences() {
|
||||
spyWifiTetherSettings();
|
||||
|
||||
mWifiTetherSettings.onStart();
|
||||
mSettings.onStart();
|
||||
|
||||
verify(mPreferenceScreen).removeAll();
|
||||
}
|
||||
@@ -149,7 +167,7 @@ public class WifiTetherSettingsTest {
|
||||
spyWifiTetherSettings();
|
||||
when(mWifiRestriction.isHotspotAvailable(mContext)).thenReturn(false);
|
||||
|
||||
mWifiTetherSettings.onStart();
|
||||
mSettings.onStart();
|
||||
|
||||
verify(mPreferenceScreen).removeAll();
|
||||
verify(mEmptyTextView).setText(anyInt());
|
||||
@@ -158,21 +176,21 @@ public class WifiTetherSettingsTest {
|
||||
@Test
|
||||
public void onSecuritySummaryChanged_canNotShowWifiHotspot_returnFalse() {
|
||||
int stringResId = R.string.wifi_security_sae;
|
||||
mWifiTetherSettings.mWifiHotspotSecurity = mock(Preference.class);
|
||||
mSettings.mWifiHotspotSecurity = mock(Preference.class);
|
||||
|
||||
mWifiTetherSettings.onSecuritySummaryChanged(stringResId);
|
||||
mSettings.onSecuritySummaryChanged(stringResId);
|
||||
|
||||
verify(mWifiTetherSettings.mWifiHotspotSecurity).setSummary(stringResId);
|
||||
verify(mSettings.mWifiHotspotSecurity).setSummary(stringResId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onSpeedSummaryChanged_canNotShowWifiHotspot_returnFalse() {
|
||||
int stringResId = R.string.wifi_hotspot_speed_summary_6g;
|
||||
mWifiTetherSettings.mWifiHotspotSpeed = mock(Preference.class);
|
||||
mSettings.mWifiHotspotSpeed = mock(Preference.class);
|
||||
|
||||
mWifiTetherSettings.onSpeedSummaryChanged(stringResId);
|
||||
mSettings.onSpeedSummaryChanged(stringResId);
|
||||
|
||||
verify(mWifiTetherSettings.mWifiHotspotSpeed).setSummary(stringResId);
|
||||
verify(mSettings.mWifiHotspotSpeed).setSummary(stringResId);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -183,7 +201,7 @@ public class WifiTetherSettingsTest {
|
||||
|
||||
@Test
|
||||
public void createPreferenceControllers_hasAutoOffPreference() {
|
||||
assertThat(mWifiTetherSettings.createPreferenceControllers(mContext)
|
||||
assertThat(mSettings.createPreferenceControllers(mContext)
|
||||
.stream()
|
||||
.filter(controller -> controller instanceof WifiTetherAutoOffPreferenceController)
|
||||
.count())
|
||||
@@ -270,23 +288,42 @@ public class WifiTetherSettingsTest {
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setupSpeedFeature_speedFeatureIsAvailable_setVisibleToTrue() {
|
||||
mSettings.setupSpeedFeature(true);
|
||||
|
||||
verify(mWifiHotspotSecurity).setVisible(true);
|
||||
verify(mWifiHotspotSpeed).setVisible(true);
|
||||
verify(mSecuritySummary).observe(any(), any());
|
||||
verify(mSpeedSummary).observe(any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setupSpeedFeature_speedFeatureIsNotAvailable_setVisibleToFalse() {
|
||||
mSettings.setupSpeedFeature(false);
|
||||
|
||||
verify(mWifiHotspotSecurity).setVisible(false);
|
||||
verify(mWifiHotspotSpeed).setVisible(false);
|
||||
verify(mSecuritySummary, never()).observe(any(), any());
|
||||
verify(mSpeedSummary, never()).observe(any(), any());
|
||||
}
|
||||
|
||||
private void spyWifiTetherSettings() {
|
||||
mWifiTetherSettings = spy(new WifiTetherSettings(mWifiRestriction));
|
||||
mSettings = spy(new WifiTetherSettings(mWifiRestriction));
|
||||
final FragmentActivity activity = mock(FragmentActivity.class);
|
||||
when(mWifiTetherSettings.getActivity()).thenReturn(activity);
|
||||
when(mWifiTetherSettings.getContext()).thenReturn(mContext);
|
||||
when(mSettings.getActivity()).thenReturn(activity);
|
||||
when(mSettings.getContext()).thenReturn(mContext);
|
||||
final Resources.Theme theme = mContext.getTheme();
|
||||
when(activity.getTheme()).thenReturn(theme);
|
||||
when(activity.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||
doNothing().when(mWifiTetherSettings)
|
||||
.onCreatePreferences(any(Bundle.class), nullable(String.class));
|
||||
doNothing().when(mSettings).onCreatePreferences(any(Bundle.class), nullable(String.class));
|
||||
final FakeFeatureFactory fakeFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
ReflectionHelpers.setField(mWifiTetherSettings, "mDashboardFeatureProvider",
|
||||
ReflectionHelpers.setField(mSettings, "mDashboardFeatureProvider",
|
||||
fakeFeatureFactory.dashboardFeatureProvider);
|
||||
ReflectionHelpers.setField(mWifiTetherSettings, "mEmptyTextView", mEmptyTextView);
|
||||
doReturn(mPreferenceScreen).when(mWifiTetherSettings).getPreferenceScreen();
|
||||
ReflectionHelpers.setField(mSettings, "mEmptyTextView", mEmptyTextView);
|
||||
doReturn(mPreferenceScreen).when(mSettings).getPreferenceScreen();
|
||||
|
||||
mWifiTetherSettings.onCreate(Bundle.EMPTY);
|
||||
mSettings.onCreate(Bundle.EMPTY);
|
||||
}
|
||||
|
||||
@Implements(RestrictedDashboardFragment.class)
|
||||
|
||||
@@ -224,6 +224,44 @@ public class FingerprintEnrollProgressViewModelTest {
|
||||
assertThat(progress.getRemaining()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProgressUpdateClearHelpMessage() {
|
||||
// Start enrollment
|
||||
mViewModel.setToken(new byte[] { 1, 2, 3 });
|
||||
final boolean ret = mViewModel.startEnrollment(ENROLL_ENROLL);
|
||||
assertThat(ret).isTrue();
|
||||
assertThat(mCallbackWrapper.mValue).isNotNull();
|
||||
final LiveData<EnrollmentProgress> progressLiveData = mViewModel.getProgressLiveData();
|
||||
final LiveData<EnrollmentStatusMessage> helpMsgLiveData =
|
||||
mViewModel.getHelpMessageLiveData();
|
||||
|
||||
// Update first progress
|
||||
mCallbackWrapper.mValue.onEnrollmentProgress(25);
|
||||
EnrollmentProgress progress = progressLiveData.getValue();
|
||||
assertThat(progress).isNotNull();
|
||||
assertThat(progress.getSteps()).isEqualTo(25);
|
||||
assertThat(progress.getRemaining()).isEqualTo(25);
|
||||
|
||||
// Update help message
|
||||
final int testHelpMsgId = 3;
|
||||
final String testHelpString = "Test Help String";
|
||||
mCallbackWrapper.mValue.onEnrollmentHelp(testHelpMsgId, testHelpString);
|
||||
final EnrollmentStatusMessage helpMsg = helpMsgLiveData.getValue();
|
||||
assertThat(helpMsg).isNotNull();
|
||||
assertThat(helpMsg.getMsgId()).isEqualTo(testHelpMsgId);
|
||||
assertThat(helpMsg.getStr().toString()).isEqualTo(testHelpString);
|
||||
|
||||
// Update second progress
|
||||
mCallbackWrapper.mValue.onEnrollmentProgress(20);
|
||||
progress = progressLiveData.getValue();
|
||||
assertThat(progress).isNotNull();
|
||||
assertThat(progress.getSteps()).isEqualTo(25);
|
||||
assertThat(progress.getRemaining()).isEqualTo(20);
|
||||
|
||||
// Help message shall be set to null
|
||||
assertThat(helpMsgLiveData.getValue()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProgressUpdateWithMessageDisplayController() {
|
||||
// Enable MessageDisplayController and mock handler for it
|
||||
|
||||
@@ -36,6 +36,7 @@ import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.atLeast;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -592,6 +593,65 @@ public class WifiHotspotRepositoryTest {
|
||||
assertThat(mWifiHotspotRepository.get6gAvailable()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSpeedFeatureAvailable_configNotShow_returnFalse() {
|
||||
mWifiHotspotRepository.mIsConfigShowSpeed = false;
|
||||
|
||||
assertThat(mWifiHotspotRepository.isSpeedFeatureAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSpeedFeatureAvailable_5gBandNotSupported_returnFalse() {
|
||||
mWifiHotspotRepository.mIsConfigShowSpeed = true;
|
||||
mWifiHotspotRepository.mIs5gBandSupported = false;
|
||||
|
||||
assertThat(mWifiHotspotRepository.isSpeedFeatureAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSpeedFeatureAvailable_throwExceptionWhenGet5gSapChannel_returnFalse() {
|
||||
mWifiHotspotRepository.mIsConfigShowSpeed = true;
|
||||
mWifiHotspotRepository.mIs5gBandSupported = true;
|
||||
doThrow(IllegalArgumentException.class).when(mWifiManager)
|
||||
.getUsableChannels(WifiScanner.WIFI_BAND_5_GHZ_WITH_DFS, OP_MODE_SAP);
|
||||
|
||||
assertThat(mWifiHotspotRepository.isSpeedFeatureAvailable()).isFalse();
|
||||
|
||||
doThrow(UnsupportedOperationException.class).when(mWifiManager)
|
||||
.getUsableChannels(WifiScanner.WIFI_BAND_5_GHZ_WITH_DFS, OP_MODE_SAP);
|
||||
|
||||
assertThat(mWifiHotspotRepository.isSpeedFeatureAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSpeedFeatureAvailable_throwExceptionWhenGet6gSapChannel_returnFalse() {
|
||||
mWifiHotspotRepository.mIsConfigShowSpeed = true;
|
||||
mWifiHotspotRepository.mIs5gBandSupported = true;
|
||||
doReturn(Arrays.asList(new WifiAvailableChannel(FREQ_5GHZ, OP_MODE_SAP))).when(mWifiManager)
|
||||
.getUsableChannels(WifiScanner.WIFI_BAND_5_GHZ_WITH_DFS, OP_MODE_SAP);
|
||||
doThrow(IllegalArgumentException.class).when(mWifiManager)
|
||||
.getUsableChannels(WifiScanner.WIFI_BAND_6_GHZ, OP_MODE_SAP);
|
||||
|
||||
assertThat(mWifiHotspotRepository.isSpeedFeatureAvailable()).isFalse();
|
||||
|
||||
doThrow(UnsupportedOperationException.class).when(mWifiManager)
|
||||
.getUsableChannels(WifiScanner.WIFI_BAND_6_GHZ, OP_MODE_SAP);
|
||||
|
||||
assertThat(mWifiHotspotRepository.isSpeedFeatureAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSpeedFeatureAvailable_conditionsAreReady_returnTrue() {
|
||||
mWifiHotspotRepository.mIsConfigShowSpeed = true;
|
||||
mWifiHotspotRepository.mIs5gBandSupported = true;
|
||||
doReturn(Arrays.asList(new WifiAvailableChannel(FREQ_5GHZ, OP_MODE_SAP))).when(mWifiManager)
|
||||
.getUsableChannels(WifiScanner.WIFI_BAND_5_GHZ_WITH_DFS, OP_MODE_SAP);
|
||||
doReturn(Arrays.asList(new WifiAvailableChannel(FREQ_6GHZ, OP_MODE_SAP))).when(mWifiManager)
|
||||
.getUsableChannels(WifiScanner.WIFI_BAND_6_GHZ, OP_MODE_SAP);
|
||||
|
||||
assertThat(mWifiHotspotRepository.isSpeedFeatureAvailable()).isTrue();
|
||||
}
|
||||
|
||||
private void mockConfigSecurityType(int securityType) {
|
||||
mockConfig(securityType, SPEED_2GHZ);
|
||||
}
|
||||
|
||||
@@ -237,4 +237,11 @@ public class WifiTetherMaximizeCompatibilityPreferenceControllerTest {
|
||||
|
||||
assertThat(builder.build().getBand()).isEqualTo(SoftApConfiguration.BAND_2GHZ);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_shouldHidePreference_returnFalse() {
|
||||
mController.mShouldHidePreference = true;
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,4 +203,11 @@ public class WifiTetherSecurityPreferenceControllerTest {
|
||||
.isEqualTo(SoftApConfiguration.SECURITY_TYPE_WPA2_PSK);
|
||||
assertThat(mPreference.getSummary().toString()).isEqualTo("WPA2-Personal");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_shouldHidePreference_returnFalse() {
|
||||
mController.mShouldHidePreference = true;
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,10 @@ public class WifiTetherViewModelTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCleared_setAutoRefreshFalse() {
|
||||
public void onCleared_removeObservers() {
|
||||
mViewModel.getSecuritySummary();
|
||||
mViewModel.getSpeedSummary();
|
||||
|
||||
mViewModel.onCleared();
|
||||
|
||||
verify(mSecurityType).removeObserver(mViewModel.mSecurityTypeObserver);
|
||||
@@ -116,4 +119,11 @@ public class WifiTetherViewModelTest {
|
||||
assertThat(mViewModel.mSpeedSummary).isNotNull();
|
||||
verify(mSpeedType).observeForever(mViewModel.mSpeedTypeObserver);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSpeedFeatureAvailable_verifyRepositoryIsCalled() {
|
||||
mViewModel.isSpeedFeatureAvailable();
|
||||
|
||||
verify(mWifiHotspotRepository).isSpeedFeatureAvailable();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user