Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d58cc2df authored by ezio84's avatar ezio84 Committed by Luca Stefani
Browse files

GlobalScreenshot: Fix screenshot not saved with some languages

like Virgin Islands English when taking a screenshot of the Settings app

Change-Id: Ic04f66f5813b9597c96835d15c74509c93530a5c
parent 5bee4ef0
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -84,6 +84,7 @@ import com.android.systemui.util.NotificationChannels;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
@@ -162,8 +163,18 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
        CharSequence appName = getRunningActivityName(context);
        boolean onKeyguard = context.getSystemService(KeyguardManager.class).isKeyguardLocked();
        if (!onKeyguard && appName != null) {
            // Replace all spaces and special chars with an underscore
            String appNameString = appName.toString().replaceAll("[\\\\/:*?\"<>|\\s]+", "_");
            String appNameString = appName.toString();
            try {
                // With some languages like Virgin Islands English, the Settings app gets a weird
                // long name and some special voodoo chars, so we convert the string to utf-8 to get
                // a  char instead, easy to remove it then
                final String temp = new String(appNameString.getBytes("ISO-8859-15"), "UTF-8");
                appNameString = temp.replaceAll("[]+", "");
            } catch (UnsupportedEncodingException e) {
                // Do nothing
            }
            // Now replace all spaces and special chars with an underscore
            appNameString = appNameString.replaceAll("[\\\\/:*?\"<>|\\s]+", "_");
            mImageFileName = String.format(SCREENSHOT_FILE_NAME_TEMPLATE_APPNAME,
                    imageDate, appNameString);
        } else {