Merge "Refine permission check process of 2-pane deep link" into udc-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 476d487..ccf002a 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -3119,8 +3119,6 @@
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
- <action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
- <action android:name="android.intent.action.MY_PACKAGE_UNSUSPENDED"/>
<action android:name="com.google.android.setupwizard.SETUP_WIZARD_FINISHED"/>
<action android:name="com.android.settings.battery.action.PERIODIC_JOB_RECHECK"/>
</intent-filter>
diff --git a/res/values/config.xml b/res/values/config.xml
index ee727bc..28bf723 100755
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -710,4 +710,9 @@
<item></item>
</string-array>
+ <!-- List of packages that should be hidden for MVNO. Do not translate -->
+ <string-array name="datausage_hiding_carrier_service_package_names" translatable="false"/>
+
+ <!-- List of MVNO. Do not translate -->
+ <integer-array name="datausage_hiding_carrier_service_carrier_id" translatable="false"/>
</resources>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 0d54cf4..de33ec7 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -412,10 +412,10 @@
<dimen name="sfps_enroll_find_sensor_lottie_margin">0dp</dimen>
<!-- Flash notifications dimensions -->
- <dimen name="screen_flash_color_button_frame_size">38dp</dimen>
- <dimen name="screen_flash_color_button_outer_circle_size">38dp</dimen>
+ <dimen name="screen_flash_color_button_frame_size">48dp</dimen>
+ <dimen name="screen_flash_color_button_outer_circle_size">48dp</dimen>
<dimen name="screen_flash_color_button_outer_circle_stroke_width">2dp</dimen>
- <dimen name="screen_flash_color_button_inner_circle_size">32dp</dimen>
+ <dimen name="screen_flash_color_button_inner_circle_size">42dp</dimen>
<dimen name="screen_flash_color_button_inner_circle_padding">3dp</dimen>
<dimen name="screen_flash_color_button_inner_circle_stroke">1dp</dimen>
</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 8d921f9..44f6503 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2020,13 +2020,37 @@
<!-- Title for Wifi hotspot speed [CHAR LIMIT=NONE]-->
<string name="wifi_hotspot_speed_title">Speed & compatibility</string>
<!-- Summary for Wifi hotspot speed to 2.4 GHz band [CHAR LIMIT=NONE]-->
- <string name="wifi_hotspot_speed_2g_summary">2.4 GHz / Any device can connect</string>
+ <string name="wifi_hotspot_speed_summary_2g">2.4 GHz / Any device can connect</string>
<!-- Summary for Wifi hotspot speed to 5 GHz band [CHAR LIMIT=NONE]-->
- <string name="wifi_hotspot_speed_5g_summary">5 GHz / Most devices can connect</string>
+ <string name="wifi_hotspot_speed_summary_5g">5 GHz / Most devices can connect</string>
<!-- Summary for Wifi hotspot speed to 6 GHz band [CHAR LIMIT=NONE]-->
- <string name="wifi_hotspot_speed_6g_summary">6 GHz / Few devices can connect</string>
+ <string name="wifi_hotspot_speed_summary_6g">6 GHz / Few devices can connect</string>
<!-- Summary for Wifi hotspot speed to 6 GHz band [CHAR LIMIT=NONE]-->
- <string name="wifi_hotspot_speed_2g_and_5g_summary">2.4 and 5 GHz / Any device can connect</string>
+ <string name="wifi_hotspot_speed_summary_2g_and_5g">2.4 and 5 GHz / Any device can connect</string>
+ <!-- Top introduction on the Wi-Fi hotspot speed settings, summarizes options available for Wi-Fi hotspot bands. [CHAR LIMIT=NONE] -->
+ <string name="wifi_hotspot_speed_intro">Choose a frequency for your hotspot. The frequency affects the connection speed and what types of devices can find your hotspot.</string>
+ <!-- Category title on the radio button of the Wi-Fi hotspot speed. [CHAR LIMIT=NONE] -->
+ <string name="wifi_hotspot_speed_category">Preferred frequency</string>
+ <!-- Title for radio button of the Wi-Fi hotspot speed to 2.4 GHz band [CHAR LIMIT=NONE]-->
+ <string name="wifi_hotspot_speed_2g">2.4 GHz</string>
+ <!-- Summary for radio button of the Wi-Fi hotspot speed to 2.4 GHz band [CHAR LIMIT=NONE]-->
+ <string name="wifi_hotspot_speed_2g_summary">Slower speeds. Any device can connect.</string>
+ <!-- Title for radio button of the Wi-Fi hotspot speed to 5 GHz band [CHAR LIMIT=NONE]-->
+ <string name="wifi_hotspot_speed_5g">5 GHz</string>
+ <!-- Summary for radio button of the Wi-Fi hotspot speed to 5 GHz band [CHAR LIMIT=NONE]-->
+ <string name="wifi_hotspot_speed_5g_summary">Fast speeds. Most devices can connect.</string>
+ <!-- Title for radio button of the Wi-Fi hotspot speed to 2.4 GHz and 5 GHz bands [CHAR LIMIT=NONE]-->
+ <string name="wifi_hotspot_speed_2g_5g">2.4 and 5 GHz</string>
+ <!-- Summary for radio button of the Wi-Fi hotspot speed to 2.4 GHz and 5 GHz bands [CHAR LIMIT=NONE]-->
+ <string name="wifi_hotspot_speed_2g_5g_summary">Fast speeds. Any device can connect to this dual-band hotspot.</string>
+ <!-- Title for radio button of the Wi-Fi hotspot speed to 6 GHz band [CHAR LIMIT=NONE]-->
+ <string name="wifi_hotspot_speed_6g">6 GHz</string>
+ <!-- Summary for radio button of the Wi-Fi hotspot speed to 6 GHz band [CHAR LIMIT=NONE]-->
+ <string name="wifi_hotspot_speed_6g_summary">Fastest speeds. Fewest devices can connect.</string>
+ <!-- Summary for the Wi-Fi hotspot speed unavailable [CHAR LIMIT=NONE]-->
+ <string name="wifi_hotspot_speed_summary_unavailable">Not available in your country or region</string>
+ <!-- The footer message for switch screen resolution [CHAR LIMIT=NONE] -->
+ <string name="wifi_hotspot_speed_footer">If your preferred frequency isn\u0027t available, your hotspot may use a different one. Hotspot security settings may change if you change the frequency.</string>
<!-- Summary text when turning hotspot on -->
<string name="wifi_tether_starting">Turning hotspot on\u2026</string>
diff --git a/res/xml/accounts_work_dashboard_settings_credman.xml b/res/xml/accounts_work_dashboard_settings_credman.xml
index 1559476..2946a21 100644
--- a/res/xml/accounts_work_dashboard_settings_credman.xml
+++ b/res/xml/accounts_work_dashboard_settings_credman.xml
@@ -22,9 +22,9 @@
android:title="@string/account_dashboard_title"
settings:keywords="@string/keywords_accounts">
- <com.android.settings.widget.WorkOnlyCategory
- android:key="autofill_work_app_defaults"
- android:order="30"
+ <PreferenceCategory
+ android:key="default_service_category"
+ android:order="10"
android:title="@string/default_autofill_app">
<com.android.settings.widget.GearPreference
@@ -36,11 +36,11 @@
android:name="for_work"
android:value="true" />
</com.android.settings.widget.GearPreference>
- </com.android.settings.widget.WorkOnlyCategory>
+ </PreferenceCategory>
<PreferenceCategory
android:key="credman_category"
- android:order="20"
+ android:order="50"
android:persistent="false"
android:title="@string/credman_credentials"
settings:controller="com.android.settings.applications.credentials.CredentialManagerPreferenceController"
diff --git a/res/xml/wifi_hotspot_speed.xml b/res/xml/wifi_hotspot_speed.xml
new file mode 100644
index 0000000..b19a5b9
--- /dev/null
+++ b/res/xml/wifi_hotspot_speed.xml
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ 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.
+ -->
+<PreferenceScreen
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:settings="http://schemas.android.com/apk/res-auto"
+ android:title="@string/wifi_hotspot_speed_title"
+ settings:searchable="false">
+
+ <com.android.settingslib.widget.TopIntroPreference
+ android:key="wifi_hotspot_speed_intro"
+ android:title="@string/wifi_hotspot_speed_intro"/>
+
+ <PreferenceCategory
+ android:key="wifi_hotspot_speed"
+ android:title="@string/wifi_hotspot_speed_category">
+
+ <com.android.settingslib.widget.SelectorWithWidgetPreference
+ android:key="wifi_hotspot_speed_2g"
+ android:title="@string/wifi_hotspot_speed_2g"
+ android:summary="@string/wifi_hotspot_speed_2g_summary"
+ android:visibility="gone"/>
+
+ <com.android.settingslib.widget.SelectorWithWidgetPreference
+ android:key="wifi_hotspot_speed_5g"
+ android:title="@string/wifi_hotspot_speed_5g"
+ android:summary="@string/wifi_hotspot_speed_5g_summary"
+ android:visibility="gone"/>
+
+ <com.android.settingslib.widget.SelectorWithWidgetPreference
+ android:key="wifi_hotspot_speed_2g_5g"
+ android:title="@string/wifi_hotspot_speed_2g_5g"
+ android:summary="@string/wifi_hotspot_speed_2g_5g_summary"/>
+
+ <com.android.settingslib.widget.SelectorWithWidgetPreference
+ android:key="wifi_hotspot_speed_6g"
+ android:title="@string/wifi_hotspot_speed_6g"
+ android:summary="@string/wifi_hotspot_speed_6g_summary"/>
+ </PreferenceCategory>
+
+ <com.android.settingslib.widget.FooterPreference
+ android:key="wifi_hotspot_speed__footer"
+ android:title="@string/wifi_hotspot_speed_footer"
+ android:selectable="false"/>
+</PreferenceScreen>
+
+
+
diff --git a/res/xml/wifi_tether_settings.xml b/res/xml/wifi_tether_settings.xml
index 1cd5f48..3023a6e 100644
--- a/res/xml/wifi_tether_settings.xml
+++ b/res/xml/wifi_tether_settings.xml
@@ -50,5 +50,6 @@
android:key="wifi_hotspot_speed"
android:title="@string/wifi_hotspot_speed_title"
android:summary="@string/summary_placeholder"
+ android:fragment="com.android.settings.wifi.tether.WifiHotspotSpeedSettings"
settings:isPreferenceVisible="@bool/config_show_wifi_hotspot_speed"/>
</PreferenceScreen>
diff --git a/src/com/android/settings/bluetooth/HearingDeviceCallRoutingPreferenceController.java b/src/com/android/settings/bluetooth/HearingDeviceCallRoutingPreferenceController.java
index ea5ba8b..4e5e193 100644
--- a/src/com/android/settings/bluetooth/HearingDeviceCallRoutingPreferenceController.java
+++ b/src/com/android/settings/bluetooth/HearingDeviceCallRoutingPreferenceController.java
@@ -19,6 +19,7 @@
import android.content.Context;
import android.provider.Settings;
+import com.android.settings.Utils;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.HearingAidAudioRoutingConstants;
@@ -44,6 +45,11 @@
}
@Override
+ public int getAvailabilityStatus() {
+ return Utils.isVoiceCapable(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
+ }
+
+ @Override
protected int[] getSupportedAttributeList() {
return HearingAidAudioRoutingConstants.CALL_ROUTING_ATTRIBUTES;
}
diff --git a/src/com/android/settings/datausage/DataUsageList.java b/src/com/android/settings/datausage/DataUsageList.java
index 68751e5..b1661e1 100644
--- a/src/com/android/settings/datausage/DataUsageList.java
+++ b/src/com/android/settings/datausage/DataUsageList.java
@@ -58,15 +58,20 @@
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.datausage.CycleAdapter.SpinnerInterface;
import com.android.settings.network.MobileDataEnabledListener;
+import com.android.settings.network.MobileNetworkRepository;
import com.android.settings.network.ProxySubscriptionManager;
import com.android.settings.widget.LoadingViewController;
import com.android.settingslib.AppItem;
+import com.android.settingslib.mobile.dataservice.SubscriptionInfoEntity;
import com.android.settingslib.net.NetworkCycleChartData;
import com.android.settingslib.net.NetworkCycleChartDataLoader;
import com.android.settingslib.net.NetworkStatsSummaryLoader;
+import com.android.settingslib.net.UidDetail;
import com.android.settingslib.net.UidDetailProvider;
+import com.android.settingslib.utils.ThreadUtils;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
@@ -118,6 +123,8 @@
private Preference mUsageAmount;
private PreferenceGroup mApps;
private View mHeader;
+ private MobileNetworkRepository mMobileNetworkRepository;
+ private SubscriptionInfoEntity mSubscriptionInfoEntity;
@Override
public int getMetricsCategory() {
@@ -146,6 +153,11 @@
}
processArgument();
+ mMobileNetworkRepository = MobileNetworkRepository.getInstance(getContext());
+ ThreadUtils.postOnBackgroundThread(() -> {
+ mSubscriptionInfoEntity = mMobileNetworkRepository.getSubInfoById(
+ String.valueOf(mSubId));
+ });
mDataStateListener = new MobileDataEnabledListener(activity, this);
}
@@ -451,7 +463,23 @@
}
Collections.sort(items);
+ final List<String> packageNames = Arrays.asList(getContext().getResources().getStringArray(
+ R.array.datausage_hiding_carrier_service_package_names));
+ boolean shouldHidePackageName = mSubscriptionInfoEntity != null
+ ? Arrays.stream(getContext().getResources().getIntArray(
+ R.array.datausage_hiding_carrier_service_carrier_id))
+ .anyMatch(carrierId -> (carrierId == mSubscriptionInfoEntity.carrierId))
+ : false;
+
for (int i = 0; i < items.size(); i++) {
+ UidDetail detail = mUidDetailProvider.getUidDetail(items.get(i).key, true);
+ // Do not show carrier service package in data usage list if it should be hidden for
+ // the carrier.
+ if (detail != null && shouldHidePackageName && packageNames.contains(
+ detail.packageName)) {
+ continue;
+ }
+
final int percentTotal = largest != 0 ? (int) (items.get(i).total * 100 / largest) : 0;
final AppDataUsagePreference preference = new AppDataUsagePreference(getContext(),
items.get(i), percentTotal, mUidDetailProvider);
diff --git a/src/com/android/settings/fuelgauge/batteryusage/BatteryHistEntry.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryHistEntry.java
index 2cfb526..827f0fc 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/BatteryHistEntry.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryHistEntry.java
@@ -204,8 +204,7 @@
@Override
public String toString() {
- final String recordAtDateTime =
- ConvertUtils.utcToLocalTime(/*context=*/ null, mTimestamp);
+ final String recordAtDateTime = ConvertUtils.utcToLocalTimeForLogging(mTimestamp);
final StringBuilder builder = new StringBuilder()
.append("\nBatteryHistEntry{")
.append(String.format("\n\tpackage=%s|label=%s|uid=%d|userId=%d|isHidden=%b",
diff --git a/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageBroadcastReceiver.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageBroadcastReceiver.java
index 9c7ec35..a437877 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageBroadcastReceiver.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageBroadcastReceiver.java
@@ -54,11 +54,13 @@
if (intent == null || intent.getAction() == null) {
return;
}
- Log.d(TAG, "onReceive:" + intent.getAction());
+ final String action = intent.getAction();
+ Log.d(TAG, "onReceive:" + action);
+ DatabaseUtils.recordDateTime(context, action);
final String fullChargeIntentAction = FeatureFactory.getFactory(context)
.getPowerUsageFeatureProvider(context)
.getFullChargeIntentAction();
- switch (intent.getAction()) {
+ switch (action) {
case Intent.ACTION_BATTERY_LEVEL_CHANGED:
// Only when fullChargeIntentAction is ACTION_BATTERY_LEVEL_CHANGED,
// ACTION_BATTERY_LEVEL_CHANGED will be considered as the full charge event and then
diff --git a/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageDataLoader.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageDataLoader.java
index d446bb2..fb1be3e 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageDataLoader.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageDataLoader.java
@@ -57,6 +57,10 @@
}
final long elapsedTime = System.currentTimeMillis() - start;
Log.d(TAG, String.format("getBatteryUsageStats() in %d/ms", elapsedTime));
+ if (isFullChargeStart) {
+ DatabaseUtils.recordDateTime(
+ context, DatabaseUtils.KEY_LAST_LOAD_FULL_CHARGE_TIME);
+ }
// Uploads the BatteryEntry data into database.
DatabaseUtils.sendBatteryEntryData(
diff --git a/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageStatsLoader.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageStatsLoader.java
index d61b276..7f112ae 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageStatsLoader.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageStatsLoader.java
@@ -45,7 +45,8 @@
builder.includeBatteryHistory();
}
try {
- return mBatteryStatsManager.getBatteryUsageStats(builder.build());
+ return mBatteryStatsManager.getBatteryUsageStats(
+ builder.includeProcessStateData().build());
} catch (RuntimeException e) {
Log.e(TAG, "loadInBackground() for getBatteryUsageStats()", e);
// Use default BatteryUsageStats.
diff --git a/src/com/android/settings/fuelgauge/batteryusage/BootBroadcastReceiver.java b/src/com/android/settings/fuelgauge/batteryusage/BootBroadcastReceiver.java
index 8c9285e..64b5b77 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/BootBroadcastReceiver.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BootBroadcastReceiver.java
@@ -61,8 +61,6 @@
switch (action) {
case Intent.ACTION_BOOT_COMPLETED:
- case Intent.ACTION_MY_PACKAGE_REPLACED:
- case Intent.ACTION_MY_PACKAGE_UNSUSPENDED:
case ACTION_SETUP_WIZARD_FINISHED:
case ACTION_PERIODIC_JOB_RECHECK:
Log.d(TAG, "refresh periodic job from action=" + action);
diff --git a/src/com/android/settings/fuelgauge/batteryusage/ConvertUtils.java b/src/com/android/settings/fuelgauge/batteryusage/ConvertUtils.java
index c1b7818..fcf934f 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/ConvertUtils.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/ConvertUtils.java
@@ -237,9 +237,10 @@
return eventBuilder.build();
}
- /** Converts UTC timestamp to human readable local time string. */
- public static String utcToLocalTime(Context context, long timestamp) {
- final Locale locale = getLocale(context);
+ /** Converts UTC timestamp to local time string for logging only, so use the US locale for
+ * better readability in debugging. */
+ public static String utcToLocalTimeForLogging(long timestamp) {
+ final Locale locale = Locale.US;
final String pattern =
DateFormat.getBestDateTimePattern(locale, "MMM dd,yyyy HH:mm:ss");
return DateFormat.format(pattern, timestamp).toString();
diff --git a/src/com/android/settings/fuelgauge/batteryusage/DataProcessor.java b/src/com/android/settings/fuelgauge/batteryusage/DataProcessor.java
index 338cb11..38d4e69 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/DataProcessor.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/DataProcessor.java
@@ -17,7 +17,6 @@
package com.android.settings.fuelgauge.batteryusage;
import static com.android.settings.fuelgauge.batteryusage.ConvertUtils.getEffectivePackageName;
-import static com.android.settings.fuelgauge.batteryusage.ConvertUtils.utcToLocalTime;
import android.app.usage.IUsageStatsManager;
import android.app.usage.UsageEvents;
@@ -1357,7 +1356,7 @@
final Map<String, BatteryHistEntry> entryMap = processedBatteryHistoryMap.get(timestamp);
if (entryMap == null || entryMap.isEmpty()) {
Log.e(TAG, "abnormal entry list in the timestamp:"
- + utcToLocalTime(context, timestamp));
+ + ConvertUtils.utcToLocalTimeForLogging(timestamp));
return null;
}
// The current time battery history hasn't been loaded yet, returns the current battery
@@ -1934,7 +1933,7 @@
final BatteryHistEntry entry) {
if (sDebug) {
Log.d(TAG, String.format(entry != null ? "%s %s:\n%s" : "%s %s:%s",
- utcToLocalTime(context, timestamp), content, entry));
+ ConvertUtils.utcToLocalTimeForLogging(timestamp), content, entry));
}
}
}
diff --git a/src/com/android/settings/fuelgauge/batteryusage/DatabaseUtils.java b/src/com/android/settings/fuelgauge/batteryusage/DatabaseUtils.java
index 655114f..ef1434c 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/DatabaseUtils.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/DatabaseUtils.java
@@ -19,6 +19,7 @@
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
+import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.Uri;
@@ -37,6 +38,7 @@
import com.android.settings.fuelgauge.batteryusage.db.BatteryStateDatabase;
import com.android.settingslib.fuelgauge.BatteryStatus;
+import java.io.PrintWriter;
import java.time.Clock;
import java.time.Duration;
import java.util.ArrayList;
@@ -50,12 +52,15 @@
/** A utility class to operate battery usage database. */
public final class DatabaseUtils {
private static final String TAG = "DatabaseUtils";
+ private static final String SHARED_PREFS_FILE = "battery_usage_shared_prefs";
+
/** Clear memory threshold for device booting phase. **/
private static final long CLEAR_MEMORY_THRESHOLD_MS = Duration.ofMinutes(5).toMillis();
private static final long CLEAR_MEMORY_DELAYED_MS = Duration.ofSeconds(2).toMillis();
- @VisibleForTesting
static final int DATA_RETENTION_INTERVAL_DAY = 9;
+ static final String KEY_LAST_LOAD_FULL_CHARGE_TIME = "last_load_full_charge_time";
+ static final String KEY_LAST_UPLOAD_FULL_CHARGE_TIME = "last_upload_full_charge_time";
/** An authority name of the battery content provider. */
public static final String AUTHORITY = "com.android.settings.battery.usage.provider";
@@ -126,9 +131,10 @@
.build();
final long latestTimestamp =
loadAppUsageLatestTimestampFromContentProvider(context, appUsageLatestTimestampUri);
+ final String latestTimestampString = ConvertUtils.utcToLocalTimeForLogging(latestTimestamp);
Log.d(TAG, String.format(
- "getAppUsageStartTimestampOfUser() userId=%d latestTimestamp=%d in %d/ms",
- userId, latestTimestamp, (System.currentTimeMillis() - startTime)));
+ "getAppUsageStartTimestampOfUser() userId=%d latestTimestamp=%s in %d/ms",
+ userId, latestTimestampString, (System.currentTimeMillis() - startTime)));
// Use (latestTimestamp + 1) here to avoid loading the events of the latestTimestamp
// repeatedly.
return Math.max(latestTimestamp + 1, earliestTimestamp);
@@ -146,7 +152,8 @@
// sure the app usage calculation near the boundaries is correct.
final long queryTimestamp =
Math.max(rawStartTimestamp, sixDaysAgoTimestamp) - USAGE_QUERY_BUFFER_HOURS;
- Log.d(TAG, "sixDayAgoTimestamp: " + sixDaysAgoTimestamp);
+ Log.d(TAG, "sixDayAgoTimestamp: " + ConvertUtils.utcToLocalTimeForLogging(
+ sixDaysAgoTimestamp));
final String queryUserIdString = userIds.stream()
.map(userId -> String.valueOf(userId))
.collect(Collectors.joining(","));
@@ -174,7 +181,8 @@
Context context, Calendar calendar) {
final long startTime = System.currentTimeMillis();
final long sixDaysAgoTimestamp = getTimestampSixDaysAgo(calendar);
- Log.d(TAG, "sixDayAgoTimestamp: " + sixDaysAgoTimestamp);
+ Log.d(TAG, "sixDayAgoTimestamp: " + ConvertUtils.utcToLocalTimeForLogging(
+ sixDaysAgoTimestamp));
// Builds the content uri everytime to avoid cache.
final Uri batteryStateUri =
new Uri.Builder()
@@ -373,10 +381,50 @@
resolver.notifyChange(BATTERY_CONTENT_URI, /*observer=*/ null);
Log.d(TAG, String.format("sendBatteryEntryData() size=%d in %d/ms",
size, (System.currentTimeMillis() - startTime)));
+ if (isFullChargeStart) {
+ recordDateTime(context, KEY_LAST_UPLOAD_FULL_CHARGE_TIME);
+ }
clearMemory();
return valuesList;
}
+ /** Dump all required data into {@link PrintWriter}. */
+ public static void dump(Context context, PrintWriter writer) {
+ writeString(context, writer, "BatteryLevelChanged",
+ Intent.ACTION_BATTERY_LEVEL_CHANGED);
+ writeString(context, writer, "BatteryUnplugging",
+ BatteryUsageBroadcastReceiver.ACTION_BATTERY_UNPLUGGING);
+ writeString(context, writer, "ClearBatteryCacheData",
+ BatteryUsageBroadcastReceiver.ACTION_CLEAR_BATTERY_CACHE_DATA);
+ writeString(context, writer, "LastLoadFullChargeTime",
+ KEY_LAST_LOAD_FULL_CHARGE_TIME);
+ writeString(context, writer, "LastUploadFullChargeTime",
+ KEY_LAST_UPLOAD_FULL_CHARGE_TIME);
+ }
+
+ static SharedPreferences getSharedPreferences(Context context) {
+ return context.getApplicationContext().getSharedPreferences(
+ SHARED_PREFS_FILE, Context.MODE_PRIVATE);
+ }
+
+ static void recordDateTime(Context context, String preferenceKey) {
+ final SharedPreferences sharedPreferences = getSharedPreferences(context);
+ if (sharedPreferences != null) {
+ final String currentTime = ConvertUtils.utcToLocalTimeForLogging(
+ System.currentTimeMillis());
+ sharedPreferences.edit().putString(preferenceKey, currentTime).apply();
+ }
+ }
+
+ private static void writeString(
+ Context context, PrintWriter writer, String prefix, String key) {
+ final SharedPreferences sharedPreferences = getSharedPreferences(context);
+ if (sharedPreferences != null) {
+ final String content = sharedPreferences.getString(key, "");
+ writer.println(String.format("\t\t%s: %s", prefix, content));
+ }
+ }
+
private static long loadAppUsageLatestTimestampFromContentProvider(
Context context, final Uri appUsageLatestTimestampUri) {
// We have already make sure the context here is with profile parent's user identity. Don't
diff --git a/src/com/android/settings/fuelgauge/batteryusage/PeriodicJobManager.java b/src/com/android/settings/fuelgauge/batteryusage/PeriodicJobManager.java
index 2b18e92..3d78c00 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/PeriodicJobManager.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/PeriodicJobManager.java
@@ -26,11 +26,8 @@
import com.android.settings.overlay.FeatureFactory;
-import java.text.SimpleDateFormat;
import java.time.Clock;
import java.time.Duration;
-import java.util.Date;
-import java.util.Locale;
/** Manages the periodic job to schedule or cancel the next job. */
public final class PeriodicJobManager {
@@ -41,8 +38,6 @@
private final Context mContext;
private final AlarmManager mAlarmManager;
- private final SimpleDateFormat mSimpleDateFormat =
- new SimpleDateFormat("MMM dd,yyyy HH:mm:ss", Locale.ENGLISH);
@VisibleForTesting
static final int DATA_FETCH_INTERVAL_MINUTE = 60;
@@ -69,7 +64,6 @@
}
/** Schedules the next alarm job if it is available. */
- @SuppressWarnings("JavaUtilDate")
public void refreshJob(final boolean fromBoot) {
if (mAlarmManager == null) {
Log.e(TAG, "cannot schedule next alarm job");
@@ -83,7 +77,7 @@
mAlarmManager.setExactAndAllowWhileIdle(
AlarmManager.RTC_WAKEUP, triggerAtMillis, pendingIntent);
Log.d(TAG, "schedule next alarm job at "
- + mSimpleDateFormat.format(new Date(triggerAtMillis)));
+ + ConvertUtils.utcToLocalTimeForLogging(triggerAtMillis));
}
void cancelJob(PendingIntent pendingIntent) {
diff --git a/src/com/android/settings/fuelgauge/batteryusage/bugreport/LogUtils.java b/src/com/android/settings/fuelgauge/batteryusage/bugreport/LogUtils.java
index 8215839..9be378b 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/bugreport/LogUtils.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/bugreport/LogUtils.java
@@ -19,6 +19,8 @@
import android.content.Context;
import android.util.Log;
+import com.android.settings.fuelgauge.batteryusage.ConvertUtils;
+import com.android.settings.fuelgauge.batteryusage.DatabaseUtils;
import com.android.settings.fuelgauge.batteryusage.db.AppUsageEventDao;
import com.android.settings.fuelgauge.batteryusage.db.AppUsageEventEntity;
import com.android.settings.fuelgauge.batteryusage.db.BatteryState;
@@ -26,12 +28,9 @@
import com.android.settings.fuelgauge.batteryusage.db.BatteryStateDatabase;
import java.io.PrintWriter;
-import java.text.SimpleDateFormat;
import java.time.Clock;
import java.time.Duration;
-import java.util.Date;
import java.util.List;
-import java.util.Locale;
/** A utility class to aggregate and provide required log data. */
public final class LogUtils {
@@ -39,8 +38,9 @@
private static final Duration DUMP_TIME_OFFSET = Duration.ofHours(24);
private static final Duration DUMP_TIME_OFFSET_FOR_ENTRY = Duration.ofHours(4);
- @SuppressWarnings("JavaUtilDate")
static void dumpBatteryUsageDatabaseHist(Context context, PrintWriter writer) {
+ DatabaseUtils.dump(context, writer);
+ writer.flush();
final BatteryStateDao dao =
BatteryStateDatabase
.getInstance(context.getApplicationContext())
@@ -57,20 +57,18 @@
return;
}
// Dumps all distinct timestamps.
- final SimpleDateFormat formatter =
- new SimpleDateFormat("MMM dd, HH:mm:ss", Locale.US);
timestamps.forEach(timestamp -> {
- final String formattedTimestamp = formatter.format(new Date(timestamp));
+ final String formattedTimestamp = ConvertUtils.utcToLocalTimeForLogging(timestamp);
writer.println("\t" + formattedTimestamp);
Log.w(TAG, "\t" + formattedTimestamp);
});
+ writer.flush();
final List<BatteryState> stateList = dao.getAllAfter(
Clock.systemUTC().millis() - DUMP_TIME_OFFSET_FOR_ENTRY.toMillis());
stateList.stream().forEach(state -> writer.println(state));
}
- @SuppressWarnings("JavaUtilDate")
static void dumpAppUsageDatabaseHist(Context context, PrintWriter writer) {
final AppUsageEventDao dao =
BatteryStateDatabase
@@ -80,6 +78,7 @@
final List<AppUsageEventEntity> eventList = dao.getAllAfter(
Clock.systemUTC().millis() - DUMP_TIME_OFFSET_FOR_ENTRY.toMillis());
eventList.stream().forEach(event -> writer.println(event));
+ writer.flush();
}
private LogUtils() {}
diff --git a/src/com/android/settings/fuelgauge/batteryusage/db/AppUsageEventEntity.java b/src/com/android/settings/fuelgauge/batteryusage/db/AppUsageEventEntity.java
index 9d62d07..c08c735 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/db/AppUsageEventEntity.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/db/AppUsageEventEntity.java
@@ -21,19 +21,15 @@
import androidx.room.Entity;
import androidx.room.PrimaryKey;
+import com.android.settings.fuelgauge.batteryusage.ConvertUtils;
+
import com.google.errorprone.annotations.CanIgnoreReturnValue;
-import java.text.SimpleDateFormat;
-import java.util.Date;
import java.util.Locale;
-import java.util.TimeZone;
/** A {@link Entity} class to save app usage events into database. */
@Entity
public class AppUsageEventEntity {
- private static String sCacheZoneId;
- private static SimpleDateFormat sCacheSimpleDateFormat;
-
/** Keys for accessing {@link ContentValues}. */
public static final String KEY_UID = "uid";
public static final String KEY_USER_ID = "userId";
@@ -83,14 +79,8 @@
}
@Override
- @SuppressWarnings("JavaUtilDate")
public String toString() {
- final String currentZoneId = TimeZone.getDefault().getID();
- if (!currentZoneId.equals(sCacheZoneId) || sCacheSimpleDateFormat == null) {
- sCacheZoneId = currentZoneId;
- sCacheSimpleDateFormat = new SimpleDateFormat("MMM dd,yyyy HH:mm:ss", Locale.US);
- }
- final String recordAtDateTime = sCacheSimpleDateFormat.format(new Date(timestamp));
+ final String recordAtDateTime = ConvertUtils.utcToLocalTimeForLogging(timestamp);
final StringBuilder builder = new StringBuilder()
.append("\nAppUsageEvent{")
.append(String.format(Locale.US,
diff --git a/src/com/android/settings/fuelgauge/batteryusage/db/BatteryState.java b/src/com/android/settings/fuelgauge/batteryusage/db/BatteryState.java
index 9139c10..190c274 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/db/BatteryState.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/db/BatteryState.java
@@ -23,20 +23,15 @@
import com.android.settings.fuelgauge.BatteryUtils;
import com.android.settings.fuelgauge.batteryusage.BatteryInformation;
+import com.android.settings.fuelgauge.batteryusage.ConvertUtils;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
-import java.text.SimpleDateFormat;
-import java.util.Date;
import java.util.Locale;
-import java.util.TimeZone;
/** A {@link Entity} class to save battery states snapshot into database. */
@Entity
public class BatteryState {
- private static String sCacheZoneId;
- private static SimpleDateFormat sCacheSimpleDateFormat;
-
@PrimaryKey(autoGenerate = true)
private long mId;
@@ -91,14 +86,8 @@
}
@Override
- @SuppressWarnings("JavaUtilDate")
public String toString() {
- final String currentZoneId = TimeZone.getDefault().getID();
- if (!currentZoneId.equals(sCacheZoneId) || sCacheSimpleDateFormat == null) {
- sCacheZoneId = currentZoneId;
- sCacheSimpleDateFormat = new SimpleDateFormat("MMM dd,yyyy HH:mm:ss", Locale.US);
- }
- final String recordAtDateTime = sCacheSimpleDateFormat.format(new Date(timestamp));
+ final String recordAtDateTime = ConvertUtils.utcToLocalTimeForLogging(timestamp);
final BatteryInformation batteryInformationInstance =
BatteryUtils.parseProtoFromString(
batteryInformation, BatteryInformation.getDefaultInstance());
diff --git a/src/com/android/settings/network/telephony/MobileNetworkSettings.java b/src/com/android/settings/network/telephony/MobileNetworkSettings.java
index 0f2d02bf..ce83053 100644
--- a/src/com/android/settings/network/telephony/MobileNetworkSettings.java
+++ b/src/com/android/settings/network/telephony/MobileNetworkSettings.java
@@ -489,7 +489,7 @@
Iterator<Integer> iterator = mSubscriptionInfoMap.keySet().iterator();
while (iterator.hasNext()) {
- if (iterator.next() == mSubId) {
+ if (iterator.next() == mSubId && getActivity() != null) {
finishFragment();
return;
}
diff --git a/src/com/android/settings/notification/SilentStatusBarPreferenceController.java b/src/com/android/settings/notification/SilentStatusBarPreferenceController.java
index 4c4c99d..d8c856e 100644
--- a/src/com/android/settings/notification/SilentStatusBarPreferenceController.java
+++ b/src/com/android/settings/notification/SilentStatusBarPreferenceController.java
@@ -17,6 +17,7 @@
package com.android.settings.notification;
import android.content.Context;
+import android.os.UserManager;
import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
@@ -51,7 +52,7 @@
@Override
public int getAvailabilityStatus() {
- return AVAILABLE;
+ return UserManager.get(mContext).isGuestUser() ? DISABLED_FOR_USER : AVAILABLE;
}
@Override
diff --git a/src/com/android/settings/wifi/factory/WifiFeatureProvider.java b/src/com/android/settings/wifi/factory/WifiFeatureProvider.java
index 433ff0c..ea15c43 100644
--- a/src/com/android/settings/wifi/factory/WifiFeatureProvider.java
+++ b/src/com/android/settings/wifi/factory/WifiFeatureProvider.java
@@ -16,14 +16,17 @@
package com.android.settings.wifi.factory;
+import android.annotation.Nullable;
import android.content.Context;
import android.net.wifi.WifiManager;
+import android.util.Log;
import androidx.annotation.NonNull;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelStoreOwner;
import com.android.settings.wifi.repository.WifiHotspotRepository;
+import com.android.settings.wifi.tether.WifiHotspotSpeedViewModel;
import com.android.settings.wifi.tether.WifiTetherViewModel;
import org.jetbrains.annotations.NotNull;
@@ -32,9 +35,11 @@
* Wi-Fi Feature Provider
*/
public class WifiFeatureProvider {
+ private static final String TAG = "WifiFeatureProvider";
private final Context mAppContext;
private WifiManager mWifiManager;
+ private WifiVerboseLogging mWifiVerboseLogging;
private WifiHotspotRepository mWifiHotspotRepository;
public WifiFeatureProvider(@NonNull Context appContext) {
@@ -52,11 +57,22 @@
}
/**
- * Get WifiRepository
+ * Get WifiVerboseLogging
+ */
+ public WifiVerboseLogging getWifiVerboseLogging() {
+ if (mWifiVerboseLogging == null) {
+ mWifiVerboseLogging = new WifiVerboseLogging(mAppContext, getWifiManager());
+ }
+ return mWifiVerboseLogging;
+ }
+
+ /**
+ * Get WifiHotspotRepository
*/
public WifiHotspotRepository getWifiHotspotRepository() {
if (mWifiHotspotRepository == null) {
mWifiHotspotRepository = new WifiHotspotRepository(mAppContext, getWifiManager());
+ verboseLog(TAG, "getWifiHotspotRepository():" + mWifiHotspotRepository);
}
return mWifiHotspotRepository;
}
@@ -68,5 +84,26 @@
return new ViewModelProvider(owner).get(WifiTetherViewModel.class);
}
+ /**
+ * Get WifiHotspotSpeedViewModel
+ */
+ public WifiHotspotSpeedViewModel getWifiHotspotSpeedViewModel(
+ @NotNull ViewModelStoreOwner owner) {
+ WifiHotspotSpeedViewModel viewModel =
+ new ViewModelProvider(owner).get(WifiHotspotSpeedViewModel.class);
+ verboseLog(TAG, "getWifiHotspotSpeedViewModel():" + viewModel);
+ return viewModel;
+ }
+
+ /**
+ * Send a {@link Log#VERBOSE} log message.
+ *
+ * @param tag Used to identify the source of a log message. It usually identifies
+ * the class or activity where the log call occurs.
+ * @param msg The message you would like logged.
+ */
+ public void verboseLog(@Nullable String tag, @NonNull String msg) {
+ getWifiVerboseLogging().log(tag, msg);
+ }
}
diff --git a/src/com/android/settings/wifi/factory/WifiVerboseLogging.java b/src/com/android/settings/wifi/factory/WifiVerboseLogging.java
new file mode 100644
index 0000000..2935ed4
--- /dev/null
+++ b/src/com/android/settings/wifi/factory/WifiVerboseLogging.java
@@ -0,0 +1,55 @@
+/*
+ * 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.wifi.factory;
+
+import android.annotation.Nullable;
+import android.content.Context;
+import android.net.wifi.WifiManager;
+import android.util.Log;
+
+import androidx.annotation.NonNull;
+
+/**
+ * Wi-Fi Verbose Logging
+ */
+public class WifiVerboseLogging {
+ private static final String TAG = "WifiVerboseLogging";
+
+ protected final Context mAppContext;
+ protected final WifiManager mWifiManager;
+ protected final boolean mIsVerboseLoggingEnabled;
+
+ public WifiVerboseLogging(@NonNull Context appContext, @NonNull WifiManager wifiManager) {
+ mAppContext = appContext;
+ mWifiManager = wifiManager;
+ mIsVerboseLoggingEnabled = wifiManager.isVerboseLoggingEnabled();
+ Log.v(TAG, "isVerboseLoggingEnabled:" + mIsVerboseLoggingEnabled);
+ }
+
+ /**
+ * Send a {@link Log#VERBOSE} log message.
+ *
+ * @param tag Used to identify the source of a log message. It usually identifies
+ * the class or activity where the log call occurs.
+ * @param msg The message you would like logged.
+ */
+ public void log(@Nullable String tag, @NonNull String msg) {
+ if (mIsVerboseLoggingEnabled) {
+ Log.v(tag, msg);
+ }
+ }
+}
diff --git a/src/com/android/settings/wifi/repository/WifiHotspotRepository.java b/src/com/android/settings/wifi/repository/WifiHotspotRepository.java
index ee1ceea..ff6d883 100644
--- a/src/com/android/settings/wifi/repository/WifiHotspotRepository.java
+++ b/src/com/android/settings/wifi/repository/WifiHotspotRepository.java
@@ -32,7 +32,8 @@
import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
-import androidx.lifecycle.Transformations;
+
+import com.android.settings.overlay.FeatureFactory;
import java.util.HashMap;
import java.util.List;
@@ -45,7 +46,6 @@
*/
public class WifiHotspotRepository {
private static final String TAG = "WifiHotspotRepository";
- private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
/** Wi-Fi hotspot band unknown. */
public static final int BAND_UNKNOWN = 0;
@@ -84,8 +84,12 @@
protected MutableLiveData<Integer> mSpeedType;
protected Boolean mIsDualBand;
+ protected Boolean mIs5gBandSupported;
protected Boolean mIs5gAvailable;
+ protected MutableLiveData<Boolean> m5gAvailable;
+ protected Boolean mIs6gBandSupported;
protected Boolean mIs6gAvailable;
+ protected MutableLiveData<Boolean> m6gAvailable;
protected String mCurrentCountryCode;
protected ActiveCountryCodeChangedCallback mActiveCountryCodeChangedCallback;
@@ -140,6 +144,8 @@
* Refresh data from the SoftApConfiguration.
*/
public void refresh() {
+ update6gAvailable();
+ update5gAvailable();
updateSpeedType();
}
@@ -163,8 +169,9 @@
if (mSpeedType == null) {
mSpeedType = new MutableLiveData<>();
updateSpeedType();
+ log("getSpeedType():" + mSpeedType.getValue());
}
- return Transformations.distinctUntilChanged(mSpeedType);
+ return mSpeedType;
}
protected void updateSpeedType() {
@@ -177,7 +184,7 @@
return;
}
int keyBand = config.getBand();
- logd("updateSpeedType(), getBand():" + keyBand);
+ log("updateSpeedType(), getBand():" + keyBand);
if (!is5gAvailable()) {
keyBand &= ~BAND_5GHZ;
}
@@ -195,52 +202,172 @@
} else {
keyBand = 0;
}
- logd("updateSpeedType(), keyBand:" + keyBand);
+ log("updateSpeedType(), keyBand:" + keyBand);
mSpeedType.setValue(sSpeedMap.get(keyBand));
}
- protected boolean isDualBand() {
+ /**
+ * Sets SpeedType
+ *
+ * @param speedType the Wi-Fi hotspot speed type.
+ */
+ public void setSpeedType(int speedType) {
+ log("setSpeedType():" + speedType);
+ if (mSpeedType == null) {
+ getSpeedType();
+ }
+ if (speedType == mSpeedType.getValue()) {
+ Log.w(TAG, "setSpeedType() is no changed! mSpeedType:" + mSpeedType.getValue());
+ return;
+ }
+ SoftApConfiguration config = mWifiManager.getSoftApConfiguration();
+ if (config == null) {
+ mSpeedType.setValue(SPEED_UNKNOWN);
+ Log.e(TAG, "setSpeedType(), WifiManager#getSoftApConfiguration() return null!");
+ return;
+ }
+ SoftApConfiguration.Builder configBuilder = new SoftApConfiguration.Builder(config);
+ if (speedType == SPEED_6GHZ) {
+ log("setSpeedType(), setBand(BAND_2GHZ_5GHZ_6GHZ)");
+ configBuilder.setBand(BAND_2GHZ_5GHZ_6GHZ);
+ } else if (speedType == SPEED_5GHZ) {
+ log("setSpeedType(), setBand(BAND_2GHZ_5GHZ)");
+ configBuilder.setBand(BAND_2GHZ_5GHZ);
+ } else if (mIsDualBand) {
+ log("setSpeedType(), setBands(BAND_2GHZ + BAND_2GHZ_5GHZ)");
+ int[] bands = {BAND_2GHZ, BAND_2GHZ_5GHZ};
+ configBuilder.setBands(bands);
+ } else {
+ log("setSpeedType(), setBand(BAND_2GHZ)");
+ configBuilder.setBand(BAND_2GHZ);
+ }
+ setSoftApConfiguration(configBuilder.build());
+ }
+
+ /**
+ * Return whether Wi-Fi Dual Band is supported or not.
+ * @return {@code true} if Wi-Fi Dual Band is supported
+ */
+ public boolean isDualBand() {
if (mIsDualBand == null) {
mIsDualBand = mWifiManager.isBridgedApConcurrencySupported();
- logd("isDualBand():" + mIsDualBand);
+ log("isDualBand():" + mIsDualBand);
}
return mIsDualBand;
}
- protected boolean is5gAvailable() {
+ /**
+ * 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() {
+ if (mIs5gBandSupported == null) {
+ mIs5gBandSupported = mWifiManager.is5GHzBandSupported();
+ log("is5GHzBandSupported():" + mIs5gBandSupported);
+ }
+ return mIs5gBandSupported;
+ }
+
+ /**
+ * 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() {
if (mIs5gAvailable == null) {
- // TODO(b/272450463): isBandAvailable(WifiScanner.WIFI_BAND_5_GHZ_WITH_DFS) will
- // cause crash in the old model device, use a simple check to workaround it first.
- mIs5gAvailable = (mWifiManager.is5GHzBandSupported() && mCurrentCountryCode != null);
- logd("is5gAvailable():" + mIs5gAvailable);
+ // If Settings is unable to get available 5GHz SAP information, Wi-Fi Framework's
+ // proposal is to assume that 5GHz is available. (See b/272450463#comment16)
+ mIs5gAvailable = is5GHzBandSupported()
+ && isChannelAvailable(WifiScanner.WIFI_BAND_5_GHZ_WITH_DFS,
+ true /* defaultValue */);
+ log("is5gAvailable():" + mIs5gAvailable);
}
return mIs5gAvailable;
}
- protected boolean is6gAvailable() {
+ /**
+ * Gets is5gAvailable LiveData
+ */
+ public LiveData<Boolean> get5gAvailable() {
+ if (m5gAvailable == null) {
+ m5gAvailable = new MutableLiveData<>();
+ m5gAvailable.setValue(is5gAvailable());
+ }
+ return m5gAvailable;
+ }
+
+ protected void update5gAvailable() {
+ if (m5gAvailable != null) {
+ m5gAvailable.setValue(is5gAvailable());
+ }
+ }
+
+ /**
+ * 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() {
+ if (mIs6gBandSupported == null) {
+ mIs6gBandSupported = mWifiManager.is6GHzBandSupported();
+ log("is6GHzBandSupported():" + mIs6gBandSupported);
+ }
+ return mIs6gBandSupported;
+ }
+
+ /**
+ * 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() {
if (mIs6gAvailable == null) {
- mIs6gAvailable = mWifiManager.is6GHzBandSupported()
- && isBandAvailable(WifiScanner.WIFI_BAND_6_GHZ);
- logd("is6gAvailable():" + mIs6gAvailable);
+ mIs6gAvailable = is6GHzBandSupported()
+ && isChannelAvailable(WifiScanner.WIFI_BAND_6_GHZ, false /* defaultValue */);
+ log("is6gAvailable():" + mIs6gAvailable);
}
return mIs6gAvailable;
}
/**
- * Return whether the Hotspot band is available or not.
- *
- * @param band one of the following band constants defined in {@code WifiScanner#WIFI_BAND_*}
- * constants.
- * 1. {@code WifiScanner#WIFI_BAND_5_GHZ_WITH_DFS}
- * 2. {@code WifiScanner#WIFI_BAND_6_GHZ}
+ * Gets is6gAvailable LiveData
*/
- protected boolean isBandAvailable(int band) {
- List<WifiAvailableChannel> channels = mWifiManager.getUsableChannels(band, OP_MODE_SAP);
- return (channels != null && channels.size() > 0);
+ public LiveData<Boolean> get6gAvailable() {
+ if (m6gAvailable == null) {
+ m6gAvailable = new MutableLiveData<>();
+ m6gAvailable.setValue(is6gAvailable());
+ }
+ return m6gAvailable;
+ }
+
+ protected void update6gAvailable() {
+ if (m6gAvailable != null) {
+ m6gAvailable.setValue(is6gAvailable());
+ }
+ }
+
+ /**
+ * Return whether the Hotspot channel is available or not.
+ *
+ * @param band one of the following band constants defined in
+ * {@code WifiScanner#WIFI_BAND_*} constants.
+ * 1. {@code WifiScanner#WIFI_BAND_5_GHZ_WITH_DFS}
+ * 2. {@code WifiScanner#WIFI_BAND_6_GHZ}
+ * @param defaultValue returns the default value if WifiManager#getUsableChannels is
+ * unavailable to get the SAP information.
+ */
+ protected boolean isChannelAvailable(int band, boolean defaultValue) {
+ try {
+ List<WifiAvailableChannel> channels = mWifiManager.getUsableChannels(band, OP_MODE_SAP);
+ log("isChannelAvailable(), band:" + band + ", channels:" + channels);
+ return (channels != null && channels.size() > 0);
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "Querying usable SAP channels failed, band:" + band);
+ } catch (UnsupportedOperationException e) {
+ // This is expected on some hardware.
+ Log.e(TAG, "Querying usable SAP channels is unsupported, band:" + band);
+ }
+ return defaultValue;
}
protected void purgeRefreshData() {
- mIsDualBand = null;
mIs5gAvailable = null;
mIs6gAvailable = null;
}
@@ -249,7 +376,7 @@
if (mActiveCountryCodeChangedCallback != null) {
return;
}
- logd("startMonitorSoftApConfiguration()");
+ log("startMonitorSoftApConfiguration()");
mActiveCountryCodeChangedCallback = new ActiveCountryCodeChangedCallback();
mWifiManager.registerActiveCountryCodeChangedCallback(mAppContext.getMainExecutor(),
mActiveCountryCodeChangedCallback);
@@ -259,7 +386,7 @@
if (mActiveCountryCodeChangedCallback == null) {
return;
}
- logd("stopMonitorSoftApConfiguration()");
+ log("stopMonitorSoftApConfiguration()");
mWifiManager.unregisterActiveCountryCodeChangedCallback(mActiveCountryCodeChangedCallback);
mActiveCountryCodeChangedCallback = null;
}
@@ -268,7 +395,7 @@
WifiManager.ActiveCountryCodeChangedCallback {
@Override
public void onActiveCountryCodeChanged(String country) {
- logd("onActiveCountryCodeChanged(), country:" + country);
+ log("onActiveCountryCodeChanged(), country:" + country);
mCurrentCountryCode = country;
purgeRefreshData();
refresh();
@@ -276,16 +403,14 @@
@Override
public void onCountryCodeInactive() {
- logd("onCountryCodeInactive()");
+ log("onCountryCodeInactive()");
mCurrentCountryCode = null;
purgeRefreshData();
refresh();
}
}
- private static void logd(String msg) {
- if (DEBUG) {
- Log.d(TAG, msg);
- }
+ private void log(String msg) {
+ FeatureFactory.getFactory(mAppContext).getWifiFeatureProvider().verboseLog(TAG, msg);
}
}
diff --git a/src/com/android/settings/wifi/tether/WifiHotspotSpeedSettings.java b/src/com/android/settings/wifi/tether/WifiHotspotSpeedSettings.java
new file mode 100644
index 0000000..467d394
--- /dev/null
+++ b/src/com/android/settings/wifi/tether/WifiHotspotSpeedSettings.java
@@ -0,0 +1,132 @@
+/*
+ * 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.wifi.tether;
+
+import static com.android.settings.wifi.repository.WifiHotspotRepository.SPEED_2GHZ;
+import static com.android.settings.wifi.repository.WifiHotspotRepository.SPEED_2GHZ_5GHZ;
+import static com.android.settings.wifi.repository.WifiHotspotRepository.SPEED_5GHZ;
+import static com.android.settings.wifi.repository.WifiHotspotRepository.SPEED_6GHZ;
+
+import android.app.settings.SettingsEnums;
+import android.os.Bundle;
+
+import com.android.settings.R;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.overlay.FeatureFactory;
+import com.android.settingslib.widget.SelectorWithWidgetPreference;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Wi-Fi Hotspot Speed & compatibility Settings
+ */
+public class WifiHotspotSpeedSettings extends DashboardFragment implements
+ SelectorWithWidgetPreference.OnClickListener {
+
+ private static final String TAG = "WifiHotspotSpeedSettings";
+
+ protected static final String KEY_SPEED_2GHZ = "wifi_hotspot_speed_2g";
+ protected static final String KEY_SPEED_5GHZ = "wifi_hotspot_speed_5g";
+ protected static final String KEY_SPEED_2GHZ_5GHZ = "wifi_hotspot_speed_2g_5g";
+ protected static final String KEY_SPEED_6GHZ = "wifi_hotspot_speed_6g";
+ protected static Map<String, Integer> sSpeedKeyMap = new HashMap<>();
+
+ static {
+ sSpeedKeyMap.put(KEY_SPEED_2GHZ, SPEED_2GHZ);
+ sSpeedKeyMap.put(KEY_SPEED_5GHZ, SPEED_5GHZ);
+ sSpeedKeyMap.put(KEY_SPEED_2GHZ_5GHZ, SPEED_2GHZ_5GHZ);
+ sSpeedKeyMap.put(KEY_SPEED_6GHZ, SPEED_6GHZ);
+ }
+
+ protected WifiHotspotSpeedViewModel mWifiHotspotSpeedViewModel;
+ protected Map<Integer, SelectorWithWidgetPreference> mSpeedPreferenceMap = new HashMap<>();
+
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.wifi_hotspot_speed;
+ }
+
+ @Override
+ protected String getLogTag() {
+ return TAG;
+ }
+
+ @Override
+ public int getMetricsCategory() {
+ return SettingsEnums.WIFI_TETHER_SETTINGS;
+ }
+
+ @Override
+ public void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+ loadPreferences();
+ mWifiHotspotSpeedViewModel = FeatureFactory.getFactory(getContext())
+ .getWifiFeatureProvider().getWifiHotspotSpeedViewModel(this);
+ onSpeedInfoMapDataChanged(mWifiHotspotSpeedViewModel.getSpeedInfoMapData().getValue());
+ mWifiHotspotSpeedViewModel.getSpeedInfoMapData()
+ .observe(this, this::onSpeedInfoMapDataChanged);
+ }
+
+ protected void loadPreferences() {
+ for (Map.Entry<String, Integer> entry : sSpeedKeyMap.entrySet()) {
+ SelectorWithWidgetPreference preference = findPreference(entry.getKey());
+ if (preference != null) {
+ preference.setOnClickListener(this);
+ mSpeedPreferenceMap.put(entry.getValue(), preference);
+ }
+ }
+ }
+
+ protected void onSpeedInfoMapDataChanged(
+ Map<Integer, WifiHotspotSpeedViewModel.SpeedInfo> speedInfoMap) {
+ log("onSpeedViewDataChanged(), speedInfoMap:" + speedInfoMap);
+ for (Map.Entry<Integer, SelectorWithWidgetPreference> entry :
+ mSpeedPreferenceMap.entrySet()) {
+ WifiHotspotSpeedViewModel.SpeedInfo speedInfo = speedInfoMap.get(entry.getKey());
+ if (speedInfo == null) {
+ continue;
+ }
+ SelectorWithWidgetPreference radioButton = entry.getValue();
+ if (radioButton == null) {
+ continue;
+ }
+ if (radioButton.isChecked() != speedInfo.mIsChecked) {
+ radioButton.setChecked(speedInfo.mIsChecked);
+ }
+ if (radioButton.isEnabled() != speedInfo.mIsEnabled) {
+ radioButton.setEnabled(speedInfo.mIsEnabled);
+ }
+ if (radioButton.isVisible() != speedInfo.mIsVisible) {
+ radioButton.setVisible(speedInfo.mIsVisible);
+ }
+ }
+ }
+
+ @Override
+ public void onRadioButtonClicked(SelectorWithWidgetPreference emiter) {
+ String key = emiter.getKey();
+ log("onRadioButtonClicked(), key:" + key);
+ if (sSpeedKeyMap.containsKey(key)) {
+ mWifiHotspotSpeedViewModel.setSpeedType(sSpeedKeyMap.get(key));
+ }
+ }
+
+ private void log(String msg) {
+ FeatureFactory.getFactory(getContext()).getWifiFeatureProvider().verboseLog(TAG, msg);
+ }
+}
diff --git a/src/com/android/settings/wifi/tether/WifiHotspotSpeedViewModel.java b/src/com/android/settings/wifi/tether/WifiHotspotSpeedViewModel.java
new file mode 100644
index 0000000..c30174e
--- /dev/null
+++ b/src/com/android/settings/wifi/tether/WifiHotspotSpeedViewModel.java
@@ -0,0 +1,160 @@
+/*
+ * 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.wifi.tether;
+
+import static com.android.settings.wifi.repository.WifiHotspotRepository.SPEED_2GHZ;
+import static com.android.settings.wifi.repository.WifiHotspotRepository.SPEED_2GHZ_5GHZ;
+import static com.android.settings.wifi.repository.WifiHotspotRepository.SPEED_5GHZ;
+import static com.android.settings.wifi.repository.WifiHotspotRepository.SPEED_6GHZ;
+
+import android.app.Application;
+
+import androidx.lifecycle.AndroidViewModel;
+import androidx.lifecycle.LiveData;
+import androidx.lifecycle.MutableLiveData;
+import androidx.lifecycle.Observer;
+
+import com.android.settings.overlay.FeatureFactory;
+import com.android.settings.wifi.repository.WifiHotspotRepository;
+
+import org.jetbrains.annotations.NotNull;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Wi-Fi Hotspot Speed View Model
+ */
+public class WifiHotspotSpeedViewModel extends AndroidViewModel {
+ private static final String TAG = "WifiHotspotSpeedViewModel";
+
+ protected final WifiHotspotRepository mWifiHotspotRepository;
+ protected Map<Integer, SpeedInfo> mSpeedInfoMap = new HashMap<>();
+ protected MutableLiveData<Map<Integer, SpeedInfo>> mSpeedInfoMapData;
+ protected SpeedInfo mSpeedInfo2g = new SpeedInfo(false, true, false);
+ protected SpeedInfo mSpeedInfo5g = new SpeedInfo(false, true, false);
+ protected SpeedInfo mSpeedInfo2g5g = new SpeedInfo(false, true, true);
+ protected SpeedInfo mSpeedInfo6g = new SpeedInfo(false, true, true);
+
+ protected final Observer<Boolean> m6gAvailableObserver = a -> on6gAvailableChanged(a);
+ protected final Observer<Boolean> m5gAvailableObserver = a -> on5gAvailableChanged(a);
+ protected final Observer<Integer> mSpeedTypeObserver = st -> onSpeedTypeChanged(st);
+
+ public WifiHotspotSpeedViewModel(@NotNull Application application) {
+ super(application);
+ mWifiHotspotRepository = FeatureFactory.getFactory(application).getWifiFeatureProvider()
+ .getWifiHotspotRepository();
+ mWifiHotspotRepository.get6gAvailable().observeForever(m6gAvailableObserver);
+ mWifiHotspotRepository.get5gAvailable().observeForever(m5gAvailableObserver);
+ mWifiHotspotRepository.getSpeedType().observeForever(mSpeedTypeObserver);
+ mWifiHotspotRepository.setAutoRefresh(true);
+
+ // The visibility of the 6 GHz speed option will not change on a Pixel device.
+ mSpeedInfo6g.mIsVisible = mWifiHotspotRepository.is6GHzBandSupported();
+ }
+
+ @Override
+ protected void onCleared() {
+ mWifiHotspotRepository.get6gAvailable().removeObserver(m6gAvailableObserver);
+ mWifiHotspotRepository.get5gAvailable().removeObserver(m5gAvailableObserver);
+ mWifiHotspotRepository.getSpeedType().removeObserver(mSpeedTypeObserver);
+ }
+
+ protected void on6gAvailableChanged(Boolean available) {
+ log("on6gAvailableChanged(), available:" + available);
+ mSpeedInfo6g.mIsEnabled = available;
+ updateSpeedInfoMapData();
+ }
+
+ protected void on5gAvailableChanged(Boolean available) {
+ log("on5gAvailableChanged(), available:" + available);
+ mSpeedInfo5g.mIsEnabled = available;
+
+ boolean showDualBand = mWifiHotspotRepository.isDualBand() && available;
+ log("on5gAvailableChanged(), showDualBand:" + showDualBand);
+ mSpeedInfo2g5g.mIsVisible = showDualBand;
+ mSpeedInfo2g.mIsVisible = !showDualBand;
+ mSpeedInfo5g.mIsVisible = !showDualBand;
+ updateSpeedInfoMapData();
+ }
+
+ protected void onSpeedTypeChanged(Integer speedType) {
+ log("onSpeedTypeChanged(), speedType:" + speedType);
+ mSpeedInfo2g.mIsChecked = speedType.equals(SPEED_2GHZ);
+ mSpeedInfo5g.mIsChecked = speedType.equals(SPEED_5GHZ);
+ mSpeedInfo2g5g.mIsChecked = speedType.equals(SPEED_2GHZ_5GHZ);
+ mSpeedInfo6g.mIsChecked = speedType.equals(SPEED_6GHZ);
+ updateSpeedInfoMapData();
+ }
+
+ /**
+ * Sets SpeedType
+ */
+ public void setSpeedType(Integer speedType) {
+ mWifiHotspotRepository.setSpeedType(speedType);
+ }
+
+ /**
+ * Gets Speed Information LiveData
+ */
+ public LiveData<Map<Integer, SpeedInfo>> getSpeedInfoMapData() {
+ if (mSpeedInfoMapData == null) {
+ mSpeedInfoMapData = new MutableLiveData<>();
+ mSpeedInfoMapData.setValue(mSpeedInfoMap);
+ log("getSpeedViewData(), mSpeedInfoMap:" + mSpeedInfoMapData.getValue());
+ }
+ return mSpeedInfoMapData;
+ }
+
+ protected void updateSpeedInfoMapData() {
+ mSpeedInfoMap.put(SPEED_2GHZ, mSpeedInfo2g);
+ mSpeedInfoMap.put(SPEED_5GHZ, mSpeedInfo5g);
+ mSpeedInfoMap.put(SPEED_2GHZ_5GHZ, mSpeedInfo2g5g);
+ mSpeedInfoMap.put(SPEED_6GHZ, mSpeedInfo6g);
+ if (mSpeedInfoMapData != null) {
+ mSpeedInfoMapData.setValue(mSpeedInfoMap);
+ }
+ }
+
+ /**
+ * Wi-Fi Hotspot Speed Information
+ */
+ public static final class SpeedInfo {
+ Boolean mIsChecked;
+ boolean mIsEnabled;
+ boolean mIsVisible;
+
+ public SpeedInfo(boolean isChecked, boolean isEnabled, boolean isVisible) {
+ this.mIsChecked = isChecked;
+ this.mIsEnabled = isEnabled;
+ this.mIsVisible = isVisible;
+ }
+
+ @Override
+ public String toString() {
+ return new StringBuilder("SpeedInfo{")
+ .append("isChecked:").append(mIsChecked)
+ .append(",isEnabled:").append(mIsEnabled)
+ .append(",isVisible:").append(mIsVisible)
+ .append('}').toString();
+ }
+ }
+
+ private void log(String msg) {
+ FeatureFactory.getFactory(getApplication()).getWifiFeatureProvider().verboseLog(TAG, msg);
+ }
+}
diff --git a/src/com/android/settings/wifi/tether/WifiTetherViewModel.java b/src/com/android/settings/wifi/tether/WifiTetherViewModel.java
index 4abca02..8cb74c3 100644
--- a/src/com/android/settings/wifi/tether/WifiTetherViewModel.java
+++ b/src/com/android/settings/wifi/tether/WifiTetherViewModel.java
@@ -46,13 +46,12 @@
private static final String TAG = "WifiTetherViewModel";
protected static Map<Integer, Integer> sSpeedSummaryResMap = new HashMap<>();
-
static {
sSpeedSummaryResMap.put(SPEED_UNKNOWN, R.string.summary_placeholder);
- sSpeedSummaryResMap.put(SPEED_2GHZ, R.string.wifi_hotspot_speed_2g_summary);
- sSpeedSummaryResMap.put(SPEED_5GHZ, R.string.wifi_hotspot_speed_5g_summary);
- sSpeedSummaryResMap.put(SPEED_6GHZ, R.string.wifi_hotspot_speed_6g_summary);
- sSpeedSummaryResMap.put(SPEED_2GHZ_5GHZ, R.string.wifi_hotspot_speed_2g_and_5g_summary);
+ sSpeedSummaryResMap.put(SPEED_2GHZ, R.string.wifi_hotspot_speed_summary_2g);
+ sSpeedSummaryResMap.put(SPEED_5GHZ, R.string.wifi_hotspot_speed_summary_5g);
+ sSpeedSummaryResMap.put(SPEED_6GHZ, R.string.wifi_hotspot_speed_summary_6g);
+ sSpeedSummaryResMap.put(SPEED_2GHZ_5GHZ, R.string.wifi_hotspot_speed_summary_2g_and_5g);
}
protected final WifiHotspotRepository mWifiHotspotRepository;
diff --git a/tests/robotests/src/com/android/settings/bluetooth/HearingDeviceCallRoutingPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/HearingDeviceCallRoutingPreferenceControllerTest.java
new file mode 100644
index 0000000..dec4cc4
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/bluetooth/HearingDeviceCallRoutingPreferenceControllerTest.java
@@ -0,0 +1,76 @@
+/*
+ * 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.bluetooth;
+
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.telephony.TelephonyManager;
+
+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.RobolectricTestRunner;
+
+/** Tests for {@link HearingDeviceCallRoutingPreferenceController}. */
+@RunWith(RobolectricTestRunner.class)
+public class HearingDeviceCallRoutingPreferenceControllerTest {
+
+ @Rule
+ public MockitoRule mMockitoRule = MockitoJUnit.rule();
+
+ @Spy
+ private final Context mContext = ApplicationProvider.getApplicationContext();
+ private static final String FAKE_KEY = "fake_key";
+
+ @Mock
+ private TelephonyManager mTelephonyManager;
+ private HearingDeviceCallRoutingPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
+ mController = new HearingDeviceCallRoutingPreferenceController(mContext, FAKE_KEY);
+ }
+
+ @Test
+ public void getAvailabilityStatus_hasTelephonyCalling_available() {
+ when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_noTelephonyCalling_unsupported() {
+ when(mTelephonyManager.isVoiceCapable()).thenReturn(false);
+
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageBroadcastReceiverTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageBroadcastReceiverTest.java
index 6048197..cb8a886 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageBroadcastReceiverTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageBroadcastReceiverTest.java
@@ -57,6 +57,7 @@
mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
mBatteryUsageBroadcastReceiver = new BatteryUsageBroadcastReceiver();
doReturn(mPackageManager).when(mContext).getPackageManager();
+ DatabaseUtils.getSharedPreferences(mContext).edit().clear().apply();
}
@Test
@@ -77,6 +78,7 @@
new Intent(Intent.ACTION_BATTERY_LEVEL_CHANGED));
assertThat(mBatteryUsageBroadcastReceiver.mFetchBatteryUsageData).isFalse();
+ assertSharedPreferences(Intent.ACTION_BATTERY_LEVEL_CHANGED);
}
@Test
@@ -94,6 +96,7 @@
new Intent(Intent.ACTION_BATTERY_LEVEL_CHANGED));
assertThat(mBatteryUsageBroadcastReceiver.mFetchBatteryUsageData).isFalse();
+ assertSharedPreferences(Intent.ACTION_BATTERY_LEVEL_CHANGED);
}
@Test
@@ -110,6 +113,7 @@
new Intent(Intent.ACTION_BATTERY_LEVEL_CHANGED));
assertThat(mBatteryUsageBroadcastReceiver.mFetchBatteryUsageData).isFalse();
+ assertSharedPreferences(Intent.ACTION_BATTERY_LEVEL_CHANGED);
}
@Test
@@ -126,6 +130,7 @@
new Intent(Intent.ACTION_BATTERY_LEVEL_CHANGED));
assertThat(mBatteryUsageBroadcastReceiver.mFetchBatteryUsageData).isTrue();
+ assertSharedPreferences(Intent.ACTION_BATTERY_LEVEL_CHANGED);
}
@Test
@@ -139,6 +144,7 @@
new Intent(BatteryUsageBroadcastReceiver.ACTION_BATTERY_UNPLUGGING));
assertThat(mBatteryUsageBroadcastReceiver.mFetchBatteryUsageData).isFalse();
+ assertSharedPreferences(BatteryUsageBroadcastReceiver.ACTION_BATTERY_UNPLUGGING);
}
@Test
@@ -156,6 +162,7 @@
new Intent(BatteryUsageBroadcastReceiver.ACTION_BATTERY_UNPLUGGING));
assertThat(mBatteryUsageBroadcastReceiver.mFetchBatteryUsageData).isFalse();
+ assertSharedPreferences(BatteryUsageBroadcastReceiver.ACTION_BATTERY_UNPLUGGING);
}
@Test
@@ -172,6 +179,7 @@
new Intent(BatteryUsageBroadcastReceiver.ACTION_BATTERY_UNPLUGGING));
assertThat(mBatteryUsageBroadcastReceiver.mFetchBatteryUsageData).isFalse();
+ assertSharedPreferences(BatteryUsageBroadcastReceiver.ACTION_BATTERY_UNPLUGGING);
}
@Test
@@ -188,6 +196,7 @@
new Intent(BatteryUsageBroadcastReceiver.ACTION_BATTERY_UNPLUGGING));
assertThat(mBatteryUsageBroadcastReceiver.mFetchBatteryUsageData).isTrue();
+ assertSharedPreferences(BatteryUsageBroadcastReceiver.ACTION_BATTERY_UNPLUGGING);
}
@Test
@@ -202,6 +211,8 @@
new Intent(BatteryUsageBroadcastReceiver.ACTION_CLEAR_BATTERY_CACHE_DATA));
assertThat(BatteryDiffEntry.sValidForRestriction).isEmpty();
+ assertSharedPreferences(
+ BatteryUsageBroadcastReceiver.ACTION_CLEAR_BATTERY_CACHE_DATA);
}
@Test
@@ -216,6 +227,8 @@
new Intent(BatteryUsageBroadcastReceiver.ACTION_CLEAR_BATTERY_CACHE_DATA));
assertThat(BatteryDiffEntry.sValidForRestriction).isNotEmpty();
+ assertSharedPreferences(
+ BatteryUsageBroadcastReceiver.ACTION_CLEAR_BATTERY_CACHE_DATA);
}
private static Intent getBatteryIntent(int level, int status) {
@@ -225,4 +238,9 @@
intent.putExtra(BatteryManager.EXTRA_STATUS, status);
return intent;
}
+
+ private void assertSharedPreferences(String preferenceKey) {
+ assertThat(DatabaseUtils.getSharedPreferences(mContext).contains(preferenceKey))
+ .isTrue();
+ }
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BootBroadcastReceiverTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BootBroadcastReceiverTest.java
index ba51e29..aa1ebd7 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BootBroadcastReceiverTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BootBroadcastReceiverTest.java
@@ -81,18 +81,6 @@
}
@Test
- public void onReceive_withMyPackageReplacedIntent_refreshesJob() {
- mReceiver.onReceive(mContext, new Intent(Intent.ACTION_MY_PACKAGE_REPLACED));
- assertThat(mShadowAlarmManager.peekNextScheduledAlarm()).isNotNull();
- }
-
- @Test
- public void onReceive_withMyPackageUnsuspendIntent_refreshesJob() {
- mReceiver.onReceive(mContext, new Intent(Intent.ACTION_MY_PACKAGE_UNSUSPENDED));
- assertThat(mShadowAlarmManager.peekNextScheduledAlarm()).isNotNull();
- }
-
- @Test
public void onReceive_withBootCompletedIntent_refreshesJob() {
mReceiver.onReceive(mContext, new Intent(Intent.ACTION_BOOT_COMPLETED));
assertThat(mShadowAlarmManager.peekNextScheduledAlarm()).isNotNull();
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/DatabaseUtilsTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/DatabaseUtilsTest.java
index 154497e..0cb3d1d 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/DatabaseUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/DatabaseUtilsTest.java
@@ -46,6 +46,8 @@
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
+import java.io.PrintWriter;
+import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -73,6 +75,7 @@
doReturn(mMockContentResolver).when(mContext).getContentResolver();
doReturn(mPackageManager).when(mMockContext).getPackageManager();
doReturn(mPackageManager).when(mContext).getPackageManager();
+ DatabaseUtils.getSharedPreferences(mContext).edit().clear().apply();
}
@Test
@@ -396,6 +399,38 @@
assertThat(batteryHistMap).isEmpty();
}
+ @Test
+ public void recordDateTime_writeDataIntoSharedPreferences() {
+ final String preferenceKey = "test_preference_key";
+ DatabaseUtils.recordDateTime(mContext, preferenceKey);
+
+ assertThat(DatabaseUtils.getSharedPreferences(mContext).contains(preferenceKey))
+ .isTrue();
+ }
+
+ @Test
+ public void dump_dumpExpectedData() {
+ DatabaseUtils.recordDateTime(mContext,
+ Intent.ACTION_BATTERY_LEVEL_CHANGED);
+ DatabaseUtils.recordDateTime(mContext,
+ BatteryUsageBroadcastReceiver.ACTION_BATTERY_UNPLUGGING);
+ DatabaseUtils.recordDateTime(mContext,
+ DatabaseUtils.KEY_LAST_LOAD_FULL_CHARGE_TIME);
+ DatabaseUtils.recordDateTime(mContext,
+ DatabaseUtils.KEY_LAST_UPLOAD_FULL_CHARGE_TIME);
+ final StringWriter stringWriter = new StringWriter();
+ final PrintWriter printWriter = new PrintWriter(stringWriter);
+
+ DatabaseUtils.dump(mContext, printWriter);
+
+ String dumpContent = stringWriter.toString();
+ assertThat(dumpContent.contains("BatteryLevelChanged")).isTrue();
+ assertThat(dumpContent.contains("BatteryUnplugging")).isTrue();
+ assertThat(dumpContent.contains("ClearBatteryCacheData")).isTrue();
+ assertThat(dumpContent.contains("LastLoadFullChargeTime")).isTrue();
+ assertThat(dumpContent.contains("LastUploadFullChargeTime")).isTrue();
+ }
+
private static void verifyBatteryEntryContentValues(
double consumedPower, ContentValues values) {
final BatteryInformation batteryInformation =
diff --git a/tests/robotests/src/com/android/settings/notification/SilentStatusBarPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/SilentStatusBarPreferenceControllerTest.java
index a913b9e..9d1dbfb 100644
--- a/tests/robotests/src/com/android/settings/notification/SilentStatusBarPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/SilentStatusBarPreferenceControllerTest.java
@@ -16,14 +16,21 @@
package com.android.settings.notification;
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.DISABLED_FOR_USER;
+
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import static org.robolectric.Shadows.shadowOf;
import android.content.Context;
+import android.content.pm.UserInfo;
+import android.os.UserHandle;
+import android.os.UserManager;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
@@ -35,6 +42,7 @@
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
+import org.robolectric.shadows.ShadowUserManager;
@RunWith(RobolectricTestRunner.class)
public class SilentStatusBarPreferenceControllerTest {
@@ -60,6 +68,27 @@
}
@Test
+ public void isAvailable_systemUser_available() {
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+ }
+
+ @Test
+ public void isAvailable_extraUser_available() {
+ ShadowUserManager um = shadowOf(mContext.getSystemService(UserManager.class));
+ um.addUser(UserHandle.myUserId(), "Another User", UserInfo.FLAG_FULL);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+ }
+
+ @Test
+ public void isAvailable_guestUser_disabled() {
+ ShadowUserManager um = shadowOf(mContext.getSystemService(UserManager.class));
+ um.addUser(UserHandle.myUserId(), "Guest", UserInfo.FLAG_GUEST);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_FOR_USER);
+ }
+
+ @Test
public void isChecked_settingIsOff() {
when(mBackend.shouldHideSilentStatusBarIcons(any())).thenReturn(false);
assertThat(mController.isChecked()).isFalse();
diff --git a/tests/robotests/src/com/android/settings/security/screenlock/AutoPinConfirmPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/security/screenlock/AutoPinConfirmPreferenceControllerTest.java
index 55e1f1a..15b2ae9 100644
--- a/tests/robotests/src/com/android/settings/security/screenlock/AutoPinConfirmPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/security/screenlock/AutoPinConfirmPreferenceControllerTest.java
@@ -86,7 +86,7 @@
"true", /* makeDefault */ false);
when(mLockPatternUtils.getCredentialTypeForUser(TEST_USER_ID))
.thenReturn(LockPatternUtils.CREDENTIAL_TYPE_PIN);
- when(mLockPatternUtils.getPinLength(TEST_USER_ID)).thenReturn(5L);
+ when(mLockPatternUtils.getPinLength(TEST_USER_ID)).thenReturn(5);
assertThat(mController.isAvailable()).isFalse();
}
@@ -98,7 +98,7 @@
when(mLockPatternUtils.isSecure(TEST_USER_ID)).thenReturn(true);
when(mLockPatternUtils.getCredentialTypeForUser(TEST_USER_ID))
.thenReturn(LockPatternUtils.CREDENTIAL_TYPE_PIN);
- when(mLockPatternUtils.getPinLength(TEST_USER_ID)).thenReturn(6L);
+ when(mLockPatternUtils.getPinLength(TEST_USER_ID)).thenReturn(6);
assertThat(mController.isAvailable()).isTrue();
}
diff --git a/tests/robotests/src/com/android/settings/wifi/tether/WifiHotspotSpeedSettingsTest.java b/tests/robotests/src/com/android/settings/wifi/tether/WifiHotspotSpeedSettingsTest.java
new file mode 100644
index 0000000..ec8cfe8
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiHotspotSpeedSettingsTest.java
@@ -0,0 +1,238 @@
+/*
+ * 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.wifi.tether;
+
+import static com.android.settings.wifi.repository.WifiHotspotRepository.SPEED_2GHZ;
+import static com.android.settings.wifi.repository.WifiHotspotRepository.SPEED_2GHZ_5GHZ;
+import static com.android.settings.wifi.repository.WifiHotspotRepository.SPEED_5GHZ;
+import static com.android.settings.wifi.repository.WifiHotspotRepository.SPEED_6GHZ;
+import static com.android.settings.wifi.tether.WifiHotspotSpeedSettings.KEY_SPEED_2GHZ;
+import static com.android.settings.wifi.tether.WifiHotspotSpeedSettings.KEY_SPEED_2GHZ_5GHZ;
+import static com.android.settings.wifi.tether.WifiHotspotSpeedSettings.KEY_SPEED_5GHZ;
+import static com.android.settings.wifi.tether.WifiHotspotSpeedSettings.KEY_SPEED_6GHZ;
+
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+
+import androidx.lifecycle.ViewModelStoreOwner;
+import androidx.test.core.app.ApplicationProvider;
+
+import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.wifi.factory.WifiFeatureProvider;
+import com.android.settingslib.widget.SelectorWithWidgetPreference;
+
+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.RobolectricTestRunner;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@RunWith(RobolectricTestRunner.class)
+public class WifiHotspotSpeedSettingsTest {
+ @Rule
+ public final MockitoRule mMockitoRule = MockitoJUnit.rule();
+ @Spy
+ Context mContext = ApplicationProvider.getApplicationContext();
+ @Mock
+ ViewModelStoreOwner mViewModelStoreOwner;
+ @Mock
+ WifiHotspotSpeedViewModel mViewModel;
+ @Mock
+ SelectorWithWidgetPreference mRadioButton;
+
+ Map<Integer, WifiHotspotSpeedViewModel.SpeedInfo> mSpeedInfoMap = new HashMap<>();
+ WifiHotspotSpeedViewModel.SpeedInfo mSpeedInfo2g =
+ new WifiHotspotSpeedViewModel.SpeedInfo(false, true, false);
+ WifiHotspotSpeedViewModel.SpeedInfo mSpeedInfo5g =
+ new WifiHotspotSpeedViewModel.SpeedInfo(false, true, false);
+ WifiHotspotSpeedViewModel.SpeedInfo mSpeedInfo2g5g =
+ new WifiHotspotSpeedViewModel.SpeedInfo(false, true, true);
+ WifiHotspotSpeedViewModel.SpeedInfo mSpeedInfo6g =
+ new WifiHotspotSpeedViewModel.SpeedInfo(false, true, true);
+
+ WifiHotspotSpeedSettings mSettings;
+
+ @Before
+ public void setUp() {
+ WifiFeatureProvider provider = FakeFeatureFactory.setupForTest().getWifiFeatureProvider();
+ when(provider.getWifiHotspotSpeedViewModel(mViewModelStoreOwner)).thenReturn(mViewModel);
+
+ mSettings = new WifiHotspotSpeedSettings();
+ mSettings.mWifiHotspotSpeedViewModel = mViewModel;
+ }
+
+ @Test
+ public void onSpeedInfoMapDataChanged_checkedSpeed2g_checkedToRadioButton2g() {
+ mSpeedInfo2g = new WifiHotspotSpeedViewModel.SpeedInfo(false, true, false);
+ updateSpeedInfoMap();
+ mockRadioButton(true, false, true);
+ mSettings.mSpeedPreferenceMap.put(SPEED_2GHZ, mRadioButton);
+
+ mSettings.onSpeedInfoMapDataChanged(mSpeedInfoMap);
+
+ verifyRadioButton(false, true, false);
+ }
+
+ @Test
+ public void onSpeedInfoMapDataChanged_uncheckedSpeed2g_uncheckedToRadioButton2g() {
+ mSpeedInfo2g = new WifiHotspotSpeedViewModel.SpeedInfo(true, false, true);
+ updateSpeedInfoMap();
+ mockRadioButton(false, true, false);
+ mSettings.mSpeedPreferenceMap.put(SPEED_2GHZ, mRadioButton);
+
+ mSettings.onSpeedInfoMapDataChanged(mSpeedInfoMap);
+
+ verifyRadioButton(true, false, true);
+ }
+
+ @Test
+ public void onSpeedInfoMapDataChanged_checkedSpeed5g_checkedToRadioButton5g() {
+ mSpeedInfo5g = new WifiHotspotSpeedViewModel.SpeedInfo(false, true, false);
+ updateSpeedInfoMap();
+ mockRadioButton(true, false, true);
+ mSettings.mSpeedPreferenceMap.put(SPEED_5GHZ, mRadioButton);
+
+ mSettings.onSpeedInfoMapDataChanged(mSpeedInfoMap);
+
+ verifyRadioButton(false, true, false);
+ }
+
+ @Test
+ public void onSpeedInfoMapDataChanged_uncheckedSpeed5g_uncheckedToRadioButton5g() {
+ mSpeedInfo5g = new WifiHotspotSpeedViewModel.SpeedInfo(true, false, true);
+ updateSpeedInfoMap();
+ mockRadioButton(false, true, false);
+ mSettings.mSpeedPreferenceMap.put(SPEED_5GHZ, mRadioButton);
+
+ mSettings.onSpeedInfoMapDataChanged(mSpeedInfoMap);
+
+ verifyRadioButton(true, false, true);
+ }
+
+ @Test
+ public void onSpeedInfoMapDataChanged_checkedSpeed2g5g_checkedToRadioButton2g5g() {
+ mSpeedInfo2g5g = new WifiHotspotSpeedViewModel.SpeedInfo(false, true, false);
+ updateSpeedInfoMap();
+ mockRadioButton(true, false, true);
+ mSettings.mSpeedPreferenceMap.put(SPEED_2GHZ_5GHZ, mRadioButton);
+
+ mSettings.onSpeedInfoMapDataChanged(mSpeedInfoMap);
+
+ verifyRadioButton(false, true, false);
+ }
+
+ @Test
+ public void onSpeedInfoMapDataChanged_uncheckedSpeed25g_uncheckedToRadioButton25g() {
+ mSpeedInfo2g5g = new WifiHotspotSpeedViewModel.SpeedInfo(true, false, true);
+ updateSpeedInfoMap();
+ mockRadioButton(false, true, false);
+ mSettings.mSpeedPreferenceMap.put(SPEED_2GHZ_5GHZ, mRadioButton);
+
+ mSettings.onSpeedInfoMapDataChanged(mSpeedInfoMap);
+
+ verifyRadioButton(true, false, true);
+ }
+
+ @Test
+ public void onSpeedInfoMapDataChanged_checkedSpeed6g_checkedToRadioButton6g() {
+ mSpeedInfo6g = new WifiHotspotSpeedViewModel.SpeedInfo(false, true, false);
+ updateSpeedInfoMap();
+ mockRadioButton(true, false, true);
+ mSettings.mSpeedPreferenceMap.put(SPEED_6GHZ, mRadioButton);
+
+ mSettings.onSpeedInfoMapDataChanged(mSpeedInfoMap);
+
+ verifyRadioButton(false, true, false);
+ }
+
+ @Test
+ public void onSpeedInfoMapDataChanged_uncheckedSpeed6g_uncheckedToRadioButton6g() {
+ mSpeedInfo6g = new WifiHotspotSpeedViewModel.SpeedInfo(true, false, true);
+ updateSpeedInfoMap();
+ mockRadioButton(false, true, false);
+ mSettings.mSpeedPreferenceMap.put(SPEED_6GHZ, mRadioButton);
+
+ mSettings.onSpeedInfoMapDataChanged(mSpeedInfoMap);
+
+ verifyRadioButton(true, false, true);
+ }
+
+ @Test
+ public void onRadioButtonClicked_toSpeed2g_setSpeedType2g() {
+ when(mRadioButton.getKey()).thenReturn(KEY_SPEED_2GHZ);
+
+ mSettings.onRadioButtonClicked(mRadioButton);
+
+ verify(mViewModel).setSpeedType(SPEED_2GHZ);
+ }
+
+ @Test
+ public void onRadioButtonClicked_toSpeed5g_setSpeedType5g() {
+ when(mRadioButton.getKey()).thenReturn(KEY_SPEED_5GHZ);
+
+ mSettings.onRadioButtonClicked(mRadioButton);
+
+ verify(mViewModel).setSpeedType(SPEED_5GHZ);
+ }
+
+ @Test
+ public void onRadioButtonClicked_toSpeed2g5g_setSpeedType2g5g() {
+ when(mRadioButton.getKey()).thenReturn(KEY_SPEED_2GHZ_5GHZ);
+
+ mSettings.onRadioButtonClicked(mRadioButton);
+
+ verify(mViewModel).setSpeedType(SPEED_2GHZ_5GHZ);
+ }
+
+ @Test
+ public void onRadioButtonClicked_toSpeed6g_setSpeedType6g() {
+ when(mRadioButton.getKey()).thenReturn(KEY_SPEED_6GHZ);
+
+ mSettings.onRadioButtonClicked(mRadioButton);
+
+ verify(mViewModel).setSpeedType(SPEED_6GHZ);
+ }
+
+ private void updateSpeedInfoMap() {
+ mSpeedInfoMap.put(SPEED_2GHZ, mSpeedInfo2g);
+ mSpeedInfoMap.put(SPEED_5GHZ, mSpeedInfo5g);
+ mSpeedInfoMap.put(SPEED_2GHZ_5GHZ, mSpeedInfo2g5g);
+ mSpeedInfoMap.put(SPEED_6GHZ, mSpeedInfo6g);
+ }
+
+ private void mockRadioButton(boolean isChecked, boolean isEnabled, boolean isVisible) {
+ when(mRadioButton.isChecked()).thenReturn(isChecked);
+ when(mRadioButton.isEnabled()).thenReturn(isEnabled);
+ when(mRadioButton.isVisible()).thenReturn(isVisible);
+ }
+
+ private void verifyRadioButton(boolean isChecked, boolean isEnabled, boolean isVisible) {
+ verify(mRadioButton).setChecked(isChecked);
+ verify(mRadioButton).setEnabled(isEnabled);
+ verify(mRadioButton).setVisible(isVisible);
+ }
+
+}
diff --git a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java
index 582f792..0c2bbf5 100644
--- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java
@@ -157,7 +157,7 @@
@Test
public void onSpeedSummaryChanged_canNotShowWifiHotspot_returnFalse() {
- int stringResId = R.string.wifi_hotspot_speed_6g_summary;
+ int stringResId = R.string.wifi_hotspot_speed_summary_6g;
mWifiTetherSettings.mWifiHotspotSpeed = mock(Preference.class);
mWifiTetherSettings.onSpeedSummaryChanged(stringResId);
diff --git a/tests/unit/src/com/android/settings/wifi/repository/WifiHotspotRepositoryTest.java b/tests/unit/src/com/android/settings/wifi/repository/WifiHotspotRepositoryTest.java
index 52f02f5..b75f9fc 100644
--- a/tests/unit/src/com/android/settings/wifi/repository/WifiHotspotRepositoryTest.java
+++ b/tests/unit/src/com/android/settings/wifi/repository/WifiHotspotRepositoryTest.java
@@ -19,6 +19,7 @@
import static android.net.wifi.SoftApConfiguration.BAND_2GHZ;
import static android.net.wifi.SoftApConfiguration.SECURITY_TYPE_OPEN;
import static android.net.wifi.SoftApConfiguration.SECURITY_TYPE_WPA3_SAE;
+import static android.net.wifi.WifiAvailableChannel.OP_MODE_SAP;
import static com.android.settings.wifi.repository.WifiHotspotRepository.BAND_2GHZ_5GHZ;
import static com.android.settings.wifi.repository.WifiHotspotRepository.BAND_2GHZ_5GHZ_6GHZ;
@@ -31,13 +32,17 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.net.wifi.SoftApConfiguration;
+import android.net.wifi.WifiAvailableChannel;
import android.net.wifi.WifiManager;
+import android.net.wifi.WifiScanner;
+import android.util.SparseIntArray;
import androidx.lifecycle.MutableLiveData;
import androidx.test.annotation.UiThreadTest;
@@ -48,11 +53,15 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
+import java.util.Arrays;
+import java.util.List;
+
@RunWith(AndroidJUnit4.class)
public class WifiHotspotRepositoryTest {
static final String WIFI_SSID = "wifi_ssid";
@@ -61,6 +70,9 @@
static final int WIFI_5GHZ_BAND_PREFERRED = BAND_2GHZ_5GHZ;
static final int WIFI_6GHZ_BAND_PREFERRED = BAND_2GHZ_5GHZ_6GHZ;
+ static final int CHANNEL_NOT_FOUND = -1;
+ static final int FREQ_5GHZ = 5000;
+ static final int FREQ_6GHZ = 6000;
@Rule
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
@@ -73,10 +85,15 @@
WifiHotspotRepository mWifiHotspotRepository;
SoftApConfiguration mSoftApConfiguration;
+ ArgumentCaptor<SoftApConfiguration> mSoftApConfigCaptor =
+ ArgumentCaptor.forClass(SoftApConfiguration.class);
@Before
public void setUp() {
+ doReturn(SPEED_6GHZ).when(mSpeedType).getValue();
+
mWifiHotspotRepository = new WifiHotspotRepository(mContext, mWifiManager);
+ mWifiHotspotRepository.mSpeedType = mSpeedType;
mWifiHotspotRepository.mCurrentCountryCode = WIFI_CURRENT_COUNTRY_CODE;
mWifiHotspotRepository.mIsDualBand = true;
mWifiHotspotRepository.mIs5gAvailable = true;
@@ -148,8 +165,7 @@
@Test
public void refresh_liveDataIsUsed_getConfigAndUpdateLiveData() {
- // If LiveData is used then it's not null.
- mWifiHotspotRepository.mSpeedType = mSpeedType;
+ mWifiHotspotRepository.getSpeedType();
mWifiHotspotRepository.refresh();
@@ -191,7 +207,6 @@
mWifiHotspotRepository.mIsDualBand = false;
SoftApConfiguration config = new SoftApConfiguration.Builder().setBand(BAND_2GHZ).build();
when(mWifiManager.getSoftApConfiguration()).thenReturn(config);
- mWifiHotspotRepository.mSpeedType = mSpeedType;
mWifiHotspotRepository.updateSpeedType();
@@ -204,7 +219,6 @@
SoftApConfiguration config = new SoftApConfiguration.Builder()
.setBand(WIFI_5GHZ_BAND_PREFERRED).build();
when(mWifiManager.getSoftApConfiguration()).thenReturn(config);
- mWifiHotspotRepository.mSpeedType = mSpeedType;
mWifiHotspotRepository.updateSpeedType();
@@ -218,7 +232,6 @@
SoftApConfiguration config = new SoftApConfiguration.Builder()
.setBand(WIFI_5GHZ_BAND_PREFERRED).build();
when(mWifiManager.getSoftApConfiguration()).thenReturn(config);
- mWifiHotspotRepository.mSpeedType = mSpeedType;
mWifiHotspotRepository.updateSpeedType();
@@ -231,7 +244,6 @@
SoftApConfiguration config = new SoftApConfiguration.Builder()
.setBand(WIFI_6GHZ_BAND_PREFERRED).build();
when(mWifiManager.getSoftApConfiguration()).thenReturn(config);
- mWifiHotspotRepository.mSpeedType = mSpeedType;
mWifiHotspotRepository.updateSpeedType();
@@ -245,7 +257,6 @@
SoftApConfiguration config = new SoftApConfiguration.Builder()
.setBand(WIFI_6GHZ_BAND_PREFERRED).build();
when(mWifiManager.getSoftApConfiguration()).thenReturn(config);
- mWifiHotspotRepository.mSpeedType = mSpeedType;
mWifiHotspotRepository.updateSpeedType();
@@ -260,7 +271,6 @@
SoftApConfiguration config = new SoftApConfiguration.Builder()
.setBand(WIFI_6GHZ_BAND_PREFERRED).build();
when(mWifiManager.getSoftApConfiguration()).thenReturn(config);
- mWifiHotspotRepository.mSpeedType = mSpeedType;
mWifiHotspotRepository.updateSpeedType();
@@ -273,7 +283,6 @@
SoftApConfiguration config = new SoftApConfiguration.Builder()
.setBand(WIFI_5GHZ_BAND_PREFERRED).build();
when(mWifiManager.getSoftApConfiguration()).thenReturn(config);
- mWifiHotspotRepository.mSpeedType = mSpeedType;
mWifiHotspotRepository.updateSpeedType();
@@ -287,10 +296,201 @@
SoftApConfiguration config = new SoftApConfiguration.Builder()
.setBand(WIFI_5GHZ_BAND_PREFERRED).build();
when(mWifiManager.getSoftApConfiguration()).thenReturn(config);
- mWifiHotspotRepository.mSpeedType = mSpeedType;
mWifiHotspotRepository.updateSpeedType();
verify(mSpeedType).setValue(SPEED_2GHZ);
}
+
+ @Test
+ public void setSpeedType_sameValue_doNotSetConfig() {
+ doReturn(SPEED_6GHZ).when(mSpeedType).getValue();
+
+ mWifiHotspotRepository.setSpeedType(SPEED_6GHZ);
+
+ verify(mWifiManager, never()).setSoftApConfiguration(any());
+ }
+
+ @Test
+ public void setSpeedType_from2g5ghz_setConfigBandTo6ghzPreferred() {
+ mockGetSoftApConfiguration(SPEED_2GHZ_5GHZ);
+
+ mWifiHotspotRepository.setSpeedType(SPEED_6GHZ);
+
+ verify(mWifiManager).setSoftApConfiguration(mSoftApConfigCaptor.capture());
+ assertThat(mSoftApConfigCaptor.getValue().getBand()).isEqualTo(BAND_2GHZ_5GHZ_6GHZ);
+ }
+
+ @Test
+ public void setSpeedType_from6ghz_setConfigBandsTo2g5ghz() {
+ mockGetSoftApConfiguration(SPEED_6GHZ);
+ mWifiHotspotRepository.mIsDualBand = true;
+
+ mWifiHotspotRepository.setSpeedType(SPEED_2GHZ_5GHZ);
+
+ verify(mWifiManager).setSoftApConfiguration(mSoftApConfigCaptor.capture());
+ SparseIntArray channels = mSoftApConfigCaptor.getValue().getChannels();
+ assertThat(channels.get(BAND_2GHZ, CHANNEL_NOT_FOUND)).isNotEqualTo(CHANNEL_NOT_FOUND);
+ assertThat(channels.get(BAND_2GHZ_5GHZ, CHANNEL_NOT_FOUND)).isNotEqualTo(CHANNEL_NOT_FOUND);
+ }
+
+ @Test
+ public void setSpeedType_from2ghz_setConfigBandTo5ghzPreferred() {
+ mockGetSoftApConfiguration(SPEED_2GHZ);
+
+ mWifiHotspotRepository.setSpeedType(SPEED_5GHZ);
+
+ verify(mWifiManager).setSoftApConfiguration(mSoftApConfigCaptor.capture());
+ assertThat(mSoftApConfigCaptor.getValue().getBand()).isEqualTo(WIFI_5GHZ_BAND_PREFERRED);
+ }
+
+ @Test
+ public void setSpeedType_from5ghz_setConfigBandTo6ghzPreferred() {
+ mockGetSoftApConfiguration(SPEED_5GHZ);
+
+ mWifiHotspotRepository.setSpeedType(SPEED_6GHZ);
+
+ verify(mWifiManager).setSoftApConfiguration(mSoftApConfigCaptor.capture());
+ assertThat(mSoftApConfigCaptor.getValue().getBand()).isEqualTo(WIFI_6GHZ_BAND_PREFERRED);
+ }
+
+ @Test
+ public void setSpeedType_from5gTo6ghz_setConfigBandTo2ghz() {
+ mockGetSoftApConfiguration(SPEED_6GHZ);
+
+ mWifiHotspotRepository.setSpeedType(SPEED_2GHZ);
+
+ verify(mWifiManager).setSoftApConfiguration(mSoftApConfigCaptor.capture());
+ assertThat(mSoftApConfigCaptor.getValue().getBand()).isEqualTo(BAND_2GHZ);
+ }
+
+ @Test
+ public void isDualBand_resultSameAsWifiManager() {
+ // Reset mIsDualBand to trigger an update
+ mWifiHotspotRepository.mIsDualBand = null;
+ when(mWifiManager.isBridgedApConcurrencySupported()).thenReturn(true);
+
+ assertThat(mWifiHotspotRepository.isDualBand()).isTrue();
+
+ // Reset mIsDualBand to trigger an update
+ mWifiHotspotRepository.mIsDualBand = null;
+ when(mWifiManager.isBridgedApConcurrencySupported()).thenReturn(false);
+
+ assertThat(mWifiHotspotRepository.isDualBand()).isFalse();
+ }
+
+ @Test
+ public void is5GHzBandSupported_resultSameAsWifiManager() {
+ // Reset mIs5gBandSupported to trigger an update
+ mWifiHotspotRepository.mIs5gBandSupported = null;
+ when(mWifiManager.is5GHzBandSupported()).thenReturn(true);
+
+ assertThat(mWifiHotspotRepository.is5GHzBandSupported()).isTrue();
+
+ // Reset mIs5gBandSupported to trigger an update
+ mWifiHotspotRepository.mIs5gBandSupported = null;
+ when(mWifiManager.is5GHzBandSupported()).thenReturn(false);
+
+ assertThat(mWifiHotspotRepository.is5GHzBandSupported()).isFalse();
+ }
+
+ @Test
+ public void is5gAvailable_hasUsableChannels_returnTrue() {
+ mWifiHotspotRepository.mIs5gBandSupported = true;
+ // Reset mIs5gAvailable to trigger an update
+ mWifiHotspotRepository.mIs5gAvailable = null;
+ List<WifiAvailableChannel> channels =
+ Arrays.asList(new WifiAvailableChannel(FREQ_5GHZ, OP_MODE_SAP));
+ when(mWifiManager.getUsableChannels(WifiScanner.WIFI_BAND_5_GHZ_WITH_DFS, OP_MODE_SAP))
+ .thenReturn(channels);
+
+ assertThat(mWifiHotspotRepository.is5gAvailable()).isTrue();
+ }
+
+ @Test
+ public void is5gAvailable_noUsableChannels_returnFalse() {
+ mWifiHotspotRepository.mIs5gBandSupported = true;
+ // Reset mIs5gAvailable to trigger an update
+ mWifiHotspotRepository.mIs5gAvailable = null;
+ when(mWifiManager.getUsableChannels(WifiScanner.WIFI_BAND_5_GHZ_WITH_DFS, OP_MODE_SAP))
+ .thenReturn(null);
+
+ assertThat(mWifiHotspotRepository.is5gAvailable()).isFalse();
+ }
+
+ @Test
+ @UiThreadTest
+ public void get5gAvailable_shouldNotReturnNull() {
+ // Reset m5gAvailable to trigger an update
+ mWifiHotspotRepository.m5gAvailable = null;
+
+ assertThat(mWifiHotspotRepository.get5gAvailable()).isNotNull();
+ }
+
+ @Test
+ public void is6GHzBandSupported_resultSameAsWifiManager() {
+ // Reset mIs6gBandSupported to trigger an update
+ mWifiHotspotRepository.mIs6gBandSupported = null;
+ when(mWifiManager.is6GHzBandSupported()).thenReturn(true);
+
+ assertThat(mWifiHotspotRepository.is6GHzBandSupported()).isTrue();
+
+ // Reset mIs6gBandSupported to trigger an update
+ mWifiHotspotRepository.mIs6gBandSupported = null;
+ when(mWifiManager.is6GHzBandSupported()).thenReturn(false);
+
+ assertThat(mWifiHotspotRepository.is6GHzBandSupported()).isFalse();
+ }
+
+ @Test
+ public void is6gAvailable_hasUsableChannels_returnTrue() {
+ mWifiHotspotRepository.mIs6gBandSupported = true;
+ // Reset mIs6gAvailable to trigger an update
+ mWifiHotspotRepository.mIs6gAvailable = null;
+ List<WifiAvailableChannel> channels =
+ Arrays.asList(new WifiAvailableChannel(FREQ_6GHZ, OP_MODE_SAP));
+ when(mWifiManager.getUsableChannels(WifiScanner.WIFI_BAND_6_GHZ, OP_MODE_SAP))
+ .thenReturn(channels);
+
+ assertThat(mWifiHotspotRepository.is6gAvailable()).isTrue();
+ }
+
+ @Test
+ public void is6gAvailable_noUsableChannels_returnFalse() {
+ mWifiHotspotRepository.mIs6gBandSupported = true;
+ // Reset mIs6gAvailable to trigger an update
+ mWifiHotspotRepository.mIs6gAvailable = null;
+ when(mWifiManager.getUsableChannels(WifiScanner.WIFI_BAND_6_GHZ, OP_MODE_SAP))
+ .thenReturn(null);
+
+ assertThat(mWifiHotspotRepository.is6gAvailable()).isFalse();
+ }
+
+ @Test
+ @UiThreadTest
+ public void get6gAvailable_shouldNotReturnNull() {
+ // Reset m6gAvailable to trigger an update
+ mWifiHotspotRepository.m6gAvailable = null;
+
+ assertThat(mWifiHotspotRepository.get6gAvailable()).isNotNull();
+ }
+
+ private void mockGetSoftApConfiguration(int speedType) {
+ doReturn(speedType).when(mSpeedType).getValue();
+ mWifiHotspotRepository.mIsDualBand = true;
+ SoftApConfiguration.Builder configBuilder = new SoftApConfiguration.Builder();
+ if (speedType == SPEED_2GHZ) {
+ mWifiHotspotRepository.mIsDualBand = false;
+ configBuilder.setBand(BAND_2GHZ);
+ } else if (speedType == SPEED_5GHZ) {
+ mWifiHotspotRepository.mIsDualBand = false;
+ configBuilder.setBand(BAND_2GHZ_5GHZ);
+ } else if (speedType == SPEED_2GHZ_5GHZ) {
+ int[] bands = {BAND_2GHZ, BAND_2GHZ_5GHZ};
+ configBuilder.setBands(bands);
+ } else if (speedType == SPEED_6GHZ) {
+ configBuilder.setBand(BAND_2GHZ_5GHZ_6GHZ);
+ }
+ when(mWifiManager.getSoftApConfiguration()).thenReturn(configBuilder.build());
+ }
}
diff --git a/tests/unit/src/com/android/settings/wifi/tether/WifiHotspotSpeedViewModelTest.java b/tests/unit/src/com/android/settings/wifi/tether/WifiHotspotSpeedViewModelTest.java
new file mode 100644
index 0000000..7308161
--- /dev/null
+++ b/tests/unit/src/com/android/settings/wifi/tether/WifiHotspotSpeedViewModelTest.java
@@ -0,0 +1,287 @@
+/*
+ * 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.wifi.tether;
+
+import static com.android.settings.wifi.repository.WifiHotspotRepository.SPEED_2GHZ;
+import static com.android.settings.wifi.repository.WifiHotspotRepository.SPEED_2GHZ_5GHZ;
+import static com.android.settings.wifi.repository.WifiHotspotRepository.SPEED_5GHZ;
+import static com.android.settings.wifi.repository.WifiHotspotRepository.SPEED_6GHZ;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.Application;
+import android.content.Context;
+
+import androidx.lifecycle.MutableLiveData;
+import androidx.test.annotation.UiThreadTest;
+import androidx.test.core.app.ApplicationProvider;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+
+import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.wifi.repository.WifiHotspotRepository;
+
+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 java.util.Map;
+
+@RunWith(AndroidJUnit4.class)
+public class WifiHotspotSpeedViewModelTest {
+ @Rule
+ public final MockitoRule mMockitoRule = MockitoJUnit.rule();
+ @Spy
+ Context mContext = ApplicationProvider.getApplicationContext();
+ @Mock
+ WifiHotspotRepository mWifiHotspotRepository;
+ @Mock
+ MutableLiveData<Integer> mSpeedType;
+ @Mock
+ MutableLiveData<Boolean> m5gAvailable;
+ @Mock
+ MutableLiveData<Boolean> m6gAvailable;
+ @Mock
+ MutableLiveData<Map<Integer, WifiHotspotSpeedViewModel.SpeedInfo>> mSpeedInfoMapData;
+
+ WifiHotspotSpeedViewModel mViewModel;
+
+ @Before
+ public void setUp() {
+ FakeFeatureFactory featureFactory = FakeFeatureFactory.setupForTest();
+ when(featureFactory.getWifiFeatureProvider().getWifiHotspotRepository())
+ .thenReturn(mWifiHotspotRepository);
+ when(mWifiHotspotRepository.getSpeedType()).thenReturn(mSpeedType);
+ when(mWifiHotspotRepository.is5GHzBandSupported()).thenReturn(true);
+ when(mWifiHotspotRepository.get5gAvailable()).thenReturn(m5gAvailable);
+ when(mWifiHotspotRepository.is6GHzBandSupported()).thenReturn(true);
+ when(mWifiHotspotRepository.get6gAvailable()).thenReturn(m6gAvailable);
+
+ mViewModel = new WifiHotspotSpeedViewModel((Application) mContext);
+ mViewModel.mSpeedInfoMapData = mSpeedInfoMapData;
+ }
+
+ @Test
+ @UiThreadTest
+ public void constructor_observeDataAndSetAutoRefresh() {
+ verify(mSpeedType).observeForever(mViewModel.mSpeedTypeObserver);
+ verify(m5gAvailable).observeForever(mViewModel.m5gAvailableObserver);
+ verify(m6gAvailable).observeForever(mViewModel.m6gAvailableObserver);
+ verify(mWifiHotspotRepository).setAutoRefresh(true);
+ }
+
+ @Test
+ @UiThreadTest
+ public void constructor_supported6GHzBand_set6gVisible() {
+ assertThat(mViewModel.mSpeedInfo6g.mIsVisible).isTrue();
+ }
+
+ @Test
+ @UiThreadTest
+ public void constructor_notSupported6GHzBand_set6gVisible() {
+ when(mWifiHotspotRepository.is6GHzBandSupported()).thenReturn(false);
+
+ WifiHotspotSpeedViewModel viewModel = new WifiHotspotSpeedViewModel((Application) mContext);
+
+ assertThat(viewModel.mSpeedInfo6g.mIsVisible).isFalse();
+ }
+
+ @Test
+ @UiThreadTest
+ public void onCleared_removeObserverData() {
+ mViewModel.onCleared();
+
+ verify(mSpeedType).removeObserver(mViewModel.mSpeedTypeObserver);
+ verify(m5gAvailable).removeObserver(mViewModel.m5gAvailableObserver);
+ verify(m6gAvailable).removeObserver(mViewModel.m6gAvailableObserver);
+ }
+
+ @Test
+ @UiThreadTest
+ public void on6gAvailableChanged_itsAvailable_setLiveData6gEnabled() {
+ mViewModel.mSpeedInfo6g.mIsEnabled = false;
+
+ mViewModel.on6gAvailableChanged(true);
+
+ verify(mSpeedInfoMapData).setValue(mViewModel.mSpeedInfoMap);
+ assertThat(mViewModel.mSpeedInfoMap.get(SPEED_6GHZ).mIsEnabled).isTrue();
+ }
+
+ @Test
+ @UiThreadTest
+ public void on6gAvailableChanged_notAvailable_setLiveData6gDisabled() {
+ mViewModel.mSpeedInfo6g.mIsEnabled = true;
+
+ mViewModel.on6gAvailableChanged(false);
+
+ verify(mSpeedInfoMapData).setValue(mViewModel.mSpeedInfoMap);
+ assertThat(mViewModel.mSpeedInfoMap.get(SPEED_6GHZ).mIsEnabled).isFalse();
+ }
+
+ @Test
+ @UiThreadTest
+ public void on5gAvailableChanged_itsAvailable_setLiveData5gEnabled() {
+ mViewModel.mSpeedInfo5g.mIsEnabled = false;
+
+ mViewModel.on5gAvailableChanged(true);
+
+ verify(mSpeedInfoMapData).setValue(mViewModel.mSpeedInfoMap);
+ assertThat(mViewModel.mSpeedInfoMap.get(SPEED_5GHZ).mIsEnabled).isTrue();
+ }
+
+ @Test
+ @UiThreadTest
+ public void on5gAvailableChanged_notAvailable_setLiveData5gDisabled() {
+ mViewModel.mSpeedInfo5g.mIsEnabled = true;
+
+ mViewModel.on5gAvailableChanged(false);
+
+ verify(mSpeedInfoMapData).setValue(mViewModel.mSpeedInfoMap);
+ assertThat(mViewModel.mSpeedInfoMap.get(SPEED_5GHZ).mIsEnabled).isFalse();
+ }
+
+ @Test
+ @UiThreadTest
+ public void on5gAvailableChanged_inSingleBand_setLiveDataToShowSingleBand() {
+ when(mWifiHotspotRepository.isDualBand()).thenReturn(false);
+
+ mViewModel.on5gAvailableChanged(true);
+
+ verify(mSpeedInfoMapData).setValue(mViewModel.mSpeedInfoMap);
+ assertThat(mViewModel.mSpeedInfoMap.get(SPEED_2GHZ).mIsVisible).isTrue();
+ assertThat(mViewModel.mSpeedInfoMap.get(SPEED_5GHZ).mIsVisible).isTrue();
+ assertThat(mViewModel.mSpeedInfoMap.get(SPEED_2GHZ_5GHZ).mIsVisible).isFalse();
+ }
+
+ @Test
+ @UiThreadTest
+ public void on5gAvailableChanged_inDualBandAnd5gUnavailable_setLiveDataToShowSingleBand() {
+ when(mWifiHotspotRepository.isDualBand()).thenReturn(true);
+
+ mViewModel.on5gAvailableChanged(false);
+
+ verify(mSpeedInfoMapData).setValue(mViewModel.mSpeedInfoMap);
+ assertThat(mViewModel.mSpeedInfoMap.get(SPEED_2GHZ).mIsVisible).isTrue();
+ assertThat(mViewModel.mSpeedInfoMap.get(SPEED_5GHZ).mIsVisible).isTrue();
+ assertThat(mViewModel.mSpeedInfoMap.get(SPEED_2GHZ_5GHZ).mIsVisible).isFalse();
+ }
+
+ @Test
+ @UiThreadTest
+ public void on5gAvailableChanged_inDualBandAnd5gAvailable_setLiveDataToShowDualBand() {
+ when(mWifiHotspotRepository.isDualBand()).thenReturn(true);
+
+ mViewModel.on5gAvailableChanged(true);
+
+ verify(mSpeedInfoMapData).setValue(mViewModel.mSpeedInfoMap);
+ assertThat(mViewModel.mSpeedInfoMap.get(SPEED_2GHZ).mIsVisible).isFalse();
+ assertThat(mViewModel.mSpeedInfoMap.get(SPEED_5GHZ).mIsVisible).isFalse();
+ assertThat(mViewModel.mSpeedInfoMap.get(SPEED_2GHZ_5GHZ).mIsVisible).isTrue();
+ }
+
+ @Test
+ @UiThreadTest
+ public void onSpeedTypeChanged_toSpeed2g_setLiveData2gChecked() {
+ mViewModel.mSpeedInfo2g.mIsChecked = false;
+
+ mViewModel.onSpeedTypeChanged(SPEED_2GHZ);
+
+ verify(mSpeedInfoMapData).setValue(mViewModel.mSpeedInfoMap);
+ assertThat(mViewModel.mSpeedInfoMap.get(SPEED_2GHZ).mIsChecked).isTrue();
+ assertThat(mViewModel.mSpeedInfoMap.get(SPEED_5GHZ).mIsChecked).isFalse();
+ assertThat(mViewModel.mSpeedInfoMap.get(SPEED_2GHZ_5GHZ).mIsChecked).isFalse();
+ assertThat(mViewModel.mSpeedInfoMap.get(SPEED_6GHZ).mIsChecked).isFalse();
+ }
+
+ @Test
+ @UiThreadTest
+ public void onSpeedTypeChanged_toSpeed5g_setLiveData5gChecked() {
+ mViewModel.mSpeedInfo5g.mIsChecked = false;
+
+ mViewModel.onSpeedTypeChanged(SPEED_5GHZ);
+
+ verify(mSpeedInfoMapData).setValue(mViewModel.mSpeedInfoMap);
+ assertThat(mViewModel.mSpeedInfoMap.get(SPEED_2GHZ).mIsChecked).isFalse();
+ assertThat(mViewModel.mSpeedInfoMap.get(SPEED_5GHZ).mIsChecked).isTrue();
+ assertThat(mViewModel.mSpeedInfoMap.get(SPEED_2GHZ_5GHZ).mIsChecked).isFalse();
+ assertThat(mViewModel.mSpeedInfoMap.get(SPEED_6GHZ).mIsChecked).isFalse();
+ }
+
+ @Test
+ @UiThreadTest
+ public void onSpeedTypeChanged_toSpeed2g5g_setLiveData5gChecked() {
+ mViewModel.mSpeedInfo2g5g.mIsChecked = false;
+
+ mViewModel.onSpeedTypeChanged(SPEED_2GHZ_5GHZ);
+
+ verify(mSpeedInfoMapData).setValue(mViewModel.mSpeedInfoMap);
+ assertThat(mViewModel.mSpeedInfoMap.get(SPEED_2GHZ).mIsChecked).isFalse();
+ assertThat(mViewModel.mSpeedInfoMap.get(SPEED_5GHZ).mIsChecked).isFalse();
+ assertThat(mViewModel.mSpeedInfoMap.get(SPEED_2GHZ_5GHZ).mIsChecked).isTrue();
+ assertThat(mViewModel.mSpeedInfoMap.get(SPEED_6GHZ).mIsChecked).isFalse();
+ }
+
+ @Test
+ @UiThreadTest
+ public void onSpeedTypeChanged_toSpeed6g_setLiveData5gChecked() {
+ mViewModel.mSpeedInfo6g.mIsChecked = false;
+
+ mViewModel.onSpeedTypeChanged(SPEED_6GHZ);
+
+ verify(mSpeedInfoMapData).setValue(mViewModel.mSpeedInfoMap);
+ assertThat(mViewModel.mSpeedInfoMap.get(SPEED_2GHZ).mIsChecked).isFalse();
+ assertThat(mViewModel.mSpeedInfoMap.get(SPEED_5GHZ).mIsChecked).isFalse();
+ assertThat(mViewModel.mSpeedInfoMap.get(SPEED_2GHZ_5GHZ).mIsChecked).isFalse();
+ assertThat(mViewModel.mSpeedInfoMap.get(SPEED_6GHZ).mIsChecked).isTrue();
+ }
+
+ @Test
+ @UiThreadTest
+ public void setSpeedType_passedToRepository() {
+ mViewModel.setSpeedType(SPEED_2GHZ);
+
+ verify(mWifiHotspotRepository).setSpeedType(SPEED_2GHZ);
+
+ mViewModel.setSpeedType(SPEED_5GHZ);
+
+ verify(mWifiHotspotRepository).setSpeedType(SPEED_5GHZ);
+
+ mViewModel.setSpeedType(SPEED_2GHZ_5GHZ);
+
+ verify(mWifiHotspotRepository).setSpeedType(SPEED_2GHZ_5GHZ);
+
+ mViewModel.setSpeedType(SPEED_6GHZ);
+
+ verify(mWifiHotspotRepository).setSpeedType(SPEED_6GHZ);
+ }
+
+ @Test
+ @UiThreadTest
+ public void getSpeedInfoMapData_shouldNotReturnNull() {
+ // Reset mSpeedInfoMapData to trigger an update
+ mViewModel.mSpeedInfoMapData = null;
+
+ assertThat(mViewModel.getSpeedInfoMapData()).isNotNull();
+ }
+}