Android11 SystemUI clock plugin 插件入门

插件的编写

参照ExamplePlugin,需要系统签名。

需要先编译以下模块得到jar,引用在项目中。

m SystemUIPluginLib

com.android.systemui.permission.PLUGIN

PluginManager.addPluginListener

SystemUI 是如何发现 clock plugin 的?

SystemUI发现插件的处理流程:

apk安装的广播处理中调用handleQueryPlugins,如果发现有插件,
则handleQueryPlugins调用的PluginInstanceManager的handleLoadPlugin 发送 PLUGIN_CONNECTED 信息 给 listener 比如 ClockManager,ClockManager 通过addOnClockChangedListener发送给KeyguardClockSwitch。

何时会加载插件?

用户解锁的时候
PluginManager.addPluginListener的时候

PluginManager 的功能

开始监听:

    private void startListening() {
        if (mListening) return;
        mListening = true;
        IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
        filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
        filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
        filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
        filter.addAction(PLUGIN_CHANGED);
        filter.addAction(DISABLE_PLUGIN);
        filter.addDataScheme("package");
        mContext.registerReceiver(this, filter);
        filter = new IntentFilter(Intent.ACTION_USER_UNLOCKED);
        mContext.registerReceiver(this, filter);
    }

PluginInstanceManager 就是一个具体的插件的管理类,比如Clock,或者Left button。

如何创建一个PluginInstanceManager

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

加载plugin的关键代码:

PluginManagerImpl:

   /** Returns class loader specific for the given plugin. */
    public ClassLoader getClassLoader(ApplicationInfo appInfo) {
        if (!isDebuggable && !isPluginPackageWhitelisted(appInfo.packageName)) {
            Log.w(TAG, "Cannot get class loader for non-whitelisted plugin. Src:"
                    + appInfo.sourceDir + ", pkg: " + appInfo.packageName);
            return null;
        }
        if (mClassLoaders.containsKey(appInfo.packageName)) {
            return mClassLoaders.get(appInfo.packageName);
        }

        List<String> zipPaths = new ArrayList<>();
        List<String> libPaths = new ArrayList<>();
        LoadedApk.makePaths(null, true, appInfo, zipPaths, libPaths);
        ClassLoader classLoader = new PathClassLoader(
                TextUtils.join(File.pathSeparator, zipPaths),
                TextUtils.join(File.pathSeparator, libPaths),
                getParentClassLoader());
        mClassLoaders.put(appInfo.packageName, classLoader);
        return classLoader;
    }

有哪些插件?

在这里插入图片描述

开机时的QUERY_ALL是怎么发送的?

取决于具体的PluginInstanceManager实例

com.android.systemui.action.PLUGIN_LOCKSCREEN_LEFT_BUTTON

在这里插入图片描述

KeyguardAffordanceView ,左边是Phone,右边是Camera.

拖到的圆形动画的实现:

在这里插入图片描述

控制是否显示:

   <!-- Show mic or phone affordance on Keyguard -->
    <bool name="config_keyguardShowLeftAffordance">false</bool>

    <!-- Show camera affordance on Keyguard -->
    <bool name="config_keyguardShowCameraAffordance">false</bool>

LeftButton 的实现效果

在这里插入图片描述

为什么显示的是白色?原因如下:

 val  loading = this.resources.getDrawable(R.drawable.loading_quan,this.theme)
        loading.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
        binding.imageView.setImageDrawable(loading)

插件apk需要push到system/app下

scp andy@192.168.16.128:android11/out/target/product/Tinker_Board_2/system/app/Left/Left.apk  .
adb root
adb remount
adb shell rm  -r /system/app/Left/
adb shell  mkdir  /system/app/Left
adb  push  Left.apk  /system/app/Left/
adb reboot
pause

相关推荐

  1. Android Gradle的

    2024-04-23 18:12:01       28 阅读
  2. 开发Chrome入门

    2024-04-23 18:12:01       38 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-23 18:12:01       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-23 18:12:01       106 阅读
  3. 在Django里面运行非项目文件

    2024-04-23 18:12:01       87 阅读
  4. Python语言-面向对象

    2024-04-23 18:12:01       96 阅读

热门阅读

  1. Python中的Map函数:简化你的循环和函数调用

    2024-04-23 18:12:01       38 阅读
  2. Python网络爬虫项目开发实战:怎么处理下载缓存

    2024-04-23 18:12:01       37 阅读
  3. 浏览器原理之浏览器同源策略

    2024-04-23 18:12:01       33 阅读
  4. Vim编辑器命令使用总结

    2024-04-23 18:12:01       45 阅读
  5. PHP 判断文件是否存在

    2024-04-23 18:12:01       33 阅读
  6. 汇编期末复习知识点

    2024-04-23 18:12:01       38 阅读
  7. 在Linux系统中,如何查看当前登录的用户

    2024-04-23 18:12:01       36 阅读
  8. DreamFusion都在什么地方用

    2024-04-23 18:12:01       36 阅读
  9. 【LeetCode热题100】【链表】合并 K 个升序链表

    2024-04-23 18:12:01       35 阅读
  10. GB4806.13食品接触复合材料广东实验室

    2024-04-23 18:12:01       36 阅读
  11. 基础技术(MapStruct、SPI、TK-Mybatis)

    2024-04-23 18:12:01       38 阅读