Merge "mac randomization notification fix typo" into qt-qpr1-dev
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 9c416a0..b9f53480 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -5980,16 +5980,6 @@
         public static final String USER_SETUP_COMPLETE = "user_setup_complete";
 
         /**
-         * Whether the Auto Embedded Setup Wizard (0 = false, 1 = true) is in progress.
-         * This differs from USER_SETUP_COMPLETE in that it can be reset back to 0
-         * in case Setup Wizard has been re-enabled on Auto Embedded devices.
-         *
-         * @hide
-         */
-        public static final String AUTOMOTIVE_USER_SETUP_IN_PROGRESS =
-                "automotive_user_setup_in_progress";
-
-        /**
          * Indicates that the user has not started setup personalization.
          * One of the possible states for {@link #USER_SETUP_PERSONALIZATION_STATE}.
          *
diff --git a/core/proto/android/providers/settings/secure.proto b/core/proto/android/providers/settings/secure.proto
index d0be86f..ef413b9 100644
--- a/core/proto/android/providers/settings/secure.proto
+++ b/core/proto/android/providers/settings/secure.proto
@@ -139,13 +139,6 @@
     }
     optional AutomaticStorageManager automatic_storage_manager = 9;
 
-    message Automotive {
-        option (android.msg_privacy).dest = DEST_EXPLICIT;
-
-        optional SettingProto automotive_user_setup_in_progress = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    }
-    optional Automotive automotive = 77;
-
     message Backup {
         option (android.msg_privacy).dest = DEST_EXPLICIT;
 
@@ -573,5 +566,5 @@
 
     // Please insert fields in alphabetical order and group them into messages
     // if possible (to avoid reaching the method limit).
-    // Next tag = 78;
+    // Next tag = 77;
 }
diff --git a/core/tests/coretests/src/android/provider/SettingsBackupTest.java b/core/tests/coretests/src/android/provider/SettingsBackupTest.java
index 029a06e..b7b02a3 100644
--- a/core/tests/coretests/src/android/provider/SettingsBackupTest.java
+++ b/core/tests/coretests/src/android/provider/SettingsBackupTest.java
@@ -703,7 +703,6 @@
                  Settings.Secure.UNSAFE_VOLUME_MUSIC_ACTIVE_MS,
                  Settings.Secure.USB_AUDIO_AUTOMATIC_ROUTING_DISABLED,
                  Settings.Secure.USER_SETUP_COMPLETE,
-                 Settings.Secure.AUTOMOTIVE_USER_SETUP_IN_PROGRESS,
                  Settings.Secure.USER_SETUP_PERSONALIZATION_STATE,
                  Settings.Secure.VOICE_INTERACTION_SERVICE,
                  Settings.Secure.VOICE_RECOGNITION_SERVICE,
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java
index 514d352..894ba9c 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java
@@ -2411,10 +2411,6 @@
                 Settings.Secure.USER_SETUP_COMPLETE,
                 SecureSettingsProto.USER_SETUP_COMPLETE);
 
-        dumpSetting(s, p,
-                Settings.Secure.AUTOMOTIVE_USER_SETUP_IN_PROGRESS,
-                SecureSettingsProto.Automotive.AUTOMOTIVE_USER_SETUP_IN_PROGRESS);
-
         final long voiceToken = p.start(SecureSettingsProto.VOICE);
         dumpSetting(s, p,
                 Settings.Secure.VOICE_INTERACTION_SERVICE,
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
index c900308..fbfbe7f 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
@@ -4449,19 +4449,6 @@
                     currentVersion = 183;
                 }
 
-                if (currentVersion == 183) {
-                    // Version 169: by default, automotive setup wizard is in progress
-                    final SettingsState secureSettings = getSecureSettingsLocked(userId);
-                    Setting currentSetting = secureSettings.getSettingLocked(
-                            Secure.AUTOMOTIVE_USER_SETUP_IN_PROGRESS);
-                    if (currentSetting.isNull()) {
-                        secureSettings.insertSettingLocked(
-                                Secure.AUTOMOTIVE_USER_SETUP_IN_PROGRESS, "1", null, true,
-                                SettingsState.SYSTEM_PACKAGE_NAME);
-                    }
-                    currentVersion = 184;
-                }
-
                 // vXXX: Add new settings above this point.
 
                 if (currentVersion != newVersion) {
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsState.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsState.java
index c05c4cd..33085a1 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsState.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsState.java
@@ -64,6 +64,8 @@
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
@@ -716,6 +718,23 @@
                 }
             } catch (Throwable t) {
                 Slog.wtf(LOG_TAG, "Failed to write settings, restoring backup", t);
+                if (t instanceof IOException) {
+                    // we failed to create a directory, so log the permissions and existence
+                    // state for the settings file and directory
+                    logSettingsDirectoryInformation(destination.getBaseFile());
+                    if (t.getMessage().contains("Couldn't create directory")) {
+                        // attempt to create the directory with Files.createDirectories, which
+                        // throws more informative errors than File.mkdirs.
+                        Path parentPath = destination.getBaseFile().getParentFile().toPath();
+                        try {
+                            Files.createDirectories(parentPath);
+                            Slog.i(LOG_TAG, "Successfully created " + parentPath);
+                        } catch (Throwable t2) {
+                            Slog.e(LOG_TAG, "Failed to write " + parentPath
+                                    + " with Files.writeDirectories", t2);
+                        }
+                    }
+                }
                 destination.failWrite(out);
             } finally {
                 IoUtils.closeQuietly(out);
@@ -729,6 +748,33 @@
         }
     }
 
+    private static void logSettingsDirectoryInformation(File settingsFile) {
+        File parent = settingsFile.getParentFile();
+        Slog.i(LOG_TAG, "directory info for directory/file " + settingsFile
+                + " with stacktrace ", new Exception());
+        File ancestorDir = parent;
+        while (ancestorDir != null) {
+            if (!ancestorDir.exists()) {
+                Slog.i(LOG_TAG, "ancestor directory " + ancestorDir
+                        + " does not exist");
+                ancestorDir = ancestorDir.getParentFile();
+            } else {
+                Slog.i(LOG_TAG, "ancestor directory " + ancestorDir
+                        + " exists");
+                Slog.i(LOG_TAG, "ancestor directory " + ancestorDir
+                        + " permissions: r: " + ancestorDir.canRead() + " w: "
+                        + ancestorDir.canWrite() + " x: " + ancestorDir.canExecute());
+                File ancestorParent = ancestorDir.getParentFile();
+                if (ancestorParent != null) {
+                    Slog.i(LOG_TAG, "ancestor's parent directory " + ancestorParent
+                            + " permissions: r: " + ancestorParent.canRead() + " w: "
+                            + ancestorParent.canWrite() + " x: " + ancestorParent.canExecute());
+                }
+                break;
+            }
+        }
+    }
+
     static void writeSingleSetting(int version, XmlSerializer serializer, String id,
             String name, String value, String defaultValue, String packageName,
             String tag, boolean defaultSysSet) throws IOException {
@@ -803,6 +849,7 @@
             in = new AtomicFile(mStatePersistFile).openRead();
         } catch (FileNotFoundException fnfe) {
             Slog.i(LOG_TAG, "No settings state " + mStatePersistFile);
+            logSettingsDirectoryInformation(mStatePersistFile);
             addHistoricalOperationLocked(HISTORICAL_OPERATION_INITIALIZE, null);
             return;
         }