Merge Android 24Q2 Release (ab/11526283) to aosp-main-future

Bug: 337098550
Merged-In: I96574a79eba581db95d387f0d9c9fde2e004c41c
Change-Id: Ib9f2c742f8aa72651ef9eca80a716dd94b9041ea
This commit is contained in:
Xin Li
2024-05-23 14:12:07 -07:00
1413 changed files with 69959 additions and 31812 deletions

View File

@@ -0,0 +1,50 @@
/*
* Copyright (C) 2023 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.testutils;
import static android.provider.Settings.Secure.ACCESSIBILITY_BUTTON_MODE_FLOATING_MENU;
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON;
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;
import android.content.Context;
import android.provider.Settings;
import com.android.settings.testutils.shadow.SettingsShadowResources;
/**
* Utility class for common methods used in the accessibility feature related tests
*/
public class AccessibilityTestUtils {
public static void setSoftwareShortcutMode(
Context context, boolean gestureNavEnabled, boolean floatingButtonEnabled) {
int mode = floatingButtonEnabled ? ACCESSIBILITY_BUTTON_MODE_FLOATING_MENU : -1;
Settings.Secure.putInt(context.getContentResolver(),
Settings.Secure.ACCESSIBILITY_BUTTON_MODE, mode);
if (gestureNavEnabled) {
SettingsShadowResources.overrideResource(
com.android.internal.R.integer.config_navBarInteractionMode,
NAV_BAR_MODE_GESTURAL);
} else {
SettingsShadowResources.overrideResource(
com.android.internal.R.integer.config_navBarInteractionMode,
NAV_BAR_MODE_3BUTTON);
}
}
}

View File

@@ -19,7 +19,8 @@ package com.android.settings.testutils.shadow;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.AuthenticatorDescription;
import android.annotation.NonNull;
import androidx.annotation.NonNull;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
@@ -30,7 +31,7 @@ import java.util.List;
import java.util.Map;
@Implements(AccountManager.class)
public class ShadowAccountManager {
public class ShadowAccountManager extends org.robolectric.shadows.ShadowAccountManager {
private static final Map<String, AuthenticatorDescription> sAuthenticators = new HashMap<>();
private static final Map<Integer, List<Account>> sAccountsByUserId = new HashMap<>();
@@ -40,7 +41,8 @@ public class ShadowAccountManager {
return sAuthenticators.values().toArray(new AuthenticatorDescription[sAuthenticators.size()]);
}
public static void addAuthenticator(AuthenticatorDescription authenticator) {
@Override
public void addAuthenticator(AuthenticatorDescription authenticator) {
sAuthenticators.put(authenticator.type, authenticator);
}

View File

@@ -16,11 +16,12 @@
package com.android.settings.testutils.shadow;
import android.annotation.NonNull;
import android.app.ApplicationPackageManager;
import android.content.pm.PackageInfo;
import android.os.IRemoteCallback;
import androidx.annotation.NonNull;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;

View File

@@ -1,102 +0,0 @@
/*
* 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.
*/
package com.android.settings.testutils.shadow;
import static android.media.AudioManager.STREAM_ACCESSIBILITY;
import static android.media.AudioManager.STREAM_ALARM;
import static android.media.AudioManager.STREAM_DTMF;
import static android.media.AudioManager.STREAM_MUSIC;
import static android.media.AudioManager.STREAM_NOTIFICATION;
import static android.media.AudioManager.STREAM_RING;
import static android.media.AudioManager.STREAM_SYSTEM;
import static android.media.AudioManager.STREAM_VOICE_CALL;
import static org.robolectric.RuntimeEnvironment.application;
import android.media.AudioDeviceCallback;
import android.media.AudioManager;
import android.os.Handler;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.shadow.api.Shadow;
import java.util.ArrayList;
import java.util.List;
@Implements(value = AudioManager.class)
public class ShadowAudioManager extends org.robolectric.shadows.ShadowAudioManager {
private int mRingerMode;
private int mDeviceCodes;
private boolean mMusicActiveRemotely;
private List<AudioDeviceCallback> mDeviceCallbacks = new ArrayList<>();
@Implementation
protected int getRingerModeInternal() {
return mRingerMode;
}
public static ShadowAudioManager getShadow() {
return Shadow.extract(application.getSystemService(AudioManager.class));
}
public void setRingerModeInternal(int mode) {
mRingerMode = mode;
}
@Implementation
public void registerAudioDeviceCallback(AudioDeviceCallback callback, Handler handler) {
mDeviceCallbacks.add(callback);
}
@Implementation
public void unregisterAudioDeviceCallback(AudioDeviceCallback callback) {
if (mDeviceCallbacks.contains(callback)) {
mDeviceCallbacks.remove(callback);
}
}
public void setMusicActiveRemotely(boolean flag) {
mMusicActiveRemotely = flag;
}
@Implementation
public boolean isMusicActiveRemotely() {
return mMusicActiveRemotely;
}
public void setOutputDevice(int deviceCodes) {
mDeviceCodes = deviceCodes;
}
@Implementation
public int getDevicesForStream(int streamType) {
switch (streamType) {
case STREAM_VOICE_CALL:
case STREAM_SYSTEM:
case STREAM_RING:
case STREAM_MUSIC:
case STREAM_ALARM:
case STREAM_NOTIFICATION:
case STREAM_DTMF:
case STREAM_ACCESSIBILITY:
return mDeviceCodes;
default:
return 0;
}
}
}

View File

@@ -16,16 +16,10 @@
package com.android.settings.testutils.shadow;
import static android.provider.SearchIndexablesContract.INDEXABLES_RAW_COLUMNS;
import android.accounts.Account;
import android.annotation.UserIdInt;
import android.content.ContentResolver;
import android.content.SyncAdapterType;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.net.Uri;
import android.provider.SearchIndexablesContract;
import android.text.TextUtils;
import org.robolectric.annotation.Implementation;
@@ -35,7 +29,7 @@ import java.util.HashMap;
import java.util.Map;
@Implements(ContentResolver.class)
public class ShadowContentResolver {
public class ShadowContentResolver extends org.robolectric.shadows.ShadowContentResolver {
private static SyncAdapterType[] sSyncAdapterTypes = new SyncAdapterType[0];
private static Map<String, Integer> sSyncable = new HashMap<>();
@@ -47,24 +41,15 @@ public class ShadowContentResolver {
return sSyncAdapterTypes;
}
@Implementation
protected final Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
MatrixCursor cursor = new MatrixCursor(INDEXABLES_RAW_COLUMNS);
MatrixCursor.RowBuilder builder = cursor.newRow()
.add(SearchIndexablesContract.NonIndexableKey.COLUMN_KEY_VALUE, "");
return cursor;
}
@Implementation
protected static int getIsSyncableAsUser(Account account, String authority, int userId) {
return sSyncable.containsKey(authority) ? sSyncable.get(authority) : 1;
return sSyncable.getOrDefault(authority, 1);
}
@Implementation
protected static boolean getSyncAutomaticallyAsUser(Account account, String authority,
int userId) {
return sSyncAutomatically.containsKey(authority) ? sSyncAutomatically.get(authority) : true;
return sSyncAutomatically.getOrDefault(authority, true);
}
@Implementation

View File

@@ -17,13 +17,14 @@
package com.android.settings.testutils.shadow;
import android.Manifest;
import android.annotation.NonNull;
import android.content.Context;
import android.content.pm.CrossProfileApps;
import android.content.pm.ICrossProfileApps;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import androidx.annotation.NonNull;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;

View File

@@ -21,8 +21,6 @@ import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED
import static android.os.Build.VERSION_CODES.O;
import static android.os.Build.VERSION_CODES.Q;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.app.admin.DevicePolicyManager;
import android.app.admin.DevicePolicyManager.DeviceOwnerType;
@@ -33,6 +31,8 @@ import android.app.admin.PasswordPolicy;
import android.content.ComponentName;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.test.core.app.ApplicationProvider;
import org.robolectric.annotation.Implementation;

View File

@@ -27,7 +27,7 @@ import org.robolectric.annotation.Implements;
import java.util.Set;
@Implements(NotificationManager.class)
public class ShadowNotificationManager {
public class ShadowNotificationManager extends org.robolectric.shadows.ShadowNotificationManager {
private int mZenMode;
private ZenModeConfig mZenModeConfig;

View File

@@ -1,54 +0,0 @@
/*
* 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.
*/
package com.android.settings.testutils.shadow;
import static android.system.OsConstants.AF_INET;
import static android.system.OsConstants.AF_INET6;
import android.system.Os;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.regex.Pattern;
@Implements(Os.class)
public class ShadowOs {
// These are not actually correct, but good enough for the test
private static final Pattern IPV4_PATTERN =
Pattern.compile("^\\d{1,3}(\\.\\d{1,3}){3}$");
private static final Pattern IPV6_PATTERN =
Pattern.compile("^[0-9a-f]{1,4}(:[0-9a-f]{0,4}){0,6}$");
private static final byte[] IPV4_BYTES = new byte[4];
private static final byte[] IPV6_BYTES = new byte[16];
@Implementation
protected static InetAddress inet_pton(int family, String address) {
if ((AF_INET == family && IPV4_PATTERN.matcher(address).find()) ||
(AF_INET6 == family && IPV6_PATTERN.matcher(address).find())) {
try {
return InetAddress.getByAddress((AF_INET == family) ? IPV4_BYTES : IPV6_BYTES);
} catch (UnknownHostException uhe) {
// Shouldn't be reached.
}
}
return null;
}
}

View File

@@ -9,7 +9,7 @@ import org.robolectric.annotation.Implements;
* This class provides helpers to test logic that reads from parcels.
*/
@Implements(Parcel.class)
public class ShadowParcel {
public class ShadowParcel extends org.robolectric.shadows.ShadowParcel {
public static int sReadIntResult;
public static int sWriteIntResult;

View File

@@ -1,38 +0,0 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.settings.testutils.shadow;
import android.os.PowerManager;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
@Implements(PowerManager.class)
public class ShadowPowerManager {
@Implementation
protected int getMinimumScreenBrightnessSetting() {
return 0;
}
@Implementation
protected int getMaximumScreenBrightnessSetting() {
return 0;
}
}

View File

@@ -15,9 +15,11 @@
*/
package com.android.settings.testutils.shadow;
import android.annotation.NonNull;
import android.annotation.UserIdInt;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.content.Intent;
import com.android.internal.util.ArrayUtils;
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
@@ -38,6 +40,8 @@ public class ShadowRestrictedLockUtilsInternal {
private static DevicePolicyManager sDevicePolicyManager;
private static String[] sDisabledTypes;
private static int sKeyguardDisabledFeatures;
private static String[] sEcmRestrictedPkgs;
private static boolean sAccessibilityServiceRestricted;
@Resetter
public static void reset() {
@@ -47,10 +51,12 @@ public class ShadowRestrictedLockUtilsInternal {
sDisabledTypes = new String[0];
sMaximumTimeToLockIsSet = false;
sMteOverridden = false;
sEcmRestrictedPkgs = new String[0];
sAccessibilityServiceRestricted = false;
}
@Implementation
protected static EnforcedAdmin checkIfMeteredDataRestricted(Context context,
protected static EnforcedAdmin checkIfMeteredDataUsageUserControlDisabled(Context context,
String packageName, int userId) {
if (sIsRestricted) {
return new EnforcedAdmin();
@@ -108,10 +114,35 @@ public class ShadowRestrictedLockUtilsInternal {
return sMteOverridden ? new EnforcedAdmin() : null;
}
public static EnforcedAdmin checkIfAccessibilityServiceDisallowed(Context context,
String packageName, int userId) {
return sAccessibilityServiceRestricted ? new EnforcedAdmin() : null;
}
@Implementation
public static Intent checkIfRequiresEnhancedConfirmation(@NonNull Context context,
@NonNull String settingIdentifier, @NonNull String packageName) {
if (ArrayUtils.contains(sEcmRestrictedPkgs, packageName)) {
return new Intent();
}
return null;
}
@Implementation
public static boolean isEnhancedConfirmationRestricted(@NonNull Context context,
@NonNull String settingIdentifier, @NonNull String packageName) {
return false;
}
public static void setRestricted(boolean restricted) {
sIsRestricted = restricted;
}
public static void setEcmRestrictedPkgs(String... pkgs) {
sEcmRestrictedPkgs = pkgs;
}
public static void setRestrictedPkgs(String... pkgs) {
sRestrictedPkgs = pkgs;
}

View File

@@ -16,6 +16,8 @@
package com.android.settings.testutils.shadow;
import static android.provider.Settings.DEFAULT_OVERRIDEABLE_BY_RESTORE;
import android.content.ContentResolver;
import android.provider.Settings;
@@ -24,12 +26,13 @@ import com.google.common.collect.Table;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.shadows.ShadowSettings;
import java.util.Map;
import java.util.WeakHashMap;
@Implements(Settings.Secure.class)
public class ShadowSecureSettings {
public class ShadowSecureSettings extends ShadowSettings.ShadowSecure {
private static final Map<ContentResolver, Table<Integer, String, Object>> sUserDataMap =
new WeakHashMap<>();
@@ -48,6 +51,16 @@ public class ShadowSecureSettings {
}
}
/**
* Same implementation as Settings.Secure because robolectric.ShadowSettings.ShadowSecure
* overrides this API.
*/
@Implementation
public static boolean putString(ContentResolver resolver, String name, String value) {
return putStringForUser(resolver, name, value, null, false,
resolver.getUserId(), DEFAULT_OVERRIDEABLE_BY_RESTORE);
}
@Implementation
public static String getStringForUser(ContentResolver resolver, String name, int userHandle) {
final Table<Integer, String, Object> userTable = getUserTable(resolver);
@@ -56,6 +69,15 @@ public class ShadowSecureSettings {
}
}
/**
* Same implementation as Settings.Secure because robolectric.ShadowSettings.ShadowSecure
* overrides this API.
*/
@Implementation
public static boolean putInt(ContentResolver resolver, String name, int value) {
return putIntForUser(resolver, name, value, resolver.getUserId());
}
@Implementation
public static boolean putIntForUser(ContentResolver resolver, String name, int value,
int userHandle) {
@@ -66,6 +88,15 @@ public class ShadowSecureSettings {
}
}
/**
* Same implementation as Settings.Secure because robolectric.ShadowSettings.ShadowSecure
* overrides this API.
*/
@Implementation
public static int getInt(ContentResolver resolver, String name, int def) {
return getIntForUser(resolver, name, def, resolver.getUserId());
}
@Implementation
public static int getIntForUser(ContentResolver resolver, String name, int def,
int userHandle) {

View File

@@ -16,12 +16,13 @@
package com.android.settings.testutils.shadow;
import android.annotation.NonNull;
import android.os.storage.DiskInfo;
import android.os.storage.StorageManager;
import android.os.storage.VolumeInfo;
import android.os.storage.VolumeRecord;
import androidx.annotation.NonNull;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.Resetter;
@@ -30,7 +31,7 @@ import java.util.ArrayList;
import java.util.List;
@Implements(StorageManager.class)
public class ShadowStorageManager {
public class ShadowStorageManager extends org.robolectric.shadows.ShadowStorageManager {
private static boolean sIsUnmountCalled;
private static boolean sIsForgetCalled;