Snap for 6344429 from ee255b5cda to mainline-release
Change-Id: I10db60ab2b68967da0cd9984fb512de1959f23ab
This commit is contained in:
@@ -1,24 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!--
|
|
||||||
~ Copyright (C) 2018 The Android Open Source Project
|
|
||||||
~
|
|
||||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
~ you may not use this file except in compliance with the License.
|
|
||||||
~ You may obtain a copy of the License at
|
|
||||||
~
|
|
||||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
~
|
|
||||||
~ Unless required by applicable law or agreed to in writing, software
|
|
||||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
~ See the License for the specific language governing permissions and
|
|
||||||
~ limitations under the License
|
|
||||||
-->
|
|
||||||
|
|
||||||
<set xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:shareInterpolator="false"
|
|
||||||
android:zAdjustment="top">
|
|
||||||
<alpha android:fromAlpha="0.0" android:toAlpha="1.0"
|
|
||||||
android:interpolator="@android:interpolator/linear_out_slow_in"
|
|
||||||
android:duration="350"/>
|
|
||||||
</set>
|
|
||||||
@@ -47,22 +47,21 @@
|
|||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="33dp"
|
||||||
android:layout_marginTop="2dp"
|
android:layout_marginTop="2dp"
|
||||||
android:layout_gravity="center_horizontal"
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:gravity="center"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/bt_battery_icon"
|
android:id="@+id/bt_battery_icon"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"/>
|
||||||
android:layout_gravity="center"/>
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/bt_battery_summary"
|
android:id="@+id/bt_battery_summary"
|
||||||
style="@style/TextAppearance.EntityHeaderSummary"
|
style="@style/TextAppearance.EntityHeaderSummary"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="4dp"
|
android:layout_marginStart="4dp"/>
|
||||||
android:layout_gravity="center_horizontal"/>
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
@@ -408,6 +408,9 @@
|
|||||||
<!-- Battery meter icon size of advanced bluetooth device -->
|
<!-- Battery meter icon size of advanced bluetooth device -->
|
||||||
<dimen name="advanced_bluetooth_battery_meter_width">7.8dp</dimen>
|
<dimen name="advanced_bluetooth_battery_meter_width">7.8dp</dimen>
|
||||||
<dimen name="advanced_bluetooth_battery_meter_height">13dp</dimen>
|
<dimen name="advanced_bluetooth_battery_meter_height">13dp</dimen>
|
||||||
|
<dimen name="advanced_bluetooth_battery_width">15.5dp</dimen>
|
||||||
|
<dimen name="advanced_bluetooth_battery_height">27.5dp</dimen>
|
||||||
|
<dimen name="advanced_bluetooth_battery_right_margin">-4dp</dimen>
|
||||||
|
|
||||||
<!-- Developer option bluetooth settings dialog -->
|
<!-- Developer option bluetooth settings dialog -->
|
||||||
<dimen name="developer_option_dialog_margin_start">8dp</dimen>
|
<dimen name="developer_option_dialog_margin_start">8dp</dimen>
|
||||||
|
|||||||
@@ -344,6 +344,8 @@ public class MasterClear extends InstrumentedFragment implements OnGlobalLayoutL
|
|||||||
noCancelMobilePlan.setVisibility(View.VISIBLE);
|
noCancelMobilePlan.setVisibility(View.VISIBLE);
|
||||||
mEsimStorage.setChecked(true /* checked */);
|
mEsimStorage.setChecked(true /* checked */);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
mEsimStorage.setChecked(false /* checked */);
|
||||||
}
|
}
|
||||||
|
|
||||||
final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
|
final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import android.provider.DeviceConfig;
|
|||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
@@ -191,11 +192,9 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
|
|||||||
context.getResources().getDimensionPixelSize(
|
context.getResources().getDimensionPixelSize(
|
||||||
R.dimen.advanced_bluetooth_battery_meter_height));
|
R.dimen.advanced_bluetooth_battery_meter_height));
|
||||||
drawable.setBatteryLevel(level);
|
drawable.setBatteryLevel(level);
|
||||||
final int attr = level > LOW_BATTERY_LEVEL || charging
|
|
||||||
? android.R.attr.colorControlNormal
|
|
||||||
: android.R.attr.colorError;
|
|
||||||
drawable.setColorFilter(new PorterDuffColorFilter(
|
drawable.setColorFilter(new PorterDuffColorFilter(
|
||||||
com.android.settings.Utils.getColorAttrDefaultColor(context, attr),
|
com.android.settings.Utils.getColorAttrDefaultColor(context,
|
||||||
|
android.R.attr.colorControlNormal),
|
||||||
PorterDuff.Mode.SRC));
|
PorterDuff.Mode.SRC));
|
||||||
drawable.setCharging(charging);
|
drawable.setCharging(charging);
|
||||||
|
|
||||||
@@ -218,12 +217,10 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
|
|||||||
final boolean charging = BluetoothUtils.getBooleanMetaData(bluetoothDevice, chargeMetaKey);
|
final boolean charging = BluetoothUtils.getBooleanMetaData(bluetoothDevice, chargeMetaKey);
|
||||||
if (batteryLevel != BluetoothUtils.META_INT_ERROR) {
|
if (batteryLevel != BluetoothUtils.META_INT_ERROR) {
|
||||||
linearLayout.setVisibility(View.VISIBLE);
|
linearLayout.setVisibility(View.VISIBLE);
|
||||||
final ImageView imageView = linearLayout.findViewById(R.id.bt_battery_icon);
|
|
||||||
imageView.setImageDrawable(createBtBatteryIcon(mContext, batteryLevel, charging));
|
|
||||||
imageView.setVisibility(View.VISIBLE);
|
|
||||||
final TextView textView = linearLayout.findViewById(R.id.bt_battery_summary);
|
final TextView textView = linearLayout.findViewById(R.id.bt_battery_summary);
|
||||||
textView.setText(com.android.settings.Utils.formatPercentage(batteryLevel));
|
textView.setText(com.android.settings.Utils.formatPercentage(batteryLevel));
|
||||||
textView.setVisibility(View.VISIBLE);
|
textView.setVisibility(View.VISIBLE);
|
||||||
|
showBatteryIcon(linearLayout, batteryLevel, charging);
|
||||||
} else {
|
} else {
|
||||||
// Hide it if it doesn't have battery information
|
// Hide it if it doesn't have battery information
|
||||||
linearLayout.setVisibility(View.GONE);
|
linearLayout.setVisibility(View.GONE);
|
||||||
@@ -234,6 +231,28 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
|
|||||||
textView.setVisibility(View.VISIBLE);
|
textView.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showBatteryIcon(LinearLayout linearLayout, int level, boolean charging) {
|
||||||
|
boolean enableLowBattery = level <= LOW_BATTERY_LEVEL && !charging;
|
||||||
|
final ImageView imageView = linearLayout.findViewById(R.id.bt_battery_icon);
|
||||||
|
if (enableLowBattery) {
|
||||||
|
imageView.setImageDrawable(mContext.getDrawable(R.drawable.ic_battery_alert_24dp));
|
||||||
|
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
|
||||||
|
mContext.getResources().getDimensionPixelSize(
|
||||||
|
R.dimen.advanced_bluetooth_battery_width),
|
||||||
|
mContext.getResources().getDimensionPixelSize(
|
||||||
|
R.dimen.advanced_bluetooth_battery_height));
|
||||||
|
layoutParams.rightMargin = mContext.getResources().getDimensionPixelSize(
|
||||||
|
R.dimen.advanced_bluetooth_battery_right_margin);
|
||||||
|
imageView.setLayoutParams(layoutParams);
|
||||||
|
} else {
|
||||||
|
imageView.setImageDrawable(createBtBatteryIcon(mContext, level, charging));
|
||||||
|
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
|
||||||
|
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||||
|
imageView.setLayoutParams(layoutParams);
|
||||||
|
}
|
||||||
|
imageView.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
private void updateDisconnectLayout() {
|
private void updateDisconnectLayout() {
|
||||||
mLayoutPreference.findViewById(R.id.layout_left).setVisibility(View.GONE);
|
mLayoutPreference.findViewById(R.id.layout_left).setVisibility(View.GONE);
|
||||||
mLayoutPreference.findViewById(R.id.layout_right).setVisibility(View.GONE);
|
mLayoutPreference.findViewById(R.id.layout_right).setVisibility(View.GONE);
|
||||||
|
|||||||
@@ -466,6 +466,7 @@ public class EnabledNetworkModePreferenceController extends
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TelephonyManagerConstants.NETWORK_MODE_NR_LTE_CDMA_EVDO:
|
case TelephonyManagerConstants.NETWORK_MODE_NR_LTE_CDMA_EVDO:
|
||||||
|
case TelephonyManagerConstants.NETWORK_MODE_NR_LTE_GSM_WCDMA:
|
||||||
case TelephonyManagerConstants.NETWORK_MODE_NR_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
|
case TelephonyManagerConstants.NETWORK_MODE_NR_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
|
||||||
setSelectedEntry(networkMode);
|
setSelectedEntry(networkMode);
|
||||||
setSummary(mContext.getString(R.string.network_5G)
|
setSummary(mContext.getString(R.string.network_5G)
|
||||||
|
|||||||
@@ -70,6 +70,8 @@ public abstract class ConversationListPreferenceController extends AbstractPrefe
|
|||||||
|
|
||||||
if (containerGroup.getPreferenceCount() == 0) {
|
if (containerGroup.getPreferenceCount() == 0) {
|
||||||
containerGroup.setVisible(false);
|
containerGroup.setVisible(false);
|
||||||
|
} else {
|
||||||
|
containerGroup.setVisible(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,6 +77,13 @@ public class BiometricFragment extends InstrumentedFragment {
|
|||||||
mClientCallback.onAuthenticationFailed();
|
mClientCallback.onAuthenticationFailed();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSystemEvent(int event) {
|
||||||
|
mClientExecutor.execute(() -> {
|
||||||
|
mClientCallback.onSystemEvent(event);
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private final DialogInterface.OnClickListener mNegativeButtonListener =
|
private final DialogInterface.OnClickListener mNegativeButtonListener =
|
||||||
@@ -121,10 +128,6 @@ public class BiometricFragment extends InstrumentedFragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isAuthenticating() {
|
|
||||||
return mAuthenticating;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@@ -144,7 +147,8 @@ public class BiometricFragment extends InstrumentedFragment {
|
|||||||
.setConfirmationRequired(mBundle.getBoolean(
|
.setConfirmationRequired(mBundle.getBoolean(
|
||||||
BiometricPrompt.KEY_REQUIRE_CONFIRMATION, true))
|
BiometricPrompt.KEY_REQUIRE_CONFIRMATION, true))
|
||||||
.setDisallowBiometricsIfPolicyExists(mBundle.getBoolean(
|
.setDisallowBiometricsIfPolicyExists(mBundle.getBoolean(
|
||||||
BiometricPrompt.EXTRA_DISALLOW_BIOMETRICS_IF_POLICY_EXISTS, false));
|
BiometricPrompt.EXTRA_DISALLOW_BIOMETRICS_IF_POLICY_EXISTS, false))
|
||||||
|
.setReceiveSystemEvents(true);
|
||||||
|
|
||||||
mBiometricPrompt = builder.build();
|
mBiometricPrompt = builder.build();
|
||||||
mCancellationSignal = new CancellationSignal();
|
mCancellationSignal = new CancellationSignal();
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import android.app.admin.DevicePolicyManager;
|
|||||||
import android.app.trust.TrustManager;
|
import android.app.trust.TrustManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.graphics.Color;
|
||||||
import android.hardware.biometrics.BiometricConstants;
|
import android.hardware.biometrics.BiometricConstants;
|
||||||
import android.hardware.biometrics.BiometricManager;
|
import android.hardware.biometrics.BiometricManager;
|
||||||
import android.hardware.biometrics.BiometricPrompt;
|
import android.hardware.biometrics.BiometricPrompt;
|
||||||
@@ -35,6 +36,7 @@ import android.os.Looper;
|
|||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.WindowManager;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
@@ -142,6 +144,16 @@ public class ConfirmDeviceCredentialActivity extends FragmentActivity {
|
|||||||
public void onAuthenticationFailed() {
|
public void onAuthenticationFailed() {
|
||||||
mDevicePolicyManager.reportFailedBiometricAttempt(mUserId);
|
mDevicePolicyManager.reportFailedBiometricAttempt(mUserId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSystemEvent(int event) {
|
||||||
|
Log.d(TAG, "SystemEvent: " + event);
|
||||||
|
switch (event) {
|
||||||
|
case BiometricConstants.BIOMETRIC_SYSTEM_EVENT_EARLY_USER_CANCEL:
|
||||||
|
finish();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private String getStringForError(int errorCode) {
|
private String getStringForError(int errorCode) {
|
||||||
@@ -159,6 +171,9 @@ public class ConfirmDeviceCredentialActivity extends FragmentActivity {
|
|||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
||||||
|
getWindow().setStatusBarColor(Color.TRANSPARENT);
|
||||||
|
|
||||||
mBiometricManager = getSystemService(BiometricManager.class);
|
mBiometricManager = getSystemService(BiometricManager.class);
|
||||||
mDevicePolicyManager = getSystemService(DevicePolicyManager.class);
|
mDevicePolicyManager = getSystemService(DevicePolicyManager.class);
|
||||||
mUserManager = UserManager.get(this);
|
mUserManager = UserManager.get(this);
|
||||||
@@ -208,7 +223,7 @@ public class ConfirmDeviceCredentialActivity extends FragmentActivity {
|
|||||||
getTitleFromCredentialType(credentialType, isManagedProfile));
|
getTitleFromCredentialType(credentialType, isManagedProfile));
|
||||||
}
|
}
|
||||||
if (mDetails == null) {
|
if (mDetails == null) {
|
||||||
bpBundle.putString(BiometricPrompt.KEY_DEVICE_CREDENTIAL_DESCRIPTION,
|
bpBundle.putString(BiometricPrompt.KEY_DEVICE_CREDENTIAL_SUBTITLE,
|
||||||
getDetailsFromCredentialType(credentialType, isManagedProfile));
|
getDetailsFromCredentialType(credentialType, isManagedProfile));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -379,14 +394,6 @@ public class ConfirmDeviceCredentialActivity extends FragmentActivity {
|
|||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void finish() {
|
|
||||||
super.finish();
|
|
||||||
// Finish without animation since the activity is just there so we can launch
|
|
||||||
// BiometricPrompt.
|
|
||||||
overridePendingTransition(R.anim.confirm_credential_biometric_transition_enter, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isInternalActivity() {
|
private boolean isInternalActivity() {
|
||||||
return this instanceof ConfirmDeviceCredentialActivity.InternalActivity;
|
return this instanceof ConfirmDeviceCredentialActivity.InternalActivity;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,22 +17,32 @@
|
|||||||
package com.android.settings.wifi;
|
package com.android.settings.wifi;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.NetworkScoreManager;
|
||||||
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.FeatureFlagUtils;
|
import android.os.Handler;
|
||||||
|
import android.os.HandlerThread;
|
||||||
|
import android.os.Looper;
|
||||||
|
import android.os.Process;
|
||||||
|
import android.os.SimpleClock;
|
||||||
|
import android.os.SystemClock;
|
||||||
|
|
||||||
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.preference.PreferenceGroup;
|
import androidx.preference.PreferenceGroup;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.SubSettingLauncher;
|
import com.android.settings.core.SubSettingLauncher;
|
||||||
import com.android.settings.wifi.details.WifiNetworkDetailsFragment;
|
|
||||||
import com.android.settings.wifi.details2.WifiNetworkDetailsFragment2;
|
import com.android.settings.wifi.details2.WifiNetworkDetailsFragment2;
|
||||||
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;
|
||||||
import com.android.settingslib.wifi.AccessPoint;
|
import com.android.settingslib.wifi.WifiEntryPreference;
|
||||||
import com.android.settingslib.wifi.AccessPointPreference;
|
import com.android.wifitrackerlib.WifiEntry;
|
||||||
import com.android.settingslib.wifi.WifiTracker;
|
import com.android.wifitrackerlib.WifiPickerTracker;
|
||||||
import com.android.settingslib.wifi.WifiTrackerFactory;
|
|
||||||
|
import java.time.Clock;
|
||||||
|
import java.time.ZoneOffset;
|
||||||
|
|
||||||
// TODO(b/151133650): Replace AbstractPreferenceController with BasePreferenceController.
|
// TODO(b/151133650): Replace AbstractPreferenceController with BasePreferenceController.
|
||||||
/**
|
/**
|
||||||
@@ -40,21 +50,28 @@ import com.android.settingslib.wifi.WifiTrackerFactory;
|
|||||||
* controller class when there is a wifi connection present.
|
* controller class when there is a wifi connection present.
|
||||||
*/
|
*/
|
||||||
public class WifiConnectionPreferenceController extends AbstractPreferenceController implements
|
public class WifiConnectionPreferenceController extends AbstractPreferenceController implements
|
||||||
WifiTracker.WifiListener {
|
WifiPickerTracker.WifiPickerTrackerCallback {
|
||||||
|
|
||||||
private static final String TAG = "WifiConnPrefCtrl";
|
private static final String TAG = "WifiConnPrefCtrl";
|
||||||
|
|
||||||
private static final String KEY = "active_wifi_connection";
|
private static final String KEY = "active_wifi_connection";
|
||||||
|
|
||||||
|
// Max age of tracked WifiEntries.
|
||||||
|
private static final long MAX_SCAN_AGE_MILLIS = 15_000;
|
||||||
|
// Interval between initiating WifiPickerTracker scans.
|
||||||
|
private static final long SCAN_INTERVAL_MILLIS = 10_000;
|
||||||
|
|
||||||
private UpdateListener mUpdateListener;
|
private UpdateListener mUpdateListener;
|
||||||
private Context mPrefContext;
|
private Context mPrefContext;
|
||||||
private String mPreferenceGroupKey;
|
private String mPreferenceGroupKey;
|
||||||
private PreferenceGroup mPreferenceGroup;
|
private PreferenceGroup mPreferenceGroup;
|
||||||
private WifiTracker mWifiTracker;
|
@VisibleForTesting
|
||||||
private AccessPointPreference mPreference;
|
public WifiPickerTracker mWifiPickerTracker;
|
||||||
private AccessPointPreference.UserBadgeCache mBadgeCache;
|
private WifiEntryPreference mPreference;
|
||||||
private int order;
|
private int order;
|
||||||
private int mMetricsCategory;
|
private int mMetricsCategory;
|
||||||
|
// Worker thread used for WifiPickerTracker work.
|
||||||
|
private HandlerThread mWorkerThread;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to notify a parent controller that this controller has changed in availability, or has
|
* Used to notify a parent controller that this controller has changed in availability, or has
|
||||||
@@ -82,16 +99,34 @@ public class WifiConnectionPreferenceController extends AbstractPreferenceContro
|
|||||||
super(context);
|
super(context);
|
||||||
mUpdateListener = updateListener;
|
mUpdateListener = updateListener;
|
||||||
mPreferenceGroupKey = preferenceGroupKey;
|
mPreferenceGroupKey = preferenceGroupKey;
|
||||||
mWifiTracker = WifiTrackerFactory.create(context, this, lifecycle, true /* includeSaved */,
|
|
||||||
true /* includeScans */);
|
|
||||||
this.order = order;
|
this.order = order;
|
||||||
mMetricsCategory = metricsCategory;
|
mMetricsCategory = metricsCategory;
|
||||||
mBadgeCache = new AccessPointPreference.UserBadgeCache(context.getPackageManager());
|
|
||||||
|
mWorkerThread = new HandlerThread(
|
||||||
|
TAG + "{" + Integer.toHexString(System.identityHashCode(this)) + "}",
|
||||||
|
Process.THREAD_PRIORITY_BACKGROUND);
|
||||||
|
mWorkerThread.start();
|
||||||
|
final Clock elapsedRealtimeClock = new SimpleClock(ZoneOffset.UTC) {
|
||||||
|
@Override
|
||||||
|
public long millis() {
|
||||||
|
return SystemClock.elapsedRealtime();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
mWifiPickerTracker = new WifiPickerTracker(lifecycle, context,
|
||||||
|
context.getSystemService(WifiManager.class),
|
||||||
|
context.getSystemService(ConnectivityManager.class),
|
||||||
|
context.getSystemService(NetworkScoreManager.class),
|
||||||
|
new Handler(Looper.getMainLooper()),
|
||||||
|
mWorkerThread.getThreadHandler(),
|
||||||
|
elapsedRealtimeClock,
|
||||||
|
MAX_SCAN_AGE_MILLIS,
|
||||||
|
SCAN_INTERVAL_MILLIS,
|
||||||
|
this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
public boolean isAvailable() {
|
||||||
return mWifiTracker.isConnected() && getCurrentAccessPoint() != null;
|
return mWifiPickerTracker.getConnectedWifiEntry() != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -107,34 +142,23 @@ public class WifiConnectionPreferenceController extends AbstractPreferenceContro
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
private AccessPoint getCurrentAccessPoint() {
|
private void updatePreference(WifiEntry wifiEntry) {
|
||||||
for (AccessPoint accessPoint : mWifiTracker.getAccessPoints()) {
|
|
||||||
if (accessPoint.isActive()) {
|
|
||||||
return accessPoint;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updatePreference(AccessPoint accessPoint) {
|
|
||||||
if (mPreference != null) {
|
if (mPreference != null) {
|
||||||
mPreferenceGroup.removePreference(mPreference);
|
mPreferenceGroup.removePreference(mPreference);
|
||||||
mPreference = null;
|
mPreference = null;
|
||||||
}
|
}
|
||||||
if (accessPoint == null) {
|
if (wifiEntry == null || mPrefContext == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mPrefContext != null) {
|
|
||||||
mPreference = new AccessPointPreference(accessPoint, mPrefContext, mBadgeCache,
|
mPreference = new WifiEntryPreference(mPrefContext, wifiEntry);
|
||||||
R.drawable.ic_wifi_signal_0, false /* forSavedNetworks */);
|
|
||||||
mPreference.setKey(KEY);
|
mPreference.setKey(KEY);
|
||||||
mPreference.refresh();
|
mPreference.refresh();
|
||||||
mPreference.setOrder(order);
|
mPreference.setOrder(order);
|
||||||
|
|
||||||
if (FeatureFlagUtils.isEnabled(mPrefContext, FeatureFlagUtils.SETTINGS_WIFITRACKER2)) {
|
|
||||||
mPreference.setOnPreferenceClickListener(pref -> {
|
mPreference.setOnPreferenceClickListener(pref -> {
|
||||||
Bundle args = new Bundle();
|
final Bundle args = new Bundle();
|
||||||
mPreference.getAccessPoint().saveWifiState(args);
|
args.putString(WifiNetworkDetailsFragment2.KEY_CHOSEN_WIFIENTRY_KEY,
|
||||||
|
wifiEntry.getKey());
|
||||||
new SubSettingLauncher(mPrefContext)
|
new SubSettingLauncher(mPrefContext)
|
||||||
.setTitleRes(R.string.pref_title_network_details)
|
.setTitleRes(R.string.pref_title_network_details)
|
||||||
.setDestination(WifiNetworkDetailsFragment2.class.getName())
|
.setDestination(WifiNetworkDetailsFragment2.class.getName())
|
||||||
@@ -143,33 +167,16 @@ public class WifiConnectionPreferenceController extends AbstractPreferenceContro
|
|||||||
.launch();
|
.launch();
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
mPreference.setOnPreferenceClickListener(pref -> {
|
|
||||||
Bundle args = new Bundle();
|
|
||||||
mPreference.getAccessPoint().saveWifiState(args);
|
|
||||||
new SubSettingLauncher(mPrefContext)
|
|
||||||
.setTitleRes(R.string.pref_title_network_details)
|
|
||||||
.setDestination(WifiNetworkDetailsFragment.class.getName())
|
|
||||||
.setArguments(args)
|
|
||||||
.setSourceMetricsCategory(mMetricsCategory)
|
|
||||||
.launch();
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
mPreferenceGroup.addPreference(mPreference);
|
mPreferenceGroup.addPreference(mPreference);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void update() {
|
private void update() {
|
||||||
AccessPoint connectedAccessPoint = null;
|
final WifiEntry connectedWifiEntry = mWifiPickerTracker.getConnectedWifiEntry();
|
||||||
if (mWifiTracker.isConnected()) {
|
if (connectedWifiEntry == null) {
|
||||||
connectedAccessPoint = getCurrentAccessPoint();
|
|
||||||
}
|
|
||||||
if (connectedAccessPoint == null) {
|
|
||||||
updatePreference(null);
|
updatePreference(null);
|
||||||
} else {
|
} else {
|
||||||
if (mPreference == null || !mPreference.getAccessPoint().equals(connectedAccessPoint)) {
|
if (mPreference == null || !mPreference.getWifiEntry().equals(connectedWifiEntry)) {
|
||||||
updatePreference(connectedAccessPoint);
|
updatePreference(connectedWifiEntry);
|
||||||
} else if (mPreference != null) {
|
} else if (mPreference != null) {
|
||||||
mPreference.refresh();
|
mPreference.refresh();
|
||||||
}
|
}
|
||||||
@@ -177,18 +184,27 @@ public class WifiConnectionPreferenceController extends AbstractPreferenceContro
|
|||||||
mUpdateListener.onChildrenUpdated();
|
mUpdateListener.onChildrenUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Called when the state of Wifi has changed. */
|
||||||
@Override
|
@Override
|
||||||
public void onWifiStateChanged(int state) {
|
public void onWifiStateChanged() {
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the results when data changes.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onWifiEntriesChanged() {
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConnectedChanged() {
|
public void onNumSavedSubscriptionsChanged() {
|
||||||
update();
|
// Do nothing.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAccessPointsChanged() {
|
public void onNumSavedNetworksChanged() {
|
||||||
update();
|
// Do nothing.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
30
tests/perftests/AndroidTest.xml
Normal file
30
tests/perftests/AndroidTest.xml
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- 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.
|
||||||
|
-->
|
||||||
|
<configuration description="Runs Settings Performance Test Cases.">
|
||||||
|
<option name="test-suite-tag" value="apct" />
|
||||||
|
<option name="test-suite-tag" value="apct-instrumentation" />
|
||||||
|
<target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
|
||||||
|
<option name="cleanup-apks" value="true" />
|
||||||
|
<option name="test-file-name" value="SettingsPerfTests.apk" />
|
||||||
|
</target_preparer>
|
||||||
|
|
||||||
|
<option name="test-tag" value="SettingsPerfTests" />
|
||||||
|
<test class="com.android.tradefed.testtype.AndroidJUnitTest" >
|
||||||
|
<option name="package" value="com.android.settings.tests.perf" />
|
||||||
|
<option name="runner" value="androidx.test.runner.AndroidJUnitRunner" />
|
||||||
|
<option name="hidden-api-checks" value="false"/>
|
||||||
|
</test>
|
||||||
|
</configuration>
|
||||||
@@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
import static org.robolectric.Shadows.shadowOf;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
@@ -58,6 +59,7 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {
|
|||||||
private static final int BATTERY_LEVEL_MAIN = 30;
|
private static final int BATTERY_LEVEL_MAIN = 30;
|
||||||
private static final int BATTERY_LEVEL_LEFT = 25;
|
private static final int BATTERY_LEVEL_LEFT = 25;
|
||||||
private static final int BATTERY_LEVEL_RIGHT = 45;
|
private static final int BATTERY_LEVEL_RIGHT = 45;
|
||||||
|
private static final int LOW_BATTERY_LEVEL = 5;
|
||||||
private static final String ICON_URI = "content://test.provider/icon.png";
|
private static final String ICON_URI = "content://test.provider/icon.png";
|
||||||
private static final String MAC_ADDRESS = "04:52:C7:0B:D8:3C";
|
private static final String MAC_ADDRESS = "04:52:C7:0B:D8:3C";
|
||||||
|
|
||||||
@@ -115,6 +117,7 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {
|
|||||||
when(mBluetoothDevice.getMetadata(
|
when(mBluetoothDevice.getMetadata(
|
||||||
BluetoothDevice.METADATA_UNTETHERED_CASE_BATTERY)).thenReturn(
|
BluetoothDevice.METADATA_UNTETHERED_CASE_BATTERY)).thenReturn(
|
||||||
String.valueOf(BATTERY_LEVEL_MAIN).getBytes());
|
String.valueOf(BATTERY_LEVEL_MAIN).getBytes());
|
||||||
|
|
||||||
when(mCachedDevice.isConnected()).thenReturn(true);
|
when(mCachedDevice.isConnected()).thenReturn(true);
|
||||||
mController.refresh();
|
mController.refresh();
|
||||||
|
|
||||||
@@ -143,6 +146,36 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {
|
|||||||
assertThat(layout.findViewById(R.id.header_icon).getVisibility()).isEqualTo(View.VISIBLE);
|
assertThat(layout.findViewById(R.id.header_icon).getVisibility()).isEqualTo(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void refresh_withLowBatteryAndUncharged_showAlertIcon() {
|
||||||
|
when(mBluetoothDevice.getMetadata(
|
||||||
|
BluetoothDevice.METADATA_UNTETHERED_LEFT_BATTERY)).thenReturn(
|
||||||
|
String.valueOf(LOW_BATTERY_LEVEL).getBytes());
|
||||||
|
when(mBluetoothDevice.getMetadata(
|
||||||
|
BluetoothDevice.METADATA_UNTETHERED_RIGHT_BATTERY)).thenReturn(
|
||||||
|
String.valueOf(LOW_BATTERY_LEVEL).getBytes());
|
||||||
|
when(mBluetoothDevice.getMetadata(
|
||||||
|
BluetoothDevice.METADATA_UNTETHERED_CASE_BATTERY)).thenReturn(
|
||||||
|
String.valueOf(BATTERY_LEVEL_MAIN).getBytes());
|
||||||
|
when(mBluetoothDevice.getMetadata(
|
||||||
|
BluetoothDevice.METADATA_UNTETHERED_LEFT_CHARGING)).thenReturn(
|
||||||
|
String.valueOf(false).getBytes());
|
||||||
|
when(mBluetoothDevice.getMetadata(
|
||||||
|
BluetoothDevice.METADATA_UNTETHERED_RIGHT_CHARGING)).thenReturn(
|
||||||
|
String.valueOf(true).getBytes());
|
||||||
|
when(mBluetoothDevice.getMetadata(
|
||||||
|
BluetoothDevice.METADATA_UNTETHERED_CASE_CHARGING)).thenReturn(
|
||||||
|
String.valueOf(false).getBytes());
|
||||||
|
when(mCachedDevice.isConnected()).thenReturn(true);
|
||||||
|
|
||||||
|
mController.refresh();
|
||||||
|
|
||||||
|
assertBatteryIcon(mLayoutPreference.findViewById(R.id.layout_left),
|
||||||
|
R.drawable.ic_battery_alert_24dp);
|
||||||
|
assertBatteryIcon(mLayoutPreference.findViewById(R.id.layout_right), /* resId= */-1);
|
||||||
|
assertBatteryIcon(mLayoutPreference.findViewById(R.id.layout_middle), /* resId= */ -1);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getAvailabilityStatus_untetheredHeadsetWithConfigOn_returnAvailable() {
|
public void getAvailabilityStatus_untetheredHeadsetWithConfigOn_returnAvailable() {
|
||||||
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SETTINGS_UI,
|
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SETTINGS_UI,
|
||||||
@@ -256,4 +289,10 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {
|
|||||||
com.android.settings.Utils.formatPercentage(batteryLevel));
|
com.android.settings.Utils.formatPercentage(batteryLevel));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void assertBatteryIcon(LinearLayout linearLayout, int resId) {
|
||||||
|
final ImageView imageView = linearLayout.findViewById(R.id.bt_battery_icon);
|
||||||
|
assertThat(shadowOf(imageView.getDrawable()).getCreatedFromResId())
|
||||||
|
.isEqualTo(resId);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,12 +29,15 @@ import static org.mockito.Mockito.when;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
|
import androidx.preference.PreferenceCategory;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.wifi.WifiConnectionPreferenceController;
|
import com.android.settings.wifi.WifiConnectionPreferenceController;
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
import com.android.settingslib.wifi.AccessPoint;
|
import com.android.settingslib.wifi.WifiEntryPreference;
|
||||||
import com.android.settingslib.wifi.AccessPointPreference;
|
import com.android.wifitrackerlib.WifiEntry;
|
||||||
import com.android.settingslib.wifi.WifiTracker;
|
import com.android.wifitrackerlib.WifiPickerTracker;
|
||||||
import com.android.settingslib.wifi.WifiTrackerFactory;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -45,19 +48,12 @@ import org.mockito.MockitoAnnotations;
|
|||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import androidx.lifecycle.LifecycleOwner;
|
|
||||||
import androidx.preference.PreferenceCategory;
|
|
||||||
import androidx.preference.PreferenceScreen;
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class WifiConnectionPreferenceControllerTest {
|
public class WifiConnectionPreferenceControllerTest {
|
||||||
private static final String KEY = "wifi_connection";
|
private static final String KEY = "wifi_connection";
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
WifiTracker mWifiTracker;
|
WifiPickerTracker mWifiPickerTracker;
|
||||||
@Mock
|
@Mock
|
||||||
PreferenceScreen mScreen;
|
PreferenceScreen mScreen;
|
||||||
@Mock
|
@Mock
|
||||||
@@ -74,7 +70,6 @@ public class WifiConnectionPreferenceControllerTest {
|
|||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mContext = spy(RuntimeEnvironment.application);
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
WifiTrackerFactory.setTestingWifiTracker(mWifiTracker);
|
|
||||||
mLifecycleOwner = () -> mLifecycle;
|
mLifecycleOwner = () -> mLifecycle;
|
||||||
mLifecycle = new Lifecycle(mLifecycleOwner);
|
mLifecycle = new Lifecycle(mLifecycleOwner);
|
||||||
when(mScreen.findPreference(eq(KEY))).thenReturn(mPreferenceCategory);
|
when(mScreen.findPreference(eq(KEY))).thenReturn(mPreferenceCategory);
|
||||||
@@ -83,49 +78,51 @@ public class WifiConnectionPreferenceControllerTest {
|
|||||||
|
|
||||||
mController = new WifiConnectionPreferenceController(mContext, mLifecycle, mUpdateListener,
|
mController = new WifiConnectionPreferenceController(mContext, mLifecycle, mUpdateListener,
|
||||||
KEY, 0, 0);
|
KEY, 0, 0);
|
||||||
|
mController.mWifiPickerTracker = mWifiPickerTracker;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAvailable_noWiFiConnection_availableIsFalse() {
|
public void isAvailable_noConnectedWifiEntry_availableIsFalse() {
|
||||||
when(mWifiTracker.isConnected()).thenReturn(false);
|
when(mWifiPickerTracker.getConnectedWifiEntry()).thenReturn(null);
|
||||||
|
|
||||||
assertThat(mController.isAvailable()).isFalse();
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void displayPreference_noWiFiConnection_noPreferenceAdded() {
|
public void displayPreference_noConnectedWifiEntry_noPreferenceAdded() {
|
||||||
when(mWifiTracker.isConnected()).thenReturn(false);
|
when(mWifiPickerTracker.getConnectedWifiEntry()).thenReturn(null);
|
||||||
when(mWifiTracker.getAccessPoints()).thenReturn(new ArrayList<>());
|
|
||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
verify(mPreferenceCategory, never()).addPreference(any());
|
verify(mPreferenceCategory, never()).addPreference(any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void displayPreference_hasWiFiConnection_preferenceAdded() {
|
public void displayPreference_hasConnectedWifiEntry_preferenceAdded() {
|
||||||
when(mWifiTracker.isConnected()).thenReturn(true);
|
final WifiEntry wifiEntry = mock(WifiEntry.class);
|
||||||
final AccessPoint accessPoint = mock(AccessPoint.class);
|
when(mWifiPickerTracker.getConnectedWifiEntry()).thenReturn(wifiEntry);
|
||||||
when(accessPoint.isActive()).thenReturn(true);
|
|
||||||
when(mWifiTracker.getAccessPoints()).thenReturn(Arrays.asList(accessPoint));
|
|
||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
verify(mPreferenceCategory).addPreference(any(AccessPointPreference.class));
|
verify(mPreferenceCategory).addPreference(any(WifiEntryPreference.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onConnectedChanged_wifiBecameDisconnected_preferenceRemoved() {
|
public void onConnectedChanged_wifiBecameDisconnected_preferenceRemoved() {
|
||||||
when(mWifiTracker.isConnected()).thenReturn(true);
|
final WifiEntry wifiEntry = mock(WifiEntry.class);
|
||||||
final AccessPoint accessPoint = mock(AccessPoint.class);
|
when(mWifiPickerTracker.getConnectedWifiEntry()).thenReturn(wifiEntry);
|
||||||
|
|
||||||
when(accessPoint.isActive()).thenReturn(true);
|
|
||||||
when(mWifiTracker.getAccessPoints()).thenReturn(Arrays.asList(accessPoint));
|
|
||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
final ArgumentCaptor<AccessPointPreference> captor = ArgumentCaptor.forClass(
|
final ArgumentCaptor<WifiEntryPreference> captor = ArgumentCaptor.forClass(
|
||||||
AccessPointPreference.class);
|
WifiEntryPreference.class);
|
||||||
verify(mPreferenceCategory).addPreference(captor.capture());
|
verify(mPreferenceCategory).addPreference(captor.capture());
|
||||||
final AccessPointPreference pref = captor.getValue();
|
final WifiEntryPreference pref = captor.getValue();
|
||||||
|
|
||||||
when(mWifiTracker.isConnected()).thenReturn(false);
|
// Become disconnected.
|
||||||
when(mWifiTracker.getAccessPoints()).thenReturn(new ArrayList<>());
|
when(mWifiPickerTracker.getConnectedWifiEntry()).thenReturn(null);
|
||||||
final int onUpdatedCountBefore = mOnChildUpdatedCount;
|
final int onUpdatedCountBefore = mOnChildUpdatedCount;
|
||||||
mController.onConnectedChanged();
|
|
||||||
|
mController.onWifiStateChanged();
|
||||||
|
|
||||||
verify(mPreferenceCategory).removePreference(pref);
|
verify(mPreferenceCategory).removePreference(pref);
|
||||||
assertThat(mOnChildUpdatedCount).isEqualTo(onUpdatedCountBefore + 1);
|
assertThat(mOnChildUpdatedCount).isEqualTo(onUpdatedCountBefore + 1);
|
||||||
}
|
}
|
||||||
@@ -133,28 +130,24 @@ public class WifiConnectionPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onAccessPointsChanged_wifiBecameConnectedToDifferentAP_preferenceReplaced() {
|
public void onAccessPointsChanged_wifiBecameConnectedToDifferentAP_preferenceReplaced() {
|
||||||
when(mWifiTracker.isConnected()).thenReturn(true);
|
final WifiEntry wifiEntry1 = mock(WifiEntry.class);
|
||||||
final AccessPoint accessPoint1 = mock(AccessPoint.class);
|
when(wifiEntry1.getKey()).thenReturn("KEY_1");
|
||||||
|
when(mWifiPickerTracker.getConnectedWifiEntry()).thenReturn(wifiEntry1);
|
||||||
when(accessPoint1.isActive()).thenReturn(true);
|
|
||||||
when(mWifiTracker.getAccessPoints()).thenReturn(Arrays.asList(accessPoint1));
|
|
||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
final ArgumentCaptor<AccessPointPreference> captor = ArgumentCaptor.forClass(
|
final ArgumentCaptor<WifiEntryPreference> captor = ArgumentCaptor.forClass(
|
||||||
AccessPointPreference.class);
|
WifiEntryPreference.class);
|
||||||
|
|
||||||
|
final WifiEntry wifiEntry2 = mock(WifiEntry.class);
|
||||||
final AccessPoint accessPoint2 = mock(AccessPoint.class);
|
when(wifiEntry1.getKey()).thenReturn("KEY_2");
|
||||||
when(accessPoint1.isActive()).thenReturn(false);
|
when(mWifiPickerTracker.getConnectedWifiEntry()).thenReturn(wifiEntry2);
|
||||||
when(accessPoint2.isActive()).thenReturn(true);
|
|
||||||
when(mWifiTracker.getAccessPoints()).thenReturn(Arrays.asList(accessPoint1, accessPoint2));
|
|
||||||
final int onUpdatedCountBefore = mOnChildUpdatedCount;
|
final int onUpdatedCountBefore = mOnChildUpdatedCount;
|
||||||
mController.onAccessPointsChanged();
|
mController.onWifiEntriesChanged();
|
||||||
|
|
||||||
verify(mPreferenceCategory, times(2)).addPreference(captor.capture());
|
verify(mPreferenceCategory, times(2)).addPreference(captor.capture());
|
||||||
final AccessPointPreference pref1 = captor.getAllValues().get(0);
|
final WifiEntryPreference pref1 = captor.getAllValues().get(0);
|
||||||
final AccessPointPreference pref2 = captor.getAllValues().get(1);
|
final WifiEntryPreference pref2 = captor.getAllValues().get(1);
|
||||||
assertThat(pref1.getAccessPoint()).isEqualTo(accessPoint1);
|
assertThat(pref1.getWifiEntry()).isEqualTo(wifiEntry1);
|
||||||
assertThat(pref2.getAccessPoint()).isEqualTo(accessPoint2);
|
assertThat(pref2.getWifiEntry()).isEqualTo(wifiEntry2);
|
||||||
verify(mPreferenceCategory).removePreference(eq(pref1));
|
verify(mPreferenceCategory).removePreference(eq(pref1));
|
||||||
assertThat(mOnChildUpdatedCount).isEqualTo(onUpdatedCountBefore + 1);
|
assertThat(mOnChildUpdatedCount).isEqualTo(onUpdatedCountBefore + 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
import static org.mockito.Mockito.any;
|
import static org.mockito.Mockito.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@@ -34,6 +35,8 @@ import android.provider.Settings;
|
|||||||
import android.service.notification.ConversationChannelWrapper;
|
import android.service.notification.ConversationChannelWrapper;
|
||||||
|
|
||||||
import androidx.preference.PreferenceCategory;
|
import androidx.preference.PreferenceCategory;
|
||||||
|
import androidx.preference.PreferenceManager;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.applications.AppInfoBase;
|
import com.android.settings.applications.AppInfoBase;
|
||||||
import com.android.settings.notification.NotificationBackend;
|
import com.android.settings.notification.NotificationBackend;
|
||||||
@@ -85,7 +88,10 @@ public class ConversationListPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPopulateList_validConversations() {
|
public void testPopulateList_validConversations() {
|
||||||
PreferenceCategory outerContainer = mock(PreferenceCategory.class);
|
final PreferenceManager preferenceManager = new PreferenceManager(mContext);
|
||||||
|
PreferenceScreen ps = preferenceManager.createPreferenceScreen(mContext);
|
||||||
|
PreferenceCategory outerContainer = spy(new PreferenceCategory(mContext));
|
||||||
|
ps.addPreference(outerContainer);
|
||||||
|
|
||||||
ConversationChannelWrapper ccw = new ConversationChannelWrapper();
|
ConversationChannelWrapper ccw = new ConversationChannelWrapper();
|
||||||
ccw.setNotificationChannel(mock(NotificationChannel.class));
|
ccw.setNotificationChannel(mock(NotificationChannel.class));
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package com.android.settings.notification.zen;
|
|||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@@ -28,11 +29,11 @@ import android.app.NotificationManager;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.os.Looper;
|
||||||
|
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.notification.zen.ZenModeEventRuleSettings;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -40,7 +41,6 @@ import org.junit.runner.RunWith;
|
|||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
|
||||||
import org.robolectric.shadows.ShadowApplication;
|
import org.robolectric.shadows.ShadowApplication;
|
||||||
import org.robolectric.shadows.ShadowToast;
|
import org.robolectric.shadows.ShadowToast;
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ public class ZenModeEventRuleSettingsTest {
|
|||||||
|
|
||||||
ShadowApplication shadowApplication = ShadowApplication.getInstance();
|
ShadowApplication shadowApplication = ShadowApplication.getInstance();
|
||||||
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
|
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
|
||||||
mContext = RuntimeEnvironment.application;
|
mContext = application;
|
||||||
|
|
||||||
mFragment = spy(new TestFragment());
|
mFragment = spy(new TestFragment());
|
||||||
mFragment.onAttach(application);
|
mFragment.onAttach(application);
|
||||||
@@ -81,6 +81,7 @@ public class ZenModeEventRuleSettingsTest {
|
|||||||
when(mActivity.getTheme()).thenReturn(res.newTheme());
|
when(mActivity.getTheme()).thenReturn(res.newTheme());
|
||||||
when(mActivity.getIntent()).thenReturn(mIntent);
|
when(mActivity.getIntent()).thenReturn(mIntent);
|
||||||
when(mActivity.getResources()).thenReturn(res);
|
when(mActivity.getResources()).thenReturn(res);
|
||||||
|
when(mActivity.getMainLooper()).thenReturn(mock(Looper.class));
|
||||||
when(mFragment.getContext()).thenReturn(mContext);
|
when(mFragment.getContext()).thenReturn(mContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package com.android.settings.notification.zen;
|
|||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@@ -28,11 +29,11 @@ import android.app.NotificationManager;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.os.Looper;
|
||||||
|
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.notification.zen.ZenModeScheduleRuleSettings;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -40,7 +41,6 @@ import org.junit.runner.RunWith;
|
|||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
|
||||||
import org.robolectric.shadows.ShadowApplication;
|
import org.robolectric.shadows.ShadowApplication;
|
||||||
import org.robolectric.shadows.ShadowToast;
|
import org.robolectric.shadows.ShadowToast;
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ public class ZenModeScheduleRuleSettingsTest {
|
|||||||
|
|
||||||
ShadowApplication shadowApplication = ShadowApplication.getInstance();
|
ShadowApplication shadowApplication = ShadowApplication.getInstance();
|
||||||
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
|
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
|
||||||
mContext = RuntimeEnvironment.application;
|
mContext = application;
|
||||||
|
|
||||||
mFragment = spy(new TestFragment());
|
mFragment = spy(new TestFragment());
|
||||||
mFragment.onAttach(application);
|
mFragment.onAttach(application);
|
||||||
@@ -78,6 +78,7 @@ public class ZenModeScheduleRuleSettingsTest {
|
|||||||
when(mActivity.getTheme()).thenReturn(res.newTheme());
|
when(mActivity.getTheme()).thenReturn(res.newTheme());
|
||||||
when(mActivity.getIntent()).thenReturn(mIntent);
|
when(mActivity.getIntent()).thenReturn(mIntent);
|
||||||
when(mActivity.getResources()).thenReturn(res);
|
when(mActivity.getResources()).thenReturn(res);
|
||||||
|
when(mActivity.getMainLooper()).thenReturn(mock(Looper.class));
|
||||||
when(mFragment.getContext()).thenReturn(mContext);
|
when(mFragment.getContext()).thenReturn(mContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
|
||||||
@@ -50,6 +51,7 @@ public class WifiMeteredPreferenceController2Test {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
mContext = RuntimeEnvironment.application;
|
mContext = RuntimeEnvironment.application;
|
||||||
|
|
||||||
mPreferenceController = spy(
|
mPreferenceController = spy(
|
||||||
|
|||||||
Reference in New Issue
Block a user