Merge "Removing file IO used for checking configuration change" into ub-launcher3-burnaby

This commit is contained in:
Sunny Goyal
2015-05-28 00:16:08 +00:00
committed by Android (Google) Code Review
3 changed files with 1 additions and 119 deletions
-9
View File
@@ -49,10 +49,8 @@ import com.android.launcher3.util.Thunk;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map.Entry;
import java.util.Stack;
/**
@@ -366,13 +364,6 @@ public class IconCache {
return mIconDb.newContentValues(entry.icon, entry.title.toString());
}
/**
* Empty out the cache.
*/
public synchronized void flush() {
mCache.clear();
}
/**
* Fetches high-res icon for the provided ItemInfo and updates the caller when done.
* @return a request ID that can be used to cancel the request.
-108
View File
@@ -112,11 +112,8 @@ import com.android.launcher3.widget.PendingAddWidgetInfo;
import com.android.launcher3.widget.WidgetHostViewLoader;
import com.android.launcher3.widget.WidgetsContainerView;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
@@ -310,8 +307,6 @@ public class Launcher extends Activity
private boolean mHasFocus = false;
private boolean mAttached = false;
@Thunk static LocaleConfiguration sLocaleConfiguration = null;
private static LongArrayMap<FolderInfo> sFolders = new LongArrayMap<>();
private View.OnTouchListener mHapticFeedbackTouchListener;
@@ -469,7 +464,6 @@ public class Launcher extends Activity
Environment.getExternalStorageDirectory() + "/launcher");
}
checkForLocaleChange();
setContentView(R.layout.launcher);
setupViews();
@@ -636,108 +630,6 @@ public class Launcher extends Activity
}
}
@Thunk void checkForLocaleChange() {
if (sLocaleConfiguration == null) {
new AsyncTask<Void, Void, LocaleConfiguration>() {
@Override
protected LocaleConfiguration doInBackground(Void... unused) {
LocaleConfiguration localeConfiguration = new LocaleConfiguration();
readConfiguration(Launcher.this, localeConfiguration);
return localeConfiguration;
}
@Override
protected void onPostExecute(LocaleConfiguration result) {
sLocaleConfiguration = result;
checkForLocaleChange(); // recursive, but now with a locale configuration
}
}.execute();
return;
}
final Configuration configuration = getResources().getConfiguration();
final String previousLocale = sLocaleConfiguration.locale;
final String locale = configuration.locale.toString();
final int previousMcc = sLocaleConfiguration.mcc;
final int mcc = configuration.mcc;
final int previousMnc = sLocaleConfiguration.mnc;
final int mnc = configuration.mnc;
boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
if (localeChanged) {
sLocaleConfiguration.locale = locale;
sLocaleConfiguration.mcc = mcc;
sLocaleConfiguration.mnc = mnc;
mIconCache.flush();
final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
new AsyncTask<Void, Void, Void>() {
public Void doInBackground(Void ... args) {
writeConfiguration(Launcher.this, localeConfiguration);
return null;
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
}
}
@Thunk static class LocaleConfiguration {
public String locale;
public int mcc = -1;
public int mnc = -1;
}
@Thunk static void readConfiguration(Context context, LocaleConfiguration configuration) {
DataInputStream in = null;
try {
in = new DataInputStream(context.openFileInput(LauncherFiles.LAUNCHER_PREFERENCES));
configuration.locale = in.readUTF();
configuration.mcc = in.readInt();
configuration.mnc = in.readInt();
} catch (FileNotFoundException e) {
// Ignore
} catch (IOException e) {
// Ignore
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
// Ignore
}
}
}
}
@Thunk static void writeConfiguration(Context context, LocaleConfiguration configuration) {
DataOutputStream out = null;
try {
out = new DataOutputStream(context.openFileOutput(
LauncherFiles.LAUNCHER_PREFERENCES, MODE_PRIVATE));
out.writeUTF(configuration.locale);
out.writeInt(configuration.mcc);
out.writeInt(configuration.mnc);
out.flush();
} catch (FileNotFoundException e) {
// Ignore
} catch (IOException e) {
//noinspection ResultOfMethodCallIgnored
context.getFileStreamPath(LauncherFiles.LAUNCHER_PREFERENCES).delete();
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {
// Ignore
}
}
}
}
public Stats getStats() {
return mStats;
}
+1 -2
View File
@@ -17,7 +17,6 @@ public class LauncherFiles {
public static final String DEFAULT_WALLPAPER_THUMBNAIL = "default_thumb2.jpg";
public static final String DEFAULT_WALLPAPER_THUMBNAIL_OLD = "default_thumb.jpg";
public static final String LAUNCHER_DB = "launcher.db";
public static final String LAUNCHER_PREFERENCES = "launcher.preferences";
public static final String SHARED_PREFERENCES_KEY = "com.android.launcher3.prefs";
public static final String WALLPAPER_CROP_PREFERENCES_KEY =
"com.android.launcher3.WallpaperCropActivity";
@@ -31,7 +30,6 @@ public class LauncherFiles {
DEFAULT_WALLPAPER_THUMBNAIL,
DEFAULT_WALLPAPER_THUMBNAIL_OLD,
LAUNCHER_DB,
LAUNCHER_PREFERENCES,
SHARED_PREFERENCES_KEY + XML,
WALLPAPER_CROP_PREFERENCES_KEY + XML,
WALLPAPER_IMAGES_DB,
@@ -43,5 +41,6 @@ public class LauncherFiles {
public static final List<String> OBSOLETE_FILES = Collections.unmodifiableList(Arrays.asList(
"launches.log",
"stats.log",
"launcher.preferences",
"com.android.launcher3.compat.PackageInstallerCompatV16.queue"));
}