www.久久久久|狼友网站av天堂|精品国产无码a片|一级av色欲av|91在线播放视频|亚洲无码主播在线|国产精品草久在线|明星AV网站在线|污污内射久久一区|婷婷综合视频网站

當(dāng)前位置:首頁(yè) > 嵌入式 > 嵌入式軟件
[導(dǎo)讀] ======================= 第一節(jié) ===========================這里簡(jiǎn)單的介紹了Android的java環(huán)境基礎(chǔ),在后面一節(jié)中會(huì)結(jié)合具體的實(shí)例來(lái)理解這一節(jié)的內(nèi)容。一、Dalvik虛擬

 ======================= 第一節(jié) ===========================

這里簡(jiǎn)單的介紹了Android的java環(huán)境基礎(chǔ),在后面一節(jié)中會(huì)結(jié)合具體的實(shí)例來(lái)理解這一節(jié)的內(nèi)容。

一、Dalvik虛擬機(jī)

Dalvik是Android的程序的java虛擬機(jī),代碼在dalvik/下,

./

|-- Android.mk

|-- CleanSpec.mk

|-- MODULE_LICENSE_APACHE2

|-- NOTICE

|-- README.txt

|-- dalvikvm 虛擬機(jī)的實(shí)現(xiàn)庫(kù)

|-- dexdump

|-- dexlist

|-- dexopt

|-- docs

|-- dvz

|-- dx

|-- hit

|-- libcore

|-- libcore-disabled

|-- libdex

|-- libnativehelper 使用JNI調(diào)用本地代碼時(shí)用到這個(gè)庫(kù)

|-- run-core-tests.sh

|-- tests

|-- tools

`-- vm

二、Android的java框架

Android層次中第3層是java框架,第四層就是java應(yīng)用程序。

Android的java類(lèi)代碼,主要是在frameworks/base/core/java/下,

./

|-- Android

|-- com

|-- jarjar-rules.txt

`-- overview.html

我們?cè)倏匆幌耭rameworks/base/目錄

./

|-- Android.mk

|-- CleanSpec.mk

|-- MODULE_LICENSE_APACHE2

|-- NOTICE

|-- api

|-- awt

|-- build

|-- camera

|-- cmds

|-- common

|-- core

|-- data

|-- docs

|-- graphics

|-- include

|-- keystore

|-- libs

|-- location

|-- media

|-- native

|-- obex

|-- opengl

|-- packages

|-- preloaded-classes

|-- sax

|-- services

|-- telephony

|-- test-runner

|-- tests

|-- tools

|-- vpn

`-- wifi

這里也有Android的java框架代碼。

三、JNI

在Android中,通過(guò)JNI,java可以調(diào)用C寫(xiě)的代碼,主要的實(shí)現(xiàn)是在frameworks/base/core/jni,通過(guò)查看Android.mk,我們可以看到最后生成了libandroid_runtime.so,具體實(shí)現(xiàn)JNI功能需要上面我們介紹的libnativehelper.so,

四、系統(tǒng)服務(wù)之java

1、binder,提供Android的IPC功能

2、servicemanager,服務(wù)管理的服務(wù)器端

3、系統(tǒng)進(jìn)程zygote,負(fù)責(zé)孵化所有的新應(yīng)用

======================= 第二節(jié) ==========================

在我平時(shí)工作中主要是進(jìn)行l(wèi)inux網(wǎng)絡(luò)子系統(tǒng)的模塊開(kāi)發(fā)、linux應(yīng)用程序(C/C++)開(kāi)發(fā)。在學(xué)習(xí)和從事驅(qū)動(dòng)模塊開(kāi)發(fā)的過(guò)程中,如果你對(duì)linux系統(tǒng)本身,包括應(yīng)用程序開(kāi)發(fā)都不了解,那么讀內(nèi)核代碼就如同天書(shū),毫無(wú)意義,所以我分析框架也是從基本系統(tǒng)api開(kāi)始的,當(dāng)然也不會(huì)太多涉及到應(yīng)用程序開(kāi)發(fā)。

好,開(kāi)始這節(jié)主要是講一個(gè)簡(jiǎn)單的adnroid應(yīng)用程序,從應(yīng)用程序出發(fā),到框架代碼。

分析的應(yīng)用程序我們也奉行拿來(lái)主義:froyo/development/samples/HelloActivity

./

|-- Android.mk

|-- AndroidManifest.xml

|-- res

|-- src

`-- tests

其他的就多說(shuō)了,看代碼

/**

* Copyright (C) 2006 The Android Open Source Project

*

* Licensed under the Apache License, Version 2.0 (the "License");

* you may not use this file except in compliance with the License.

* You may obtain a copy of the License at

*

* http://www.apache.org/licenses/LICENSE-2.0

*

* Unless required by applicable law or agreed to in writing, software

* distributed under the License is distributed on an "AS IS" BASIS,

* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

* See the License for the specific language governing permissions and

* limitations under the License.

*/

package Android.util;

import com.Android.internal.os.RuntimeInit;

import java.io.PrintWriter;

import java.io.StringWriter;

/**

* API for sending log output.

*

*

Generally, use the Log.v() Log.d() Log.i() Log.w() and Log.e()

* methods.

*

*

The order in terms of verbosity, from least to most is

* ERROR, WARN, INFO, DEBUG, VERBOSE. Verbose should never be compiled

* into an application except during development. Debug logs are compiled

* in but stripped at runtime. Error, warning and info logs are always kept.

*

*

Tip: A good convention is to declare a TAG constant

* in your class:

*

*

private static final String TAG = "MyActivity";

 

*

* and use that in subsequent calls to the log methods.

*

 

*

*

Tip: Don't forget that when you make a call like

*

Log.v(TAG, "index=" + i);

 

* that when you're building the string to pass into Log.d, the compiler uses a

* StringBuilder and at least three allocations occur: the StringBuilder

* itself, the buffer, and the String object. Realistically, there is also

* another buffer allocation and copy, and even more pressure on the gc.

* That means that if your log message is filtered out, you might be doing[!--empirenews.page--]

* significant work and incurring significant overhead.

*/

public final class Log {

/**

* Priority constant for the println method; use Log.v.

*/

public static final int VERBOSE = 2;

/**

* Priority constant for the println method; use Log.d.

*/

public static final int DEBUG = 3;

/**

* Priority constant for the println method; use Log.i.

*/

public static final int INFO = 4;

/**

* Priority constant for the println method; use Log.w.

*/

public static final int WARN = 5;

/**

* Priority constant for the println method; use Log.e.

*/

public static final int ERROR = 6;

/**

* Priority constant for the println method.

*/

public static final int ASSERT = 7;

/**

* Exception class used to capture a stack trace in {@link #wtf()}.

*/

private static class TerribleFailure extends Exception {

TerribleFailure(String msg, Throwable cause) { super(msg, cause); }

}

private Log() {

}

/**

* Send a {@link #VERBOSE} log message.

* @param tag Used to identify the source of a log message. It usually identifies

* the class or activity where the log call occurs.

* @param msg The message you would like logged.

*/

public static int v(String tag, String msg) {

return println_native(LOG_ID_MAIN, VERBOSE, tag, msg);

}

/**

* Send a {@link #VERBOSE} log message and log the exception.

* @param tag Used to identify the source of a log message. It usually identifies

* the class or activity where the log call occurs.

* @param msg The message you would like logged.

* @param tr An exception to log

*/

public static int v(String tag, String msg, Throwable tr) {

return println_native(LOG_ID_MAIN, VERBOSE, tag, msg + '/n' + getStackTraceString(tr));

}

/**

* Send a {@link #DEBUG} log message.

* @param tag Used to identify the source of a log message. It usually identifies

* the class or activity where the log call occurs.

* @param msg The message you would like logged.

*/

public static int d(String tag, String msg) {

return println_native(LOG_ID_MAIN, DEBUG, tag, msg);

}

/**

* Send a {@link #DEBUG} log message and log the exception.

* @param tag Used to identify the source of a log message. It usually identifies

* the class or activity where the log call occurs.

* @param msg The message you would like logged.

* @param tr An exception to log

*/

public static int d(String tag, String msg, Throwable tr) {

return println_native(LOG_ID_MAIN, DEBUG, tag, msg + '/n' + getStackTraceString(tr));

}

/**

* Send an {@link #INFO} log message.

* @param tag Used to identify the source of a log message. It usually identifies

* the class or activity where the log call occurs.

* @param msg The message you would like logged.

*/

public static int i(String tag, String msg) {

return println_native(LOG_ID_MAIN, INFO, tag, msg);

}

/**

* Send a {@link #INFO} log message and log the exception.

* @param tag Used to identify the source of a log message. It usually identifies

* the class or activity where the log call occurs.

* @param msg The message you would like logged.

* @param tr An exception to log

*/

public static int i(String tag, String msg, Throwable tr) {

return println_native(LOG_ID_MAIN, INFO, tag, msg + '/n' + getStackTraceString(tr));

}

/**

* Send a {@link #WARN} log message.

* @param tag Used to identify the source of a log message. It usually identifies

* the class or activity where the log call occurs.

* @param msg The message you would like logged.

*/

public static int w(String tag, String msg) {

return println_native(LOG_ID_MAIN, WARN, tag, msg);

}

/**

* Send a {@link #WARN} log message and log the exception.

* @param tag Used to identify the source of a log message. It usually identifies

* the class or activity where the log call occurs.

* @param msg The message you would like logged.

* @param tr An exception to log

*/

public static int w(String tag, String msg, Throwable tr) {

return println_native(LOG_ID_MAIN, WARN, tag, msg + '/n' + getStackTraceString(tr));

}

/**

* Checks to see whether or not a log for the specified tag is loggable at the specified level.

*

* The default level of any tag is set to INFO. This means that any level above and including[!--empirenews.page--]

* INFO will be logged. Before you make any calls to a logging method you should check to see

* if your tag should be logged. You can change the default level by setting a system property:

* 'setprop log.tag. '

* Where level is either VERBOSE, DEBUG, INFO, WARN, ERROR, ASSERT, or SUPPRESS. SUPPRESS will

* turn off all logging for your tag. You can also create a local.prop file that with the

* following in it:

* 'log.tag.='

* and place that in /data/local.prop.

*

* @param tag The tag to check.

* @param level The level to check.

* @return Whether or not that this is allowed to be logged.

* @throws IllegalArgumentException is thrown if the tag.length() > 23.

*/

public static native boolean isLoggable(String tag, int level);

/**

* Send a {@link #WARN} log message and log the exception.

* @param tag Used to identify the source of a log message. It usually identifies

* the class or activity where the log call occurs.

* @param tr An exception to log

*/

public static int w(String tag, Throwable tr) {

return println_native(LOG_ID_MAIN, WARN, tag, getStackTraceString(tr));

}

/**

* Send an {@link #ERROR} log message.

* @param tag Used to identify the source of a log message. It usually identifies

* the class or activity where the log call occurs.

* @param msg The message you would like logged.

*/

public static int e(String tag, String msg) {

return println_native(LOG_ID_MAIN, ERROR, tag, msg);

}

/**

* Send a {@link #ERROR} log message and log the exception.

* @param tag Used to identify the source of a log message. It usually identifies

* the class or activity where the log call occurs.

* @param msg The message you would like logged.

* @param tr An exception to log

*/

public static int e(String tag, String msg, Throwable tr) {

return println_native(LOG_ID_MAIN, ERROR, tag, msg + '/n' + getStackTraceString(tr));

}

/**

* What a Terrible Failure: Report a condition that should never happen.

* The error will always be logged at level ASSERT with the call stack.

* Depending on system configuration, a report may be added to the

* {@link Android.os.DropBoxManager} and/or the process may be terminated

* immediately with an error dialog.

* @param tag Used to identify the source of a log message.

* @param msg The message you would like logged.

*/

public static int wtf(String tag, String msg) {

return wtf(tag, msg, null);

}

/**

* What a Terrible Failure: Report an exception that should never happen.

* Similar to {@link #wtf(String, String)}, with an exception to log.

* @param tag Used to identify the source of a log message.

* @param tr An exception to log.

*/

public static int wtf(String tag, Throwable tr) {

return wtf(tag, tr.getMessage(), tr);

}

/**

* What a Terrible Failure: Report an exception that should never happen.

* Similar to {@link #wtf(String, Throwable)}, with a message as well.

* @param tag Used to identify the source of a log message.

* @param msg The message you would like logged.

* @param tr An exception to log. May be null.

*/

public static int wtf(String tag, String msg, Throwable tr) {

tr = new TerribleFailure(msg, tr);

int bytes = println_native(LOG_ID_MAIN, ASSERT, tag, getStackTraceString(tr));

RuntimeInit.wtf(tag, tr);

return bytes;

}

/**

* Handy function to get a loggable stack trace from a Throwable

* @param tr An exception to log

*/

public static String getStackTraceString(Throwable tr) {

if (tr == null) {

return "";

}

StringWriter sw = new StringWriter();

PrintWriter pw = new PrintWriter(sw);

tr.printStackTrace(pw);

return sw.toString();

}

/**

* Low-level logging call.

* @param priority The priority/type of this log message

* @param tag Used to identify the source of a log message. It usually identifies

* the class or activity where the log call occurs.

* @param msg The message you would like logged.

* @return The number of bytes written.

*/

public static int println(int priority, String tag, String msg) {

return println_native(LOG_ID_MAIN, priority, tag, msg);

}

/** @hide */ public static final int LOG_ID_MAIN = 0;

/** @hide */ public static final int LOG_ID_RADIO = 1;

/** @hide */ public static final int LOG_ID_EVENTS = 2;[!--empirenews.page--]

/** @hide */ public static final int LOG_ID_SYSTEM = 3;

/** @hide */ public static native int println_native(int bufID,

int priority, String tag, String msg);

}

我們看到所有代碼都是調(diào)用public static native int println_native(int bufID,

int priority, String tag, String msg);來(lái)實(shí)現(xiàn)輸出的,這個(gè)函數(shù)的實(shí)現(xiàn)就是C++,調(diào)用的方式就是JNI

我們看一下對(duì)應(yīng)的jni代碼froyo/frameworks/base/core/jni/Android_util_Log.cpp,最終調(diào)用的輸出函數(shù)是

/*

* In class Android.util.Log:

* public static native int println_native(int buffer, int priority, String tag, String msg)

*/

static jint Android_util_Log_println_native(JNIEnv* env, jobject clazz,

jint bufID, jint priority, jstring tagObj, jstring msgObj)

{

const char* tag = NULL;

const char* msg = NULL;

if (msgObj == NULL) {

jclass npeClazz;

npeClazz = env->FindClass("java/lang/NullPointerException");

assert(npeClazz != NULL);

env->ThrowNew(npeClazz, "println needs a message");

return -1;

}

if (bufID < 0 || bufID >= LOG_ID_MAX) {

jclass npeClazz;

npeClazz = env->FindClass("java/lang/NullPointerException");

assert(npeClazz != NULL);

env->ThrowNew(npeClazz, "bad bufID");

return -1;

}

if (tagObj != NULL)

tag = env->GetStringUTFChars(tagObj, NULL);

msg = env->GetStringUTFChars(msgObj, NULL);

int res = __Android_log_buf_write(bufID, (android_LogPriority)priority, tag, msg);

if (tag != NULL)

env->ReleaseStringUTFChars(tagObj, tag);

env->ReleaseStringUTFChars(msgObj, msg);

return res;

}

當(dāng)然我們發(fā)現(xiàn)最終輸出是

? 1int res = __Android_log_buf_write(bufID, (android_LogPriority)priority, tag, msg);

用力grep了一下代碼,結(jié)果如下

./system/core/include/cutils/log.h:int __Android_log_buf_write(int bufID, int prio, const char *tag, const char *text);

./system/core/liblog/logd_write.c:int __Android_log_buf_write(int bufID, int prio, const char *tag, const char *msg)

./system/core/liblog/logd_write.c: return __Android_log_buf_write(bufID, prio, tag, buf);

這個(gè)就是和Android專(zhuān)用驅(qū)動(dòng)進(jìn)行通信的方式,這個(gè)分析下去就有點(diǎn)深了,后面分析。

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專(zhuān)欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除。
換一批
延伸閱讀

9月2日消息,不造車(chē)的華為或?qū)⒋呱龈蟮莫?dú)角獸公司,隨著阿維塔和賽力斯的入局,華為引望愈發(fā)顯得引人矚目。

關(guān)鍵字: 阿維塔 塞力斯 華為

倫敦2024年8月29日 /美通社/ -- 英國(guó)汽車(chē)技術(shù)公司SODA.Auto推出其旗艦產(chǎn)品SODA V,這是全球首款涵蓋汽車(chē)工程師從創(chuàng)意到認(rèn)證的所有需求的工具,可用于創(chuàng)建軟件定義汽車(chē)。 SODA V工具的開(kāi)發(fā)耗時(shí)1.5...

關(guān)鍵字: 汽車(chē) 人工智能 智能驅(qū)動(dòng) BSP

北京2024年8月28日 /美通社/ -- 越來(lái)越多用戶希望企業(yè)業(yè)務(wù)能7×24不間斷運(yùn)行,同時(shí)企業(yè)卻面臨越來(lái)越多業(yè)務(wù)中斷的風(fēng)險(xiǎn),如企業(yè)系統(tǒng)復(fù)雜性的增加,頻繁的功能更新和發(fā)布等。如何確保業(yè)務(wù)連續(xù)性,提升韌性,成...

關(guān)鍵字: 亞馬遜 解密 控制平面 BSP

8月30日消息,據(jù)媒體報(bào)道,騰訊和網(wǎng)易近期正在縮減他們對(duì)日本游戲市場(chǎng)的投資。

關(guān)鍵字: 騰訊 編碼器 CPU

8月28日消息,今天上午,2024中國(guó)國(guó)際大數(shù)據(jù)產(chǎn)業(yè)博覽會(huì)開(kāi)幕式在貴陽(yáng)舉行,華為董事、質(zhì)量流程IT總裁陶景文發(fā)表了演講。

關(guān)鍵字: 華為 12nm EDA 半導(dǎo)體

8月28日消息,在2024中國(guó)國(guó)際大數(shù)據(jù)產(chǎn)業(yè)博覽會(huì)上,華為常務(wù)董事、華為云CEO張平安發(fā)表演講稱,數(shù)字世界的話語(yǔ)權(quán)最終是由生態(tài)的繁榮決定的。

關(guān)鍵字: 華為 12nm 手機(jī) 衛(wèi)星通信

要點(diǎn): 有效應(yīng)對(duì)環(huán)境變化,經(jīng)營(yíng)業(yè)績(jī)穩(wěn)中有升 落實(shí)提質(zhì)增效舉措,毛利潤(rùn)率延續(xù)升勢(shì) 戰(zhàn)略布局成效顯著,戰(zhàn)新業(yè)務(wù)引領(lǐng)增長(zhǎng) 以科技創(chuàng)新為引領(lǐng),提升企業(yè)核心競(jìng)爭(zhēng)力 堅(jiān)持高質(zhì)量發(fā)展策略,塑強(qiáng)核心競(jìng)爭(zhēng)優(yōu)勢(shì)...

關(guān)鍵字: 通信 BSP 電信運(yùn)營(yíng)商 數(shù)字經(jīng)濟(jì)

北京2024年8月27日 /美通社/ -- 8月21日,由中央廣播電視總臺(tái)與中國(guó)電影電視技術(shù)學(xué)會(huì)聯(lián)合牽頭組建的NVI技術(shù)創(chuàng)新聯(lián)盟在BIRTV2024超高清全產(chǎn)業(yè)鏈發(fā)展研討會(huì)上宣布正式成立。 活動(dòng)現(xiàn)場(chǎng) NVI技術(shù)創(chuàng)新聯(lián)...

關(guān)鍵字: VI 傳輸協(xié)議 音頻 BSP

北京2024年8月27日 /美通社/ -- 在8月23日舉辦的2024年長(zhǎng)三角生態(tài)綠色一體化發(fā)展示范區(qū)聯(lián)合招商會(huì)上,軟通動(dòng)力信息技術(shù)(集團(tuán))股份有限公司(以下簡(jiǎn)稱"軟通動(dòng)力")與長(zhǎng)三角投資(上海)有限...

關(guān)鍵字: BSP 信息技術(shù)
關(guān)閉
關(guān)閉