Android13 Launcher3 定制

去掉Google搜索栏

aosp/packages/apps/Launcher3/src_build_config/com/android/launcher3/BuildConfig.java

修改QSB_ON_FIRST_SCREEN为false

java 复制代码
    public static final boolean QSB_ON_FIRST_SCREEN = false;

去掉抽屉菜单,所有应用都放到桌面

增加控制变量

aosp/packages/apps/Launcher3/src_build_config/com/android/launcher3/BuildConfig.java

增加

java 复制代码
  public static final boolean REMOVE_DRAWER = true;

aosp/packages/apps/Launcher3/src/com/android/launcher3/config/FeatureFlags.java

增加

java 复制代码
public static final boolean REMOVE_DRAWER =  BuildConfig.REMOVE_DRAWER;

禁用上滑打开抽屉应用菜单

aosp/packages/apps/Launcher3/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/PortraitStatesTouchController.java

java 复制代码
 @Override
    protected boolean canInterceptTouch(MotionEvent ev) {
        if(FeatureFlags.REMOVE_DRAWER){
            return false;
        }
 		....
    }

加载所有应用

aosp/packages/apps/Launcher3/src/com/android/launcher3/model/LoaderTask.java

java 复制代码
  public void run() {
  	...
		Trace.beginSection("LoadAllApps");
     List<LauncherActivityInfo> allActivityList;
     try {
        allActivityList = loadAllApps();
     } finally {
         Trace.endSection();
     }
     logASplit(logger, "loadAllApps");

		// 增加
     if (FeatureFlags.REMOVE_DRAWER){
         getAllApplications();
     }

     verifyNotStopped();
     mResults.bindAllApps();
     logASplit(logger, "bindAllApps");
     ...
  }

	private void getAllApplications() {
      Log.d(TAG,"getAllApplications");
      final Context context =mApp.getContext();
      ArrayList<Pair<ItemInfo,Object>> installQueue = new ArrayList<>();
      final List<UserHandle> profiles =mUserManager.getUserProfiles();
      for (UserHandle user : profiles) {
          final List<LauncherActivityInfo> apps = mLauncherApps.getActivityList(null,user);
          ArrayList<ItemInstallQueue.PendingInstallShortcutInfo>added = new ArrayList<ItemInstallQueue.PendingInstallShortcutInfo>();
          synchronized (this) {
              for (LauncherActivityInfo app :apps) {
//                    if(app.getComponentName().getPackageName().equals("com.android.stk")||app.getComponentName().getPackageName().equals("com.android.fmradio")){
//                        continue;
//                    }
                  Log.d(TAG,"getAllApplications packageName: " + app.getComponentName().getPackageName());
                  ItemInstallQueue.PendingInstallShortcutInfo pendingInstallShortcutInfo
                          = new ItemInstallQueue.PendingInstallShortcutInfo(app.getActivityInfo().packageName, user);
                  added.add(pendingInstallShortcutInfo);
                  installQueue.add(pendingInstallShortcutInfo.getItemInfo(context));
              }
          }
          if (!added.isEmpty()) {
              mApp.getModel().addAndBindAddedWorkspaceItems(installQueue);
          }
      }
  }
    

aosp/packages/apps/Launcher3/src/com/android/launcher3/model/ItemInstallQueue.java

java 复制代码
// 修改private为public
 public static class PendingInstallShortcutInfo extends ItemInfo {}

安装的app添加到workspace工作区

aosp/packages/apps/Launcher3/src/com/android/launcher3/model/PackageUpdatedTask.java

java 复制代码
 @Override
    public void execute(@NonNull final LauncherAppState app, @NonNull final BgDataModel dataModel,
            @NonNull final AllAppsList appsList) {
      ...
  		bindApplicationsIfNeeded();
  			
				// 增加
        if(FeatureFlags.REMOVE_DRAWER){
            updateToWorkSpace(context, app,appsList);
        }

        final IntSet removedShortcuts = new IntSet();
        // Shortcuts to keep even if the corresponding app was removed
        final IntSet forceKeepShortcuts = new IntSet();
        ...
		}

		//安装的app添加到workspace工作区
    public void updateToWorkSpace(Context context, LauncherAppState app, AllAppsList appsList){
        Log.d(TAG,"updateToWorkSpace");
        ArrayList<Pair<ItemInfo,Object>> installQueue = new ArrayList<>();
        UserManager mUserManager = app.getContext().getSystemService(UserManager.class);
        final List<UserHandle> profiles = mUserManager.getUserProfiles();
        ArrayList<ItemInstallQueue.PendingInstallShortcutInfo> added = new ArrayList<>();
        LauncherApps mLauncherApps = app.getContext().getSystemService(LauncherApps.class);
        for(UserHandle user : profiles){
            final List<LauncherActivityInfo> apps = mLauncherApps.getActivityList(null,user);
                   synchronized (this){
                        for(LauncherActivityInfo info :apps){
                            for(AppInfo appInfo : appsList.data){
                                String packageName = info.getComponentName().getPackageName();
                                if(info.getComponentName().equals(appInfo.componentName)){
                                   if(DEBUG){
                                       Log.d(TAG,"updateToWorkSpace packageName: " + packageName);
                                   }
                                    ItemInstallQueue.PendingInstallShortcutInfo mPendingInstallShortcutInfo
                                                    = new ItemInstallQueue.PendingInstallShortcutInfo(packageName,user);
                                    added.add(mPendingInstallShortcutInfo);
                                    installQueue.add(mPendingInstallShortcutInfo.getItemInfo(context));
                                }
                            }
                        }
                   }
        }
        if(!added.isEmpty()){
            app.getModel().addAndBindAddedWorkspaceItems(installQueue);
        }
    }

打开限制

清除数据重新加载还能加载图标

aosp/packages/apps/Launcher3/src/com/android/launcher3/model/AddWorkspaceItemsTask.java

java 复制代码
public void execute(@NonNull final LauncherAppState app, @NonNull final BgDataModel dataModel,
            @NonNull final AllAppsList apps) {
...
   // b/139663018 Short-circuit this logic if the icon is a system app
   if (PackageManagerHelper.isSystemApp(app.getContext(),
           Objects.requireNonNull(item.getIntent()))) {
       if (TestProtocol.sDebugTracing) {
           Log.d(TestProtocol.MISSING_PROMISE_ICON,
                   LOG + " Item is a system app.");
       }
       if(!FeatureFlags.REMOVE_DRAWER){
           continue;
       }
   }
...
}

这里不做修改的话如果清除所有数据,那么图标就不会加载

aosp/packages/apps/Launcher3/src/com/android/launcher3/model/BaseModelUpdateTask.java

java 复制代码
  @Override
    public final void run() {
        if (!Objects.requireNonNull(mModel).isModelLoaded()) {
            if (DEBUG_TASKS) {
                Log.d(TAG, "Ignoring model task since loader is pending=" + this);
            }
            // Loader has not yet run.
            if(!FeatureFlags.REMOVE_DRAWER) {
               return;
            }
        }
        execute(mApp, mDataModel, mAllAppsList);
    }

顶部菜单移除remove换成取消cancel,无法移除

remove变成cancel

aosp/packages/apps/Launcher3/src/com/android/launcher3/DeleteDropTarget.java

java 复制代码
 private boolean canRemove(ItemInfo item) {
        // 增加
        if(FeatureFlags.REMOVE_DRAWER) {
            return false ;
        }
        return item.id != ItemInfo.NO_ID;
    }

无法删除图标

aosp/packages/apps/Launcher3/src/com/android/launcher3/dragndrop/DragController.java

java 复制代码
protected void drop(DropTarget dropTarget, Runnable flingAnimation) {
...
 // Drop onto the target.
 boolean accepted = false;
  if (dropTarget != null) {
      dropTarget.onDragExit(mDragObject);
      if (dropTarget.acceptDrop(mDragObject)) {
          if (flingAnimation != null) {
              flingAnimation.run();
          } else {
              dropTarget.onDrop(mDragObject, mOptions);
          }
          accepted = true;    
				 
				 // 增加
          if (FeatureFlags.REMOVE_DRAWER && dropTarget instanceof DeleteDropTarget
             && isNeedCancelDrag(mDragObject.dragInfo)
          ) {
              cancelDrag();
          }
      }
  }

  final View dropTargetAsView = dropTarget instanceof View ? (View) dropTarget : null;
  dispatchDropComplete(dropTargetAsView, accepted);
}

private boolean isNeedCancelDrag(ItemInfo item){
	return (item.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION ||
	    item.itemType == LauncherSettings.Favorites.ITEM_TYPE_FOLDER);
}

Android 13.0 桌面改成单层桌面的代码记录
launcher3去掉抽屉菜单,所有用都放到桌面,无法拖拽删除图标,去除hotseat
Android11去除抽屉模式

相关推荐
mmsx23 分钟前
android 登录界面编写
android·登录界面
姜毛毛-JYM23 分钟前
【JetPack】Navigation知识点总结
android
花生糖@1 小时前
Android XR 应用程序开发 | 从 Unity 6 开发准备到应用程序构建的步骤
android·unity·xr·android xr
是程序喵呀2 小时前
MySQL备份
android·mysql·adb
casual_clover2 小时前
Android 之 List 简述
android·list
锋风Fengfeng3 小时前
安卓15预置第三方apk时签名报错问题解决
android
User_undefined3 小时前
uniapp Native.js原生arr插件服务发送广播到uniapp页面中
android·javascript·uni-app
事后不诸葛4 小时前
安卓音频之dumpsys audio
framework·安卓·audio
程序员厉飞雨4 小时前
Android R8 耗时优化
android·java·前端
丘狸尾6 小时前
[cisco 模拟器] ftp服务器配置
android·运维·服务器