OSDN Git Service

Use support feature provider to provide intro url.
authorFan Zhang <zhfan@google.com>
Thu, 8 Jun 2017 22:50:18 +0000 (15:50 -0700)
committerFan Zhang <zhfan@google.com>
Thu, 8 Jun 2017 23:34:35 +0000 (23:34 +0000)
Change-Id: I3d2493ec8c84fdc61c04fd63537f959fbd589e98
Fix: 62034077
Test: make RunSettingsRoboTests

res/values/strings.xml
src/com/android/settings/overlay/SupportFeatureProvider.java
src/com/android/settings/support/NewDeviceIntroSuggestionActivity.java
tests/robotests/res/values-mcc999/strings.xml [deleted file]
tests/robotests/src/com/android/settings/support/NewDeviceIntroSuggestionActivityTest.java

index ef6e9bb..fbf703c 100644 (file)
 
     <!-- The divider symbol between different parts of the notification header including spaces. not translatable [CHAR LIMIT=3] -->
     <string name="notification_header_divider_symbol_with_spaces" translatable="false">" • "</string>
-
-    <!-- url for new device suggestion -->
-    <string name="new_device_suggestion_intro_url" translatable="false"></string>
 </resources>
index 1831486..55d5d0e 100644 (file)
@@ -24,8 +24,8 @@ import android.app.Activity;
 import android.app.FragmentManager;
 import android.content.Context;
 import android.content.Intent;
-
 import android.os.Bundle;
+
 import com.android.settings.support.SupportPhone;
 
 import java.lang.annotation.Retention;
@@ -123,8 +123,8 @@ public interface SupportFeatureProvider {
      * Starts support activity of specified type
      *
      * @param activity Calling activity
-     * @param account A account that selected by user
-     * @param type The type of support account needs.
+     * @param account  A account that selected by user
+     * @param type     The type of support account needs.
      */
     void startSupport(Activity activity, Account account, @SupportType int type);
 
@@ -137,6 +137,7 @@ public interface SupportFeatureProvider {
 
     /**
      * Checks if support v2 is enabled for this device.
+     *
      * @return a boolean indicating if support v2 is enabled.
      */
     boolean isSupportV2Enabled();
@@ -166,4 +167,9 @@ public interface SupportFeatureProvider {
      * launches the fragment that displays the system information being sent to support agents.
      */
     void launchSystemInfoFragment(Bundle args, FragmentManager manager);
+
+    /**
+     * Returns a url with information to introduce user to new device.
+     */
+    String getNewDeviceIntroUrl(Context context);
 }
index d301099..2189184 100644 (file)
@@ -28,9 +28,9 @@ import android.text.TextUtils;
 import android.text.format.DateUtils;
 import android.util.Log;
 
-import com.android.settings.R;
 import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
 import com.android.settings.overlay.FeatureFactory;
+import com.android.settings.overlay.SupportFeatureProvider;
 
 import java.util.List;
 
@@ -107,7 +107,12 @@ public class NewDeviceIntroSuggestionActivity extends Activity {
 
     @VisibleForTesting
     static Intent getLaunchIntent(Context context) {
-        final String url = context.getString(R.string.new_device_suggestion_intro_url);
+        final SupportFeatureProvider supportProvider = FeatureFactory.getFactory(context)
+                .getSupportFeatureProvider(context);
+        if (supportProvider == null) {
+            return null;
+        }
+        final String url = supportProvider.getNewDeviceIntroUrl(context);
         if (TextUtils.isEmpty(url)) {
             return null;
         }
diff --git a/tests/robotests/res/values-mcc999/strings.xml b/tests/robotests/res/values-mcc999/strings.xml
deleted file mode 100644 (file)
index fb14b44..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-<!--
-  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>
index 3392713..311c297 100644 (file)
@@ -22,7 +22,6 @@ 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;
@@ -82,32 +81,27 @@ public class NewDeviceIntroSuggestionActivityTest {
 
     @Test
     public void isSuggestionComplete_noUrl_shouldReturnTrue() {
-        assertThat(mContext.getString(R.string.new_device_suggestion_intro_url))
-                .isEqualTo("");
+        when(mFeatureFactory.supportFeatureProvider.getNewDeviceIntroUrl(any(Context.class)))
+                .thenReturn(null);
         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");
+        when(mFeatureFactory.supportFeatureProvider.getNewDeviceIntroUrl(any(Context.class)))
+                .thenReturn("https://com.android.settings");
+
         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");
+        when(mFeatureFactory.supportFeatureProvider.getNewDeviceIntroUrl(any(Context.class)))
+                .thenReturn("https://com.android.settings");
 
         final Intent intent = NewDeviceIntroSuggestionActivity.getLaunchIntent(mContext);
         mRobolectricPackageManager.addResolveInfoForIntent(intent, new ResolveInfo());