Snap for 12304452 from 9260350b93 to 24Q4-release
Change-Id: Ie73095ed17de92e1ff31742174db2b6446f9fdad
This commit is contained in:
@@ -14,3 +14,10 @@ flag {
|
|||||||
description: "This flag enables or disables the Fingerprint v2 enrollment"
|
description: "This flag enables or disables the Fingerprint v2 enrollment"
|
||||||
bug: "295206723"
|
bug: "295206723"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
flag {
|
||||||
|
name: "active_unlock_finish_parent"
|
||||||
|
namespace: "biometrics_framework"
|
||||||
|
description: "This flag enables the Active Unlock settings activity to finish its parent activity"
|
||||||
|
bug: "343576960"
|
||||||
|
}
|
||||||
|
|||||||
@@ -17,13 +17,3 @@ flag {
|
|||||||
purpose: PURPOSE_BUGFIX
|
purpose: PURPOSE_BUGFIX
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
flag {
|
|
||||||
name: "internet_preference_controller_v2"
|
|
||||||
namespace: "settings_experience"
|
|
||||||
description: "New InternetPreferenceControllerV2."
|
|
||||||
bug: "339884322"
|
|
||||||
metadata {
|
|
||||||
purpose: PURPOSE_BUGFIX
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1536,6 +1536,7 @@
|
|||||||
<item>@*android:drawable/ic_zen_mode_icon_group_of_people</item>
|
<item>@*android:drawable/ic_zen_mode_icon_group_of_people</item>
|
||||||
<item>@*android:drawable/ic_zen_mode_icon_lightbulb</item>
|
<item>@*android:drawable/ic_zen_mode_icon_lightbulb</item>
|
||||||
<item>@*android:drawable/ic_zen_mode_type_schedule_calendar</item>
|
<item>@*android:drawable/ic_zen_mode_type_schedule_calendar</item>
|
||||||
|
<item>@*android:drawable/ic_zen_mode_type_special_dnd</item>
|
||||||
<!-- Sports -->
|
<!-- Sports -->
|
||||||
<item>@*android:drawable/ic_zen_mode_icon_running</item>
|
<item>@*android:drawable/ic_zen_mode_icon_running</item>
|
||||||
<item>@*android:drawable/ic_zen_mode_icon_golf</item>
|
<item>@*android:drawable/ic_zen_mode_icon_golf</item>
|
||||||
@@ -1561,7 +1562,6 @@
|
|||||||
<!-- Other activities -->
|
<!-- Other activities -->
|
||||||
<item>@*android:drawable/ic_zen_mode_icon_train</item>
|
<item>@*android:drawable/ic_zen_mode_icon_train</item>
|
||||||
<item>@*android:drawable/ic_zen_mode_type_driving</item> <!-- Car -->
|
<item>@*android:drawable/ic_zen_mode_type_driving</item> <!-- Car -->
|
||||||
<item>@*android:drawable/ic_zen_mode_icon_croissant</item>
|
|
||||||
<item>@*android:drawable/ic_zen_mode_icon_fork_and_knife</item>
|
<item>@*android:drawable/ic_zen_mode_icon_fork_and_knife</item>
|
||||||
<item>@*android:drawable/ic_zen_mode_icon_shopping_cart</item>
|
<item>@*android:drawable/ic_zen_mode_icon_shopping_cart</item>
|
||||||
<item>@*android:drawable/ic_zen_mode_icon_child</item>
|
<item>@*android:drawable/ic_zen_mode_icon_child</item>
|
||||||
@@ -1587,6 +1587,7 @@
|
|||||||
<item>Group of people</item>
|
<item>Group of people</item>
|
||||||
<item>Lightbulb</item>
|
<item>Lightbulb</item>
|
||||||
<item>Calendar</item>
|
<item>Calendar</item>
|
||||||
|
<item>Do Not Disturb</item>
|
||||||
<!-- Sports -->
|
<!-- Sports -->
|
||||||
<item>Person running</item>
|
<item>Person running</item>
|
||||||
<item>Golf</item>
|
<item>Golf</item>
|
||||||
@@ -1612,7 +1613,6 @@
|
|||||||
<!-- Other activities -->
|
<!-- Other activities -->
|
||||||
<item>Train</item>
|
<item>Train</item>
|
||||||
<item>Car</item>
|
<item>Car</item>
|
||||||
<item>Croissant</item>
|
|
||||||
<item>Fork and knife</item>
|
<item>Fork and knife</item>
|
||||||
<item>Shopping cart</item>
|
<item>Shopping cart</item>
|
||||||
<item>Child</item>
|
<item>Child</item>
|
||||||
|
|||||||
@@ -29,7 +29,8 @@
|
|||||||
android:order="-30"
|
android:order="-30"
|
||||||
settings:allowDividerAbove="true"
|
settings:allowDividerAbove="true"
|
||||||
settings:keywords="@string/keywords_internet"
|
settings:keywords="@string/keywords_internet"
|
||||||
settings:useAdminDisabledSummary="true" />
|
settings:useAdminDisabledSummary="true"
|
||||||
|
settings:controller="com.android.settings.network.InternetPreferenceControllerV2" />
|
||||||
|
|
||||||
<com.android.settingslib.RestrictedPreference
|
<com.android.settingslib.RestrictedPreference
|
||||||
android:key="calls_and_sms"
|
android:key="calls_and_sms"
|
||||||
|
|||||||
@@ -136,14 +136,14 @@ public abstract class AppInfoBase extends SettingsPreferenceFragment
|
|||||||
mPackageName = intent.getData().getSchemeSpecificPart();
|
mPackageName = intent.getData().getSchemeSpecificPart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!hasInteractAcrossUsersPermission()) {
|
|
||||||
Log.w(TAG, "Intent not valid.");
|
|
||||||
finish();
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
if (intent != null && intent.hasExtra(Intent.EXTRA_USER_HANDLE)) {
|
if (intent != null && intent.hasExtra(Intent.EXTRA_USER_HANDLE)) {
|
||||||
mUserId = ((UserHandle) intent.getParcelableExtra(
|
mUserId = ((UserHandle) intent.getParcelableExtra(Intent.EXTRA_USER_HANDLE))
|
||||||
Intent.EXTRA_USER_HANDLE)).getIdentifier();
|
.getIdentifier();
|
||||||
|
if (mUserId != UserHandle.myUserId() && !hasInteractAcrossUsersFullPermission()) {
|
||||||
|
Log.w(TAG, "Intent not valid.");
|
||||||
|
finish();
|
||||||
|
return "";
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
mUserId = UserHandle.myUserId();
|
mUserId = UserHandle.myUserId();
|
||||||
}
|
}
|
||||||
@@ -171,7 +171,7 @@ public abstract class AppInfoBase extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected boolean hasInteractAcrossUsersPermission() {
|
protected boolean hasInteractAcrossUsersFullPermission() {
|
||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
if (!(activity instanceof SettingsActivity)) {
|
if (!(activity instanceof SettingsActivity)) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -24,14 +24,19 @@ import android.content.Intent;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
|
|
||||||
|
import androidx.activity.result.ActivityResult;
|
||||||
|
import androidx.activity.result.ActivityResultLauncher;
|
||||||
|
import androidx.activity.result.contract.ActivityResultContracts;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.biometrics.BiometricEnrollBase;
|
||||||
import com.android.settings.biometrics.activeunlock.ActiveUnlockContentListener.OnContentChangedListener;
|
import com.android.settings.biometrics.activeunlock.ActiveUnlockContentListener.OnContentChangedListener;
|
||||||
import com.android.settings.biometrics.activeunlock.ActiveUnlockDeviceNameListener;
|
import com.android.settings.biometrics.activeunlock.ActiveUnlockDeviceNameListener;
|
||||||
import com.android.settings.biometrics.activeunlock.ActiveUnlockRequireBiometricSetup;
|
import com.android.settings.biometrics.activeunlock.ActiveUnlockRequireBiometricSetup;
|
||||||
import com.android.settings.biometrics.activeunlock.ActiveUnlockStatusUtils;
|
import com.android.settings.biometrics.activeunlock.ActiveUnlockStatusUtils;
|
||||||
|
import com.android.settings.flags.Flags;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
import com.android.settingslib.search.SearchIndexable;
|
import com.android.settingslib.search.SearchIndexable;
|
||||||
|
|
||||||
@@ -52,6 +57,10 @@ public class CombinedBiometricSettings extends BiometricsSettingsBase {
|
|||||||
private CombinedBiometricStatusUtils mCombinedBiometricStatusUtils;
|
private CombinedBiometricStatusUtils mCombinedBiometricStatusUtils;
|
||||||
@Nullable private ActiveUnlockDeviceNameListener mActiveUnlockDeviceNameListener;
|
@Nullable private ActiveUnlockDeviceNameListener mActiveUnlockDeviceNameListener;
|
||||||
|
|
||||||
|
private final ActivityResultLauncher<Intent> mActiveUnlockPreferenceLauncher =
|
||||||
|
registerForActivityResult(new ActivityResultContracts.StartActivityForResult(),
|
||||||
|
this::onActiveUnlockPreferenceResult);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
@@ -158,12 +167,25 @@ public class CombinedBiometricSettings extends BiometricsSettingsBase {
|
|||||||
intent = mActiveUnlockStatusUtils.getIntent();
|
intent = mActiveUnlockStatusUtils.getIntent();
|
||||||
}
|
}
|
||||||
if (intent != null) {
|
if (intent != null) {
|
||||||
startActivityForResult(intent, ACTIVE_UNLOCK_REQUEST);
|
if (Flags.activeUnlockFinishParent()) {
|
||||||
|
mActiveUnlockPreferenceLauncher.launch(intent);
|
||||||
|
} else {
|
||||||
|
startActivityForResult(intent, ACTIVE_UNLOCK_REQUEST);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void onActiveUnlockPreferenceResult(@Nullable ActivityResult result) {
|
||||||
|
if (result != null && result.getResultCode() == BiometricEnrollBase.RESULT_TIMEOUT) {
|
||||||
|
mDoNotFinishActivity = false;
|
||||||
|
// When "Watch Unlock" is closed due to entering onStop(),
|
||||||
|
// "Face & Fingerprint Unlock" shall also close itself and back to "Security" page.
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getUseAnyBiometricSummary() {
|
protected String getUseAnyBiometricSummary() {
|
||||||
// either Active Unlock is not enabled or no device is enrolled.
|
// either Active Unlock is not enabled or no device is enrolled.
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ import android.app.time.TimeZoneCapabilitiesAndConfig;
|
|||||||
import android.app.time.TimeZoneConfiguration;
|
import android.app.time.TimeZoneConfiguration;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.TogglePreferenceController;
|
import com.android.settings.core.TogglePreferenceController;
|
||||||
@@ -115,6 +117,12 @@ public class AutoTimeZonePreferenceController extends TogglePreferenceController
|
|||||||
return R.string.menu_key_system;
|
return R.string.menu_key_system;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateState(Preference preference) {
|
||||||
|
super.updateState(preference);
|
||||||
|
refreshSummary(preference);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getSummary() {
|
public CharSequence getSummary() {
|
||||||
// If auto time zone cannot enable telephony fallback and is capable of location, then auto
|
// If auto time zone cannot enable telephony fallback and is capable of location, then auto
|
||||||
|
|||||||
@@ -172,13 +172,21 @@ public final class DataProcessor {
|
|||||||
/** Gets the {@link BatteryUsageStats} from system service. */
|
/** Gets the {@link BatteryUsageStats} from system service. */
|
||||||
@Nullable
|
@Nullable
|
||||||
public static BatteryUsageStats getBatteryUsageStats(final Context context) {
|
public static BatteryUsageStats getBatteryUsageStats(final Context context) {
|
||||||
|
final long startTime = System.currentTimeMillis();
|
||||||
final BatteryUsageStatsQuery batteryUsageStatsQuery =
|
final BatteryUsageStatsQuery batteryUsageStatsQuery =
|
||||||
new BatteryUsageStatsQuery.Builder()
|
new BatteryUsageStatsQuery.Builder()
|
||||||
.includeBatteryHistory()
|
.includeBatteryHistory()
|
||||||
.includeProcessStateData()
|
.includeProcessStateData()
|
||||||
.build();
|
.build();
|
||||||
return context.getSystemService(BatteryStatsManager.class)
|
final BatteryUsageStats batteryUsageStats =
|
||||||
.getBatteryUsageStats(batteryUsageStatsQuery);
|
context.getSystemService(BatteryStatsManager.class)
|
||||||
|
.getBatteryUsageStats(batteryUsageStatsQuery);
|
||||||
|
Log.d(
|
||||||
|
TAG,
|
||||||
|
String.format(
|
||||||
|
"getBatteryUsageStats() from BatteryStatsManager in %d/ms",
|
||||||
|
System.currentTimeMillis() - startTime));
|
||||||
|
return batteryUsageStats;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Gets the {@link UsageEvents} from system service for all unlocked users. */
|
/** Gets the {@link UsageEvents} from system service for all unlocked users. */
|
||||||
@@ -1693,8 +1701,14 @@ public final class DataProcessor {
|
|||||||
final UserManager userManager = context.getSystemService(UserManager.class);
|
final UserManager userManager = context.getSystemService(UserManager.class);
|
||||||
final SparseArray<BatteryEntry> batteryEntryList = new SparseArray<>();
|
final SparseArray<BatteryEntry> batteryEntryList = new SparseArray<>();
|
||||||
final ArrayList<BatteryEntry> results = new ArrayList<>();
|
final ArrayList<BatteryEntry> results = new ArrayList<>();
|
||||||
|
final long startTime = System.currentTimeMillis();
|
||||||
final List<UidBatteryConsumer> uidBatteryConsumers =
|
final List<UidBatteryConsumer> uidBatteryConsumers =
|
||||||
batteryUsageStats.getUidBatteryConsumers();
|
batteryUsageStats.getUidBatteryConsumers();
|
||||||
|
Log.d(
|
||||||
|
TAG,
|
||||||
|
String.format(
|
||||||
|
"get %d uidBatteryConsumers from BatteryUsageStats in %d/ms",
|
||||||
|
uidBatteryConsumers.size(), (System.currentTimeMillis() - startTime)));
|
||||||
|
|
||||||
// Sort to have all apps with "real" UIDs first, followed by apps that are supposed
|
// Sort to have all apps with "real" UIDs first, followed by apps that are supposed
|
||||||
// to be combined with the real ones.
|
// to be combined with the real ones.
|
||||||
@@ -1763,9 +1777,11 @@ public final class DataProcessor {
|
|||||||
deviceConsumer.getConsumedPowerForCustomComponent(componentId)));
|
deviceConsumer.getConsumedPowerForCustomComponent(componentId)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final int numComponentEntries = batteryEntryList.size();
|
||||||
final List<UserBatteryConsumer> userBatteryConsumers =
|
final List<UserBatteryConsumer> userBatteryConsumers =
|
||||||
batteryUsageStats.getUserBatteryConsumers();
|
batteryUsageStats.getUserBatteryConsumers();
|
||||||
for (int i = 0, size = userBatteryConsumers.size(); i < size; i++) {
|
final int numUserEntries = userBatteryConsumers.size();
|
||||||
|
for (int i = 0; i < numUserEntries; i++) {
|
||||||
final UserBatteryConsumer consumer = userBatteryConsumers.get(i);
|
final UserBatteryConsumer consumer = userBatteryConsumers.get(i);
|
||||||
results.add(
|
results.add(
|
||||||
new BatteryEntry(
|
new BatteryEntry(
|
||||||
@@ -1785,6 +1801,13 @@ public final class DataProcessor {
|
|||||||
results.add(batteryEntryList.valueAt(i));
|
results.add(batteryEntryList.valueAt(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log.d(
|
||||||
|
TAG,
|
||||||
|
String.format(
|
||||||
|
"getCoalescedUsageList(): uidEntries = %d, "
|
||||||
|
+ "userEntries = %d, componentEntries = %d",
|
||||||
|
numUidSippers, numUserEntries, numComponentEntries));
|
||||||
|
|
||||||
// The sort order must have changed, so re-sort based on total power use.
|
// The sort order must have changed, so re-sort based on total power use.
|
||||||
results.sort(BatteryEntry.COMPARATOR);
|
results.sort(BatteryEntry.COMPARATOR);
|
||||||
return results;
|
return results;
|
||||||
|
|||||||
@@ -1,316 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2020 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.android.settings.network;
|
|
||||||
|
|
||||||
import static androidx.lifecycle.Lifecycle.Event.ON_PAUSE;
|
|
||||||
import static androidx.lifecycle.Lifecycle.Event.ON_RESUME;
|
|
||||||
|
|
||||||
import static com.android.settings.network.InternetUpdater.INTERNET_CELLULAR;
|
|
||||||
import static com.android.settings.network.InternetUpdater.INTERNET_ETHERNET;
|
|
||||||
import static com.android.settings.network.InternetUpdater.INTERNET_NETWORKS_AVAILABLE;
|
|
||||||
import static com.android.settings.network.InternetUpdater.INTERNET_OFF;
|
|
||||||
import static com.android.settings.network.InternetUpdater.INTERNET_WIFI;
|
|
||||||
import static com.android.settingslib.wifi.WifiUtils.getHotspotIconResource;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.telephony.SubscriptionManager;
|
|
||||||
|
|
||||||
import androidx.annotation.IdRes;
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
|
||||||
import androidx.lifecycle.Lifecycle;
|
|
||||||
import androidx.lifecycle.LifecycleObserver;
|
|
||||||
import androidx.lifecycle.LifecycleOwner;
|
|
||||||
import androidx.lifecycle.OnLifecycleEvent;
|
|
||||||
import androidx.preference.Preference;
|
|
||||||
import androidx.preference.PreferenceScreen;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.widget.SummaryUpdater;
|
|
||||||
import com.android.settings.wifi.WifiPickerTrackerHelper;
|
|
||||||
import com.android.settings.wifi.WifiSummaryUpdater;
|
|
||||||
import com.android.settings.wifi.repository.SharedConnectivityRepository;
|
|
||||||
import com.android.settingslib.Utils;
|
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
|
||||||
import com.android.settingslib.mobile.dataservice.SubscriptionInfoEntity;
|
|
||||||
import com.android.settingslib.utils.ThreadUtils;
|
|
||||||
import com.android.wifitrackerlib.HotspotNetworkEntry;
|
|
||||||
import com.android.wifitrackerlib.WifiEntry;
|
|
||||||
import com.android.wifitrackerlib.WifiPickerTracker;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PreferenceController to update the internet state.
|
|
||||||
*/
|
|
||||||
public class InternetPreferenceController extends AbstractPreferenceController implements
|
|
||||||
LifecycleObserver, SummaryUpdater.OnSummaryChangeListener,
|
|
||||||
InternetUpdater.InternetChangeListener, MobileNetworkRepository.MobileNetworkCallback,
|
|
||||||
DefaultSubscriptionReceiver.DefaultSubscriptionListener,
|
|
||||||
WifiPickerTracker.WifiPickerTrackerCallback {
|
|
||||||
|
|
||||||
public static final String KEY = "internet_settings";
|
|
||||||
|
|
||||||
private Preference mPreference;
|
|
||||||
@VisibleForTesting
|
|
||||||
WifiSummaryUpdater mSummaryHelper;
|
|
||||||
private InternetUpdater mInternetUpdater;
|
|
||||||
private @InternetUpdater.InternetType int mInternetType;
|
|
||||||
private LifecycleOwner mLifecycleOwner;
|
|
||||||
private MobileNetworkRepository mMobileNetworkRepository;
|
|
||||||
private List<SubscriptionInfoEntity> mSubInfoEntityList = new ArrayList<>();
|
|
||||||
private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
|
||||||
private DefaultSubscriptionReceiver mDataSubscriptionChangedReceiver;
|
|
||||||
private boolean mIsHotspotNetworkEnabled = SharedConnectivityRepository.isDeviceConfigEnabled();
|
|
||||||
@VisibleForTesting
|
|
||||||
WifiPickerTrackerHelper mWifiPickerTrackerHelper;
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
static Map<Integer, Integer> sIconMap = new HashMap<>();
|
|
||||||
static {
|
|
||||||
sIconMap.put(INTERNET_OFF, R.drawable.ic_no_internet_unavailable);
|
|
||||||
sIconMap.put(INTERNET_NETWORKS_AVAILABLE, R.drawable.ic_no_internet_available);
|
|
||||||
sIconMap.put(INTERNET_WIFI, R.drawable.ic_wifi_signal_4);
|
|
||||||
sIconMap.put(INTERNET_CELLULAR, R.drawable.ic_network_cell);
|
|
||||||
sIconMap.put(INTERNET_ETHERNET, R.drawable.ic_settings_ethernet);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Map<Integer, Integer> sSummaryMap = new HashMap<>();
|
|
||||||
static {
|
|
||||||
sSummaryMap.put(INTERNET_OFF, R.string.condition_airplane_title);
|
|
||||||
sSummaryMap.put(INTERNET_NETWORKS_AVAILABLE, R.string.networks_available);
|
|
||||||
sSummaryMap.put(INTERNET_WIFI, 0);
|
|
||||||
sSummaryMap.put(INTERNET_CELLULAR, 0);
|
|
||||||
sSummaryMap.put(INTERNET_ETHERNET, R.string.to_switch_networks_disconnect_ethernet);
|
|
||||||
}
|
|
||||||
|
|
||||||
public InternetPreferenceController(Context context, Lifecycle lifecycle,
|
|
||||||
LifecycleOwner lifecycleOwner) {
|
|
||||||
super(context);
|
|
||||||
if (lifecycle == null) {
|
|
||||||
throw new IllegalArgumentException("Lifecycle must be set");
|
|
||||||
}
|
|
||||||
mSummaryHelper = new WifiSummaryUpdater(mContext, this);
|
|
||||||
mInternetUpdater = new InternetUpdater(context, lifecycle, this);
|
|
||||||
mInternetType = mInternetUpdater.getInternetType();
|
|
||||||
mLifecycleOwner = lifecycleOwner;
|
|
||||||
mMobileNetworkRepository = MobileNetworkRepository.getInstance(context);
|
|
||||||
mDataSubscriptionChangedReceiver = new DefaultSubscriptionReceiver(context, this);
|
|
||||||
if (mIsHotspotNetworkEnabled) {
|
|
||||||
mWifiPickerTrackerHelper = new WifiPickerTrackerHelper(lifecycle, context, this);
|
|
||||||
}
|
|
||||||
lifecycle.addObserver(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void displayPreference(PreferenceScreen screen) {
|
|
||||||
super.displayPreference(screen);
|
|
||||||
mPreference = screen.findPreference(KEY);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void drawIcon(int iconResId) {
|
|
||||||
Drawable drawable = mContext.getDrawable(iconResId);
|
|
||||||
if (drawable != null) {
|
|
||||||
drawable.setTintList(Utils.getColorAttr(mContext, android.R.attr.colorControlNormal));
|
|
||||||
mPreference.setIcon(drawable);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateState(Preference preference) {
|
|
||||||
if (mPreference == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mInternetType == INTERNET_WIFI && updateHotspotNetwork()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final @IdRes int icon = sIconMap.get(mInternetType);
|
|
||||||
if (icon != 0) {
|
|
||||||
drawIcon(icon);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mInternetType == INTERNET_WIFI) {
|
|
||||||
mPreference.setSummary(mSummaryHelper.getSummary());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mInternetType == INTERNET_CELLULAR) {
|
|
||||||
updateCellularSummary();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final @IdRes int summary = sSummaryMap.get(mInternetType);
|
|
||||||
if (summary != 0) {
|
|
||||||
mPreference.setSummary(summary);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
boolean updateHotspotNetwork() {
|
|
||||||
if (mWifiPickerTrackerHelper == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
WifiEntry entry = mWifiPickerTrackerHelper.getWifiPickerTracker().getConnectedWifiEntry();
|
|
||||||
if (!(entry instanceof HotspotNetworkEntry)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
drawIcon(getHotspotIconResource(((HotspotNetworkEntry) entry).getDeviceType()));
|
|
||||||
mPreference.setSummary(((HotspotNetworkEntry) entry).getAlternateSummary());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAvailable() {
|
|
||||||
return mContext.getResources().getBoolean(R.bool.config_show_internet_settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPreferenceKey() {
|
|
||||||
return KEY;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @OnLifecycleEvent(ON_RESUME) */
|
|
||||||
@OnLifecycleEvent(ON_RESUME)
|
|
||||||
public void onResume() {
|
|
||||||
mMobileNetworkRepository.addRegister(mLifecycleOwner, this,
|
|
||||||
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
|
||||||
mMobileNetworkRepository.updateEntity();
|
|
||||||
mSummaryHelper.register(true);
|
|
||||||
mDataSubscriptionChangedReceiver.registerReceiver();
|
|
||||||
mDefaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @OnLifecycleEvent(ON_PAUSE) */
|
|
||||||
@OnLifecycleEvent(ON_PAUSE)
|
|
||||||
public void onPause() {
|
|
||||||
mMobileNetworkRepository.removeRegister(this);
|
|
||||||
mSummaryHelper.register(false);
|
|
||||||
mDataSubscriptionChangedReceiver.unRegisterReceiver();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when internet type is changed.
|
|
||||||
*
|
|
||||||
* @param internetType the internet type
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void onInternetTypeChanged(@InternetUpdater.InternetType int internetType) {
|
|
||||||
final boolean needUpdate = (internetType != mInternetType);
|
|
||||||
mInternetType = internetType;
|
|
||||||
if (needUpdate) {
|
|
||||||
ThreadUtils.postOnMainThread(() -> {
|
|
||||||
updateState(mPreference);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when airplane mode state is changed.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void onAirplaneModeChanged(boolean isAirplaneModeOn) {
|
|
||||||
ThreadUtils.postOnMainThread(() -> {
|
|
||||||
updateState(mPreference);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSummaryChanged(String summary) {
|
|
||||||
if (mInternetType == INTERNET_WIFI) {
|
|
||||||
updateState(mPreference);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
void updateCellularSummary() {
|
|
||||||
CharSequence summary = null;
|
|
||||||
SubscriptionInfoEntity activeSubInfo = null;
|
|
||||||
SubscriptionInfoEntity defaultSubInfo = null;
|
|
||||||
|
|
||||||
for (SubscriptionInfoEntity subInfo : getSubscriptionInfoList()) {
|
|
||||||
if (subInfo.isActiveDataSubscriptionId) {
|
|
||||||
activeSubInfo = subInfo;
|
|
||||||
}
|
|
||||||
if (subInfo.getSubId() == getDefaultDataSubscriptionId()) {
|
|
||||||
defaultSubInfo = subInfo;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (activeSubInfo == null || defaultSubInfo == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
activeSubInfo = activeSubInfo.isSubscriptionVisible ? activeSubInfo : defaultSubInfo;
|
|
||||||
|
|
||||||
if (activeSubInfo.equals(defaultSubInfo)) {
|
|
||||||
// DDS is active
|
|
||||||
summary = activeSubInfo.uniqueName;
|
|
||||||
} else {
|
|
||||||
summary = mContext.getString(
|
|
||||||
R.string.mobile_data_temp_using, activeSubInfo.uniqueName);
|
|
||||||
}
|
|
||||||
|
|
||||||
mPreference.setSummary(summary);
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
protected List<SubscriptionInfoEntity> getSubscriptionInfoList() {
|
|
||||||
return mSubInfoEntityList;
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
protected int getDefaultDataSubscriptionId() {
|
|
||||||
return mDefaultDataSubId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAvailableSubInfoChanged(List<SubscriptionInfoEntity> subInfoEntityList) {
|
|
||||||
mSubInfoEntityList = subInfoEntityList;
|
|
||||||
updateState(mPreference);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDefaultDataChanged(int defaultDataSubId) {
|
|
||||||
mDefaultDataSubId = defaultDataSubId;
|
|
||||||
updateState(mPreference);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onWifiEntriesChanged() {
|
|
||||||
if (mInternetType == INTERNET_WIFI) {
|
|
||||||
updateState(mPreference);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onWifiStateChanged() {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNumSavedNetworksChanged() {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNumSavedSubscriptionsChanged() {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -25,7 +25,6 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.SettingsDumpService;
|
import com.android.settings.SettingsDumpService;
|
||||||
import com.android.settings.core.OnActivityResultListener;
|
import com.android.settings.core.OnActivityResultListener;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.flags.Flags;
|
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
@@ -90,14 +89,6 @@ public class NetworkDashboardFragment extends DashboardFragment implements
|
|||||||
|
|
||||||
controllers.add(new MobileNetworkSummaryController(context, lifecycle, lifecycleOwner));
|
controllers.add(new MobileNetworkSummaryController(context, lifecycle, lifecycleOwner));
|
||||||
controllers.add(vpnPreferenceController);
|
controllers.add(vpnPreferenceController);
|
||||||
|
|
||||||
if (Flags.internetPreferenceControllerV2()) {
|
|
||||||
controllers.add(
|
|
||||||
new InternetPreferenceControllerV2(context, InternetPreferenceController.KEY));
|
|
||||||
} else {
|
|
||||||
controllers.add(new InternetPreferenceController(context, lifecycle, lifecycleOwner));
|
|
||||||
}
|
|
||||||
|
|
||||||
controllers.add(privateDnsPreferenceController);
|
controllers.add(privateDnsPreferenceController);
|
||||||
|
|
||||||
// Start SettingsDumpService after the MobileNetworkRepository is created.
|
// Start SettingsDumpService after the MobileNetworkRepository is created.
|
||||||
|
|||||||
@@ -43,15 +43,18 @@ import java.util.function.Function;
|
|||||||
abstract class AbstractZenModeHeaderController extends AbstractZenModePreferenceController {
|
abstract class AbstractZenModeHeaderController extends AbstractZenModePreferenceController {
|
||||||
|
|
||||||
private final DashboardFragment mFragment;
|
private final DashboardFragment mFragment;
|
||||||
|
private final ZenIconLoader mIconLoader;
|
||||||
private EntityHeaderController mHeaderController;
|
private EntityHeaderController mHeaderController;
|
||||||
@Nullable private ZenIcon.Key mCurrentIconKey;
|
@Nullable private ZenIcon.Key mCurrentIconKey;
|
||||||
|
|
||||||
AbstractZenModeHeaderController(
|
AbstractZenModeHeaderController(
|
||||||
@NonNull Context context,
|
@NonNull Context context,
|
||||||
|
@NonNull ZenIconLoader iconLoader,
|
||||||
@NonNull String key,
|
@NonNull String key,
|
||||||
@NonNull DashboardFragment fragment) {
|
@NonNull DashboardFragment fragment) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
mFragment = fragment;
|
mFragment = fragment;
|
||||||
|
mIconLoader = iconLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -90,7 +93,7 @@ abstract class AbstractZenModeHeaderController extends AbstractZenModePreference
|
|||||||
if (!Objects.equal(mCurrentIconKey, zenMode.getIconKey())) {
|
if (!Objects.equal(mCurrentIconKey, zenMode.getIconKey())) {
|
||||||
mCurrentIconKey = zenMode.getIconKey();
|
mCurrentIconKey = zenMode.getIconKey();
|
||||||
FutureUtil.whenDone(
|
FutureUtil.whenDone(
|
||||||
ZenIconLoader.getInstance().getIcon(mContext, zenMode),
|
mIconLoader.getIcon(mContext, zenMode),
|
||||||
icon -> {
|
icon -> {
|
||||||
checkNotNull(mHeaderController)
|
checkNotNull(mHeaderController)
|
||||||
.setIcon(iconStylist.apply(icon.drawable()))
|
.setIcon(iconStylist.apply(icon.drawable()))
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import androidx.annotation.VisibleForTesting;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
|
import com.android.settingslib.notification.modes.ZenIconLoader;
|
||||||
import com.android.settingslib.notification.modes.ZenMode;
|
import com.android.settingslib.notification.modes.ZenMode;
|
||||||
import com.android.settingslib.notification.modes.ZenModesBackend;
|
import com.android.settingslib.notification.modes.ZenModesBackend;
|
||||||
|
|
||||||
@@ -102,7 +103,8 @@ public abstract class ZenModeEditNameIconFragmentBase extends DashboardFragment
|
|||||||
protected final List<AbstractPreferenceController> createPreferenceControllers(
|
protected final List<AbstractPreferenceController> createPreferenceControllers(
|
||||||
Context context) {
|
Context context) {
|
||||||
return ImmutableList.of(
|
return ImmutableList.of(
|
||||||
new ZenModeIconPickerIconPreferenceController(context, "chosen_icon", this),
|
new ZenModeIconPickerIconPreferenceController(context, ZenIconLoader.getInstance(),
|
||||||
|
"chosen_icon", this),
|
||||||
new ZenModeEditNamePreferenceController(context, "name", this::setModeName),
|
new ZenModeEditNamePreferenceController(context, "name", this::setModeName),
|
||||||
new ZenModeIconPickerListPreferenceController(context, "icon_list",
|
new ZenModeIconPickerListPreferenceController(context, "icon_list",
|
||||||
this::setModeIcon),
|
this::setModeIcon),
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import androidx.core.view.MenuProvider;
|
|||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
|
import com.android.settingslib.notification.modes.ZenIconLoader;
|
||||||
import com.android.settingslib.notification.modes.ZenMode;
|
import com.android.settingslib.notification.modes.ZenMode;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -54,7 +55,8 @@ public class ZenModeFragment extends ZenModeFragmentBase {
|
|||||||
@Override
|
@Override
|
||||||
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
||||||
List<AbstractPreferenceController> prefControllers = new ArrayList<>();
|
List<AbstractPreferenceController> prefControllers = new ArrayList<>();
|
||||||
prefControllers.add(new ZenModeHeaderController(context, "header", this));
|
prefControllers.add(
|
||||||
|
new ZenModeHeaderController(context, ZenIconLoader.getInstance(), "header", this));
|
||||||
prefControllers.add(new ZenModeBlurbPreferenceController(context, "mode_blurb"));
|
prefControllers.add(new ZenModeBlurbPreferenceController(context, "mode_blurb"));
|
||||||
prefControllers.add(
|
prefControllers.add(
|
||||||
new ZenModeButtonPreferenceController(context, "activate", this, mBackend));
|
new ZenModeButtonPreferenceController(context, "activate", this, mBackend));
|
||||||
|
|||||||
@@ -23,15 +23,14 @@ import androidx.preference.PreferenceScreen;
|
|||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
|
import com.android.settingslib.notification.modes.ZenIconLoader;
|
||||||
import com.android.settingslib.notification.modes.ZenMode;
|
import com.android.settingslib.notification.modes.ZenMode;
|
||||||
|
|
||||||
class ZenModeHeaderController extends AbstractZenModeHeaderController {
|
class ZenModeHeaderController extends AbstractZenModeHeaderController {
|
||||||
|
|
||||||
ZenModeHeaderController(
|
ZenModeHeaderController(@NonNull Context context, @NonNull ZenIconLoader iconLoader,
|
||||||
@NonNull Context context,
|
@NonNull String key, @NonNull DashboardFragment fragment) {
|
||||||
@NonNull String key,
|
super(context, iconLoader, key, fragment);
|
||||||
@NonNull DashboardFragment fragment) {
|
|
||||||
super(context, key, fragment);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -24,14 +24,16 @@ import androidx.preference.PreferenceScreen;
|
|||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
|
import com.android.settingslib.notification.modes.ZenIconLoader;
|
||||||
import com.android.settingslib.notification.modes.ZenMode;
|
import com.android.settingslib.notification.modes.ZenMode;
|
||||||
|
|
||||||
/** Controller used for displaying the currently-chosen icon at the top of the icon picker. */
|
/** Controller used for displaying the currently-chosen icon at the top of the icon picker. */
|
||||||
class ZenModeIconPickerIconPreferenceController extends AbstractZenModeHeaderController {
|
class ZenModeIconPickerIconPreferenceController extends AbstractZenModeHeaderController {
|
||||||
|
|
||||||
ZenModeIconPickerIconPreferenceController(@NonNull Context context, @NonNull String key,
|
ZenModeIconPickerIconPreferenceController(@NonNull Context context,
|
||||||
|
@NonNull ZenIconLoader iconLoader, @NonNull String key,
|
||||||
@NonNull DashboardFragment fragment) {
|
@NonNull DashboardFragment fragment) {
|
||||||
super(context, key, fragment);
|
super(context, iconLoader, key, fragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import com.android.settings.notification.modes.ZenModesListAddModePreferenceCont
|
|||||||
import com.android.settings.notification.modes.ZenModesListAddModePreferenceController.OnAddModeListener;
|
import com.android.settings.notification.modes.ZenModesListAddModePreferenceController.OnAddModeListener;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
|
import com.android.settingslib.notification.modes.ZenIconLoader;
|
||||||
import com.android.settingslib.notification.modes.ZenMode;
|
import com.android.settingslib.notification.modes.ZenMode;
|
||||||
import com.android.settingslib.notification.modes.ZenModesBackend;
|
import com.android.settingslib.notification.modes.ZenModesBackend;
|
||||||
import com.android.settingslib.search.SearchIndexable;
|
import com.android.settingslib.search.SearchIndexable;
|
||||||
@@ -56,7 +57,7 @@ public class ZenModesListFragment extends ZenModesFragmentBase {
|
|||||||
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
|
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
|
||||||
ZenModesBackend backend, OnAddModeListener onAddModeListener) {
|
ZenModesBackend backend, OnAddModeListener onAddModeListener) {
|
||||||
return ImmutableList.of(
|
return ImmutableList.of(
|
||||||
new ZenModesListPreferenceController(context, backend),
|
new ZenModesListPreferenceController(context, backend, ZenIconLoader.getInstance()),
|
||||||
new ZenModesListAddModePreferenceController(context, onAddModeListener)
|
new ZenModesListAddModePreferenceController(context, onAddModeListener)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ import com.android.settingslib.notification.modes.ZenMode;
|
|||||||
|
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
|
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Preference representing a single mode item on the modes aggregator page. Clicking on this
|
* Preference representing a single mode item on the modes aggregator page. Clicking on this
|
||||||
* preference leads to an individual mode's configuration page.
|
* preference leads to an individual mode's configuration page.
|
||||||
@@ -38,18 +40,29 @@ import com.google.common.base.Strings;
|
|||||||
class ZenModesListItemPreference extends RestrictedPreference {
|
class ZenModesListItemPreference extends RestrictedPreference {
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
|
private final ZenIconLoader mIconLoader;
|
||||||
|
private final Executor mUiExecutor;
|
||||||
private ZenMode mZenMode;
|
private ZenMode mZenMode;
|
||||||
|
|
||||||
private TextView mTitleView;
|
private TextView mTitleView;
|
||||||
private TextView mSummaryView;
|
private TextView mSummaryView;
|
||||||
|
|
||||||
ZenModesListItemPreference(Context context, ZenMode zenMode) {
|
ZenModesListItemPreference(Context context, ZenIconLoader iconLoader, ZenMode zenMode) {
|
||||||
|
this(context, iconLoader, context.getMainExecutor(), zenMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
ZenModesListItemPreference(Context context, ZenIconLoader iconLoader, Executor uiExecutor,
|
||||||
|
ZenMode zenMode) {
|
||||||
super(context);
|
super(context);
|
||||||
mContext = context;
|
mContext = context;
|
||||||
|
mIconLoader = iconLoader;
|
||||||
|
mUiExecutor = uiExecutor;
|
||||||
setZenMode(zenMode);
|
setZenMode(zenMode);
|
||||||
setKey(zenMode.getId());
|
setKey(zenMode.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||||
super.onBindViewHolder(holder);
|
super.onBindViewHolder(holder);
|
||||||
@@ -93,12 +106,12 @@ class ZenModesListItemPreference extends RestrictedPreference {
|
|||||||
|
|
||||||
setIconSize(ICON_SIZE_SMALL);
|
setIconSize(ICON_SIZE_SMALL);
|
||||||
FutureUtil.whenDone(
|
FutureUtil.whenDone(
|
||||||
ZenIconLoader.getInstance().getIcon(mContext, mZenMode),
|
mIconLoader.getIcon(mContext, mZenMode),
|
||||||
icon -> setIcon(
|
icon -> setIcon(
|
||||||
zenMode.isActive()
|
zenMode.isActive()
|
||||||
? IconUtil.applyAccentTint(mContext, icon.drawable())
|
? IconUtil.applyAccentTint(mContext, icon.drawable())
|
||||||
: IconUtil.applyNormalTint(mContext, icon.drawable())),
|
: IconUtil.applyNormalTint(mContext, icon.drawable())),
|
||||||
mContext.getMainExecutor());
|
mUiExecutor);
|
||||||
|
|
||||||
updateTextColor(zenMode);
|
updateTextColor(zenMode);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import androidx.preference.PreferenceCategory;
|
|||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
import com.android.settingslib.notification.modes.ZenIconLoader;
|
||||||
import com.android.settingslib.notification.modes.ZenMode;
|
import com.android.settingslib.notification.modes.ZenMode;
|
||||||
import com.android.settingslib.notification.modes.ZenModesBackend;
|
import com.android.settingslib.notification.modes.ZenModesBackend;
|
||||||
import com.android.settingslib.search.SearchIndexableRaw;
|
import com.android.settingslib.search.SearchIndexableRaw;
|
||||||
@@ -42,11 +43,14 @@ class ZenModesListPreferenceController extends BasePreferenceController
|
|||||||
implements BasePreferenceController.UiBlocker {
|
implements BasePreferenceController.UiBlocker {
|
||||||
protected static final String KEY = "zen_modes_list";
|
protected static final String KEY = "zen_modes_list";
|
||||||
|
|
||||||
protected ZenModesBackend mBackend;
|
private final ZenModesBackend mBackend;
|
||||||
|
private final ZenIconLoader mIconLoader;
|
||||||
|
|
||||||
ZenModesListPreferenceController(Context context, @NonNull ZenModesBackend backend) {
|
ZenModesListPreferenceController(Context context, @NonNull ZenModesBackend backend, @NonNull
|
||||||
|
ZenIconLoader iconLoader) {
|
||||||
super(context, KEY);
|
super(context, KEY);
|
||||||
mBackend = backend;
|
mBackend = backend;
|
||||||
|
mIconLoader = iconLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -82,7 +86,7 @@ class ZenModesListPreferenceController extends BasePreferenceController
|
|||||||
modePreference.setZenMode(mode);
|
modePreference.setZenMode(mode);
|
||||||
} else {
|
} else {
|
||||||
// new rule; create a new ZenRulePreference & add it to the preference category
|
// new rule; create a new ZenRulePreference & add it to the preference category
|
||||||
modePreference = new ZenModesListItemPreference(mContext, mode);
|
modePreference = new ZenModesListItemPreference(mContext, mIconLoader, mode);
|
||||||
category.addPreference(modePreference);
|
category.addPreference(modePreference);
|
||||||
}
|
}
|
||||||
modePreference.setOrder(modes.indexOf(mode));
|
modePreference.setOrder(modes.indexOf(mode));
|
||||||
|
|||||||
@@ -1,110 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 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;
|
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.IntentFilter;
|
|
||||||
import android.net.ConnectivityManager;
|
|
||||||
import android.net.NetworkScoreManager;
|
|
||||||
import android.net.wifi.WifiInfo;
|
|
||||||
import android.net.wifi.WifiManager;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.widget.SummaryUpdater;
|
|
||||||
import com.android.settingslib.wifi.WifiStatusTracker;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper class that listeners to wifi callback and notify client when there is update in
|
|
||||||
* wifi summary info.
|
|
||||||
*/
|
|
||||||
public class WifiSummaryUpdater extends SummaryUpdater {
|
|
||||||
|
|
||||||
private final WifiStatusTracker mWifiTracker;
|
|
||||||
private final BroadcastReceiver mReceiver;
|
|
||||||
|
|
||||||
private static final IntentFilter INTENT_FILTER;
|
|
||||||
static {
|
|
||||||
INTENT_FILTER = new IntentFilter();
|
|
||||||
INTENT_FILTER.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
|
|
||||||
INTENT_FILTER.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
|
||||||
INTENT_FILTER.addAction(WifiManager.RSSI_CHANGED_ACTION);
|
|
||||||
}
|
|
||||||
|
|
||||||
public WifiSummaryUpdater(Context context, OnSummaryChangeListener listener) {
|
|
||||||
this(context, listener, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
public WifiSummaryUpdater(Context context, OnSummaryChangeListener listener,
|
|
||||||
WifiStatusTracker wifiTracker) {
|
|
||||||
super(context, listener);
|
|
||||||
mWifiTracker = wifiTracker != null ? wifiTracker :
|
|
||||||
new WifiStatusTracker(context, context.getSystemService(WifiManager.class),
|
|
||||||
context.getSystemService(NetworkScoreManager.class),
|
|
||||||
context.getSystemService(ConnectivityManager.class),
|
|
||||||
this::notifyChangeIfNeeded);
|
|
||||||
mReceiver = new BroadcastReceiver() {
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
mWifiTracker.handleBroadcast(intent);
|
|
||||||
notifyChangeIfNeeded();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void register(boolean register) {
|
|
||||||
if (register) {
|
|
||||||
mWifiTracker.fetchInitialState();
|
|
||||||
notifyChangeIfNeeded();
|
|
||||||
mContext.registerReceiver(mReceiver, INTENT_FILTER,
|
|
||||||
Context.RECEIVER_EXPORTED_UNAUDITED);
|
|
||||||
} else {
|
|
||||||
mContext.unregisterReceiver(mReceiver);
|
|
||||||
}
|
|
||||||
mWifiTracker.setListening(register);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getSummary() {
|
|
||||||
if (!mWifiTracker.enabled) {
|
|
||||||
return mContext.getString(R.string.switch_off_text);
|
|
||||||
}
|
|
||||||
if (!mWifiTracker.connected) {
|
|
||||||
return mContext.getString(R.string.disconnected);
|
|
||||||
}
|
|
||||||
String ssid = WifiInfo.sanitizeSsid(mWifiTracker.ssid);
|
|
||||||
if (TextUtils.isEmpty(mWifiTracker.statusLabel)) {
|
|
||||||
return ssid;
|
|
||||||
}
|
|
||||||
return mContext.getResources().getString(
|
|
||||||
com.android.settingslib.R.string.preference_summary_default_combination,
|
|
||||||
ssid, mWifiTracker.statusLabel);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* return true if Wi-Fi connected.
|
|
||||||
*/
|
|
||||||
public boolean isWifiConnected() {
|
|
||||||
return mWifiTracker.connected;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -55,6 +55,7 @@ import com.android.settingslib.spa.widget.ui.CategoryTitle
|
|||||||
import com.android.wifitrackerlib.WifiEntry
|
import com.android.wifitrackerlib.WifiEntry
|
||||||
import java.time.Clock
|
import java.time.Clock
|
||||||
import java.time.ZoneOffset
|
import java.time.ZoneOffset
|
||||||
|
import java.util.Base64
|
||||||
|
|
||||||
const val WIFI_ENTRY_KEY = "wifiEntryKey"
|
const val WIFI_ENTRY_KEY = "wifiEntryKey"
|
||||||
|
|
||||||
@@ -68,7 +69,8 @@ object WifiPrivacyPageProvider : SettingsPageProvider {
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
override fun Page(arguments: Bundle?) {
|
override fun Page(arguments: Bundle?) {
|
||||||
val wifiEntryKey = arguments!!.getString(WIFI_ENTRY_KEY)
|
val wifiEntryKey =
|
||||||
|
String(Base64.getUrlDecoder().decode(arguments!!.getString(WIFI_ENTRY_KEY)))
|
||||||
if (wifiEntryKey != null) {
|
if (wifiEntryKey != null) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val lifecycle = LocalLifecycleOwner.current.lifecycle
|
val lifecycle = LocalLifecycleOwner.current.lifecycle
|
||||||
@@ -81,7 +83,7 @@ object WifiPrivacyPageProvider : SettingsPageProvider {
|
|||||||
|
|
||||||
fun getRoute(
|
fun getRoute(
|
||||||
wifiEntryKey: String,
|
wifiEntryKey: String,
|
||||||
): String = "${name}/$wifiEntryKey"
|
): String = "${name}/${Base64.getUrlEncoder().encodeToString(wifiEntryKey.toByteArray())}"
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
|||||||
@@ -250,7 +250,7 @@ public class AppInfoWithHeaderTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean hasInteractAcrossUsersPermission() {
|
protected boolean hasInteractAcrossUsersFullPermission() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,7 +267,7 @@ public class AppInfoWithHeaderTest {
|
|||||||
|
|
||||||
private static final class TestFragmentWithoutPermission extends TestFragment {
|
private static final class TestFragmentWithoutPermission extends TestFragment {
|
||||||
@Override
|
@Override
|
||||||
protected boolean hasInteractAcrossUsersPermission() {
|
protected boolean hasInteractAcrossUsersFullPermission() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ public final class PeriodicJobReceiverTest {
|
|||||||
|
|
||||||
mReceiver.onReceive(mContext, JOB_UPDATE_INTENT);
|
mReceiver.onReceive(mContext, JOB_UPDATE_INTENT);
|
||||||
|
|
||||||
TimeUnit.MILLISECONDS.sleep(100);
|
TimeUnit.MILLISECONDS.sleep(1000);
|
||||||
assertThat(mDao.getAllAfter(0)).hasSize(1);
|
assertThat(mDao.getAllAfter(0)).hasSize(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,7 +119,7 @@ public final class PeriodicJobReceiverTest {
|
|||||||
|
|
||||||
mReceiver.onReceive(mContext, JOB_UPDATE_INTENT);
|
mReceiver.onReceive(mContext, JOB_UPDATE_INTENT);
|
||||||
|
|
||||||
TimeUnit.MILLISECONDS.sleep(100);
|
TimeUnit.MILLISECONDS.sleep(1000);
|
||||||
assertThat(mDao.getAllAfter(0)).hasSize(3);
|
assertThat(mDao.getAllAfter(0)).hasSize(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ import org.junit.runner.RunWith;
|
|||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.shadows.ShadowLooper;
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
@EnableFlags(Flags.FLAG_MODES_UI)
|
@EnableFlags(Flags.FLAG_MODES_UI)
|
||||||
@@ -45,18 +44,18 @@ public class ZenModesListItemPreferenceTest {
|
|||||||
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
private final ZenIconLoader mIconLoader = new ZenIconLoader(
|
||||||
|
MoreExecutors.newDirectExecutorService());
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mContext = RuntimeEnvironment.application;
|
mContext = RuntimeEnvironment.application;
|
||||||
ZenIconLoader.setInstance(new ZenIconLoader(MoreExecutors.newDirectExecutorService()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void constructor_setsMode() {
|
public void constructor_setsMode() {
|
||||||
ZenModesListItemPreference preference = new ZenModesListItemPreference(mContext,
|
ZenModesListItemPreference preference = newPreference(TestModeBuilder.EXAMPLE);
|
||||||
TestModeBuilder.EXAMPLE);
|
|
||||||
|
|
||||||
assertThat(preference.getKey()).isEqualTo(TestModeBuilder.EXAMPLE.getId());
|
assertThat(preference.getKey()).isEqualTo(TestModeBuilder.EXAMPLE.getId());
|
||||||
assertThat(preference.getZenMode()).isEqualTo(TestModeBuilder.EXAMPLE);
|
assertThat(preference.getZenMode()).isEqualTo(TestModeBuilder.EXAMPLE);
|
||||||
@@ -70,8 +69,7 @@ public class ZenModesListItemPreferenceTest {
|
|||||||
.setEnabled(true)
|
.setEnabled(true)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
ZenModesListItemPreference preference = new ZenModesListItemPreference(mContext, mode);
|
ZenModesListItemPreference preference = newPreference(mode);
|
||||||
ShadowLooper.idleMainLooper(); // To load icon.
|
|
||||||
|
|
||||||
assertThat(preference.getTitle()).isEqualTo("Enabled mode");
|
assertThat(preference.getTitle()).isEqualTo("Enabled mode");
|
||||||
assertThat(preference.getSummary()).isEqualTo("When the thrush knocks");
|
assertThat(preference.getSummary()).isEqualTo("When the thrush knocks");
|
||||||
@@ -87,8 +85,7 @@ public class ZenModesListItemPreferenceTest {
|
|||||||
.setActive(true)
|
.setActive(true)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
ZenModesListItemPreference preference = new ZenModesListItemPreference(mContext, mode);
|
ZenModesListItemPreference preference = newPreference(mode);
|
||||||
ShadowLooper.idleMainLooper();
|
|
||||||
|
|
||||||
assertThat(preference.getTitle()).isEqualTo("Active mode");
|
assertThat(preference.getTitle()).isEqualTo("Active mode");
|
||||||
assertThat(preference.getSummary()).isEqualTo("ON • When Birnam forest comes to Dunsinane");
|
assertThat(preference.getSummary()).isEqualTo("ON • When Birnam forest comes to Dunsinane");
|
||||||
@@ -103,8 +100,7 @@ public class ZenModesListItemPreferenceTest {
|
|||||||
.setEnabled(false, /* byUser= */ false)
|
.setEnabled(false, /* byUser= */ false)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
ZenModesListItemPreference preference = new ZenModesListItemPreference(mContext, mode);
|
ZenModesListItemPreference preference = newPreference(mode);
|
||||||
ShadowLooper.idleMainLooper();
|
|
||||||
|
|
||||||
assertThat(preference.getTitle()).isEqualTo("Mode disabled by app");
|
assertThat(preference.getTitle()).isEqualTo("Mode disabled by app");
|
||||||
assertThat(preference.getSummary()).isEqualTo("Not set");
|
assertThat(preference.getSummary()).isEqualTo("Not set");
|
||||||
@@ -119,11 +115,15 @@ public class ZenModesListItemPreferenceTest {
|
|||||||
.setEnabled(false, /* byUser= */ true)
|
.setEnabled(false, /* byUser= */ true)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
ZenModesListItemPreference preference = new ZenModesListItemPreference(mContext, mode);
|
ZenModesListItemPreference preference = newPreference(mode);
|
||||||
ShadowLooper.idleMainLooper();
|
|
||||||
|
|
||||||
assertThat(preference.getTitle()).isEqualTo("Mode disabled by user");
|
assertThat(preference.getTitle()).isEqualTo("Mode disabled by user");
|
||||||
assertThat(preference.getSummary()).isEqualTo("Disabled");
|
assertThat(preference.getSummary()).isEqualTo("Disabled");
|
||||||
assertThat(preference.getIcon()).isNotNull();
|
assertThat(preference.getIcon()).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ZenModesListItemPreference newPreference(ZenMode zenMode) {
|
||||||
|
return new ZenModesListItemPreference(mContext, mIconLoader, MoreExecutors.directExecutor(),
|
||||||
|
zenMode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,11 +40,13 @@ import androidx.preference.PreferenceManager;
|
|||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settingslib.notification.modes.TestModeBuilder;
|
import com.android.settingslib.notification.modes.TestModeBuilder;
|
||||||
|
import com.android.settingslib.notification.modes.ZenIconLoader;
|
||||||
import com.android.settingslib.notification.modes.ZenMode;
|
import com.android.settingslib.notification.modes.ZenMode;
|
||||||
import com.android.settingslib.notification.modes.ZenModesBackend;
|
import com.android.settingslib.notification.modes.ZenModesBackend;
|
||||||
import com.android.settingslib.search.SearchIndexableRaw;
|
import com.android.settingslib.search.SearchIndexableRaw;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.google.common.util.concurrent.MoreExecutors;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
@@ -95,7 +97,8 @@ public class ZenModesListPreferenceControllerTest {
|
|||||||
PreferenceScreen preferenceScreen = preferenceManager.createPreferenceScreen(mContext);
|
PreferenceScreen preferenceScreen = preferenceManager.createPreferenceScreen(mContext);
|
||||||
preferenceScreen.addPreference(mPreference);
|
preferenceScreen.addPreference(mPreference);
|
||||||
|
|
||||||
mPrefController = new ZenModesListPreferenceController(mContext, mBackend);
|
mPrefController = new ZenModesListPreferenceController(mContext, mBackend,
|
||||||
|
new ZenIconLoader(MoreExecutors.newDirectExecutorService()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -1,152 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 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;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
|
||||||
import static org.mockito.Mockito.doNothing;
|
|
||||||
import static org.mockito.Mockito.doReturn;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.spy;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.IntentFilter;
|
|
||||||
import android.net.wifi.WifiManager;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.widget.SummaryUpdater.OnSummaryChangeListener;
|
|
||||||
import com.android.settingslib.wifi.WifiStatusTracker;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
import org.robolectric.RobolectricTestRunner;
|
|
||||||
import org.robolectric.RuntimeEnvironment;
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
|
||||||
public class WifiSummaryUpdaterTest {
|
|
||||||
@Mock private WifiStatusTracker mWifiTracker;
|
|
||||||
@Mock private SummaryListener mListener;
|
|
||||||
|
|
||||||
private Context mContext;
|
|
||||||
private WifiSummaryUpdater mSummaryUpdater;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
mContext = spy(RuntimeEnvironment.application.getApplicationContext());
|
|
||||||
doReturn(mock(Intent.class)).when(mContext).registerReceiver(any(), any(), anyInt());
|
|
||||||
doNothing().when(mContext).unregisterReceiver(any(BroadcastReceiver.class));
|
|
||||||
|
|
||||||
mSummaryUpdater = new WifiSummaryUpdater(mContext, mListener, mWifiTracker);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void register_true_shouldRegisterListenerAndTracker() {
|
|
||||||
mSummaryUpdater.register(true);
|
|
||||||
|
|
||||||
verify(mContext).registerReceiver(any(BroadcastReceiver.class), any(IntentFilter.class),
|
|
||||||
anyInt());
|
|
||||||
verify(mWifiTracker).setListening(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void register_true_shouldFetchInitialStateAndSendSummaryChange() {
|
|
||||||
mSummaryUpdater.register(true);
|
|
||||||
|
|
||||||
verify(mWifiTracker).fetchInitialState();
|
|
||||||
verify(mListener).onSummaryChanged(anyString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void register_false_shouldUnregisterListenerAndTracker() {
|
|
||||||
mSummaryUpdater.register(true);
|
|
||||||
mSummaryUpdater.register(false);
|
|
||||||
|
|
||||||
verify(mContext).unregisterReceiver(any(BroadcastReceiver.class));
|
|
||||||
verify(mWifiTracker).setListening(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void onReceive_networkStateChanged_shouldSendSummaryChange() {
|
|
||||||
mSummaryUpdater.register(true);
|
|
||||||
mContext.sendBroadcast(new Intent(WifiManager.NETWORK_STATE_CHANGED_ACTION));
|
|
||||||
|
|
||||||
verify(mListener).onSummaryChanged(anyString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void onReceive_rssiChanged_shouldSendSummaryChange() {
|
|
||||||
mSummaryUpdater.register(true);
|
|
||||||
mContext.sendBroadcast(new Intent(WifiManager.RSSI_CHANGED_ACTION));
|
|
||||||
|
|
||||||
verify(mListener).onSummaryChanged(anyString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getSummary_wifiDisabled_shouldReturnDisabled() {
|
|
||||||
mWifiTracker.enabled = false;
|
|
||||||
|
|
||||||
assertThat(mSummaryUpdater.getSummary())
|
|
||||||
.isEqualTo(mContext.getString(R.string.switch_off_text));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getSummary_wifiDisconnected_shouldReturnDisconnected() {
|
|
||||||
mWifiTracker.enabled = true;
|
|
||||||
mWifiTracker.connected = false;
|
|
||||||
|
|
||||||
assertThat(mSummaryUpdater.getSummary())
|
|
||||||
.isEqualTo(mContext.getString(R.string.disconnected));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getSummary_wifiConnected_shouldReturnSsid() {
|
|
||||||
mWifiTracker.enabled = true;
|
|
||||||
mWifiTracker.connected = true;
|
|
||||||
mWifiTracker.ssid = "Test Ssid";
|
|
||||||
|
|
||||||
assertThat(mSummaryUpdater.getSummary()).isEqualTo("Test Ssid");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getSummary_wifiConnected_withSpeedLabel_shouldReturnSsid_withSpeedLabel() {
|
|
||||||
mWifiTracker.enabled = true;
|
|
||||||
mWifiTracker.connected = true;
|
|
||||||
mWifiTracker.ssid = "Test Ssid";
|
|
||||||
mWifiTracker.statusLabel = "Very Fast";
|
|
||||||
|
|
||||||
assertThat(mSummaryUpdater.getSummary()).isEqualTo("Test Ssid / Very Fast");
|
|
||||||
}
|
|
||||||
|
|
||||||
private class SummaryListener implements OnSummaryChangeListener {
|
|
||||||
private String summary;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSummaryChanged(String summary) {
|
|
||||||
this.summary = summary;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,297 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2020 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.android.settings.network;
|
|
||||||
|
|
||||||
import static com.android.settings.network.InternetUpdater.INTERNET_NETWORKS_AVAILABLE;
|
|
||||||
import static com.android.settings.network.InternetUpdater.INTERNET_WIFI;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.times;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.IntentFilter;
|
|
||||||
import android.net.ConnectivityManager;
|
|
||||||
import android.net.NetworkRequest;
|
|
||||||
import android.net.NetworkScoreManager;
|
|
||||||
import android.net.wifi.WifiManager;
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.Looper;
|
|
||||||
|
|
||||||
import androidx.lifecycle.Lifecycle;
|
|
||||||
import androidx.lifecycle.LifecycleOwner;
|
|
||||||
import androidx.lifecycle.LifecycleRegistry;
|
|
||||||
import androidx.preference.Preference;
|
|
||||||
import androidx.preference.PreferenceManager;
|
|
||||||
import androidx.preference.PreferenceScreen;
|
|
||||||
import androidx.test.annotation.UiThreadTest;
|
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.testutils.ResourcesUtils;
|
|
||||||
import com.android.settings.wifi.WifiPickerTrackerHelper;
|
|
||||||
import com.android.settings.wifi.WifiSummaryUpdater;
|
|
||||||
import com.android.settingslib.mobile.dataservice.SubscriptionInfoEntity;
|
|
||||||
import com.android.wifitrackerlib.HotspotNetworkEntry;
|
|
||||||
import com.android.wifitrackerlib.StandardWifiEntry;
|
|
||||||
import com.android.wifitrackerlib.WifiPickerTracker;
|
|
||||||
|
|
||||||
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.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
|
||||||
public class InternetPreferenceControllerTest {
|
|
||||||
|
|
||||||
private static final String TEST_SUMMARY = "test summary";
|
|
||||||
private static final String TEST_ALTERNATE_SUMMARY = "test alternate summary";
|
|
||||||
private static final String NOT_CONNECTED = "Not connected";
|
|
||||||
private static final String SUB_ID_1 = "1";
|
|
||||||
private static final String SUB_ID_2 = "2";
|
|
||||||
private static final String DISPLAY_NAME_1 = "Sub 1";
|
|
||||||
private static final String DISPLAY_NAME_2 = "Sub 2";
|
|
||||||
|
|
||||||
@Rule
|
|
||||||
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
|
|
||||||
@Spy
|
|
||||||
private Context mContext = ApplicationProvider.getApplicationContext();
|
|
||||||
@Mock
|
|
||||||
private SubscriptionInfoEntity mActiveSubInfo;
|
|
||||||
@Mock
|
|
||||||
private SubscriptionInfoEntity mDefaultDataSubInfo;
|
|
||||||
@Mock
|
|
||||||
private ConnectivityManager mConnectivityManager;
|
|
||||||
@Mock
|
|
||||||
private LifecycleOwner mLifecycleOwner;
|
|
||||||
@Mock
|
|
||||||
private WifiManager mWifiManager;
|
|
||||||
@Mock
|
|
||||||
private WifiSummaryUpdater mSummaryHelper;
|
|
||||||
@Mock
|
|
||||||
private WifiPickerTrackerHelper mWifiPickerTrackerHelper;
|
|
||||||
@Mock
|
|
||||||
private WifiPickerTracker mWifiPickerTracker;
|
|
||||||
@Mock
|
|
||||||
private HotspotNetworkEntry mHotspotNetworkEntry;
|
|
||||||
|
|
||||||
private LifecycleRegistry mLifecycleRegistry;
|
|
||||||
|
|
||||||
private MockInternetPreferenceController mController;
|
|
||||||
private PreferenceScreen mScreen;
|
|
||||||
private Preference mPreference;
|
|
||||||
private List<SubscriptionInfoEntity> mSubscriptionInfoEntityList = new ArrayList<>();
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
when(mContext.getSystemService(ConnectivityManager.class)).thenReturn(mConnectivityManager);
|
|
||||||
when(mContext.getSystemService(NetworkScoreManager.class))
|
|
||||||
.thenReturn(mock(NetworkScoreManager.class));
|
|
||||||
when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
|
|
||||||
when(mWifiManager.getWifiState()).thenReturn(WifiManager.WIFI_STATE_DISABLED);
|
|
||||||
when(mWifiPickerTrackerHelper.getWifiPickerTracker()).thenReturn(mWifiPickerTracker);
|
|
||||||
when(mWifiPickerTracker.getConnectedWifiEntry()).thenReturn(null /* WifiEntry */);
|
|
||||||
when(mHotspotNetworkEntry.getAlternateSummary()).thenReturn(TEST_ALTERNATE_SUMMARY);
|
|
||||||
|
|
||||||
if (Looper.myLooper() == null) {
|
|
||||||
Looper.prepare();
|
|
||||||
}
|
|
||||||
mLifecycleRegistry = new LifecycleRegistry(mLifecycleOwner);
|
|
||||||
when(mLifecycleOwner.getLifecycle()).thenReturn(mLifecycleRegistry);
|
|
||||||
mController = new MockInternetPreferenceController(mContext, mock(Lifecycle.class),
|
|
||||||
mLifecycleOwner);
|
|
||||||
mController.sIconMap.put(INTERNET_WIFI, 0);
|
|
||||||
mController.mWifiPickerTrackerHelper = mWifiPickerTrackerHelper;
|
|
||||||
|
|
||||||
final PreferenceManager preferenceManager = new PreferenceManager(mContext);
|
|
||||||
mScreen = preferenceManager.createPreferenceScreen(mContext);
|
|
||||||
mPreference = new Preference(mContext);
|
|
||||||
mPreference.setKey(InternetPreferenceController.KEY);
|
|
||||||
mScreen.addPreference(mPreference);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class MockInternetPreferenceController extends
|
|
||||||
com.android.settings.network.InternetPreferenceController {
|
|
||||||
|
|
||||||
private int mDefaultDataSubscriptionId;
|
|
||||||
public MockInternetPreferenceController(Context context, Lifecycle lifecycle,
|
|
||||||
LifecycleOwner lifecycleOwner) {
|
|
||||||
super(context, lifecycle, lifecycleOwner);
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<SubscriptionInfoEntity> mSubscriptionInfoEntity;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<SubscriptionInfoEntity> getSubscriptionInfoList() {
|
|
||||||
return mSubscriptionInfoEntity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSubscriptionInfoList(List<SubscriptionInfoEntity> list) {
|
|
||||||
mSubscriptionInfoEntity = list;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getDefaultDataSubscriptionId() {
|
|
||||||
return mDefaultDataSubscriptionId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDefaultDataSubscriptionId(int subscriptionId) {
|
|
||||||
mDefaultDataSubscriptionId = subscriptionId;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private SubscriptionInfoEntity setupSubscriptionInfoEntity(String subId, int slotId,
|
|
||||||
String displayName, boolean isVisible, boolean isValid, boolean isActive,
|
|
||||||
boolean isActiveData) {
|
|
||||||
return new SubscriptionInfoEntity(subId, slotId, false, false, displayName, isVisible,
|
|
||||||
false, isValid, isActive, isActiveData);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isAvailable_shouldMatchPrefFlag() {
|
|
||||||
assertThat(mController.isAvailable()).isEqualTo(
|
|
||||||
mContext.getResources().getBoolean(R.bool.config_show_internet_settings));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@UiThreadTest
|
|
||||||
public void onResume_shouldRegisterCallback() {
|
|
||||||
mController.onResume();
|
|
||||||
|
|
||||||
verify(mContext).registerReceiver(any(BroadcastReceiver.class), any(IntentFilter.class),
|
|
||||||
any(int.class));
|
|
||||||
verify(mConnectivityManager).registerNetworkCallback(
|
|
||||||
any(NetworkRequest.class),
|
|
||||||
any(ConnectivityManager.NetworkCallback.class),
|
|
||||||
any(Handler.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@UiThreadTest
|
|
||||||
public void onPause_shouldUnregisterCallback() {
|
|
||||||
mController.onResume();
|
|
||||||
mController.onPause();
|
|
||||||
|
|
||||||
verify(mContext, times(2)).unregisterReceiver(any(BroadcastReceiver.class));
|
|
||||||
verify(mConnectivityManager, times(2)).unregisterNetworkCallback(
|
|
||||||
any(ConnectivityManager.NetworkCallback.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void onSummaryChanged_internetWifi_updateSummary() {
|
|
||||||
when(mSummaryHelper.getSummary()).thenReturn(TEST_SUMMARY);
|
|
||||||
mController.mSummaryHelper = mSummaryHelper;
|
|
||||||
mController.onInternetTypeChanged(INTERNET_WIFI);
|
|
||||||
mController.displayPreference(mScreen);
|
|
||||||
|
|
||||||
mController.onSummaryChanged(TEST_SUMMARY);
|
|
||||||
|
|
||||||
assertThat(mPreference.getSummary()).isEqualTo(TEST_SUMMARY);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void onSummaryChanged_internetNetworksAvailable_notUpdateSummary() {
|
|
||||||
when(mSummaryHelper.getSummary()).thenReturn(TEST_SUMMARY);
|
|
||||||
mController.mSummaryHelper = mSummaryHelper;
|
|
||||||
mController.onInternetTypeChanged(INTERNET_NETWORKS_AVAILABLE);
|
|
||||||
mController.displayPreference(mScreen);
|
|
||||||
mPreference.setSummary(NOT_CONNECTED);
|
|
||||||
|
|
||||||
mController.onSummaryChanged(TEST_SUMMARY);
|
|
||||||
|
|
||||||
assertThat(mPreference.getSummary()).isNotEqualTo(TEST_SUMMARY);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updateCellularSummary_getNullSubscriptionInfo_shouldNotCrash() {
|
|
||||||
mController.setSubscriptionInfoList(mSubscriptionInfoEntityList);
|
|
||||||
|
|
||||||
mController.updateCellularSummary();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updateCellularSummary_getActiveSubscriptionInfo_cbrs() {
|
|
||||||
mController.setDefaultDataSubscriptionId(Integer.parseInt(SUB_ID_2));
|
|
||||||
mActiveSubInfo = setupSubscriptionInfoEntity(SUB_ID_1, 1, DISPLAY_NAME_1,
|
|
||||||
false, true, true, true);
|
|
||||||
mDefaultDataSubInfo = setupSubscriptionInfoEntity(SUB_ID_2, 1, DISPLAY_NAME_2,
|
|
||||||
false, true, true, false);
|
|
||||||
mSubscriptionInfoEntityList.add(mActiveSubInfo);
|
|
||||||
mSubscriptionInfoEntityList.add(mDefaultDataSubInfo);
|
|
||||||
mController.setSubscriptionInfoList(mSubscriptionInfoEntityList);
|
|
||||||
mController.displayPreference(mScreen);
|
|
||||||
|
|
||||||
mController.updateCellularSummary();
|
|
||||||
assertThat(mPreference.getSummary()).isEqualTo(DISPLAY_NAME_2);
|
|
||||||
|
|
||||||
mActiveSubInfo = setupSubscriptionInfoEntity(SUB_ID_1, 1, DISPLAY_NAME_1,
|
|
||||||
true, true, true, true);
|
|
||||||
mSubscriptionInfoEntityList.add(mActiveSubInfo);
|
|
||||||
mController.setSubscriptionInfoList(mSubscriptionInfoEntityList);
|
|
||||||
mController.onAvailableSubInfoChanged(mSubscriptionInfoEntityList);
|
|
||||||
final String expectedSummary =
|
|
||||||
ResourcesUtils.getResourcesString(mContext, "mobile_data_temp_using",
|
|
||||||
DISPLAY_NAME_1);
|
|
||||||
mController.updateCellularSummary();
|
|
||||||
assertThat(mPreference.getSummary()).isEqualTo(expectedSummary);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updateHotspotNetwork_isHotspotNetworkEntry_updateAlternateSummary() {
|
|
||||||
when(mWifiPickerTracker.getConnectedWifiEntry()).thenReturn(mHotspotNetworkEntry);
|
|
||||||
mController.onInternetTypeChanged(INTERNET_WIFI);
|
|
||||||
mController.displayPreference(mScreen);
|
|
||||||
mPreference.setSummary(TEST_SUMMARY);
|
|
||||||
|
|
||||||
mController.updateHotspotNetwork();
|
|
||||||
|
|
||||||
assertThat(mPreference.getSummary().toString()).isEqualTo(TEST_ALTERNATE_SUMMARY);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updateHotspotNetwork_notHotspotNetworkEntry_notChangeSummary() {
|
|
||||||
when(mWifiPickerTracker.getConnectedWifiEntry()).thenReturn(mock(StandardWifiEntry.class));
|
|
||||||
mController.onInternetTypeChanged(INTERNET_WIFI);
|
|
||||||
mController.displayPreference(mScreen);
|
|
||||||
mPreference.setSummary(TEST_SUMMARY);
|
|
||||||
|
|
||||||
mController.updateHotspotNetwork();
|
|
||||||
|
|
||||||
assertThat(mPreference.getSummary().toString()).isEqualTo(TEST_SUMMARY);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updateHotspotNetwork_hotspotNetworkNotEnabled_returnFalse() {
|
|
||||||
mController.mWifiPickerTrackerHelper = null;
|
|
||||||
|
|
||||||
assertThat(mController.updateHotspotNetwork()).isFalse();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user