Remove old accounts tile, replaced by a separate screen

Bug: 15815948
Bug: 15819268
Change-Id: I3b6978cff346c73cca1d6a2c209ffe4c71808244
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index 4675bb2..e2aeaf2 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -16,9 +16,6 @@
 
 package com.android.settings;
 
-import android.accounts.Account;
-import android.accounts.AccountManager;
-import android.accounts.OnAccountsUpdateListener;
 import android.app.ActionBar;
 import android.app.Activity;
 import android.app.Fragment;
@@ -70,8 +67,6 @@
 import com.android.settings.accessibility.AccessibilitySettings;
 import com.android.settings.accessibility.CaptionPropertiesFragment;
 import com.android.settings.accounts.AccountSyncSettings;
-import com.android.settings.accounts.AuthenticatorHelper;
-import com.android.settings.accounts.ManageAccountsSettings;
 import com.android.settings.applications.InstalledAppDetails;
 import com.android.settings.applications.ManageApplications;
 import com.android.settings.applications.ProcessStatsUi;
@@ -117,8 +112,6 @@
 
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
 import java.util.List;
 import java.util.Set;
 
@@ -127,10 +120,9 @@
 public class SettingsActivity extends Activity
         implements PreferenceManager.OnPreferenceTreeClickListener,
         PreferenceFragment.OnPreferenceStartFragmentCallback,
-        ButtonBarHandler, OnAccountsUpdateListener, FragmentManager.OnBackStackChangedListener,
+        ButtonBarHandler, FragmentManager.OnBackStackChangedListener,
         SearchView.OnQueryTextListener, SearchView.OnCloseListener,
-        MenuItem.OnActionExpandListener,
-        AuthenticatorHelper.OnAccountsUpdateListener {
+        MenuItem.OnActionExpandListener {
 
     private static final String LOG_TAG = "Settings";
 
@@ -221,7 +213,6 @@
             R.id.language_settings,
             R.id.user_settings,
             R.id.account_settings,
-            R.id.account_add,
             R.id.system_section,
             R.id.date_time_settings,
             R.id.about_settings,
@@ -275,7 +266,6 @@
             UserSettings.class.getName(),
             NotificationAccessSettings.class.getName(),
             ConditionProviderSettings.class.getName(),
-            ManageAccountsSettings.class.getName(),
             PrintSettingsFragment.class.getName(),
             PrintJobSettingsFragment.class.getName(),
             TrustedCredentialsSettings.class.getName(),
@@ -297,9 +287,6 @@
     private SharedPreferences mDevelopmentPreferences;
     private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
 
-    private AuthenticatorHelper mAuthenticatorHelper;
-    private boolean mListeningToAccountUpdates;
-
     private boolean mBatteryPresent = true;
     private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
 
@@ -363,10 +350,6 @@
         return mSwitchBar;
     }
 
-    public AuthenticatorHelper getAuthenticatorHelper() {
-        return mAuthenticatorHelper;
-    }
-
     public List<DashboardCategory> getDashboardCategories() {
         if (mNeedToRebuildCategories || mCategories.size() == 0) {
             buildDashboardCategories(mCategories);
@@ -482,13 +465,6 @@
         if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
             getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
         }
-        // TODO: Delete accounts tile once we have the new screen working
-        // See: http://b/15815948
-        final UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
-        mAuthenticatorHelper = new AuthenticatorHelper(
-                this, UserHandle.getCallingUserHandle(), um, this);
-        mAuthenticatorHelper.updateAuthDescriptions(this);
-        mAuthenticatorHelper.onAccountsUpdated(null);
 
         mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
                 Context.MODE_PRIVATE);
@@ -743,10 +719,6 @@
         mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
                 mDevelopmentPreferencesListener);
         mDevelopmentPreferencesListener = null;
-
-        if (mListeningToAccountUpdates) {
-            AccountManager.get(this).removeOnAccountsUpdatedListener(this);
-        }
     }
 
     protected boolean isValidFragment(String fragmentName) {
@@ -1071,10 +1043,6 @@
 
             // Ids are integers, so downcasting is ok
             int id = (int) category.id;
-            if (id == R.id.account_settings) {
-                insertAccountsTiles(category);
-                continue;
-            }
             int n = category.getTilesCount() - 1;
             while (n >= 0) {
 
@@ -1146,10 +1114,6 @@
                             UserManager.DISALLOW_DEBUGGING_FEATURES)) {
                         category.removeTile(n);
                     }
-                } else if (id == R.id.account_add) {
-                    if (um.hasUserRestriction(UserManager.DISALLOW_MODIFY_ACCOUNTS)) {
-                        category.removeTile(n);
-                    }
                 }
 
                 if (UserHandle.MU_ENABLED && UserHandle.myUserId() != 0
@@ -1201,62 +1165,6 @@
         return true;
     }
 
-    private void insertAccountsTiles(DashboardCategory target) {
-        String[] accountTypes = mAuthenticatorHelper.getEnabledAccountTypes();
-        List<DashboardTile> dashboardTiles = new ArrayList<DashboardTile>(accountTypes.length);
-        for (String accountType : accountTypes) {
-            CharSequence label = mAuthenticatorHelper.getLabelForType(this, accountType);
-            if (label == null) {
-                continue;
-            }
-
-            Account[] accounts = AccountManager.get(this).getAccountsByType(accountType);
-            boolean skipToAccount = accounts.length == 1
-                    && !mAuthenticatorHelper.hasAccountPreferences(accountType);
-            DashboardTile accountTile = new DashboardTile();
-            accountTile.title = label;
-            if (accountTile.extras == null) {
-                accountTile.extras = new Bundle();
-            }
-            if (skipToAccount) {
-                accountTile.fragment = AccountSyncSettings.class.getName();
-                accountTile.fragmentArguments = new Bundle();
-                // Need this for the icon
-                accountTile.extras.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE, accountType);
-                accountTile.extras.putParcelable(AccountSyncSettings.ACCOUNT_KEY, accounts[0]);
-                accountTile.fragmentArguments.putParcelable(AccountSyncSettings.ACCOUNT_KEY,
-                        accounts[0]);
-            } else {
-                accountTile.fragment = ManageAccountsSettings.class.getName();
-                accountTile.fragmentArguments = new Bundle();
-                accountTile.extras.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE, accountType);
-                accountTile.fragmentArguments.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE,
-                        accountType);
-                accountTile.fragmentArguments.putString(ManageAccountsSettings.KEY_ACCOUNT_LABEL,
-                        label.toString());
-            }
-            dashboardTiles.add(accountTile);
-            mAuthenticatorHelper.preloadDrawableForType(this, accountType);
-        }
-
-        // Sort by label
-        Collections.sort(dashboardTiles, new Comparator<DashboardTile>() {
-            @Override
-            public int compare(DashboardTile t1, DashboardTile t2) {
-                return t1.title.toString().compareTo(t2.title.toString());
-            }
-        });
-        int index = 0;
-        for (DashboardTile tile : dashboardTiles) {
-            target.addTile(index, tile);
-            index++;
-        }
-        if (!mListeningToAccountUpdates) {
-            AccountManager.get(this).addOnAccountsUpdatedListener(this, null, true);
-            mListeningToAccountUpdates = true;
-        }
-    }
-
     private void getMetaData() {
         try {
             ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
@@ -1283,18 +1191,6 @@
         return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
     }
 
-    @Override
-    public void onAccountsUpdated(Account[] accounts) {
-        // TODO: watch for package upgrades to invalidate cache; see 7206643
-        mAuthenticatorHelper.updateAuthDescriptions(this);
-        invalidateCategories();
-    }
-
-    @Override
-    public void onAccountsUpdate(UserHandle userHandle) {
-        invalidateCategories();
-    }
-
     public static void requestHomeNotice() {
         sShowNoHomeNotice = true;
     }
diff --git a/src/com/android/settings/accounts/AuthenticatorHelper.java b/src/com/android/settings/accounts/AuthenticatorHelper.java
index e74c8d5..7ea2f12 100644
--- a/src/com/android/settings/accounts/AuthenticatorHelper.java
+++ b/src/com/android/settings/accounts/AuthenticatorHelper.java
@@ -171,9 +171,7 @@
         return false;
     }
 
-    public void onAccountsUpdated(Account[] accounts) {
-        // TODO: Revert to non-public once no longer needed in SettingsActivity
-        // See http://b/15819268
+    void onAccountsUpdated(Account[] accounts) {
         updateAuthDescriptions(mContext);
         if (accounts == null) {
             accounts = AccountManager.get(mContext).getAccountsAsUser(mUserHandle.getIdentifier());
@@ -193,6 +191,7 @@
 
     @Override
     public void onReceive(final Context context, final Intent intent) {
+        // TODO: watch for package upgrades to invalidate cache; see http://b/7206643
         final Account[] accounts = AccountManager.get(mContext)
                 .getAccountsAsUser(mUserHandle.getIdentifier());
         onAccountsUpdated(accounts);
diff --git a/src/com/android/settings/dashboard/DashboardSummary.java b/src/com/android/settings/dashboard/DashboardSummary.java
index ece32f6..ed89d89 100644
--- a/src/com/android/settings/dashboard/DashboardSummary.java
+++ b/src/com/android/settings/dashboard/DashboardSummary.java
@@ -16,13 +16,9 @@
 
 package com.android.settings.dashboard;
 
-import android.accounts.Account;
-import android.accounts.AccountManager;
-import android.accounts.OnAccountsUpdateListener;
 import android.app.Fragment;
 import android.content.Context;
 import android.content.res.Resources;
-import android.graphics.drawable.Drawable;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.Message;
@@ -35,18 +31,14 @@
 import android.widget.TextView;
 import com.android.settings.R;
 import com.android.settings.SettingsActivity;
-import com.android.settings.accounts.AuthenticatorHelper;
-import com.android.settings.accounts.ManageAccountsSettings;
 
 import java.util.List;
 
-public class DashboardSummary extends Fragment implements OnAccountsUpdateListener {
+public class DashboardSummary extends Fragment {
     private static final String LOG_TAG = "DashboardSummary";
 
     private LayoutInflater mLayoutInflater;
     private ViewGroup mDashboard;
-    private AuthenticatorHelper mAuthHelper;
-    private boolean mAccountListenerAdded;
 
     private static final int MSG_REBUILD_UI = 1;
     private Handler mHandler = new Handler() {
@@ -72,8 +64,6 @@
         final View rootView = inflater.inflate(R.layout.dashboard, container, false);
         mDashboard = (ViewGroup) rootView.findViewById(R.id.dashboard_container);
 
-        mAuthHelper = ((SettingsActivity) context).getAuthenticatorHelper();
-
         return rootView;
     }
 
@@ -129,45 +119,19 @@
     public void onResume() {
         super.onResume();
 
-        if (!mAccountListenerAdded) {
-            AccountManager.get(getActivity()).addOnAccountsUpdatedListener(this, null, false);
-            mAccountListenerAdded = true;
-        }
-
         sendRebuildUI();
     }
 
-    @Override
-    public void onDestroy() {
-        super.onDestroy();
-
-        if (mAccountListenerAdded) {
-            AccountManager.get(getActivity()).removeOnAccountsUpdatedListener(this);
-            mAccountListenerAdded = false;
-        }
-    }
-
     private void updateTileView(Context context, Resources res, DashboardTile tile,
             ImageView tileIcon, TextView tileTextView, TextView statusTextView) {
 
-        if (tile.extras != null
-                && tile.extras.containsKey(ManageAccountsSettings.KEY_ACCOUNT_TYPE)) {
-            String accType = tile.extras.getString(ManageAccountsSettings.KEY_ACCOUNT_TYPE);
-            Drawable drawable = mAuthHelper.getDrawableForType(context, accType);
-            tileIcon.setImageDrawable(drawable);
+        if (tile.iconRes > 0) {
+            tileIcon.setImageResource(tile.iconRes);
         } else {
-            if (tile.iconRes > 0) {
-                tileIcon.setImageResource(tile.iconRes);
-            } else {
-                tileIcon.setImageDrawable(null);
-            }
+            tileIcon.setImageDrawable(null);
+            tileIcon.setBackground(null);
         }
-        if (tileIcon != null) {
-            if (tile.iconRes > 0) {
-            } else {
-                tileIcon.setBackground(null);
-            }
-        }
+
         tileTextView.setText(tile.getTitle(res));
 
         CharSequence summary = tile.getSummary(res);
@@ -184,11 +148,4 @@
             mHandler.sendEmptyMessage(MSG_REBUILD_UI);
         }
     }
-
-    @Override
-    public void onAccountsUpdated(Account[] accounts) {
-        final SettingsActivity sa = (SettingsActivity) getActivity();
-        sa.setNeedToRebuildCategories(true);
-        sendRebuildUI();
-    }
 }