android-components icon indicating copy to clipboard operation
android-components copied to clipboard

Addon data lost upon migration

Open agi90 opened this issue 6 years ago • 9 comments

STR:

install ublock on fennec add more custom lists in "Filter lists" under settings install fenix notice custom lists selected above are gone now

looks like this is due to us deleting prefs.js during migration, which the extension code uses to determine the internal UUID for the extension. This UUID is used to key all data in the indexdb database, so without the prefs.js file we lose all data.

┆Issue is synchronized with this Jira Task

agi90 avatar Apr 23 '20 16:04 agi90

Looks like this data is stored in extensions.webextensions.uuids:

user_pref("extensions.webextensions.uuids", "{\"[email protected]\":\"27d62a2a-a535-4043-a80e-e9f685538fb9\",\"[email protected]\":\"2fb8df56-dfbc-40c8-a9ad-0cdd0f7c4753\",\"[email protected]\":\"acf1622d-0552-4bdd-8c10-fb26169b6e84\",\"mozacBrowserIcons\":\"bfb022c8-f3c2-40cf-8110-5b974de0ceb5\",\"mozacWebchannel\":\"ebe6e621-16b8-49ec-b4b8-fb8dbb1c7469\",\"mozacReaderview\":\"a648ad8c-e779-4b27-98c4-bbc0207ff819\"}");

agi90 avatar Apr 23 '20 16:04 agi90

We're deleting prefs.js as part of the GeckoMigration step: https://github.com/mozilla-mobile/android-components/blob/master/components/support/migration/src/main/java/mozilla/components/support/migration/GeckoMigration.kt#L28

csadilek avatar Apr 23 '20 16:04 csadilek

All of the extensions stuff i have in prefs.js:

user_pref("extensions.activeThemeID", "[email protected]");
user_pref("extensions.blocklist.pingCountVersion", 0);
user_pref("extensions.databaseSchema", 32);
user_pref("extensions.getAddons.databaseSchema", 6);
user_pref("extensions.incognito.migrated", true);
user_pref("extensions.lastAppBuildId", "20200421231527");
user_pref("extensions.lastAppVersion", "76.0");
user_pref("extensions.lastPlatformVersion", "76.0");
user_pref("extensions.systemAddonSet", "{\"schema\":1,\"addons\":{}}");
user_pref("extensions.webcompat.perform_injections", true);
user_pref("extensions.webcompat.perform_ua_overrides", true);
user_pref("extensions.webextensions.uuids", "{\"[email protected]\":\"343a953c-5af3-4397-a044-7ab95dabb80a\",\"mozacBrowserIcons\":\"08eec704-5cda-4051-9351-066deb4b5ef9\",\"[email protected]\":\"3c1c2807-43e2-49d9-b8c1-3201822dc6e1\",\"mozacWebchannel\":\"7dfed7b5-be3f-4415-892d-d26e6b1981a5\",\"mozacReaderview\":\"6afb207d-6093-466b-8f73-551bd4834e31\"}");

grigoryk avatar Apr 23 '20 20:04 grigoryk

@rpl pointed me to this prefs.js parser in the tree we could potentially re-use to limit the risk of getting parsing wrong: https://searchfox.org/mozilla-central/source/modules/libpref/parser

csadilek avatar Apr 27 '20 14:04 csadilek

@rpl also mentioned we should keep extensions.databaseSchema and it's being used when migrating the AddonManager db.

csadilek avatar Apr 27 '20 15:04 csadilek

as agreed with @csadilek and @agi90, follows a couple of other ideas about how to be able to preserve some of the prefs set in Fennec while migrating an existing profile to Fenix, without having to write a new parser for the prefs.js file from scratch.

Migrate the prefs we want to preserve in a new Fennec dot release

As an "intermediate migration step":

  • a new Fennec dot release could read the values set on the preferences that we would need to preserve and then save those "pref names and related values" into a new plain JSON file created in the profile directory

then GeckoView, on his first startup on that profile migrating from Fennec, could restore the prefs by doing something like:

  • read the JSON file created from the Fennec "intermediate migration step" from the profile
  • and restore the pref value previously set for those preferences

Rename pref.js to old_fennec_pref.js from the android-components side + use "Cu.Sandbox, Cu.exportFunction and loadSubScript" to load them back from the GeckoView side

With this alternative approach there would not be any need for an intermediate Fennec dot release, and so it may be also a bit easier to have it QA verified on Nightly and Beta:

  • the migration code provided by the android-components would just rename the pref.js file (instead of just removing it as it is currently doing), e.g. into old_fennec_prefs.js, so that we are sure that GeckoView will not be loading automatically any of the old preferences
  • then on its first startup GeckoView would check if a migration is still needed (e.g. by checking a new pref :-P), and if needed it would:
    • create a sandbox
    • export in the sanbox a function named user_pref which will be ignore the prefs that we don't want to restore and set the one that we want to preserve
    • load the content of the old_fennec_prefs.js file from the profile and execute it into the sandbox where the custom user_pref function has been defined

I haven't tried it locally, but this strategy should look more or less as the following snippet (minus any typo and mistake that I may have done in the following snippet by writing it without actually trying it :-P):

if (!Services.prefs.getBoolPref("geckoview.didMigratePrefs", false)) {
  const profileDir = Services.dirsvc.get("ProfD", Ci.nsIFile);
  const oldPrefsPath = OS.Path.join(profileDir.path, "old_fennec_prefs.js");
  const oldPrefsExists = await OS.File.exists(oldPrefsPath);
  
  if (!oldPrefsExists) {
    break;
  }
  
  const PREFS_TO_PRESERVE = [
    "extensions.databaseSchema",
    "extensions.webextensions.uuid",
    ...
  ];
   
  const collectUserPrefFn = (prefName, prefValue) => {
    if (PREFS_TO_PRESERVE.includes(prefName) {
      // ... call the right Services.prefs.set*Value method
      // based on the type of prefValue (or based on the expected
      // type for the prefs we want to preserve.
    }
  };
  
  const nullPrincipal = Services.scriptSecurityManager.createNullPrincipal({});
  const sandbox = new Cu.Sandbox(nullPrincipal, { sandboxPrototype: undefined });
  
  let oldPrefsRaw = await OS.File.read(oldPrefsPath, { encoding: "utf-8" });
  Cu.exportFunction(collectUserPrefFn, prefsSandbox, { defineAs: "user_pref" });
  
  try {
    Services.scriptloader.loadSubScript(
      "data:application/javascript;charset=utf-8," + oldPrefsRaw,
      sandbox
    );
  } catch (err) {
    // Unexpected error while parsing or loading the old prefs in the sandbox.
  }
}

These two approaches are not what I would call "elegant" (or "pretty"), but they may worth to keep them into account in case we don't have better options.

rpl avatar Apr 27 '20 17:04 rpl

I would vote for the second approach. The first one is a no-go for me, because users can easily skip that dot release when the Fenix-based Firefox is released before they upgraded their Fennec browser.

Rob--W avatar Apr 27 '20 17:04 Rob--W

As I also mentioned over slack, another set of prefs that we may preserve are the extensions.webextensions.ExtensionStorageIDB.migrated.<EXT_ID> ones, which are set for the extensions that have been already migrated from the storage.local JSON-based backend to the one that is based on a IndexedDB database.

(To be totally fair, it shouldn't make a big difference if they are not preserved because, if the "extension id -> extension uuid" mapping is preserved, the migration code will notice that an indexeddb database is already been created for the extension and it is not empty and the pref would be set again to true without trying to migrate the data again).

rpl avatar Apr 27 '20 18:04 rpl

I had tested this issue on Nightly Migration build 200501 with Motorola Moto G6 (Android 8) and I could reproduce it. The pages added to uBlock Origin Options -> Filter lists -> Custom -> Import -> Apply changes, are not imported after migration.

Verified as fixed on the latest Nightly Migration build 200511 with Motorola Moto G6 (Android 8). The pages added to the Custom list are imported after migration.

I had filed the following related issue: https://github.com/mozilla-mobile/android-components/issues/6933.

ebalazs-sv avatar May 11 '20 10:05 ebalazs-sv