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去除抽屉模式

相关推荐
Dnelic-3 小时前
【单元测试】【Android】JUnit 4 和 JUnit 5 的差异记录
android·junit·单元测试·android studio·自学笔记
Eastsea.Chen5 小时前
MTK Android12 user版本MtkLogger
android·framework
长亭外的少年12 小时前
Kotlin 编译失败问题及解决方案:从守护进程到 Gradle 配置
android·开发语言·kotlin
建群新人小猿15 小时前
会员等级经验问题
android·开发语言·前端·javascript·php
1024小神16 小时前
tauri2.0版本开发苹果ios和安卓android应用,环境搭建和最后编译为apk
android·ios·tauri
兰琛16 小时前
20241121 android中树结构列表(使用recyclerView实现)
android·gitee
Y多了个想法17 小时前
RK3568 android11 适配敦泰触摸屏 FocalTech-ft5526
android·rk3568·触摸屏·tp·敦泰·focaltech·ft5526
NotesChapter18 小时前
Android吸顶效果,并有着ViewPager左右切换
android
_祝你今天愉快19 小时前
分析android :The binary version of its metadata is 1.8.0, expected version is 1.5.
android
暮志未晚Webgl19 小时前
109. UE5 GAS RPG 实现检查点的存档功能
android·java·ue5