summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHelena Josol <helenajosol@google.com>2014-10-06 16:06:46 +0100
committerDanesh M <daneshm90@gmail.com>2015-09-27 14:59:01 -0700
commita8f7b6a9f33fcedd6f1e429606e1241d7ed7e54b (patch)
tree3c68a489fe263eb2f70833b6dbb0be5f44c73cbb
parent0e6e432422c5c685f8878086c2c5b891cd44cf4f (diff)
downloadandroid_packages_apps_Trebuchet-a8f7b6a9f33fcedd6f1e429606e1241d7ed7e54b.tar.gz
android_packages_apps_Trebuchet-a8f7b6a9f33fcedd6f1e429606e1241d7ed7e54b.tar.bz2
android_packages_apps_Trebuchet-a8f7b6a9f33fcedd6f1e429606e1241d7ed7e54b.zip
Create a central list of files the Launcher writes to the app directory
Replace hardcoded Launcher filenames with the defined constants. Bug: 12753154 Change-Id: I072f202d9388a703b9e6851bde64ea7fafe4b10a
-rw-r--r--WallpaperPicker/src/com/android/launcher3/SavedWallpaperImages.java9
-rw-r--r--src/com/android/launcher3/Launcher.java8
-rw-r--r--src/com/android/launcher3/LauncherFiles.java27
-rw-r--r--src/com/android/launcher3/LauncherProvider.java4
-rw-r--r--src/com/android/launcher3/ThemeChangedReceiver.java4
-rw-r--r--src/com/android/launcher3/WidgetPreviewLoader.java4
6 files changed, 40 insertions, 16 deletions
diff --git a/WallpaperPicker/src/com/android/launcher3/SavedWallpaperImages.java b/WallpaperPicker/src/com/android/launcher3/SavedWallpaperImages.java
index 2bdf8f1cd..9f92bc105 100644
--- a/WallpaperPicker/src/com/android/launcher3/SavedWallpaperImages.java
+++ b/WallpaperPicker/src/com/android/launcher3/SavedWallpaperImages.java
@@ -180,7 +180,6 @@ public class SavedWallpaperImages extends BaseAdapter implements ListAdapter {
static class ImageDb extends SQLiteOpenHelper {
final static int DB_VERSION = 1;
- final static String DB_NAME = "saved_wallpaper_images.db";
final static String TABLE_NAME = "saved_wallpaper_images";
final static String COLUMN_ID = "id";
final static String COLUMN_IMAGE_THUMBNAIL_FILENAME = "image_thumbnail";
@@ -189,7 +188,8 @@ public class SavedWallpaperImages extends BaseAdapter implements ListAdapter {
Context mContext;
public ImageDb(Context context) {
- super(context, context.getDatabasePath(DB_NAME).getPath(), null, DB_VERSION);
+ super(context, context.getDatabasePath(LauncherFiles.WALLPAPER_IMAGES_DB).getPath(),
+ null, DB_VERSION);
// Store the context for later use
mContext = context;
}
@@ -197,8 +197,9 @@ public class SavedWallpaperImages extends BaseAdapter implements ListAdapter {
public static void moveFromCacheDirectoryIfNecessary(Context context) {
// We used to store the saved images in the cache directory, but that meant they'd get
// deleted sometimes-- move them to the data directory
- File oldSavedImagesFile = new File(context.getCacheDir(), ImageDb.DB_NAME);
- File savedImagesFile = context.getDatabasePath(ImageDb.DB_NAME);
+ File oldSavedImagesFile = new File(context.getCacheDir(),
+ LauncherFiles.WALLPAPER_IMAGES_DB);
+ File savedImagesFile = context.getDatabasePath(LauncherFiles.WALLPAPER_IMAGES_DB);
if (oldSavedImagesFile.exists()) {
oldSavedImagesFile.renameTo(savedImagesFile);
}
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index d9f1985fe..d3be726e6 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -198,7 +198,6 @@ public class Launcher extends Activity
static final int SCREEN_COUNT = 5;
static final int DEFAULT_SCREEN = 2;
- private static final String PREFERENCES = "launcher.preferences";
// To turn on these properties, type
// adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
@@ -790,7 +789,7 @@ public class Launcher extends Activity
private static void readConfiguration(Context context, LocaleConfiguration configuration) {
DataInputStream in = null;
try {
- in = new DataInputStream(context.openFileInput(PREFERENCES));
+ in = new DataInputStream(context.openFileInput(LauncherFiles.LAUNCHER_PREFS));
configuration.locale = in.readUTF();
configuration.mcc = in.readInt();
configuration.mnc = in.readInt();
@@ -812,7 +811,8 @@ public class Launcher extends Activity
private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
DataOutputStream out = null;
try {
- out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
+ out = new DataOutputStream(context.openFileOutput(
+ LauncherFiles.LAUNCHER_PREFS, MODE_PRIVATE));
out.writeUTF(configuration.locale);
out.writeInt(configuration.mcc);
out.writeInt(configuration.mnc);
@@ -821,7 +821,7 @@ public class Launcher extends Activity
// Ignore
} catch (IOException e) {
//noinspection ResultOfMethodCallIgnored
- context.getFileStreamPath(PREFERENCES).delete();
+ context.getFileStreamPath(LauncherFiles.LAUNCHER_PREFS).delete();
} finally {
if (out != null) {
try {
diff --git a/src/com/android/launcher3/LauncherFiles.java b/src/com/android/launcher3/LauncherFiles.java
new file mode 100644
index 000000000..89600c2df
--- /dev/null
+++ b/src/com/android/launcher3/LauncherFiles.java
@@ -0,0 +1,27 @@
+package com.android.launcher3;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Central list of files the Launcher writes to the application data directory.
+ *
+ * To add a new Launcher file, create a String constant referring to the filename, and add it to
+ * ALL_FILES, as shown below.
+ */
+public class LauncherFiles {
+
+ public static final String SHARED_PREFS = "com.android.launcher3.prefs.xml";
+ public static final String LAUNCHER_DB = "launcher.db";
+ public static final String LAUNCHER_PREFS = "launcher.preferences";
+ public static final String WALLPAPER_IMAGES_DB = "saved_wallpaper_images.db";
+ public static final String WIDGET_PREVIEWS_DB = "widgetpreviews.db";
+
+ public static final List<String> ALL_FILES = Collections.unmodifiableList(Arrays.asList(
+ SHARED_PREFS,
+ LAUNCHER_DB,
+ LAUNCHER_PREFS,
+ WALLPAPER_IMAGES_DB,
+ WIDGET_PREVIEWS_DB));
+}
diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java
index f1b7d337c..6b42c1ad1 100644
--- a/src/com/android/launcher3/LauncherProvider.java
+++ b/src/com/android/launcher3/LauncherProvider.java
@@ -73,8 +73,6 @@ public class LauncherProvider extends ContentProvider {
private static final String TAG = "Launcher.LauncherProvider";
private static final boolean LOGD = false;
- private static final String DATABASE_NAME = "launcher.db";
-
private static final int DATABASE_VERSION = 21;
static final String OLD_AUTHORITY = "com.android.launcher2.settings";
@@ -431,7 +429,7 @@ public class LauncherProvider extends ContentProvider {
private boolean mNewDbCreated = false;
DatabaseHelper(Context context) {
- super(context, DATABASE_NAME, null, DATABASE_VERSION);
+ super(context, LauncherFiles.LAUNCHER_DB, null, DATABASE_VERSION);
mContext = context;
mPackageManager = context.getPackageManager();
mAppWidgetHost = new AppWidgetHost(context, Launcher.APPWIDGET_HOST_ID);
diff --git a/src/com/android/launcher3/ThemeChangedReceiver.java b/src/com/android/launcher3/ThemeChangedReceiver.java
index 12c9ef755..6bfd09241 100644
--- a/src/com/android/launcher3/ThemeChangedReceiver.java
+++ b/src/com/android/launcher3/ThemeChangedReceiver.java
@@ -19,8 +19,6 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
-import static com.android.launcher3.WidgetPreviewLoader.CacheDb.DB_NAME;
-
import java.io.File;
import java.util.ArrayList;
@@ -71,7 +69,7 @@ public class ThemeChangedReceiver extends BroadcastReceiver {
File[] files = context.getCacheDir().listFiles();
if (files != null) {
for (File f : files) {
- if (!f.isDirectory() && f.getName().startsWith(DB_NAME)) f.delete();
+ if (!f.isDirectory() && f.getName().startsWith(LauncherFiles.LAUNCHER_DB)) f.delete();
}
}
}
diff --git a/src/com/android/launcher3/WidgetPreviewLoader.java b/src/com/android/launcher3/WidgetPreviewLoader.java
index 7fcb9f9ad..a5e9f1dc7 100644
--- a/src/com/android/launcher3/WidgetPreviewLoader.java
+++ b/src/com/android/launcher3/WidgetPreviewLoader.java
@@ -288,7 +288,6 @@ public class WidgetPreviewLoader {
static class CacheDb extends SQLiteOpenHelper {
final static int DB_VERSION = 2;
- final static String DB_NAME = "widgetpreviews.db";
final static String TABLE_NAME = "shortcut_and_widget_previews";
final static String COLUMN_NAME = "name";
final static String COLUMN_SIZE = "size";
@@ -296,7 +295,8 @@ public class WidgetPreviewLoader {
Context mContext;
public CacheDb(Context context) {
- super(context, new File(context.getCacheDir(), DB_NAME).getPath(), null, DB_VERSION);
+ super(context, new File(context.getCacheDir(),
+ LauncherFiles.WIDGET_PREVIEWS_DB).getPath(), null, DB_VERSION);
// Store the context for later use
mContext = context;
}