Use resource processor for Settings

Bug: 293810334
Test: m Settings
Test: robotests
Change-Id: Ie515e137648eddfdfcab5e8095f5be99721d9e1b
This commit is contained in:
Chaohui Wang
2023-08-11 13:43:02 +08:00
parent b199f3512a
commit 2cab62254c
35 changed files with 114 additions and 512 deletions

View File

@@ -55,6 +55,7 @@ android_library {
],
srcs: ["src/**/*.java", "src/**/*.kt"],
use_resource_processor: true,
resource_dirs: [
"res",
"res-export", // for external usage
@@ -136,6 +137,7 @@ android_app {
],
static_libs: ["Settings-core"],
uses_libs: ["org.apache.http.legacy"],
use_resource_processor: true,
resource_dirs: [],
optimize: {
proguard_flags_files: ["proguard.flags"],

View File

@@ -50,9 +50,9 @@ import com.google.android.setupdesign.template.RequireScrollMixin
import com.google.android.setupdesign.util.DeviceHelper
import com.google.android.setupdesign.util.DynamicColorPalette
import com.google.android.setupdesign.util.DynamicColorPalette.ColorType.ACCENT
import java.util.function.Supplier
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import java.util.function.Supplier
/**
* Fingerprint intro onboarding page fragment implementation
@@ -324,6 +324,6 @@ fun FragmentActivity.bindFingerprintEnrollIntroView(
)
}
view.findViewById<ScrollView>(R.id.sud_scroll_view)?.importantForAccessibility =
View.IMPORTANT_FOR_ACCESSIBILITY_YES
view.findViewById<ScrollView>(com.google.android.setupdesign.R.id.sud_scroll_view)
?.importantForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_YES
}

View File

@@ -18,12 +18,10 @@ package com.android.settings.remoteauth.finish
import android.os.Bundle
import android.view.View
import com.airbnb.lottie.LottieAnimationView
import com.android.settings.R
import com.android.settings.remoteauth.RemoteAuthEnrollBase
import com.android.settingslib.widget.LottieColorUtils
import com.airbnb.lottie.LottieAnimationView
import com.google.android.setupcompat.template.FooterButton
/**
@@ -45,7 +43,7 @@ class RemoteAuthEnrollFinish :
.setText(R.string.security_settings_remoteauth_enroll_finish_btn_next)
.setListener(this::onPrimaryFooterButtonClick)
.setButtonType(FooterButton.ButtonType.NEXT)
.setTheme(R.style.SudGlifButton_Primary)
.setTheme(com.google.android.setupdesign.R.style.SudGlifButton_Primary)
.build()
}

View File

@@ -49,7 +49,7 @@ class RemoteAuthEnrollIntroduction :
.setText(R.string.security_settings_remoteauth_enroll_introduction_agree)
.setListener(::onPrimaryFooterButtonClick)
.setButtonType(FooterButton.ButtonType.OPT_IN)
.setTheme(R.style.SudGlifButton_Primary)
.setTheme(com.google.android.setupdesign.R.style.SudGlifButton_Primary)
.build()
}
@@ -58,7 +58,7 @@ class RemoteAuthEnrollIntroduction :
.setText(R.string.security_settings_remoteauth_enroll_introduction_disagree)
.setListener(::onSecondaryFooterButtonClick)
.setButtonType(FooterButton.ButtonType.NEXT)
.setTheme(R.style.SudGlifButton_Primary)
.setTheme(com.google.android.setupdesign.R.style.SudGlifButton_Primary)
.build()
}

View File

@@ -86,8 +86,8 @@ public class SearchMenuController implements LifecycleObserver, OnCreateOptionsM
return;
}
final MenuItem searchItem = menu.add(Menu.NONE, MENU_SEARCH, 0 /* order */,
R.string.search_menu);
searchItem.setIcon(R.drawable.ic_search_24dp);
com.android.settingslib.search.R.string.search_menu);
searchItem.setIcon(com.android.settingslib.search.R.drawable.ic_search_24dp);
searchItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
searchItem.setOnMenuItemClickListener(target -> {

View File

@@ -1,7 +1,3 @@
//############################################################
// Build SettingsRoboTestStub.apk which includes test-only resources.#
//############################################################
package {
// See: http://go/android-license-faq
// A large-scale-change added 'default_applicable_licenses' to import
@@ -11,6 +7,7 @@ package {
default_applicable_licenses: ["packages_apps_Settings_license"],
}
// Build SettingsRoboTestStub.apk which includes test-only resources.
android_app {
name: "SettingsRoboTestStub",
defaults: [
@@ -25,33 +22,8 @@ android_app {
static_libs: [
"Settings-core",
"androidx-constraintlayout_constraintlayout",
"androidx.slice_slice-builders",
"androidx.slice_slice-core",
"androidx.slice_slice-view",
"androidx.core_core",
"androidx.appcompat_appcompat",
"androidx.cardview_cardview",
"androidx.fragment_fragment-testing",
"androidx.preference_preference",
"androidx.recyclerview_recyclerview",
"androidx.window_window",
"com.google.android.material_material",
"setupcompat",
"setupdesign",
"androidx.lifecycle_lifecycle-runtime",
"androidx.test.core",
"androidx.test.runner",
"androidx.test.ext.junit",
"frameworks-base-testutils",
"guava",
"jsr305",
"settings-contextual-card-protos-lite",
"settings-log-bridge-protos-lite",
"settings-telephony-protos-lite",
"contextualcards",
"settings-logtags",
"zxing-core-1.7",
],
aaptflags: ["--extra-packages com.android.settings"],
@@ -67,9 +39,7 @@ android_app {
],
}
//############################################################
// Settings Robolectric test target. #
//############################################################
// Settings Robolectric test target.
android_robolectric_test {
name: "SettingsRoboTests",
srcs: [
@@ -79,12 +49,12 @@ android_robolectric_test {
static_libs: [
"SettingsLib-robo-testutils",
"android-support-annotations",
"Settings-robo-testutils",
"androidx.test.core",
"androidx.test.espresso.core",
"androidx.test.ext.junit",
"androidx.test.rules",
"androidx.test.runner",
"androidx.test.ext.junit",
"androidx.test.espresso.core",
],
libs: [
@@ -109,7 +79,7 @@ android_robolectric_test {
java_library {
name: "Settings-robo-testutils",
srcs: ["src/com/android/settings/testutils/**/*.java"],
srcs: ["testutils/**/*.java"],
libs: [
"Settings-core",

View File

@@ -35,21 +35,29 @@ class RemoteAuthEnrollFinishTest {
@Test
fun testRemoteAuthenticatorEnrollFinish_hasHeader() {
launchFragmentInContainer<RemoteAuthEnrollFinish>(Bundle(), R.style.SudThemeGlif)
.onFragment {
assertThat((it.view as GlifLayout).headerText)
.isEqualTo(mContext.getString(
R.string.security_settings_remoteauth_enroll_finish_title))
}
launchFragmentInContainer<RemoteAuthEnrollFinish>(
Bundle(),
com.google.android.setupdesign.R.style.SudThemeGlif,
).onFragment {
assertThat((it.view as GlifLayout).headerText)
.isEqualTo(
mContext.getString(R.string.security_settings_remoteauth_enroll_finish_title)
)
}
}
@Test
fun testRemoteAuthenticatorEnrollFinish_hasDescription() {
launchFragmentInContainer<RemoteAuthEnrollFinish>(Bundle(), R.style.SudThemeGlif)
.onFragment {
assertThat((it.view as GlifLayout).descriptionText)
.isEqualTo(mContext.getString(
R.string.security_settings_remoteauth_enroll_finish_description))
}
launchFragmentInContainer<RemoteAuthEnrollFinish>(
Bundle(),
com.google.android.setupdesign.R.style.SudThemeGlif,
).onFragment {
assertThat((it.view as GlifLayout).descriptionText)
.isEqualTo(
mContext.getString(
R.string.security_settings_remoteauth_enroll_finish_description
)
)
}
}
}
}

View File

@@ -30,23 +30,31 @@ import org.robolectric.RobolectricTestRunner
@RunWith(RobolectricTestRunner::class)
class RemoteAuthEnrollIntroductionTest {
private var mContext : Context = ApplicationProvider.getApplicationContext()
private var mContext: Context = ApplicationProvider.getApplicationContext()
@Test
fun testRemoteAuthenticatorEnrollIntroduction_hasHeader() {
launchFragmentInContainer<RemoteAuthEnrollIntroduction>(Bundle(), R.style.SudThemeGlif)
.onFragment {
assertThat((it.view as GlifLayout).headerText)
.isEqualTo(mContext.getString(R.string.security_settings_remoteauth_enroll_introduction_title))
}
launchFragmentInContainer<RemoteAuthEnrollIntroduction>(
Bundle(),
com.google.android.setupdesign.R.style.SudThemeGlif,
).onFragment {
assertThat((it.view as GlifLayout).headerText)
.isEqualTo(mContext.getString(R.string.security_settings_remoteauth_enroll_introduction_title))
}
}
@Test
fun testRemoteAuthenticatorEnrollIntroduction_hasDescription() {
launchFragmentInContainer<RemoteAuthEnrollIntroduction>(Bundle(), R.style.SudThemeGlif)
.onFragment {
assertThat((it.view as GlifLayout).descriptionText)
.isEqualTo(mContext.getString(R.string.security_settings_remoteauth_enroll_introduction_message))
}
launchFragmentInContainer<RemoteAuthEnrollIntroduction>(
Bundle(),
com.google.android.setupdesign.R.style.SudThemeGlif,
).onFragment {
assertThat((it.view as GlifLayout).descriptionText)
.isEqualTo(
mContext.getString(
R.string.security_settings_remoteauth_enroll_introduction_message
)
)
}
}
}
}

View File

@@ -33,7 +33,6 @@ import android.view.MenuItem;
import androidx.fragment.app.FragmentActivity;
import com.android.settings.R;
import com.android.settings.core.InstrumentedFragment;
import com.android.settings.testutils.shadow.ShadowUtils;
@@ -72,7 +71,7 @@ public class SearchMenuControllerTest {
when(mHost.getActivity()).thenReturn(mActivity);
when(mMenu.add(Menu.NONE, MENU_SEARCH, 0 /* order */,
R.string.search_menu))
com.android.settingslib.search.R.string.search_menu))
.thenReturn(mock(MenuItem.class));
}
@@ -82,7 +81,7 @@ public class SearchMenuControllerTest {
mHost.getSettingsLifecycle().onCreateOptionsMenu(mMenu, null /* inflater */);
verify(mMenu).add(Menu.NONE, MENU_SEARCH, 0 /* order */,
R.string.search_menu);
com.android.settingslib.search.R.string.search_menu);
}
@Test

View File

@@ -1,36 +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 com.android.settings.applications.AppInfoBase;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
@Implements(AppInfoBase.class)
public class ShadowAppInfoBase {
@Implementation
protected void onResume() {
// No-op.
}
@Implementation
protected void onPause() {
// No-op.
}
}

View File

@@ -1,32 +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 android.os.Looper;
import com.android.settingslib.applications.ApplicationsState;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
@Implements(ApplicationsState.class)
public class ShadowApplicationsState {
@Implementation
protected Looper getBackgroundLooper() {
return Looper.getMainLooper();
}
}

View File

@@ -1,22 +0,0 @@
package com.android.settings.testutils.shadow;
import com.android.settings.datausage.DataSaverBackend;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
@Implements(DataSaverBackend.class)
public class ShadowDataSaverBackend {
private static boolean isEnabled = true;
@Implementation
protected boolean isDataSaverEnabled() {
return isEnabled;
}
@Implementation
protected void setDataSaverEnabled(boolean enabled) {
isEnabled = enabled;
}
}

View File

@@ -1,66 +0,0 @@
/*
* Copyright (C) 2016 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 org.robolectric.util.ReflectionHelpers.ClassParameter.from;
import android.hardware.input.IInputManager;
import android.hardware.input.InputManager;
import android.os.Handler;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.util.ReflectionHelpers;
import java.util.ArrayList;
import java.util.List;
/**
* Shadow for {@link InputManager} that has accessors for registered
* {@link InputManager.InputDeviceListener}s.
*/
@Implements(value = InputManager.class, callThroughByDefault = false)
public class ShadowInputManager {
private List<InputManager.InputDeviceListener> mInputDeviceListeners;
@Implementation
protected void __constructor__(IInputManager service) {
mInputDeviceListeners = new ArrayList<>();
}
@Implementation
protected static InputManager getInstance() {
return ReflectionHelpers.callConstructor(
InputManager.class,
from(IInputManager.class, null));
}
@Implementation
protected void registerInputDeviceListener(InputManager.InputDeviceListener listener,
Handler handler) {
// TODO: Use handler.
if (!mInputDeviceListeners.contains(listener)) {
mInputDeviceListeners.add(listener);
}
}
@Implementation
protected void unregisterInputDeviceListener(InputManager.InputDeviceListener listener) {
mInputDeviceListeners.remove(listener);
}
}

View File

@@ -1,60 +0,0 @@
/*
* 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.
*/
package com.android.settings.testutils.shadow;
import static org.mockito.Mockito.mock;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkScoreManager;
import android.net.wifi.WifiManager;
import android.os.Handler;
import androidx.annotation.NonNull;
import androidx.lifecycle.Lifecycle;
import com.android.wifitrackerlib.NetworkDetailsTracker;
import com.android.wifitrackerlib.WifiEntry;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import java.time.Clock;
@Implements(NetworkDetailsTracker.class)
public class ShadowNetworkDetailsTracker {
@Implementation
public static NetworkDetailsTracker createNetworkDetailsTracker(@NonNull Lifecycle lifecycle,
@NonNull Context context,
@NonNull WifiManager wifiManager,
@NonNull ConnectivityManager connectivityManager,
@NonNull NetworkScoreManager networkScoreManager,
@NonNull Handler mainHandler,
@NonNull Handler workerHandler,
@NonNull Clock clock,
long maxScanAgeMillis,
long scanIntervalMillis,
String key) {
return mock(NetworkDetailsTracker.class);
}
@Implementation
public WifiEntry getWifiEntry() {
return mock(WifiEntry.class);
}
}

View File

@@ -1,45 +0,0 @@
/*
* Copyright (C) 2019 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.annotation.CallbackExecutor;
import android.content.Context;
import android.os.Handler;
import android.permission.PermissionControllerManager;
import androidx.annotation.NonNull;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import java.util.concurrent.Executor;
@Implements(PermissionControllerManager.class)
public class ShadowPermissionControllerManager {
protected void __constructor__(Context contexts, Handler handler) {
// no nothing, everything is shadowed
}
@Implementation
public void getPermissionUsages(boolean countSystem, long numMillis,
@NonNull @CallbackExecutor Executor executor,
@NonNull PermissionControllerManager.OnPermissionUsageResultCallback callback) {
// Do nothing
}
}

View File

@@ -1,93 +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 static org.robolectric.RuntimeEnvironment.application;
import android.net.wifi.ScanResult;
import android.net.wifi.SoftApConfiguration;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.net.wifi.hotspot2.PasspointConfiguration;
import org.robolectric.annotation.HiddenApi;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.shadow.api.Shadow;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@Implements(value = WifiManager.class)
public class ShadowWifiManager extends org.robolectric.shadows.ShadowWifiManager {
private List<PasspointConfiguration> mPasspointConfiguration;
public WifiConfiguration savedWifiConfig;
private SoftApConfiguration mSavedApConfig;
@Implementation
protected SoftApConfiguration getSoftApConfiguration() {
return mSavedApConfig;
}
@Implementation
protected boolean setSoftApConfiguration(SoftApConfiguration softApConfig) {
mSavedApConfig = softApConfig;
return true;
}
@HiddenApi // @SystemApi
@Implementation
protected void connect(WifiConfiguration config, WifiManager.ActionListener listener) {
savedWifiConfig = config;
}
@HiddenApi
@Implementation
protected void save(WifiConfiguration config, WifiManager.ActionListener listener) {
savedWifiConfig = config;
}
@Implementation
protected List<PasspointConfiguration> getPasspointConfigurations() {
return mPasspointConfiguration == null ? Collections.emptyList() : mPasspointConfiguration;
}
@Implementation
protected void addOrUpdatePasspointConfiguration(PasspointConfiguration config) {
if (mPasspointConfiguration == null) {
mPasspointConfiguration = new ArrayList<>();
}
mPasspointConfiguration.add(config);
}
@Implementation
protected boolean isDualModeSupported() {
return false;
}
@Implementation
protected List<ScanResult> getScanResults() {
return new ArrayList<ScanResult>();
}
public static ShadowWifiManager get() {
return Shadow.extract(application.getSystemService(WifiManager.class));
}
}

View File

@@ -1,55 +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 android.net.wifi.p2p.WifiP2pManager;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.Resetter;
/**
* Shadow class for WifiP2pManager.
*/
@Implements(value = WifiP2pManager.class)
public class ShadowWifiP2pManager extends org.robolectric.shadows.ShadowWifiP2pManager {
private static int sFactoryResetCount;
@Implementation
protected void factoryReset(WifiP2pManager.Channel c, WifiP2pManager.ActionListener listener) {
if (c != null) {
sFactoryResetCount++;
} else {
throw new IllegalArgumentException("channel must be non-null.");
}
}
@Resetter
public static void reset() {
sFactoryResetCount = 0;
}
/**
* Return the count of factoryReset called.
*
* @return the count of factoryReset called.
*/
public static int getFactoryResetCount() {
return sFactoryResetCount;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2016 The Android Open Source Project
* 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.
@@ -11,7 +11,7 @@
* 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
* limitations under the License.
*/
package com.android.settings.testutils;
@@ -23,7 +23,6 @@ import com.android.settings.accessibility.AccessibilityMetricsFeatureProvider;
import com.android.settings.accessibility.AccessibilitySearchFeatureProvider;
import com.android.settings.accounts.AccountFeatureProvider;
import com.android.settings.applications.ApplicationFeatureProvider;
import com.android.settings.onboarding.OnboardingFeatureProvider;
import com.android.settings.biometrics.face.FaceFeatureProvider;
import com.android.settings.biometrics2.factory.BiometricsRepositoryProvider;
import com.android.settings.bluetooth.BluetoothFeatureProvider;
@@ -39,6 +38,7 @@ import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
import com.android.settings.homepage.contextualcards.ContextualCardFeatureProvider;
import com.android.settings.inputmethod.KeyboardSettingsFeatureProvider;
import com.android.settings.localepicker.LocaleFeatureProvider;
import com.android.settings.onboarding.OnboardingFeatureProvider;
import com.android.settings.overlay.DockUpdaterFeatureProvider;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.overlay.SupportFeatureProvider;

View File

@@ -1,3 +1,19 @@
/*
* 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.shadow;
import static org.robolectric.RuntimeEnvironment.application;

View File

@@ -38,39 +38,40 @@ public class ShadowAlertDialogCompat extends ShadowDialog {
@SuppressLint("StaticFieldLeak")
@Nullable
private static ShadowAlertDialogCompat latestSupportAlertDialog;
private static ShadowAlertDialogCompat sLatestSupportAlertDialog;
@RealObject
private AlertDialog realAlertDialog;
private AlertDialog mRealAlertDialog;
@Implementation
public void show() {
super.show();
latestSupportAlertDialog = this;
sLatestSupportAlertDialog = this;
}
public CharSequence getMessage() {
final Object alertController = ReflectionHelpers.getField(realAlertDialog, "mAlert");
final Object alertController = ReflectionHelpers.getField(mRealAlertDialog, "mAlert");
return ReflectionHelpers.getField(alertController, "mMessage");
}
public CharSequence getTitle() {
final Object alertController = ReflectionHelpers.getField(realAlertDialog, "mAlert");
final Object alertController = ReflectionHelpers.getField(mRealAlertDialog, "mAlert");
return ReflectionHelpers.getField(alertController, "mTitle");
}
public View getView() {
final Object alertController = ReflectionHelpers.getField(realAlertDialog, "mAlert");
final Object alertController = ReflectionHelpers.getField(mRealAlertDialog, "mAlert");
return ReflectionHelpers.getField(alertController, "mView");
}
@Nullable
public static AlertDialog getLatestAlertDialog() {
return latestSupportAlertDialog == null ? null : latestSupportAlertDialog.realAlertDialog;
return sLatestSupportAlertDialog == null
? null : sLatestSupportAlertDialog.mRealAlertDialog;
}
@Resetter
public static void reset() {
latestSupportAlertDialog = null;
sLatestSupportAlertDialog = null;
}
public static ShadowAlertDialogCompat shadowOf(AlertDialog alertDialog) {
@@ -78,6 +79,6 @@ public class ShadowAlertDialogCompat extends ShadowDialog {
}
public void clickOnItem(int index) {
Shadows.shadowOf(realAlertDialog.getListView()).performItemClick(index);
Shadows.shadowOf(mRealAlertDialog.getListView()).performItemClick(index);
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018 The Android Open Source Project
* 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.
@@ -16,16 +16,23 @@
package com.android.settings.testutils.shadow;
import com.android.settingslib.wifi.AccessPoint;
import com.android.settings.datausage.DataSaverBackend;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
@Implements(AccessPoint.class)
public class ShadowAccessPoint {
@Implements(DataSaverBackend.class)
public class ShadowDataSaverBackend {
private static boolean sIsEnabled = true;
@Implementation
protected String getSavedNetworkSummary() {
return "saved";
protected boolean isDataSaverEnabled() {
return sIsEnabled;
}
@Implementation
protected void setDataSaverEnabled(boolean enabled) {
sIsEnabled = enabled;
}
}

View File

@@ -114,8 +114,8 @@ public class ShadowLockPatternUtils {
}
@Implementation
protected byte[] getPasswordHistoryHashFactor(LockscreenCredential currentPassword,
int userId) {
protected byte[] getPasswordHistoryHashFactor(
LockscreenCredential currentPassword, int userId) {
return null;
}
@@ -130,8 +130,8 @@ public class ShadowLockPatternUtils {
}
@Implementation
public @DevicePolicyManager.PasswordComplexity int getRequestedPasswordComplexity(int userId,
boolean deviceWideOnly) {
@DevicePolicyManager.PasswordComplexity
public int getRequestedPasswordComplexity(int userId, boolean deviceWideOnly) {
int complexity = sUserToComplexityMap.getOrDefault(userId,
DevicePolicyManager.PASSWORD_COMPLEXITY_NONE);
if (!deviceWideOnly) {
@@ -178,14 +178,16 @@ public class ShadowLockPatternUtils {
}
@Implementation
public boolean setLockCredential(@NonNull LockscreenCredential newCredential,
public boolean setLockCredential(
@NonNull LockscreenCredential newCredential,
@NonNull LockscreenCredential savedCredential, int userHandle) {
setIsSecure(userHandle, true);
return true;
}
@Implementation
public boolean checkCredential(@NonNull LockscreenCredential credential, int userId,
public boolean checkCredential(
@NonNull LockscreenCredential credential, int userId,
@Nullable LockPatternUtils.CheckCredentialProgressCallback progressCallback)
throws LockPatternUtils.RequestThrottledException {
return true;

View File

@@ -52,7 +52,7 @@ public class ShadowUserManager extends org.robolectric.shadows.ShadowUserManager
private final Set<Integer> mManagedProfiles = new HashSet<>();
private final Set<String> mEnabledTypes = new HashSet<>();
private boolean mIsQuietModeEnabled = false;
private int[] profileIdsForUser = new int[0];
private int[] mProfileIdsForUser = new int[0];
private boolean mUserSwitchEnabled;
private Bundle mDefaultGuestUserRestriction = new Bundle();
private boolean mIsGuestUser = false;
@@ -154,11 +154,11 @@ public class ShadowUserManager extends org.robolectric.shadows.ShadowUserManager
@Implementation
protected int[] getProfileIdsWithDisabled(@UserIdInt int userId) {
return profileIdsForUser;
return mProfileIdsForUser;
}
public void setProfileIdsWithDisabled(int[] profileIds) {
profileIdsForUser = profileIds;
mProfileIdsForUser = profileIds;
}
@Implementation