Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
[Android] Fixed crash of XWalkPreferences
Browse files Browse the repository at this point in the history
Everytime XWalkPreference.sevValue() is invoked, it checks if previous
listeners exist, if exist and the key is ANIMATABLE_XWALK_VIEW, if
will throw an runtime exception.

The listener is registered when an XWalkView is created and unregistered
when an XWalkView is destroyed. But after XWalkView is decoupled from
the activity, XWalkView can not be destroyed automatically when an
activity is closed. So previous listeners are still remaining  and have
the app crashed.

This patch changs the behavior on this situation, warning that this
setting is not effective to previous XWalkViews instead of throwing the
exception.

BUG=XWALK-7309
  • Loading branch information
Lin Sun committed Oct 26, 2016
1 parent 75f9aba commit 43a92e0
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package org.xwalk.core.internal;

import android.util.Log;

import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
Expand All @@ -18,6 +20,8 @@
*/
@XWalkAPI(noInstance = true)
public class XWalkPreferencesInternal {
private static final String TAG = "XWalkPreferences";

static class PreferenceValue {
static final int PREFERENCE_TYPE_BOOLEAN = 1;
static final int PREFERENCE_TYPE_INTEGER = 2;
Expand Down Expand Up @@ -196,8 +200,7 @@ public static synchronized void setValue(String key, boolean enabled) throws Run
// If the listener list is not empty, we consider the preference is
// loaded by Crosswalk and taken effect already.
if (key == ANIMATABLE_XWALK_VIEW && !sListeners.isEmpty()) {
throw new RuntimeException("Warning: the preference key " + key +
" can not be set if the preference is already loaded by Crosswalk");
Log.d(TAG, "ANIMATABLE_XWALK_VIEW is not effective to existing XWalkView objects");
}
if (sPrefMap.get(key).getBooleanValue() != enabled) {
PreferenceValue v = new PreferenceValue(enabled);
Expand All @@ -219,8 +222,7 @@ public static synchronized void setValue(String key, int value) throws RuntimeEx
// If the listener list is not empty, we consider the preference is
// loaded by Crosswalk and taken effect already.
if (key == ANIMATABLE_XWALK_VIEW && !sListeners.isEmpty()) {
throw new RuntimeException("Warning: the preference key " + key +
" can not be set if the preference is already loaded by Crosswalk");
Log.d(TAG, "ANIMATABLE_XWALK_VIEW is not effective to existing XWalkView objects");
}
if (sPrefMap.get(key).getIntegerValue() != value) {
PreferenceValue v = new PreferenceValue(value);
Expand All @@ -242,8 +244,7 @@ public static synchronized void setValue(String key, String value) throws Runtim
// If the listener list is not empty, we consider the preference is
// loaded by Crosswalk and taken effect already.
if (key == ANIMATABLE_XWALK_VIEW && !sListeners.isEmpty()) {
throw new RuntimeException("Warning: the preference key " + key +
" can not be set if the preference is already loaded by Crosswalk");
Log.d(TAG, "ANIMATABLE_XWALK_VIEW is not effective to existing XWalkView objects");
}
if (value != null && !value.equals(sPrefMap.get(key).getStringValue())) {
PreferenceValue v = new PreferenceValue(value);
Expand Down

0 comments on commit 43a92e0

Please sign in to comment.