• Android5.1 默认主launcher、强制主launcher


    一.Android5.1 默认主launcher

    1.1.默认launcher属性

    diff --git a/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java b/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
    index 2566663..82c5497 100755
    --- a/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
    +++ b/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
    @@ -3259,6 +3259,66 @@ public final class ActivityManagerService extends ActivityManagerNative
             }
             return intent;
         }
    +    
    +    private void setDefaultLauncher() {  
    +    	
    +    	
    +    	String packageName = SystemProperties.get("persist.app.pkgName","com.android.launcher3");
    +    	String className = SystemProperties.get("persist.app.className","com.android.launcher3.Launcher");
    +           
    +        Slog.i(TAG, "defautl packageName = " + packageName + ", default className = " + className); 
    +        
    +         
    +        if ((packageName != null && packageName.trim().length() > 1) && (className != null && className.trim().length() > 0)) {
    +        	
    +                IPackageManager pm = ActivityThread.getPackageManager();   
    +                ArrayList<IntentFilter> intentList = new ArrayList<IntentFilter>();  
    +                ArrayList<ComponentName> cnList = new ArrayList<ComponentName>();  
    +                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());  
    +                    }  
    +              	}   
    +                Intent intent = new Intent(Intent.ACTION_MAIN);  
    +                intent.addCategory(Intent.CATEGORY_HOME);  
    +                List<ResolveInfo> list = new ArrayList<ResolveInfo>();  
    +                try   
    +                {  
    +                    list = pm.queryIntentActivities(intent,  
    +                        intent.resolveTypeIfNeeded(mContext.getContentResolver()),  
    +                        PackageManager.MATCH_DEFAULT_ONLY,UserHandle.getCallingUserId());  
    +                }catch (RemoteException e) {  
    +                    throw new RuntimeException("Package manager has died", e);  
    +                }   
    +                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;  
    +                }  
    +                ComponentName launcher = new ComponentName(packageName, className);  
    +                try   
    +                {  
    +                    pm.addPreferredActivity(filter, bestMatch, set, launcher,UserHandle.getCallingUserId());  
    +                } catch (RemoteException e) {  
    +                    throw new RuntimeException("Package manager has died", e);  
    +                }   
    +            
    +        }  
    +    } 
     
         boolean startHomeActivityLocked(int userId, String reason) {
             if (mFactoryTest == FactoryTest.FACTORY_TEST_LOW_LEVEL
    @@ -3268,6 +3328,9 @@ public final class ActivityManagerService extends ActivityManagerNative
                 // error message and don't try to start anything.
                 return false;
             }
    +        
    +        setDefaultLauncher();
    +        
             Intent intent = getHomeIntent();
             ActivityInfo aInfo =
                 resolveActivityInfo(intent, STOCK_PM_FLAGS, userId);
    diff --git a/packages/apps/Settings/src/com/android/settings/HomeSettings.java b/packages/apps/Settings/src/com/android/settings/HomeSettings.java
    old mode 100644
    new mode 100755
    index 6da1848..8364ee0
    --- a/packages/apps/Settings/src/com/android/settings/HomeSettings.java
    +++ b/packages/apps/Settings/src/com/android/settings/HomeSettings.java
    @@ -55,6 +55,7 @@ import com.android.settings.search.BaseSearchIndexProvider;
     import com.android.settings.search.Index;
     import com.android.settings.search.Indexable;
     import com.android.settings.search.SearchIndexableRaw;
    +import android.os.SystemProperties;
     
     public class HomeSettings extends SettingsPreferenceFragment implements Indexable {
         static final String TAG = "HomeSettings";
    @@ -124,6 +125,21 @@ public class HomeSettings extends SettingsPreferenceFragment implements Indexabl
                     mHomeComponentSet, newHome.activityName);
     
             getActivity().setResult(Activity.RESULT_OK);
    +        
    +        //Log.d("xinhua_launcher","className = "+newHome.activityName.getClassName());
    +        //Log.d("xinhua_launcher","packageName = " +newHome.activityName.getPackageName());
    +        
    +        SystemProperties.set("persist.app.pkgName",newHome.activityName.getPackageName());
    +        SystemProperties.set("persist.app.className",newHome.activityName.getClassName());
    +        
    +        startHomeApk();
    +    }
    +    
    +    void startHomeApk(){
    +    		Intent intent= new Intent(Intent.ACTION_MAIN);
    +				intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    +				intent.addCategory(Intent.CATEGORY_HOME);
    +				getActivity().startActivity(intent);    	
         }
     
         void uninstallApp(HomeAppPreference pref) {
    

     

    二.强制主launcher

    --- a/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
    +++ b/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
    @@ -3268,10 +3268,27 @@ public final class ActivityManagerService extends ActivityManagerNative
                 // error message and don't try to start anything.
                 return false;
             }
    -        Intent intent = getHomeIntent();
    +        String className = SystemProperties.get("persist.app.className","com.android.launcher3.Launcher");
    +   			Intent intent = getHomeIntent();
             ActivityInfo aInfo =
                 resolveActivityInfo(intent, STOCK_PM_FLAGS, userId);
    -        if (aInfo != null) {
    +			if (aInfo != null) {
    +					 PackageManager pm = mContext.getPackageManager();
    +					 Intent newintent = new Intent(Intent.ACTION_MAIN);
    +					 newintent.addCategory(Intent.CATEGORY_HOME);
    +					 List<ResolveInfo> resolveInfoList = pm.queryIntentActivities(newintent, 0);				
    +					 if(resolveInfoList != null){
    +					 		int size = resolveInfoList.size();
    +					 		for(int i = 0; i < size; i++){
    +								ResolveInfo rInfo = resolveInfoList.get(i);				
    +								if(rInfo.activityInfo.name.equals(className)){
    +									aInfo = rInfo.activityInfo;
    +					 			}
    +					 		}
    +					 }
    +					 
    +					 Log.d("gatsby","packageName = "+aInfo.applicationInfo.packageName);
    +        
                 intent.setComponent(new ComponentName(
                         aInfo.applicationInfo.packageName, aInfo.name));
                 // Don't do this if the home app is currently being

     

  • 相关阅读:
    P4568 [JLOI2011]飞行路线 最短路+分层图
    虚树
    点分治
    P2157 [SDOI2009]学校食堂 状压DP
    P2767 树的数量 DP | 组合数学
    CF348D LGV引理
    LGV引理
    P3647 [APIO2014]连珠线 换根DP
    第3章 决策树
    USDT/BTC/ETC/HT的解释
  • 原文地址:https://www.cnblogs.com/crushgirl/p/14652878.html
Copyright © 2020-2023  润新知