Android Kernel

说到 Android Kernel 那就不得不说到 Linux Kernel,Android Kernel 基于 Linux Kernel 的长期稳定版本

Linux Kernel

首先 Linux Kernel 是什么? Linux Kernel 是在 GNU GPL v2 开源许可下开源的硬件底层驱动,包括了 CPU 调度,存储管理,IO 管理,等等。Linux Kernel 是 GPL 开源,所以为了适用移动设备内存,CPU 频率,耗电等特点,Google 将这部分 Linux Kernel 做了修改,并按照 GPL 将修改开源了。

The kernel has complete control over the system.

Android 最早的内核是基于 Linux 2.6 内核的,在很长一段时间内,Android 的 Kernel 一直使用非常老版本的 Linux Kernel,但是随着时间发展,渐渐的每一个版本的 Android 发布都再使用最新的 Linux Kernel 1.

Android Kernel

回到 Android Kernel,不同设别出厂的时候就会带一个 stock 官方的 kernel,当然这个 Kernel 是稳定可以用于日常使用的。但是有些官方优化的 Kernel 并没有发挥硬件的最佳,所以 xda 上就有很多人发布不同的 Kernel,可以支持一些电池的优化,或者对硬件一些更好的支持。

ElementalX

ElementalX 内核是一个我从 Nexus 6, OnePlus 3 开始就使用过的 Kernel,由 flar2 开发。

ElementalX 内核的突出特点就是稳定,在不牺牲稳定性的前提下对系统做一些优化,比如滑动手势,亮度模式,震动模式,声音控制,文件系统格式等等。

个人使用的情况也是非常稳定,没有遇到过任何硬件不兼容问题。

Franco Kernel

Franco Kernel 由 franciscofranco 开发,是非常著名的一个 Kernel,支持非常多的设备。

blu_spark

blu_spark kernel 由 eng.stk 开发。

更多的 kernel 可以查阅这里

reference


2019-06-07 android , kernel , linux-kernel , aosp

OnePlus 7 Pro 折腾记

OnePlus 7 Pro 折腾记。

Unlock Bootloader

先前准备:

  • 备份数据,具体可以使用 adb 命令,见后文
  • 开启开发者模式,Settings -> About Phone -> 点击 Build Number 7 次
  • 调试模式,Settings -> Developer option -> Enable USB Debugging
  • 开启 OEM Unlocking,Settings -> Developer options -> OEM Unlocking 开启
  • PC 上安装 fastboot 工具

具体步骤

  • 数据线连接手机,adb devices 确认连接成功
  • 手机出现 Debug 对话框,确认
  • 进入 bootloader 模式,adb reboot bootloader
  • fastboot devices
  • fastboot oem unlock
  • 然后使用音量键选择,重启
  • 等待重启完毕就 OK 了

Root OnePlus 7 Pro with patched Boot Image

在 root 之前需要注意

  • 使用原生 OOS
  • Unlocked bootloader
  • fastboot 工具

然后根据一下流程:

  • 根据自己的版本 GM1910,系统版本 Oxygen OS 9.5.6 下载 patched boot image,或者自己制作 patched boot image
  • 安装最新的 Magisk Manager
  • adb reboot bootloader 进入 fastboot mode
  • fastboot devices
  • 如果担心下错 boot image,可以尝试使用 fastboot boot boot.img 来用本地的 image 文件启动
  • 确认没有问题之后,刷入 fastboot flash boot boot_patched.img
  • fastboot reboot 重启
  • 打开 Magisk ,安装,使用 Direct Install
  • 这样就有了一个 root 的 OnePlus 7 Pro

From: xda

Magisk

From: xda

更新系统 OTA 之后保留 recovery root 等

  • 使用全量包更新,然后在 System , System, 设置中使用本地更新,切记更新完成不要立即重启
  • 打开 Magisk ,点击 Magisk 一行的安装,在弹出的对话框中点击安装
  • 然后在弹出的对话框 (select Method) 中选择 Install to Inactive Slot (After OTA) 选项 (中文应该是,安装到未使用的槽位,安装完 OTA 后)
  • 最后安装重启

使用 adb 备份数据

使用 adb 备份数据的时候千万注意,adb 备份的数据恢复时不会自动安装应用,并且可能恢复不完整。如果可能还是使用 Titanium Backup (ROOT) 等专业工具备份和恢复。

adb backup -apk -shared -all -f op7pro-backup-file.ad

参数解释:

  • -apk|-noapk 是否备份包含 apk 或者仅仅备份应用数据,推荐使用 -apk 选项,默认为 -noapk
  • -shared|-noshared 决定是否备份设备共享的 SD 卡内容,默认为 -noshared,主要包括内部存储中的音乐,图片和视频等,推荐使用 -shared
  • -all 备份所有应用
  • -system|-nosystem 决定 -all 选项是否包含系统应用,默认是 -system
  • -f 后面需要指定路径及文件名,表示用来存储的位置,比如 -f /path/backup.file 那么会存储在 path 目录下名为 backup.file 的文件中

恢复数据

设备连接电脑,adb devices 查看连接成功

adb restore op7pro-backup-file.ad

如果想要手动解开这个备份文件,可以参考这个项目

一些问题

GM 版本问题

氧系统有好几个版本的全量 ROM, GM21AA,GM21BA。这两个版本的含义是:

  • 标记有 GM21AA 的包适用于印度、全球(不含欧洲)、美国的无锁版 Model

      - GM1911: India
      - GM1917: Global/US Unlocked (?)
    
  • GM21BA 欧洲销售版本

      - GM1913: EU
    
  • GM27BA EU 5G 版本,GM 1915
  • GM31CB GM1915 T-Mobile (Carrier Locked)

adb 连接问题

adb 之前保证打开开发者模式,并且设置中确保设置打开,

adb devices
List of devices attached
5fxxxxxx	no permissions (verify udev rules); see [http://developer.android.com/tools/device.html]

在使用 adb 连接的时候如果遇到这个问题,那么在通知栏中,换一种 USB 连接模式,保证非充电模式。如果还不行可以尝试

adb kill-server
adb start-server

更多关于 adb 和 fastboot 命令的使用可以参考之前的 adb 文章fastboot 文章


2019-06-02 oneplus , android , root , magisk , adb

Java 定时任务框架 Job-scheduling Quartz 使用

Quartz is a richly featured, open source job scheduling library that can be integrated within virtually any Java application - from the smallest stand-alone application to the largest e-commerce system.

Setup

<dependency>
    <groupId>org.quartz-scheduler</groupId>
    <artifactId>quartz</artifactId>
    <version>2.2.1</version>
</dependency>

Usage

客户端调用

JobDetail job = newJob(MyJob.class)
    .withIdentity("myJob")
    .build();

Trigger trigger = newTrigger()
    .withIdentity(triggerKey("myTrigger", "myTriggerGroup"))
    .withSchedule(simpleSchedule()
        .withIntervalInHours(1)
        .repeatForever())
    .startAt(futureDate(10, MINUTES))
    .build();

scheduler.scheduleJob(job, trigger);

Source Code

StdSchedulerFactory 是 Scheduler 的工厂方法,实现了 SchedulerFactory 接口。

// 提供客户端可用的 Scheduler
Scheduler getScheduler() throws SchedulerException;
// 通过名字获取
Scheduler getScheduler() throws SchedulerException;
// 返回当前 JVM 中通过该 Factory 创建的所有 Scheduler
Collection<Scheduler> getAllSchedulers() throws SchedulerException;

SchedulerRepository 单例,内部持有一个 Map HashMap<String, Scheduler> schedulers

类中,绑定 (bind),解绑 (remove) 都为同步方法,保证线程安全。

Scheduler

Scheduler 是一个很庞大的接口,它的实现主要有

  • RemoteScheduler, via RMI
  • StdScheduler, std
  • JBoss4RMIRemoteMBeanScheduler, via JBoss’s JMX RMIAdaptor

Quartz 的核心实现也基本都在这些实现类中,Scheduler 可以用来定时触发任务。

CronScheduleBuilder

CronScheduleBuilder 用来将字符串的 cron 表达式变成 CronScheduleBuilder 对象,ScheduleBuilder 是一个抽象类

public class CronScheduleBuilder extends ScheduleBuilder<CronTrigger> {
    public static CronScheduleBuilder cronSchedule(String cronExpression) { }
}

主要的实现有:

  • CronScheduleBuilder 主要实现 cron 定时任务,通过字符表达式
  • SimpleScheduleBuilder 比较简单的 ScheduleBuilder
  • CalendarIntervalScheduleBuilder 看例子 withIntervalInDays(3) 每隔 3 天,如果要使用固定间隔的可以看一下这个
  • DailyTimeIntervalScheduleBuilder 看例子比较简单 onDaysOfTheWeek(MONDAY, THURSDAY) , 每一个周一和周四

比如

CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(job.getCronExpr());
trigger = TriggerBuilder.newTrigger().withIdentity(triggerId).withSchedule(scheduleBuilder)
    .forJob(jobDetail).build();
scheduler.scheduleJob(jobDetail, trigger);

2019-05-30 java , quartz , schedule , cronjob

jbpm 中 ProcessEventListener 顺序问题

在 jBPM 商业流程中有一个 ProcessEventListener ,可以用来回调流程的执行过程,但是这个 Listener 的执行顺序非常奇怪。

首先我们先看看这个 interface

public interface ProcessEventListener {

  void beforeProcessStarted( ProcessStartedEvent event );
  void afterProcessStarted( ProcessStartedEvent event );
  void beforeProcessCompleted( ProcessCompletedEvent event );
  void afterProcessCompleted( ProcessCompletedEvent event );
  void beforeNodeTriggered( ProcessNodeTriggeredEvent event );
  void afterNodeTriggered( ProcessNodeTriggeredEvent event );
  void beforeNodeLeft( ProcessNodeLeftEvent event );
  void afterNodeLeft( ProcessNodeLeftEvent event );
  void beforeVariableChanged(ProcessVariableChangedEvent event);
  void afterVariableChanged(ProcessVariableChangedEvent event);

}

我相信大多数人看到这些方法回调大致可以猜测 afterProcessStarted 应该是在流程开始之后被调用,然而实际的调用顺序是这样的:

- beforeProcessStarted
  - beforeNodeTriggered
    - beforeNodeLeft
      - beforeNodeTriggered
        - beforeVariableChanged
          afterVariableChanged
        - beforeNodeLeft
          - beforeNodeTriggered
            - beforeNodeLeft
              - beforeNodeTriggered
                afterNodeTriggered
              afterNodeLeft
            - beforeNodeLeft
                beforeNodeTriggered
                afterNodeTriggered
              afterNodeLeft
            afterNodeTriggered
          afterNodeLeft
        afterNodeTriggered
      afterNodeLeft
    afterNodeTriggered
  afterProcessStarted

afterProcessStarted 会在流程结束时被调用。有人提过 bug 但是官方认为这是程序设计,所以使用文档的形式 将这种方式说明了。

查看源代码可以在 RuleExecutor 中可以看到:

jbpm listener

实验

假设有如下图的流程

jbpm process

那么打印所有的日志可以观察到:

- DefaultRuleContainer beforeVariableChanged ==>[ProcessVariableChanged(id=age; instanceId=age; oldValue=null; newValue=18; processName=BPTest; processId=FlowTest.BPTest)]
- DefaultRuleContainer afterVariableChanged ==>[ProcessVariableChanged(id=age; instanceId=age; oldValue=null; newValue=18; processName=BPTest; processId=FlowTest.BPTest)]
- DefaultRuleContainer beforeProcessStarted ==>[ProcessStarted(name=BPTest; id=FlowTest.BPTest)]
- event ==>[ProcessStarted(name=BPTest; id=FlowTest.BPTest)]
- DefaultRuleContainer beforeNodeTriggered ==>[ProcessNodeTriggered(nodeId=4; id=0; nodeName=StartPoint; processName=BPTest; processId=FlowTest.BPTest)]
- DefaultRuleContainer beforeNodeLeft ==>[ProcessNodeLeft(nodeId=4; id=0; nodeName=StartPoint; processName=BPTest; processId=FlowTest.BPTest)]
- DefaultRuleContainer beforeNodeTriggered ==>[ProcessNodeTriggered(nodeId=7; id=1; nodeName= 年龄是否大于 18; processName=BPTest; processId=FlowTest.BPTest)]
- DefaultRuleContainer beforeNodeLeft ==>[ProcessNodeLeft(nodeId=7; id=1; nodeName= 年龄是否大于 18; processName=BPTest; processId=FlowTest.BPTest)]
- DefaultRuleContainer beforeNodeTriggered ==>[ProcessNodeTriggered(nodeId=2; id=2; nodeName=A1Task; processName=BPTest; processId=FlowTest.BPTest)]
- DefaultRuleContainer beforeNodeLeft ==>[ProcessNodeLeft(nodeId=2; id=2; nodeName=A1Task; processName=BPTest; processId=FlowTest.BPTest)]
- DefaultRuleContainer beforeNodeTriggered ==>[ProcessNodeTriggered(nodeId=6; id=3; nodeName=A2Task; processName=BPTest; processId=FlowTest.BPTest)]
- DefaultRuleContainer beforeNodeLeft ==>[ProcessNodeLeft(nodeId=6; id=3; nodeName=A2Task; processName=BPTest; processId=FlowTest.BPTest)]
- DefaultRuleContainer beforeNodeTriggered ==>[ProcessNodeTriggered(nodeId=3; id=4; nodeName=End; processName=BPTest; processId=FlowTest.BPTest)]
- DefaultRuleContainer beforeNodeLeft ==>[ProcessNodeLeft(nodeId=3; id=4; nodeName=End; processName=BPTest; processId=FlowTest.BPTest)]
- DefaultRuleContainer beforeProcessCompleted ==>[ProcessCompleted(name=BPTest; id=FlowTest.BPTest)]
- DefaultRuleContainer afterProcessCompleted ==>[ProcessCompleted(name=BPTest; id=FlowTest.BPTest)]
- event ==>[ProcessCompleted(name=BPTest; id=FlowTest.BPTest)]
- DefaultRuleContainer afterNodeLeft ==>[ProcessNodeLeft(nodeId=3; id=4; nodeName=End; processName=BPTest; processId=FlowTest.BPTest)]
- DefaultRuleContainer afterNodeTriggered ==>[ProcessNodeTriggered(nodeId=3; id=4; nodeName=End; processName=BPTest; processId=FlowTest.BPTest)]
- DefaultRuleContainer afterNodeLeft ==>[ProcessNodeLeft(nodeId=6; id=3; nodeName=A2Task; processName=BPTest; processId=FlowTest.BPTest)]
- DefaultRuleContainer afterNodeTriggered ==>[ProcessNodeTriggered(nodeId=6; id=3; nodeName=A2Task; processName=BPTest; processId=FlowTest.BPTest)]
- DefaultRuleContainer afterNodeLeft ==>[ProcessNodeLeft(nodeId=2; id=2; nodeName=A1Task; processName=BPTest; processId=FlowTest.BPTest)]
- DefaultRuleContainer afterNodeTriggered ==>[ProcessNodeTriggered(nodeId=2; id=2; nodeName=A1Task; processName=BPTest; processId=FlowTest.BPTest)]
- DefaultRuleContainer afterNodeLeft ==>[ProcessNodeLeft(nodeId=7; id=1; nodeName= 年龄是否大于 18; processName=BPTest; processId=FlowTest.BPTest)]
- DefaultRuleContainer afterNodeTriggered ==>[ProcessNodeTriggered(nodeId=7; id=1; nodeName= 年龄是否大于 18; processName=BPTest; processId=FlowTest.BPTest)]
- DefaultRuleContainer afterNodeLeft ==>[ProcessNodeLeft(nodeId=4; id=0; nodeName=StartPoint; processName=BPTest; processId=FlowTest.BPTest)]
- DefaultRuleContainer afterNodeTriggered ==>[ProcessNodeTriggered(nodeId=4; id=0; nodeName=StartPoint; processName=BPTest; processId=FlowTest.BPTest)]
- DefaultRuleContainer afterProcessStarted ==>[ProcessStarted(name=BPTest; id=FlowTest.BPTest)]

reference


2019-05-23 jbpm , drools , business-process , rule , rule-engine

每天学习一个命令:pidstat 查看进程消耗资源

The pidstat command is used for monitoring individual tasks currently being managed by the Linux kernel.

installation

apt-get install sysstat

usage

pidstat [options] [interval] [times]

Most common use options:

  • -r show memory usage
  • -d show io usage per process id
  • -p PID specify PID

Examples

Show CPU usage of all process

pidstat -p ALL
pidstat

Show memory usage

Following command will display PID memory usage 10 times every 2 seconds:

pidstat -r -p PID 2 10

Result fields:

  • PID
  • Minflt/s
  • Majflt/s
  • VSZ virtual memory usage KB
  • RSS KB
  • Command task name

show IO usage

pidstat -d -p PID

Result field:

  • PID
  • kB_rd/s read from disk each second KB
  • kB_wr/s write to disk each second KB
  • kB_ccwr/s
  • Command task name

reference


2019-05-14 linux , commmand , network

每天学习一个命令:pidof 查找进程 PID

pidof finds the process id’s(pids) of the names programs.

Usage

pidof [name]

Example

find chrome pid

pidof chrome
pidof -s chrome

Options:

  • -s instructs the program to only return one pid.

Extension

  • pgrep

2019-05-14 pid , netstat , command , linux

Cross-platform Softwares I am using

This post will only list cross-platform softwares I used now. Each software has its own behaviors, and binded with its own shortcut. It takes time to be familiar with it. So I decided to use only cross-platform softwares in daily life in case I have to swith my main System. But it seems fine till now. I am happy with these great softwares.

IntelliJ IDEA

DescriptionIntelliJ IDEA is a Java integrated development environment for developing computer software. It is developed by JetBrains, and is available as an Apache 2 Licensed community edition, and in a proprietary commercial edition. Both can be used for commercial development.

Open Sources Alternatives:

  • Eclipse

Chrome

DescriptionGoogle Chrome is a cross-platform web browser developed by Google. It was first released in 2008 for Microsoft Windows, and was later ported to Linux, macOS, iOS, and Android. The browser is also the main component of Chrome OS, where it serves as the platform for web apps.

Alternatives:

  • vivaldi

SmartGit

SmartGit is a Git GUI client with support for SVN, GitHub, BitBucket pull requests and comments.

WizNote

WizNote for Windows/Mac/Linux is a cross-platform cloud based note-taking client.

GoldenDict

GoldenDict is an open-source dictionary program that gives translations of words and phrases for different languages. It allows the use of several popular dictionary file formats simultaneously and without conversion. The project aims to create a feature-rich dictionary search program.

TeamViewer

TeamViewer is proprietary software for remote control, desktop sharing, online meetings, web conferencing and file transfer between computers.

pCloud

pCloud is the secure cloud storage, where you can store, share and work on all your files.

Crypt

VeraCrypt is a source-available freeware utility used for on-the-fly encryption. It can create a virtual encrypted disk within a file or encrypt a partition or the entire storage device with pre-boot authentication. VeraCrypt is a fork of the discontinued TrueCrypt project.

TagSpace

TagSpaces is an open-source data manager and file navigator. It helps organize files on local drives by adding tags to files. Users get the same user interface to manage their files on different platforms. TagSpaces is compatible with Windows, Linux, Mac, Android, iPhone, Firefox and Chrome.

Calibre

Calibre is a cross-platform open-source suite of e-book software. Calibre supports organizing existing e-books into virtual libraries, displaying, editing, creating and converting e-books, as well as syncing e-books with a variety of e-readers. Editing books is supported for EPUB and AZW3 formats.

Telegram

Telegram is a cloud-based instant messaging and voice over IP service developed by Telegram Messenger LLP, a privately held company registered in London, United Kingdom, founded by the Russian entrepreneur Pavel Durov and his brother Nikolai.

Etcher

Etcher is a powerful OS image flasher built with web technologies to ensure flashing an SDCard or USB drive is a pleasant and safe experience.


2019-05-10 applications , apps

使用 Stylus 扩展自定义页面样式

有油猴脚本可以用来修改网页页面,那么相应的也能通过挂载自己的定义的 CSS 来实现对页面的修改。

如果有了这样的概念,那么可以在页面做到,完全修改页面显示的样式,增加背景,移除广告等等事情。

installation

安装扩展

CSS 样式

从该站点寻找可用的样式

InoReader

  • https://userstyles.org/styles/119240/inoreader-countrystyle-flat-ui-remove-ads

reference


2019-05-08 stylus , css , chrome , firefox , extension

Cinnamon alt+f2 命令

很早就开始用 Cinnamon 作为 Linux 的主要桌面环境,还折腾过 Cinnamon 的主题,但是其实一直没怎么关注 Alt + F2 的功能,唯一知道的命令就是 r 用来重启 Cinnamon。所以这里就总结总结 Alt+F2 可以用的命令。

内置命令

-‘r’ - restart Cinnamon

  • ‘rt’ - reload the current Cinnamon theme
  • ‘lg’ - start the Looking Glass debugger (which itself seems not to be documented anywhere)

任何 Xwindows 应用

在 Alt + F2 下运行无界面的命令,比如 ls 可能得不到任何结果,但是可以运行比如 firefox 这样有窗口的命令。该命令需要在 PATH 下。

快速打开文件夹

在 Alt + F2 窗口下输入文件目录可以快速使用默认文件浏览器打开该目录。


2019-04-29 cinnamon , commands

The Silver Searcher 使用

Once I wrote a post about ack-grep, and Franklin Yu left a comment about the silver searcher. He said this tool is much faster than the ack-grep. So this post is about The Silver Searcher. As always, I will introduce what is the Silver Searcher, how to install and use it.

Follow the link, we can see that author claim that this tool started off as a clone of ack, but then diverged slightly. And in most case, this tool is 5-10x faster then ack.

Installation

Find the download link at official site.

apt-get install silversearcher-ag

Usage

ag [file-type] [options] PATTERN [PATH]

As the man describe, recursively search for PATTERN in PATH.

Usage

Most options are similar to grep, like -i, -v, -B, -A etc

Find text under a path

most use case will be find a keyword from a bunch of files. 最常用的一个方式便是在目录中搜索关键词,ag 能够非常快速的搜索文件内容,所以非常适合查询日志,或者代码等文本文件。

ag keyword /path/to/

Count the matches of keywords

ag -c keyword /path/

自定义查询深度

Default depth is 25, if you want unlimited, you should use -1

ag --depth NUM keyword .

查找包含关键字的文件名

If you forget the filename, but only remeber only few letters, you can use -g to print only filenames.

-g 选项表示查询文件名,而不会去查询文件内容。比如说想要查询目录下文件名中包含 Pattern 的文件名,那么可以使用:

ag -g PATTERN .

results will be only filenames. 这样结果就只会打印出符合的文件名。

打印出包含关键字的文件名

上面 -g 选项只会去查询文件名,那么如果想要查找内容中包含某个关键字的文件名,可以使用 -l 选项:

ag -l 'pattern' /path/to

使用 -L 会显示没有匹配的文件名

在特定的文件中查询

ag 提供了 -G 选项,可以用来缩小查询的范围,-G PATTERN 可以指定 Pattern,那么 ag 只会在 -G 指定的文件中查询,比如只查询 .+\.java.java 结尾的文件。

ag -G ".+\.java" "string to search" /path/to

For more details, you can check man ag

reference


2019-04-25 ack-grep , search , grep

电子书

最近文章