diff --git a/README.md b/README.md index 8c849c8a..e20c9754 100644 --- a/README.md +++ b/README.md @@ -36,3 +36,12 @@ hexo s ```script hexo d ``` + + + +##### 建站记录 + + +数学公式的支持: +需要手动安装pandoc程序 +https://github.com/theme-next/hexo-theme-next/blob/master/docs/zh-CN/MATH.md \ No newline at end of file diff --git a/source/_drafts/android-aosp-binder.md b/source/_drafts/android-aosp-binder.md new file mode 100644 index 00000000..ecf5c5ad --- /dev/null +++ b/source/_drafts/android-aosp-binder.md @@ -0,0 +1,63 @@ +--- +title: Android Binder +tags: Android +------------- + +一、Binder是什么 + +
+ +
+ ++ An IPC/component system for developing object-oriented OS services + - Not yet another object-oriented kernel + - Instead an object-oriented operating system environment that works on traditional kernels, like Linux! + ++ Essential to Android! ++ Comes from OpenBinder + - Started at Be, Inc. as a key part of the "next generation BeOS" (~ 2001) + - Acquired by PalmSource + - First implementation used in Palm Cobalt (micro-kernel based OS) + - Palm switched to Linux, so Binder ported to Linux, open-sourced (~ 2005) + - Google hired Dianne Hackborn, a key OpenBinder engineer, to join the Android team + - Used as-is for the initial bring-up of Android, but then completely rewritten (~ 2008) + - OpenBinder no longer maintained - long live Binder! + ++ Focused on scalability, stability, flexibility, low-latency/overhead, easy programming model + +二、IPC + ++ Inter-process communication (IPC) is a framework for the exchange of signals and data across multiple processes ++ Used for message passing, synchronization, shared memory, and remote procedure calls (RPC) ++ Enables information sharing, computational speedup, modularity, convenience, privilege separation, data isolation, stability + - Each process has its own (sandboxed) address space, typically running under a unique system ID ++ Many IPC options + - Files (including memory mapped) + - Signals + - Sockets (UNIX domain, TCP/IP) + - Pipes (including named pipes) + - Semaphores + - Shared memory + - Message passing (including queues, message bus) + - Intents, ContentProviders, Messenger + - Binder! + + +三、为什么使用Binder + + + + + + + + + + + + + + +
+ +
\ No newline at end of file diff --git a/source/_drafts/android-aosp-event-loop.md b/source/_drafts/android-aosp-event-loop.md deleted file mode 100644 index a1f1fa53..00000000 --- a/source/_drafts/android-aosp-event-loop.md +++ /dev/null @@ -1,18 +0,0 @@ ---- -title: 事件循环 -tags: -- Android ---------- - - -一、相关类和结构 - - -二、 - - -Epoll 实现原理 -https://www.jxhs.me/2021/04/08/linux%E5%86%85%E6%A0%B8Epoll-%E5%AE%9E%E7%8E%B0%E5%8E%9F%E7%90%86/ - -【原创】Linux select/poll机制原理分析 -https://www.cnblogs.com/LoyenWang/p/12622904.html \ No newline at end of file diff --git a/source/_drafts/android-basic-app-widgets.md b/source/_drafts/android-basic-app-widgets.md index e8d56146..3563044a 100644 --- a/source/_drafts/android-basic-app-widgets.md +++ b/source/_drafts/android-basic-app-widgets.md @@ -25,14 +25,10 @@ tags: 1.4 设计指引 + 小部件内容 小部件是吸引用户进入app的绝佳机制。 - - + 小部件导航 将用户导航到常用功能,快速完成用户的意图。 - + 小部件的尺寸 长按并放手进入大小调节模式。通过尺寸变化,控制信息的展示量。 - + 布局注意事项 根据设备网格的分辨率来摆放布局。记住以下几点: @@ -56,7 +52,7 @@ tags: #### 二、创建简单的小部件 -2.1 小部件元器件 +##### 2.1 涉及的类 + `AppWidgetProviderInfo` 描述小部件元信息,布局、更新频率等 + `AppWidgetProvider` @@ -64,7 +60,7 @@ tags:
- +
除了基本的元器件,如果你的小部件需要用户配置信息,你需要提供配置修改界面让用户修改配置,如钟表小部件的时区修改。 @@ -72,8 +68,7 @@ tags: + Android-11及以前,每次添加小部件都启动配置页。 -2.2 声明`AppWidgetProviderInfo` - +##### 2.2 声明`AppWidgetProviderInfo` 在res/xml/声明: ```xml + + + + + +``` + +2.3.2 实现`AppWidgetProvider`类 ++ onUpdate() ++ onAppWidgetOptionsChanged() ++ onDeleted(Context, int[]) ++ onEnabled(Context) ++ onDisabled(Context) ++ onReceive(Context, Intent) + +其中`onUpdate()`回调尤为重要。 + + +2.3.3 接收小部件广播意图 ++ ACTION_APPWIDGET_UPDATE ++ ACTION_APPWIDGET_DELETED ++ ACTION_APPWIDGET_ENABLED ++ ACTION_APPWIDGET_DISABLED ++ ACTION_APPWIDGET_OPTIONS_CHANGED + + + +##### 2.4 创建布局 +布局基于RemoteViews实现,不能使用自定义view。也不能使用RemoteViews支持的类的子类。但它支持ViewStub。 + +2.4.1 对状态行为的支持 +Android-12支持以下包含状态的View,但是需要保存状态并注册状态变更事件。 ++ CheckBox ++ Switch ++ RadioButton + +```kotlin +// Check the view. +remoteView.setCompoundButtonChecked(R.id.my_checkbox, true) + +// Check a radio group. +remoteView.setRadioGroupChecked(R.id.my_radio_group, R.id.radio_button_2) + +// Listen for check changes. The intent will have an extra with the key +// EXTRA_CHECKED that specifies the current checked state of the view. +remoteView.setOnCheckedChangeResponse( + R.id.my_checkbox, + RemoteViews.RemoteResponse.fromPendingIntent(onCheckedChangePendingIntent) +) +``` + +##### 2.5 实现圆角 +Android-12新增的参数: ++ system_app_widget_background_radius 不能大于28dp ++ system_app_widget_inner_radius + +
+ +
+ + +#### 三、增强你的小部件 + 这里讨论一些可选项,Android-12中的体验增强。 + +##### 3.1 添加设备主题 + 3.1.1 使用动态颜色向后兼容 + +##### 3.2 声音支持 +##### 3.3 优化选择小部件时的体验 + Android-12增加动态预览和小部件描述。 +##### 3.4 添加小部件描述 +```xml + + +``` +##### 3.5 平滑转场效果 +Android-12起当用户从小部件拉起应用时,使用`@android:id/background` or `android.R.id.background`优化拉起效果: +```xml +// Top level layout of the widget. + + +``` + +##### 3.6 运行时修改`RemoteViews` +Android-12新增一些方法 +```xml +// Set the colors of a progress bar at runtime. +remoteView.setColorStateList(R.id.progress, "setProgressTintList", createProgressColorStateList()) + +// Specify exact sizes for margins. +remoteView.setViewLayoutMargin(R.id.text, RemoteViews.MARGIN_END, 8f, TypedValue.COMPLEX_UNIT_DP) +``` + diff --git a/source/_drafts/android-source-retrofit.md b/source/_drafts/android-source-retrofit.md index e4eb6e20..bc3a30ed 100644 --- a/source/_drafts/android-source-retrofit.md +++ b/source/_drafts/android-source-retrofit.md @@ -1,7 +1,7 @@ --- title: Retrofit源码阅读 -tags: ---- +tags: Android +------------- 一、基本原理概述 diff --git a/source/_posts/android-aosp-event-loop.md b/source/_posts/android-aosp-event-loop.md new file mode 100644 index 00000000..0d8ab0c8 --- /dev/null +++ b/source/_posts/android-aosp-event-loop.md @@ -0,0 +1,169 @@ +--- +title: Android消息机制 +tags: + - Android +date: 2022-06-20 15:34:15 +categories: +- 计算机 +description: +------ + +#### 相关类和结构 +
+ +
+ +#### 基本使用 +##### 主线程的事件循环 +```java +package android.app; + +public final class ActivityThread extends ClientTransactionHandler + implements ActivityThreadInternal { + + public static void main(String[] args) { + //... + Looper.prepareMainLooper(); + + Looper.loop(); + } +} + +``` + +##### 构建自己的事件循环 +```java +class LooperThread extends Thread { + public Handler mHandler; + + public void run() { + Looper.prepare(); + + mHandler = new Handler() { + public void handleMessage(Message msg) { + // process incoming messages here + } + }; + + Looper.loop(); + } +} +``` + +#### 原理剖析 + +##### 构建事件循环 + +
+ +
+ + +##### 发送消息 + +
+ +
+ + +##### 消息执行 + +
+ +
+ +##### 同步屏障 + +###### 3.4.1 消息的分类 ++ 同步消息 ++ 异步消息 ++ 屏障消息 + +###### 3.4.2 同步屏障是什么 + +一种特殊的Message,其target=null + +###### 3.4.3 同步屏障工作原理 +```java +Message next() { + //... + + int pendingIdleHandlerCount = -1; // -1 only during first iteration + int nextPollTimeoutMillis = 0; + for (;;) { + //... + synchronized (this) { + // Try to retrieve the next message. Return if found. + final long now = SystemClock.uptimeMillis(); + Message prevMsg = null; + Message msg = mMessages; + if (msg != null && msg.target == null) {//碰到同步屏障 + // Stalled by a barrier. Find the next asynchronous message in the queue. + // do while循环遍历消息链表 + // 跳出循环时,msg指向离表头最近的一个异步消息 + do { + prevMsg = msg; + msg = msg.next; + } while (msg != null && !msg.isAsynchronous()); + } + if (msg != null) { + if (now < msg.when) { + //... + } else { + // Got a message. + mBlocked = false; + if (prevMsg != null) { + //将msg从消息链表中移除 + prevMsg.next = msg.next; + } else { + mMessages = msg.next; + } + msg.next = null; + if (DEBUG) Log.v(TAG, "Returning message: " + msg); + msg.markInUse(); + //返回异步消息 + return msg; + } + } else { + // No more messages. + nextPollTimeoutMillis = -1; + } + //... + } + //... + } +} +``` +当设置了同步屏障之后,next函数将会忽略所有的同步消息,返回异步消息。换句话说就是,设置了同步屏障之后,Handler只会处理异步消息。再换句话说,同步屏障为Handler消息机制增加了一种简单的优先级机制,异步消息的优先级要高于同步消息。 + + +###### 3.4.4 实际应用 + +Android应用框架中为了更快的响应UI刷新事件在ViewRootImpl.scheduleTraversals中使用了同步屏障 + +```java +void scheduleTraversals() { + if (!mTraversalScheduled) { + mTraversalScheduled = true; + //设置同步障碍,确保mTraversalRunnable优先被执行 + mTraversalBarrier = mHandler.getLooper().getQueue().postSyncBarrier(); + //内部通过Handler发送了一个异步消息 + mChoreographer.postCallback( + Choreographer.CALLBACK_TRAVERSAL, mTraversalRunnable, null); + if (!mUnbufferedInputDispatch) { + scheduleConsumeBatchedInput(); + } + notifyRendererOfFramePending(); + pokeDrawLockIfNeeded(); + } +} +``` + + +#### 常见问题 + +Epoll 实现原理 +https://www.jxhs.me/2021/04/08/linux%E5%86%85%E6%A0%B8Epoll-%E5%AE%9E%E7%8E%B0%E5%8E%9F%E7%90%86/ + +【原创】Linux select/poll机制原理分析 +https://www.cnblogs.com/LoyenWang/p/12622904.html \ No newline at end of file diff --git a/source/_posts/econonmics-roa-roe-roic-roce.md b/source/_posts/econonmics-roa-roe-roic-roce.md index 8694cad6..3a8f4b69 100644 --- a/source/_posts/econonmics-roa-roe-roic-roce.md +++ b/source/_posts/econonmics-roa-roe-roic-roce.md @@ -9,6 +9,7 @@ categories: description: --- +#### 一、概述 + 资产回报率(ROA) + 净资产回报率(ROE) + 投入资本回报率(ROIC) @@ -17,7 +18,10 @@ description: 不同的回报率,实际上是衡量公司的不同视角。 -#### 资产回报率(ROA) +#### 二、资产回报率(ROA) + +##### 2.1 基本概念 +**运用全部资金获取利润能力的集中体现**
@@ -27,26 +31,14 @@ $$ ROA=\frac{净利润}{总资产} $$ -**运用全部资金获取利润能力的集中体现** - -另一计算公式: - -ROA = 净利润率NPM × 资产利用率AU - -其中: - -$$ - 净利润率NPM = \frac{净利润}{营业总收入} -$$ - -反映银行费用管理(或成本控制)的有效性。 +##### 2.2 概念拆分 $$ - 资产利用率AU = \frac{营业总收入}{总资产} = \frac{(主营业务收入+非主营业务收入)}{总资产} + ROA = 净利润率NPM * 资产利用率AU = \frac{净利润}{营业总收入} * \frac{营业总收入}{总资产} = \frac{(主营业务收入+非主营业务收入)}{总资产} $$ -反映银行业务经营及获利能力。 +##### 2.3 概念理解 ROA这个回报率衡量的是资产的回报率。 但是一个公司资产负债表上的资产价值更多的是反映了历史而不是当前, 而且不同的行业的ROA具有不可比性。 @@ -54,22 +46,55 @@ ROA这个回报率衡量的是资产的回报率。 但是无偿使用上下游资金实际上是公司有竞争力的体现。 +#### 三、净资产回报率(ROE) + +##### 2.1 基本概念 -#### 净资产回报率(ROE) +ROE的视角是从股东的角度看问题,单纯从股权的角度衡量回报,而不考虑公司的资本结构及负债情况。衡量公司赚钱的效率。
-ROE的视角是从股东的角度看问题,单纯从股权的角度衡量回报,而不考虑公司的资本结构及负债情况。 - $$ 净资产收益率 = \frac{净利润}{净资产} $$ +> A公司:10亿净资产赚2亿。ROE = 20% +> B公司:50亿净资产赚5亿。ROE = 10% + +##### 2.2 概念拆分 + +$$ + 净资产收益率 = \frac{净利润}{净资产} = \frac{净利润}{营业收入} * \frac{营业收入}{总资产} * \frac{总资产}{净资产} +$$ + +$$ + 净资产收益率 = 净利润 * 资产周转率 * 权益乘数 +$$ + +$$ + 权益乘数 = \frac{总资产}{净资产} +$$ + +$$ + 资产周转率 = \frac{营业收入}{总资产} +$$ + +影响因素: ++ 净利润:反应盈利能力 ++ 资产周转率:反应资产使用效率 ++ 权益乘数:反应负债程度 + +提升ROE的办法: ++ 提高周转率 ++ 廉价的债务杠杆 ++ 更高的债务杠杆 ++ 更低的所得税 ++ 更高的运营利润率 -假定某公司年度净利润为2亿元,年度平均净资产为15亿元,则其本年度之净资产收益率就是13.33%(即(2亿元/15亿元)*100%)。 +##### 2.3 概念理解 ROE对股东来说意义最大,是股票复利增长的源泉。 ROE可以在不同行业与不同企业之间横向比较。 相当于股票这种“股权债券”的收益率。 @@ -85,7 +110,7 @@ ROE的问题在于无法反映债务杠杆对净利润的影响。 ---- -#### 投入资本回报率(ROIC) +#### 四、投入资本回报率(ROIC)
@@ -119,7 +144,7 @@ ROIC的问题在于没有考虑无息流动负债的影响。ROIC实际上是衡 -#### 使用资本回报率(ROCE) +#### 五、使用资本回报率(ROCE)
diff --git a/source/images/android-appwidget-corner.png b/source/images/android-appwidget-corner.png new file mode 100644 index 00000000..ff11e5ea Binary files /dev/null and b/source/images/android-appwidget-corner.png differ diff --git a/source/images/android-basic-aidl-overview.png b/source/images/android-basic-aidl-overview.png new file mode 100644 index 00000000..7cc1dc59 Binary files /dev/null and b/source/images/android-basic-aidl-overview.png differ diff --git a/source/images/android-basic-eventloop-callback.png b/source/images/android-basic-eventloop-callback.png new file mode 100644 index 00000000..d4c85714 Binary files /dev/null and b/source/images/android-basic-eventloop-callback.png differ diff --git a/source/images/android-basic-eventloop-send.png b/source/images/android-basic-eventloop-send.png new file mode 100644 index 00000000..888ec415 Binary files /dev/null and b/source/images/android-basic-eventloop-send.png differ diff --git a/source/images/android-basic-eventloop-start.png b/source/images/android-basic-eventloop-start.png new file mode 100644 index 00000000..923a7039 Binary files /dev/null and b/source/images/android-basic-eventloop-start.png differ diff --git a/source/images/android-basic-eventloop.png b/source/images/android-basic-eventloop.png new file mode 100644 index 00000000..d020bd30 Binary files /dev/null and b/source/images/android-basic-eventloop.png differ diff --git a/source/images/android-binder-what.svg b/source/images/android-binder-what.svg new file mode 100644 index 00000000..94a3418b --- /dev/null +++ b/source/images/android-binder-what.svg @@ -0,0 +1,3 @@ + + +2012-12-04 19:14ZBinderLayer 1com.bar.app3libbinderLocationManagerPackageManagerActivityManagerContentProviderServiceActivitycom.foo.app2libbinderLocationManagerPackageManagerActivityManagerContentProviderServiceActivityLinux Kernelsystem_serverLocationManager ServicePackageManager ServiceActivityManager Servicelibbinderco.mrkn.app1libbinderLocationManagerPackageManagerActivityManagerContentProviderServiceActivityservicemanagerContextManagerSurfaceFlingerSurfaceFlingerlibbindermediaserverlibbinderMediaPlayerServiceCameraServiceAudioFlinger/dev/binder diff --git a/uml/android-appwidget-service.puml b/uml/android-appwidget-service.puml new file mode 100644 index 00000000..081a6ba5 --- /dev/null +++ b/uml/android-appwidget-service.puml @@ -0,0 +1,43 @@ +@startuml +'https://plantuml.com/class-diagram + +interface IAppWidgetService + +abstract class Stub + +class Proxy{ + - mRemote:IBinder +} + +class AppWidgetServiceImpl + + +Stub <|-- AppWidgetServiceImpl + + +interface IInterface + +interface IBinder + +class Binder + +class AppWidgetManager{ + - mService:IAppWidgetService +} + + +IBinder <|-- Binder + +IInterface <|-- IAppWidgetService + +Binder <|-- Stub + +IAppWidgetService <|..Stub + +IAppWidgetService <|.. Proxy + +Proxy "1"*-- IBinder :包含 + +AppWidgetManager "1"*-- IAppWidgetService :包含 + +@enduml \ No newline at end of file