Snap for 7183400 from 9edf9597e9 to sc-v2-release

Change-Id: Idee932deec98c2079dd842727b23115e97c28b98
This commit is contained in:
android-build-team Robot
2021-03-04 02:08:11 +00:00
23 changed files with 261 additions and 118 deletions

View File

@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2021 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.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingStart="56dp"
android:paddingEnd="8dp"
android:paddingTop="16dp"
android:paddingBottom="16dp">
<TextView
android:id="@android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="16dp"
android:layout_marginStart="16dp"
android:maxLines="1"
android:textAppearance="@android:style/TextAppearance.Material.Subhead"
android:textColor="?android:attr/textColorPrimary" />
<SeekBar
android:id="@*android:id/seekbar"
android:layout_gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:orientation="horizontal">
<TextView
android:id="@android:id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_weight="1"
android:maxLines="1"
android:textAlignment="viewStart"/>
<TextView
android:id="@android:id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_weight="1"
android:maxLines="1"
android:textAlignment="viewEnd"/>
</LinearLayout>
</LinearLayout>

View File

@@ -2985,7 +2985,7 @@
<!-- [CHAR LIMIT=NONE] Display settings screen, setting description for the always-on ambient display feature. -->
<string name="doze_always_on_summary">Increased battery usage</string>
<!-- [CHAR LIMIT=30] Display and accessibility settings screens, setting option name to force bold text. -->
<string name="force_bold_text">Bold Text</string>
<string name="force_bold_text">Bold text</string>
<!-- [CHAR LIMIT=30] Sound & display settings screen, setting option name to change font size -->
<string name="title_font_size">Font size</string>
<!-- Summary for Font size. Lets the user know that this will make text larger or smaller. Appears in the accessibility portion of setup wizard. [CHAR LIMIT=NONE] -->
@@ -4037,7 +4037,7 @@
<string name="managed_profile_location_services">Location services for work</string>
<!-- [CHAR LIMIT=60] Location settings screen, screen title -->
<string name="location_time_zone_detection_screen_title">Location time zone detection</string>
<string name="location_time_zone_detection_screen_title">Use location to set time zone</string>
<!-- [CHAR LIMIT=50] Location settings screen, title for the setting that control whether the
device can use its location for time zone detection. -->
<string name="location_time_zone_detection_enabled_title">Location time zone detection</string>
@@ -4051,7 +4051,7 @@
<!-- [CHAR LIMIT=NONE] Location settings screen, summary when location time zone detection is not
applicable due to other settings like the "automatic time zone detection enabled" setting
being set to "off". -->
<string name="location_time_zone_detection_auto_is_off">Automatic time zone detection is disabled</string>
<string name="location_time_zone_detection_auto_is_off">Automatic time zone is off</string>
<!-- [CHAR LIMIT=NONE] Location settings screen, summary when location time zone detection is not
applicable for the user for unspecified reasons. More specific messages are used when there
is a clear reason. -->
@@ -12801,6 +12801,8 @@
<!-- Alert Dialog text when user didn't input the phone number [CHAR LIMIT=50]-->
<string name="smart_forwarding_missing_alert_dialog_text">OK</string>
<!-- Enable 2G: Title for if user wants to enable 2G [CHAR LIMIT=40] -->
<!-- Title for toggle if user wants to enable 2G [CHAR LIMIT=40] -->
<string name="enable_2g_title">Allow 2G</string>
<!-- Title for toggle if user wants to enable 2G [CHAR LIMIT=NONE] -->
<string name="enable_2g_summary">Use 2G cellular connections. For emergency calls, 2G is always turned on.</string>
</resources>

View File

@@ -258,5 +258,6 @@
<SwitchPreference
android:key="enable_2g"
android:title="@string/enable_2g_title"
android:summary="@string/enable_2g_summary"
settings:controller="com.android.settings.network.telephony.Enable2gPreferenceController" />
</PreferenceScreen>

View File

@@ -17,13 +17,16 @@
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:persistent="false"
android:title="@string/reduce_bright_colors_preference_title">
<com.android.settings.widget.SeekBarPreference
<com.android.settings.widget.LabeledContinuousSeekBarPreference
android:key="rbc_intensity"
android:persistent="false"
android:title="@string/reduce_bright_colors_intensity_preference_title"/>
android:title="@string/reduce_bright_colors_intensity_preference_title"
settings:textStart="@string/reduce_bright_colors_intensity_preference_start_label"
settings:textEnd="@string/reduce_bright_colors_intensity_preference_end_label"/>
<SwitchPreference
android:key="rbc_persist"

View File

@@ -128,8 +128,15 @@ public class ToggleScreenMagnificationPreferenceFragment extends
@Override
protected void initSettingsPreference() {
// If the device doesn't support magnification area, it should hide the settings preference.
if (!getContext().getResources().getBoolean(
com.android.internal.R.bool.config_magnification_area)) {
return;
}
mSettingsPreference = new Preference(getPrefContext());
mSettingsPreference.setTitle(R.string.accessibility_menu_item_settings);
// TODO(b/177371954): "magnification area" should be brought up to the highest level of the
// settings UI so that it appears below "shortcut" to replace "settings.
mSettingsPreference.setFragment(MagnificationSettingsFragment.class.getName());
mSettingsPreference.setPersistent(false);

View File

@@ -28,7 +28,7 @@ import android.content.pm.PackageManager;
import android.hardware.usb.UsbManager;
import android.hardware.usb.UsbPort;
import android.hardware.usb.UsbPortStatus;
import android.net.ConnectivityManager;
import android.net.TetheringManager;
import android.os.UserHandle;
import android.os.UserManager;
@@ -74,9 +74,8 @@ public class UsbBackend {
mIsAdminUser = userManager.isAdminUser();
mMidiSupported = context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_MIDI);
ConnectivityManager cm =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
mTetheringSupported = cm.isTetheringSupported();
final TetheringManager tm = context.getSystemService(TetheringManager.class);
mTetheringSupported = tm.isTetheringSupported();
updatePorts();
}

View File

@@ -16,14 +16,17 @@
package com.android.settings.connecteddevice.usb;
import static android.net.ConnectivityManager.TETHERING_USB;
import static android.net.TetheringManager.TETHERING_USB;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.hardware.usb.UsbManager;
import android.net.ConnectivityManager;
import android.net.TetheringManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerExecutor;
import android.util.Log;
import androidx.annotation.VisibleForTesting;
import androidx.preference.PreferenceScreen;
@@ -43,10 +46,13 @@ import java.util.List;
* Provides options for selecting the default USB mode.
*/
public class UsbDefaultFragment extends RadioButtonPickerFragment {
private static final String TAG = "UsbDefaultFragment";
@VisibleForTesting
UsbBackend mUsbBackend;
@VisibleForTesting
ConnectivityManager mConnectivityManager;
TetheringManager mTetheringManager;
@VisibleForTesting
OnStartTetheringCallback mOnStartTetheringCallback = new OnStartTetheringCallback();
@VisibleForTesting
@@ -57,6 +63,7 @@ public class UsbDefaultFragment extends RadioButtonPickerFragment {
boolean mIsStartTethering = false;
private UsbConnectionBroadcastReceiver mUsbReceiver;
private Handler mHandler = new Handler();
@VisibleForTesting
UsbConnectionBroadcastReceiver.UsbConnectionListener mUsbConnectionListener =
@@ -71,7 +78,7 @@ public class UsbDefaultFragment extends RadioButtonPickerFragment {
public void onAttach(Context context) {
super.onAttach(context);
mUsbBackend = new UsbBackend(context);
mConnectivityManager = context.getSystemService(ConnectivityManager.class);
mTetheringManager = context.getSystemService(TetheringManager.class);
mUsbReceiver = new UsbConnectionBroadcastReceiver(context, mUsbConnectionListener,
mUsbBackend);
getSettingsLifecycle().addObserver(mUsbReceiver);
@@ -138,9 +145,9 @@ public class UsbDefaultFragment extends RadioButtonPickerFragment {
if (!Utils.isMonkeyRunning()) {
if (functions == UsbManager.FUNCTION_RNDIS) {
// We need to have entitlement check for usb tethering, so use API in
// ConnectivityManager.
// TetheringManager.
mIsStartTethering = true;
mConnectivityManager.startTethering(TETHERING_USB, true /* showProvisioningUi */,
mTetheringManager.startTethering(TETHERING_USB, new HandlerExecutor(mHandler),
mOnStartTetheringCallback);
} else {
mIsStartTethering = false;
@@ -159,20 +166,19 @@ public class UsbDefaultFragment extends RadioButtonPickerFragment {
}
@VisibleForTesting
final class OnStartTetheringCallback extends
ConnectivityManager.OnStartTetheringCallback {
final class OnStartTetheringCallback implements
TetheringManager.StartTetheringCallback {
@Override
public void onTetheringStarted() {
super.onTetheringStarted();
// Set default usb functions again to make internal data persistent
mCurrentFunctions = UsbManager.FUNCTION_RNDIS;
mUsbBackend.setDefaultUsbFunctions(UsbManager.FUNCTION_RNDIS);
}
@Override
public void onTetheringFailed() {
super.onTetheringFailed();
public void onTetheringFailed(int error) {
Log.w(TAG, "onTetheringFailed() error : " + error);
mUsbBackend.setDefaultUsbFunctions(mPreviousFunctions);
updateCandidates();
}

View File

@@ -17,11 +17,12 @@
package com.android.settings.connecteddevice.usb;
import static android.hardware.usb.UsbPortStatus.DATA_ROLE_DEVICE;
import static android.net.ConnectivityManager.TETHERING_USB;
import android.content.Context;
import android.hardware.usb.UsbManager;
import android.net.ConnectivityManager;
import android.net.TetheringManager;
import android.os.Handler;
import android.os.HandlerExecutor;
import android.util.Log;
import androidx.annotation.VisibleForTesting;
@@ -55,7 +56,8 @@ public class UsbDetailsFunctionsController extends UsbDetailsController
}
private PreferenceCategory mProfilesContainer;
private ConnectivityManager mConnectivityManager;
private TetheringManager mTetheringManager;
private Handler mHandler = new Handler();
@VisibleForTesting
OnStartTetheringCallback mOnStartTetheringCallback;
@VisibleForTesting
@@ -64,7 +66,7 @@ public class UsbDetailsFunctionsController extends UsbDetailsController
public UsbDetailsFunctionsController(Context context, UsbDetailsFragment fragment,
UsbBackend backend) {
super(context, fragment, backend);
mConnectivityManager = context.getSystemService(ConnectivityManager.class);
mTetheringManager = context.getSystemService(TetheringManager.class);
mOnStartTetheringCallback = new OnStartTetheringCallback();
mPreviousFunction = mUsbBackend.getCurrentFunctions();
}
@@ -130,7 +132,7 @@ public class UsbDetailsFunctionsController extends UsbDetailsController
+ UsbManager.usbFunctionsToString(previousFunction));
}
if (function != previousFunction && !Utils.isMonkeyRunning()
&& !shouldIgnoreClickEvent(function, previousFunction)) {
&& !isClickEventIgnored(function, previousFunction)) {
mPreviousFunction = previousFunction;
//Update the UI in advance to make it looks smooth
@@ -144,8 +146,9 @@ public class UsbDetailsFunctionsController extends UsbDetailsController
if (function == UsbManager.FUNCTION_RNDIS) {
// We need to have entitlement check for usb tethering, so use API in
// ConnectivityManager.
mConnectivityManager.startTethering(TETHERING_USB, true /* showProvisioningUi */,
// TetheringManager.
mTetheringManager.startTethering(
TetheringManager.TETHERING_USB, new HandlerExecutor(mHandler),
mOnStartTetheringCallback);
} else {
mUsbBackend.setCurrentFunctions(function);
@@ -153,7 +156,7 @@ public class UsbDetailsFunctionsController extends UsbDetailsController
}
}
private boolean shouldIgnoreClickEvent(long function, long previousFunction) {
private boolean isClickEventIgnored(long function, long previousFunction) {
return isAccessoryMode(previousFunction) && function == UsbManager.FUNCTION_MTP;
}
@@ -172,12 +175,11 @@ public class UsbDetailsFunctionsController extends UsbDetailsController
}
@VisibleForTesting
final class OnStartTetheringCallback extends
ConnectivityManager.OnStartTetheringCallback {
final class OnStartTetheringCallback implements TetheringManager.StartTetheringCallback {
@Override
public void onTetheringFailed() {
super.onTetheringFailed();
public void onTetheringFailed(int error) {
Log.w(TAG, "onTetheringFailed() error : " + error);
mUsbBackend.setCurrentFunctions(mPreviousFunction);
}
}

View File

@@ -20,10 +20,7 @@ import static android.net.NetworkPolicyManager.POLICY_REJECT_METERED_BACKGROUND;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.net.INetworkPolicyListener;
import android.net.NetworkPolicyManager;
import android.os.RemoteException;
import android.telephony.SubscriptionPlan;
import android.util.SparseIntArray;
import com.android.settings.overlay.FeatureFactory;
@@ -180,33 +177,17 @@ public class DataSaverBackend {
}
private final INetworkPolicyListener mPolicyListener = new INetworkPolicyListener.Stub() {
@Override
public void onUidRulesChanged(int uid, int uidRules) throws RemoteException {
}
private final NetworkPolicyManager.Listener mPolicyListener =
new NetworkPolicyManager.Listener() {
@Override
public void onUidPoliciesChanged(final int uid, final int uidPolicies) {
ThreadUtils.postOnMainThread(() -> handleUidPoliciesChanged(uid, uidPolicies));
}
@Override
public void onMeteredIfacesChanged(String[] strings) throws RemoteException {
}
@Override
public void onRestrictBackgroundChanged(final boolean isDataSaving) throws RemoteException {
public void onRestrictBackgroundChanged(final boolean isDataSaving) {
ThreadUtils.postOnMainThread(() -> handleRestrictBackgroundChanged(isDataSaving));
}
@Override
public void onSubscriptionOverride(int subId, int overrideMask, int overrideValue,
int[] networkTypes) {
}
@Override
public void onSubscriptionPlansChanged(int subId, SubscriptionPlan[] plans) {
}
};
public interface Listener {

View File

@@ -85,7 +85,8 @@ public class RecentLocationAccessPreferenceController extends LocationBasePrefer
final Context prefContext = mCategoryRecentLocationRequests.getContext();
final List<RecentLocationAccesses.Access> recentLocationAccesses = new ArrayList<>();
final UserManager userManager = UserManager.get(mContext);
for (RecentLocationAccesses.Access access : mRecentLocationApps.getAppListSorted()) {
for (RecentLocationAccesses.Access access : mRecentLocationApps.getAppListSorted(
/* showSystemApps= */ false)) {
if (isRequestMatchesProfileType(userManager, access, mType)) {
recentLocationAccesses.add(access);
}

View File

@@ -208,7 +208,7 @@ public class RequestManageCredentials extends Activity {
.write();
finishWithResultCancelled();
});
allowButton.setOnClickListener(b -> setOrUpdateCredentialManagementApp());
allowButton.setOnClickListener(b -> setOrUpdateCredentialManagementAppAndFinish());
}
private void loadExtendedFloatingActionButton() {
@@ -220,13 +220,14 @@ public class RequestManageCredentials extends Activity {
});
}
private void setOrUpdateCredentialManagementApp() {
private void setOrUpdateCredentialManagementAppAndFinish() {
try {
mKeyChainConnection.getService().setCredentialManagementApp(
mCredentialManagerPackage, mAuthenticationPolicy);
DevicePolicyEventLogger
.createEvent(DevicePolicyEnums.CREDENTIAL_MANAGEMENT_APP_REQUEST_ACCEPTED)
.write();
setResult(RESULT_OK);
} catch (RemoteException e) {
Log.e(TAG, "Unable to set credential manager app", e);
logRequestFailure();

View File

@@ -28,6 +28,7 @@ import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.UnrecoverableKeyException;
import java.security.cert.Certificate;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
@@ -88,6 +89,10 @@ public class AndroidKeystoreAliasLoader {
if (key != null) {
if (key instanceof PrivateKey) {
mKeyCertAliases.add(alias);
final Certificate[] cert = keyStore.getCertificateChain(alias);
if (cert != null && cert.length >= 2) {
mCaCertAliases.add(alias);
}
}
} else {
if (keyStore.getCertificate(alias) != null) {

View File

@@ -24,8 +24,6 @@ import android.content.pm.PackageManager;
import android.net.ProxyInfo;
import android.os.Bundle;
import android.os.SystemProperties;
import android.security.Credentials;
import android.security.KeyStore;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
@@ -42,10 +40,12 @@ import androidx.appcompat.app.AlertDialog;
import com.android.internal.net.VpnProfile;
import com.android.net.module.util.ProxyUtils;
import com.android.settings.R;
import com.android.settings.utils.AndroidKeystoreAliasLoader;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
/**
@@ -58,7 +58,7 @@ import java.util.List;
class ConfigDialog extends AlertDialog implements TextWatcher,
View.OnClickListener, AdapterView.OnItemSelectedListener,
CompoundButton.OnCheckedChangeListener {
private final KeyStore mKeyStore = KeyStore.getInstance();
private static final String TAG = "ConfigDialog";
private final DialogInterface.OnClickListener mListener;
private final VpnProfile mProfile;
@@ -153,10 +153,13 @@ class ConfigDialog extends AlertDialog implements TextWatcher,
mL2tpSecret.setTextAppearance(android.R.style.TextAppearance_DeviceDefault_Medium);
mIpsecIdentifier.setText(mProfile.ipsecIdentifier);
mIpsecSecret.setText(mProfile.ipsecSecret);
loadCertificates(mIpsecUserCert, Credentials.USER_PRIVATE_KEY, 0, mProfile.ipsecUserCert);
loadCertificates(mIpsecCaCert, Credentials.CA_CERTIFICATE,
AndroidKeystoreAliasLoader androidKeystoreAliasLoader =
new AndroidKeystoreAliasLoader(null);
loadCertificates(mIpsecUserCert, androidKeystoreAliasLoader.getKeyCertAliases(), 0,
mProfile.ipsecUserCert);
loadCertificates(mIpsecCaCert, androidKeystoreAliasLoader.getCaCertAliases(),
R.string.vpn_no_ca_cert, mProfile.ipsecCaCert);
loadCertificates(mIpsecServerCert, Credentials.USER_CERTIFICATE,
loadCertificates(mIpsecServerCert, androidKeystoreAliasLoader.getKeyCertAliases(),
R.string.vpn_no_server_cert, mProfile.ipsecServerCert);
mSaveLogin.setChecked(mProfile.saveLogin);
mAlwaysOnVpn.setChecked(mProfile.key.equals(VpnUtils.getLockdownVpn()));
@@ -511,27 +514,30 @@ class ConfigDialog extends AlertDialog implements TextWatcher,
typeSpinner.setAdapter(adapter);
}
private void loadCertificates(Spinner spinner, String prefix, int firstId, String selected) {
private void loadCertificates(Spinner spinner, Collection<String> choices, int firstId,
String selected) {
Context context = getContext();
String first = (firstId == 0) ? "" : context.getString(firstId);
String[] certificates = mKeyStore.list(prefix);
String[] myChoices;
if (certificates == null || certificates.length == 0) {
certificates = new String[] {first};
if (choices == null || choices.size() == 0) {
myChoices = new String[] {first};
} else {
String[] array = new String[certificates.length + 1];
array[0] = first;
System.arraycopy(certificates, 0, array, 1, certificates.length);
certificates = array;
myChoices = new String[choices.size() + 1];
myChoices[0] = first;
int i = 1;
for (String c : choices) {
myChoices[i++] = c;
}
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
context, android.R.layout.simple_spinner_item, certificates);
context, android.R.layout.simple_spinner_item, myChoices);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
for (int i = 1; i < certificates.length; ++i) {
if (certificates[i].equals(selected)) {
for (int i = 1; i < myChoices.length; ++i) {
if (myChoices[i].equals(selected)) {
spinner.setSelection(i);
break;
}

View File

@@ -25,7 +25,7 @@ import android.os.Bundle;
import android.os.RemoteException;
import android.os.UserHandle;
import android.security.Credentials;
import android.security.KeyStore;
import android.security.LegacyVpnProfileStore;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
@@ -151,9 +151,8 @@ public class ConfigDialogFragment extends InstrumentedDialogFragment implements
return;
}
// Delete from KeyStore
KeyStore keyStore = KeyStore.getInstance();
keyStore.delete(Credentials.VPN + profile.key, KeyStore.UID_SELF);
// Delete from profile store.
LegacyVpnProfileStore.remove(Credentials.VPN + profile.key);
updateLockdownVpn(false, profile);
}
@@ -188,8 +187,7 @@ public class ConfigDialogFragment extends InstrumentedDialogFragment implements
}
private void save(VpnProfile profile, boolean lockdown) {
KeyStore.getInstance().put(Credentials.VPN + profile.key, profile.encode(),
KeyStore.UID_SELF, /* flags */ 0);
LegacyVpnProfileStore.put(Credentials.VPN + profile.key, profile.encode());
// Flush out old version of profile
disconnect(profile);

View File

@@ -41,7 +41,7 @@ import android.os.Message;
import android.os.UserHandle;
import android.os.UserManager;
import android.security.Credentials;
import android.security.KeyStore;
import android.security.LegacyVpnProfileStore;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.Log;
@@ -57,7 +57,6 @@ import com.android.internal.annotations.GuardedBy;
import com.android.internal.net.LegacyVpnInfo;
import com.android.internal.net.VpnConfig;
import com.android.internal.net.VpnProfile;
import com.android.internal.util.ArrayUtils;
import com.android.settings.R;
import com.android.settings.RestrictedSettingsFragment;
import com.android.settings.widget.GearPreference;
@@ -94,8 +93,6 @@ public class VpnSettings extends RestrictedSettingsFragment implements
private UserManager mUserManager;
private VpnManager mVpnManager;
private final KeyStore mKeyStore = KeyStore.getInstance();
private Map<String, LegacyVpnPreference> mLegacyVpnPreferences = new ArrayMap<>();
private Map<AppVpnInfo, AppPreference> mAppPreferences = new ArrayMap<>();
@@ -222,7 +219,7 @@ public class VpnSettings extends RestrictedSettingsFragment implements
final Context context = activity.getApplicationContext();
// Run heavy RPCs before switching to UI thread
final List<VpnProfile> vpnProfiles = loadVpnProfiles(mKeyStore);
final List<VpnProfile> vpnProfiles = loadVpnProfiles();
final List<AppVpnInfo> vpnApps = getVpnApps(context, /* includeProfiles */ true);
final Map<String, LegacyVpnInfo> connectedLegacyVpns = getConnectedLegacyVpns();
@@ -540,12 +537,13 @@ public class VpnSettings extends RestrictedSettingsFragment implements
return result;
}
static List<VpnProfile> loadVpnProfiles(KeyStore keyStore, int... excludeTypes) {
private static List<VpnProfile> loadVpnProfiles() {
final ArrayList<VpnProfile> result = Lists.newArrayList();
for (String key : keyStore.list(Credentials.VPN)) {
final VpnProfile profile = VpnProfile.decode(key, keyStore.get(Credentials.VPN + key));
if (profile != null && !ArrayUtils.contains(excludeTypes, profile.type)) {
for (String key : LegacyVpnProfileStore.list(Credentials.VPN)) {
final VpnProfile profile = VpnProfile.decode(key,
LegacyVpnProfileStore.get(Credentials.VPN + key));
if (profile != null) {
result.add(profile);
}
}

View File

@@ -20,7 +20,7 @@ import android.net.VpnManager;
import android.os.RemoteException;
import android.provider.Settings;
import android.security.Credentials;
import android.security.KeyStore;
import android.security.LegacyVpnProfileStore;
import com.android.internal.net.LegacyVpnInfo;
import com.android.internal.net.VpnConfig;
@@ -28,27 +28,25 @@ import com.android.internal.net.VpnConfig;
/**
* Utility functions for vpn.
*
* Keystore methods should only be called in system user
* LegacyVpnProfileStore methods should only be called in system user
*/
public class VpnUtils {
private static final String TAG = "VpnUtils";
public static String getLockdownVpn() {
final byte[] value = KeyStore.getInstance().get(
Credentials.LOCKDOWN_VPN, true /* suppressKeyNotFoundWarning */);
final byte[] value = LegacyVpnProfileStore.get(Credentials.LOCKDOWN_VPN);
return value == null ? null : new String(value);
}
public static void clearLockdownVpn(Context context) {
KeyStore.getInstance().delete(Credentials.LOCKDOWN_VPN);
LegacyVpnProfileStore.remove(Credentials.LOCKDOWN_VPN);
// Always notify VpnManager after keystore update
getVpnManager(context).updateLockdownVpn();
}
public static void setLockdownVpn(Context context, String lockdownKey) {
KeyStore.getInstance().put(Credentials.LOCKDOWN_VPN, lockdownKey.getBytes(),
KeyStore.UID_SELF, /* flags */ 0);
LegacyVpnProfileStore.put(Credentials.LOCKDOWN_VPN, lockdownKey.getBytes());
// Always notify VpnManager after keystore update
getVpnManager(context).updateLockdownVpn();
}

View File

@@ -0,0 +1,44 @@
/*
* Copyright (C) 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.widget;
import android.content.Context;
import android.util.AttributeSet;
import com.android.settings.R;
/** A continuous labeled slider preference */
public class LabeledContinuousSeekBarPreference extends LabeledSeekBarPreference {
public LabeledContinuousSeekBarPreference(Context context) {
this(context, null);
}
public LabeledContinuousSeekBarPreference(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public LabeledContinuousSeekBarPreference(Context context, AttributeSet attrs,
int defStyleAttr) {
this(context, attrs, defStyleAttr, 0);
}
public LabeledContinuousSeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr,
int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
setLayoutResource(R.layout.preference_labeled_continuous_slider);
}
}

View File

@@ -31,6 +31,7 @@ import static org.mockito.Mockito.when;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.os.Bundle;
import android.provider.Settings;
import android.view.LayoutInflater;
@@ -75,7 +76,8 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
"com.android.server.accessibility.MagnificationController";
private TestToggleScreenMagnificationPreferenceFragment mFragment;
private Context mContext = ApplicationProvider.getApplicationContext();
private Context mContext;
private Resources mResources;
@Mock
private PreferenceManager mPreferenceManager;
@@ -86,10 +88,14 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
public void setUpTestFragment() {
MockitoAnnotations.initMocks(this);
mContext = spy(ApplicationProvider.getApplicationContext());
mFragment = spy(new TestToggleScreenMagnificationPreferenceFragment());
when(mFragment.getPreferenceManager()).thenReturn(mPreferenceManager);
when(mFragment.getPreferenceManager().getContext()).thenReturn(mContext);
when(mFragment.getContext()).thenReturn(mContext);
mResources = spy(mContext.getResources());
when(mContext.getResources()).thenReturn(mResources);
when(mFragment.getContext().getResources()).thenReturn(mResources);
doReturn(null).when(mFragment).getPreferenceScreen();
doReturn(mActivity).when(mFragment).getActivity();
}
@@ -250,6 +256,16 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
assertThat(expectedType).isEqualTo(UserShortcutType.HARDWARE | UserShortcutType.TRIPLETAP);
}
@Test
public void initSettingsPreference_notSupportsMagnificationArea_settingsPreferenceIsNull() {
when(mResources.getBoolean(
com.android.internal.R.bool.config_magnification_area))
.thenReturn(false);
mFragment.initSettingsPreference();
assertThat(mFragment.mSettingsPreference).isNull();
}
private void putStringIntoSettings(String key, String componentName) {
Settings.Secure.putString(mContext.getContentResolver(), key, componentName);
}

View File

@@ -34,7 +34,7 @@ import android.content.pm.PackageManager;
import android.hardware.usb.UsbManager;
import android.hardware.usb.UsbPort;
import android.hardware.usb.UsbPortStatus;
import android.net.ConnectivityManager;
import android.net.TetheringManager;
import android.os.UserHandle;
import android.os.UserManager;
@@ -57,7 +57,7 @@ public class UsbBackendTest {
@Mock
private UserManager mUserManager;
@Mock
private ConnectivityManager mConnectivityManager;
private TetheringManager mTetheringManager;
@Mock
private UsbPort mUsbPort;
@Mock
@@ -69,8 +69,8 @@ public class UsbBackendTest {
when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_MIDI))
.thenReturn(true);
when((Object) mContext.getSystemService(UsbManager.class)).thenReturn(mUsbManager);
when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE))
.thenReturn(mConnectivityManager);
when((Object) mContext.getSystemService(
TetheringManager.class)).thenReturn(mTetheringManager);
when(mUsbManager.getPorts()).thenReturn(Collections.singletonList(mUsbPort));
when(mUsbPortStatus.isConnected()).thenReturn(true);
when(mUsbPort.getStatus()).thenReturn(mUsbPortStatus);

View File

@@ -18,11 +18,12 @@ package com.android.settings.connecteddevice.usb;
import static android.hardware.usb.UsbPortStatus.DATA_ROLE_DEVICE;
import static android.hardware.usb.UsbPortStatus.POWER_ROLE_SINK;
import static android.net.ConnectivityManager.TETHERING_USB;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@@ -30,7 +31,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.hardware.usb.UsbManager;
import android.net.ConnectivityManager;
import android.net.TetheringManager;
import androidx.preference.PreferenceScreen;
@@ -50,7 +51,7 @@ public class UsbDefaultFragmentTest {
@Mock
private UsbBackend mUsbBackend;
@Mock
private ConnectivityManager mConnectivityManager;
private TetheringManager mTetheringManager;
private UsbDefaultFragment mFragment;
@@ -59,7 +60,7 @@ public class UsbDefaultFragmentTest {
MockitoAnnotations.initMocks(this);
mFragment = new TestFragment();
mFragment.mUsbBackend = mUsbBackend;
mFragment.mConnectivityManager = mConnectivityManager;
mFragment.mTetheringManager = mTetheringManager;
}
@Test
@@ -136,8 +137,9 @@ public class UsbDefaultFragmentTest {
mFragment.setDefaultKey(UsbBackend.usbFunctionsToString(UsbManager.FUNCTION_RNDIS));
verify(mConnectivityManager).startTethering(TETHERING_USB, true,
mFragment.mOnStartTetheringCallback);
verify(mTetheringManager).startTethering(eq(TetheringManager.TETHERING_USB),
any(),
eq(mFragment.mOnStartTetheringCallback));
assertThat(mFragment.mPreviousFunctions).isEqualTo(
UsbManager.FUNCTION_MTP);
}

View File

@@ -18,11 +18,12 @@ package com.android.settings.connecteddevice.usb;
import static android.hardware.usb.UsbPortStatus.DATA_ROLE_DEVICE;
import static android.hardware.usb.UsbPortStatus.POWER_ROLE_SINK;
import static android.net.ConnectivityManager.TETHERING_USB;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
@@ -31,7 +32,7 @@ import static org.mockito.Mockito.when;
import android.content.Context;
import android.hardware.usb.UsbManager;
import android.net.ConnectivityManager;
import android.net.TetheringManager;
import androidx.fragment.app.FragmentActivity;
import androidx.preference.PreferenceCategory;
@@ -73,7 +74,7 @@ public class UsbDetailsFunctionsControllerTest {
@Mock
private FragmentActivity mActivity;
@Mock
private ConnectivityManager mConnectivityManager;
private TetheringManager mTetheringManager;
@Before
public void setUp() {
@@ -89,7 +90,7 @@ public class UsbDetailsFunctionsControllerTest {
when(mFragment.getContext()).thenReturn(mContext);
when(mFragment.getPreferenceManager()).thenReturn(mPreferenceManager);
when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
when(mContext.getSystemService(ConnectivityManager.class)).thenReturn(mConnectivityManager);
when(mContext.getSystemService(TetheringManager.class)).thenReturn(mTetheringManager);
mDetailsFunctionsController = new UsbDetailsFunctionsController(mContext, mFragment,
mUsbBackend);
@@ -245,8 +246,9 @@ public class UsbDetailsFunctionsControllerTest {
mDetailsFunctionsController.onRadioButtonClicked(mRadioButtonPreference);
verify(mConnectivityManager).startTethering(TETHERING_USB, true,
mDetailsFunctionsController.mOnStartTetheringCallback);
verify(mTetheringManager).startTethering(eq(TetheringManager.TETHERING_USB),
any(),
eq(mDetailsFunctionsController.mOnStartTetheringCallback));
assertThat(mDetailsFunctionsController.mPreviousFunction).isEqualTo(
UsbManager.FUNCTION_MTP);
}
@@ -295,15 +297,16 @@ public class UsbDetailsFunctionsControllerTest {
mDetailsFunctionsController.onRadioButtonClicked(mRadioButtonPreference);
verify(mUsbBackend, never()).setCurrentFunctions(UsbManager.FUNCTION_PTP);
verify(mConnectivityManager, never()).startTethering(TETHERING_USB, true,
mDetailsFunctionsController.mOnStartTetheringCallback);
verify(mTetheringManager, never()).startTethering(eq(TetheringManager.TETHERING_USB),
any(),
eq(mDetailsFunctionsController.mOnStartTetheringCallback));
}
@Test
public void onTetheringFailed_resetPreviousFunctions() {
mDetailsFunctionsController.mPreviousFunction = UsbManager.FUNCTION_PTP;
mDetailsFunctionsController.mOnStartTetheringCallback.onTetheringFailed();
mDetailsFunctionsController.mOnStartTetheringCallback.onTetheringFailed(0);
verify(mUsbBackend).setCurrentFunctions(UsbManager.FUNCTION_PTP);
}

View File

@@ -105,6 +105,7 @@ public class BaseBluetoothDialogPreferenceTest {
public void onBindDialogView_checkRadioButtonsText() {
when(mView.findViewById(ID1)).thenReturn(mRadioButton1);
when(mView.findViewById(ID2)).thenReturn(mRadioButton2);
when(mView.findViewById(TEXT_VIEW_ID)).thenReturn(mTextView);
assertThat(mRadioButton1.getText()).isNotEqualTo(BUTTON1);
assertThat(mRadioButton2.getText()).isNotEqualTo(BUTTON2);
@@ -118,6 +119,7 @@ public class BaseBluetoothDialogPreferenceTest {
public void onBindDialogView_checkRadioButtonsState() {
when(mView.findViewById(ID1)).thenReturn(mRadioButton1);
when(mView.findViewById(ID2)).thenReturn(mRadioButton2);
when(mView.findViewById(TEXT_VIEW_ID)).thenReturn(mTextView);
List<Integer> indexes = new ArrayList<>();
indexes.add(0);
when(mCallback.getSelectableIndex()).thenReturn(indexes);

View File

@@ -98,7 +98,7 @@ public class RecentLocationAccessPreferenceControllerTest {
@Test
@Ignore
public void updateState_whenAppListIsEmpty_shouldDisplayTitleTextAndDetailsText() {
doReturn(new ArrayList<>()).when(mRecentLocationApps).getAppListSorted();
doReturn(new ArrayList<>()).when(mRecentLocationApps).getAppListSorted(false);
mController.displayPreference(mScreen);
mController.updateState(mLayoutPreference);