OSDN Git Service

Fallback to default wallpaper picker if first choice fails
authorFan Zhang <zhfan@google.com>
Fri, 17 Mar 2017 22:05:14 +0000 (15:05 -0700)
committerFan Zhang <zhfan@google.com>
Fri, 17 Mar 2017 23:49:58 +0000 (16:49 -0700)
- Add fallback logic in WallpaperSuggestionActivity
- Move some classes around
- Delete some unused class

Change-Id: Ifc8864428647a94f3ecae50d193c2156b2592ff3
Fix: 36140287
Test: make RunSettingsRoboTests

12 files changed:
AndroidManifest.xml
res/values/strings.xml
src/com/android/settings/DevelopmentSettings.java
src/com/android/settings/core/gateway/SettingsGateway.java
src/com/android/settings/dashboard/DashboardSummary.java
src/com/android/settings/dashboard/NoHomeDialogFragment.java [deleted file]
src/com/android/settings/dashboard/suggestions/SuggestionsChecks.java [moved from src/com/android/settings/dashboard/SuggestionsChecks.java with 89% similarity]
src/com/android/settings/development/AppPicker.java [moved from src/com/android/settings/AppPicker.java with 98% similarity]
src/com/android/settings/search/SearchIndexableResources.java
src/com/android/settings/wallpaper/WallpaperSuggestionActivity.java [moved from src/com/android/settings/WallpaperSuggestionActivity.java with 51% similarity]
src/com/android/settings/wallpaper/WallpaperTypeSettings.java [moved from src/com/android/settings/WallpaperTypeSettings.java with 96% similarity]
tests/robotests/src/com/android/settings/wallpaper/WallpaperSuggestionActivityTest.java [new file with mode: 0644]

index 07d7ecc..0c5c6ef 100644 (file)
         </activity>
 
         <!-- Wireless Controls -->
-
         <activity android:name=".Settings$NetworkDashboardActivity"
             android:taskAffinity="com.android.settings"
             android:label="@string/network_dashboard_title"
                   android:icon="@drawable/ic_wallpaper"
                   android:taskAffinity="">
             <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
-                       android:value="com.android.settings.WallpaperTypeSettings" />
+                       android:value="com.android.settings.wallpaper.WallpaperTypeSettings" />
         </activity>
 
-        <activity android:name="WallpaperSuggestionActivity"
+        <activity android:name=".wallpaper.WallpaperSuggestionActivity"
                   android:label="@string/wallpaper_settings_title"
                   android:icon="@drawable/ic_wallpaper"
-                  android:exported="true"
                   android:theme="@android:style/Theme.NoDisplay">
             <intent-filter android:priority="1">
                 <action android:name="android.intent.action.MAIN" />
                 android:value="com.android.settings.DevelopmentSettings" />
         </activity-alias>
 
-        <activity android:name=".AppPicker" android:label="@string/select_application"
-                android:theme="@android:style/Theme.DeviceDefault.Light.Dialog" />
+        <activity android:name=".development.AppPicker"
+                  android:label="@string/select_application"
+                  android:theme="@android:style/Theme.DeviceDefault.Light.Dialog" />
 
         <activity android:name="Settings$WebViewAppPickerActivity"
                   android:label="@string/select_webview_provider_dialog_title">
index ac62144..ae2ee09 100644 (file)
 
     <!-- Home application selection - uninstall button [CHAR LIMIT=80] -->
     <string name="home_app_uninstall_button">Uninstall this application</string>
-    <!-- Message to user that Home Settings will be hidden because there is now only one available home application -->
-    <string name="only_one_home_message">Home settings will be hidden until you install another home application.</string>
 
     <!-- Warning message when changing a global setting for a tablet.[CHAR LIMIT=none] -->
     <string name="global_change_warning" product="tablet">This setting affects all users on this tablet.</string>
index dc70725..6aae587 100644 (file)
@@ -31,7 +31,6 @@ import android.bluetooth.BluetoothCodecConfig;
 import android.bluetooth.BluetoothCodecStatus;
 import android.bluetooth.BluetoothProfile;
 import android.content.BroadcastReceiver;
-import android.content.ComponentName;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.DialogInterface;
@@ -85,12 +84,11 @@ import android.widget.Toast;
 
 import com.android.internal.app.LocalePicker;
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
-import com.android.settings.applications.BackgroundCheckSummary;
 import com.android.settings.dashboard.DashboardFeatureProvider;
-import com.android.settings.development.BugReportPreferenceController;
+import com.android.settings.development.AppPicker;
 import com.android.settings.development.BugReportInPowerPreferenceController;
+import com.android.settings.development.BugReportPreferenceController;
 import com.android.settings.development.TelephonyMonitorPreferenceController;
-import com.android.settings.fuelgauge.InactiveApps;
 import com.android.settings.overlay.FeatureFactory;
 import com.android.settings.search.BaseSearchIndexProvider;
 import com.android.settings.search.Indexable;
index f6cad28..8514e8f 100644 (file)
@@ -36,7 +36,6 @@ import com.android.settings.TestingSettings;
 import com.android.settings.TetherSettings;
 import com.android.settings.TrustedCredentialsSettings;
 import com.android.settings.UserDictionarySettings;
-import com.android.settings.WallpaperTypeSettings;
 import com.android.settings.WifiCallingSettings;
 import com.android.settings.accessibility.AccessibilitySettings;
 import com.android.settings.accessibility.AccessibilitySettingsForSetupWizard;
@@ -116,6 +115,7 @@ import com.android.settings.system.SystemDashboardFragment;
 import com.android.settings.tts.TextToSpeechSettings;
 import com.android.settings.users.UserSettings;
 import com.android.settings.vpn2.VpnSettings;
+import com.android.settings.wallpaper.WallpaperTypeSettings;
 import com.android.settings.webview.WebViewAppPicker;
 import com.android.settings.wfd.WifiDisplaySettings;
 import com.android.settings.wifi.ConfigureWifiSettings;
index 7a5f395..4419f24 100644 (file)
@@ -37,6 +37,7 @@ import com.android.settings.dashboard.conditional.ConditionManager;
 import com.android.settings.dashboard.conditional.FocusRecyclerView;
 import com.android.settings.dashboard.suggestions.SuggestionDismissController;
 import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
+import com.android.settings.dashboard.suggestions.SuggestionsChecks;
 import com.android.settings.overlay.FeatureFactory;
 import com.android.settingslib.SuggestionParser;
 import com.android.settingslib.drawer.CategoryKey;
diff --git a/src/com/android/settings/dashboard/NoHomeDialogFragment.java b/src/com/android/settings/dashboard/NoHomeDialogFragment.java
deleted file mode 100644 (file)
index e27570b..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2014 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.dashboard;
-
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.app.Dialog;
-import android.app.DialogFragment;
-import android.os.Bundle;
-
-import com.android.internal.logging.nano.MetricsProto;
-import com.android.settings.R;
-import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
-
-public class NoHomeDialogFragment extends InstrumentedDialogFragment {
-    public static void show(Activity parent) {
-        final NoHomeDialogFragment dialog = new NoHomeDialogFragment();
-        dialog.show(parent.getFragmentManager(), null);
-    }
-
-    @Override
-    public Dialog onCreateDialog(Bundle savedInstanceState) {
-        return new AlertDialog.Builder(getActivity())
-                .setMessage(R.string.only_one_home_message)
-                .setPositiveButton(android.R.string.ok, null)
-                .create();
-    }
-
-    @Override
-    public int getMetricsCategory() {
-        return MetricsProto.MetricsEvent.DIALOG_NO_HOME;
-    }
-}
@@ -1,18 +1,20 @@
 /*
- * Copyright (C) 2016 The Android Open Source Project
+ * 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
+ * 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.
+ * 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.dashboard;
+package com.android.settings.dashboard.suggestions;
 
 import android.app.AutomaticZenRule;
 import android.app.IWallpaperManager;
@@ -30,15 +32,14 @@ import android.os.RemoteException;
 import android.os.ServiceManager;
 
 import com.android.ims.ImsManager;
-import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
 import com.android.settings.Settings.FingerprintEnrollSuggestionActivity;
 import com.android.settings.Settings.FingerprintSuggestionActivity;
 import com.android.settings.Settings.ScreenLockSuggestionActivity;
 import com.android.settings.Settings.WifiCallingSuggestionActivity;
 import com.android.settings.Settings.ZenModeAutomationSuggestionActivity;
 import com.android.settings.Utils;
-import com.android.settings.WallpaperSuggestionActivity;
 import com.android.settings.overlay.FeatureFactory;
+import com.android.settings.wallpaper.WallpaperSuggestionActivity;
 import com.android.settingslib.drawer.Tile;
 
 import java.util.Collection;
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package com.android.settings;
+package com.android.settings.development;
 
 import android.app.ListActivity;
 import android.content.Context;
@@ -31,6 +31,7 @@ import android.view.ViewGroup;
 import android.widget.ArrayAdapter;
 import android.widget.ListView;
 
+import com.android.settings.R;
 import com.android.settings.applications.AppViewHolder;
 
 import java.text.Collator;
index a659077..329451c 100644 (file)
@@ -20,17 +20,16 @@ import android.provider.SearchIndexableResource;
 import android.support.annotation.DrawableRes;
 import android.support.annotation.VisibleForTesting;
 import android.support.annotation.XmlRes;
+
 import com.android.settings.DateTimeSettings;
 import com.android.settings.DevelopmentSettings;
 import com.android.settings.DeviceInfoSettings;
 import com.android.settings.DisplaySettings;
 import com.android.settings.EncryptionAndCredential;
 import com.android.settings.LegalSettings;
-import com.android.settings.PrivacySettings;
 import com.android.settings.R;
 import com.android.settings.ScreenPinningSettings;
 import com.android.settings.SecuritySettings;
-import com.android.settings.WallpaperTypeSettings;
 import com.android.settings.accessibility.AccessibilitySettings;
 import com.android.settings.accounts.UserAndAccountDashboardFragment;
 import com.android.settings.applications.AdvancedAppSettings;
@@ -76,6 +75,7 @@ import com.android.settings.system.SystemDashboardFragment;
 import com.android.settings.tts.TtsEnginePreferenceFragment;
 import com.android.settings.tts.TtsSlidersFragment;
 import com.android.settings.users.UserSettings;
+import com.android.settings.wallpaper.WallpaperTypeSettings;
 import com.android.settings.wifi.ConfigureWifiSettings;
 import com.android.settings.wifi.SavedAccessPointsWifiSettings;
 import com.android.settings.wifi.WifiSettings;
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016 The Android Open Source Project
+ * 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.
  * 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
+ * limitations under the License.
  */
 
-package com.android.settings;
+package com.android.settings.wallpaper;
 
 import android.app.Activity;
 import android.content.Intent;
+import android.content.pm.PackageManager;
 import android.os.Bundle;
+import android.support.annotation.VisibleForTesting;
+
+import com.android.internal.logging.nano.MetricsProto;
+import com.android.settings.R;
+import com.android.settings.Utils;
 
 public class WallpaperSuggestionActivity extends Activity {
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
-        Intent intent = new Intent()
+        final PackageManager pm = getPackageManager();
+        final Intent intent = new Intent()
                 .setClassName(getString(R.string.config_wallpaper_picker_package),
                         getString(R.string.config_wallpaper_picker_class))
                 .addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
-        startActivity(intent);
+        if (pm.resolveActivity(intent, 0) != null) {
+            startActivity(intent);
+        } else {
+            startFallbackSuggestion();
+        }
+
         finish();
     }
+
+    @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
+    void startFallbackSuggestion() {
+        // fall back to default wallpaper picker
+        Utils.startWithFragment(this, WallpaperTypeSettings.class.getName(), null, null, 0,
+                R.string.wallpaper_suggestion_title, null,
+                MetricsProto.MetricsEvent.DASHBOARD_SUMMARY);
+    }
+
 }
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 The Android Open Source Project
+ * 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.
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package com.android.settings;
+package com.android.settings.wallpaper;
 
 import android.content.ComponentName;
 import android.content.Context;
@@ -26,6 +26,8 @@ import android.support.v7.preference.Preference;
 import android.support.v7.preference.PreferenceScreen;
 
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.settings.R;
+import com.android.settings.SettingsPreferenceFragment;
 import com.android.settings.search.BaseSearchIndexProvider;
 import com.android.settings.search.Indexable;
 import com.android.settings.search.SearchIndexableRaw;
diff --git a/tests/robotests/src/com/android/settings/wallpaper/WallpaperSuggestionActivityTest.java b/tests/robotests/src/com/android/settings/wallpaper/WallpaperSuggestionActivityTest.java
new file mode 100644 (file)
index 0000000..494492e
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * 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.wallpaper;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.SubSettings;
+import com.android.settings.TestConfig;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.Robolectric;
+import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowActivity;
+import org.robolectric.util.ActivityController;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.when;
+import static org.robolectric.Shadows.shadowOf;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class WallpaperSuggestionActivityTest {
+
+    @Mock
+    private Context mContext;
+    @Mock
+    private PackageManager mPackageManager;
+    private ActivityController<WallpaperSuggestionActivity> mController;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        when(mContext.getPackageManager()).thenReturn(mPackageManager);
+        mController = Robolectric.buildActivity(WallpaperSuggestionActivity.class);
+    }
+
+    @Test
+    public void launch_primarySuggestionActivityDoesNotExist_shouldFallback() {
+        ShadowActivity activity = shadowOf(mController.setup().get());
+        final Intent intent = activity.getNextStartedActivity();
+
+        assertThat(intent.getComponent().getClassName()).isEqualTo(SubSettings.class.getName());
+    }
+}