Search code examples
androidandroid-source

How to add my application before launcher in AOSP


How to modify boot sequence in AOSP: I will add custom application(registration app - login and password, which will be send to server for authorization purposes) before starting Launcher2 application. How can I do this? I know that ActivityManager manages which Activity to start, but I have no clue where should I place my application start. I need to launch my application right after android system boot complete.


Solution

  • In ICS, there is a method named startHomeActivityLocked in ActivityManagerService. In that method, the ActivityManagerService will start the Launcher2 application by sending an android.intent.category.HOME intent.

    boolean startHomeActivityLocked(int userId) {
        ....
        intent.setComponent(mTopComponent);
            if (mFactoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
                intent.addCategory(Intent.CATEGORY_HOME);
            }
            ActivityInfo aInfo =
                resolveActivityInfo(intent, STOCK_PM_FLAGS, userId);
            if (aInfo != null) {
                intent.setComponent(new ComponentName(
                        aInfo.applicationInfo.packageName, aInfo.name));
                // Don't do this if the home app is currently being
                // instrumented.
                aInfo = new ActivityInfo(aInfo);
                aInfo.applicationInfo = getAppInfoForUser(aInfo.applicationInfo, userId);
                ProcessRecord app = getProcessRecordLocked(aInfo.processName,
                        aInfo.applicationInfo.uid);
                if (app == null || app.instrumentationClass == null) {
                    intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
                    mMainStack.startActivityLocked(null, intent, null, aInfo,
                            null, null, 0, 0, 0, 0, null, false, null);
                }
            }
    }
    

    So you can add your code in that method or before the call site of that method. In particular, you can replace the intent to make the ActivityManagerService start your application, not the Launcher. And when your application finishs the authentication, you can make your application send an intent to Launcher2.

    In gingerbread, the method signature is boolean startHomeActivityLocked() because Android doesn't support multiple user in this build.