Merge "Collapse common package (2/2)" into ub-contactsdialer-i-dev
diff --git a/res/drawable/ic_error_black_24dp.xml b/res/drawable/ic_error_black_24dp.xml
new file mode 100644
index 0000000..5b67ee2
--- /dev/null
+++ b/res/drawable/ic_error_black_24dp.xml
@@ -0,0 +1,25 @@
+<!-- Copyright (C) 2016 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<!-- From https://material.io/icons/#ic_error -->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#FF000000"
+        android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13,17h-2v-2h2v2zM13,13h-2L11,7h2v6z"/>
+</vector>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 13edf1e..9ebcb4c 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1667,7 +1667,7 @@
     <!-- Dialog title when selecting the bulk operation to perform from a list. [CHAR LIMIT=36] -->
     <string name="dialog_export">Export contacts</string>
 
-    <!-- Dialog title when importing contacts from an external source. [CHAR LIMIT=36] -->
+    <!-- Dialog title when importing contacts from an external source such as SIM card or a vcf file. [CHAR LIMIT=36] -->
     <string name="dialog_import">Import contacts from</string>
 
     <!-- Toast indicating that sharing a contact has failed. [CHAR LIMIT=NONE]  -->
@@ -1908,7 +1908,10 @@
     <string name="importing_sim_finished_title">Finished importing SIM card</string>
 
     <!-- Notification title shown when importing SIM contacts failed [CHAR LIMIT=40] -->
-    <string name="importing_sim_failed_title">Couldn\'t import SIM card</string>
+    <string name="importing_sim_failed_title">Import failed</string>
+
+    <!-- Notification message shown when importing SIM contacts failed [CHAR LIMIT=NONE] -->
+    <string name="importing_sim_failed_message">Couldn\'t import contacts from SIM card</string>
 
     <!-- The notification title shown while SIM contacts are being imported [CHAR LIMIT=40] -->
     <string name="importing_sim_in_progress_title">Importing SIM</string>
diff --git a/src/com/android/contacts/SimImportService.java b/src/com/android/contacts/SimImportService.java
index 70e1d43..9e7884f 100644
--- a/src/com/android/contacts/SimImportService.java
+++ b/src/com/android/contacts/SimImportService.java
@@ -203,8 +203,9 @@
         builder.setOngoing(false)
                 .setAutoCancel(true)
                 .setContentTitle(this.getString(R.string.importing_sim_failed_title))
+                .setContentText(this.getString(R.string.importing_sim_failed_message))
                 .setColor(this.getResources().getColor(R.color.dialtacts_theme_color))
-                .setSmallIcon(R.drawable.ic_check_mark)
+                .setSmallIcon(R.drawable.ic_error_black_24dp)
                 .setContentIntent(PendingIntent.getActivity(this, 0, intent, 0));
         return builder.build();
     }
diff --git a/src/com/android/contacts/preference/ContactsPreferences.java b/src/com/android/contacts/preference/ContactsPreferences.java
index 584dff6..48fb205 100644
--- a/src/com/android/contacts/preference/ContactsPreferences.java
+++ b/src/com/android/contacts/preference/ContactsPreferences.java
@@ -16,6 +16,8 @@
 
 package com.android.contacts.preference;
 
+import android.app.backup.BackupAgent;
+import android.app.backup.BackupManager;
 import android.content.Context;
 import android.content.SharedPreferences;
 import android.content.SharedPreferences.Editor;
@@ -79,6 +81,7 @@
     private ChangeListener mListener = null;
     private Handler mHandler;
     private final SharedPreferences mPreferences;
+    private final BackupManager mBackupManager;
     private final boolean mIsDefaultAccountUserChangeable;
     private String mDefaultAccountKey;
 
@@ -92,6 +95,8 @@
         mContext = context;
         mIsDefaultAccountUserChangeable = isDefaultAccountUserChangeable;
 
+        mBackupManager = new BackupManager(mContext);
+
         mHandler = new Handler(Looper.getMainLooper());
         mPreferences = mContext.getSharedPreferences(context.getPackageName(),
                 Context.MODE_PRIVATE);
@@ -127,6 +132,7 @@
         final Editor editor = mPreferences.edit();
         editor.putInt(SORT_ORDER_KEY, sortOrder);
         editor.commit();
+        mBackupManager.dataChanged();
     }
 
     public boolean isDisplayOrderUserChangeable() {
@@ -156,6 +162,7 @@
         final Editor editor = mPreferences.edit();
         editor.putInt(DISPLAY_ORDER_KEY, displayOrder);
         editor.commit();
+        mBackupManager.dataChanged();
     }
 
     public boolean isDefaultAccountUserChangeable() {
diff --git a/src/com/android/contacts/util/SharedPreferenceUtil.java b/src/com/android/contacts/util/SharedPreferenceUtil.java
index ada7a57..1604711 100644
--- a/src/com/android/contacts/util/SharedPreferenceUtil.java
+++ b/src/com/android/contacts/util/SharedPreferenceUtil.java
@@ -16,6 +16,7 @@
 
 package com.android.contacts.util;
 
+import android.app.backup.BackupManager;
 import android.content.Context;
 import android.content.SharedPreferences;
 
@@ -36,13 +37,13 @@
     public static final String PREFERENCE_KEY_GLOBAL_SYNC_OFF_DISMISSES =
             "num-of-dismisses-auto-sync-off";
 
-    private static final String PREFERENCE_KEY_HAMBURGER_PROMO_DISPLAYED =
+    public static final String PREFERENCE_KEY_HAMBURGER_PROMO_DISPLAYED =
             "hamburgerPromoDisplayed";
 
-    private static final String PREFERENCE_KEY_HAMBURGER_MENU_CLICKED =
+    public static final String PREFERENCE_KEY_HAMBURGER_MENU_CLICKED =
             "hamburgerMenuClicked";
 
-    private static final String PREFERENCE_KEY_HAMBURGER_PROMO_TRIGGER_ACTION_HAPPENED =
+    public static final String PREFERENCE_KEY_HAMBURGER_PROMO_TRIGGER_ACTION_HAPPENED =
             "hamburgerPromoTriggerActionHappened";
 
     private static final String PREFERENCE_KEY_IMPORTED_SIM_CARDS =
@@ -69,6 +70,7 @@
         getSharedPreferences(context).edit()
                 .putBoolean(PREFERENCE_KEY_HAMBURGER_PROMO_DISPLAYED, true)
                 .apply();
+        new BackupManager(context).dataChanged();
     }
 
     public static boolean getHamburgerMenuClickedBefore(Context context) {
@@ -80,6 +82,7 @@
         getSharedPreferences(context).edit()
                 .putBoolean(PREFERENCE_KEY_HAMBURGER_MENU_CLICKED, true)
                 .apply();
+        new BackupManager(context).dataChanged();
     }
 
     public static boolean getHamburgerPromoTriggerActionHappenedBefore(Context context) {
@@ -91,6 +94,7 @@
         getSharedPreferences(context).edit()
                 .putBoolean(PREFERENCE_KEY_HAMBURGER_PROMO_TRIGGER_ACTION_HAPPENED, true)
                 .apply();
+        new BackupManager(context).dataChanged();
     }
 
     /**
@@ -109,7 +113,12 @@
     }
 
     protected static SharedPreferences getSharedPreferences(Context context) {
-        return context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
+        return context.getSharedPreferences(getSharedPreferencesFilename(context),
+                Context.MODE_PRIVATE);
+    }
+
+    public static String getSharedPreferencesFilename(Context context) {
+        return context.getPackageName();
     }
 
     public static int getNumOfDismissesForAutoSyncOff(Context context) {
@@ -244,9 +253,11 @@
     public static void setWelcomeCardDismissed(Context context, boolean isDismissed) {
         getSharedPreferences(context).edit().putBoolean(PREFERENCE_WELCOME_CARD_DISMISSED,
                 isDismissed).apply();
+        new BackupManager(context).dataChanged();
     }
 
     public static void clear(Context context) {
         getSharedPreferences(context).edit().clear().commit();
+        new BackupManager(context).dataChanged();
     }
 }