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

相关推荐
- 羊羊不超越 -3 分钟前
App渠道来源追踪方案全面分析(iOS/Android/鸿蒙)
android·ios·harmonyos
wk灬丨44 分钟前
Android Kotlin Flow 冷流 热流
android·kotlin·flow
千雅爸爸44 分钟前
Android MVVM demo(使用DataBinding,LiveData,Fresco,RecyclerView,Room,ViewModel 完成)
android
晨曦_子画1 小时前
编程语言之战:AI 之后的 Kotlin 与 Java
android·java·开发语言·人工智能·kotlin
孤客网络科技工作室2 小时前
AJAX 全面教程:从基础到高级
android·ajax·okhttp
Mr Lee_3 小时前
android 配置鼠标右键快捷对apk进行反编译
android
顾北川_野3 小时前
Android CALL关于电话音频和紧急电话设置和获取
android·音视频
&岁月不待人&4 小时前
Kotlin by lazy和lateinit的使用及区别
android·开发语言·kotlin
Winston Wood5 小时前
Android Parcelable和Serializable的区别与联系
android·序列化
清风徐来辽6 小时前
Android 项目模型配置管理
android