From c5b23e1e7198c980126894f9d31955f61fe92dae Mon Sep 17 00:00:00 2001 From: Andy Stadler Date: Mon, 7 Mar 2011 17:05:00 -0800 Subject: [PATCH] DO NOT MERGE: Harden Device.getDeviceId() * If we read a null deviceName, delete the file and create a new one. Bug: 3506362 Backport of Ida670db2f4b75cb9c94636a0af541ae5df50addf Change-Id: If844fe2a2f3d7096a8b18e826a3640a7d9dff830 --- emailcommon/src/com/android/emailcommon/Device.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/emailcommon/src/com/android/emailcommon/Device.java b/emailcommon/src/com/android/emailcommon/Device.java index a93a17a2e..8cd7d561b 100644 --- a/emailcommon/src/com/android/emailcommon/Device.java +++ b/emailcommon/src/com/android/emailcommon/Device.java @@ -59,9 +59,14 @@ public class Device { rdr = new BufferedReader(new FileReader(f), 128); id = rdr.readLine(); rdr.close(); - // STOPSHIP Remove logging - Log.w(Logging.LOG_TAG, "deviceId read as: " + id); - return id; + if (id == null) { + // It's very bad if we read a null device id; let's delete that file + if (!f.delete()) { + Log.e(Logging.LOG_TAG, "Can't delete null deviceName file; try overwrite."); + } + } else { + return id; + } } else { Log.w(Logging.LOG_TAG, f.getAbsolutePath() + ": File exists, but can't read?" + " Trying to remove.");