parent
acbe38f3e1
commit
d5d61c3485
|
@ -25,6 +25,7 @@ import android.content.SharedPreferences;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
import android.view.InflateException;
|
||||||
|
|
||||||
public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceChangeListener {
|
public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
|
|
||||||
|
@ -400,6 +401,9 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
} catch (OutOfMemoryError e) {
|
} catch (OutOfMemoryError e) {
|
||||||
tryGC = LatinIMEUtil.GCUtils.getInstance().tryGCOrWait(
|
tryGC = LatinIMEUtil.GCUtils.getInstance().tryGCOrWait(
|
||||||
mLayoutId + "," + newLayout, e);
|
mLayoutId + "," + newLayout, e);
|
||||||
|
} catch (InflateException e) {
|
||||||
|
tryGC = LatinIMEUtil.GCUtils.getInstance().tryGCOrWait(
|
||||||
|
mLayoutId + "," + newLayout, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mInputView.setExtentionLayoutResId(LAYOUTS[newLayout]);
|
mInputView.setExtentionLayoutResId(LAYOUTS[newLayout]);
|
||||||
|
|
|
@ -24,7 +24,7 @@ public class LatinIMEUtil {
|
||||||
private static final String TAG = "GCUtils";
|
private static final String TAG = "GCUtils";
|
||||||
public static final int GC_TRY_COUNT = 2;
|
public static final int GC_TRY_COUNT = 2;
|
||||||
// GC_TRY_LOOP_MAX is used for the hard limit of GC wait,
|
// GC_TRY_LOOP_MAX is used for the hard limit of GC wait,
|
||||||
// GC_TRY_LOOP_MAX should be GC_TRY_COUNT.
|
// GC_TRY_LOOP_MAX should be greater than GC_TRY_COUNT.
|
||||||
public static final int GC_TRY_LOOP_MAX = 5;
|
public static final int GC_TRY_LOOP_MAX = 5;
|
||||||
private static final long GC_INTERVAL = DateUtils.SECOND_IN_MILLIS;
|
private static final long GC_INTERVAL = DateUtils.SECOND_IN_MILLIS;
|
||||||
private static GCUtils sInstance = new GCUtils();
|
private static GCUtils sInstance = new GCUtils();
|
||||||
|
@ -38,15 +38,15 @@ public class LatinIMEUtil {
|
||||||
mGCTryCount = 0;
|
mGCTryCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean tryGCOrWait(String metaData, OutOfMemoryError oome) {
|
public boolean tryGCOrWait(String metaData, Throwable t) {
|
||||||
if (LatinImeLogger.sDBG) {
|
if (LatinImeLogger.sDBG) {
|
||||||
Log.d(TAG, "Encountered Out of memory Error. Try GC.");
|
Log.d(TAG, "Encountered Exception or Error. Try GC.");
|
||||||
}
|
}
|
||||||
if (mGCTryCount == 0) {
|
if (mGCTryCount == 0) {
|
||||||
System.gc();
|
System.gc();
|
||||||
}
|
}
|
||||||
if (++mGCTryCount > GC_TRY_COUNT) {
|
if (++mGCTryCount > GC_TRY_COUNT) {
|
||||||
LatinImeLogger.logOnException(metaData, oome);
|
LatinImeLogger.logOnException(metaData, t);
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
|
@ -54,7 +54,7 @@ public class LatinIMEUtil {
|
||||||
return true;
|
return true;
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Log.e(TAG, "Sleep was interrupted.");
|
Log.e(TAG, "Sleep was interrupted.");
|
||||||
LatinImeLogger.logOnException(metaData, oome);
|
LatinImeLogger.logOnException(metaData, t);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue