Bug 1220773 - Do not run our updater if app was installed from Google Play. r=ahunt,esawin

MozReview-Commit-ID: Bz4kErHzhen

--HG--
extra : rebase_source : 292887fa4de4ba604f6b966ef0296857078bba2b
This commit is contained in:
Sebastian Kaspari 2016-07-26 10:36:37 +02:00
Родитель 483b42a995
Коммит 5ff7384025
4 изменённых файлов: 21 добавлений и 6 удалений

Просмотреть файл

@ -748,7 +748,7 @@ public class BrowserApp extends GeckoApp
// The update service is enabled for RELEASE_BUILD, which includes the release and beta channels.
// However, no updates are served. Therefore, we don't trust the update service directly, and
// try to avoid prompting unnecessarily. See Bug 1232798.
if (!AppConstants.RELEASE_BUILD && UpdateServiceHelper.isUpdaterEnabled()) {
if (!AppConstants.RELEASE_BUILD && UpdateServiceHelper.isUpdaterEnabled(this)) {
Permissions.from(this)
.withPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE)
.doNotPrompt()

Просмотреть файл

@ -39,6 +39,7 @@ import org.mozilla.gecko.tabqueue.TabQueueHelper;
import org.mozilla.gecko.tabqueue.TabQueuePrompt;
import org.mozilla.gecko.updater.UpdateService;
import org.mozilla.gecko.updater.UpdateServiceHelper;
import org.mozilla.gecko.util.ContextUtils;
import org.mozilla.gecko.util.EventCallback;
import org.mozilla.gecko.util.GeckoEventListener;
import org.mozilla.gecko.util.HardwareUtils;
@ -708,7 +709,7 @@ OnSharedPreferenceChangeListener
pref.setOnPreferenceChangeListener(this);
if (PREFS_UPDATER_AUTODOWNLOAD.equals(key)) {
if (!AppConstants.MOZ_UPDATER) {
if (!AppConstants.MOZ_UPDATER || ContextUtils.isInstalledFromGooglePlay(this)) {
preferences.removePreference(pref);
i--;
continue;

Просмотреть файл

@ -8,6 +8,7 @@ package org.mozilla.gecko.updater;
import org.mozilla.gecko.annotation.RobocopTarget;
import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.PrefsHelper;
import org.mozilla.gecko.util.ContextUtils;
import org.mozilla.gecko.util.GeckoJarReader;
import android.content.Context;
@ -131,8 +132,8 @@ public class UpdateServiceHelper {
}
}
public static boolean isUpdaterEnabled() {
return AppConstants.MOZ_UPDATER && isEnabled;
public static boolean isUpdaterEnabled(final Context context) {
return AppConstants.MOZ_UPDATER && isEnabled && !ContextUtils.isInstalledFromGooglePlay(context);
}
public static void setUpdateUrl(Context context, String url) {
@ -168,7 +169,7 @@ public class UpdateServiceHelper {
}
public static void registerForUpdates(final Context context) {
if (!isUpdaterEnabled()) {
if (!isUpdaterEnabled(context)) {
return;
}
@ -189,7 +190,7 @@ public class UpdateServiceHelper {
}
public static void registerForUpdates(Context context, UpdateService.AutoDownloadPolicy policy, String url) {
if (!isUpdaterEnabled()) {
if (!isUpdaterEnabled(context)) {
return;
}

Просмотреть файл

@ -9,8 +9,11 @@ package org.mozilla.gecko.util;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.text.TextUtils;
public class ContextUtils {
private static final String INSTALLER_GOOGLE_PLAY = "com.android.vending";
private ContextUtils() {}
/**
@ -25,4 +28,14 @@ public class ContextUtils {
throw new AssertionError("Should not happen: Can't get package info of own package");
}
}
public static boolean isInstalledFromGooglePlay(final Context context) {
final String installerPackageName = context.getPackageManager().getInstallerPackageName(context.getPackageName());
if (TextUtils.isEmpty(installerPackageName)) {
return false;
}
return INSTALLER_GOOGLE_PLAY.equals(installerPackageName);
}
}