Enter the application directly after booting as the default launcher (overlord screen) or start the specified application automatically after booting

By default, this app is loaded as the launcher for the first time at startup , which is to set the apk as the boot guide, and not to set this as the default launcher . If the application is a launcher application, it will prompt you to choose which laucher to choose after pressing Return. The premise is that the application is not built-in As a launcher application, you can use the following method.

Boot from start, boot automatically start a specified application! !!!

Method 1: (recommended) but this one is relatively slow, the system has entered the system after booting, but it will take a while to receive the broadcast, and it needs to complete the system update before receiving it

vendor/mediatek/proprietary/packages/apps/SystemUI/ src/com/android/systemui/SystemUIApplication.java

In the place where the boot broadcast is received , execute the jump , here is the broadcast acceptance jump, which can be directly and explicitly started

IntentFilter bootCompletedFilter = new IntentFilter(Intent.ACTION_BOOT_COMPLETED);

            bootCompletedFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);

            registerReceiver(new BroadcastReceiver() {
   
   

Add the following operations

One: You can directly and explicitly start

Intent cIntent=new Intent();

        cIntent.setClassName("lte.trunk.tapp","lte.trunk.tapp.settings.AASSettingActivity");

        cIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                        android.util.Log.d("yantao", "cIntent="+cIntent);

        context.startActivity(cIntent);

Two: use the PackageManager().getLaunchIntentForPackage method, you don’t need to pass the class name, it’s suitable for those who don’t know which activity comes out first, just need a package name

Intent cIntent=new Intent();

                cIntent = context.getPackageManager().getLaunchIntentForPackage("lte.trunk.tapp");

                android.util.Log.d("yantao", "cIntent="+cIntent);

                if(cIntent != null){

                cIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                    context.startActivity(cIntent);

                } else {

                    android.util.Log.d("yantao", "getLaunchIntentForPackage failed");

                }

O version! o above does not work

frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java

After the Home Activity is started in the above ActivityManagerService , the finishBooting() function will be called

Add the following at the end of this finishBooting , so that you can start the specified application and directly enter this application, even if it is a launcher application . For the first time loading this time, the previous judgment can be omitted

if (Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 1) {

+            Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 1);

+            Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.USER_SETUP_COMPLETE, 1);

+        }

+           Intent cIntent=new Intent();

+            cIntent = mContext.getPackageManager().getLaunchIntentForPackage("com.mcptt");

+            if(cIntent != null){

+                mContext.startActivity(cIntent);

+            } else {

+                android.util.Log.i("yantao", "getLaunchIntentForPackage failed" );+            }

+        //*/                     

The above is to set this apk as the startup wizard. In ActivityManagerService , since the startup wizard is only started before the system is started for the first time, when the startup wizard is closed, you need to set yourself not to start. There is a sentence mAnrManager.writeEvent(AnrManager.EVENT_BOOT_COMPLETED) in finishBooting in the source code ; that is, the setting is no longer started. Then at the same time, you need to tell the system that the startup wizard has been completed, and you need to write the following properties into the system ( requires system permissions )

Settings.Global.putInt(getActivity().getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 1);

Settings.Secure.putInt(getActivity().getContentResolver(), Settings.Secure.USER_SETUP_COMPLETE, 1);

Then in frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java, modify what others wrote and press the power button to lock in launcher3 . The judgment is as follows, in case KeyEvent.KEYCODE_POWER: { this case , _

else{

                        

-                        if(getCurrentActivityName(mContext).equals("com.android.launcher3.Launcher")) {

-                                if (down) {

-                                    interceptPowerKeyDown(event, interactive);

-                                } else {

-                                    interceptPowerKeyUp(event, interactive, canceled);

-                                }

-                        }else{

-                                if (down) {

-                                    Intent intent=new Intent();

-                                    intent.setClassName("com.android.launcher3","com.android.launcher3.Launcher");

-                                    mContext.startActivity(intent);

-                                }

-                        }

What he means is that if it is currently in launcher3 , then the power button is used normally, and if it is not, then launcher3 is forced to be turned on

We just need to roll this back to the source code itself. It's the normal use of the power button

if (down) {

                 interceptPowerKeyDown(event, interactive);

             } else {

                 interceptPowerKeyUp(event, interactive, canceled);

             }

             }

                break;

            }

The above is for an application that is not a launcher itself . If it is a launcher application, then set it as the default launcher .

frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java

In this method , startHomeActivityLocked is added at the end of the source code

Add this method to change the default launcher

final PackageManager mPm = mContext.getPackageManager();

       Intent homeIntent=new Intent();

       homeIntent.addCategory(Intent.CATEGORY_HOME);

       homeIntent.setAction(Intent.ACTION_MAIN);

       homeIntent.addCategory(Intent.CATEGORY_DEFAULT);

       ResolveInfo info = mPm.resolveActivity(homeIntent, PackageManager.MATCH_DEFAULT_ONLY);

       ComponentName DefaultLauncher=new ComponentName("afrizona.maxalerts.rotas","afrizona.maxalerts.rotas.MainActivity");

       ArrayList<ResolveInfo> homeActivities = new ArrayList<ResolveInfo>();

       ComponentName currentDefaultHome = mPm.getHomeActivities(homeActivities);

       ComponentName[]mHomeComponentSet = new ComponentName[homeActivities.size()];

       for (int i = 0; i < homeActivities.size(); i++) {

              final ResolveInfo candidate = homeActivities.get(i);

              Log.d(TAG,"homeActivitie: candidate = "+candidate);

              final ActivityInfo activityInfo= candidate.activityInfo;

              ComponentName activityName = new ComponentName(activityInfo.packageName, activityInfo.name);

              mHomeComponentSet[i] = activityName;

       }

       IntentFilter mHomeFilter = new IntentFilter(Intent.ACTION_MAIN);

       mHomeFilter.addCategory(Intent.CATEGORY_HOME);

       mHomeFilter.addCategory(Intent.CATEGORY_DEFAULT);

       List<ComponentName>Activities=new ArrayList();

       mPm.replacePreferredActivity(mHomeFilter, IntentFilter.MATCH_CATEGORY_EMPTY,mHomeComponentSet, DefaultLauncher);

When it’s over, don’t forget to delete the other people’s forced power button to return to launcher3 in PhoneWindowManager , if there is any

Guess you like

Origin blog.csdn.net/youthking1314/article/details/128393909