From 5c3816ba0385131a82afc6554d3d8fed3585154d Mon Sep 17 00:00:00 2001 From: Fan Zhang Date: Thu, 12 Jul 2018 10:58:13 -0700 Subject: [PATCH] Remove NewDeviceIntroSuggestion The functionality is entirely replaced by other apps. Change-Id: Id3d425cf92a07bae070cd22c0d726aba0472dd5d Fixes: 111195449 Test: robotest --- AndroidManifest.xml | 16 --- res/drawable/ic_new_device_suggestion_24dp.xml | 26 ---- res/values/config.xml | 3 - res/values/strings.xml | 12 -- .../suggestions/SuggestionFeatureProviderImpl.java | 3 - .../support/NewDeviceIntroSuggestionActivity.java | 155 --------------------- tests/robotests/res/values/config.xml | 1 - .../suggestions/SettingsSuggestionsTest.java | 45 +++--- .../NewDeviceIntroSuggestionActivityTest.java | 151 -------------------- 9 files changed, 18 insertions(+), 394 deletions(-) delete mode 100644 res/drawable/ic_new_device_suggestion_24dp.xml delete mode 100644 src/com/android/settings/support/NewDeviceIntroSuggestionActivity.java delete mode 100644 tests/robotests/src/com/android/settings/support/NewDeviceIntroSuggestionActivityTest.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index efea32c43a..b66688110d 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -824,22 +824,6 @@ - - - - - - - - - - - - - - diff --git a/res/values/config.xml b/res/values/config.xml index 0a733079a9..2920ac839d 100755 --- a/res/values/config.xml +++ b/res/values/config.xml @@ -117,9 +117,6 @@ com.android.storagemanager.deletionhelper.DeletionHelperActivity - - false - diff --git a/res/values/strings.xml b/res/values/strings.xml index a4377b0a8b..82ae090c1f 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -10007,18 +10007,6 @@ Pause notifications to stay focused - - What\'s new and exciting? - - - Take a tour of your new phone - - - Take a tour of your new tablet - - - Take a tour of your new device - " • " diff --git a/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImpl.java b/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImpl.java index 1601f19b57..e1cf1a3448 100644 --- a/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImpl.java +++ b/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImpl.java @@ -34,7 +34,6 @@ import com.android.settings.notification.ZenOnboardingActivity; import com.android.settings.notification.ZenSuggestionActivity; import com.android.settings.overlay.FeatureFactory; import com.android.settings.password.ScreenLockSuggestionActivity; -import com.android.settings.support.NewDeviceIntroSuggestionActivity; import com.android.settings.wallpaper.WallpaperSuggestionActivity; import com.android.settings.wifi.calling.WifiCallingSuggestionActivity; import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; @@ -88,8 +87,6 @@ public class SuggestionFeatureProviderImpl implements SuggestionFeatureProvider return WifiCallingSuggestionActivity.isSuggestionComplete(context); } else if (className.equals(NightDisplaySuggestionActivity.class.getName())) { return NightDisplayPreferenceController.isSuggestionComplete(context); - } else if (className.equals(NewDeviceIntroSuggestionActivity.class.getName())) { - return NewDeviceIntroSuggestionActivity.isSuggestionComplete(context); } else if (className.equals(ZenSuggestionActivity.class.getName())) { return ZenOnboardingActivity.isSuggestionComplete(context); } diff --git a/src/com/android/settings/support/NewDeviceIntroSuggestionActivity.java b/src/com/android/settings/support/NewDeviceIntroSuggestionActivity.java deleted file mode 100644 index e025c6062e..0000000000 --- a/src/com/android/settings/support/NewDeviceIntroSuggestionActivity.java +++ /dev/null @@ -1,155 +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. - */ - -package com.android.settings.support; - -import android.app.Activity; -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.content.pm.PackageInfo; -import android.content.pm.PackageManager; -import android.content.pm.ResolveInfo; -import android.net.Uri; -import android.os.Bundle; -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; - -import androidx.annotation.NonNull; -import androidx.annotation.VisibleForTesting; - -public class NewDeviceIntroSuggestionActivity extends Activity { - - private static final String TAG = "NewDeviceIntroSugg"; - @VisibleForTesting - static final String PREF_KEY_SUGGGESTION_FIRST_DISPLAY_TIME = - "pref_new_device_intro_suggestion_first_display_time_ms"; - @VisibleForTesting - static final String PREF_KEY_SUGGGESTION_COMPLETE = - "pref_new_device_intro_suggestion_complete"; - @VisibleForTesting - static final long PERMANENT_DISMISS_THRESHOLD = DateUtils.DAY_IN_MILLIS * 14; - - public static final String TIPS_PACKAGE_NAME = "com.google.android.apps.tips"; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - final Intent intent = getLaunchIntent(this); - if (intent != null) { - final SuggestionFeatureProvider featureProvider = FeatureFactory.getFactory(this) - .getSuggestionFeatureProvider(this); - final SharedPreferences prefs = featureProvider.getSharedPrefs(this); - prefs.edit().putBoolean(PREF_KEY_SUGGGESTION_COMPLETE, true).commit(); - startActivity(intent); - } - finish(); - } - - public static boolean isSuggestionComplete(Context context) { - // Always returns 'true' if Tips application exists. Check b/77652536 for more details. - return isTipsInstalledAsSystemApp(context) - || !isSupported(context) - || isExpired(context) - || hasLaunchedBefore(context) - || !canOpenUrlInBrowser(context); - } - - private static boolean isSupported(Context context) { - return context.getResources() - .getBoolean(R.bool.config_new_device_intro_suggestion_supported); - } - - private static boolean isExpired(Context context) { - final SuggestionFeatureProvider featureProvider = FeatureFactory.getFactory(context) - .getSuggestionFeatureProvider(context); - final SharedPreferences prefs = featureProvider.getSharedPrefs(context); - final long currentTimeMs = System.currentTimeMillis(); - final long firstDisplayTimeMs; - - if (!prefs.contains(PREF_KEY_SUGGGESTION_FIRST_DISPLAY_TIME)) { - firstDisplayTimeMs = currentTimeMs; - prefs.edit().putLong(PREF_KEY_SUGGGESTION_FIRST_DISPLAY_TIME, currentTimeMs).commit(); - } else { - firstDisplayTimeMs = prefs.getLong(PREF_KEY_SUGGGESTION_FIRST_DISPLAY_TIME, -1); - } - - final long dismissTimeMs = firstDisplayTimeMs + PERMANENT_DISMISS_THRESHOLD; - - final boolean expired = currentTimeMs > dismissTimeMs; - - Log.d(TAG, "is suggestion expired: " + expired); - return expired; - } - - private static boolean canOpenUrlInBrowser(Context context) { - final Intent intent = getLaunchIntent(context); - if (intent == null) { - // No url/intent to launch. - return false; - } - // Make sure we can handle the intent. - final List resolveInfos = - context.getPackageManager().queryIntentActivities(intent, 0); - return resolveInfos != null && resolveInfos.size() != 0; - } - - private static boolean hasLaunchedBefore(Context context) { - final SuggestionFeatureProvider featureProvider = FeatureFactory.getFactory(context) - .getSuggestionFeatureProvider(context); - final SharedPreferences prefs = featureProvider.getSharedPrefs(context); - return prefs.getBoolean(PREF_KEY_SUGGGESTION_COMPLETE, false); - } - - @VisibleForTesting - static Intent getLaunchIntent(Context context) { - 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; - } - return new Intent() - .setAction(Intent.ACTION_VIEW) - .addCategory(Intent.CATEGORY_BROWSABLE) - .setData(Uri.parse(url)); - } - - /** - * Check if the specified package exists and is marked with FLAG_SYSTEM - */ - private static boolean isTipsInstalledAsSystemApp(@NonNull Context context) { - try { - final PackageInfo info = context.getPackageManager().getPackageInfo(TIPS_PACKAGE_NAME, - PackageManager.MATCH_SYSTEM_ONLY); - return info != null; - } catch (PackageManager.NameNotFoundException e) { - Log.w(TAG, "Cannot find the package: " + TIPS_PACKAGE_NAME, e); - return false; - } - } -} diff --git a/tests/robotests/res/values/config.xml b/tests/robotests/res/values/config.xml index 359df6cc0a..bbf2520e8f 100644 --- a/tests/robotests/res/values/config.xml +++ b/tests/robotests/res/values/config.xml @@ -16,7 +16,6 @@ - true true true true diff --git a/tests/robotests/src/com/android/settings/suggestions/SettingsSuggestionsTest.java b/tests/robotests/src/com/android/settings/suggestions/SettingsSuggestionsTest.java index 38d9ce5ba7..54bff58b86 100644 --- a/tests/robotests/src/com/android/settings/suggestions/SettingsSuggestionsTest.java +++ b/tests/robotests/src/com/android/settings/suggestions/SettingsSuggestionsTest.java @@ -31,7 +31,6 @@ import com.android.settings.Settings; import com.android.settings.biometrics.fingerprint.FingerprintEnrollSuggestionActivity; import com.android.settings.biometrics.fingerprint.FingerprintSuggestionActivity; import com.android.settings.notification.ZenSuggestionActivity; -import com.android.settings.support.NewDeviceIntroSuggestionActivity; import com.android.settings.testutils.SettingsRobolectricTestRunner; import com.android.settings.wallpaper.WallpaperSuggestionActivity; import com.android.settings.wifi.calling.WifiCallingSuggestionActivity; @@ -46,41 +45,41 @@ public class SettingsSuggestionsTest { @Test public void wallpaperSuggestion_isValid() { assertSuggestionEquals( - WallpaperSuggestionActivity.class.getName(), - R.string.wallpaper_suggestion_title, - R.string.wallpaper_suggestion_summary); + WallpaperSuggestionActivity.class.getName(), + R.string.wallpaper_suggestion_title, + R.string.wallpaper_suggestion_summary); } @Test public void fingerprintSuggestion_isValid() { assertSuggestionEquals( - FingerprintSuggestionActivity.class.getName(), - R.string.suggestion_additional_fingerprints, - R.string.suggestion_additional_fingerprints_summary); + FingerprintSuggestionActivity.class.getName(), + R.string.suggestion_additional_fingerprints, + R.string.suggestion_additional_fingerprints_summary); } @Test public void fingerprintEnrollSuggestion_isValid() { assertSuggestionEquals( - FingerprintEnrollSuggestionActivity.class.getName(), - R.string.suggested_fingerprint_lock_settings_title, - R.string.suggested_fingerprint_lock_settings_summary); + FingerprintEnrollSuggestionActivity.class.getName(), + R.string.suggested_fingerprint_lock_settings_title, + R.string.suggested_fingerprint_lock_settings_summary); } @Test public void wifiCallingSuggestion_isValid() { assertSuggestionEquals( - WifiCallingSuggestionActivity.class.getName(), - R.string.wifi_calling_suggestion_title, - R.string.wifi_calling_suggestion_summary); + WifiCallingSuggestionActivity.class.getName(), + R.string.wifi_calling_suggestion_title, + R.string.wifi_calling_suggestion_summary); } @Test public void nightDisplaySuggestion_isValid() { assertSuggestionEquals( - Settings.NightDisplaySuggestionActivity.class.getName(), - R.string.night_display_suggestion_title, - R.string.night_display_suggestion_summary); + Settings.NightDisplaySuggestionActivity.class.getName(), + R.string.night_display_suggestion_title, + R.string.night_display_suggestion_summary); } @Test @@ -91,16 +90,8 @@ public class SettingsSuggestionsTest { R.string.zen_suggestion_summary); } - @Test - public void newDeviceIntroSuggestion_isValid() { - assertSuggestionEquals( - NewDeviceIntroSuggestionActivity.class.getName(), - R.string.new_device_suggestion_title, - R.string.new_device_suggestion_summary); - } - private void assertSuggestionEquals(String activityName, @StringRes int titleRes, - @StringRes int summaryRes) { + @StringRes int summaryRes) { final Context context = RuntimeEnvironment.application; final PackageManager pm = context.getPackageManager(); @@ -117,13 +108,13 @@ public class SettingsSuggestionsTest { final String title = (String) info.metaData.get("com.android.settings.title"); final String actualTitle = - context.getString(resources.getIdentifier(title.substring(8), "string", pName)); + context.getString(resources.getIdentifier(title.substring(8), "string", pName)); final String expectedTitle = context.getString(titleRes); assertThat(actualTitle).isEqualTo(expectedTitle); final String summary = (String) info.metaData.get("com.android.settings.summary"); final String actualSummary = - context.getString(resources.getIdentifier(summary.substring(8), "string", pName)); + context.getString(resources.getIdentifier(summary.substring(8), "string", pName)); final String expectedSummary = context.getString(summaryRes); assertThat(actualSummary).isEqualTo(expectedSummary); } diff --git a/tests/robotests/src/com/android/settings/support/NewDeviceIntroSuggestionActivityTest.java b/tests/robotests/src/com/android/settings/support/NewDeviceIntroSuggestionActivityTest.java deleted file mode 100644 index 34f8d8af7b..0000000000 --- a/tests/robotests/src/com/android/settings/support/NewDeviceIntroSuggestionActivityTest.java +++ /dev/null @@ -1,151 +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. - */ - -package com.android.settings.support; - -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.TIPS_PACKAGE_NAME; -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; - -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.content.pm.PackageInfo; -import android.content.pm.ResolveInfo; - -import com.android.settings.R; -import com.android.settings.testutils.FakeFeatureFactory; -import com.android.settings.testutils.SettingsRobolectricTestRunner; - -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.Shadows; -import org.robolectric.shadows.ShadowPackageManager; - -@RunWith(SettingsRobolectricTestRunner.class) -public class NewDeviceIntroSuggestionActivityTest { - - @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private Context mMockContext; - - private Context mContext; - private FakeFeatureFactory mFeatureFactory; - private ShadowPackageManager mShadowPackageManager; - - @Before - public void setUp() { - MockitoAnnotations.initMocks(this); - mContext = RuntimeEnvironment.application; - mShadowPackageManager = Shadows.shadowOf(mContext.getPackageManager()); - - mFeatureFactory = FakeFeatureFactory.setupForTest(); - when(mFeatureFactory.suggestionsFeatureProvider.getSharedPrefs(any(Context.class))) - .thenReturn(getSharedPreferences()); - } - - @Test - public void isSuggestionComplete_TipsNotExistsAndNotExpiredAndCanOpenUrl_shouldReturnFalse() { - mShadowPackageManager.removePackage(TIPS_PACKAGE_NAME); - - when(mMockContext.getResources() - .getBoolean(R.bool.config_new_device_intro_suggestion_supported)) - .thenReturn(true); - - when(mFeatureFactory.supportFeatureProvider.getNewDeviceIntroUrl(any(Context.class))) - .thenReturn("https://com.android.settings"); - final Intent intent = NewDeviceIntroSuggestionActivity.getLaunchIntent(mContext); - mShadowPackageManager.addResolveInfoForIntent(intent, new ResolveInfo()); - - assertThat(isSuggestionComplete(mContext)).isFalse(); - } - - @Test - public void isSuggestionComplete_TipsExistsAndNotExpiredAndCanOpenUrl_shouldReturnTrue() { - final PackageInfo mockInfo = new PackageInfo(); - mockInfo.packageName = TIPS_PACKAGE_NAME; - mShadowPackageManager.addPackage(mockInfo); - - when(mMockContext.getResources() - .getBoolean(R.bool.config_new_device_intro_suggestion_supported)) - .thenReturn(true); - - when(mFeatureFactory.supportFeatureProvider.getNewDeviceIntroUrl(any(Context.class))) - .thenReturn("https://com.android.settings"); - final Intent intent = NewDeviceIntroSuggestionActivity.getLaunchIntent(mContext); - mShadowPackageManager.addResolveInfoForIntent(intent, new ResolveInfo()); - - assertThat(isSuggestionComplete(mContext)).isTrue(); - } - - @Test - public void isSuggestionComplete_notSupported_shouldReturnTrue() { - when(mMockContext.getResources() - .getBoolean(R.bool.config_new_device_intro_suggestion_supported)) - .thenReturn(false); - - assertThat(isSuggestionComplete(mContext)).isTrue(); - } - - @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).commit(); - assertThat(isSuggestionComplete(mContext)).isTrue(); - } - - @Test - public void isSuggestionComplete_noUrl_shouldReturnTrue() { - when(mFeatureFactory.supportFeatureProvider.getNewDeviceIntroUrl(any(Context.class))) - .thenReturn(null); - assertThat(isSuggestionComplete(mContext)).isTrue(); - } - - @Test - public void isSuggestionComplete_alreadyLaunchedBefore_shouldReturnTrue() { - 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(); - } - - @Test - public void isSuggestionComplete_notExpiredAndCanOpenUrlInBrowser_shouldReturnFalse() { - when(mFeatureFactory.supportFeatureProvider.getNewDeviceIntroUrl(any(Context.class))) - .thenReturn("https://com.android.settings"); - - final Intent intent = NewDeviceIntroSuggestionActivity.getLaunchIntent(mContext); - mShadowPackageManager.addResolveInfoForIntent(intent, new ResolveInfo()); - assertThat(isSuggestionComplete(mContext)).isFalse(); - } - - private SharedPreferences getSharedPreferences() { - return mContext.getSharedPreferences("test_new_device_sugg", Context.MODE_PRIVATE); - } -} -- 2.11.0