Merge "Fix resource id not match issue." into sc-dev
This commit is contained in:
@@ -25,7 +25,7 @@ import android.util.Log;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.Switch;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.test.core.app.ActivityScenario;
|
import androidx.test.core.app.ActivityScenario;
|
||||||
import androidx.test.ext.junit.rules.ActivityScenarioRule;
|
import androidx.test.ext.junit.rules.ActivityScenarioRule;
|
||||||
@@ -34,21 +34,22 @@ import androidx.test.filters.SmallTest;
|
|||||||
import androidx.test.platform.app.InstrumentationRegistry;
|
import androidx.test.platform.app.InstrumentationRegistry;
|
||||||
import androidx.test.runner.lifecycle.Stage;
|
import androidx.test.runner.lifecycle.Stage;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.testutils.CommonUtils;
|
||||||
import com.android.settings.testutils.UiUtils;
|
import com.android.settings.testutils.UiUtils;
|
||||||
|
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
@SmallTest
|
@SmallTest
|
||||||
public class AppNotificationComponentTest {
|
public class AppNotificationComponentTest {
|
||||||
private static final String TAG =
|
|
||||||
AppNotificationComponentTest.class.getSimpleName();
|
|
||||||
private final Instrumentation mInstrumentation = InstrumentationRegistry.getInstrumentation();
|
private final Instrumentation mInstrumentation = InstrumentationRegistry.getInstrumentation();
|
||||||
private final String mNoSlientAppName = "com.google.android.dialer";
|
private final String mNoSlientAppName = "com.google.android.dialer";
|
||||||
|
public final String TAG = this.getClass().getName();
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public ActivityScenarioRule<com.android.settings.Settings.AppNotificationSettingsActivity>
|
public ActivityScenarioRule<com.android.settings.Settings.AppNotificationSettingsActivity>
|
||||||
@@ -57,35 +58,65 @@ public class AppNotificationComponentTest {
|
|||||||
.putExtra(Settings.EXTRA_APP_PACKAGE, mNoSlientAppName)
|
.putExtra(Settings.EXTRA_APP_PACKAGE, mNoSlientAppName)
|
||||||
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests user should not able to modify notification settings for some system apps.
|
||||||
|
* In this case, test `phone` app that will disabled notification configuration.
|
||||||
|
* Steps:
|
||||||
|
* 1. Open notification page of phone app.
|
||||||
|
* 2. Checks system privilege notification should not able to be changed.
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void test_special_app_could_not_disable_notification() {
|
public void test_special_app_could_not_disable_notification() {
|
||||||
|
List<String> disabledList = Arrays.asList("Default", "Incoming calls",
|
||||||
|
"Background Processing", "Missed calls",
|
||||||
|
"Ongoing calls", "Voicemails");
|
||||||
|
|
||||||
ActivityScenario ac = rule.getScenario();
|
ActivityScenario ac = rule.getScenario();
|
||||||
ac.onActivity(
|
ac.onActivity(
|
||||||
activity -> {
|
activity -> {
|
||||||
View rv = activity.findViewById(R.id.recycler_view);
|
View recyclerView = activity.findViewById(
|
||||||
|
CommonUtils.getResId("recycler_view"));
|
||||||
|
|
||||||
if (rv == null) {
|
if (recyclerView == null) {
|
||||||
Log.d("UI_UTILS",
|
Log.d("UI_UTILS",
|
||||||
"Target not found: R.id.recycler_view #" + Integer.toHexString(
|
"Target not found: R.id.recycler_view #" + Integer.toHexString(
|
||||||
R.id.recycler_view));
|
CommonUtils.getResId("recycler_view")));
|
||||||
UiUtils.dumpView(UiUtils.getFirstViewFromActivity(activity));
|
UiUtils.dumpView(UiUtils.getFirstViewFromActivity(activity));
|
||||||
assertThat(Boolean.TRUE).isFalse();
|
assertThat(Boolean.TRUE).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
UiUtils.waitUntilCondition(5000,
|
UiUtils.waitUntilCondition(5000,
|
||||||
() -> rv.findViewById(R.id.main_switch_bar) != null);
|
() -> recyclerView.findViewById(CommonUtils.getResId("recycler_view"))
|
||||||
|
!= null);
|
||||||
|
|
||||||
View mainSwitchBar = rv.findViewById(R.id.main_switch_bar);
|
View mainSwitchBar = recyclerView.findViewById(
|
||||||
|
CommonUtils.getResId("main_switch_bar"));
|
||||||
|
|
||||||
assertThat(mainSwitchBar.isEnabled()).isEqualTo(false);
|
assertThat(mainSwitchBar.isEnabled()).isEqualTo(false);
|
||||||
|
Log.d(TAG, "main switch bar = " + mainSwitchBar.isEnabled());
|
||||||
|
|
||||||
UiUtils.waitForActivitiesInStage(1000, Stage.RESUMED);
|
UiUtils.waitForActivitiesInStage(10000, Stage.RESUMED);
|
||||||
|
Log.d(TAG, "In stage!.");
|
||||||
|
|
||||||
for (int i = 0; i < ((ViewGroup) rv).getChildCount(); i++) {
|
UiUtils.dumpView(UiUtils.getFirstViewFromActivity(activity));
|
||||||
if (((ViewGroup) rv).getChildAt(i) instanceof LinearLayout) {
|
|
||||||
Switch sWidget = rv.findViewById(R.id.switchWidget);
|
// The privileges are under the recycle view. Fetch all of them and check.
|
||||||
if (sWidget != null) {
|
ViewGroup viewGroup = (ViewGroup) recyclerView;
|
||||||
assertThat(sWidget.isEnabled()).isEqualTo(false);
|
|
||||||
|
for (int i = 0; i < viewGroup.getChildCount(); i++) {
|
||||||
|
if (viewGroup.getChildAt(i) instanceof LinearLayout) {
|
||||||
|
// A notification in Settings should have both switch_widget and text.
|
||||||
|
// There has another circle pin is no belongs to Settings package.
|
||||||
|
// But belongs to Switch in Android.
|
||||||
|
View sWidget = viewGroup.getChildAt(i).findViewById(
|
||||||
|
CommonUtils.getResId("switchWidget"));
|
||||||
|
TextView sText = viewGroup.getChildAt(i).findViewById(
|
||||||
|
android.R.id.title);
|
||||||
|
if (sText != null && sWidget != null
|
||||||
|
&& disabledList.stream().anyMatch(
|
||||||
|
str -> str.equals(sText.getText().toString().trim()))) {
|
||||||
|
|
||||||
|
assertThat(sWidget.isEnabled()).isFalse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -22,6 +22,8 @@ import android.os.Environment;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
|
import androidx.test.platform.app.InstrumentationRegistry;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@@ -93,4 +95,15 @@ public class CommonUtils {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a resource identifier for the given resource name in Settings app.
|
||||||
|
*
|
||||||
|
* @param name The name of the desired resource.
|
||||||
|
* @return int The associated resource identifier. Returns 0 if no such resource was found. (0
|
||||||
|
* is not a valid resource ID.)
|
||||||
|
*/
|
||||||
|
public static int getResId(String name) {
|
||||||
|
return InstrumentationRegistry.getInstrumentation().getTargetContext().getResources()
|
||||||
|
.getIdentifier(name, "id", Constants.SETTINGS_PACKAGE_NAME);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -20,4 +20,5 @@ public class Constants {
|
|||||||
public static final long ACTIVITY_LAUNCH_WAIT_TIMEOUT = 5000;
|
public static final long ACTIVITY_LAUNCH_WAIT_TIMEOUT = 5000;
|
||||||
public static final long VIEW_APPEAR_WAIT_MEDIUM_TIMEOUT = 5000;
|
public static final long VIEW_APPEAR_WAIT_MEDIUM_TIMEOUT = 5000;
|
||||||
public static final long WIFI_CONNECT_WAIT_TIMEOUT = 15000;
|
public static final long WIFI_CONNECT_WAIT_TIMEOUT = 15000;
|
||||||
|
public static final String SETTINGS_PACKAGE_NAME = "com.android.settings";
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user