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 androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import android.text.TextUtils;
import android.text.format.DateUtils;
@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);
}
public static boolean isSuggestionComplete(Context context) {
- return !isSupported(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);
.addCategory(Intent.CATEGORY_BROWSABLE)
.setData(Uri.parse(url));
}
+
+ /**
+ * Check if the specified package exists and is marked with <i>FLAG_SYSTEM</i>
+ */
+ 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;
+ }
+ }
}
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 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;
}
@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))