全志 增加启动默launcher函数 Patch

add 添加启动默launcher函数diff --git a/android/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java b/android/fr
index 446b0e4..9b7e2ba 100755
--- a/android/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/android/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -3692,7 +3692,81 @@ public final class ActivityManagerService extends ActivityManagerNative}return intent;}
-
+       
+        /* launch the defualt launcher when the system boots for the first time */
+    private boolean mFirstLaunch = false;
+       private void setDefaultLauncher(int userId)
+    {
+        // get default component
+        String  packageName = SystemProperties.get("ro.sw.defaultlauncherpackage", "no");
+        String  className = SystemProperties.get("ro.sw.defaultlauncherclass", "no");
+        Slog.i(TAG, "default packageName = " + packageName + ", default className = " + className);
+        if(!packageName.equals("no") && !className.equals("no")){
+            boolean firstLaunch = true;//SystemProperties.getBoolean("persist.sys.sw.firstLaunch", true);
+            Slog.d(TAG, "firstLaunch = " + firstLaunch);
+            if(firstLaunch){
+                mFirstLaunch = true;
+                // do this only for the first boot
+                SystemProperties.set("persist.sys.sw.firstLaunch", "false");
+            }
+            Slog.d(TAG, "mFirstLaunch = " + mFirstLaunch);
+            if(mFirstLaunch){
+                IPackageManager pm = ActivityThread.getPackageManager();
+
+                //clear the current preferred launcher
+                ArrayList intentList = new ArrayList();
+                ArrayList cnList = new ArrayList();
+                mContext.getPackageManager().getPreferredActivities(intentList, cnList, null);
+                IntentFilter dhIF;
+                for(int i = 0; i < cnList.size(); i++)
+                {
+                    dhIF = intentList.get(i);
+                    if(dhIF.hasAction(Intent.ACTION_MAIN) &&
+                            dhIF.hasCategory(Intent.CATEGORY_HOME))
+                    {
+                        mContext.getPackageManager().clearPackagePreferredActivities(cnList.get(i).getPackageName());
+                    }
+                }
+
+                // get all Launcher activities
+                Intent intent = new Intent(Intent.ACTION_MAIN);
+                intent.addCategory(Intent.CATEGORY_HOME);
+                List list = new ArrayList();
+                try
+                {
+                    list = pm.queryIntentActivities(intent,
+                            intent.resolveTypeIfNeeded(mContext.getContentResolver()),
+                            PackageManager.MATCH_DEFAULT_ONLY, userId);
+                }catch (RemoteException e) {
+                    throw new RuntimeException("Package manager has died", e);
+                }
+                // get all components and the best match
+                IntentFilter filter = new IntentFilter();
+                filter.addAction(Intent.ACTION_MAIN);
+                filter.addCategory(Intent.CATEGORY_HOME);
+                filter.addCategory(Intent.CATEGORY_DEFAULT);
+                final int N = list.size();
+                ComponentName[] set = new ComponentName[N];
+                int bestMatch = 0;
+                for (int i = 0; i < N; i++)
+                {
+                    ResolveInfo r = list.get(i);
+                    set[i] = new ComponentName(r.activityInfo.packageName,
+                            r.activityInfo.name);
+                    if (r.match > bestMatch) bestMatch = r.match;
+                }
+                // add the default launcher as the preferred launcher
+                ComponentName launcher = new ComponentName(packageName, className);
+                try
+                {
+                    pm.addPreferredActivity(filter, bestMatch, set, launcher, userId);
+                } catch (RemoteException e) {
+                    throw new RuntimeException("Package manager has died", e);
+                }
+            }
+        }
+    }
+       boolean startHomeActivityLocked(int userId, String reason) {if (mFactoryTest == FactoryTest.FACTORY_TEST_LOW_LEVEL&& mTopAction == null) {
@@ -3701,6 +3775,10 @@ public final class ActivityManagerService extends ActivityManagerNative// error message and don't try to start anything.return false;}
+               /* launch the defualt launcher when the system boots for the first time */
+               setDefaultLauncher(userId);
+               
+  


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部