Bug 1220904 - Message that Old Sync accounts are deprecated and going away. r=nalexander, l10n=flod, a=sylvestre
authorvivek <vivekb.balakrishnan@gmail.com>
Fri, 20 Nov 2015 21:58:38 +0200
changeset 310577 3c125ce5d3b1ec5367d9f788f6096b085a04a72a
parent 310576 c3e2b78a0fe3e4f7da9802b120c2cdc92a2668ff
child 310578 5a51913d7daf21404fcc4aef65424fd95c77d0b8
push id5513
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 13:55:34 +0000
treeherdermozilla-beta@5ee97dd05b5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnalexander, sylvestre
bugs1220904
milestone45.0a2
Bug 1220904 - Message that Old Sync accounts are deprecated and going away. r=nalexander, l10n=flod, a=sylvestre
mobile/android/base/locales/en-US/sync_strings.dtd
mobile/android/services/src/main/java/org/mozilla/gecko/sync/SyncConstants.java
mobile/android/services/src/main/java/org/mozilla/gecko/sync/receivers/SyncAccountDeletedService.java
mobile/android/services/src/main/java/org/mozilla/gecko/sync/receivers/UpgradeReceiver.java
mobile/android/services/strings.xml.in
--- a/mobile/android/base/locales/en-US/sync_strings.dtd
+++ b/mobile/android/base/locales/en-US/sync_strings.dtd
@@ -265,8 +265,13 @@
 <!-- Localization note: the format string below will be replaced
      with the Firefox Account's email address. -->
 <!ENTITY fxaccount_sync_sign_in_error_notification_text2 'Tap to sign in as &formatS;'>
 
 <!ENTITY fxaccount_sync_finish_migrating_notification_title 'Finish upgrading &syncBrand.shortName.label;?'>
 <!-- Localization note: the format string below will be replaced
      with the Firefox Account's email address. -->
 <!ENTITY fxaccount_sync_finish_migrating_notification_text 'Tap to sign in as &formatS;'>
+
+<!-- Localization note: the following strings are used in a
+     notification and should be kept as short as possible. -->
+<!ENTITY old_sync_deprecated_notification_title 'Sign in to continue syncing'>
+<!ENTITY old_sync_deprecated_notification_content 'Your account is no longer supported'>
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/sync/SyncConstants.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/sync/SyncConstants.java
@@ -49,9 +49,11 @@ public class SyncConstants {
    * Account type.
    */
   public static final String PER_ACCOUNT_TYPE_PERMISSION = AppConstants.MOZ_ANDROID_SHARED_ACCOUNT_TYPE + ".permission.PER_ACCOUNT_TYPE";
 
   public static final String DEFAULT_AUTH_SERVER = "https://auth.services.mozilla.com/";
 
   // Used for BackoffHandler storage for Sync 1.1's SyncAdapter.
   public static final String BACKOFF_PREF_SUFFIX_11 = "sync";
+
+  public static final String SYNC_ACCOUNT_DEPRECATED_ACTION = AppConstants.MOZ_ANDROID_SHARED_ACCOUNT_TYPE + ".accounts.SYNC_ACCOUNT_DEPRECATED_ACTION";
 }
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/sync/receivers/SyncAccountDeletedService.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/sync/receivers/SyncAccountDeletedService.java
@@ -1,28 +1,33 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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.sync.receivers;
 
+import org.mozilla.gecko.fxa.FirefoxAccounts;
+import org.mozilla.gecko.fxa.FxAccountConstants;
+import org.mozilla.gecko.fxa.activities.FxAccountWebFlowActivity;
 import org.mozilla.gecko.sync.ExtendedJSONObject;
 import org.mozilla.gecko.background.common.GlobalConstants;
 import org.mozilla.gecko.background.common.log.Logger;
 import org.mozilla.gecko.sync.Sync11Configuration;
 import org.mozilla.gecko.sync.SyncConstants;
 import org.mozilla.gecko.sync.SyncConfiguration;
 import org.mozilla.gecko.sync.Utils;
 import org.mozilla.gecko.sync.config.AccountPickler;
 import org.mozilla.gecko.sync.config.ClientRecordTerminator;
 import org.mozilla.gecko.sync.net.BasicAuthHeaderProvider;
 import org.mozilla.gecko.sync.repositories.android.FennecTabsRepository;
 import org.mozilla.gecko.sync.setup.Constants;
+import org.mozilla.gecko.sync.setup.SyncAccounts;
 import org.mozilla.gecko.sync.setup.SyncAccounts.SyncAccountParameters;
 
+import android.accounts.Account;
 import android.accounts.AccountManager;
 import android.app.IntentService;
 import android.content.Context;
 import android.content.Intent;
 import android.content.SharedPreferences;
 
 public class SyncAccountDeletedService extends IntentService {
   public static final String LOG_TAG = "SyncAccountDeletedService";
@@ -36,16 +41,37 @@ public class SyncAccountDeletedService e
     // Intent can, in theory, be null. Bug 1025937.
     if (intent == null) {
       Logger.debug(LOG_TAG, "Short-circuiting on null intent.");
       return;
     }
 
     final Context context = this;
 
+    if (SyncConstants.SYNC_ACCOUNT_DEPRECATED_ACTION.equals(intent.getAction())) {
+      // Delete Old Sync account.
+      final Account[] accounts = SyncAccounts.syncAccounts(this);
+      for (Account account : accounts) {
+        AccountManager.get(this).removeAccount(account, null, null);
+      }
+
+      // Offer signin for Firefox Account if we don't already have one.
+      if (!FirefoxAccounts.firefoxAccountsExist(this)) {
+        final Intent fxAccountWebIntent = new Intent(FxAccountConstants.ACTION_FXA_GET_STARTED);
+        fxAccountWebIntent.putExtra(FxAccountWebFlowActivity.EXTRA_ENDPOINT, FxAccountConstants.ENDPOINT_PREFERENCES);
+        fxAccountWebIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        fxAccountWebIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
+        context.startActivity(fxAccountWebIntent);
+      }
+
+      // Return early. The SYNC_ACCOUNT_DELETED_ACTION spawn by the account
+      // deletion above will remove the pickle file.
+      return;
+    }
+
     long intentVersion = intent.getLongExtra(Constants.JSON_KEY_VERSION, 0);
     long expectedVersion = SyncConstants.SYNC_ACCOUNT_DELETED_INTENT_VERSION;
     if (intentVersion != expectedVersion) {
       Logger.warn(LOG_TAG, "Intent malformed: version " + intentVersion + " given but version " + expectedVersion + "expected. " +
           "Not cleaning up after deleted Account.");
       return;
     }
 
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/sync/receivers/UpgradeReceiver.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/sync/receivers/UpgradeReceiver.java
@@ -1,44 +1,57 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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.sync.receivers;
 
+import org.mozilla.gecko.R;
 import org.mozilla.gecko.background.common.GlobalConstants;
 import org.mozilla.gecko.background.common.log.Logger;
 import org.mozilla.gecko.sync.CredentialException;
 import org.mozilla.gecko.sync.SyncConfiguration;
+import org.mozilla.gecko.sync.SyncConstants;
 import org.mozilla.gecko.sync.ThreadPool;
 import org.mozilla.gecko.sync.Utils;
 import org.mozilla.gecko.sync.config.ConfigurationMigrator;
 import org.mozilla.gecko.sync.setup.Constants;
 import org.mozilla.gecko.sync.setup.SyncAccounts;
 import org.mozilla.gecko.sync.setup.SyncAccounts.SyncAccountParameters;
 
 import android.accounts.Account;
 import android.accounts.AccountManager;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
+import android.support.v4.app.NotificationCompat.Builder;
 
 public class UpgradeReceiver extends BroadcastReceiver {
   private static final String LOG_TAG = "UpgradeReceiver";
 
   @Override
   public void onReceive(final Context context, Intent intent) {
     Logger.debug(LOG_TAG, "Broadcast received.");
 
     // This unpickles any pickled accounts.
     if (!SyncAccounts.syncAccountsExist(context)) {
       Logger.info(LOG_TAG, "No Sync Accounts found; not upgrading anything.");
       return;
     }
 
+    // Show account not supported notification.
+    ThreadPool.run(new Runnable() {
+      @Override
+      public void run() {
+        notifyAccountDeprecation(context);
+      }
+    });
+
     // Should filter for specific MY_PACKAGE_REPLACED intent, but Android does
     // not expose it.
     ThreadPool.run(new Runnable() {
       @Override
       public void run() {
         final AccountManager accountManager = AccountManager.get(context);
         final Account[] accounts = SyncAccounts.syncAccounts(context);
 
@@ -89,9 +102,29 @@ public class UpgradeReceiver extends Bro
           } catch (Exception e) {
             Logger.warn(LOG_TAG, "Caught exception trying to migrate preferences; ignoring.", e);
             continue;
           }
         }
       }
     });
   }
+
+  /**
+   * Show a persistent notification telling the user that their Old Sync account is deprecated.
+   */
+  private void notifyAccountDeprecation(final Context context) {
+    final Intent notificationIntent = new Intent(SyncConstants.SYNC_ACCOUNT_DEPRECATED_ACTION);
+    notificationIntent.setClass(context, SyncAccountDeletedService.class);
+    final PendingIntent pendingIntent = PendingIntent.getService(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
+    final Builder builder = new Builder(context)
+        .setSmallIcon(R.drawable.ic_status_logo)
+        .setContentTitle(context.getString(R.string.old_sync_deprecated_notification_title))
+        .setContentText(context.getString(R.string.old_sync_deprecated_notification_content))
+        .setAutoCancel(true)
+        .setOngoing(true)
+        .setContentIntent(pendingIntent);
+
+    final NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
+    final int notificationID = SyncConstants.SYNC_ACCOUNT_DEPRECATED_ACTION.hashCode();
+    notificationManager.notify(notificationID, builder.build());
+  }
 }
--- a/mobile/android/services/strings.xml.in
+++ b/mobile/android/services/strings.xml.in
@@ -237,8 +237,12 @@
 <string name="fxaccount_remove_account_dialog_message">&fxaccount_remove_account_dialog_message;</string>
 <string name="fxaccount_remove_account_toast">&fxaccount_remove_account_toast;</string>
 
 <string name="fxaccount_sync_finish_migrating_notification_title">&fxaccount_sync_finish_migrating_notification_title;</string>
 <string name="fxaccount_sync_finish_migrating_notification_text">&fxaccount_sync_finish_migrating_notification_text;</string>
 
 <!-- Log Personal information -->
 <string name="fxaccount_enable_debug_mode">&fxaccount_enable_debug_mode;</string>
+
+<!-- Old Sync Account deprecated notification. -->
+<string name="old_sync_deprecated_notification_title">&old_sync_deprecated_notification_title;</string>
+<string name="old_sync_deprecated_notification_content">&old_sync_deprecated_notification_content;</string>