Bug 1220773 - Do not run our updater if app was installed from Google Play. r=ahunt,esawin
authorSebastian Kaspari <s.kaspari@gmail.com>
Tue, 26 Jul 2016 10:36:37 +0200
changeset 346764 64c473c3414f8f837e5f524f4e484e562d1d405a
parent 346763 db3f18dc78a30fec622e17da661254ba6d0335ae
child 346765 232175372fa0ad56a86a769ae187d8a19abe4c4b
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersahunt, esawin
bugs1220773
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1220773 - Do not run our updater if app was installed from Google Play. r=ahunt,esawin MozReview-Commit-ID: Bz4kErHzhen
mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
mobile/android/base/java/org/mozilla/gecko/preferences/GeckoPreferences.java
mobile/android/base/java/org/mozilla/gecko/updater/UpdateServiceHelper.java
mobile/android/base/java/org/mozilla/gecko/util/ContextUtils.java
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -743,17 +743,17 @@ public class BrowserApp extends GeckoApp
         });
 
         // Set the maximum bits-per-pixel the favicon system cares about.
         IconDirectoryEntry.setMaxBPP(GeckoAppShell.getScreenDepth());
 
         // 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()
                        .andFallback(new Runnable() {
                            @Override
                            public void run() {
                                showUpdaterPermissionSnackbar();
                            }
--- a/mobile/android/base/java/org/mozilla/gecko/preferences/GeckoPreferences.java
+++ b/mobile/android/base/java/org/mozilla/gecko/preferences/GeckoPreferences.java
@@ -34,16 +34,17 @@ import org.mozilla.gecko.feeds.FeedServi
 import org.mozilla.gecko.feeds.action.CheckForUpdatesAction;
 import org.mozilla.gecko.permissions.Permissions;
 import org.mozilla.gecko.restrictions.Restrictable;
 import org.mozilla.gecko.restrictions.Restrictions;
 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;
 import org.mozilla.gecko.util.InputOptionsUtils;
 import org.mozilla.gecko.util.NativeEventListener;
 import org.mozilla.gecko.util.NativeJSObject;
 import org.mozilla.gecko.util.ThreadUtils;
 
@@ -703,17 +704,17 @@ OnSharedPreferenceChangeListener
                         preferences.removePreference(pref);
                         i--;
                         continue;
                     }
                 }
 
                 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;
                     }
                 } else if (PREFS_TRACKING_PROTECTION.equals(key)) {
                     // Remove UI for global TP pref in non-Nightly builds.
                     if (!AppConstants.NIGHTLY_BUILD) {
                         preferences.removePreference(pref);
--- a/mobile/android/base/java/org/mozilla/gecko/updater/UpdateServiceHelper.java
+++ b/mobile/android/base/java/org/mozilla/gecko/updater/UpdateServiceHelper.java
@@ -3,16 +3,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 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;
 import android.content.Intent;
 import android.content.pm.PackageManager;
 import android.content.pm.ApplicationInfo;
 import android.os.Build;
 import android.util.Log;
@@ -126,18 +127,18 @@ public class UpdateServiceHelper {
         try {
             return new URI(url);
         } catch (java.net.URISyntaxException e) {
             Log.e(LOGTAG, "Failed to create update url: ", e);
             return null;
         }
     }
 
-    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) {
         registerForUpdates(context, null, url);
     }
 
     public static void setAutoDownloadPolicy(Context context, UpdateService.AutoDownloadPolicy policy) {
         registerForUpdates(context, policy, null);
@@ -163,17 +164,17 @@ public class UpdateServiceHelper {
         if (context == null) {
             return;
         }
 
         context.startService(createIntent(context, ACTION_APPLY_UPDATE));
     }
 
     public static void registerForUpdates(final Context context) {
-        if (!isUpdaterEnabled()) {
+        if (!isUpdaterEnabled(context)) {
              return;
         }
 
         final HashMap<String, Object> prefs = new HashMap<String, Object>();
 
         PrefsHelper.getPrefs(Pref.names, new PrefsHelper.PrefHandlerBase() {
             @Override public void prefValue(String pref, String value) {
                 prefs.put(pref, value);
@@ -184,17 +185,17 @@ public class UpdateServiceHelper {
                     UpdateService.AutoDownloadPolicy.get(
                         (String) prefs.get(Pref.AUTO_DOWNLOAD_POLICY.toString())),
                       (String) prefs.get(Pref.UPDATE_URL.toString()));
             }
         });
     }
 
     public static void registerForUpdates(Context context, UpdateService.AutoDownloadPolicy policy, String url) {
-        if (!isUpdaterEnabled()) {
+        if (!isUpdaterEnabled(context)) {
              return;
         }
 
         Intent intent = createIntent(context, ACTION_REGISTER_FOR_UPDATES);
 
         if (policy != null) {
             intent.putExtra(EXTRA_AUTODOWNLOAD_NAME, policy.value);
         }
--- a/mobile/android/base/java/org/mozilla/gecko/util/ContextUtils.java
+++ b/mobile/android/base/java/org/mozilla/gecko/util/ContextUtils.java
@@ -4,25 +4,38 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
 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() {}
 
     /**
      * @return {@link android.content.pm.PackageInfo#firstInstallTime} for the context's package.
      * @throws PackageManager.NameNotFoundException Unexpected - we get the package name from the context so
      *         it's expected to be found.
      */
     public static PackageInfo getCurrentPackageInfo(final Context context) {
         try {
             return context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
         } catch (PackageManager.NameNotFoundException e) {
             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);
+    }
 }