Android13 Framework隐藏某些App
设备开发中,有的要带通话功能,有的不带通话功能。则需要隐藏对应的一些App。
实现以上功能需要在,抽屉里隐藏,抽屉里的上层应用推荐隐藏,Setting 全部显示全部App的设置里隐藏。
QSSI.13/packages/apps/Launcher3/src/com/android/launcher3/AppFilter.java
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {Context context = app.getContext();
....
for (AppTarget target : mTargets) {WorkspaceItemInfo itemInfo;ShortcutInfo si = target.getShortcutInfo();String className = target.getClassName();if(status==0){if (className.contains("org.yyyy.xx") ||className.contains("com.google.android.apps.messaging") ||className.contains("com.google.android.contacts")) {continue;}}
QSSI.13/packages/apps/Settings/src/com/android/settings/applications/manageapplications/ManageApplications.java
@Overridepublic void onRebuildComplete(ArrayList<AppEntry> entries) {if (DEBUG) {Log.d(TAG, "onRebuildComplete size=" + entries.size());}// Preload top visible icons of app list.AppUtils.preloadTopIcons(mContext, entries,mContext.getResources().getInteger(R.integer.config_num_visible_app_icons));final int filterType = mAppFilter.getFilterType();if (filterType == FILTER_APPS_POWER_ALLOWLIST|| filterType == FILTER_APPS_POWER_ALLOWLIST_ALL) {entries = removeDuplicateIgnoringUser(entries);}mEntries = entries;hideSomeApp()}private void hideSomeApp() {if(!hasPhone(mContext)){int remove = 0;Iterator<ApplicationsState.AppEntry> iterator = mEntries.iterator();while (iterator.hasNext()) {ApplicationsState.AppEntry appEntry = iterator.next();String pkgName = appEntry.info.packageName;if (pkgName.equals("org.xxxx.yyyy")//|| pkgName.equals("com.google.android.apps.messaging")|| pkgName.equals("com.google.android.contacts")) {iterator.remove();remove++;}if (remove == 3) {break;}}}}
QSSI.13/packages/apps/Launcher3/quickstep/src/com/android/launcher3/model/PredictionUpdateTask.java
public boolean shouldShowApp(ComponentName app) {String packageName = app.getPackageName();// String clzName = app.getClassName();
// Log.e(TAG, "packageName ============ " + packageName);
// Log.e(TAG, "clzName ============ " + clzName);if(!hasPhone(context)){if (packageName.equals("org.xxx.yyyy") || packageName.equals("com.google.android.apps.messaging")|| packageName.equals("com.google.android.contacts")) {return false;}}//com.google.android.apps.messagingreturn !mFilteredComponents.contains(app);}
可以在Setting设置参数里添加一个参数,进行判断,可以动态的配置功能。
public boolean hasPhone(Context context) {//0:未启用 1:启用int phoneStatus = android.provider.Settings.Global.getInt(context.getContentResolver(), "xxxYYYY", 0);if (phoneStatus == 0) {return false;} else {return true;}}