Snap for 11816316 from 965da3df32 to 24Q3-release
Change-Id: Iedfe0a5abcdef2e999f20c1a94f62c6872816876
This commit is contained in:
@@ -20,6 +20,7 @@ message BatteryOptimizeHistoricalLogEntry {
|
||||
RESTORE = 4;
|
||||
BACKUP = 5;
|
||||
FORCE_RESET = 6;
|
||||
EXTERNAL_UPDATE = 7;
|
||||
}
|
||||
|
||||
optional string package_name = 1;
|
||||
|
||||
@@ -18,11 +18,10 @@ package com.android.settings.datausage.lib
|
||||
|
||||
import android.content.Context
|
||||
import android.net.NetworkTemplate
|
||||
import android.text.format.DateUtils
|
||||
import android.util.Range
|
||||
import com.android.settings.datausage.lib.NetworkCycleDataRepository.Companion.asFourWeeks
|
||||
import com.android.settings.datausage.lib.NetworkCycleDataRepository.Companion.bucketRange
|
||||
import com.android.settings.datausage.lib.NetworkCycleDataRepository.Companion.getCycles
|
||||
import com.android.settings.datausage.lib.NetworkCycleDataRepository.Companion.reverseBucketRange
|
||||
import com.android.settings.datausage.lib.NetworkStatsRepository.Companion.Bucket
|
||||
import com.android.settings.datausage.lib.NetworkStatsRepository.Companion.aggregate
|
||||
import com.android.settings.datausage.lib.NetworkStatsRepository.Companion.filterTime
|
||||
@@ -39,16 +38,11 @@ class NetworkCycleBucketRepository(
|
||||
getCycles().map { aggregateUsage(it) }.filter { it.usage > 0 }
|
||||
|
||||
private fun getCycles(): List<Range<Long>> =
|
||||
networkCycleDataRepository.getPolicy()?.getCycles() ?: queryCyclesAsFourWeeks()
|
||||
networkCycleDataRepository.getPolicy()?.getCycles().orEmpty()
|
||||
.ifEmpty { queryCyclesAsFourWeeks() }
|
||||
|
||||
private fun queryCyclesAsFourWeeks(): List<Range<Long>> {
|
||||
val timeRange = buckets.aggregate()?.timeRange ?: return emptyList()
|
||||
return reverseBucketRange(
|
||||
startTime = timeRange.lower,
|
||||
endTime = timeRange.upper,
|
||||
step = DateUtils.WEEK_IN_MILLIS * 4,
|
||||
)
|
||||
}
|
||||
private fun queryCyclesAsFourWeeks(): List<Range<Long>> =
|
||||
buckets.aggregate()?.timeRange.asFourWeeks()
|
||||
|
||||
fun queryChartData(usageData: NetworkUsageData) = NetworkCycleChartData(
|
||||
total = usageData,
|
||||
|
||||
@@ -42,16 +42,10 @@ class NetworkCycleDataRepository(
|
||||
fun loadFirstCycle(): NetworkUsageData? = getCycles().firstOrNull()?.let { queryUsage(it) }
|
||||
|
||||
override fun getCycles(): List<Range<Long>> =
|
||||
getPolicy()?.getCycles() ?: queryCyclesAsFourWeeks()
|
||||
getPolicy()?.getCycles().orEmpty().ifEmpty { queryCyclesAsFourWeeks() }
|
||||
|
||||
private fun queryCyclesAsFourWeeks(): List<Range<Long>> {
|
||||
val timeRange = networkStatsRepository.getTimeRange() ?: return emptyList()
|
||||
return reverseBucketRange(
|
||||
startTime = timeRange.lower,
|
||||
endTime = timeRange.upper,
|
||||
step = DateUtils.WEEK_IN_MILLIS * 4,
|
||||
)
|
||||
}
|
||||
private fun queryCyclesAsFourWeeks(): List<Range<Long>> =
|
||||
networkStatsRepository.getTimeRange().asFourWeeks()
|
||||
|
||||
override fun getPolicy(): NetworkPolicy? =
|
||||
with(NetworkPolicyEditor(policyManager)) {
|
||||
@@ -59,7 +53,6 @@ class NetworkCycleDataRepository(
|
||||
getPolicy(networkTemplate)
|
||||
}
|
||||
|
||||
|
||||
override fun queryUsage(range: Range<Long>) = NetworkUsageData(
|
||||
startTime = range.lower,
|
||||
endTime = range.upper,
|
||||
@@ -71,6 +64,15 @@ class NetworkCycleDataRepository(
|
||||
Range(it.lower.toInstant().toEpochMilli(), it.upper.toInstant().toEpochMilli())
|
||||
}.toList()
|
||||
|
||||
fun Range<Long>?.asFourWeeks(): List<Range<Long>> {
|
||||
val timeRange = this ?: return emptyList()
|
||||
return reverseBucketRange(
|
||||
startTime = timeRange.lower,
|
||||
endTime = timeRange.upper,
|
||||
step = DateUtils.WEEK_IN_MILLIS * 4,
|
||||
)
|
||||
}
|
||||
|
||||
fun bucketRange(startTime: Long, endTime: Long, step: Long): List<Range<Long>> =
|
||||
(startTime..endTime step step).zipWithNext(::Range)
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.android.settings.display;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
|
||||
@@ -79,7 +80,8 @@ public class EvenDimmerPreferenceController extends TogglePreferenceController {
|
||||
}
|
||||
|
||||
private boolean getEvenDimmerActivated() {
|
||||
return Settings.Secure.getFloat(mContext.getContentResolver(),
|
||||
Settings.Secure.EVEN_DIMMER_ACTIVATED, 0) == 1;
|
||||
return Settings.Secure.getFloatForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.EVEN_DIMMER_ACTIVATED,
|
||||
/* def= */ 1.0f, UserHandle.USER_CURRENT) == 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,9 @@ package com.android.settings.network;
|
||||
|
||||
import static android.provider.SettingsSlicesContract.KEY_AIRPLANE_MODE;
|
||||
|
||||
import static com.android.settings.network.SatelliteWarningDialogActivity.EXTRA_TYPE_OF_SATELLITE_WARNING_DIALOG;
|
||||
import static com.android.settings.network.SatelliteWarningDialogActivity.TYPE_IS_AIRPLANE_MODE;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
@@ -25,6 +28,7 @@ import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.provider.SettingsSlicesContract;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.fragment.app.Fragment;
|
||||
@@ -38,13 +42,20 @@ import com.android.settings.Utils;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnDestroy;
|
||||
import com.android.settingslib.core.lifecycle.events.OnResume;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
|
||||
public class AirplaneModePreferenceController extends TogglePreferenceController
|
||||
implements LifecycleObserver, OnStart, OnStop, OnDestroy,
|
||||
AirplaneModeEnabler.OnAirplaneModeChangedListener {
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class AirplaneModePreferenceController extends TogglePreferenceController
|
||||
implements LifecycleObserver, OnStart, OnResume, OnStop, OnDestroy,
|
||||
AirplaneModeEnabler.OnAirplaneModeChangedListener {
|
||||
private static final String TAG = AirplaneModePreferenceController.class.getSimpleName();
|
||||
public static final int REQUEST_CODE_EXIT_ECM = 1;
|
||||
|
||||
/**
|
||||
@@ -60,12 +71,15 @@ public class AirplaneModePreferenceController extends TogglePreferenceController
|
||||
private Fragment mFragment;
|
||||
private AirplaneModeEnabler mAirplaneModeEnabler;
|
||||
private TwoStatePreference mAirplaneModePreference;
|
||||
private SatelliteRepository mSatelliteRepository;
|
||||
@VisibleForTesting
|
||||
AtomicBoolean mIsSatelliteOn = new AtomicBoolean(false);
|
||||
|
||||
public AirplaneModePreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
|
||||
if (isAvailable(mContext)) {
|
||||
mAirplaneModeEnabler = new AirplaneModeEnabler(mContext, this);
|
||||
mSatelliteRepository = new SatelliteRepository(mContext);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,18 +94,28 @@ public class AirplaneModePreferenceController extends TogglePreferenceController
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
if (KEY_AIRPLANE_MODE.equals(preference.getKey()) && isAvailable()
|
||||
&& mAirplaneModeEnabler.isInEcmMode()) {
|
||||
if (KEY_AIRPLANE_MODE.equals(preference.getKey()) && isAvailable()) {
|
||||
// In ECM mode launch ECM app dialog
|
||||
if (mFragment != null) {
|
||||
mFragment.startActivityForResult(
|
||||
new Intent(TelephonyManager.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null)
|
||||
.setPackage(Utils.PHONE_PACKAGE_NAME),
|
||||
REQUEST_CODE_EXIT_ECM);
|
||||
if (mAirplaneModeEnabler.isInEcmMode()) {
|
||||
if (mFragment != null) {
|
||||
mFragment.startActivityForResult(
|
||||
new Intent(TelephonyManager.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null)
|
||||
.setPackage(Utils.PHONE_PACKAGE_NAME),
|
||||
REQUEST_CODE_EXIT_ECM);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (mIsSatelliteOn.get()) {
|
||||
mContext.startActivity(
|
||||
new Intent(mContext, SatelliteWarningDialogActivity.class)
|
||||
.putExtra(
|
||||
EXTRA_TYPE_OF_SATELLITE_WARNING_DIALOG,
|
||||
TYPE_IS_AIRPLANE_MODE)
|
||||
);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -134,6 +158,17 @@ public class AirplaneModePreferenceController extends TogglePreferenceController
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
try {
|
||||
mIsSatelliteOn.set(
|
||||
mSatelliteRepository.requestIsEnabled(Executors.newSingleThreadExecutor())
|
||||
.get(2000, TimeUnit.MILLISECONDS));
|
||||
} catch (ExecutionException | TimeoutException | InterruptedException e) {
|
||||
Log.e(TAG, "Error to get satellite status : " + e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
if (isAvailable()) {
|
||||
@@ -165,7 +200,7 @@ public class AirplaneModePreferenceController extends TogglePreferenceController
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
if (isChecked() == isChecked) {
|
||||
if (isChecked() == isChecked || mIsSatelliteOn.get()) {
|
||||
return false;
|
||||
}
|
||||
if (isAvailable()) {
|
||||
|
||||
@@ -91,7 +91,6 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
||||
private AirplaneModeObserver mAirplaneModeObserver;
|
||||
private DataRoamingObserver mDataRoamingObserver;
|
||||
private MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
private Map<Integer, MobileDataContentObserver> mDataContentObserverMap = new HashMap<>();
|
||||
private int mPhysicalSlotIndex = SubscriptionManager.INVALID_SIM_SLOT_INDEX;
|
||||
private int mLogicalSlotIndex = SubscriptionManager.INVALID_SIM_SLOT_INDEX;
|
||||
private int mCardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
|
||||
@@ -210,6 +209,9 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
||||
*/
|
||||
public void addRegister(LifecycleOwner lifecycleOwner,
|
||||
MobileNetworkCallback mobileNetworkCallback, int subId) {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "addRegister by SUB ID " + subId);
|
||||
}
|
||||
if (sCallbacks.isEmpty()) {
|
||||
mSubscriptionManager.addOnSubscriptionsChangedListener(mContext.getMainExecutor(),
|
||||
this);
|
||||
@@ -221,7 +223,6 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
||||
observeAllUiccInfo(lifecycleOwner);
|
||||
observeAllMobileNetworkInfo(lifecycleOwner);
|
||||
if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||
addRegisterBySubId(subId);
|
||||
createTelephonyManagerBySubId(subId);
|
||||
mDataRoamingObserver.register(mContext, subId);
|
||||
}
|
||||
@@ -230,21 +231,6 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
||||
sendAvailableSubInfoCache(mobileNetworkCallback);
|
||||
}
|
||||
|
||||
public void addRegisterBySubId(int subId) {
|
||||
Log.d(TAG, "MobileDataContentObserver addRegisterBySubId: " + subId);
|
||||
MobileDataContentObserver dataContentObserver = new MobileDataContentObserver(
|
||||
new Handler(Looper.getMainLooper()));
|
||||
dataContentObserver.setOnMobileDataChangedListener(() -> {
|
||||
sExecutor.execute(() -> {
|
||||
Log.d(TAG, "MobileDataContentObserver changed");
|
||||
insertMobileNetworkInfo(mContext, subId,
|
||||
getTelephonyManagerBySubId(mContext, subId));
|
||||
});
|
||||
});
|
||||
dataContentObserver.register(mContext, subId);
|
||||
mDataContentObserverMap.put(subId, dataContentObserver);
|
||||
}
|
||||
|
||||
private void createTelephonyManagerBySubId(int subId) {
|
||||
if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID
|
||||
|| mTelephonyCallbackMap.containsKey(subId)) {
|
||||
@@ -254,7 +240,7 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
||||
return;
|
||||
}
|
||||
PhoneCallStateTelephonyCallback
|
||||
telephonyCallback = new PhoneCallStateTelephonyCallback();
|
||||
telephonyCallback = new PhoneCallStateTelephonyCallback(subId);
|
||||
TelephonyManager telephonyManager = mContext.getSystemService(
|
||||
TelephonyManager.class).createForSubscriptionId(subId);
|
||||
telephonyManager.registerTelephonyCallback(mContext.getMainExecutor(),
|
||||
@@ -293,10 +279,6 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mDataContentObserverMap.containsKey(subId)) {
|
||||
mDataContentObserverMap.get(subId).unRegister(mContext);
|
||||
mDataContentObserverMap.remove(subId);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeRegister(MobileNetworkCallback mobileNetworkCallback) {
|
||||
@@ -307,10 +289,6 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
||||
mSubscriptionManager.removeOnSubscriptionsChangedListener(this);
|
||||
mAirplaneModeObserver.unRegister(mContext);
|
||||
mDataRoamingObserver.unRegister(mContext);
|
||||
mDataContentObserverMap.forEach((id, observer) -> {
|
||||
observer.unRegister(mContext);
|
||||
});
|
||||
mDataContentObserverMap.clear();
|
||||
|
||||
mTelephonyManagerMap.forEach((id, manager) -> {
|
||||
TelephonyCallback callback = mTelephonyCallbackMap.get(id);
|
||||
@@ -763,7 +741,14 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
||||
}
|
||||
|
||||
private class PhoneCallStateTelephonyCallback extends TelephonyCallback implements
|
||||
TelephonyCallback.CallStateListener {
|
||||
TelephonyCallback.CallStateListener,
|
||||
TelephonyCallback.UserMobileDataStateListener {
|
||||
|
||||
private int mSubId;
|
||||
|
||||
public PhoneCallStateTelephonyCallback(int subId) {
|
||||
mSubId = subId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCallStateChanged(int state) {
|
||||
@@ -771,6 +756,15 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
||||
callback.onCallStateChanged(state);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUserMobileDataStateChanged(boolean enabled) {
|
||||
Log.d(TAG, "onUserMobileDataStateChanged enabled " + enabled + " on SUB " + mSubId);
|
||||
sExecutor.execute(() -> {
|
||||
insertMobileNetworkInfo(mContext, mSubId,
|
||||
getTelephonyManagerBySubId(mContext, mSubId));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,7 +41,7 @@ class SatelliteWarningDialogActivity : SpaDialogWindowTypeActivity() {
|
||||
}
|
||||
|
||||
override fun getDialogWindowType(): Int {
|
||||
return WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
|
||||
return WindowManager.LayoutParams.LAST_APPLICATION_WINDOW
|
||||
}
|
||||
|
||||
@Composable
|
||||
|
||||
@@ -100,9 +100,6 @@ public abstract class DefaultSubscriptionController extends TelephonyBasePrefere
|
||||
mMobileNetworkRepository.addRegister(mLifecycleOwner, this,
|
||||
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||
mMobileNetworkRepository.updateEntity();
|
||||
// Can not get default subId from database until get the callback, add register by subId
|
||||
// later.
|
||||
mMobileNetworkRepository.addRegisterBySubId(getDefaultSubscriptionId());
|
||||
mDataSubscriptionChangedReceiver.registerReceiver();
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ import com.android.settings.slices.SliceBuilderUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public class NfcPanel implements PanelContent {
|
||||
|
||||
private final Context mContext;
|
||||
|
||||
@@ -77,7 +77,14 @@ public class PanelFeatureProviderImpl implements PanelFeatureProvider {
|
||||
context.sendBroadcast(volumeIntent);
|
||||
return null;
|
||||
} else {
|
||||
return VolumePanel.create(context);
|
||||
if (Flags.slicesRetirement()) {
|
||||
Intent volIntent = new Intent(Settings.ACTION_SOUND_SETTINGS);
|
||||
volIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(volIntent);
|
||||
return null;
|
||||
} else {
|
||||
return VolumePanel.create(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,10 @@ import java.util.concurrent.FutureTask;
|
||||
|
||||
/**
|
||||
* Panel data class for Volume settings.
|
||||
*
|
||||
* @deprecated this is no longer used after V and will be removed.
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public class VolumePanel implements PanelContent, LifecycleObserver {
|
||||
private static final String TAG = "VolumePanel";
|
||||
|
||||
|
||||
@@ -32,7 +32,10 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* Panel data class for Wifi settings.
|
||||
*
|
||||
* @deprecated this is not used after V and will be removed.
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public class WifiPanel implements PanelContent {
|
||||
|
||||
private final Context mContext;
|
||||
|
||||
@@ -385,6 +385,10 @@ public class SimSlotChangeHandler {
|
||||
}
|
||||
|
||||
private void startSimConfirmDialogActivity(int subId) {
|
||||
if (!isSuwFinished(mContext)) {
|
||||
Log.d(TAG, "Still in SUW. Do nothing");
|
||||
return;
|
||||
}
|
||||
if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
|
||||
Log.i(TAG, "Unable to enable subscription due to invalid subscription ID.");
|
||||
return;
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
|
||||
package com.android.settings.wifi;
|
||||
|
||||
import static com.android.settings.network.SatelliteWarningDialogActivity.EXTRA_TYPE_OF_SATELLITE_WARNING_DIALOG;
|
||||
import static com.android.settings.network.SatelliteWarningDialogActivity.TYPE_IS_WIFI;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
@@ -27,19 +30,26 @@ import android.net.wifi.SupplicantState;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.network.SatelliteRepository;
|
||||
import com.android.settings.network.SatelliteWarningDialogActivity;
|
||||
import com.android.settings.widget.SwitchWidgetController;
|
||||
import com.android.settingslib.WirelessUtils;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class WifiEnabler implements SwitchWidgetController.OnSwitchChangeListener {
|
||||
|
||||
private static final String TAG = WifiEnabler.class.getSimpleName();
|
||||
private final SwitchWidgetController mSwitchWidget;
|
||||
private final WifiManager mWifiManager;
|
||||
private final ConnectivityManager mConnectivityManager;
|
||||
@@ -48,7 +58,9 @@ public class WifiEnabler implements SwitchWidgetController.OnSwitchChangeListene
|
||||
private Context mContext;
|
||||
private boolean mListeningToOnSwitchChange = false;
|
||||
private AtomicBoolean mConnected = new AtomicBoolean(false);
|
||||
|
||||
private SatelliteRepository mSatelliteRepository;
|
||||
@VisibleForTesting
|
||||
AtomicBoolean mIsSatelliteOn = new AtomicBoolean(false);
|
||||
|
||||
private boolean mStateMachineEvent;
|
||||
private final IntentFilter mIntentFilter;
|
||||
@@ -93,7 +105,7 @@ public class WifiEnabler implements SwitchWidgetController.OnSwitchChangeListene
|
||||
// The order matters! We really should not depend on this. :(
|
||||
mIntentFilter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);
|
||||
mIntentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
||||
|
||||
mSatelliteRepository = new SatelliteRepository(context);
|
||||
setupSwitchController();
|
||||
}
|
||||
|
||||
@@ -124,6 +136,14 @@ public class WifiEnabler implements SwitchWidgetController.OnSwitchChangeListene
|
||||
mSwitchWidget.startListening();
|
||||
mListeningToOnSwitchChange = true;
|
||||
}
|
||||
// Refresh satellite mode status.
|
||||
try {
|
||||
mIsSatelliteOn.set(
|
||||
mSatelliteRepository.requestIsEnabled(Executors.newSingleThreadExecutor())
|
||||
.get(2000, TimeUnit.MILLISECONDS));
|
||||
} catch (ExecutionException | TimeoutException | InterruptedException e) {
|
||||
Log.e(TAG, "Error to get satellite status : " + e);
|
||||
}
|
||||
}
|
||||
|
||||
public void pause() {
|
||||
@@ -185,6 +205,18 @@ public class WifiEnabler implements SwitchWidgetController.OnSwitchChangeListene
|
||||
if (mStateMachineEvent) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Show dialog and do nothing under satellite mode.
|
||||
if (mIsSatelliteOn.get()) {
|
||||
mContext.startActivity(
|
||||
new Intent(mContext, SatelliteWarningDialogActivity.class)
|
||||
.putExtra(
|
||||
EXTRA_TYPE_OF_SATELLITE_WARNING_DIALOG,
|
||||
TYPE_IS_WIFI)
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Show toast message if Wi-Fi is not allowed in airplane mode
|
||||
if (isChecked && !WirelessUtils.isRadioAllowed(mContext, Settings.Global.RADIO_WIFI)) {
|
||||
Toast.makeText(mContext, R.string.wifi_in_airplane_mode, Toast.LENGTH_SHORT).show();
|
||||
|
||||
@@ -32,7 +32,10 @@ import com.android.wifitrackerlib.WifiEntry.ConnectCallback;
|
||||
|
||||
/**
|
||||
* This receiver helps connect to Wi-Fi network
|
||||
*
|
||||
* @deprecated this is not used after V and will be removed.
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public class ConnectToWifiHandler extends BroadcastReceiver {
|
||||
|
||||
static final String KEY_CHOSEN_WIFIENTRY_KEY = "key_chosen_wifientry_key";
|
||||
|
||||
@@ -39,7 +39,10 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* {@link SliceBackgroundWorker} for Wi-Fi, used by {@link WifiSlice}.
|
||||
*
|
||||
* @deprecated this is not used after V and will be removed.
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public class WifiScanWorker extends SliceBackgroundWorker<WifiSliceItem> implements
|
||||
WifiPickerTracker.WifiPickerTrackerCallback, LifecycleOwner, WifiEntryCallback {
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ import com.android.settings.SubSettings;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.network.NetworkProviderSettings;
|
||||
import com.android.settings.network.SatelliteRepository;
|
||||
import com.android.settings.network.WifiSwitchPreferenceController;
|
||||
import com.android.settings.slices.CustomSliceable;
|
||||
import com.android.settings.slices.SliceBackgroundWorker;
|
||||
@@ -66,11 +67,18 @@ import com.android.wifitrackerlib.WifiEntry;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* {@link CustomSliceable} for Wi-Fi, used by generic clients.
|
||||
*
|
||||
* @deprecated This is not used after V and will be removed.
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public class WifiSlice implements CustomSliceable {
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -225,7 +233,8 @@ public class WifiSlice implements CustomSliceable {
|
||||
.setAccentColor(COLOR_NOT_TINTED)
|
||||
.setKeywords(getKeywords())
|
||||
.addRow(getHeaderRow(isWifiEnabled, wifiSliceItem));
|
||||
if (!isWiFiPermissionGranted || !mWifiRestriction.isChangeWifiStateAllowed(mContext)) {
|
||||
if (!isWiFiPermissionGranted || !mWifiRestriction.isChangeWifiStateAllowed(mContext)
|
||||
|| isSatelliteOn()) {
|
||||
return builder;
|
||||
}
|
||||
|
||||
@@ -416,4 +425,17 @@ public class WifiSlice implements CustomSliceable {
|
||||
return WifiEnterpriseRestrictionUtils.isChangeWifiStateAllowed(context);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isSatelliteOn() {
|
||||
SatelliteRepository satelliteRepository = new SatelliteRepository(mContext);
|
||||
boolean isSatelliteOn = false;
|
||||
try {
|
||||
isSatelliteOn =
|
||||
satelliteRepository.requestIsEnabled(Executors.newSingleThreadExecutor())
|
||||
.get(2000, TimeUnit.MILLISECONDS);
|
||||
} catch (ExecutionException | TimeoutException | InterruptedException e) {
|
||||
Log.e(TAG, "Error to get satellite status : " + e);
|
||||
}
|
||||
return isSatelliteOn;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,10 @@ import com.android.wifitrackerlib.WifiEntry;
|
||||
/**
|
||||
* The data set which is needed by a Wi-Fi Slice, it collects necessary data from {@link WifiEntry}
|
||||
* and provides similar getter methods for corresponding data.
|
||||
*
|
||||
* @deprecated this is not used after V and will be removed.
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public class WifiSliceItem {
|
||||
|
||||
private final Context mContext;
|
||||
|
||||
@@ -35,6 +35,7 @@ import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class VolumePanelTest {
|
||||
|
||||
|
||||
@@ -18,12 +18,15 @@ package com.android.settings.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.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.util.AndroidRuntimeException;
|
||||
|
||||
import com.android.settings.testutils.shadow.ShadowRestrictedLockUtilsInternal;
|
||||
import com.android.settings.widget.SwitchWidgetController;
|
||||
@@ -65,4 +68,17 @@ public class WifiEnablerTest {
|
||||
|
||||
assertThat(mEnabler.onSwitchToggled(true)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onSwitchToggled_satelliteOn_startWarningActivity() {
|
||||
mEnabler.mIsSatelliteOn.set(true);
|
||||
|
||||
try {
|
||||
mEnabler.onSwitchToggled(true);
|
||||
} catch (AndroidRuntimeException e) {
|
||||
// Catch exception of starting activity .
|
||||
}
|
||||
|
||||
verify(mContext).startActivity(any());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class WifiScanWorkerTest {
|
||||
|
||||
|
||||
@@ -72,6 +72,7 @@ import org.robolectric.shadows.ShadowBinder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {
|
||||
WifiSliceTest.ShadowSliceBackgroundWorker.class,
|
||||
|
||||
@@ -42,6 +42,13 @@ class NetworkCycleBucketRepositoryTest {
|
||||
|
||||
private val mockNetworkCycleDataRepository = mock<NetworkCycleDataRepository>()
|
||||
|
||||
private fun createRepository(buckets: List<Bucket>) = NetworkCycleBucketRepository(
|
||||
context = context,
|
||||
networkTemplate = template,
|
||||
buckets = buckets,
|
||||
networkCycleDataRepository = mockNetworkCycleDataRepository,
|
||||
)
|
||||
|
||||
@Test
|
||||
fun loadCycles_byPolicy() {
|
||||
val policy = mock<NetworkPolicy> {
|
||||
@@ -52,9 +59,7 @@ class NetworkCycleBucketRepositoryTest {
|
||||
mockNetworkCycleDataRepository.stub {
|
||||
on { getPolicy() } doReturn policy
|
||||
}
|
||||
val repository = NetworkCycleBucketRepository(
|
||||
context = context,
|
||||
networkTemplate = template,
|
||||
val repository = createRepository(
|
||||
buckets = listOf(
|
||||
Bucket(
|
||||
uid = 0,
|
||||
@@ -62,8 +67,7 @@ class NetworkCycleBucketRepositoryTest {
|
||||
startTimeStamp = CYCLE1_START_TIME,
|
||||
endTimeStamp = CYCLE1_END_TIME,
|
||||
)
|
||||
),
|
||||
networkCycleDataRepository = mockNetworkCycleDataRepository,
|
||||
)
|
||||
)
|
||||
|
||||
val cycles = repository.loadCycles()
|
||||
@@ -78,13 +82,14 @@ class NetworkCycleBucketRepositoryTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun loadCycles_asFourWeeks() {
|
||||
mockNetworkCycleDataRepository.stub {
|
||||
on { getPolicy() } doReturn null
|
||||
fun loadCycles_policyHasNoCycle_asFourWeeks() {
|
||||
val policy = mock<NetworkPolicy> {
|
||||
on { cycleIterator() } doReturn emptyList<Range<ZonedDateTime>>().iterator()
|
||||
}
|
||||
val repository = NetworkCycleBucketRepository(
|
||||
context = context,
|
||||
networkTemplate = template,
|
||||
mockNetworkCycleDataRepository.stub {
|
||||
on { getPolicy() } doReturn policy
|
||||
}
|
||||
val repository = createRepository(
|
||||
buckets = listOf(
|
||||
Bucket(
|
||||
uid = 0,
|
||||
@@ -92,8 +97,34 @@ class NetworkCycleBucketRepositoryTest {
|
||||
startTimeStamp = CYCLE2_START_TIME,
|
||||
endTimeStamp = CYCLE2_END_TIME,
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
val cycles = repository.loadCycles()
|
||||
|
||||
assertThat(cycles).containsExactly(
|
||||
NetworkUsageData(
|
||||
startTime = CYCLE2_END_TIME - DateUtils.WEEK_IN_MILLIS * 4,
|
||||
endTime = CYCLE2_END_TIME,
|
||||
usage = CYCLE2_BYTES,
|
||||
),
|
||||
networkCycleDataRepository = mockNetworkCycleDataRepository,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun loadCycles_noPolicy_asFourWeeks() {
|
||||
mockNetworkCycleDataRepository.stub {
|
||||
on { getPolicy() } doReturn null
|
||||
}
|
||||
val repository = createRepository(
|
||||
buckets = listOf(
|
||||
Bucket(
|
||||
uid = 0,
|
||||
bytes = CYCLE2_BYTES,
|
||||
startTimeStamp = CYCLE2_START_TIME,
|
||||
endTimeStamp = CYCLE2_END_TIME,
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
val cycles = repository.loadCycles()
|
||||
@@ -114,9 +145,7 @@ class NetworkCycleBucketRepositoryTest {
|
||||
endTime = CYCLE4_END_TIME,
|
||||
usage = CYCLE3_BYTES + CYCLE4_BYTES,
|
||||
)
|
||||
val repository = NetworkCycleBucketRepository(
|
||||
context = context,
|
||||
networkTemplate = template,
|
||||
val repository = createRepository(
|
||||
buckets = listOf(
|
||||
Bucket(
|
||||
uid = 0,
|
||||
@@ -131,7 +160,6 @@ class NetworkCycleBucketRepositoryTest {
|
||||
endTimeStamp = CYCLE4_END_TIME,
|
||||
),
|
||||
),
|
||||
networkCycleDataRepository = mockNetworkCycleDataRepository,
|
||||
)
|
||||
|
||||
val summary = repository.queryChartData(cycle)
|
||||
|
||||
@@ -25,6 +25,7 @@ import androidx.test.core.app.ApplicationProvider
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.android.settings.testutils.zonedDateTime
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import java.time.ZonedDateTime
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
@@ -77,7 +78,28 @@ class NetworkCycleDataRepositoryTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun loadFirstCycle_asFourWeeks() = runTest {
|
||||
fun loadFirstCycle_policyHasNoCycle_asFourWeeks() = runTest {
|
||||
val policy = mock<NetworkPolicy> {
|
||||
on { cycleIterator() } doReturn emptyList<Range<ZonedDateTime>>().iterator()
|
||||
}
|
||||
doReturn(policy).whenever(repository).getPolicy()
|
||||
mockNetworkStatsRepository.stub {
|
||||
on { getTimeRange() } doReturn Range(CYCLE2_START_TIME, CYCLE2_END_TIME)
|
||||
}
|
||||
|
||||
val firstCycle = repository.loadFirstCycle()
|
||||
|
||||
assertThat(firstCycle).isEqualTo(
|
||||
NetworkUsageData(
|
||||
startTime = CYCLE2_END_TIME - DateUtils.WEEK_IN_MILLIS * 4,
|
||||
endTime = CYCLE2_END_TIME,
|
||||
usage = CYCLE2_BYTES,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun loadFirstCycle_noPolicy_asFourWeeks() = runTest {
|
||||
doReturn(null).whenever(repository).getPolicy()
|
||||
mockNetworkStatsRepository.stub {
|
||||
on { getTimeRange() } doReturn Range(CYCLE2_START_TIME, CYCLE2_END_TIME)
|
||||
|
||||
@@ -16,10 +16,14 @@
|
||||
|
||||
package com.android.settings.network;
|
||||
|
||||
import static android.provider.SettingsSlicesContract.KEY_AIRPLANE_MODE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
@@ -28,6 +32,7 @@ import android.content.pm.PackageManager;
|
||||
import android.os.Looper;
|
||||
import android.provider.Settings;
|
||||
import android.provider.SettingsSlicesContract;
|
||||
import android.util.AndroidRuntimeException;
|
||||
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
@@ -73,12 +78,12 @@ public class AirplaneModePreferenceControllerTest {
|
||||
mResolver = mContext.getContentResolver();
|
||||
doReturn(mPackageManager).when(mContext).getPackageManager();
|
||||
mController = new AirplaneModePreferenceController(mContext,
|
||||
SettingsSlicesContract.KEY_AIRPLANE_MODE);
|
||||
KEY_AIRPLANE_MODE);
|
||||
|
||||
mPreferenceManager = new PreferenceManager(mContext);
|
||||
mScreen = mPreferenceManager.createPreferenceScreen(mContext);
|
||||
mPreference = new RestrictedSwitchPreference(mContext);
|
||||
mPreference.setKey(SettingsSlicesContract.KEY_AIRPLANE_MODE);
|
||||
mPreference.setKey(KEY_AIRPLANE_MODE);
|
||||
mScreen.addPreference(mPreference);
|
||||
mController.setFragment(null);
|
||||
}
|
||||
@@ -167,4 +172,18 @@ public class AirplaneModePreferenceControllerTest {
|
||||
public void isPublicSlice_returnsTrue() {
|
||||
assertThat(mController.isPublicSlice()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_satelliteOn_startWarningActivity() {
|
||||
mController.mIsSatelliteOn.set(true);
|
||||
when(mAirplaneModeEnabler.isInEcmMode()).thenReturn(false);
|
||||
|
||||
try {
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
} catch (AndroidRuntimeException e) {
|
||||
// Catch exception of starting activity .
|
||||
}
|
||||
|
||||
verify(mContext).startActivity(any());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class NfcPanelTest {
|
||||
|
||||
|
||||
@@ -27,12 +27,15 @@ import static org.mockito.Mockito.verify;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.platform.test.annotations.DisableFlags;
|
||||
import android.provider.Settings;
|
||||
import android.util.FeatureFlagUtils;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.flags.Flags;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -68,6 +71,7 @@ public class PanelFeatureProviderImplTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisableFlags(Flags.FLAG_SLICES_RETIREMENT)
|
||||
public void getPanel_volumePanel_returnsCorrectPanel() {
|
||||
FeatureFlagUtils.setEnabled(mContext, FeatureFlagUtils.SETTINGS_VOLUME_PANEL_IN_SYSTEMUI,
|
||||
false);
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class WifiPanelTest {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user