Merge "Add flags to send package name for feedback." into nyc-mr2-dev

This commit is contained in:
TreeHugger Robot
2016-12-20 22:57:16 +00:00
committed by Android (Google) Code Review
3 changed files with 146 additions and 4 deletions

View File

@@ -38,6 +38,12 @@
<!-- Intent key for package name values --> <!-- Intent key for package name values -->
<string name="config_helpIntentNameKey" translatable="false"></string> <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 --> <!-- The apps that need to be hided when they are disabled -->
<string-array name="config_hideWhenDisabled_packageNames"></string-array> <string-array name="config_hideWhenDisabled_packageNames"></string-array>
</resources> </resources>

View File

@@ -185,12 +185,18 @@ public class HelpUtils {
{resources.getString(R.string.config_helpPackageNameKey)}; {resources.getString(R.string.config_helpPackageNameKey)};
String[] packageNameValue = String[] packageNameValue =
{resources.getString(R.string.config_helpPackageNameValue)}; {resources.getString(R.string.config_helpPackageNameValue)};
String intentExtraKey = String helpIntentExtraKey =
resources.getString(R.string.config_helpIntentExtraKey); resources.getString(R.string.config_helpIntentExtraKey);
String intentNameKey = String helpIntentNameKey =
resources.getString(R.string.config_helpIntentNameKey); resources.getString(R.string.config_helpIntentNameKey);
intent.putExtra(intentExtraKey, packageNameKey); String feedbackIntentExtraKey =
intent.putExtra(intentNameKey, packageNameValue); 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 */); intent.putExtra(EXTRA_THEME, 1 /* Light, dark action bar */);
TypedArray array = context.obtainStyledAttributes(new int[]{android.R.attr.colorPrimary}); TypedArray array = context.obtainStyledAttributes(new int[]{android.R.attr.colorPrimary});

View File

@@ -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();
}
}