Merge "Import translations. DO NOT MERGE ANYWHERE" into tm-qpr-dev
diff --git a/src/com/android/settings/datausage/DataUsageSummary.java b/src/com/android/settings/datausage/DataUsageSummary.java
index fabf059..ec68bab 100644
--- a/src/com/android/settings/datausage/DataUsageSummary.java
+++ b/src/com/android/settings/datausage/DataUsageSummary.java
@@ -19,6 +19,7 @@
import android.content.Context;
import android.net.NetworkTemplate;
import android.os.Bundle;
+import android.os.UserManager;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.text.BidiFormatter;
@@ -27,6 +28,8 @@
import android.text.TextUtils;
import android.text.format.Formatter;
import android.text.style.RelativeSizeSpan;
+import android.util.EventLog;
+import android.util.Log;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
@@ -83,6 +86,12 @@
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
Context context = getContext();
+ if (isGuestUser(context)) {
+ Log.e(TAG, "This setting isn't available due to user restriction.");
+ EventLog.writeEvent(0x534e4554, "262243574", -1 /* UID */, "Guest user");
+ finish();
+ return;
+ }
if (!isSimHardwareVisible(context)) {
finish();
@@ -282,4 +291,11 @@
updateState();
mSummaryController.updateState(mSummaryPreference);
}
+
+ private static boolean isGuestUser(Context context) {
+ if (context == null) return false;
+ final UserManager userManager = context.getSystemService(UserManager.class);
+ if (userManager == null) return false;
+ return userManager.isGuestUser();
+ }
}
diff --git a/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivity.java b/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivity.java
index 6c9d498..e6f0b31 100644
--- a/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivity.java
+++ b/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivity.java
@@ -28,7 +28,6 @@
import android.provider.Settings;
import android.util.EventLog;
import android.util.Log;
-import android.view.WindowManager;
import androidx.annotation.VisibleForTesting;
import androidx.fragment.app.FragmentTransaction;
@@ -100,7 +99,6 @@
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
if (savedInstanceState != null) {
String qrCode = savedInstanceState.getString(KEY_QR_CODE);
diff --git a/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java b/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java
index 68d49fc..4ac7387 100644
--- a/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java
+++ b/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java
@@ -31,13 +31,14 @@
import android.content.Context;
import android.content.res.Resources;
import android.net.NetworkPolicyManager;
+import android.os.UserManager;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import androidx.fragment.app.FragmentActivity;
+import androidx.test.core.app.ApplicationProvider;
import com.android.settings.R;
-
import com.android.settings.testutils.shadow.ShadowDashboardFragment;
import com.android.settings.testutils.shadow.ShadowDataUsageUtils;
import com.android.settings.testutils.shadow.ShadowUserManager;
@@ -45,13 +46,15 @@
import org.junit.Before;
import org.junit.Ignore;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
@@ -66,16 +69,22 @@
})
@RunWith(RobolectricTestRunner.class)
public class DataUsageSummaryTest {
-
+ @Rule
+ public final MockitoRule mMockitoRule = MockitoJUnit.rule();
+ @Spy
+ Context mContext = ApplicationProvider.getApplicationContext();
+ @Mock
+ private UserManager mUserManager;
@Mock
private NetworkPolicyManager mNetworkPolicyManager;
@Mock
private NetworkStatsManager mNetworkStatsManager;
private TelephonyManager mTelephonyManager;
- private Context mContext;
private Resources mResources;
private FragmentActivity mActivity;
+ private DataUsageSummary mDataUsageSummary;
+
/**
* This set up is contrived to get a passing test so that the build doesn't block without tests.
* These tests should be updated as code gets refactored to improve testability.
@@ -83,12 +92,13 @@
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
+ doReturn(mUserManager).when(mContext).getSystemService(UserManager.class);
+ doReturn(false).when(mUserManager).isGuestUser();
+
ShadowApplication shadowContext = ShadowApplication.getInstance();
ShadowUserManager.getShadow().setIsAdminUser(true);
shadowContext.setSystemService(Context.NETWORK_POLICY_SERVICE, mNetworkPolicyManager);
- mContext = spy(RuntimeEnvironment.application);
mTelephonyManager = mContext.getSystemService(TelephonyManager.class);
final ShadowTelephonyManager shadowTelephonyManager = Shadows.shadowOf(mTelephonyManager);
shadowTelephonyManager.setTelephonyManagerForSubscriptionId(
@@ -101,6 +111,12 @@
doReturn(true).when(mResources).getBoolean(R.bool.config_show_sim_info);
doReturn(mNetworkStatsManager).when(mActivity).getSystemService(NetworkStatsManager.class);
+
+ mDataUsageSummary = spy(new DataUsageSummary());
+ doReturn(mContext).when(mDataUsageSummary).getContext();
+ doNothing().when(mDataUsageSummary).enableProxySubscriptionManager(any());
+ doReturn(true).when(mDataUsageSummary).removePreference(anyString());
+ doNothing().when(mDataUsageSummary).addWifiSection();
}
@Test
@@ -201,4 +217,22 @@
verify(dataUsageSummary).addWifiSection();
verify(dataUsageSummary, never()).addMobileSection(anyInt());
}
+
+ @Test
+ public void onCreate_isNotGuestUser_shouldNotFinish() {
+ doReturn(false).when(mUserManager).isGuestUser();
+
+ mDataUsageSummary.onCreate(null);
+
+ verify(mDataUsageSummary, never()).finish();
+ }
+
+ @Test
+ public void onCreate_isGuestUser_shouldFinish() {
+ doReturn(true).when(mUserManager).isGuestUser();
+
+ mDataUsageSummary.onCreate(null);
+
+ verify(mDataUsageSummary).finish();
+ }
}
diff --git a/tests/robotests/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivityTest.java b/tests/robotests/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivityTest.java
index 88fa83a..d8605de 100644
--- a/tests/robotests/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivityTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivityTest.java
@@ -16,10 +16,6 @@
package com.android.settings.wifi.dpp;
-import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
-
-import static com.google.common.truth.Truth.assertThat;
-
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
@@ -77,12 +73,6 @@
}
@Test
- public void launchActivity_shouldAddFlagSecure() {
- assertThat(mActivity.getWindow().getAttributes().flags & FLAG_SECURE)
- .isEqualTo(FLAG_SECURE);
- }
-
- @Test
public void handleIntent_isGuestUser_shouldFinish() {
when(mUserManager.isGuestUser()).thenReturn(true);