当前位置: 首页 > article >正文

Android BSP 开发之六

1.设定Android settings中某个xml文件(包括其子项)或者某个Preference不被搜索到
 

设定某个xml文件(包括子项)不被搜索到
    找到该xml文件对应的fragment java文件中的SEARCH_INDEX_DATA_PROVIDER,在该provider中对isPageSearchEnabled方法进行重写并返回false.
 

 public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
            new BaseSearchIndexProvider() {
                @Override
                public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
                        boolean enabled) {
                    List<SearchIndexableResource> indexables = new ArrayList<>();
                    SearchIndexableResource indexable = new SearchIndexableResource(context);
                    indexable.xmlResId = R.xml.accessibility_vibration_settings;
                    indexables.add(indexable);
                    return indexables;
                }

                @Override
                protected boolean isPageSearchEnabled(Context context) {
                    return false;
                }
            };

设定特定的Preference不被搜索到
    找到这个特定的Preference对应的xml文件所在的fragment java文件中的SEARCH_INDEX_DATA_PROVIDER, 对该Provider中的getNonIndexableKeys方法进行重写.
 

 public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
            new BaseSearchIndexProvider() {

                @Override
                public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
                        boolean enabled) {
                    List<SearchIndexableResource> indexables = new ArrayList<>();
                    SearchIndexableResource indexable = new SearchIndexableResource(context);
                    indexable.xmlResId = R.xml.accessibility_settings;
                    indexables.add(indexable);
                    return indexables;
                }
                @Override
                public List<String> getNonIndexableKeys(Context context) {
                    final List<String> nonIndexableKeys = super.getNonIndexableKeys(context);
                    nonIndexableKeys.add("vibration_preference_screen"); //这个key为特定preference key
                    return nonIndexableKeys;
                }
            };

2.在长按Power弹出的选项中添加或删除项


    在长按power弹出的选项中添加或删除某一项,在frameworks/base/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java文件中定义一个私有类继承SinglePressAction.
 

private final class BatteryShelfModeAction extends SinglePressAction{
        private BatteryShelfModeAction() {
            super(R.drawable.ic_lock_power_off,    //display icon
                    android.R.string.battery_shelf_mode_title_in_power_menu);  //display icon label
        }

        @Override
        public boolean showDuringKeyguard() {
            return true;
        }

        @Override
        public boolean showBeforeProvisioning() {
            return true;
        }

        @Override
        public void onPress() {
            // enter battery shelf mode
            Intent batteryShelfDialogIntent = new Intent();
            batteryShelfDialogIntent.setComponent(new ComponentName("com.wistron.touchfwupdate", "com.wistron.battery.BatteryShelfMode"));
            batteryShelfDialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            mContext.startActivity(batteryShelfDialogIntent);
        }
    }

GlobalActionsDialog.java文件中的createDialog 方法中找到globalActionsList
 

 mItems = new ArrayList<Action>();
        String[] defaultActions = mContext.getResources().getStringArray(
                R.array.config_globalActionsList);

        ArraySet<String> addedKeys = new ArraySet<String>();
        mHasLogoutButton = false;
        mHasLockdownButton = false;
        for (int i = 0; i < defaultActions.length; i++) {

frameworks/base/core/res/res/values/config.xml中的config_globalActionsList

添加key
 

<string-array translatable="false" name="config_globalActionsList">
        <item>power</item>
        <item>restart</item>
        <item>lockdown</item>
        <item>logout</item>
        <item>bugreport</item>
        <item>screenshot</item>
        <item>shelf_mode</item>
        <item>emergency</item>
    </string-array>

在 GlobalActionsDialog.java文件中的createDialog 方法中添加
 

for (int i = 0; i < defaultActions.length; i++) {
            String actionKey = defaultActions[i];
            if (addedKeys.contains(actionKey)) {
                // If we already have added this, don't add it again.
                continue;
            }
            if (GLOBAL_ACTION_KEY_POWER.equals(actionKey)) {
                mItems.add(new PowerAction());
            } else if (GLOBAL_ACTION_KEY_AIRPLANE.equals(actionKey)) {
                mItems.add(mAirplaneModeOn);
            } else if (GLOBAL_ACTION_KEY_BUGREPORT.equals(actionKey)) {
                if (Settings.Global.getInt(mContext.getContentResolver(),
                        Settings.Global.BUGREPORT_IN_POWER_MENU, 0) != 0 && isCurrentUserOwner()) {
                    mItems.add(new BugReportAction());
                }
            } else if (GLOBAL_ACTION_KEY_SILENT.equals(actionKey)) {
                if (mShowSilentToggle) {
                    mItems.add(mSilentModeAction);
                }
            } else if (GLOBAL_ACTION_KEY_USERS.equals(actionKey)) {
                if (SystemProperties.getBoolean("fw.power_user_switcher", false)) {
                    addUsersToMenu(mItems);
                }
            } else if (GLOBAL_ACTION_KEY_SETTINGS.equals(actionKey)) {
                mItems.add(getSettingsAction());
            } else if (GLOBAL_ACTION_KEY_LOCKDOWN.equals(actionKey)) {
                if (Settings.Secure.getIntForUser(mContext.getContentResolver(),
                            Settings.Secure.LOCKDOWN_IN_POWER_MENU, 0, getCurrentUser().id) != 0
                        && shouldDisplayLockdown()) {
                    mItems.add(getLockdownAction());
                    mHasLockdownButton = true;
                }
            } else if (GLOBAL_ACTION_KEY_VOICEASSIST.equals(actionKey)) {
                mItems.add(getVoiceAssistAction());
            } else if (GLOBAL_ACTION_KEY_ASSIST.equals(actionKey)) {
                mItems.add(getAssistAction());
            } else if (GLOBAL_ACTION_KEY_RESTART.equals(actionKey)) {
                mItems.add(new RestartAction());
            } else if (GLOBAL_ACTION_KEY_SCREENSHOT.equals(actionKey)) {
                mItems.add(new ScreenshotAction());
            } else if (GLOBAL_ACTION_KEY_LOGOUT.equals(actionKey)) {
                if (mDevicePolicyManager.isLogoutEnabled()
                        && getCurrentUser().id != UserHandle.USER_SYSTEM) {
                    mItems.add(new LogoutAction());
                    mHasLogoutButton = true;
                }
            } else if (GLOBAL_ACTION_KEY_EMERGENCY.equals(actionKey)) {
                if (!mEmergencyAffordanceManager.needsEmergencyAffordance()) {
                    mItems.add(new EmergencyDialerAction());
                }
            } else if (GLOBAL_ACTION_KEY_BATTERY_SHELF_MODE.equals(actionKey)) {
//                if (!SystemProperties.get("ro.boot.hwid", "0").equals("0"))
                    mItems.add(new BatteryShelfModeAction());
            }
            else {
                Log.e(TAG, "Invalid global action key " + actionKey);
            }
            // Add here so we don't add more than one.
            addedKeys.add(actionKey);
        }


http://www.kler.cn/news/148401.html

相关文章:

  • 什么是网络爬虫技术?它的重要用途有哪些?
  • 商用车的智慧眼车规级激光雷达
  • java 系统属性和环境属性
  • 计算机网络基础知识自用
  • 【微服务专题】微服务架构演进
  • Spring Boot 3.2.0 虚拟线程初体验 (部分装配解析)
  • Linux内存管理(六十四):ION 内存管理器——system heap
  • VMware虚机重启后静态IP不生效
  • QT linux下应用程序打包
  • uni-app中vue3+setup实现下拉刷新、上拉加载更多效果
  • 角色管理--高级产品经理岗
  • uniapp 导航分类
  • Vue表单的整体处理
  • 成为AI产品经理——模型评估概述
  • GeoTrust证书
  • 96.STL-遍历算法 transform
  • 文章解读与仿真程序复现思路——电力自动化设备EI\CSCD\北大核心《考虑碳排放分摊的综合能源服务商交易策略》
  • HttpRunner原来还能这么用,大开眼界!!!
  • WPF创建进度条
  • 「计算机网络」Cisco Packet Tracker计算机网络仿真器的使用
  • YOLOv5算法进阶改进(5)— 主干网络中引入SCConv | 即插即用的空间和通道维度重构卷积
  • android项目之调用webview
  • TypeScript学习记录
  • LeetCode51. N-Queens
  • java后端实现登录退出功能,并用过滤器验证
  • android trace文件的抓取与查看方法
  • 【Lidar】基于Python的点云数据下采样+体素显示
  • tauri中使用rust调用动态链接库例子(使用libloading库和libc库)
  • ubuntu22.04 arrch64版在线安装java环境
  • C语言-指针讲解(3)