全部 文章 问答 分享 共找到29个相关内容
Mysql数据库安装
mysql镜像 运行镜像 sudo docker run -p 3306:3306 --name=sob_test_mysql \ -v /home/aosp/docker/mysql/conf:/etc/
AOSP-android开源项目必备基础知识Shell
AOSP-android开源项目必备基础知识Shell不管是做运维还是做android系统开发,都要学习shell这里我们主要是针对android系统开发,AOSP-android开源项目。我们学习
AOSP系列文章(一)-Android系统源码下载和编译
联网系统。你可以改一个iOS一样的UI出来,也可以改一个跟Windows一样的UI出来。 前期准备: 做android开发,最好可以访问到google的网站!这样子你才可以访问AOSP的网站
AOSP团队开发模式
AOSP相关内容 AOSP android open source project 安卓开源工程 相关内容,请大家看这个链接吧 AOSP安卓开源项目 AOSP团队开发模式 这里的开发模式,指的是人员
Dodcker创建Mysql容器
- "/var/lib/mysql:/home/aosp/docker/mysql/db" - "/etc/mysql:/home/aosp/docker/mysql/conf
AOSP-Android系统定制下载系统源码
AOSP-Android系统定制下载系统源码前期准备从这里开始,我们就去做android系统的修改,相信会有更多的同学有更多的玩法。android是开源的,在源代码里没有秘密。同学们可以去修改系统,
Android系统编译-AOSP-创建自己公司的产品
Android系统编译-AOSP-创建自己公司的产品 前面我们已经了解了怎么样去下载源码,怎么样去编译 但是呢,编译的都是别人的产品 比如说 这个列表里,是7.1默认的设备列表 假设你公司有自己的
Android系统编译说明(AOSP)
Android系统编译说明(AOSP) 前面我们已经去编译了android系统,只是告诉了同学们步骤,但是没有给大家说明一下每个步骤里的参数是什么意思。 相关文章 AOSP-Android系统定制
Android5.1格式化sd卡AOSP
Android5.1格式化sd卡AOSP今天下午在做一个格式化的,看了一下系统的API,实现了。分享给大家吧。权限:1、声明 <uses-permission android:name=&
学习路线
学完中级领券联盟,是否要学高级课程AOSP了。
Android 操作系统架构
Android 操作系统架构这篇文章很全面,是大厂一线工程师写的,如果要往android系统底层走的同学,可以看看。
AOSP-Android系统源码目录结构
AOSP-Android系统源码目录结构 当我们下载好源码以后,就会得到这些,以下是Android7.1的源码 out下载完没有哈,这个是我编译过的,所以就有了out目录了。 这里面的目录各自存放
Ubuntu安装和配置Samba
apt-get install samba samba-common 设置密码 sudo smbpasswd -a aosp aosp是我的用户名 aosp@ubuntu:~/
AOSP-android必备基础知识 Linux Shell
# 为什么要学习Shell呢?不管是做运维还是做android系统开发,都要学习shell这里我们主要是针对android系统开发,AOSP-android开源项目。我们学习Shell有两个目的,
使用docker创建Nginx服务器容器
80 \ -v /home/aosp/docker/nginx/wwwroot:/usr/share/nginx/html \ -v /home/aosp/docker/nginx/conf/nginx
阳光沙滩博客系统-后端项目部署
build -t sob_blog:1.0 . 运行镜像 docker run -p 2020:2021 --name=sob_blog --restart=always -d -v /home/aosp/
如何获取未安装APK的名字(其他都是扯淡)
需求背景:要对apk进行管理,但是在不安装的情况下,我们需要拿到这个apk应用的名称,也就是安装好后,现实在Launcher里的名称。怎么获取未安装应apk的名字呢(label)主要的代码如下: //Here is the main code //First we should get the dir of the apk. //By the way,please remember to add the uses-permission READ_EXTERNAL_STORAGE into the manifests file. String apkPath = "/storage/sdcard0/Download/test.apk";//Just an example,please replace it as yours. //We can get the label name by the path,but we need to get the packageManager first; PackageManager pm = this.getPackageManager(); //Get the packageInfo PackageInfo pi = pm.getPackageArchiveInfo(apkPath, PackageManager.GET_ACTIVITIES); //Set the source and public source dir. pi.applicationInfo.sourceDir = apkPath; pi.applicationInfo.publicSourceDir = apkPath; //Now,we get the app name but we haven't install. String appName = (String) pi.applicationInfo.loadLabel(pm); //Out put the name System.out.println("appName ==== " + appName);手机上的apk路径是演示的路径,那么我们把程序跑起来以后呢,就可以看得到这样的结果啦:I/System.out: appName ==== 滴答表盘然而我并没有安装这个apk,但是小手一抖,还是拿到了,对吧!你也试试吧,你一定可以的!代码地址:https://github.com/TrillGates/GetApkLabelName
编译Android 8.1.0遇到的问题
log: 1 warning generated. [ 0% 71/78909] target C: sh <= external/mksh/src/lex.c [ 0% 72/78909] target C: sh <= external/mksh/src/funcs.c [ 0% 73/78909] target C: sh <= external/mksh/src/edit.c [ 0% 74/78909] target C: toybox <= external/toybox/toys/other/clear.c [ 0% 75/78909] target C: toybox <= external/toybox/toys/other/fallocate.c [ 0% 76/78909] target C: toybox <= external/toybox/toys/other/dos2unix.c [ 0% 77/78909] host Java: ahat (out/host/common/obj/JAVA_LIBRARIES/ahat_intermediates/classes) warning: [options] bootstrap class path not set in conjunction with -source 1.7 Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 1 warning [ 0% 78/78909] host Java: jsilver (out/host/common/obj/JAVA_LIBRARIES/jsilver_intermediates/classes) Note: external/jsilver/src/org/clearsilver/FactoryLoader.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. ninja: build stopped: subcommand failed. 19:23:18 ninja failed with: exit status 1 build/core/main.mk:21: recipe for target 'run_soong_ui' failed make: *** [run_soong_ui] Error 1 #### make failed to build some targets (47 seconds) #### 编译之前先执行以下命令 export LC_ALL=C
Android系统编译,资源文件名不能为大写,编译报错。
今天在编译系统,其实我是无意识地把所有英文命名的复制到了系统的应用中,然后进行编译,结果报错了。make: *** [out/target/common/obj/APPS/SystemUI_intermediates/src/R.stamp] Error 1报了上面这个错,真不知道什么原因。也没有什么相关的信息出来这个时候我们只能用阿基米德的排水法。先是复原回去,然后删除编译出来的中间文件,编译,通过,说明的确是因为复制了新的图片而导致编译错误了。然后用差别的方法验证,我只复制其种一张图片,删除中间文件再编译,通过。得出结论:跟其中的图片有关系。想到的东西:是不是命名跟系统的有冲突,我这里是一个独立的应用SystemUI,一般不会有,那是不是图片损坏,预览了一下,全部正常。我看了一下所有文件的名字,只有一个比较特殊的就是GPS.png后来我在输出的Log里搜了一下GPSres/mipmap-mdpi-v4/GPS.png: Invalid file name: must contain only [a-z0-9_.] res/mipmap-mdpi-v4/GPS.png: Invalid file name: must contain only [a-z0-9_.] res/mipmap-mdpi-v4/GPS.png: Invalid file name: must contain only [a-z0-9_.]这里的意思是命名不可用,也就是命名不规则,不合法。命名只能是a到z的小写字母,0到9,_.这几个符号。OK,改一下就编译过去了!!!记录一下,就这次的编译错误。如果是因为字符串的问题,比如说,字符串在布局文件里有,而没有提到strings.xml里也会报错的,但是这个会告诉你是那里错了。
使用虚拟机VM,Ubuntu 18.04.2 LTS编译android系统7.1遇到的问题
使用虚拟机VM,Ubuntu 18.04.2 LTS编译android系统7.1遇到的问题 recipe for target 'ninja_wrapper' failed build/core/ninja.mk:148: recipe for target 'ninja_wrapper' failed make: *** [ninja_wrapper] Error 1 解决方法,在build/envsetup.sh里添加以下代码: export LC_ALL=C 为了去除所有本地化的设置,让命令能正确执行。 increasing heap size with java option '-Xmx' Try increasing heap size with java option '-Xmx' 这个是堆内存不够了 执行以下三条命令,再继续编译即可 export JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4g" ./prebuilts/sdk/tools/jack-admin kill-server ./prebuilts/sdk/tools/jack-admin start-server KVM is not installed on this machine 没有安装kvm加速器 Please ensure KVM is properly installed and usable. CPU acceleration status: KVM is not installed on this machine (/dev/kvm is missing). sudo apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils 安装就好,但是后面还会有问题,接着往下看吧 Your CPU does not support KVM extensions sudo apt-get install qemu-kvm cpu-checker 你的CPU不支持KVM扩展 我的是英特尔的CPU 为什么不支持呢? 因为我用的是VM,没有开启虚拟技术加速引擎 把这个勾选上,因为我的在跑着,所以是置灰的。关机后设置,开机即有效。 查看状态 kvm-ok 一般来说,按前面的套路走了,就可以使用了。 This user doesn't have permissions to use KVM (/dev/kvm). 虽然kvm ok了。但是当用用户没有这个权限 groupadd kvm usermod -G kvm -a 你当前的用户名 echo 'KERNEL=="kvm",GROUP="kvm",MODE="0660"' >> /etc/udev/rules.d/androidUseKVM.rules 运行模拟器 到此,用虚拟机编译的坑就遇到这些 如果你在实践中遇到什么问题,可以到问答模块发帖子讨论。
android应用执行adb命令来截图
android应用执行adb命令来截图 测试那边需要一个截图工具,本为以随便就搞定了,哈哈。谁知道看了一下,我们干掉了SystemUI,我们是做系统定制的,把一些东西干掉了。所以就没法调用系统的API进行截图了。 使用adb截图,用电脑可以,但是用应用去执行adb命令截图,做不到: String mSavedPath = "/mnt/sdcard/imei-" + getIMEI(MainActivity.this) + "-time-" + stampToDate(System.currentTimeMillis() + "") + "screenshot.png"; try { Runtime.getRuntime().exec("screencap -p " + mSavedPath); } catch (Exception e) { e.printStackTrace(); } ToastUtils.toastShow(MainActivity.this, "截图成功!"); 报了一些无权限相关的错误。 于是就想到了把它放到系统里头编译: Android.mk LOCAL_PATH:= $(call my-dir)/app/src/main include $(CLEAR_VARS) LOCAL_PACKAGE_NAME := ScreenShot LOCAL_SRC_FILES := $(call all-java-files-under, java) WITH_DEXPREOPT := false LOCAL_CERTIFICATE := platform include $(BUILD_PACKAGE) ################################################## include $(CLEAR_VARS) include $(BUILD_MULTI_PREBUILT) ################################################### include $(call all-makefiles-under,$(LOCAL_PATH)) 编译出来以后,安装,使用,亲测成功了! 当然啦,只能截图我当前系统的界面,其他系统就不行了。除非用那个系统来编译。 上面脚本一有句是重点: LOCAL_CERTIFICATE := platform 也就是用系统签名 WITH_DEXPREOPT := false 这个的意思 就是不生成odex 一般来说,apk里面是java文件。odex里是资源文件 这样做方便我们安装 好啦,这文章就到这 里啦!
Android系统编译日常记录
Android系统编译日常记录记录一下,有时候不常编译的话,有些东西会忘记的。1.编译的时候,把日志输出到 build.log里面make -j40 2>&1 | tee build.log2.输出当前编译环境printconfig我们source build/envsetup.sh的时候,其实就是把envsetup.sh里的脚本当成shell命令去执行。所以这一步完成以后,我们才可以执行上面这些命令。比如说,launch、make、mm、mmm、这些命令都要执行source build/envsetup.sh以后才可以执行!也就是说,我们如果遇到一些不记得的命令,可以先去看看这个文件envsetup.sh里的shell脚本。3.如何能让系统编译默认打log和支持adb呢?修改以下这些项:build/core/main.mk#Target is more debuggable and adbd is on by default ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=10为false,1为true。也就是说1表示打开adb调试#Disable debugging in plain user builds. enable_target_debugging := true这个是表示是否调试,true表示打开调试,false表示关闭调试。4.调试跟系统相关的app有些时候,我们开发的应用跟系统的服务有关联,如果没有编译出sdk来,用android studio就没法编译了。所以我们需要放到系统里面进行编译。按传统的做法:1、最笨的方法是:全编译,再刷机。虽然是增量编译,但是也要花费不少的时间。编译完成以后还要刷机。2、单独一个模块编译,再make snod,再进行刷机。目前比较好的方法是怎么样的呢?模块编译成apk,使用覆盖的形式,省去了make snod的时间(大概四分钟左右),省去刷机和第一次启动的时间(大概5分钟左右)这个编译命令是:mm WITH_DEXPREOPT=false -B 进入到需要编译的目录模块,输入这个命令,就可以编译出对应的apk了,而不是apk+odex。有了apk之后,再去删除系统的,重启以后直接安装即可。 5.把应用编译成apk在系统编译里头,默认会把应用编译成apk和odex,其中apk只有java编译出来的类,odex有资源文件 如果要单独编译成一个apk的话,可以在mk文件里添加: WITH_DEXPREOPT := false打开MTKlogadb shell am start -n com.mediatek.mtklogger/com.mediatek.mtklogger.MainActivity
AOSP日记,修改分辨率,修改dpi,全屏禁止下拉拖出状态栏
这其实是一个业余爱好吧!把自己倒腾的东西记录下来,可以看,请不要转载。全屏的时候,禁止顶部划出状态栏要达到这个效果,就是禁止掉从上往下滑动的代码,这个是全局的。代码在PhoneWindowManager.java里头// monitor for system gestures mSystemGestures = new SystemGesturesPointerEventListener(context, new SystemGesturesPointerEventListener.Callbacks() { @Override public void onSwipeFromTop() { if (isGestureIsolated()) return; if (mStatusBar != null) { //requestTransientBars(mStatusBar); } } @Override public void onSwipeFromBottom() { if (isGestureIsolated()) return; if (mNavigationBar != null && mNavigationBarOnBottom) { requestTransientBars(mNavigationBar); } } @Override public void onSwipeFromRight() { if (isGestureIsolated()) return; if (mNavigationBar != null && !mNavigationBarOnBottom) { requestTransientBars(mNavigationBar); } } @Override public void onDebug() { // no-op } private boolean isGestureIsolated() { WindowState win = mFocusedWindow != null ? mFocusedWindow : mTopFullscreenOpaqueWindowState; if (win != null && (win.getSystemUiVisibility() & View.SYSTEM_UI_FLAG_IMMERSIVE_GESTURE_ISOLATED) != 0) return true; else return false; } });//requestTransientBars(mStatusBar);前面看到,我把这句注释掉了,这样子,从顶部往下滑动的动作,就不会显示出状态栏了,导航栏的设置同理。修改屏幕的分辨率MTK平台的,其他的可能不一样,android5.1的,其他版本或者其他方案商的得去看看咯,这个作为参考。第一个文件:\kernel-3.10\arch\arm\configs修改你的项目名里的配置文件CONFIG_LCM_HEIGHT=”1920″ CONFIG_LCM_WIDTH=”1080″改成你的想要的分辨率第二个文件:kernel-3.10\drivers\misc\mediatek\lcm\ek79030修改#define FRAME_WIDTH (1080)//(400) #define FRAME_HEIGHT (1920)//(1280)第三个文件:\bootable\bootloader\lk\dev\lcm\ek79030\ek79030.c#define FRAME_WIDTH (480)//(400) #define FRAME_HEIGHT (800)//(1280)修改屏幕的dpi这个文件在system.prop里头,这个system.prop其实是用来编译前配置的,比如说我要配置默认是否显示导航栏之类的。ro.sf.lcd_density=160
Android系统编译日常记录mtk平台
记录一下,有时候不常编译的话,有些东西会忘记的。编译的时候,把日志输出到 build.log里面make -j40 2>&1 | tee build.log输出当前编译环境printconfig我们source build/envsetup.sh的时候,其实就是把envsetup.sh里的脚本当成shell命令去执行。所以这一步完成以后,我们才可以执行上面这些命令。比如说,launch、make、mm、mmm、这些命令都要执行source build/envsetup.sh以后才可以执行!也就是说,我们如果遇到一些不记得的命令,可以先去看看这个文件envsetup.sh里的shell脚本。如何能让系统编译默认打log和支持adb呢?修改以下这些项:build/core/main.mk#Target is more debuggable and adbd is on by defaultADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=10为false,1为true。也就是说1表示打开adb调试#Disable debugging in plain user builds. enable_target_debugging := true这个是表示是否调试,true表示打开调试,false表示关闭调试。调试跟系统相关的app有些时候,我们开发的应用跟系统的服务有关联,如果没有编译出sdk来,用android studio就没法编译了。所以我们需要放到系统里面进行编译。按传统的做法:1、最笨的方法是:全编译,再刷机。虽然是增量编译,但是也要花费不少的时间。编译完成以后还要刷机。2、单独一个模块编译,再make snod,再进行刷机。目前比较好的方法是怎么样的呢?模块编译成apk,使用覆盖的形式,省去了make snod的时间(大概四分钟左右),省去刷机和第一次启动的时间(大概5分钟左右)这个编译命令是:mm WITH_DEXPREOPT=false -B 进入到需要编译的目录模块,输入这个命令,就可以编译出对应的apk了,而不是apk+odex。有了apk之后,再去删除系统的,重启以后直接安装即可。把应用编译成apk在系统编译里头,默认会把应用编译成apk和odex,其中apk只有java编译出来的类,odex有资源文件 如果要单独编译成一个apk的话,可以在mk文件里添加:WITH_DEXPREOPT := false打开MTKlogadb shell am start -n com.mediatek.mtklogger/com.mediatek.mtklogger.MainActivity
Shell命令getopts简单明了的解释
话可以去看看以下这篇文章 相关内容 AOSP-android必备基础知识 Linux Shell
阳光沙滩博客系统-Redis
6379:6379" volumes: - /home/aosp/docker/redis/data:/data 连接Redis 添加依赖
Android8.1源码GPS看看记录
定位 定位方式有很多种,比如说GPS,Network,基站。 如何判断设备支持什么类型的定位? 在LocationManager里提供了方法,获取到所有的Providers public List getAllProviders() { try { return mService.getAllProviders(); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } 通过context就可以获取到LocationManager了,LocationManager服务在系统初始化的时候注册,所以通过context就可以获取到了。详情请看附录。 系统架构 主要看看GPS的 GPS主要关注GnssLocationProvider,其他的Provider用于其他定位方式。 创建的地方在LocationManagerService mRealProviders.put(LocationManager.GPS_PROVIDER, gnssProvider); mRealProviders.put(LocationManager.NETWORK_PROVIDER, networkProvider); mRealProviders.put(LocationManager.FUSED_PROVIDER, fusedLocationProvider); hardwear对应的文件在hardwear目录下 \android8.1\hardware\interfaces\gnss\1.0\default 主要的类关系图 完整的上层获取到底层Location信息变化的流程(Android8.1版本) 以下步骤,省略了权限,是否支持GPS检查之类的安全操作,主要路线如下:对着代码走一次就知道了。 ===============App层============================================= 1、获取到LocationManager LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 2、向LocationManager里添加监听 lm.requestLocationUpdates( LocationManager.GPS_PROVIDER, 1000,//时间 100.0f,//触发通知的变化距离 new LocationListener() { @Override public void onLocationChanged(Location location) { //location变化 } @Override public void onStatusChanged(String provider, int status, Bundle extras) { //状态变化 } @Override public void onProviderEnabled(String provider) { //定位方式开启:gps、network.. } @Override public void onProviderDisabled(String provider) { //定位方式关闭 } } ); 3、做了一层包装,然后调用requestLocationUpdates public void requestLocationUpdates(@NonNull String provider, long minTime, float minDistance, @NonNull LocationListener listener) { checkProvider(provider); checkListener(listener); LocationRequest request = LocationRequest.createFromDeprecatedProvider( provider, minTime, minDistance, false); requestLocationUpdates(request, listener, null, null); } 4、调用到远程服务的requestLocationUpdates private void requestLocationUpdates(LocationRequest request, LocationListener listener, Looper looper, PendingIntent intent) { String packageName = mContext.getPackageName(); // wrap the listener class ListenerTransport transport = wrapListener(listener, looper); try { mService.requestLocationUpdates(request, transport, intent, packageName); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } catch (IllegalArgumentException e) { Log.e(TAG, "IllegalArgumentException", e); } } ===============Framework层 Java ============================================= 5、远程服务是谁呢? private final ILocationManager mService; public class LocationManagerService extends ILocationManager.Stub 远程服务是LocationManagerService 那我们在LocationManagerService里找找requestLocationUpdates方法 @Override public void requestLocationUpdates(LocationRequest request, ILocationListener listener, PendingIntent intent, String packageName) { if (request == null) request = DEFAULT_LOCATION_REQUEST; checkPackageName(packageName); int allowedResolutionLevel = getCallerAllowedResolutionLevel(); checkResolutionLevelIsSufficientForProviderUse(allowedResolutionLevel, request.getProvider()); WorkSource workSource = request.getWorkSource(); if (workSource != null && workSource.size() > 0) { checkDeviceStatsAllowed(); } boolean hideFromAppOps = request.getHideFromAppOps(); if (hideFromAppOps) { checkUpdateAppOpsAllowed(); } LocationRequest sanitizedRequest = createSanitizedRequest(request, allowedResolutionLevel); final int pid = Binder.getCallingPid(); final int uid = Binder.getCallingUid(); // providers may use public location API's, need to clear identity long identity = Binder.clearCallingIdentity(); try { // We don't check for MODE_IGNORED here; we will do that when we go to deliver // a location. checkLocationAccess(pid, uid, packageName, allowedResolutionLevel); synchronized (mLock) { Receiver recevier = checkListenerOrIntentLocked(listener, intent, pid, uid, packageName, workSource, hideFromAppOps); requestLocationUpdatesLocked(sanitizedRequest, recevier, pid, uid, packageName); } } finally { Binder.restoreCallingIdentity(identity); } } 6、走到这里,关心Listener在哪里调用就知道Location在哪里更新了 上面的代码里我们走到了checkListenerOrIntentLocked private Receiver checkListenerOrIntentLocked(ILocationListener listener, PendingIntent intent, int pid, int uid, String packageName, WorkSource workSource, boolean hideFromAppOps) { if (intent == null && listener == null) { throw new IllegalArgumentException("need either listener or intent"); } else if (intent != null && listener != null) { throw new IllegalArgumentException("cannot register both listener and intent"); } else if (intent != null) { checkPendingIntent(intent); return getReceiverLocked(intent, pid, uid, packageName, workSource, hideFromAppOps); } else { return getReceiverLocked(listener, pid, uid, packageName, workSource, hideFromAppOps); } } 7、getReceiverLocked里会创建Receiver,Listener主成了Receiver的成员变量了。这里是framework层的LocationManagerService private Receiver getReceiverLocked(ILocationListener listener, int pid, int uid, String packageName, WorkSource workSource, boolean hideFromAppOps) { IBinder binder = listener.asBinder(); Receiver receiver = mReceivers.get(binder); if (receiver == null) { receiver = new Receiver(listener, null, pid, uid, packageName, workSource, hideFromAppOps); try { receiver.getListener().asBinder().linkToDeath(receiver, 0); } catch (RemoteException e) { Slog.e(TAG, "linkToDeath failed:", e); return null; } mReceivers.put(binder, receiver); } return receiver; } 8、通知上层更新的地方 mListener.onStatusChanged(provider, status, extras); mListener.onLocationChanged(new Location(location)); mListener.onProviderEnabled(provider); mListener.onProviderDisabled(provider); 这就对应着我们开头设置监听的地方了。 那么以上又是如何通知的呢? 9、通知LocationChange的地方 public boolean callLocationChangedLocked(Location location) { ... mListener.onLocationChanged(new Location(location)); ... } 哪里通知Location变化呢? private void handleLocationChangedLocked(Location location, boolean passive) { ... if (!receiver.callStatusChangedLocked(provider, status, extras)) { receiverDead = true; Slog.w(TAG, "RemoteException calling onStatusChanged on " + receiver); } ... } 往上回去找则是 private void handleLocationChanged(Location location, boolean passive) { ... synchronized (mLock) { if (isAllowedByCurrentUserSettingsLocked(provider)) { if (!passive) { // notify passive provider of the new location mPassiveProvider.updateLocation(myLocation); } handleLocationChangedLocked(myLocation, passive); } } } 其实就是在Handler里接收到消息以后通知的 private class LocationWorkerHandler extends Handler { public LocationWorkerHandler(Looper looper) { super(looper, null, true); } @Override public void handleMessage(Message msg) { switch (msg.what) { case MSG_LOCATION_CHANGED: handleLocationChanged((Location) msg.obj, msg.arg1 == 1); break; } } } 所以,我们找到MSG_LOCATION_CHANGED发送的地方,就知道Location是从哪里来的了。 在LocationManagerService.java里 @Override public void reportLocation(Location location, boolean passive) { checkCallerIsProvider(); if (!location.isComplete()) { Log.w(TAG, "Dropping incomplete location: " + location); return; } mLocationHandler.removeMessages(MSG_LOCATION_CHANGED, location); Message m = Message.obtain(mLocationHandler, MSG_LOCATION_CHANGED, location); m.arg1 = (passive ? 1 : 0); mLocationHandler.sendMessageAtFrontOfQueue(m); } 接下来则便是要找到reportLocation是哪里调用的呢? 当系统启动的时候,会走这个代码 com.android.server.LocationManagerService#loadProvidersLocked GnssLocationProvider gnssProvider = new GnssLocationProvider(mContext, this, mLocationHandler.getLooper()); reportLocation是被GnssLocationProvider里通知的。 在创建GnssLocationProvider的时候,把this传进去了,也就是LocationManagerService。那么GnssLocationProvider就可以通知LocationManagerService里的reportLocation方法了。 代码如下: /** * called from native code to update our position. */ private void reportLocation(boolean hasLatLong, Location location) { ... synchronized (mLocation) { mLocation = location; // It would be nice to push the elapsed real-time timestamp // further down the stack, but this is still useful mLocation.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos()); mLocation.setExtras(mLocationExtras); try { mILocationManager.reportLocation(mLocation, false); } catch (RemoteException e) { Log.e(TAG, "RemoteException calling reportLocation"); } } ... } 到这里,我们可以看到注释,called from native code to update our position.这个方法是被Native调用的,也就是底层通过反射的方式调用此方法。这里就到了framework的jni层了。 ===============Framework层 JNI ============================================= ./base/services/core/jni/com_android_server_location_GnssLocationProvider.cpp 我们就以reportLocation这个方法为例,在com_android_server_location_GnssLocationProvider.cpp里 Return GnssCallback::gnssLocationCb( const ::android::hardware::gnss::V1_0::GnssLocation& location) { JNIEnv* env = getJniEnv(); jobject jLocation = translateLocation(env, location); bool hasLatLong = (static_cast(location.gnssLocationFlags) & hardware::gnss::V1_0::GnssLocationFlags::HAS_LAT_LONG) != 0; env->CallVoidMethod(mCallbacksObj, method_reportLocation, boolToJbool(hasLatLong), jLocation); checkAndClearExceptionFromCallback(env, __FUNCTION__); return Void(); } 这里面就是Location变化的回调了。 到这里的话,就到了framework的jni层了。 再往下就到hal层了。引入的头文件 #include #include #include sp gnssHal = nullptr; # 可以看到通过gnssHal去设置了callback,然后底层就可以通过回调的方式通知到framework层的jni层了 auto result = gnssHal->setCallback(gnssCbIface); ============== hal 层 =============================================  \android8.1\hardware\interfaces\gnss\1.0\default 附录 服务在哪里注册的?为什么context.getSystemService(xxx) 就可以获取到服务? 服务会在SystemServiceRegistry.java进行注册,这个是在系统初始化的时候进行注册的。调用context.getSystemService(xxx)服务,除了WindowService、SearchService、LayoutInflateService以外,其他的Service都是从contextImpl中的getSystemService(serviceName)中获取的。前面三个服务,直接在Activity/contextWrapper里创建返回了。 ContextImpl.java里获取常见的服务: 注释的是key,返回的是value。我们前面Context.LOCATION_SERVICE,对应的就是LocationManager了,所以返回了LocationManager。如果想知道ContextImpl.java里是如何获取的,请继续往下看吧。 #WINDOW_SERVICE android.view.WindowManager #LAYOUT_INFLATER_SERVICE android.view.LayoutInflater #ACTIVITY_SERVICE android.app.ActivityManager #POWER_SERVICE android.os.PowerManager #ALARM_SERVICE android.app.AlarmManager #NOTIFICATION_SERVICE android.app.NotificationManager #KEYGUARD_SERVICE android.app.KeyguardManager #LOCATION_SERVICE android.location.LocationManager #SEARCH_SERVICE android.app.SearchManager #SENSOR_SERVICE android.hardware.SensorManager #STORAGE_SERVICE android.os.storage.StorageManager #VIBRATOR_SERVICE android.os.Vibrator #CONNECTIVITY_SERVICE android.net.ConnectivityManager #WIFI_SERVICE android.net.wifi.WifiManager #AUDIO_SERVICE android.media.AudioManager #MEDIA_ROUTER_SERVICE android.media.MediaRouter #TELEPHONY_SERVICE android.telephony.TelephonyManager #TELEPHONY_SUBSCRIPTION_SERVICE android.telephony.SubscriptionManager #CARRIER_CONFIG_SERVICE android.telephony.CarrierConfigManager #INPUT_METHOD_SERVICE android.view.inputmethod.InputMethodManager #UI_MODE_SERVICE android.app.UiModeManager #DOWNLOAD_SERVICE android.app.DownloadManager #BATTERY_SERVICE android.os.BatteryManager #JOB_SCHEDULER_SERVICE android.app.job.JobScheduler #NETWORK_STATS_SERVICE android.app.usage.NetworkStatsManager android.os.HardwarePropertiesManager #HARDWARE_PROPERTIES_SERVICE 在android.app.ContextImpl.java中,路径在frameworks/base/core/java/android/app/ContextImpl.java里 我们可以看到 public Object getSystemService(String name) { return SystemServiceRegistry.getSystemService(this, name); } 也就是说,是从SystemServiceRegistry里获取的,里面维护者一个Map集合。 key是服务的名称,值是服务。也就是上面这个表,当然,还可以添加其他服务。
MyBatis使用级别文章(详细)
AOSP就知道了,一般厂商自己定义的东西就放在vendor目录下面。那怎么使用呢?第一步: <databaseIdProvider type="DB_VENDOR">
Android原生代码是怎么实现返回键和Home键功能的呢?
最近要修改SystemUI,所以要看原生的代码,SystemUI包括什么内容呢?锁屏界面通知壁纸管理截屏状态栏目+NavigationBar(导航栏:返回键,Home键,最近任务)由于我看的代码是MTK修改过的,我也不知道是不是原生的,反正大同小异吧。原生系统的代码我也有,待会去看一下就知道了。这一篇文章的主题是返回键和Home键的功能实现是怎么样的。首先,这个是Navigation Bar:对,这就是导航栏,俗称NavigationBar它的布局代码是怎么样的呢?大家注意到没有?里面有一个很重要的东西:keyCode=”value”我们小时候复写返回键的功能的时候,也就是禁止返回键,我们有两个方法,一个是复写onBackPress()方法,或者判断onKeyEvent的keyCode,当我们判断到keyCode是4的时候,就是返回键被点击了,接着消费掉即可。所以,keyCode代表一个按键的code,各个按键的code如下: /** Key code constant: Unknown key code. */ public static final int KEYCODE_UNKNOWN = 0; /** Key code constant: Soft Left key. * Usually situated below the display on phones and used as a multi-function * feature key for selecting a software defined function shown on the bottom left * of the display. */ public static final int KEYCODE_SOFT_LEFT = 1; /** Key code constant: Soft Right key. * Usually situated below the display on phones and used as a multi-function * feature key for selecting a software defined function shown on the bottom right * of the display. */ public static final int KEYCODE_SOFT_RIGHT = 2; /** Key code constant: Home key. * This key is handled by the framework and is never delivered to applications. */ public static final int KEYCODE_HOME = 3; /** Key code constant: Back key. */ public static final int KEYCODE_BACK = 4; /** Key code constant: Call key. */ public static final int KEYCODE_CALL = 5; /** Key code constant: End Call key. */ public static final int KEYCODE_ENDCALL = 6; /** Key code constant: '0' key. */ public static final int KEYCODE_0 = 7; /** Key code constant: '1' key. */ public static final int KEYCODE_1 = 8; /** Key code constant: '2' key. */ public static final int KEYCODE_2 = 9; /** Key code constant: '3' key. */ public static final int KEYCODE_3 = 10; /** Key code constant: '4' key. */ public static final int KEYCODE_4 = 11; /** Key code constant: '5' key. */ public static final int KEYCODE_5 = 12; /** Key code constant: '6' key. */ public static final int KEYCODE_6 = 13; /** Key code constant: '7' key. */ public static final int KEYCODE_7 = 14; /** Key code constant: '8' key. */ public static final int KEYCODE_8 = 15; /** Key code constant: '9' key. */ public static final int KEYCODE_9 = 16; /** Key code constant: '*' key. */ public static final int KEYCODE_STAR = 17; /** Key code constant: '#' key. */ public static final int KEYCODE_POUND = 18; /** Key code constant: Directional Pad Up key. * May also be synthesized from trackball motions. */ public static final int KEYCODE_DPAD_UP = 19; /** Key code constant: Directional Pad Down key. * May also be synthesized from trackball motions. */ public static final int KEYCODE_DPAD_DOWN = 20; /** Key code constant: Directional Pad Left key. * May also be synthesized from trackball motions. */ public static final int KEYCODE_DPAD_LEFT = 21; /** Key code constant: Directional Pad Right key. * May also be synthesized from trackball motions. */ public static final int KEYCODE_DPAD_RIGHT = 22; /** Key code constant: Directional Pad Center key. * May also be synthesized from trackball motions. */ public static final int KEYCODE_DPAD_CENTER = 23; /** Key code constant: Volume Up key. * Adjusts the speaker volume up. */ public static final int KEYCODE_VOLUME_UP = 24; /** Key code constant: Volume Down key. * Adjusts the speaker volume down. */ public static final int KEYCODE_VOLUME_DOWN = 25; /** Key code constant: Power key. */ public static final int KEYCODE_POWER = 26; /** Key code constant: Camera key. * Used to launch a camera application or take pictures. */ public static final int KEYCODE_CAMERA = 27; /** Key code constant: Clear key. */ public static final int KEYCODE_CLEAR = 28; /** Key code constant: 'A' key. */ public static final int KEYCODE_A = 29; /** Key code constant: 'B' key. */ public static final int KEYCODE_B = 30; /** Key code constant: 'C' key. */ public static final int KEYCODE_C = 31; /** Key code constant: 'D' key. */ public static final int KEYCODE_D = 32; /** Key code constant: 'E' key. */ public static final int KEYCODE_E = 33; /** Key code constant: 'F' key. */ public static final int KEYCODE_F = 34; /** Key code constant: 'G' key. */ public static final int KEYCODE_G = 35; /** Key code constant: 'H' key. */ public static final int KEYCODE_H = 36; /** Key code constant: 'I' key. */ public static final int KEYCODE_I = 37; /** Key code constant: 'J' key. */ public static final int KEYCODE_J = 38; /** Key code constant: 'K' key. */ public static final int KEYCODE_K = 39; /** Key code constant: 'L' key. */ public static final int KEYCODE_L = 40; /** Key code constant: 'M' key. */ public static final int KEYCODE_M = 41; /** Key code constant: 'N' key. */ public static final int KEYCODE_N = 42; /** Key code constant: 'O' key. */ public static final int KEYCODE_O = 43; /** Key code constant: 'P' key. */ public static final int KEYCODE_P = 44; /** Key code constant: 'Q' key. */ public static final int KEYCODE_Q = 45; /** Key code constant: 'R' key. */ public static final int KEYCODE_R = 46; /** Key code constant: 'S' key. */ public static final int KEYCODE_S = 47; /** Key code constant: 'T' key. */ public static final int KEYCODE_T = 48; /** Key code constant: 'U' key. */ public static final int KEYCODE_U = 49; /** Key code constant: 'V' key. */ public static final int KEYCODE_V = 50; /** Key code constant: 'W' key. */ public static final int KEYCODE_W = 51; /** Key code constant: 'X' key. */ public static final int KEYCODE_X = 52; /** Key code constant: 'Y' key. */ public static final int KEYCODE_Y = 53; /** Key code constant: 'Z' key. */ public static final int KEYCODE_Z = 54; /** Key code constant: ',' key. */ public static final int KEYCODE_COMMA = 55; /** Key code constant: '.' key. */ public static final int KEYCODE_PERIOD = 56; /** Key code constant: Left Alt modifier key. */ public static final int KEYCODE_ALT_LEFT = 57; /** Key code constant: Right Alt modifier key. */ public static final int KEYCODE_ALT_RIGHT = 58; /** Key code constant: Left Shift modifier key. */ public static final int KEYCODE_SHIFT_LEFT = 59; /** Key code constant: Right Shift modifier key. */ public static final int KEYCODE_SHIFT_RIGHT = 60; /** Key code constant: Tab key. */ public static final int KEYCODE_TAB = 61; /** Key code constant: Space key. */ public static final int KEYCODE_SPACE = 62; /** Key code constant: Symbol modifier key. * Used to enter alternate symbols. */ public static final int KEYCODE_SYM = 63; /** Key code constant: Explorer special function key. * Used to launch a browser application. */ public static final int KEYCODE_EXPLORER = 64; /** Key code constant: Envelope special function key. * Used to launch a mail application. */ public static final int KEYCODE_ENVELOPE = 65; /** Key code constant: Enter key. */ public static final int KEYCODE_ENTER = 66; /** Key code constant: Backspace key. * Deletes characters before the insertion point, unlike {@link #KEYCODE_FORWARD_DEL}. */ public static final int KEYCODE_DEL = 67; /** Key code constant: '`' (backtick) key. */ public static final int KEYCODE_GRAVE = 68; /** Key code constant: '-'. */ public static final int KEYCODE_MINUS = 69; /** Key code constant: '=' key. */ public static final int KEYCODE_EQUALS = 70; /** Key code constant: '[' key. */ public static final int KEYCODE_LEFT_BRACKET = 71; /** Key code constant: ']' key. */ public static final int KEYCODE_RIGHT_BRACKET = 72; /** Key code constant: '\' key. */ public static final int KEYCODE_BACKSLASH = 73; /** Key code constant: ';' key. */ public static final int KEYCODE_SEMICOLON = 74; /** Key code constant: ''' (apostrophe) key. */ public static final int KEYCODE_APOSTROPHE = 75; /** Key code constant: '/' key. */ public static final int KEYCODE_SLASH = 76; /** Key code constant: '@' key. */ public static final int KEYCODE_AT = 77; /** Key code constant: Number modifier key. * Used to enter numeric symbols. * This key is not Num Lock; it is more like {@link #KEYCODE_ALT_LEFT} and is * interpreted as an ALT key by {@link android.text.method.MetaKeyKeyListener}. */ public static final int KEYCODE_NUM = 78; /** Key code constant: Headset Hook key. * Used to hang up calls and stop media. */ public static final int KEYCODE_HEADSETHOOK = 79; /** Key code constant: Camera Focus key. * Used to focus the camera. */ public static final int KEYCODE_FOCUS = 80; // *Camera* focus /** Key code constant: '+' key. */ public static final int KEYCODE_PLUS = 81; /** Key code constant: Menu key. */ public static final int KEYCODE_MENU = 82; /** Key code constant: Notification key. */ public static final int KEYCODE_NOTIFICATION = 83; /** Key code constant: Search key. */ public static final int KEYCODE_SEARCH = 84; /** Key code constant: Play/Pause media key. */ public static final int KEYCODE_MEDIA_PLAY_PAUSE= 85; /** Key code constant: Stop media key. */ public static final int KEYCODE_MEDIA_STOP = 86; /** Key code constant: Play Next media key. */ public static final int KEYCODE_MEDIA_NEXT = 87; /** Key code constant: Play Previous media key. */ public static final int KEYCODE_MEDIA_PREVIOUS = 88; /** Key code constant: Rewind media key. */ public static final int KEYCODE_MEDIA_REWIND = 89; /** Key code constant: Fast Forward media key. */ public static final int KEYCODE_MEDIA_FAST_FORWARD = 90; /** Key code constant: Mute key. * Mutes the microphone, unlike {@link #KEYCODE_VOLUME_MUTE}. */ public static final int KEYCODE_MUTE = 91; /** Key code constant: Page Up key. */ public static final int KEYCODE_PAGE_UP = 92; /** Key code constant: Page Down key. */ public static final int KEYCODE_PAGE_DOWN = 93; /** Key code constant: Picture Symbols modifier key. * Used to switch symbol sets (Emoji, Kao-moji). */ public static final int KEYCODE_PICTSYMBOLS = 94; // switch symbol-sets (Emoji,Kao-moji) /** Key code constant: Switch Charset modifier key. * Used to switch character sets (Kanji, Katakana). */ public static final int KEYCODE_SWITCH_CHARSET = 95; // switch char-sets (Kanji,Katakana) /** Key code constant: A Button key. * On a game controller, the A button should be either the button labeled A * or the first button on the bottom row of controller buttons. */ public static final int KEYCODE_BUTTON_A = 96; /** Key code constant: B Button key. * On a game controller, the B button should be either the button labeled B * or the second button on the bottom row of controller buttons. */ public static final int KEYCODE_BUTTON_B = 97; /** Key code constant: C Button key. * On a game controller, the C button should be either the button labeled C * or the third button on the bottom row of controller buttons. */ public static final int KEYCODE_BUTTON_C = 98; /** Key code constant: X Button key. * On a game controller, the X button should be either the button labeled X * or the first button on the upper row of controller buttons. */ public static final int KEYCODE_BUTTON_X = 99; /** Key code constant: Y Button key. * On a game controller, the Y button should be either the button labeled Y * or the second button on the upper row of controller buttons. */ public static final int KEYCODE_BUTTON_Y = 100; /** Key code constant: Z Button key. * On a game controller, the Z button should be either the button labeled Z * or the third button on the upper row of controller buttons. */ public static final int KEYCODE_BUTTON_Z = 101; /** Key code constant: L1 Button key. * On a game controller, the L1 button should be either the button labeled L1 (or L) * or the top left trigger button. */ public static final int KEYCODE_BUTTON_L1 = 102; /** Key code constant: R1 Button key. * On a game controller, the R1 button should be either the button labeled R1 (or R) * or the top right trigger button. */ public static final int KEYCODE_BUTTON_R1 = 103; /** Key code constant: L2 Button key. * On a game controller, the L2 button should be either the button labeled L2 * or the bottom left trigger button. */ public static final int KEYCODE_BUTTON_L2 = 104; /** Key code constant: R2 Button key. * On a game controller, the R2 button should be either the button labeled R2 * or the bottom right trigger button. */ public static final int KEYCODE_BUTTON_R2 = 105; /** Key code constant: Left Thumb Button key. * On a game controller, the left thumb button indicates that the left (or only) * joystick is pressed. */ public static final int KEYCODE_BUTTON_THUMBL = 106; /** Key code constant: Right Thumb Button key. * On a game controller, the right thumb button indicates that the right * joystick is pressed. */ public static final int KEYCODE_BUTTON_THUMBR = 107; /** Key code constant: Start Button key. * On a game controller, the button labeled Start. */ public static final int KEYCODE_BUTTON_START = 108; /** Key code constant: Select Button key. * On a game controller, the button labeled Select. */ public static final int KEYCODE_BUTTON_SELECT = 109; /** Key code constant: Mode Button key. * On a game controller, the button labeled Mode. */ public static final int KEYCODE_BUTTON_MODE = 110; /** Key code constant: Escape key. */ public static final int KEYCODE_ESCAPE = 111; /** Key code constant: Forward Delete key. * Deletes characters ahead of the insertion point, unlike {@link #KEYCODE_DEL}. */ public static final int KEYCODE_FORWARD_DEL = 112; /** Key code constant: Left Control modifier key. */ public static final int KEYCODE_CTRL_LEFT = 113; /** Key code constant: Right Control modifier key. */ public static final int KEYCODE_CTRL_RIGHT = 114; /** Key code constant: Caps Lock key. */ public static final int KEYCODE_CAPS_LOCK = 115; /** Key code constant: Scroll Lock key. */ public static final int KEYCODE_SCROLL_LOCK = 116; /** Key code constant: Left Meta modifier key. */ public static final int KEYCODE_META_LEFT = 117; /** Key code constant: Right Meta modifier key. */ public static final int KEYCODE_META_RIGHT = 118; /** Key code constant: Function modifier key. */ public static final int KEYCODE_FUNCTION = 119; /** Key code constant: System Request / Print Screen key. */ public static final int KEYCODE_SYSRQ = 120; /** Key code constant: Break / Pause key. */ public static final int KEYCODE_BREAK = 121; /** Key code constant: Home Movement key. * Used for scrolling or moving the cursor around to the start of a line * or to the top of a list. */ public static final int KEYCODE_MOVE_HOME = 122; /** Key code constant: End Movement key. * Used for scrolling or moving the cursor around to the end of a line * or to the bottom of a list. */ public static final int KEYCODE_MOVE_END = 123; /** Key code constant: Insert key. * Toggles insert / overwrite edit mode. */ public static final int KEYCODE_INSERT = 124; /** Key code constant: Forward key. * Navigates forward in the history stack. Complement of {@link #KEYCODE_BACK}. */ public static final int KEYCODE_FORWARD = 125; /** Key code constant: Play media key. */ public static final int KEYCODE_MEDIA_PLAY = 126; /** Key code constant: Pause media key. */ public static final int KEYCODE_MEDIA_PAUSE = 127; /** Key code constant: Close media key. * May be used to close a CD tray, for example. */ public static final int KEYCODE_MEDIA_CLOSE = 128; /** Key code constant: Eject media key. * May be used to eject a CD tray, for example. */ public static final int KEYCODE_MEDIA_EJECT = 129; /** Key code constant: Record media key. */ public static final int KEYCODE_MEDIA_RECORD = 130; /** Key code constant: F1 key. */ public static final int KEYCODE_F1 = 131; /** Key code constant: F2 key. */ public static final int KEYCODE_F2 = 132; /** Key code constant: F3 key. */ public static final int KEYCODE_F3 = 133; /** Key code constant: F4 key. */ public static final int KEYCODE_F4 = 134; /** Key code constant: F5 key. */ public static final int KEYCODE_F5 = 135; /** Key code constant: F6 key. */ public static final int KEYCODE_F6 = 136; /** Key code constant: F7 key. */ public static final int KEYCODE_F7 = 137; /** Key code constant: F8 key. */ public static final int KEYCODE_F8 = 138; /** Key code constant: F9 key. */ public static final int KEYCODE_F9 = 139; /** Key code constant: F10 key. */ public static final int KEYCODE_F10 = 140; /** Key code constant: F11 key. */ public static final int KEYCODE_F11 = 141; /** Key code constant: F12 key. */ public static final int KEYCODE_F12 = 142; /** Key code constant: Num Lock key. * This is the Num Lock key; it is different from {@link #KEYCODE_NUM}. * This key alters the behavior of other keys on the numeric keypad. */ public static final int KEYCODE_NUM_LOCK = 143; /** Key code constant: Numeric keypad '0' key. */ public static final int KEYCODE_NUMPAD_0 = 144; /** Key code constant: Numeric keypad '1' key. */ public static final int KEYCODE_NUMPAD_1 = 145; /** Key code constant: Numeric keypad '2' key. */ public static final int KEYCODE_NUMPAD_2 = 146; /** Key code constant: Numeric keypad '3' key. */ public static final int KEYCODE_NUMPAD_3 = 147; /** Key code constant: Numeric keypad '4' key. */ public static final int KEYCODE_NUMPAD_4 = 148; /** Key code constant: Numeric keypad '5' key. */ public static final int KEYCODE_NUMPAD_5 = 149; /** Key code constant: Numeric keypad '6' key. */ public static final int KEYCODE_NUMPAD_6 = 150; /** Key code constant: Numeric keypad '7' key. */ public static final int KEYCODE_NUMPAD_7 = 151; /** Key code constant: Numeric keypad '8' key. */ public static final int KEYCODE_NUMPAD_8 = 152; /** Key code constant: Numeric keypad '9' key. */ public static final int KEYCODE_NUMPAD_9 = 153; /** Key code constant: Numeric keypad '/' key (for division). */ public static final int KEYCODE_NUMPAD_DIVIDE = 154; /** Key code constant: Numeric keypad '*' key (for multiplication). */ public static final int KEYCODE_NUMPAD_MULTIPLY = 155; /** Key code constant: Numeric keypad '-' key (for subtraction). */ public static final int KEYCODE_NUMPAD_SUBTRACT = 156; /** Key code constant: Numeric keypad '+' key (for addition). */ public static final int KEYCODE_NUMPAD_ADD = 157; /** Key code constant: Numeric keypad '.' key (for decimals or digit grouping). */ public static final int KEYCODE_NUMPAD_DOT = 158; /** Key code constant: Numeric keypad ',' key (for decimals or digit grouping). */ public static final int KEYCODE_NUMPAD_COMMA = 159; /** Key code constant: Numeric keypad Enter key. */ public static final int KEYCODE_NUMPAD_ENTER = 160; /** Key code constant: Numeric keypad '=' key. */ public static final int KEYCODE_NUMPAD_EQUALS = 161; /** Key code constant: Numeric keypad '(' key. */ public static final int KEYCODE_NUMPAD_LEFT_PAREN = 162; /** Key code constant: Numeric keypad ')' key. */ public static final int KEYCODE_NUMPAD_RIGHT_PAREN = 163; /** Key code constant: Volume Mute key. * Mutes the speaker, unlike {@link #KEYCODE_MUTE}. * This key should normally be implemented as a toggle such that the first press * mutes the speaker and the second press restores the original volume. */ public static final int KEYCODE_VOLUME_MUTE = 164; /** Key code constant: Info key. * Common on TV remotes to show additional information related to what is * currently being viewed. */ public static final int KEYCODE_INFO = 165; /** Key code constant: Channel up key. * On TV remotes, increments the television channel. */ public static final int KEYCODE_CHANNEL_UP = 166; /** Key code constant: Channel down key. * On TV remotes, decrements the television channel. */ public static final int KEYCODE_CHANNEL_DOWN = 167; /** Key code constant: Zoom in key. */ public static final int KEYCODE_ZOOM_IN = 168; /** Key code constant: Zoom out key. */ public static final int KEYCODE_ZOOM_OUT = 169; /** Key code constant: TV key. * On TV remotes, switches to viewing live TV. */ public static final int KEYCODE_TV = 170; /** Key code constant: Window key. * On TV remotes, toggles picture-in-picture mode or other windowing functions. */ public static final int KEYCODE_WINDOW = 171; /** Key code constant: Guide key. * On TV remotes, shows a programming guide. */ public static final int KEYCODE_GUIDE = 172; /** Key code constant: DVR key. * On some TV remotes, switches to a DVR mode for recorded shows. */ public static final int KEYCODE_DVR = 173; /** Key code constant: Bookmark key. * On some TV remotes, bookmarks content or web pages. */ public static final int KEYCODE_BOOKMARK = 174; /** Key code constant: Toggle captions key. * Switches the mode for closed-captioning text, for example during television shows. */ public static final int KEYCODE_CAPTIONS = 175; /** Key code constant: Settings key. * Starts the system settings activity. */ public static final int KEYCODE_SETTINGS = 176; /** Key code constant: TV power key. * On TV remotes, toggles the power on a television screen. */ public static final int KEYCODE_TV_POWER = 177; /** Key code constant: TV input key. * On TV remotes, switches the input on a television screen. */ public static final int KEYCODE_TV_INPUT = 178; /** Key code constant: Set-top-box power key. * On TV remotes, toggles the power on an external Set-top-box. */ public static final int KEYCODE_STB_POWER = 179; /** Key code constant: Set-top-box input key. * On TV remotes, switches the input mode on an external Set-top-box. */ public static final int KEYCODE_STB_INPUT = 180; /** Key code constant: A/V Receiver power key. * On TV remotes, toggles the power on an external A/V Receiver. */ public static final int KEYCODE_AVR_POWER = 181; /** Key code constant: A/V Receiver input key. * On TV remotes, switches the input mode on an external A/V Receiver. */ public static final int KEYCODE_AVR_INPUT = 182; /** Key code constant: Red "programmable" key. * On TV remotes, acts as a contextual/programmable key. */ public static final int KEYCODE_PROG_RED = 183; /** Key code constant: Green "programmable" key. * On TV remotes, actsas a contextual/programmable key. */ public static final int KEYCODE_PROG_GREEN = 184; /** Key code constant: Yellow "programmable" key. * On TV remotes, acts as a contextual/programmable key. */ public static final int KEYCODE_PROG_YELLOW = 185; /** Key code constant: Blue "programmable" key. * On TV remotes, acts as a contextual/programmable key. */ public static final int KEYCODE_PROG_BLUE = 186; /** Key code constant: App switch key. * Should bring up the application switcher dialog. */ public static final int KEYCODE_APP_SWITCH = 187; /** Key code constant: Generic Game Pad Button #1.*/ public static final int KEYCODE_BUTTON_1 = 188; /** Key code constant: Generic Game Pad Button #2.*/ public static final int KEYCODE_BUTTON_2 = 189; /** Key code constant: Generic Game Pad Button #3.*/ public static final int KEYCODE_BUTTON_3 = 190; /** Key code constant: Generic Game Pad Button #4.*/ public static final int KEYCODE_BUTTON_4 = 191; /** Key code constant: Generic Game Pad Button #5.*/ public static final int KEYCODE_BUTTON_5 = 192; /** Key code constant: Generic Game Pad Button #6.*/ public static final int KEYCODE_BUTTON_6 = 193; /** Key code constant: Generic Game Pad Button #7.*/ public static final int KEYCODE_BUTTON_7 = 194; /** Key code constant: Generic Game Pad Button #8.*/ public static final int KEYCODE_BUTTON_8 = 195; /** Key code constant: Generic Game Pad Button #9.*/ public static final int KEYCODE_BUTTON_9 = 196; /** Key code constant: Generic Game Pad Button #10.*/ public static final int KEYCODE_BUTTON_10 = 197; /** Key code constant: Generic Game Pad Button #11.*/ public static final int KEYCODE_BUTTON_11 = 198; /** Key code constant: Generic Game Pad Button #12.*/ public static final int KEYCODE_BUTTON_12 = 199; /** Key code constant: Generic Game Pad Button #13.*/ public static final int KEYCODE_BUTTON_13 = 200; /** Key code constant: Generic Game Pad Button #14.*/ public static final int KEYCODE_BUTTON_14 = 201; /** Key code constant: Generic Game Pad Button #15.*/ public static final int KEYCODE_BUTTON_15 = 202; /** Key code constant: Generic Game Pad Button #16.*/ public static final int KEYCODE_BUTTON_16 = 203; /** Key code constant: Language Switch key. * Toggles the current input language such as switching between English and Japanese on * a QWERTY keyboard. On some devices, the same function may be performed by * pressing Shift+Spacebar. */ public static final int KEYCODE_LANGUAGE_SWITCH = 204; /** Key code constant: Manner Mode key. * Toggles silent or vibrate mode on and off to make the device behave more politely * in certain settings such as on a crowded train. On some devices, the key may only * operate when long-pressed. */ public static final int KEYCODE_MANNER_MODE = 205; /** Key code constant: 3D Mode key. * Toggles the display between 2D and 3D mode. */ public static final int KEYCODE_3D_MODE = 206; /** Key code constant: Contacts special function key. * Used to launch an address book application. */ public static final int KEYCODE_CONTACTS = 207; /** Key code constant: Calendar special function key. * Used to launch a calendar application. */ public static final int KEYCODE_CALENDAR = 208; /** Key code constant: Music special function key. * Used to launch a music player application. */ public static final int KEYCODE_MUSIC = 209; /** Key code constant: Calculator special function key. * Used to launch a calculator application. */ public static final int KEYCODE_CALCULATOR = 210; /** Key code constant: Japanese full-width / half-width key. */ public static final int KEYCODE_ZENKAKU_HANKAKU = 211; /** Key code constant: Japanese alphanumeric key. */ public static final int KEYCODE_EISU = 212; /** Key code constant: Japanese non-conversion key. */ public static final int KEYCODE_MUHENKAN = 213; /** Key code constant: Japanese conversion key. */ public static final int KEYCODE_HENKAN = 214; /** Key code constant: Japanese katakana / hiragana key. */ public static final int KEYCODE_KATAKANA_HIRAGANA = 215; /** Key code constant: Japanese Yen key. */ public static final int KEYCODE_YEN = 216; /** Key code constant: Japanese Ro key. */ public static final int KEYCODE_RO = 217; /** Key code constant: Japanese kana key. */ public static final int KEYCODE_KANA = 218; /** Key code constant: Assist key. * Launches the global assist activity. Not delivered to applications. */ public static final int KEYCODE_ASSIST = 219; /** Key code constant: Brightness Down key. * Adjusts the screen brightness down. */ public static final int KEYCODE_BRIGHTNESS_DOWN = 220; /** Key code constant: Brightness Up key. * Adjusts the screen brightness up. */ public static final int KEYCODE_BRIGHTNESS_UP = 221; /** Key code constant: Audio Track key. * Switches the audio tracks. */ public static final int KEYCODE_MEDIA_AUDIO_TRACK = 222; /** Key code constant: Sleep key. * Puts the device to sleep. Behaves somewhat like {@link #KEYCODE_POWER} but it * has no effect if the device is already asleep. */ public static final int KEYCODE_SLEEP = 223; /** Key code constant: Wakeup key. * Wakes up the device. Behaves somewhat like {@link #KEYCODE_POWER} but it * has no effect if the device is already awake. */ public static final int KEYCODE_WAKEUP = 224; /** Key code constant: Pairing key. * Initiates peripheral pairing mode. Useful for pairing remote control * devices or game controllers, especially if no other input mode is * available. */ public static final int KEYCODE_PAIRING = 225; /** Key code constant: Media Top Menu key. * Goes to the top of media menu. */ public static final int KEYCODE_MEDIA_TOP_MENU = 226; /** Key code constant: '11' key. */ public static final int KEYCODE_11 = 227; /** Key code constant: '12' key. */ public static final int KEYCODE_12 = 228; /** Key code constant: Last Channel key. * Goes to the last viewed channel. */ public static final int KEYCODE_LAST_CHANNEL = 229; /** Key code constant: TV data service key. * Displays data services like weather, sports. */ public static final int KEYCODE_TV_DATA_SERVICE = 230; /** Key code constant: Voice Assist key. * Launches the global voice assist activity. Not delivered to applications. */ public static final int KEYCODE_VOICE_ASSIST = 231; /** Key code constant: Radio key. * Toggles TV service / Radio service. */ public static final int KEYCODE_TV_RADIO_SERVICE = 232; /** Key code constant: Teletext key. * Displays Teletext service. */ public static final int KEYCODE_TV_TELETEXT = 233; /** Key code constant: Number entry key. * Initiates to enter multi-digit channel nubmber when each digit key is assigned * for selecting separate channel. Corresponds to Number Entry Mode (0x1D) of CEC * User Control Code. */ public static final int KEYCODE_TV_NUMBER_ENTRY = 234; /** Key code constant: Analog Terrestrial key. * Switches to analog terrestrial broadcast service. */ public static final int KEYCODE_TV_TERRESTRIAL_ANALOG = 235; /** Key code constant: Digital Terrestrial key. * Switches to digital terrestrial broadcast service. */ public static final int KEYCODE_TV_TERRESTRIAL_DIGITAL = 236; /** Key code constant: Satellite key. * Switches to digital satellite broadcast service. */ public static final int KEYCODE_TV_SATELLITE = 237; /** Key code constant: BS key. * Switches to BS digital satellite broadcasting service available in Japan. */ public static final int KEYCODE_TV_SATELLITE_BS = 238; /** Key code constant: CS key. * Switches to CS digital satellite broadcasting service available in Japan. */ public static final int KEYCODE_TV_SATELLITE_CS = 239; /** Key code constant: BS/CS key. * Toggles between BS and CS digital satellite services. */ public static final int KEYCODE_TV_SATELLITE_SERVICE = 240; /** Key code constant: Toggle Network key. * Toggles selecting broacast services. */ public static final int KEYCODE_TV_NETWORK = 241; /** Key code constant: Antenna/Cable key. * Toggles broadcast input source between antenna and cable. */ public static final int KEYCODE_TV_ANTENNA_CABLE = 242; /** Key code constant: HDMI #1 key. * Switches to HDMI input #1. */ public static final int KEYCODE_TV_INPUT_HDMI_1 = 243; /** Key code constant: HDMI #2 key. * Switches to HDMI input #2. */ public static final int KEYCODE_TV_INPUT_HDMI_2 = 244; /** Key code constant: HDMI #3 key. * Switches to HDMI input #3. */ public static final int KEYCODE_TV_INPUT_HDMI_3 = 245; /** Key code constant: HDMI #4 key. * Switches to HDMI input #4. */ public static final int KEYCODE_TV_INPUT_HDMI_4 = 246; /** Key code constant: Composite #1 key. * Switches to composite video input #1. */ public static final int KEYCODE_TV_INPUT_COMPOSITE_1 = 247; /** Key code constant: Composite #2 key. * Switches to composite video input #2. */ public static final int KEYCODE_TV_INPUT_COMPOSITE_2 = 248; /** Key code constant: Component #1 key. * Switches to component video input #1. */ public static final int KEYCODE_TV_INPUT_COMPONENT_1 = 249; /** Key code constant: Component #2 key. * Switches to component video input #2. */ public static final int KEYCODE_TV_INPUT_COMPONENT_2 = 250; /** Key code constant: VGA #1 key. * Switches to VGA (analog RGB) input #1. */ public static final int KEYCODE_TV_INPUT_VGA_1 = 251; /** Key code constant: Audio description key. * Toggles audio description off / on. */ public static final int KEYCODE_TV_AUDIO_DESCRIPTION = 252; /** Key code constant: Audio description mixing volume up key. * Louden audio description volume as compared with normal audio volume. */ public static final int KEYCODE_TV_AUDIO_DESCRIPTION_MIX_UP = 253; /** Key code constant: Audio description mixing volume down key. * Lessen audio description volume as compared with normal audio volume. */ public static final int KEYCODE_TV_AUDIO_DESCRIPTION_MIX_DOWN = 254; /** Key code constant: Zoom mode key. * Changes Zoom mode (Normal, Full, Zoom, Wide-zoom, etc.) */ public static final int KEYCODE_TV_ZOOM_MODE = 255; /** Key code constant: Contents menu key. * Goes to the title list. Corresponds to Contents Menu (0x0B) of CEC User Control * Code */ public static final int KEYCODE_TV_CONTENTS_MENU = 256; /** Key code constant: Media context menu key. * Goes to the context menu of media contents. Corresponds to Media Context-sensitive * Menu (0x11) of CEC User Control Code. */ public static final int KEYCODE_TV_MEDIA_CONTEXT_MENU = 257; /** Key code constant: Timer programming key. * Goes to the timer recording menu. Corresponds to Timer Programming (0x54) of * CEC User Control Code. */ public static final int KEYCODE_TV_TIMER_PROGRAMMING = 258; /** Key code constant: Help key. */ public static final int KEYCODE_HELP = 259; private static final int LAST_KEYCODE = KEYCODE_HELP;我们研究 的这两个: /** Key code constant: Back key. */ public static final int KEYCODE_BACK = 4; /** Key code constant: Call key. */ public static final int KEYCODE_CALL = 5;前面界面代码里头,其实是一个View,然后有一个自定义属性,就是keyCode。所以,我们应该看一下com.android.systemui.statusbar.policy.KeyButtonView这个类的代码:我们可以看到,通过自定义属性拿到keyCode,也就是这里的mCode。接着呢?当然是处理触摸事件啦:sendEvent的方法是怎么样子的呢? public void sendEvent(int action, int flags) { sendEvent(action, flags, SystemClock.uptimeMillis()); } void sendEvent(int action, int flags, long when) { final int repeatCount = (flags & KeyEvent.FLAG_LONG_PRESS) != 0 ? 1 : 0; final KeyEvent ev = new KeyEvent(mDownTime, when, action, mCode, repeatCount, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, flags | KeyEvent.FLAG_FROM_SYSTEM | KeyEvent.FLAG_VIRTUAL_HARD_KEY, InputDevice.SOURCE_KEYBOARD); InputManager.getInstance().injectInputEvent(ev, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC); }好啦,就这么把一个keyCode发出去了,不同的是keyCode,所以返回键和Home键是一个意思的。
  • 1