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
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="33dp"
|
||||
android:layout_marginTop="2dp"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal">
|
||||
<ImageView
|
||||
android:id="@+id/bt_battery_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"/>
|
||||
android:layout_height="wrap_content"/>
|
||||
<TextView
|
||||
android:id="@+id/bt_battery_summary"
|
||||
style="@style/TextAppearance.EntityHeaderSummary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="4dp"
|
||||
android:layout_gravity="center_horizontal"/>
|
||||
android:layout_marginStart="4dp"/>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -408,6 +408,9 @@
|
||||
<!-- Battery meter icon size of advanced bluetooth device -->
|
||||
<dimen name="advanced_bluetooth_battery_meter_width">7.8dp</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 -->
|
||||
<dimen name="developer_option_dialog_margin_start">8dp</dimen>
|
||||
|
||||
@@ -344,6 +344,8 @@ public class MasterClear extends InstrumentedFragment implements OnGlobalLayoutL
|
||||
noCancelMobilePlan.setVisibility(View.VISIBLE);
|
||||
mEsimStorage.setChecked(true /* checked */);
|
||||
}
|
||||
} else {
|
||||
mEsimStorage.setChecked(false /* checked */);
|
||||
}
|
||||
|
||||
final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
|
||||
|
||||
@@ -31,6 +31,7 @@ import android.provider.DeviceConfig;
|
||||
import android.provider.MediaStore;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
@@ -191,11 +192,9 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
|
||||
context.getResources().getDimensionPixelSize(
|
||||
R.dimen.advanced_bluetooth_battery_meter_height));
|
||||
drawable.setBatteryLevel(level);
|
||||
final int attr = level > LOW_BATTERY_LEVEL || charging
|
||||
? android.R.attr.colorControlNormal
|
||||
: android.R.attr.colorError;
|
||||
drawable.setColorFilter(new PorterDuffColorFilter(
|
||||
com.android.settings.Utils.getColorAttrDefaultColor(context, attr),
|
||||
com.android.settings.Utils.getColorAttrDefaultColor(context,
|
||||
android.R.attr.colorControlNormal),
|
||||
PorterDuff.Mode.SRC));
|
||||
drawable.setCharging(charging);
|
||||
|
||||
@@ -218,12 +217,10 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
|
||||
final boolean charging = BluetoothUtils.getBooleanMetaData(bluetoothDevice, chargeMetaKey);
|
||||
if (batteryLevel != BluetoothUtils.META_INT_ERROR) {
|
||||
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);
|
||||
textView.setText(com.android.settings.Utils.formatPercentage(batteryLevel));
|
||||
textView.setVisibility(View.VISIBLE);
|
||||
showBatteryIcon(linearLayout, batteryLevel, charging);
|
||||
} else {
|
||||
// Hide it if it doesn't have battery information
|
||||
linearLayout.setVisibility(View.GONE);
|
||||
@@ -234,6 +231,28 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
|
||||
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() {
|
||||
mLayoutPreference.findViewById(R.id.layout_left).setVisibility(View.GONE);
|
||||
mLayoutPreference.findViewById(R.id.layout_right).setVisibility(View.GONE);
|
||||
|
||||
@@ -466,6 +466,7 @@ public class EnabledNetworkModePreferenceController extends
|
||||
}
|
||||
break;
|
||||
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:
|
||||
setSelectedEntry(networkMode);
|
||||
setSummary(mContext.getString(R.string.network_5G)
|
||||
|
||||
@@ -70,6 +70,8 @@ public abstract class ConversationListPreferenceController extends AbstractPrefe
|
||||
|
||||
if (containerGroup.getPreferenceCount() == 0) {
|
||||
containerGroup.setVisible(false);
|
||||
} else {
|
||||
containerGroup.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -77,6 +77,13 @@ public class BiometricFragment extends InstrumentedFragment {
|
||||
mClientCallback.onAuthenticationFailed();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSystemEvent(int event) {
|
||||
mClientExecutor.execute(() -> {
|
||||
mClientCallback.onSystemEvent(event);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
private final DialogInterface.OnClickListener mNegativeButtonListener =
|
||||
@@ -121,10 +128,6 @@ public class BiometricFragment extends InstrumentedFragment {
|
||||
}
|
||||
}
|
||||
|
||||
boolean isAuthenticating() {
|
||||
return mAuthenticating;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -144,7 +147,8 @@ public class BiometricFragment extends InstrumentedFragment {
|
||||
.setConfirmationRequired(mBundle.getBoolean(
|
||||
BiometricPrompt.KEY_REQUIRE_CONFIRMATION, true))
|
||||
.setDisallowBiometricsIfPolicyExists(mBundle.getBoolean(
|
||||
BiometricPrompt.EXTRA_DISALLOW_BIOMETRICS_IF_POLICY_EXISTS, false));
|
||||
BiometricPrompt.EXTRA_DISALLOW_BIOMETRICS_IF_POLICY_EXISTS, false))
|
||||
.setReceiveSystemEvents(true);
|
||||
|
||||
mBiometricPrompt = builder.build();
|
||||
mCancellationSignal = new CancellationSignal();
|
||||
|
||||
@@ -25,6 +25,7 @@ import android.app.admin.DevicePolicyManager;
|
||||
import android.app.trust.TrustManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.hardware.biometrics.BiometricConstants;
|
||||
import android.hardware.biometrics.BiometricManager;
|
||||
import android.hardware.biometrics.BiometricPrompt;
|
||||
@@ -35,6 +36,7 @@ import android.os.Looper;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.util.Log;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
@@ -142,6 +144,16 @@ public class ConfirmDeviceCredentialActivity extends FragmentActivity {
|
||||
public void onAuthenticationFailed() {
|
||||
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) {
|
||||
@@ -159,6 +171,9 @@ public class ConfirmDeviceCredentialActivity extends FragmentActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
||||
getWindow().setStatusBarColor(Color.TRANSPARENT);
|
||||
|
||||
mBiometricManager = getSystemService(BiometricManager.class);
|
||||
mDevicePolicyManager = getSystemService(DevicePolicyManager.class);
|
||||
mUserManager = UserManager.get(this);
|
||||
@@ -208,7 +223,7 @@ public class ConfirmDeviceCredentialActivity extends FragmentActivity {
|
||||
getTitleFromCredentialType(credentialType, isManagedProfile));
|
||||
}
|
||||
if (mDetails == null) {
|
||||
bpBundle.putString(BiometricPrompt.KEY_DEVICE_CREDENTIAL_DESCRIPTION,
|
||||
bpBundle.putString(BiometricPrompt.KEY_DEVICE_CREDENTIAL_SUBTITLE,
|
||||
getDetailsFromCredentialType(credentialType, isManagedProfile));
|
||||
}
|
||||
|
||||
@@ -379,14 +394,6 @@ public class ConfirmDeviceCredentialActivity extends FragmentActivity {
|
||||
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() {
|
||||
return this instanceof ConfirmDeviceCredentialActivity.InternalActivity;
|
||||
}
|
||||
|
||||
@@ -17,22 +17,32 @@
|
||||
package com.android.settings.wifi;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkScoreManager;
|
||||
import android.net.wifi.WifiManager;
|
||||
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.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.wifi.details.WifiNetworkDetailsFragment;
|
||||
import com.android.settings.wifi.details2.WifiNetworkDetailsFragment2;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.wifi.AccessPoint;
|
||||
import com.android.settingslib.wifi.AccessPointPreference;
|
||||
import com.android.settingslib.wifi.WifiTracker;
|
||||
import com.android.settingslib.wifi.WifiTrackerFactory;
|
||||
import com.android.settingslib.wifi.WifiEntryPreference;
|
||||
import com.android.wifitrackerlib.WifiEntry;
|
||||
import com.android.wifitrackerlib.WifiPickerTracker;
|
||||
|
||||
import java.time.Clock;
|
||||
import java.time.ZoneOffset;
|
||||
|
||||
// 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.
|
||||
*/
|
||||
public class WifiConnectionPreferenceController extends AbstractPreferenceController implements
|
||||
WifiTracker.WifiListener {
|
||||
WifiPickerTracker.WifiPickerTrackerCallback {
|
||||
|
||||
private static final String TAG = "WifiConnPrefCtrl";
|
||||
|
||||
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 Context mPrefContext;
|
||||
private String mPreferenceGroupKey;
|
||||
private PreferenceGroup mPreferenceGroup;
|
||||
private WifiTracker mWifiTracker;
|
||||
private AccessPointPreference mPreference;
|
||||
private AccessPointPreference.UserBadgeCache mBadgeCache;
|
||||
@VisibleForTesting
|
||||
public WifiPickerTracker mWifiPickerTracker;
|
||||
private WifiEntryPreference mPreference;
|
||||
private int order;
|
||||
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
|
||||
@@ -82,16 +99,34 @@ public class WifiConnectionPreferenceController extends AbstractPreferenceContro
|
||||
super(context);
|
||||
mUpdateListener = updateListener;
|
||||
mPreferenceGroupKey = preferenceGroupKey;
|
||||
mWifiTracker = WifiTrackerFactory.create(context, this, lifecycle, true /* includeSaved */,
|
||||
true /* includeScans */);
|
||||
this.order = order;
|
||||
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
|
||||
public boolean isAvailable() {
|
||||
return mWifiTracker.isConnected() && getCurrentAccessPoint() != null;
|
||||
return mWifiPickerTracker.getConnectedWifiEntry() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -107,88 +142,69 @@ public class WifiConnectionPreferenceController extends AbstractPreferenceContro
|
||||
update();
|
||||
}
|
||||
|
||||
private AccessPoint getCurrentAccessPoint() {
|
||||
for (AccessPoint accessPoint : mWifiTracker.getAccessPoints()) {
|
||||
if (accessPoint.isActive()) {
|
||||
return accessPoint;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void updatePreference(AccessPoint accessPoint) {
|
||||
private void updatePreference(WifiEntry wifiEntry) {
|
||||
if (mPreference != null) {
|
||||
mPreferenceGroup.removePreference(mPreference);
|
||||
mPreference = null;
|
||||
}
|
||||
if (accessPoint == null) {
|
||||
if (wifiEntry == null || mPrefContext == null) {
|
||||
return;
|
||||
}
|
||||
if (mPrefContext != null) {
|
||||
mPreference = new AccessPointPreference(accessPoint, mPrefContext, mBadgeCache,
|
||||
R.drawable.ic_wifi_signal_0, false /* forSavedNetworks */);
|
||||
mPreference.setKey(KEY);
|
||||
mPreference.refresh();
|
||||
mPreference.setOrder(order);
|
||||
|
||||
if (FeatureFlagUtils.isEnabled(mPrefContext, FeatureFlagUtils.SETTINGS_WIFITRACKER2)) {
|
||||
mPreference.setOnPreferenceClickListener(pref -> {
|
||||
Bundle args = new Bundle();
|
||||
mPreference.getAccessPoint().saveWifiState(args);
|
||||
new SubSettingLauncher(mPrefContext)
|
||||
.setTitleRes(R.string.pref_title_network_details)
|
||||
.setDestination(WifiNetworkDetailsFragment2.class.getName())
|
||||
.setArguments(args)
|
||||
.setSourceMetricsCategory(mMetricsCategory)
|
||||
.launch();
|
||||
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);
|
||||
}
|
||||
mPreference = new WifiEntryPreference(mPrefContext, wifiEntry);
|
||||
mPreference.setKey(KEY);
|
||||
mPreference.refresh();
|
||||
mPreference.setOrder(order);
|
||||
mPreference.setOnPreferenceClickListener(pref -> {
|
||||
final Bundle args = new Bundle();
|
||||
args.putString(WifiNetworkDetailsFragment2.KEY_CHOSEN_WIFIENTRY_KEY,
|
||||
wifiEntry.getKey());
|
||||
new SubSettingLauncher(mPrefContext)
|
||||
.setTitleRes(R.string.pref_title_network_details)
|
||||
.setDestination(WifiNetworkDetailsFragment2.class.getName())
|
||||
.setArguments(args)
|
||||
.setSourceMetricsCategory(mMetricsCategory)
|
||||
.launch();
|
||||
return true;
|
||||
});
|
||||
mPreferenceGroup.addPreference(mPreference);
|
||||
}
|
||||
|
||||
private void update() {
|
||||
AccessPoint connectedAccessPoint = null;
|
||||
if (mWifiTracker.isConnected()) {
|
||||
connectedAccessPoint = getCurrentAccessPoint();
|
||||
}
|
||||
if (connectedAccessPoint == null) {
|
||||
final WifiEntry connectedWifiEntry = mWifiPickerTracker.getConnectedWifiEntry();
|
||||
if (connectedWifiEntry == null) {
|
||||
updatePreference(null);
|
||||
} else {
|
||||
if (mPreference == null || !mPreference.getAccessPoint().equals(connectedAccessPoint)) {
|
||||
updatePreference(connectedAccessPoint);
|
||||
} else if (mPreference != null) {
|
||||
mPreference.refresh();
|
||||
}
|
||||
if (mPreference == null || !mPreference.getWifiEntry().equals(connectedWifiEntry)) {
|
||||
updatePreference(connectedWifiEntry);
|
||||
} else if (mPreference != null) {
|
||||
mPreference.refresh();
|
||||
}
|
||||
}
|
||||
mUpdateListener.onChildrenUpdated();
|
||||
}
|
||||
|
||||
/** Called when the state of Wifi has changed. */
|
||||
@Override
|
||||
public void onWifiStateChanged(int state) {
|
||||
public void onWifiStateChanged() {
|
||||
update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the results when data changes.
|
||||
*/
|
||||
@Override
|
||||
public void onWifiEntriesChanged() {
|
||||
update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectedChanged() {
|
||||
update();
|
||||
public void onNumSavedSubscriptionsChanged() {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccessPointsChanged() {
|
||||
update();
|
||||
public void onNumSavedNetworksChanged() {
|
||||
// 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.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.robolectric.Shadows.shadowOf;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
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_LEFT = 25;
|
||||
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 MAC_ADDRESS = "04:52:C7:0B:D8:3C";
|
||||
|
||||
@@ -115,6 +117,7 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {
|
||||
when(mBluetoothDevice.getMetadata(
|
||||
BluetoothDevice.METADATA_UNTETHERED_CASE_BATTERY)).thenReturn(
|
||||
String.valueOf(BATTERY_LEVEL_MAIN).getBytes());
|
||||
|
||||
when(mCachedDevice.isConnected()).thenReturn(true);
|
||||
mController.refresh();
|
||||
|
||||
@@ -143,6 +146,36 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {
|
||||
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
|
||||
public void getAvailabilityStatus_untetheredHeadsetWithConfigOn_returnAvailable() {
|
||||
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SETTINGS_UI,
|
||||
@@ -256,4 +289,10 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {
|
||||
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 androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.wifi.WifiConnectionPreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.wifi.AccessPoint;
|
||||
import com.android.settingslib.wifi.AccessPointPreference;
|
||||
import com.android.settingslib.wifi.WifiTracker;
|
||||
import com.android.settingslib.wifi.WifiTrackerFactory;
|
||||
import com.android.settingslib.wifi.WifiEntryPreference;
|
||||
import com.android.wifitrackerlib.WifiEntry;
|
||||
import com.android.wifitrackerlib.WifiPickerTracker;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -45,19 +48,12 @@ import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
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)
|
||||
public class WifiConnectionPreferenceControllerTest {
|
||||
private static final String KEY = "wifi_connection";
|
||||
|
||||
@Mock
|
||||
WifiTracker mWifiTracker;
|
||||
WifiPickerTracker mWifiPickerTracker;
|
||||
@Mock
|
||||
PreferenceScreen mScreen;
|
||||
@Mock
|
||||
@@ -74,7 +70,6 @@ public class WifiConnectionPreferenceControllerTest {
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
WifiTrackerFactory.setTestingWifiTracker(mWifiTracker);
|
||||
mLifecycleOwner = () -> mLifecycle;
|
||||
mLifecycle = new Lifecycle(mLifecycleOwner);
|
||||
when(mScreen.findPreference(eq(KEY))).thenReturn(mPreferenceCategory);
|
||||
@@ -83,49 +78,51 @@ public class WifiConnectionPreferenceControllerTest {
|
||||
|
||||
mController = new WifiConnectionPreferenceController(mContext, mLifecycle, mUpdateListener,
|
||||
KEY, 0, 0);
|
||||
mController.mWifiPickerTracker = mWifiPickerTracker;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_noWiFiConnection_availableIsFalse() {
|
||||
when(mWifiTracker.isConnected()).thenReturn(false);
|
||||
public void isAvailable_noConnectedWifiEntry_availableIsFalse() {
|
||||
when(mWifiPickerTracker.getConnectedWifiEntry()).thenReturn(null);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_noWiFiConnection_noPreferenceAdded() {
|
||||
when(mWifiTracker.isConnected()).thenReturn(false);
|
||||
when(mWifiTracker.getAccessPoints()).thenReturn(new ArrayList<>());
|
||||
public void displayPreference_noConnectedWifiEntry_noPreferenceAdded() {
|
||||
when(mWifiPickerTracker.getConnectedWifiEntry()).thenReturn(null);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
verify(mPreferenceCategory, never()).addPreference(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_hasWiFiConnection_preferenceAdded() {
|
||||
when(mWifiTracker.isConnected()).thenReturn(true);
|
||||
final AccessPoint accessPoint = mock(AccessPoint.class);
|
||||
when(accessPoint.isActive()).thenReturn(true);
|
||||
when(mWifiTracker.getAccessPoints()).thenReturn(Arrays.asList(accessPoint));
|
||||
public void displayPreference_hasConnectedWifiEntry_preferenceAdded() {
|
||||
final WifiEntry wifiEntry = mock(WifiEntry.class);
|
||||
when(mWifiPickerTracker.getConnectedWifiEntry()).thenReturn(wifiEntry);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
verify(mPreferenceCategory).addPreference(any(AccessPointPreference.class));
|
||||
verify(mPreferenceCategory).addPreference(any(WifiEntryPreference.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onConnectedChanged_wifiBecameDisconnected_preferenceRemoved() {
|
||||
when(mWifiTracker.isConnected()).thenReturn(true);
|
||||
final AccessPoint accessPoint = mock(AccessPoint.class);
|
||||
final WifiEntry wifiEntry = mock(WifiEntry.class);
|
||||
when(mWifiPickerTracker.getConnectedWifiEntry()).thenReturn(wifiEntry);
|
||||
|
||||
when(accessPoint.isActive()).thenReturn(true);
|
||||
when(mWifiTracker.getAccessPoints()).thenReturn(Arrays.asList(accessPoint));
|
||||
mController.displayPreference(mScreen);
|
||||
final ArgumentCaptor<AccessPointPreference> captor = ArgumentCaptor.forClass(
|
||||
AccessPointPreference.class);
|
||||
final ArgumentCaptor<WifiEntryPreference> captor = ArgumentCaptor.forClass(
|
||||
WifiEntryPreference.class);
|
||||
verify(mPreferenceCategory).addPreference(captor.capture());
|
||||
final AccessPointPreference pref = captor.getValue();
|
||||
final WifiEntryPreference pref = captor.getValue();
|
||||
|
||||
when(mWifiTracker.isConnected()).thenReturn(false);
|
||||
when(mWifiTracker.getAccessPoints()).thenReturn(new ArrayList<>());
|
||||
// Become disconnected.
|
||||
when(mWifiPickerTracker.getConnectedWifiEntry()).thenReturn(null);
|
||||
final int onUpdatedCountBefore = mOnChildUpdatedCount;
|
||||
mController.onConnectedChanged();
|
||||
|
||||
mController.onWifiStateChanged();
|
||||
|
||||
verify(mPreferenceCategory).removePreference(pref);
|
||||
assertThat(mOnChildUpdatedCount).isEqualTo(onUpdatedCountBefore + 1);
|
||||
}
|
||||
@@ -133,28 +130,24 @@ public class WifiConnectionPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void onAccessPointsChanged_wifiBecameConnectedToDifferentAP_preferenceReplaced() {
|
||||
when(mWifiTracker.isConnected()).thenReturn(true);
|
||||
final AccessPoint accessPoint1 = mock(AccessPoint.class);
|
||||
|
||||
when(accessPoint1.isActive()).thenReturn(true);
|
||||
when(mWifiTracker.getAccessPoints()).thenReturn(Arrays.asList(accessPoint1));
|
||||
final WifiEntry wifiEntry1 = mock(WifiEntry.class);
|
||||
when(wifiEntry1.getKey()).thenReturn("KEY_1");
|
||||
when(mWifiPickerTracker.getConnectedWifiEntry()).thenReturn(wifiEntry1);
|
||||
mController.displayPreference(mScreen);
|
||||
final ArgumentCaptor<AccessPointPreference> captor = ArgumentCaptor.forClass(
|
||||
AccessPointPreference.class);
|
||||
final ArgumentCaptor<WifiEntryPreference> captor = ArgumentCaptor.forClass(
|
||||
WifiEntryPreference.class);
|
||||
|
||||
|
||||
final AccessPoint accessPoint2 = mock(AccessPoint.class);
|
||||
when(accessPoint1.isActive()).thenReturn(false);
|
||||
when(accessPoint2.isActive()).thenReturn(true);
|
||||
when(mWifiTracker.getAccessPoints()).thenReturn(Arrays.asList(accessPoint1, accessPoint2));
|
||||
final WifiEntry wifiEntry2 = mock(WifiEntry.class);
|
||||
when(wifiEntry1.getKey()).thenReturn("KEY_2");
|
||||
when(mWifiPickerTracker.getConnectedWifiEntry()).thenReturn(wifiEntry2);
|
||||
final int onUpdatedCountBefore = mOnChildUpdatedCount;
|
||||
mController.onAccessPointsChanged();
|
||||
mController.onWifiEntriesChanged();
|
||||
|
||||
verify(mPreferenceCategory, times(2)).addPreference(captor.capture());
|
||||
final AccessPointPreference pref1 = captor.getAllValues().get(0);
|
||||
final AccessPointPreference pref2 = captor.getAllValues().get(1);
|
||||
assertThat(pref1.getAccessPoint()).isEqualTo(accessPoint1);
|
||||
assertThat(pref2.getAccessPoint()).isEqualTo(accessPoint2);
|
||||
final WifiEntryPreference pref1 = captor.getAllValues().get(0);
|
||||
final WifiEntryPreference pref2 = captor.getAllValues().get(1);
|
||||
assertThat(pref1.getWifiEntry()).isEqualTo(wifiEntry1);
|
||||
assertThat(pref2.getWifiEntry()).isEqualTo(wifiEntry2);
|
||||
verify(mPreferenceCategory).removePreference(eq(pref1));
|
||||
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.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -34,6 +35,8 @@ import android.provider.Settings;
|
||||
import android.service.notification.ConversationChannelWrapper;
|
||||
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.applications.AppInfoBase;
|
||||
import com.android.settings.notification.NotificationBackend;
|
||||
@@ -85,7 +88,10 @@ public class ConversationListPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
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();
|
||||
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 org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -28,11 +29,11 @@ import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Looper;
|
||||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.notification.zen.ZenModeEventRuleSettings;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -40,7 +41,6 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
import org.robolectric.shadows.ShadowToast;
|
||||
|
||||
@@ -68,7 +68,7 @@ public class ZenModeEventRuleSettingsTest {
|
||||
|
||||
ShadowApplication shadowApplication = ShadowApplication.getInstance();
|
||||
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mContext = application;
|
||||
|
||||
mFragment = spy(new TestFragment());
|
||||
mFragment.onAttach(application);
|
||||
@@ -81,6 +81,7 @@ public class ZenModeEventRuleSettingsTest {
|
||||
when(mActivity.getTheme()).thenReturn(res.newTheme());
|
||||
when(mActivity.getIntent()).thenReturn(mIntent);
|
||||
when(mActivity.getResources()).thenReturn(res);
|
||||
when(mActivity.getMainLooper()).thenReturn(mock(Looper.class));
|
||||
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 org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -28,11 +29,11 @@ import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Looper;
|
||||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.notification.zen.ZenModeScheduleRuleSettings;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -40,7 +41,6 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
import org.robolectric.shadows.ShadowToast;
|
||||
|
||||
@@ -65,7 +65,7 @@ public class ZenModeScheduleRuleSettingsTest {
|
||||
|
||||
ShadowApplication shadowApplication = ShadowApplication.getInstance();
|
||||
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mContext = application;
|
||||
|
||||
mFragment = spy(new TestFragment());
|
||||
mFragment.onAttach(application);
|
||||
@@ -78,6 +78,7 @@ public class ZenModeScheduleRuleSettingsTest {
|
||||
when(mActivity.getTheme()).thenReturn(res.newTheme());
|
||||
when(mActivity.getIntent()).thenReturn(mIntent);
|
||||
when(mActivity.getResources()).thenReturn(res);
|
||||
when(mActivity.getMainLooper()).thenReturn(mock(Looper.class));
|
||||
when(mFragment.getContext()).thenReturn(mContext);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ 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;
|
||||
|
||||
@@ -50,6 +51,7 @@ public class WifiMeteredPreferenceController2Test {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
|
||||
mPreferenceController = spy(
|
||||
|
||||
Reference in New Issue
Block a user