summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2016-12-20 22:57:16 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2016-12-20 22:57:19 +0000
commit72df83d1177672d6eb2e37f761177137f04b77c0 (patch)
treec65605f9b64295a6e106773b17982121cac44551
parenta03c3e74a4a315b81b89d69b3217de6d194eec03 (diff)
parent8dc3b870a0d4095c2382f131fdba68168d757d2c (diff)
Merge "Add flags to send package name for feedback." into nyc-mr2-dev
-rwxr-xr-xpackages/SettingsLib/res/values/config.xml6
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/HelpUtils.java14
-rw-r--r--packages/SettingsLib/tests/robotests/src/com/android/settingslib/HelpUtilsTest.java130
3 files changed, 146 insertions, 4 deletions
diff --git a/packages/SettingsLib/res/values/config.xml b/packages/SettingsLib/res/values/config.xml
index 0aa76a024d5b..64f21b50c0bc 100755
--- a/packages/SettingsLib/res/values/config.xml
+++ b/packages/SettingsLib/res/values/config.xml
@@ -38,6 +38,12 @@
<!-- Intent key for package name values -->
<string name="config_helpIntentNameKey" translatable="false"></string>
+ <!-- Intent key for the package name keys -->
+ <string name="config_feedbackIntentExtraKey" translatable="false"></string>
+
+ <!-- Intent key for package name values -->
+ <string name="config_feedbackIntentNameKey" translatable="false"></string>
+
<!-- The apps that need to be hided when they are disabled -->
<string-array name="config_hideWhenDisabled_packageNames"></string-array>
</resources> \ No newline at end of file
diff --git a/packages/SettingsLib/src/com/android/settingslib/HelpUtils.java b/packages/SettingsLib/src/com/android/settingslib/HelpUtils.java
index 381f903a9701..e7c8c0b975b0 100644
--- a/packages/SettingsLib/src/com/android/settingslib/HelpUtils.java
+++ b/packages/SettingsLib/src/com/android/settingslib/HelpUtils.java
@@ -185,12 +185,18 @@ public class HelpUtils {
{resources.getString(R.string.config_helpPackageNameKey)};
String[] packageNameValue =
{resources.getString(R.string.config_helpPackageNameValue)};
- String intentExtraKey =
+ String helpIntentExtraKey =
resources.getString(R.string.config_helpIntentExtraKey);
- String intentNameKey =
+ String helpIntentNameKey =
resources.getString(R.string.config_helpIntentNameKey);
- intent.putExtra(intentExtraKey, packageNameKey);
- intent.putExtra(intentNameKey, packageNameValue);
+ String feedbackIntentExtraKey =
+ resources.getString(R.string.config_feedbackIntentExtraKey);
+ String feedbackIntentNameKey =
+ resources.getString(R.string.config_feedbackIntentNameKey);
+ intent.putExtra(helpIntentExtraKey, packageNameKey);
+ intent.putExtra(helpIntentNameKey, packageNameValue);
+ intent.putExtra(feedbackIntentExtraKey, packageNameKey);
+ intent.putExtra(feedbackIntentNameKey, packageNameValue);
}
intent.putExtra(EXTRA_THEME, 1 /* Light, dark action bar */);
TypedArray array = context.obtainStyledAttributes(new int[]{android.R.attr.colorPrimary});
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/HelpUtilsTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/HelpUtilsTest.java
new file mode 100644
index 000000000000..5d843c1a80ca
--- /dev/null
+++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/HelpUtilsTest.java
@@ -0,0 +1,130 @@
+/*
+ * 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.settingslib;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.res.Resources;
+import android.content.res.TypedArray;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.annotation.Config;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Mockito.when;
+
+/**
+ * Tests for {@link HelpUtils}.
+ */
+@RunWith(RobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class HelpUtilsTest {
+ private static final String PACKAGE_NAME_KEY = "package-name-key";
+ private static final String PACKAGE_NAME_VALUE = "package-name-value";
+ private static final String HELP_INTENT_EXTRA_KEY = "help-intent-extra";
+ private static final String HELP_INTENT_NAME_KEY = "help-intent-name";
+ private static final String FEEDBACK_INTENT_EXTRA_KEY = "feedback-intent-extra";
+ private static final String FEEDBACK_INTENT_NAME_KEY = "feedback-intent-name";
+
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private Context mContext;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ when(mContext.getResources().getString(R.string.config_helpPackageNameKey))
+ .thenReturn(PACKAGE_NAME_KEY);
+ when(mContext.getResources().getString(R.string.config_helpPackageNameValue))
+ .thenReturn(PACKAGE_NAME_VALUE);
+ when(mContext.getResources().getString(R.string.config_helpIntentExtraKey))
+ .thenReturn(HELP_INTENT_EXTRA_KEY);
+ when(mContext.getResources().getString(R.string.config_helpIntentNameKey))
+ .thenReturn(HELP_INTENT_NAME_KEY);
+ when(mContext.getResources().getString(R.string.config_feedbackIntentExtraKey))
+ .thenReturn(FEEDBACK_INTENT_EXTRA_KEY);
+ when(mContext.getResources().getString(R.string.config_feedbackIntentNameKey))
+ .thenReturn(FEEDBACK_INTENT_NAME_KEY);
+
+ }
+
+ @Test
+ public void addIntentParameters_configTrue_argumentTrue() {
+ when(mContext.getResources().getBoolean(R.bool.config_sendPackageName)).thenReturn(true);
+ Intent intent = new Intent();
+
+ HelpUtils.addIntentParameters(
+ mContext, intent, null /* backupContext */, true /* sendPackageName */);
+
+ assertThat(intent.getStringArrayExtra(HELP_INTENT_EXTRA_KEY)).asList()
+ .containsExactly(PACKAGE_NAME_KEY);
+ assertThat(intent.getStringArrayExtra(HELP_INTENT_NAME_KEY)).asList()
+ .containsExactly(PACKAGE_NAME_VALUE);
+ assertThat(intent.getStringArrayExtra(FEEDBACK_INTENT_EXTRA_KEY)).asList()
+ .containsExactly(PACKAGE_NAME_KEY);
+ assertThat(intent.getStringArrayExtra(FEEDBACK_INTENT_NAME_KEY)).asList()
+ .containsExactly(PACKAGE_NAME_VALUE);
+ }
+
+ @Test
+ public void addIntentParameters_configTrue_argumentFalse() {
+ when(mContext.getResources().getBoolean(R.bool.config_sendPackageName)).thenReturn(true);
+ Intent intent = new Intent();
+
+ HelpUtils.addIntentParameters(
+ mContext, intent, null /* backupContext */, false /* sendPackageName */);
+
+ assertThat(intent.hasExtra(HELP_INTENT_EXTRA_KEY)).isFalse();
+ assertThat(intent.hasExtra(HELP_INTENT_NAME_KEY)).isFalse();
+ assertThat(intent.hasExtra(FEEDBACK_INTENT_EXTRA_KEY)).isFalse();
+ assertThat(intent.hasExtra(FEEDBACK_INTENT_NAME_KEY)).isFalse();
+ }
+
+ @Test
+ public void addIntentParameters_configFalse_argumentTrue() {
+ when(mContext.getResources().getBoolean(R.bool.config_sendPackageName)).thenReturn(false);
+ Intent intent = new Intent();
+
+ HelpUtils.addIntentParameters(
+ mContext, intent, null /* backupContext */, true /* sendPackageName */);
+
+ assertThat(intent.hasExtra(HELP_INTENT_EXTRA_KEY)).isFalse();
+ assertThat(intent.hasExtra(HELP_INTENT_NAME_KEY)).isFalse();
+ assertThat(intent.hasExtra(FEEDBACK_INTENT_EXTRA_KEY)).isFalse();
+ assertThat(intent.hasExtra(FEEDBACK_INTENT_NAME_KEY)).isFalse();
+ }
+
+ @Test
+ public void addIntentParameters_configFalse_argumentFalse() {
+ when(mContext.getResources().getBoolean(R.bool.config_sendPackageName)).thenReturn(false);
+ Intent intent = new Intent();
+
+ HelpUtils.addIntentParameters(
+ mContext, intent, null /* backupContext */, false /* sendPackageName */);
+
+ assertThat(intent.hasExtra(HELP_INTENT_EXTRA_KEY)).isFalse();
+ assertThat(intent.hasExtra(HELP_INTENT_NAME_KEY)).isFalse();
+ assertThat(intent.hasExtra(FEEDBACK_INTENT_EXTRA_KEY)).isFalse();
+ assertThat(intent.hasExtra(FEEDBACK_INTENT_NAME_KEY)).isFalse();
+ }
+}