Chinaunix首页 | 论坛 | 博客
  • 博客访问: 9140475
  • 博文数量: 1725
  • 博客积分: 12961
  • 博客等级: 上将
  • 技术积分: 19840
  • 用 户 组: 普通用户
  • 注册时间: 2009-01-09 11:25
个人简介

偷得浮生半桶水(半日闲), 好记性不如抄下来(烂笔头). 信息爆炸的时代, 学习是一项持续的工作.

文章分类

全部博文(1725)

文章存档

2024年(1)

2023年(26)

2022年(112)

2021年(217)

2020年(157)

2019年(192)

2018年(81)

2017年(78)

2016年(70)

2015年(52)

2014年(40)

2013年(51)

2012年(85)

2011年(45)

2010年(231)

2009年(287)

分类: Android平台

2014-05-09 09:45:07

1. 自动中文 (http://blog.csdn.net/ydt_lwj/article/details/7767207)
在解决这个问题时确定了应该要去修改Makefile的相应的文件里的PRODUCT_LOCALES变量,只是没有修改正确,android里 对这个变量的赋值,是根据你在make时所编译的项目对相应的.mk文件中PRODUCT_LOCALES进行赋值,如果你没有在相应的项目里的有关的mk文件里对这个变量复制,那么编译时这个变量的值就会是默认为android自己对这个变更的复制。

有两种方法可以实现在编译完后的语言默认没中文:

方法1:在相应的项目的.mk文件中添加如下内容:

  1. #Overrdies   
  2.  PRODUCT_LOCALES := \   
  3.               zh_CN \   
  4.               en_US   

注意:在对PRODUCT_LOCALES这个变量的赋值谁在最前面就默认为是谁。

方法2:在core.mk文件中的PRODUCT_PROPERTY_OVERRIDES变量后加上设置语言属性的两个变量:

  1. PRODUCT_PROPERTY_OVERRIDES := \   
  2.     ro.config.notification_sound=OnTheHunt.ogg \   
  3.     ro.config.alarm_alert=Alarm_Classic.ogga  
在这句的后面加上如下代码:

  1. persist.sys.language=zh  
  2. persist.sys.country=CN   

添加完如下所示:

  1. PRODUCT_PROPERTY_OVERRIDES := \   
  2.     ro.config.notification_sound=OnTheHunt.ogg \   
  3.     ro.config.alarm_alert=Alarm_Classic.ogga \   
  4.     persist.sys.language=zh \   
  5.     persist.sys.country=CN   

第一种方法在设置里的语言和键盘设置的语言设置里会只有你添加的语言。而方法二语言设置里有android里添加的所有的语言,

方法一中要根据不同的项目去修改相应的mk文件,方法二只需修改一个core.mk文件就可以,项目再多只修改这个文件就可以做到默认语言是中文的了。

==============================================================================

默认开启adb。

今天需要编译一个android4.2.2 的user版本来测试;

android编译相关的东西在源码的build目录下,全编前需要执行

. build/envsetup.sh

执行上面的shell脚本会include一些其他目录下的shell脚本,以及声明一些命令函数,比如说接下来执行的choosecombo命令;

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
function choosecombo() { choosetype $1 echo echo chooseproduct $2 echo echo choosevariant $3 echo set_stuff_for_environment printconfig } 

choosecombo release msm8960 eng;

release表示的是Build type;(choose type) type有release和debug两个选项

msm8960表示的是product;(choose product) product有genric和msm8960,当然product根据项目不同是有不同选项的;

eng表示的是版本类型;(choose variant) variant有user,userdebug,eng三个选项

通过adb shell中执行getprop persist.sys.usb.config,可以看到系统usb的相关选项,persist.sys.usb.config显示的就是当前系统关于usb选项的系统配置;

diag,serial_smd,serial_tty,rmnet_bam,mass_storage,adb

全编脚本中make命令会调用build/core/**main.mk**,在里面可以看到一段关于debuggable的编译选项,赋值ADDITIONAL_DEFAULT_PROPERTIES;

1
2
3
4
5
6
7
8
9
ifeq (true,$(strip $(enable_target_debugging))) # Target is more debuggable and adbd is on by default ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=1 # Include the debugging/testing OTA keys in this build. INCLUDE_TEST_OTA_KEYS := true else # !enable_target_debugging # Target is less debuggable and adbd is off by default ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=0 endif # !enable_target_debugging 

并且

1
include $(BUILD_SYSTEM)/Makefile 

在build/core/Makefile中的

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# default.prop INSTALLED_DEFAULT_PROP_TARGET := $(TARGET_ROOT_OUT)/default.prop ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_DEFAULT_PROP_TARGET) ADDITIONAL_DEFAULT_PROPERTIES := $(call collapse-pairs, $(ADDITIONAL_DEFAULT_PROPERTIES)) ADDITIONAL_DEFAULT_PROPERTIES += $(call collapse-pairs, $(PRODUCT_DEFAULT_PROPERTY_OVERRIDES)) ADDITIONAL_DEFAULT_PROPERTIES := $(call uniq-pairs-by-first-component, $(ADDITIONAL_DEFAULT_PROPERTIES),=) $(INSTALLED_DEFAULT_PROP_TARGET): @echo Target buildinfo: $@ @mkdir -p $(dir $@) $(hide) echo "#" > $@; echo "# ADDITIONAL_DEFAULT_PROPERTIES" >> $@; echo "#" >> $@; $(hide) $(foreach line,$(ADDITIONAL_DEFAULT_PROPERTIES), echo "$(line)" >> $@;) build/tools/post_process_props.py $@ 

执行**post_process_props.py**脚本文件,**post_process_props.py会根据main.mk中的ro.debuggable指定的值来生成default.prop的persist.sys.usb.config;**
**

**


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# If ro.debuggable is 1, then enable adb on USB by default # (this is for userdebug builds) if prop.get("ro.debuggable") == "1": val = prop.get("persist.sys.usb.config") if val == "": val = "adb" else: val = val + ",adb" prop.put("persist.sys.usb.config", val) # UsbDeviceManager expects a value here. If it doesn't get it, it will # default to "adb". That might not the right policy there, but it's better # to be explicit. if not prop.get("persist.sys.usb.config"): prop.put("persist.sys.usb.config", "none"); 

如果想要编译user版本的时候打开adb,修改

1
prop.put("persist.sys.usb.config", "none"); 

1
prop.put("persist.sys.usb.config", "adb"); 

即可;

eng版本的default.prop

1
2
3
4
5
6
7
# # ADDITIONAL_DEFAULT_PROPERTIES # ro.secure=0 ro.allow.mock.location=1 ro.debuggable=1 persist.sys.usb.config=adb 

默认user版本default.prop

**

**

1
2
3
4
5
6
7
# # ADDITIONAL_DEFAULT_PROPERTIES # ro.secure=1 ro.allow.mock.location=1 ro.debuggable=0 persist.sys.usb.config=none 

以上结论经过自己验证可行,如有错误之处,希望能够指出;

另外,针对user版本上无法进行usb debug,可以在settings-About phone-Build number上点击N次,然后就会提示“No need,you are already a developer”,这时,settings中

就会出现Develper options选项,进去就可以打开usb debug了;

==============================================================================

android命令行播放mp3

http://blog.csdn.net/armeasy/article/details/6676608

在android的在命令行下,可以使用强大的am指令做很多事情。


在android终端输入am,正常情况下会有如下提示信息:
# am
usage: am [subcommand] [options]
    start an Activity: am start [-D] [-W]
        -D: enable debugging
        -W: wait for launch to complete

    start a Service: am startservice

    send a broadcast Intent: am broadcast

    start an Instrumentation: am instrument [flags]
        -r: print raw results (otherwise decode REPORT_KEY_STREAMRESULT)
        -e : set argument to
        -p : write profiling data to
        -w: wait for instrumentation to finish before returning

    start profiling: am profile start
    stop profiling: am profile stop

    specifications include these flags:
        [-a ] [-d ] [-t ]
        [-c [-c ] ...]
        [-e|--es ...]
        [--esn ...]
        [--ez ...]
        [-e|--ei ...]
        [-n ] [-f ]
        [--grant-read-uri-permission] [--grant-write-uri-permission]
        [--debug-log-resolution]
        [--activity-brought-to-front] [--activity-clear-top]
        [--activity-clear-when-task-reset] [--activity-exclude-from-recents]
        [--activity-launched-from-history] [--activity-multiple-task]
        [--activity-no-animation] [--activity-no-history]
        [--activity-no-user-action] [--activity-previous-is-top]
        [--activity-reorder-to-front] [--activity-reset-task-if-needed]
        [--activity-single-top]
        [--receiver-registered-only] [--receiver-replace-pending]
        []

#启动的方法为:
# am start -n 包(package)名/包名.活动(activity)名称
启动的方法可以从每个应用的AndroidManifest.xml的文件中得到,以计算器(calculator)为例,


    
        
            
                
                
            

        

    

由此计算器(calculator)的启动方法为:
# am start -W -n com.android.calculator2/com.android.calculator2.Calculator

Music的启动方法为:
# am start -W -n com.android.music/com.android.music.MusicBrowserActivity

这时,屏幕上会有music的播放列表,但是并没有播放。如果需要播放,得执行下面的指令:
am start -n com.android.music/com.android.music.MediaPlaybackActivity -d /sdcard/liangliangxianwang.mp3

#############################################################################
http://blog.csdn.net/linweidong/article/details/6910864

用Android代码实现自动打开USB调试

打开Android手机的USB调试对于使用豌豆夹、调试程序等来说很重要。下面说说如何用代码自动打开USB调试。先分析USB调试的相关源代码。

在 packages/apps/Settings/src/com//settings/DevelopmentSettings.java 找到关于 USB Debug Enable 的代码:

  1. Settings.Secure.putInt(getContentResolver(), Settings.Secure.ADB_ENABLED,  0 );    

此文件中,将根据用户设置将其值保存到 Settings 数据库中。别处将根据其值动态变化做出相应动作

经搜索,在 frameworks/base/services/java/com/android/server/NotificationManagerService.java 中存在利用该值判断是否在状态栏中进行通知。代码如下:


别处将根据其值动态变化做出相应动作如状态栏消息提示。


  1. void  observe() {    
  2.     ContentResolver resolver = mContext.getContentResolver();    
  3.     resolver.registerContentObserver(Settings.Secure.getUriFor(    
  4.             Settings.Secure.ADB_ENABLED), false ,  this );    
  5.     update();    
  6. }    
  7.     
  8. @Override   public   void  onChange( boolean  selfChange) {    
  9.     update();    
  10. }    
  11.     
  12. public   void  update() {    
  13.     ContentResolver resolver = mContext.getContentResolver();    
  14.     mAdbEnabled = Settings.Secure.getInt(resolver,    
  15.                 Settings.Secure.ADB_ENABLED, 0 ) !=  0 ;    
  16.     updateAdbNotification();    
  17. }    

 


通过分析代码,我们可以实现用程序自动打开usb调试了。

  1. boolean enableAdb = (Settings.Secure.getInt(getContentResolver(), Settings.Secure.ADB_ENABLED, 0) > 0);  
  2.     if (!enableAdb) {  
  3.     Settings.Secure.putInt(getContentResolver(), Settings.Secure.ADB_ENABLED, 1);  
  4.     }  


马上进行运行,会出现异常,通过Logcat可以看到没有权限。android.permission.WRITE_SECURE_SETTINGS是不允许普通程序来执行,必须要有系统的签名或放到

/system/app下。

(1)、在AndroidManifest.xml加上两个权限

  1. <uses-permission android:name="android.permission.WRITE_SETTINGS">uses-permission>   
  2. <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />  

 

可以把程序push到/system/app,并对这个apk加上0644的权限,重启手机,可以发现usb调试自动打开了。

############################################################################

Android环境下sqlite3数据库查询的方法


用来修改 usb debug 等设置内容。
进入数据库控制台   sqlite3         /data/data/com.android.providers.settings/databases/settings.db

查看表
.tables
出现 Secure 表。
查看表结构  select * from sqlite_master where type="table";

进行 update
update Secure set value=1 where name = 'touch_exploration_enabled'
usb调试
Settings.Secure.putInt(getContentResolver(), Settings.Secure.ADB_ENABLED, 1);  //ADB_ENABLED = "adb_enabled";
insert into Secure(name, value) values("adb_enabled", 1);


查新看数据是否改变
sqlite> select * from Secure

退出
.quit

当然你也可以操作自己的数据库
create table IF NOT EXISTS my (_id INTEGER not null, name text not null, value INTEGER)
INSERT INTO my values(1,"touch_exploration_enabled",1)
drop table my

注意:

1) 你需要取得Android 系统的  root 权限.


2)  如果你是改 Secure 等这些保存设置的 table, 改完后请重启 Android, 因为 Setting 这些是会做 cache 的

你用Android 提供的接口就不用重启:

Settings.Secure.putInt(this.getContentResolver(), Settings.Secure.TOUCH_EXPLORATION_ENABLED, 1);


但为了编译它,你需要你需要 在 AndroidManifest.xml 声明

android:sharedUserId="android.uid.system

以及


并且把它作为 platform apps, 就是在 Android.mk 中声明

LOCAL_CERTIFICATE := platform

这显然不如直接用 sqlite3 命令简单


3) 另外就是你把 Android 中的 *.db 复制到 unix 中,想让 unix 下面的 sqlite3 打开时不行的, 可能 Android 对 sqlite3的 src 改动

如果把 unix 的 sqlite3 用 adb push /system/xbin/     也是不能用的,  因为 unix 下的 sqlite3 是用 glibc 编译的, 而 Android 是基于bionic.




############################################################################
命令行  
    insmod /system/lib/modules/8192cu.ko
    chmod 0777 /data/system/
    chmod 0777 /data/misc/wifi
    chmod 0777 /data/misc/wifi/wpa_supplicant.conf
    
    wpa_supplicant -B -Dnl80211 -iwlan0 -c/data/misc/wifi/wpa_supplicant.conf    
    dhcpcd wlan0
    
    android dns设置
        setprop net.dns1 8.8.8.8 setprop net.dns2 8.8.4.4
    
    wpa_supplicant.conf    文件内容    
            ctrl_interface=DIR=/data/system/wpa_supplicant GROUP=wifi
            update_config=1                   
            device_name=marsboard
            manufacturer=rockchip
            model_name=mars      
            model_number=mars
                             
            network={
                    ssid="YIMA"
                    psk="linzhibin"
                    key_mgmt=WPA-PSK
            }
        
    # wpa_supplicant.conf 已经预先配置好了
    # /data/misc/wifi 权限有很大问题, 否则wpa_supplicant 根本启动不起来。

############################################################################






















































阅读(9558) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~