Fallback to default wallpaper picker if first choice fails

- Add fallback logic in WallpaperSuggestionActivity
- Move some classes around
- Delete some unused class

Change-Id: Ifc8864428647a94f3ecae50d193c2156b2592ff3
Fix: 36140287
Test: make RunSettingsRoboTests
This commit is contained in:
Fan Zhang
2017-03-17 15:05:14 -07:00
parent 92c6a45358
commit 2907f86971
12 changed files with 119 additions and 80 deletions

View File

@@ -143,7 +143,6 @@
</activity>
<!-- Wireless Controls -->
<activity android:name=".Settings$NetworkDashboardActivity"
android:taskAffinity="com.android.settings"
android:label="@string/network_dashboard_title"
@@ -803,13 +802,12 @@
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" />
@@ -1942,7 +1940,8 @@
android:value="com.android.settings.DevelopmentSettings" />
</activity-alias>
<activity android:name=".AppPicker" android:label="@string/select_application"
<activity android:name=".development.AppPicker"
android:label="@string/select_application"
android:theme="@android:style/Theme.DeviceDefault.Light.Dialog" />
<activity android:name="Settings$WebViewAppPickerActivity"

View File

@@ -5718,8 +5718,6 @@
<!-- 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>

View 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;

View 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;

View 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;

View File

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

View File

@@ -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;

View File

@@ -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;

View 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;

View File

@@ -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.
@@ -11,25 +11,46 @@
* 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);
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);
}
}

View File

@@ -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;

View File

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