Skip to content

Commit

Permalink
Merge pull request #10620 from wordpress-mobile/issue/8828-Aztec-cras…
Browse files Browse the repository at this point in the history
…h-Android-8

Disable HW acceleration on Aztec when it crashes on Android 8 - Release Gutenberg to v1.15.1
  • Loading branch information
mchowning authored Oct 22, 2019
2 parents d2a865d + 5a6a8df commit fec059a
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
import org.wordpress.android.widgets.AppRatingDialog;
import org.wordpress.android.widgets.WPSnackbar;
import org.wordpress.android.widgets.WPViewPager;
import org.wordpress.aztec.exceptions.DynamicLayoutGetBlockIndexOutOfBoundsException;
import org.wordpress.aztec.util.AztecLog;

import java.io.File;
Expand Down Expand Up @@ -1620,7 +1621,29 @@ public void initializeEditorFragment() {
}
);
}

PostModel currentPost = getPost();
if (currentPost != null && AppPrefs.isPostWithHWAccelerationOff(currentPost.getLocalSiteId(),
currentPost.getId())) {
// We need to disable HW Acc. on this post
aztecEditorFragment.disableHWAcceleration();
}
aztecEditorFragment.setExternalLogger(new AztecLog.ExternalLogger() {
// This method handles the custom Exception thrown by Aztec to notify the parent app of the error #8828
// We don't need to log the error, since it was already logged by Aztec, instead we need to write the
// prefs to disable HW acceleration for it.
private boolean isError8828(@NotNull Throwable throwable) {
if (!(throwable instanceof DynamicLayoutGetBlockIndexOutOfBoundsException)) {
return false;
}
PostModel currentPost = getPost();
if (currentPost == null) {
return false;
}
AppPrefs.addPostWithHWAccelerationOff(currentPost.getLocalSiteId(), currentPost.getId());
return true;
}

@Override
public void log(@NotNull String s) {
// For now, we're wrapping up the actual log into an exception to reduce possibility
Expand All @@ -1631,11 +1654,17 @@ public void log(@NotNull String s) {

@Override
public void logException(@NotNull Throwable throwable) {
if (isError8828(throwable)) {
return;
}
CrashLoggingUtils.logException(new AztecEditorFragment.AztecLoggingException(throwable), T.EDITOR);
}

@Override
public void logException(@NotNull Throwable throwable, String s) {
if (isError8828(throwable)) {
return;
}
CrashLoggingUtils.logException(
new AztecEditorFragment.AztecLoggingException(throwable), T.EDITOR, s);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import org.wordpress.android.analytics.AnalyticsTracker.Stat;
import org.wordpress.android.fluxc.model.PostModel;
import org.wordpress.android.fluxc.model.SiteModel;
import org.wordpress.android.ui.prefs.AppPrefs;
import org.wordpress.android.util.AppLog;
import org.wordpress.android.util.AppLog.T;
import org.wordpress.android.util.SiteUtils;
import org.wordpress.android.util.analytics.AnalyticsUtils;

import java.io.Serializable;
import java.util.ArrayList;
Expand All @@ -33,6 +35,7 @@ public class PostEditorAnalyticsSession implements Serializable {
private Editor mCurrentEditor;
private boolean mHasUnsupportedBlocks = false;
private Outcome mOutcome = null;
private boolean mHWAccOff = false;

enum Editor {
GUTENBERG,
Expand Down Expand Up @@ -77,6 +80,8 @@ enum Outcome {
} else {
mContentType = "classic";
}

mHWAccOff = AppPrefs.isPostWithHWAccelerationOff(site.getId(), post.getId());
}

public void start(ArrayList<Object> unsupportedBlocksList) {
Expand Down Expand Up @@ -132,6 +137,8 @@ private Map<String, Object> getCommonProperties() {
properties.put(KEY_BLOG_TYPE, mBlogType);
properties.put(KEY_SESSION_ID, mSessionId);
properties.put(KEY_HAS_UNSUPPORTED_BLOCKS, mHasUnsupportedBlocks ? "1" : "0");
properties.put(AnalyticsUtils.EDITOR_HAS_HW_ACCELERATION_DISABLED_KEY, mHWAccOff ? "1" : "0");

return properties;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.wordpress.android.fluxc.model.post.PostStatus;
import org.wordpress.android.fluxc.store.PostStore;
import org.wordpress.android.ui.posts.RemotePreviewLogicHelper.RemotePreviewType;
import org.wordpress.android.ui.prefs.AppPrefs;
import org.wordpress.android.ui.uploads.PostEvents;
import org.wordpress.android.ui.uploads.UploadUtils;
import org.wordpress.android.ui.utils.UiString.UiStringText;
Expand Down Expand Up @@ -186,6 +187,8 @@ public static void trackOpenEditorAnalytics(PostModel post, SiteModel site) {
if (!post.isLocalDraft()) {
properties.put("post_id", post.getRemotePostId());
}
properties.put(AnalyticsUtils.EDITOR_HAS_HW_ACCELERATION_DISABLED_KEY, AppPrefs.isPostWithHWAccelerationOff(
site.getId(), post.getId()) ? "1" : "0");
properties.put(AnalyticsUtils.HAS_GUTENBERG_BLOCKS_KEY,
PostUtils.contentContainsGutenbergBlocks(post.getContent()));
AnalyticsUtils.trackWithSiteDetails(AnalyticsTracker.Stat.EDITOR_OPENED, site,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ public enum DeletablePrefKey implements PrefKey {
// Widget settings
STATS_WIDGET_SELECTED_SITE_ID,
STATS_WIDGET_COLOR_MODE,
STATS_WIDGET_DATA_TYPE
STATS_WIDGET_DATA_TYPE,

// Keep the local_blog_id + local_post_id values that have HW Acc. turned off
AZTEC_EDITOR_DISABLE_HW_ACC_KEYS,
}

/**
Expand Down Expand Up @@ -959,4 +962,36 @@ public static void setSystemNotificationsEnabled(boolean enabled) {
public static boolean getSystemNotificationsEnabled() {
return getBoolean(UndeletablePrefKey.SYSTEM_NOTIFICATIONS_ENABLED, true);
}

private static List<String> getPostWithHWAccelerationOff() {
String idsAsString = getString(DeletablePrefKey.AZTEC_EDITOR_DISABLE_HW_ACC_KEYS, "");
return Arrays.asList(idsAsString.split(","));
}

/*
* adds a local site ID to the top of list of recently chosen sites
*/
public static void addPostWithHWAccelerationOff(int localSiteId, int localPostId) {
if (localSiteId == 0 || localPostId == 0 || isPostWithHWAccelerationOff(localSiteId, localPostId)) {
return;
}
String key = localSiteId + "-" + localPostId;
List<String> currentIds = new ArrayList<>(getPostWithHWAccelerationOff());
currentIds.add(key);
// store in prefs
String idsAsString = TextUtils.join(",", currentIds);
setString(DeletablePrefKey.AZTEC_EDITOR_DISABLE_HW_ACC_KEYS, idsAsString);
}

public static boolean isPostWithHWAccelerationOff(int localSiteId, int localPostId) {
if (localSiteId == 0 || localPostId == 0) {
return false;
}
List<String> currentIds = getPostWithHWAccelerationOff();
String key = localSiteId + "-" + localPostId;
if (currentIds.contains(key)) {
return true;
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public class AnalyticsUtils {
private static final String NEWS_CARD_VERSION = "version";

public static final String HAS_GUTENBERG_BLOCKS_KEY = "has_gutenberg_blocks";
public static final String EDITOR_HAS_HW_ACCELERATION_DISABLED_KEY = "editor_has_hw_disabled";

public enum BlockEditorEnabledSource {
VIA_SITE_SETTINGS,
Expand Down
2 changes: 1 addition & 1 deletion libs/editor/WordPressEditor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
}

ext {
aztecVersion = 'v1.3.33'
aztecVersion = 'v1.3.34'
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ public AztecLoggingException(Throwable originalException) {

private LiveTextWatcher mTextWatcher = new LiveTextWatcher();

private View mFragmentView;

public static AztecEditorFragment newInstance(String title, String content, boolean isExpanded) {
mIsToolbarExpanded = isExpanded;
AztecEditorFragment fragment = new AztecEditorFragment();
Expand All @@ -219,6 +221,7 @@ public void onCreate(Bundle savedInstanceState) {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_aztec_editor, container, false);
mFragmentView = view;

mTitle = view.findViewById(R.id.title);
mContent = view.findViewById(R.id.aztec);
Expand Down Expand Up @@ -2339,4 +2342,8 @@ public void disableContentLogOnCrashes() {
public void setExternalLogger(AztecLog.ExternalLogger logger) {
mContent.setExternalLogger(logger);
}

public void disableHWAcceleration() {
mFragmentView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
}

0 comments on commit fec059a

Please sign in to comment.