Merge "Fix bypass CALL_PRIVILEGED permission in AppRestrictionsFragment"
diff --git a/res/layout/daltonizer_preview.xml b/res/layout/daltonizer_preview.xml
index de462f1..c500554 100644
--- a/res/layout/daltonizer_preview.xml
+++ b/res/layout/daltonizer_preview.xml
@@ -18,7 +18,9 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/preview_viewport"
android:layout_width="match_parent"
- android:layout_height="wrap_content">
+ android:layout_height="wrap_content"
+ android:paddingStart="?android:attr/listPreferredItemPaddingStart"
+ android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
<LinearLayout
android:id="@+id/palette_view"
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 59d5980..94de83b 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -289,6 +289,7 @@
<dimen name="accessibility_layout_margin_start_end">16dp</dimen>
<dimen name="accessibility_button_preference_padding_top_bottom">18dp</dimen>
<dimen name="accessibility_imageview_size">176dp</dimen>
+ <dimen name="accessibility_illustration_view_radius">28dp</dimen>
<!-- The margin between two Textviews-->
<dimen name="accessibility_textview_layout_margin_bottom">24dp</dimen>
diff --git a/res/xml/privacy_dashboard_settings.xml b/res/xml/privacy_dashboard_settings.xml
index cd7d798..7e1d5ce 100644
--- a/res/xml/privacy_dashboard_settings.xml
+++ b/res/xml/privacy_dashboard_settings.xml
@@ -49,7 +49,6 @@
android:key="privacy_permissions_usage"
android:title="@string/permissions_usage_title"
android:summary="@string/permissions_usage_summary"
- settings:searchable="false"
settings:controller="com.android.settings.privacy.PrivacyHubPreferenceController">
<intent android:action="android.intent.action.REVIEW_PERMISSION_USAGE"/>
</Preference>
@@ -58,8 +57,7 @@
<Preference
android:key="privacy_manage_perms"
android:title="@string/app_permissions"
- android:summary="@string/runtime_permissions_summary_control_app_access"
- settings:searchable="false">
+ android:summary="@string/runtime_permissions_summary_control_app_access">
<intent android:action="android.intent.action.MANAGE_PERMISSIONS"/>
</Preference>
diff --git a/src/com/android/settings/SettingsPreferenceFragment.java b/src/com/android/settings/SettingsPreferenceFragment.java
index 1d6a48d..d3e1c49 100644
--- a/src/com/android/settings/SettingsPreferenceFragment.java
+++ b/src/com/android/settings/SettingsPreferenceFragment.java
@@ -54,6 +54,7 @@
import com.android.settingslib.widget.LayoutPreference;
import com.google.android.material.appbar.AppBarLayout;
+import com.google.android.setupcompat.util.WizardManagerHelper;
import java.util.UUID;
@@ -63,7 +64,7 @@
public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceFragment
implements DialogCreatable, HelpResourceProvider, Indexable {
- private static final String TAG = "SettingsPreference";
+ private static final String TAG = "SettingsPreferenceFragment";
private static final String SAVE_HIGHLIGHTED_KEY = "android:preference_highlighted";
@@ -122,6 +123,15 @@
private boolean mPreferenceHighlighted = false;
@Override
+ public void onAttach(Context context) {
+ if (shouldSkipForInitialSUW() && !WizardManagerHelper.isDeviceProvisioned(getContext())) {
+ Log.w(TAG, "Skip " + getClass().getSimpleName() + " before SUW completed.");
+ finish();
+ }
+ super.onAttach(context);
+ }
+
+ @Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
@@ -267,6 +277,16 @@
|| (mAdapter.getPreferenceAdapterPosition(preference) != RecyclerView.NO_POSITION));
}
+ /**
+ * Whether UI should be skipped in the initial SUW flow.
+ *
+ * @return {@code true} when UI should be skipped in the initial SUW flow.
+ * {@code false} when UI should not be skipped in the initial SUW flow.
+ */
+ protected boolean shouldSkipForInitialSUW() {
+ return false;
+ }
+
protected void onDataSetChanged() {
highlightPreferenceIfNeeded();
updateEmptyView();
diff --git a/src/com/android/settings/accessibility/PaletteListPreference.java b/src/com/android/settings/accessibility/PaletteListPreference.java
index ac552eb..4e10b93 100644
--- a/src/com/android/settings/accessibility/PaletteListPreference.java
+++ b/src/com/android/settings/accessibility/PaletteListPreference.java
@@ -148,6 +148,8 @@
rootView.addView(textView);
}
+
+ updateFirstAndLastItemsBackground(context, rootView, paletteData.size());
}
private GradientDrawable createGradientDrawable(ViewGroup rootView, @ColorInt int color) {
@@ -164,6 +166,19 @@
return gradientDrawable;
}
+ private void updateFirstAndLastItemsBackground(Context context, ViewGroup rootView, int size) {
+ final int radius =
+ context.getResources().getDimensionPixelSize(
+ R.dimen.accessibility_illustration_view_radius);
+ final int lastIndex = size - 1;
+ final GradientDrawable firstItem =
+ (GradientDrawable) rootView.getChildAt(0).getBackground();
+ final GradientDrawable lastItem =
+ (GradientDrawable) rootView.getChildAt(lastIndex).getBackground();
+ firstItem.setCornerRadii(new float[]{radius, radius, radius, radius, 0, 0, 0, 0});
+ lastItem.setCornerRadii(new float[]{0, 0, 0, 0, radius, radius, radius, radius});
+ }
+
private List<Integer> getPaletteColors(Context context) {
final int[] paletteResources =
context.getResources().getIntArray(R.array.setting_palette_colors);
diff --git a/src/com/android/settings/accounts/AccountDashboardFragment.java b/src/com/android/settings/accounts/AccountDashboardFragment.java
index f57b124..a2b6182 100644
--- a/src/com/android/settings/accounts/AccountDashboardFragment.java
+++ b/src/com/android/settings/accounts/AccountDashboardFragment.java
@@ -84,6 +84,11 @@
return controllers;
}
+ @Override
+ protected boolean shouldSkipForInitialSUW() {
+ return true;
+ }
+
static void buildAutofillPreferenceControllers(
Context context, List<AbstractPreferenceController> controllers) {
controllers.add(new DefaultAutofillPreferenceController(context));
diff --git a/src/com/android/settings/applications/appinfo/AppInfoDashboardFragment.java b/src/com/android/settings/applications/appinfo/AppInfoDashboardFragment.java
index 159eec6..243dc56 100755
--- a/src/com/android/settings/applications/appinfo/AppInfoDashboardFragment.java
+++ b/src/com/android/settings/applications/appinfo/AppInfoDashboardFragment.java
@@ -507,6 +507,11 @@
return true;
}
+ @Override
+ protected boolean shouldSkipForInitialSUW() {
+ return true;
+ }
+
private void uninstallPkg(String packageName, boolean allUsers, boolean andDisable) {
stopListeningToPackageRemove();
// Create new intent to launch Uninstaller activity
diff --git a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
index c02ae42..946e0d7 100644
--- a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
+++ b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
@@ -215,6 +215,11 @@
}
}
+ @Override
+ protected boolean shouldSkipForInitialSUW() {
+ return true;
+ }
+
/**
* Long-pressing a developer options quick settings tile will by default (see
* QS_TILE_PREFERENCES in the manifest) take you to the developer options page.
diff --git a/src/com/android/settings/display/BrightnessLevelPreferenceController.java b/src/com/android/settings/display/BrightnessLevelPreferenceController.java
index de4fe25..171f426 100644
--- a/src/com/android/settings/display/BrightnessLevelPreferenceController.java
+++ b/src/com/android/settings/display/BrightnessLevelPreferenceController.java
@@ -19,6 +19,7 @@
import static com.android.settingslib.display.BrightnessUtils.GAMMA_SPACE_MIN;
import static com.android.settingslib.display.BrightnessUtils.convertLinearToGammaFloat;
+import android.app.ActivityOptions;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
@@ -156,7 +157,11 @@
final Intent intent = new Intent(ACTION_SHOW_BRIGHTNESS_DIALOG);
intent.putExtra(SettingsBaseActivity.EXTRA_PAGE_TRANSITION_TYPE,
SettingsTransitionHelper.TransitionType.TRANSITION_NONE);
- mContext.startActivity(intent);
+
+ // Start activity in the same task and pass fade animations
+ final ActivityOptions options = ActivityOptions.makeCustomAnimation(mContext,
+ android.R.anim.fade_in, android.R.anim.fade_out);
+ mContext.startActivityForResult(preference.getKey(), intent, 0, options.toBundle());
return true;
}
diff --git a/src/com/android/settings/network/NetworkProviderSettings.java b/src/com/android/settings/network/NetworkProviderSettings.java
index 0082934..e0f8181 100644
--- a/src/com/android/settings/network/NetworkProviderSettings.java
+++ b/src/com/android/settings/network/NetworkProviderSettings.java
@@ -566,7 +566,9 @@
}
if (mSelectedWifiEntry.canDisconnect()) {
- menu.add(Menu.NONE, MENU_ID_SHARE, 0 /* order */, R.string.share);
+ if (mSelectedWifiEntry.canShare()) {
+ menu.add(Menu.NONE, MENU_ID_SHARE, 0 /* order */, R.string.share);
+ }
menu.add(Menu.NONE, MENU_ID_DISCONNECT, 1 /* order */,
R.string.wifi_disconnect_button_text);
}
diff --git a/src/com/android/settings/network/SwitchToEuiccSubscriptionSidecar.java b/src/com/android/settings/network/SwitchToEuiccSubscriptionSidecar.java
index 9b0105b..888e5b2 100644
--- a/src/com/android/settings/network/SwitchToEuiccSubscriptionSidecar.java
+++ b/src/com/android/settings/network/SwitchToEuiccSubscriptionSidecar.java
@@ -18,7 +18,6 @@
import android.app.FragmentManager;
import android.app.PendingIntent;
-import android.content.Intent;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.UiccCardInfo;
@@ -106,21 +105,8 @@
// Use INVALID_SUBSCRIPTION_ID to disable the esim profile.
// The SimSlotMapping is ready, then to execute activate/inactivate esim.
mIsDuringSimSlotMapping = true;
- EuiccManager.ResultListener callback = new EuiccManager.ResultListener() {
- @Override
- public void onComplete(int resultCode, Intent resultIntent) {
- Log.i(TAG, String.format("Result code : %d;", resultCode));
- if (resultCode == EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_OK) {
- mSwitchSlotSidecar.runSwitchToEuiccSlot(getTargetSlot(), mPort,
- removedSubInfo);
- } else {
- setState(State.ERROR, resultCode);
- }
- }
- };
mEuiccManager.switchToSubscription(SubscriptionManager.INVALID_SUBSCRIPTION_ID, mPort,
- getContext().getMainExecutor(),
- callback);
+ mCallbackIntent);
} else {
mSwitchSlotSidecar.runSwitchToEuiccSlot(getTargetSlot(), mPort, removedSubInfo);
}
@@ -187,19 +173,7 @@
private void switchToSubscription() {
// The SimSlotMapping is ready, then to execute activate/inactivate esim.
- EuiccManager.ResultListener callback = new EuiccManager.ResultListener() {
- @Override
- public void onComplete(int resultCode, Intent resultIntent) {
- Log.i(TAG, String.format("Result code : %d;", resultCode));
- if (resultCode == EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_OK) {
- setState(State.SUCCESS, Substate.UNUSED);
- } else {
- setState(State.ERROR, resultCode);
- }
- }
- };
- mEuiccManager.switchToSubscription(mSubId, mPort, getContext().getMainExecutor(),
- callback);
+ mEuiccManager.switchToSubscription(mSubId, mPort, mCallbackIntent);
}
@Override
diff --git a/src/com/android/settings/privacy/CameraToggleController.java b/src/com/android/settings/privacy/CameraToggleController.java
index 1a5da76..756553c 100644
--- a/src/com/android/settings/privacy/CameraToggleController.java
+++ b/src/com/android/settings/privacy/CameraToggleController.java
@@ -40,7 +40,7 @@
public int getAvailabilityStatus() {
return mSensorPrivacyManagerHelper.supportsSensorToggle(getSensor())
&& DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_PRIVACY, "camera_toggle_enabled",
- true) ? AVAILABLE_UNSEARCHABLE : UNSUPPORTED_ON_DEVICE;
+ true) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
@Override
diff --git a/src/com/android/settings/privacy/MicToggleController.java b/src/com/android/settings/privacy/MicToggleController.java
index 23d41d6..c2389d2 100644
--- a/src/com/android/settings/privacy/MicToggleController.java
+++ b/src/com/android/settings/privacy/MicToggleController.java
@@ -40,7 +40,7 @@
public int getAvailabilityStatus() {
return mSensorPrivacyManagerHelper.supportsSensorToggle(getSensor())
&& DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_PRIVACY, "mic_toggle_enabled",
- true) ? AVAILABLE_UNSEARCHABLE : UNSUPPORTED_ON_DEVICE;
+ true) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
@Override
diff --git a/src/com/android/settings/privacy/WorkPolicyInfoPreferenceController.java b/src/com/android/settings/privacy/WorkPolicyInfoPreferenceController.java
index 977d1bf..55ba064 100644
--- a/src/com/android/settings/privacy/WorkPolicyInfoPreferenceController.java
+++ b/src/com/android/settings/privacy/WorkPolicyInfoPreferenceController.java
@@ -37,9 +37,7 @@
@Override
public int getAvailabilityStatus() {
- return mEnterpriseProvider.hasWorkPolicyInfo()
- ? AVAILABLE_UNSEARCHABLE
- : UNSUPPORTED_ON_DEVICE;
+ return mEnterpriseProvider.hasWorkPolicyInfo() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
@Override
diff --git a/src/com/android/settings/security/CredentialStorage.java b/src/com/android/settings/security/CredentialStorage.java
index 090fdf6..ea33631 100644
--- a/src/com/android/settings/security/CredentialStorage.java
+++ b/src/com/android/settings/security/CredentialStorage.java
@@ -86,7 +86,7 @@
final String action = intent.getAction();
final UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
if (!userManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_CREDENTIALS)) {
- if (ACTION_RESET.equals(action)) {
+ if (ACTION_RESET.equals(action) && checkCallerIsSelf()) {
new ResetDialog();
} else {
if (ACTION_INSTALL.equals(action) && checkCallerIsCertInstallerOrSelfInProfile()) {
@@ -319,6 +319,19 @@
}
/**
+ * Check that the caller is Settings.
+ */
+ private boolean checkCallerIsSelf() {
+ try {
+ return Process.myUid() == android.app.ActivityManager.getService()
+ .getLaunchedFromUid(getActivityToken());
+ } catch (RemoteException re) {
+ // Error talking to ActivityManager, just give up
+ return false;
+ }
+ }
+
+ /**
* Check that the caller is either certinstaller or Settings running in a profile of this user.
*/
private boolean checkCallerIsCertInstallerOrSelfInProfile() {
diff --git a/src/com/android/settings/system/ResetDashboardFragment.java b/src/com/android/settings/system/ResetDashboardFragment.java
index e5fc8f1..c352b92 100644
--- a/src/com/android/settings/system/ResetDashboardFragment.java
+++ b/src/com/android/settings/system/ResetDashboardFragment.java
@@ -64,6 +64,11 @@
use(EraseEuiccDataController.class).setFragment(this);
}
+ @Override
+ protected boolean shouldSkipForInitialSUW() {
+ return true;
+ }
+
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
Lifecycle lifecycle) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
diff --git a/src/com/android/settings/wifi/WifiDialogActivity.java b/src/com/android/settings/wifi/WifiDialogActivity.java
index a423bd8..67f291d 100644
--- a/src/com/android/settings/wifi/WifiDialogActivity.java
+++ b/src/com/android/settings/wifi/WifiDialogActivity.java
@@ -105,6 +105,7 @@
private Intent mIntent;
private NetworkDetailsTracker mNetworkDetailsTracker;
private HandlerThread mWorkerThread;
+ private WifiManager mWifiManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -150,22 +151,12 @@
@Override
protected void onStart() {
super.onStart();
- if (mDialog2 != null || mDialog != null) {
+ if (mDialog2 != null || mDialog != null || !hasWifiManager()) {
return;
}
if (WizardManagerHelper.isAnySetupWizard(getIntent())) {
- final int targetStyle = ThemeHelper.isSetupWizardDayNightEnabled(this)
- ? R.style.SuwAlertDialogThemeCompat_DayNight :
- R.style.SuwAlertDialogThemeCompat_Light;
- if (mIsWifiTrackerLib) {
- mDialog2 = WifiDialog2.createModal(this, this,
- mNetworkDetailsTracker.getWifiEntry(),
- WifiConfigUiBase2.MODE_CONNECT, targetStyle);
- } else {
- mDialog = WifiDialog.createModal(this, this, mAccessPoint,
- WifiConfigUiBase.MODE_CONNECT, targetStyle);
- }
+ createDialogWithSuwTheme();
} else {
if (mIsWifiTrackerLib) {
mDialog2 = WifiDialog2.createModal(this, this,
@@ -177,11 +168,30 @@
}
if (mIsWifiTrackerLib) {
- mDialog2.show();
- mDialog2.setOnDismissListener(this);
+ if (mDialog2 != null) {
+ mDialog2.show();
+ mDialog2.setOnDismissListener(this);
+ }
} else {
- mDialog.show();
- mDialog.setOnDismissListener(this);
+ if (mDialog != null) {
+ mDialog.show();
+ mDialog.setOnDismissListener(this);
+ }
+ }
+ }
+
+ @VisibleForTesting
+ protected void createDialogWithSuwTheme() {
+ final int targetStyle = ThemeHelper.isSetupWizardDayNightEnabled(this)
+ ? R.style.SuwAlertDialogThemeCompat_DayNight :
+ R.style.SuwAlertDialogThemeCompat_Light;
+ if (mIsWifiTrackerLib) {
+ mDialog2 = WifiDialog2.createModal(this, this,
+ mNetworkDetailsTracker.getWifiEntry(),
+ WifiConfigUiBase2.MODE_CONNECT, targetStyle);
+ } else {
+ mDialog = WifiDialog.createModal(this, this, mAccessPoint,
+ WifiConfigUiBase.MODE_CONNECT, targetStyle);
}
}
@@ -221,21 +231,21 @@
@Override
public void onForget(WifiDialog dialog) {
- final WifiManager wifiManager = getSystemService(WifiManager.class);
+ if (!hasWifiManager()) return;
final AccessPoint accessPoint = dialog.getController().getAccessPoint();
if (accessPoint != null) {
if (!accessPoint.isSaved()) {
if (accessPoint.getNetworkInfo() != null &&
accessPoint.getNetworkInfo().getState() != NetworkInfo.State.DISCONNECTED) {
// Network is active but has no network ID - must be ephemeral.
- wifiManager.disableEphemeralNetwork(
+ mWifiManager.disableEphemeralNetwork(
AccessPoint.convertToQuotedString(accessPoint.getSsidStr()));
} else {
// Should not happen, but a monkey seems to trigger it
Log.e(TAG, "Failed to forget invalid network " + accessPoint.getConfig());
}
} else {
- wifiManager.forget(accessPoint.getConfig().networkId, null /* listener */);
+ mWifiManager.forget(accessPoint.getConfig().networkId, null /* listener */);
}
}
@@ -251,6 +261,7 @@
@Override
public void onSubmit(WifiDialog2 dialog) {
+ if (!hasWifiManager()) return;
final WifiEntry wifiEntry = dialog.getController().getWifiEntry();
final WifiConfiguration config = dialog.getController().getConfig();
@@ -258,7 +269,7 @@
if (config == null && wifiEntry != null && wifiEntry.canConnect()) {
wifiEntry.connect(null /* callback */);
} else {
- getSystemService(WifiManager.class).connect(config, null /* listener */);
+ mWifiManager.connect(config, null /* listener */);
}
}
@@ -269,22 +280,22 @@
@Override
public void onSubmit(WifiDialog dialog) {
+ if (!hasWifiManager()) return;
final WifiConfiguration config = dialog.getController().getConfig();
final AccessPoint accessPoint = dialog.getController().getAccessPoint();
- final WifiManager wifiManager = getSystemService(WifiManager.class);
if (getIntent().getBooleanExtra(KEY_CONNECT_FOR_CALLER, true)) {
if (config == null) {
if (accessPoint != null && accessPoint.isSaved()) {
- wifiManager.connect(accessPoint.getConfig(), null /* listener */);
+ mWifiManager.connect(accessPoint.getConfig(), null /* listener */);
}
} else {
- wifiManager.save(config, null /* listener */);
+ mWifiManager.save(config, null /* listener */);
if (accessPoint != null) {
// accessPoint is null for "Add network"
NetworkInfo networkInfo = accessPoint.getNetworkInfo();
if (networkInfo == null || !networkInfo.isConnected()) {
- wifiManager.connect(config, null /* listener */);
+ mWifiManager.connect(config, null /* listener */);
}
}
}
@@ -350,6 +361,12 @@
}
}
+ private boolean hasWifiManager() {
+ if (mWifiManager != null) return true;
+ mWifiManager = getSystemService(WifiManager.class);
+ return (mWifiManager != null);
+ }
+
protected boolean hasPermissionForResult() {
final String callingPackage = getCallingPackage();
if (callingPackage == null) {
diff --git a/tests/robotests/src/com/android/settings/SettingsPreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/SettingsPreferenceFragmentTest.java
index cb53f69..6489311 100644
--- a/tests/robotests/src/com/android/settings/SettingsPreferenceFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/SettingsPreferenceFragmentTest.java
@@ -23,11 +23,13 @@
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;
import android.content.Context;
import android.os.Bundle;
+import android.provider.Settings;
import android.view.View;
import android.widget.FrameLayout;
@@ -41,6 +43,7 @@
import com.android.settings.testutils.shadow.ShadowFragment;
import com.android.settings.widget.WorkOnlyCategory;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -64,7 +67,9 @@
private PreferenceScreen mPreferenceScreen;
private Context mContext;
private TestFragment mFragment;
+ private TestFragment2 mFragment2;
private View mEmptyView;
+ private int mInitDeviceProvisionedValue;
@Before
public void setUp() {
@@ -72,13 +77,24 @@
FakeFeatureFactory.setupForTest();
mContext = RuntimeEnvironment.application;
mFragment = spy(new TestFragment());
+ mFragment2 = spy(new TestFragment2());
doReturn(mActivity).when(mFragment).getActivity();
when(mFragment.getContext()).thenReturn(mContext);
+ when(mFragment2.getContext()).thenReturn(mContext);
mEmptyView = new View(mContext);
ReflectionHelpers.setField(mFragment, "mEmptyView", mEmptyView);
doReturn(ITEM_COUNT).when(mPreferenceScreen).getPreferenceCount();
+
+ mInitDeviceProvisionedValue = Settings.Global.getInt(mContext.getContentResolver(),
+ Settings.Global.DEVICE_PROVISIONED, 0);
+ }
+
+ @After
+ public void tearDown() {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.DEVICE_PROVISIONED, mInitDeviceProvisionedValue);
}
@Test
@@ -210,9 +226,67 @@
assertThat(mFragment.mPinnedHeaderFrameLayout.getVisibility()).isEqualTo(View.INVISIBLE);
}
+ @Test
+ public void onAttach_shouldNotSkipForSUWAndDeviceIsProvisioned_notCallFinish() {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.DEVICE_PROVISIONED, 1);
+
+ mFragment.onAttach(mContext);
+
+ verify(mFragment, never()).finish();
+ }
+
+ @Test
+ public void onAttach_shouldNotSkipForSUWAndDeviceIsNotProvisioned_notCallFinish() {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.DEVICE_PROVISIONED, 0);
+
+ mFragment.onAttach(mContext);
+
+ verify(mFragment, never()).finish();
+ }
+
+ @Test
+ public void onAttach_shouldSkipForSUWAndDeviceIsDeviceProvisioned_notCallFinish() {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.DEVICE_PROVISIONED, 1);
+
+ mFragment2.onAttach(mContext);
+
+ verify(mFragment2, never()).finish();
+ }
+
+ @Test
+ public void onAttach_shouldSkipForSUWAndDeviceProvisioned_notCallFinish() {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.DEVICE_PROVISIONED, 0);
+
+ mFragment2.onAttach(mContext);
+
+ verify(mFragment2, times(1)).finish();
+ }
+
public static class TestFragment extends SettingsPreferenceFragment {
@Override
+ protected boolean shouldSkipForInitialSUW() {
+ return false;
+ }
+
+ @Override
+ public int getMetricsCategory() {
+ return 0;
+ }
+ }
+
+ public static class TestFragment2 extends SettingsPreferenceFragment {
+
+ @Override
+ protected boolean shouldSkipForInitialSUW() {
+ return true;
+ }
+
+ @Override
public int getMetricsCategory() {
return 0;
}
diff --git a/tests/robotests/src/com/android/settings/accounts/AccountDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/accounts/AccountDashboardFragmentTest.java
index fe57090..921587e 100644
--- a/tests/robotests/src/com/android/settings/accounts/AccountDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/AccountDashboardFragmentTest.java
@@ -114,4 +114,9 @@
assertThat(indexRaws).isNotEmpty();
}
+
+ @Test
+ public void shouldSkipForInitialSUW_returnTrue() {
+ assertThat(mFragment.shouldSkipForInitialSUW()).isTrue();
+ }
}
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/AppInfoDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/AppInfoDashboardFragmentTest.java
index 95d7659..2cec3d1 100644
--- a/tests/robotests/src/com/android/settings/applications/appinfo/AppInfoDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/AppInfoDashboardFragmentTest.java
@@ -384,6 +384,11 @@
.isTrue();
}
+ @Test
+ public void shouldSkipForInitialSUW_returnTrue() {
+ assertThat(mFragment.shouldSkipForInitialSUW()).isTrue();
+ }
+
@Implements(AppUtils.class)
public static class ShadowAppUtils {
diff --git a/tests/robotests/src/com/android/settings/development/DevelopmentSettingsDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/development/DevelopmentSettingsDashboardFragmentTest.java
index 2d4082b..bd4ee56 100644
--- a/tests/robotests/src/com/android/settings/development/DevelopmentSettingsDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/development/DevelopmentSettingsDashboardFragmentTest.java
@@ -278,6 +278,11 @@
verify(controller).onDisableLogPersistDialogRejected();
}
+ @Test
+ public void shouldSkipForInitialSUW_returnTrue() {
+ assertThat(mDashboard.shouldSkipForInitialSUW()).isTrue();
+ }
+
@Implements(EnableDevelopmentSettingWarningDialog.class)
public static class ShadowEnableDevelopmentSettingWarningDialog {
diff --git a/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java b/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java
index f3e3674..9994876 100644
--- a/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java
@@ -329,6 +329,55 @@
}
@Test
+ public void onCreateContextMenu_canShare_shouldHaveShareMenuForConnectedWifiEntry() {
+ final FragmentActivity activity = mock(FragmentActivity.class);
+ when(activity.getApplicationContext()).thenReturn(mContext);
+ when(mNetworkProviderSettings.getActivity()).thenReturn(activity);
+
+ final WifiEntry wifiEntry = mock(WifiEntry.class);
+ when(wifiEntry.canDisconnect()).thenReturn(true);
+ when(wifiEntry.canShare()).thenReturn(true);
+ when(wifiEntry.canForget()).thenReturn(true);
+ when(wifiEntry.isSaved()).thenReturn(true);
+ when(wifiEntry.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_CONNECTED);
+
+ final LongPressWifiEntryPreference connectedWifiEntryPreference =
+ mNetworkProviderSettings.createLongPressWifiEntryPreference(wifiEntry);
+ final View view = mock(View.class);
+ when(view.getTag()).thenReturn(connectedWifiEntryPreference);
+
+ final ContextMenu menu = mock(ContextMenu.class);
+ mNetworkProviderSettings.onCreateContextMenu(menu, view, null /* info */);
+
+ verify(menu).add(anyInt(), eq(NetworkProviderSettings.MENU_ID_SHARE), anyInt(), anyInt());
+ }
+
+ @Test
+ public void onCreateContextMenu_canNotShare_shouldDisappearShareMenuForConnectedWifiEntry() {
+ final FragmentActivity activity = mock(FragmentActivity.class);
+ when(activity.getApplicationContext()).thenReturn(mContext);
+ when(mNetworkProviderSettings.getActivity()).thenReturn(activity);
+
+ final WifiEntry wifiEntry = mock(WifiEntry.class);
+ when(wifiEntry.canDisconnect()).thenReturn(true);
+ when(wifiEntry.canShare()).thenReturn(false);
+ when(wifiEntry.canForget()).thenReturn(true);
+ when(wifiEntry.isSaved()).thenReturn(true);
+ when(wifiEntry.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_CONNECTED);
+
+ final LongPressWifiEntryPreference connectedWifiEntryPreference =
+ mNetworkProviderSettings.createLongPressWifiEntryPreference(wifiEntry);
+ final View view = mock(View.class);
+ when(view.getTag()).thenReturn(connectedWifiEntryPreference);
+
+ final ContextMenu menu = mock(ContextMenu.class);
+ mNetworkProviderSettings.onCreateContextMenu(menu, view, null /* info */);
+
+ verify(menu, never())
+ .add(anyInt(), eq(NetworkProviderSettings.MENU_ID_SHARE), anyInt(), anyInt());
+ }
+
+ @Test
public void onWifiEntriesChanged_shouldChangeNextButtonState() {
mNetworkProviderSettings.onWifiEntriesChanged();
diff --git a/tests/robotests/src/com/android/settings/privacy/WorkPolicyInfoPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/privacy/WorkPolicyInfoPreferenceControllerTest.java
index 79aec30..82444aa 100644
--- a/tests/robotests/src/com/android/settings/privacy/WorkPolicyInfoPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/privacy/WorkPolicyInfoPreferenceControllerTest.java
@@ -16,7 +16,7 @@
package com.android.settings.privacy;
-import static com.android.settings.core.BasePreferenceController.AVAILABLE_UNSEARCHABLE;
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
import static com.google.common.truth.Truth.assertThat;
@@ -33,8 +33,8 @@
import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
-import org.junit.runner.RunWith;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@@ -64,12 +64,12 @@
}
@Test
- public void getAvailabilityStatus_haveWorkPolicyInfo_shouldReturnAvailableUnsearchable() {
+ public void getAvailabilityStatus_haveWorkPolicyInfo_shouldReturnAvailable() {
when(mEnterpriseProvider.hasWorkPolicyInfo()).thenReturn(true);
WorkPolicyInfoPreferenceController controller =
new WorkPolicyInfoPreferenceController(mContext, "test_key");
- assertThat(controller.getAvailabilityStatus()).isEqualTo(AVAILABLE_UNSEARCHABLE);
+ assertThat(controller.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/system/ResetDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/system/ResetDashboardFragmentTest.java
new file mode 100644
index 0000000..c1d4788
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/system/ResetDashboardFragmentTest.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2022 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.system;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+
+@RunWith(RobolectricTestRunner.class)
+public class ResetDashboardFragmentTest {
+
+ private ResetDashboardFragment mFragment;
+
+ @Before
+ public void setup() {
+ mFragment = new ResetDashboardFragment();
+ }
+
+ @Test
+ public void shouldSkipForInitialSUW_returnTrue() {
+ assertThat(mFragment.shouldSkipForInitialSUW()).isTrue();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiDialogActivityTest.java b/tests/robotests/src/com/android/settings/wifi/WifiDialogActivityTest.java
index 9a61b6b..4ceb1e3 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiDialogActivityTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiDialogActivityTest.java
@@ -26,7 +26,8 @@
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -36,41 +37,25 @@
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
-import androidx.lifecycle.Lifecycle.State;
-import androidx.test.core.app.ActivityScenario;
-
-import com.android.settings.R;
-import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
-import com.android.settings.testutils.shadow.ShadowConnectivityManager;
-import com.android.settings.testutils.shadow.ShadowNetworkDetailsTracker;
-import com.android.settings.testutils.shadow.ShadowWifiManager;
+import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settingslib.wifi.AccessPoint;
+import com.android.wifitrackerlib.WifiEntry;
import com.google.android.setupcompat.util.WizardManagerHelper;
-import org.junit.After;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
-import org.robolectric.annotation.Config;
-import org.robolectric.util.ReflectionHelpers;
@RunWith(RobolectricTestRunner.class)
-@Config(shadows = {
- ShadowAlertDialogCompat.class,
- ShadowConnectivityManager.class,
- ShadowNetworkDetailsTracker.class,
- ShadowWifiManager.class
-})
public class WifiDialogActivityTest {
- private static final String CALLING_PACKAGE = "calling_package";
- private static final String AP1_SSID = "\"ap1\"";
+ static final String CALLING_PACKAGE = "calling_package";
+ static final int REQUEST_CODE = REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER;
@Mock
PackageManager mPackageManager;
@@ -87,13 +72,13 @@
@Mock
WifiConfigController2 mWifiConfiguration2;
@Mock
+ WifiEntry mWifiEntry;
+ @Mock
Intent mResultData;
@Mock
- private WifiConfigController mController;
- @Mock
- private WifiConfigController2 mController2;
+ WifiConfigController mController;
- private ActivityScenario<WifiDialogActivity> mWifiDialogActivity;
+ WifiDialogActivity mActivity;
@Before
public void setUp() {
@@ -102,254 +87,190 @@
when(mController.getConfig()).thenReturn(mWifiConfiguration);
when(mController.getAccessPoint()).thenReturn(mAccessPoint);
when(mWifiDialog2.getController()).thenReturn(mWifiConfiguration2);
+ when(mWifiConfiguration2.getWifiEntry()).thenReturn(mWifiEntry);
+ when(mWifiEntry.canConnect()).thenReturn(true);
+ FakeFeatureFactory.setupForTest();
- WifiConfiguration wifiConfig = new WifiConfiguration();
- wifiConfig.SSID = AP1_SSID;
- doReturn(wifiConfig).when(mController).getConfig();
- doReturn(wifiConfig).when(mController2).getConfig();
- }
-
- @After
- public void cleanUp() {
- if (mWifiDialogActivity != null) {
- mWifiDialogActivity.close();
- }
- }
-
- private ActivityScenario<WifiDialogActivity> createTargetActivity(Intent activityIntent) {
- return ActivityScenario.launch(activityIntent);
+ mActivity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
+ when(mActivity.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
}
@Test
public void onSubmit_shouldConnectToNetwork() {
- WifiDialogActivity activity = Robolectric.setupActivity(WifiDialogActivity.class);
- WifiDialog dialog = (WifiDialog) ShadowAlertDialogCompat.getLatestAlertDialog();
- assertThat(dialog).isNotNull();
+ mActivity.onSubmit(mWifiDialog);
- ReflectionHelpers.setField(dialog, "mController", mController);
-
- activity.onSubmit(dialog);
-
- assertThat(ShadowWifiManager.get().savedWifiConfig.SSID).isEqualTo(AP1_SSID);
+ verify(mWifiManager).connect(any(), any());
}
@Test
public void onSubmit_noPermissionForResult_setResultWithoutData() {
- WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
- when(activity.hasPermissionForResult()).thenReturn(false);
- when(activity.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
+ when(mActivity.hasPermissionForResult()).thenReturn(false);
- activity.onSubmit(mWifiDialog);
+ mActivity.onSubmit(mWifiDialog);
- verify(activity).setResult(RESULT_CONNECTED, null);
+ verify(mActivity).setResult(RESULT_CONNECTED, null);
}
@Test
public void onSubmit_hasPermissionForResult_setResultWithData() {
- WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
- when(activity.hasPermissionForResult()).thenReturn(true);
- when(activity.createResultData(any(), any())).thenReturn(mResultData);
- when(activity.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
+ when(mActivity.hasPermissionForResult()).thenReturn(true);
+ when(mActivity.createResultData(any(), any())).thenReturn(mResultData);
- activity.onSubmit(mWifiDialog);
+ mActivity.onSubmit(mWifiDialog);
- verify(activity).setResult(RESULT_CONNECTED, mResultData);
+ verify(mActivity).setResult(RESULT_CONNECTED, mResultData);
}
@Test
public void onSubmit2_noPermissionForResult_setResultWithoutData() {
- WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
- when(activity.hasPermissionForResult()).thenReturn(false);
- when(activity.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
+ when(mActivity.hasPermissionForResult()).thenReturn(false);
- activity.onSubmit(mWifiDialog2);
+ mActivity.onSubmit(mWifiDialog2);
- verify(activity).setResult(RESULT_CONNECTED, null);
+ verify(mActivity).setResult(RESULT_CONNECTED, null);
}
@Test
public void onSubmit2_hasPermissionForResult_setResultWithData() {
- WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
- when(activity.hasPermissionForResult()).thenReturn(true);
- when(activity.createResultData(any(), any())).thenReturn(mResultData);
- when(activity.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
+ when(mActivity.hasPermissionForResult()).thenReturn(true);
+ when(mActivity.createResultData(any(), any())).thenReturn(mResultData);
- activity.onSubmit(mWifiDialog2);
+ mActivity.onSubmit(mWifiDialog2);
- verify(activity).setResult(RESULT_CONNECTED, mResultData);
+ verify(mActivity).setResult(RESULT_CONNECTED, mResultData);
}
@Test
- @Ignore
public void onSubmit2_whenConnectForCallerIsTrue_shouldConnectToNetwork() {
final Intent intent = new Intent("com.android.settings.WIFI_DIALOG");
intent.putExtra(WifiDialogActivity.KEY_CHOSEN_WIFIENTRY_KEY, "FAKE_KEY");
intent.putExtra(WifiDialogActivity.KEY_CONNECT_FOR_CALLER, true);
- mWifiDialogActivity = createTargetActivity(intent);
+ mActivity = spy(Robolectric.buildActivity(WifiDialogActivity.class, intent).setup().get());
+ when(mActivity.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
- mWifiDialogActivity.moveToState(State.CREATED);
- mWifiDialogActivity.moveToState(State.STARTED);
+ mActivity.onSubmit(mWifiDialog2);
- WifiDialog2 dialog = (WifiDialog2) ShadowAlertDialogCompat.getLatestAlertDialog();
- assertThat(dialog).isNotNull();
-
- ReflectionHelpers.setField(dialog, "mController", mController2);
-
- mWifiDialogActivity.onActivity(activity -> {
- activity.onSubmit(dialog);
- assertThat(ShadowWifiManager.get().savedWifiConfig.SSID).isEqualTo(AP1_SSID);
- });
+ verify(mWifiEntry).connect(any());
}
@Test
public void onSubmit_whenConnectForCallerIsFalse_shouldNotConnectToNetwork() {
- WifiDialogActivity activity =
- Robolectric.buildActivity(
- WifiDialogActivity.class,
- new Intent().putExtra(WifiDialogActivity.KEY_CONNECT_FOR_CALLER, false))
- .setup().get();
- WifiDialog dialog = (WifiDialog) ShadowAlertDialogCompat.getLatestAlertDialog();
+ final Intent intent = new Intent();
+ intent.putExtra(WifiDialogActivity.KEY_CONNECT_FOR_CALLER, false);
+ mActivity = spy(Robolectric.buildActivity(WifiDialogActivity.class, intent).setup().get());
+ when(mActivity.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
- assertThat(dialog).isNotNull();
+ mActivity.onSubmit(mWifiDialog);
- ReflectionHelpers.setField(dialog, "mController", mController);
-
- activity.onSubmit(dialog);
-
- assertThat(ShadowWifiManager.get().savedWifiConfig).isNull();
+ verify(mWifiManager, never()).connect(any(), any());
}
@Test
- @Ignore
public void onSubmit2_whenConnectForCallerIsFalse_shouldNotConnectToNetwork() {
final Intent intent = new Intent("com.android.settings.WIFI_DIALOG");
intent.putExtra(WifiDialogActivity.KEY_CHOSEN_WIFIENTRY_KEY, "FAKE_KEY");
intent.putExtra(WifiDialogActivity.KEY_CONNECT_FOR_CALLER, false);
- mWifiDialogActivity = createTargetActivity(intent);
+ mActivity = spy(Robolectric.buildActivity(WifiDialogActivity.class, intent).setup().get());
+ when(mActivity.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
- mWifiDialogActivity.moveToState(State.CREATED);
- mWifiDialogActivity.moveToState(State.STARTED);
+ mActivity.onSubmit(mWifiDialog2);
- WifiDialog2 dialog = (WifiDialog2) ShadowAlertDialogCompat.getLatestAlertDialog();
- assertThat(dialog).isNotNull();
-
- ReflectionHelpers.setField(dialog, "mController", mController2);
-
- mWifiDialogActivity.onActivity(activity -> {
- activity.onSubmit(dialog);
- assertThat(ShadowWifiManager.get().savedWifiConfig).isEqualTo(null);
- });
+ verify(mWifiEntry, never()).connect(any());
}
@Test
- public void onSubmit_whenLaunchInSetupFlow_shouldBeLightThemeForWifiDialog() {
- WifiDialogActivity activity =
- Robolectric.buildActivity(
- WifiDialogActivity.class,
- new Intent()
- .putExtra(WifiDialogActivity.KEY_CONNECT_FOR_CALLER, false)
- .putExtra(WizardManagerHelper.EXTRA_IS_FIRST_RUN, true)
- .putExtra(WizardManagerHelper.EXTRA_IS_SETUP_FLOW, true))
- .setup().get();
- WifiDialog dialog = (WifiDialog) ShadowAlertDialogCompat.getLatestAlertDialog();
+ public void onStart_whenLaunchInSetupFlow_shouldCreateDialogWithSuwTheme() {
+ final Intent intent = new Intent();
+ intent.putExtra(WifiDialogActivity.KEY_CONNECT_FOR_CALLER, false);
+ intent.putExtra(WizardManagerHelper.EXTRA_IS_FIRST_RUN, true);
+ intent.putExtra(WizardManagerHelper.EXTRA_IS_SETUP_FLOW, true);
+ mActivity = spy(Robolectric.buildActivity(WifiDialogActivity.class, intent).setup().get());
+ when(mActivity.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
+ doNothing().when(mActivity).createDialogWithSuwTheme();
- assertThat(dialog).isNotNull();
+ mActivity.onStart();
- activity.onSubmit(dialog);
-
- assertThat(dialog.getContext().getThemeResId())
- .isEqualTo(R.style.SuwAlertDialogThemeCompat_Light);
+ verify(mActivity).createDialogWithSuwTheme();
}
@Test
public void onActivityResult_noPermissionForResult_setResultWithoutData() {
- WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
- when(activity.hasPermissionForResult()).thenReturn(false);
- final Intent data = new Intent();
+ when(mActivity.hasPermissionForResult()).thenReturn(false);
- activity.onActivityResult(REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER, RESULT_OK,
- data);
+ mActivity.onActivityResult(REQUEST_CODE, RESULT_OK, mResultData);
- verify(activity).setResult(RESULT_CONNECTED);
+ verify(mActivity).setResult(RESULT_CONNECTED);
}
@Test
public void onActivityResult_hasPermissionForResult_setResultWithData() {
- WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
- when(activity.hasPermissionForResult()).thenReturn(true);
- final Intent data = new Intent();
+ when(mActivity.hasPermissionForResult()).thenReturn(true);
- activity.onActivityResult(REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER, RESULT_OK,
- data);
+ mActivity.onActivityResult(REQUEST_CODE, RESULT_OK, mResultData);
- verify(activity).setResult(RESULT_CONNECTED, data);
+ verify(mActivity).setResult(RESULT_CONNECTED, mResultData);
}
@Test
public void hasPermissionForResult_noCallingPackage_returnFalse() {
- WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
- when(activity.getCallingPackage()).thenReturn(null);
+ when(mActivity.getCallingPackage()).thenReturn(null);
- final boolean result = activity.hasPermissionForResult();
+ final boolean result = mActivity.hasPermissionForResult();
assertThat(result).isFalse();
}
@Test
public void hasPermissionForResult_noPermission_returnFalse() {
- WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
- when(activity.getCallingPackage()).thenReturn(null);
+ when(mActivity.getCallingPackage()).thenReturn(null);
when(mPackageManager.checkPermission(ACCESS_COARSE_LOCATION, CALLING_PACKAGE))
.thenReturn(PackageManager.PERMISSION_DENIED);
when(mPackageManager.checkPermission(ACCESS_FINE_LOCATION, CALLING_PACKAGE))
.thenReturn(PackageManager.PERMISSION_DENIED);
- final boolean result = activity.hasPermissionForResult();
+ final boolean result = mActivity.hasPermissionForResult();
assertThat(result).isFalse();
}
@Test
public void hasPermissionForResult_hasCoarseLocationPermission_returnFalse() {
- WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
- when(activity.getCallingPackage()).thenReturn(CALLING_PACKAGE);
- when(activity.getPackageManager()).thenReturn(mPackageManager);
+ when(mActivity.getCallingPackage()).thenReturn(CALLING_PACKAGE);
+ when(mActivity.getPackageManager()).thenReturn(mPackageManager);
when(mPackageManager.checkPermission(ACCESS_COARSE_LOCATION, CALLING_PACKAGE))
.thenReturn(PackageManager.PERMISSION_GRANTED);
when(mPackageManager.checkPermission(ACCESS_FINE_LOCATION, CALLING_PACKAGE))
.thenReturn(PackageManager.PERMISSION_DENIED);
- final boolean result = activity.hasPermissionForResult();
+ final boolean result = mActivity.hasPermissionForResult();
assertThat(result).isFalse();
}
@Test
public void hasPermissionForResult_hasFineLocationPermission_returnTrue() {
- WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
- when(activity.getCallingPackage()).thenReturn(CALLING_PACKAGE);
- when(activity.getPackageManager()).thenReturn(mPackageManager);
+ when(mActivity.getCallingPackage()).thenReturn(CALLING_PACKAGE);
+ when(mActivity.getPackageManager()).thenReturn(mPackageManager);
when(mPackageManager.checkPermission(ACCESS_COARSE_LOCATION, CALLING_PACKAGE))
.thenReturn(PackageManager.PERMISSION_DENIED);
when(mPackageManager.checkPermission(ACCESS_FINE_LOCATION, CALLING_PACKAGE))
.thenReturn(PackageManager.PERMISSION_GRANTED);
- final boolean result = activity.hasPermissionForResult();
+ final boolean result = mActivity.hasPermissionForResult();
assertThat(result).isTrue();
}
@Test
public void hasPermissionForResult_haveBothLocationPermissions_returnTrue() {
- WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
- when(activity.getCallingPackage()).thenReturn(CALLING_PACKAGE);
- when(activity.getPackageManager()).thenReturn(mPackageManager);
+ when(mActivity.getCallingPackage()).thenReturn(CALLING_PACKAGE);
+ when(mActivity.getPackageManager()).thenReturn(mPackageManager);
when(mPackageManager.checkPermission(ACCESS_COARSE_LOCATION, CALLING_PACKAGE))
.thenReturn(PackageManager.PERMISSION_GRANTED);
when(mPackageManager.checkPermission(ACCESS_FINE_LOCATION, CALLING_PACKAGE))
.thenReturn(PackageManager.PERMISSION_GRANTED);
- final boolean result = activity.hasPermissionForResult();
+ final boolean result = mActivity.hasPermissionForResult();
assertThat(result).isTrue();
}