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

Commit b39a82aa authored by Seigo Nonaka's avatar Seigo Nonaka
Browse files

Remove unused shortcut title to improve the boot time performance

The title field of ModifierShortcutManager$ShortcutInfo is not used.
Because making this string requires font access, we cannot remove the
Typeface.loadPreinstalledSystemFontMap function call in system_server
which takes non trivial amount of time.

Removing this field improves 2 seconds of the boot performance on
Wear devices.

More background:
WindowManagerService loads shortcut label which requires system
font initialization. However, the system font initialization happens
after WindowManagerService startup, so system_server loads Typeface
only with preinstalled system fonts for this purpose.

Bug: 288189927
Test: Manually confirmed the shortcut still works.
Test: Manually confirmed the shortcut description still appears by Meta+?
Test: gts-tradefed run gts-dev -m GtsFontHostTestCases
Test: atest atest UpdatableFontDirTest
Test: atest UpdatableSystemFontTest
Test: atest GtsFontHostTestCases
Test: atest FontManagerTest
Change-Id: Ib01e96fa7cef7e9bac17a2f8a7d1942fcff5a407
parent 5e56f8b9
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -227,6 +227,12 @@ public final class FontManagerService extends IFontManager.Stub {
        mContext = context;
        mIsSafeMode = safeMode;
        initialize();

        try {
            Typeface.setSystemFontMap(getCurrentFontMap());
        } catch (IOException | ErrnoException e) {
            Slog.w(TAG, "Failed to set system font map of system_server");
        }
    }

    @Nullable
+12 −28
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.res.XmlResourceParser;
import android.os.RemoteException;
@@ -59,8 +58,8 @@ class ModifierShortcutManager {
    private static final String ATTRIBUTE_CATEGORY = "category";
    private static final String ATTRIBUTE_SHIFT = "shift";

    private final SparseArray<ShortcutInfo> mIntentShortcuts = new SparseArray<>();
    private final SparseArray<ShortcutInfo> mShiftShortcuts = new SparseArray<>();
    private final SparseArray<Intent> mIntentShortcuts = new SparseArray<>();
    private final SparseArray<Intent> mShiftShortcuts = new SparseArray<>();

    private LongSparseArray<IShortcutService> mShortcutKeyServices = new LongSparseArray<>();

@@ -118,26 +117,26 @@ class ModifierShortcutManager {
            return null;
        }

        ShortcutInfo shortcut = null;
        Intent shortcutIntent = null;

        // If the Shift key is pressed, then search for the shift shortcuts.
        SparseArray<ShortcutInfo> shortcutMap = isShiftOn ? mShiftShortcuts : mIntentShortcuts;
        SparseArray<Intent> shortcutMap = isShiftOn ? mShiftShortcuts : mIntentShortcuts;

        // First try the exact keycode (with modifiers).
        int shortcutChar = kcm.get(keyCode, metaState);
        if (shortcutChar != 0) {
            shortcut = shortcutMap.get(shortcutChar);
            shortcutIntent = shortcutMap.get(shortcutChar);
        }

        // Next try the primary character on that key.
        if (shortcut == null) {
        if (shortcutIntent == null) {
            shortcutChar = Character.toLowerCase(kcm.getDisplayLabel(keyCode));
            if (shortcutChar != 0) {
                shortcut = shortcutMap.get(shortcutChar);
                shortcutIntent = shortcutMap.get(shortcutChar);
            }
        }

        return (shortcut != null) ? shortcut.intent : null;
        return shortcutIntent;
    }

    private void loadShortcuts() {
@@ -173,12 +172,10 @@ class ModifierShortcutManager {
                final boolean isShiftShortcut = (shiftName != null && shiftName.equals("true"));

                final Intent intent;
                final String title;
                if (packageName != null && className != null) {
                    ActivityInfo info = null;
                    ComponentName componentName = new ComponentName(packageName, className);
                    try {
                        info = packageManager.getActivityInfo(componentName,
                        packageManager.getActivityInfo(componentName,
                                PackageManager.MATCH_DIRECT_BOOT_AWARE
                                        | PackageManager.MATCH_DIRECT_BOOT_UNAWARE
                                        | PackageManager.MATCH_UNINSTALLED_PACKAGES);
@@ -187,7 +184,7 @@ class ModifierShortcutManager {
                                new String[] { packageName });
                        componentName = new ComponentName(packages[0], className);
                        try {
                            info = packageManager.getActivityInfo(componentName,
                            packageManager.getActivityInfo(componentName,
                                    PackageManager.MATCH_DIRECT_BOOT_AWARE
                                            | PackageManager.MATCH_DIRECT_BOOT_UNAWARE
                                            | PackageManager.MATCH_UNINSTALLED_PACKAGES);
@@ -201,21 +198,18 @@ class ModifierShortcutManager {
                    intent = new Intent(Intent.ACTION_MAIN);
                    intent.addCategory(Intent.CATEGORY_LAUNCHER);
                    intent.setComponent(componentName);
                    title = info.loadLabel(packageManager).toString();
                } else if (categoryName != null) {
                    intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, categoryName);
                    title = "";
                } else {
                    Log.w(TAG, "Unable to add bookmark for shortcut " + shortcutName
                            + ": missing package/class or category attributes");
                    continue;
                }

                ShortcutInfo shortcut = new ShortcutInfo(title, intent);
                if (isShiftShortcut) {
                    mShiftShortcuts.put(shortcutChar, shortcut);
                    mShiftShortcuts.put(shortcutChar, intent);
                } else {
                    mIntentShortcuts.put(shortcutChar, shortcut);
                    mIntentShortcuts.put(shortcutChar, intent);
                }
            }
        } catch (XmlPullParserException | IOException e) {
@@ -370,14 +364,4 @@ class ModifierShortcutManager {

        return false;
    }

    private static final class ShortcutInfo {
        public final String title;
        public final Intent intent;

        ShortcutInfo(String title, Intent intent) {
            this.title = title;
            this.intent = intent;
        }
    }
}
+0 −8
Original line number Diff line number Diff line
@@ -51,7 +51,6 @@ import android.credentials.CredentialManager;
import android.database.sqlite.SQLiteCompatibilityWalFlags;
import android.database.sqlite.SQLiteGlobal;
import android.graphics.GraphicsStatsService;
import android.graphics.Typeface;
import android.hardware.display.DisplayManagerInternal;
import android.net.ConnectivityManager;
import android.net.ConnectivityModuleConnector;
@@ -910,13 +909,6 @@ public final class SystemServer implements Dumpable {
            SystemServerInitThreadPool tp = SystemServerInitThreadPool.start();
            mDumper.addDumpable(tp);

            // Load preinstalled system fonts for system server, so that WindowManagerService, etc
            // can start using Typeface. Note that fonts are required not only for text rendering,
            // but also for some text operations (e.g. TextUtils.makeSafeForPresentation()).
            if (Typeface.ENABLE_LAZY_TYPEFACE_INITIALIZATION) {
                Typeface.loadPreinstalledSystemFontMap();
            }

            // Attach JVMTI agent if this is a debuggable build and the system property is set.
            if (Build.IS_DEBUGGABLE) {
                // Property is of the form "library_path=parameters".