Add a suggestion: showing new device features

- New suggestion activity
- Removed useless api SuggestionFeatureProvider.isPresent().

- Also updated support activity search indexing icon and summary

Change-Id: Ib52cf26a985f57bf0aac918606b10f75bd024639
Fix: 62034077
Fix: 62196070
Test: make RunSettingsRoboTests
This commit is contained in:
Fan Zhang
2017-05-31 17:47:37 -07:00
parent 75c1fcb7fb
commit 9011a67431
13 changed files with 331 additions and 20 deletions

View File

@@ -0,0 +1,20 @@
<!--
Copyright (C) 2017 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.
-->
<resources>
<!-- url for new device suggestion -->
<string name="new_device_suggestion_intro_url" translatable="false">http://www.com.android.settings.test.com</string>
</resources>

View File

@@ -18,8 +18,8 @@
package com.android.settings.search;
import android.app.LoaderManager;
import android.content.Intent;
import android.content.Context;
import android.content.Intent;
import android.content.Loader;
import android.os.Bundle;
import android.util.Pair;
@@ -404,6 +404,8 @@ public class SearchFragmentTest {
// Should log result name, result count, clicked rank, etc.
final SearchViewHolder resultViewHolder = mock(SearchViewHolder.class);
when(resultViewHolder.getClickActionMetricName())
.thenReturn(MetricsProto.MetricsEvent.ACTION_CLICK_SETTINGS_SEARCH_RESULT);
ResultPayload payLoad = new ResultPayload(
(new Intent()).putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT, "test_setting"));
SearchResult searchResult = new SearchResult.Builder()

View File

@@ -0,0 +1,121 @@
/*
* Copyright (C) 2017 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.support;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ResolveInfo;
import com.android.settings.R;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.testutils.FakeFeatureFactory;
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.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.res.builder.RobolectricPackageManager;
import static com.android.settings.support.NewDeviceIntroSuggestionActivity
.PERMANENT_DISMISS_THRESHOLD;
import static com.android.settings.support.NewDeviceIntroSuggestionActivity
.PREF_KEY_SUGGGESTION_COMPLETE;
import static com.android.settings.support.NewDeviceIntroSuggestionActivity
.PREF_KEY_SUGGGESTION_FIRST_DISPLAY_TIME;
import static com.android.settings.support.NewDeviceIntroSuggestionActivity.isSuggestionComplete;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class NewDeviceIntroSuggestionActivityTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mMockContext;
private FakeFeatureFactory mFeatureFactory;
private Context mContext;
private RobolectricPackageManager mRobolectricPackageManager;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mFeatureFactory = FakeFeatureFactory.setupForTest(mMockContext);
mContext = RuntimeEnvironment.application;
mRobolectricPackageManager = RuntimeEnvironment.getRobolectricPackageManager();
when(mFeatureFactory.suggestionsFeatureProvider.getSharedPrefs(any(Context.class)))
.thenReturn(getSharedPreferences());
}
@Test
public void isSuggestionComplete_suggestionExpired_shouldReturnTrue() {
final long currentTime = System.currentTimeMillis();
getSharedPreferences().edit().putLong(PREF_KEY_SUGGGESTION_FIRST_DISPLAY_TIME,
currentTime - 2 * PERMANENT_DISMISS_THRESHOLD);
assertThat(isSuggestionComplete(mContext))
.isTrue();
}
@Test
public void isSuggestionComplete_noUrl_shouldReturnTrue() {
assertThat(mContext.getString(R.string.new_device_suggestion_intro_url))
.isEqualTo("");
assertThat(isSuggestionComplete(mContext))
.isTrue();
}
// Use a non-default resource qualifier to load the test string in
// res/values-mcc999/strings.xml.
@Config(qualifiers = "mcc999")
@Test
public void isSuggestionComplete_alreadyLaunchedBefore_shouldReturnTrue() {
assertThat(mContext.getString(R.string.new_device_suggestion_intro_url))
.startsWith("http");
getSharedPreferences().edit().putBoolean(PREF_KEY_SUGGGESTION_COMPLETE, true).commit();
assertThat(isSuggestionComplete(mContext))
.isTrue();
}
// Use a non-default resource qualifier to load the test string in
// res/values-mcc999/strings.xml.
@Config(qualifiers = "mcc999")
@Test
public void isSuggestionComplete_notExpiredAndCanOpenUrlInBrowser_shouldReturnFalse() {
assertThat(mContext.getString(R.string.new_device_suggestion_intro_url))
.startsWith("http");
final Intent intent = NewDeviceIntroSuggestionActivity.getLaunchIntent(mContext);
mRobolectricPackageManager.addResolveInfoForIntent(intent, new ResolveInfo());
assertThat(isSuggestionComplete(mContext)).isFalse();
}
private SharedPreferences getSharedPreferences() {
return mContext.getSharedPreferences("test_new_device_sugg", Context.MODE_PRIVATE);
}
}