1.更改设置中的平板加密为不加密的:
修改\device\intel\cherrytrail\cht_cr_rvp\fstab文件中的forceencrypt 修改为 encryptable
2.去除桌面底部的关机和重启功能(去除桌面底部按钮):
方法1:
修改\frameworks\base\packages\SystemUI\res\layout\navigation_bar.xml文件:将显示关机和重启的代码gone掉(此方法无效)
方法2:
frameworks\base\packages\SystemUI\src\com\android\systemui\statusbar\phone\PhoneStatusBar.java文件中的1189,1192行加入以下两句:
mNavigationBarView.getShutdownButton().setVisibility(View.INVISIBLE);
mNavigationBarView.getRebootButton().setVisibility(View.INVISIBLE);
3.修改系统的默认桌面壁纸:
直接替换frameworks/base/core/res/res/drawable-nodpi/目录下的default_wallpaper.jpg文件即可。还有drawable-sw600dp-nodpi和drawable-sw720dp-nodpi里的也需要修改
4.修改默认的鼠标光标:
Frameworks/base/core/res/res/ 下找到pointer_arrow.png替换
5.修改系统浏览器默认主页:
打开packages\apps\Browser下的values里的String.xml,将里面的homepage_base字符串换成想要的网址
6.删除系统自带app:
找到相关的配置文件,比如:device\intel\cherrytrail\cht_cr_rvp下的device.mk.将其中指向要删除的app语句注释掉:
若是无法找到的那就直接删除软件包吧0.0。
7.默认更改为中国标准时区
方法1:(此方法无效)
在源码目录 build/target/board/generic,修改文件 system.prop,在文件最后添加(7.8.9行):
ro.product.locale.language=zh
ro.product.locale.region=CN
persist.sys.defaulttimezone=Asia/Shanghai
方法2:
用其他方法无效的原因是因为在build\tools\buildinfo.sh文件中如果定义了时区和语言,改别的地方都不会有效果。所以要修改此文件。
(1)注释掉文件中如下内容:
if [ -n "$PRODUCT_DEFAULT_LANGUAGE" ] ; then
echo "ro.product.locale.language=$PRODUCT_DEFAULT_LANGUAGE"
fi
if [ -n "$PRODUCT_DEFAULT_REGION" ] ; then
echo "ro.product.locale.region=$PRODUCT_DEFAULT_REGION"
Fi
(2)在文件的末尾加入以下语句:
echo "persist.sys.language=zh"
echo "persist.sys.country=CN"
echo "persist.sys.localevar="
echo "persist.sys.timezone=Asia/Shanghai"
echo "ro.product.locale.language=zh"
echo "ro.product.locale.region=CN"
注意:如果编译时报ro.product.locale.language cannot exceed 31 bytes..错误,需要修改build\tools\post_process_props.py文件中的内容,如下:
PROP_NAME_MAX = 31
修改为:PROP_NAME_MAX = 32
8.时间格式选择为24小时制
修改文件\frameworks\base\packages\SettingsProvider\res\values\defaults.xml
增加代码
24
24表示 24 小时制,也可以改为 12 ( 12 小时制)
修改文件
\frameworks\base\packages\SettingsProvider\src\com\android\providers\s
ettings\DatabaseHelper.java
找到函数loadSystemSettings () ,在函数中增加以下语句:
loadStringSetting(stmt,Settings.System.TIME_12_24, R.string.time_12_24);
9.关于编译时出现 java:1: error: illegal character.....
开始以为是编码没有选对,调整了并询问原开发人员确认是UTF-8没有问题。上网翻阅资料后才发现,是由于Windows系统开发的编码为UTF-8(BOM)导致,BOM是Byte-Order Mark的意思。一种为了让编辑器自动识别编码。在文件前3个字节加上了EE,BB,BF,但标准的UTF-8(Linux不支持BOM)编码并不会这样做。
所以在Linux下编译Java,问题就这样产生了。
我解决此问题的方法是用notepad++设置“转换为UTF-8无BOM编码格式”
10.更改Android 未知来源的默认设置
Android系统的“设置” ->“应用程序”->“未知来源”默认是关闭的,当你想让它默认为打开的时候,可以这样做:
在Android系统的源码里面做如下修改:
路径:Frameworks/base/packages/SettingsProvider/res/values/defaults.xml
修改前:false
修改后:true
11.关于源码中自带输入法的设置问题
(1)虚拟键盘 - >文本校正:禁用建议联系人姓名,禁用下一个单词建议。
修改文件:
packages\inputmethods\LatinIME\java\res\xml\prefs_screen_correction.xml如下图(11.1):
(2)虚拟键盘:首选项:禁用自动大小写,禁用双倍空间周围,禁用按键上的声音
修改文件:
packages\inputmethods\LatinIME\java\res\xml\pprefs_screen_preferences.xml如下图(11.2):
12.开机使屏幕自动旋转两次(先旋转一次然后回到原来屏幕方向)解决方法
在launcher中加一个广播接受者接收开机的广播然后跳转到一个activity进行屏幕旋转操作,核心代码:
//OnBootReceiver.java
package com.android.launcher2;
import android.content.BroadcastReceiver;
import android.provider.Settings;
import android.content.Intent;
import android.content.Context;
public class OnBootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
Intent it = new Intent(context,AutoRotationActivity.class);
it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
it.putExtra("isAutoRotation",true);
context.startActivity(it);
}
}
}
//AutoRotationActivity.java
package com.android.launcher2;
import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.provider.Settings;
import com.android.launcher.R;
public class AutoRotationActivity extends Activity {
public boolean isAutoRotation = false;
public String ROTATION_PORTRAIT = "portrait";
public String ROTATION_LANDSCAPE = "landscape";
public String ROTATION_NONE = "none";
@Override
protected void onCreate(Bundle savedInstanceState) {
uper.onCreate(savedInstanceState);
setContentView(R.layout.avtivity_auto_rotation);
Intent it=getIntent();
isAutoRotation = it.getBooleanExtra("isAutoRotation",false);
if(isAutoRotation){
Settings.System.putString(getContentResolver(),Settings.System.DISPLAY_ROTATION_ON_MAIN,ROTATION_LANDSCAPE);
try{
Thread.sleep(1000);
}catch(InterruptedException e){
e.printStackTrace();
}
Settings.System.putString(getContentResolver(),Settings.System.DISPLAY_ROTATION_ON_MAIN,ROTATION_PORTRAIT);
AutoRotationActivity.this.finish();
}
}
}
//AndroidManifest.xml
13.使adb拥有root 权限
(1)修改
build/core/main.mk
ifneq (,$(user_variant))
# Target is secure in user builds.
ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=1
将ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=1改成
ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=0即可。
(2)在Android JB版本(4.1)以后,google从编译上直接去除了adbd的user版本root权限, 为此您要修改system/core/adb/android.mk中的编译选项
ALLOW_ADBD_ROOT,如果没有打开这个选项,那么adb.c中将不会根据ro.secure去选择root还是shell权限,直接返回shell权限。因此您必须需要
Android.mk中的第126行:
ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT))) ===>
ifneq (,$(filter userdebug user eng,$(TARGET_BUILD_VARIANT)))
**(3)在android L (5.0)以后, google默认开启SELinux enforce mode,需要在user build上将su label默认build进SEPolicy.放开SELinux的限.更新alps/external/sepolicy/Android.mk 116行, 将su label默认编译进入sepolicy.
sepolicy_policy.conf := $(intermediates)/policy.conf
$(sepolicy_policy.conf): PRIVATE_MLS_SENS := $(MLS_SENS)
$(sepolicy_policy.conf): PRIVATE_MLS_CATS := $(MLS_CATS)
$(sepolicy_policy.conf) : $(call build_policy, $(sepolicy_build_files))
@mkdir -p $(dir $@)
$(hide) m4 -D mls_num_sens=$(PRIVATE_MLS_SENS) -D mls_num_cats=$(PRIVATE_MLS_CATS) \
-D target_build_variant=$(TARGET_BUILD_VARIANT) \
D force_permissive_to_unconfined=$(FORCE_PERMISSIVE_TO_UNCONFINED) \
-s $^ > $@
$(hide) sed '/dontaudit/d' $@ > [email protected]
将-D target_build_variant=$(TARGET_BUILD_VARIANT)改成-D target_build_variant=eng
13.预装apk
(1)在packages/app中创建文件夹 文件夹名与apk的名字最好一致
(2)将apk复制到创建的文件夹下并新建一个android.mk文件
(3)编写android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Module name should match apk name to be installed
LOCAL_MODULE := vnc
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_CERTIFICATE := PRESIGNED
include $(BUILD_PREBUILT)
(4)这个是apk中不包含so包的,如果包含so包需加以下内容:(@lib表示是在该apk中的lib)
LOCAL_PREBUILT_JNI_LIBS := \
@lib/xxxxxx.so\
@lib/xxxxxxxxxxxxxx.so \
@lib/xxxxxxxxxx.so
如果包含不同系统架构的so包需要进行以下的分类:
ifeq ($(TARGET_ARCH),x86)
LOCAL_PREBUILT_JNI_LIBS := \
@lib/x86/xxxxxx.so \
@lib/x86/xxxxxxxxxxxxxx.so \
@lib/x86/xxxxxxxxxx.so
endif
ifeq ($(TARGET_ARCH),arm)
LOCAL_PREBUILT_JNI_LIBS := \
@lib/armeabi-v7a/xxxxxx.so \
@lib/armeabi-v7a/xxxxxxxxxxxxxx.so \
@lib/armeabi-v7a/lxxxxxxxxxx.so
endif
ifeq ($(TARGET_ARCH),mips)
LOCAL_PREBUILT_JNI_LIBS := \
@lib/mips/xxxxx.so\
@lib/mips/xxxxxxxxxxxxxx.so
endif
......
14.去除底部菜单栏和禁止下拉菜单下拉
(1去除底部栏修改frameworks\base\packages\SystemUI\src\com\android
\systemui\statusbar\phone\PhoneStatusBar.java:
在start方法中注释掉 addNavigationBar();即可
(2禁止下拉菜单下拉修改frameworks\base\packages\SystemUI\src\com\android
systemui\statusbar\phone\PhoneStatusBarView.java:
@Override
public PanelView selectPanelForTouch(MotionEvent touch) {
// No double swiping. If either panel is open, nothing else can be pulled down.
// modify by cheng 20170713
// return mNotificationPanel.getExpandedHeight() > 0
// ? null
// : mNotificationPanel;
return null;
}
直接return null;
15.以太网设置静态ip概率性失败
修改文件frameworks\opt\net\ethernet\java\com\android\server\ethernet
EthernetNetworkFactory.java:
(1)加入 private Handler mHandler;
(2)在mContext = context;下面加mHandler = target;
(3)在if (!setStaticIpAddress(config.getStaticIpConfiguration())) {下加入以下代码:
if((mContext != null) && (mHandler != null)) {
Log.d(TAG, "Setting static ip failed now restart");
stop();
start(mContext,mHandler);
即如果没有设置成功就stop然后再重新start.
16.将底部导航栏可动态隐藏
1.长按隐藏底部导航栏
虚拟按键有3个,考虑到返回键一般有一定的作用,于是修改主页键(虚拟圆形按键)的长点击事件,使其在长点击后可以隐藏导航栏。
frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.Java
private void prepareNavigationBarView() {
mNavigationBarView.reorient(); mNavigationBarView.getRecentsButton().setOnClickListener(mRecentsClickListener);
mNavigationBarView.getRecentsButton().setOnTouchListener(mRecentsPreloadOnTouchListener);
mNavigationBarView.getRecentsButton().setLongClickable(true);
mNavigationBarView.getRecentsButton().setOnLongClickListener(mLongPressBackRecentsListener);
mNavigationBarView.getBackButton().setLongClickable(true);
mNavigationBarView.getBackButton().setOnLongClickListener(mLongPressBackRecentsListener);
mNavigationBarView.getHomeButton().setOnTouchListener(mHomeActionListener);
mNavigationBarView.getHomeButton().setLongClickable(true);
mNavigationBarView.getHomeButton().setOnLongClickListener(mLongHomeListener);
}
View.OnLongClickListener mLongHomeListener = new View.OnLongClickListener(){
@Override
public boolean onLongClick(View v) {
removeNavigationBar();
return true;
}
};
private void removeNavigationBar() {
if (DEBUG) Log.d(TAG, "removeNavigationBar: about to remove " + mNavigationBarView);
if (mNavigationBarView == null) return;
mWindowManager.removeView(mNavigationBarView);
mNavigationBarView = null;
}
此时进行长点击任务键将隐藏导航栏。
2.接下来便是显示NavigationBar,这个修改相对复杂一点。因为此时NavigationBar处于不可见状态,我们无法通过增加按钮的方式让其显示,但是我们知道,状态栏下拉通过手势向下滑动即可。因此很容易便想到通过手势从屏幕底部向上滑动来显示NavigationBar。我的想法是在policy模块中增加一个接口,通过frameworks/base/services/core/Java/com/android/server/statusbar/StatusBarManagerService.java服务传递到状态栏中,从而触发显示NavigationBar事件。
也许大家会有疑问,为什么是在policy模块修改?其实我这只是一种解决方案,因为我知道
frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java 有现成的手势滑动接口。其实你也可以SystemUI中增加一个这样的事件,我们需要的就是这么一个触发事件。
PhoneWindowManager.java的修改主要是实现onSwipeFromBottom(竖屏时)和onSwipeFromRight(横屏时)两个接口,然后调用showNavigationBar,在showNavigationBar函数中,我们调用StatusBarManagerService服务中的showNavigationBar函数,具体如下:
frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
@@ -1241,13 +1241,27 @@ public class PhoneWindowManager implements WindowManagerPolicy {
public void onSwipeFromBottom() {
if (mNavigationBar != null && mNavigationBarOnBottom) {
requestTransientBars(mNavigationBar);
}
+ else{
+ Log.i("way", "onSwipeFromBottom...");
+ showNavigationBar();
+ }
}
@Override
public void onSwipeFromRight() {
if (mNavigationBar != null && !mNavigationBarOnBottom) {
requestTransientBars(mNavigationBar);
+ }
+ else{
+ Log.i("way", "onSwipeFromRight...");
+ showNavigationBar();
}
}
@Override
public void onDebug() {
@@ -1293,7 +1307,24 @@ public class PhoneWindowManager implements WindowManagerPolicy {
goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
}
}
+
+ private void showNavigationBar(){
+ mHandler.post(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ IStatusBarService statusbar = getStatusBarService();
+ if (statusbar != null) {
+ statusbar.showNavigationBar();
+ }
+ } catch (RemoteException e) {
+ // re-acquire status bar service next time it is needed.
+ mStatusBarService = null;
+ }
+ }
+ });
+ }
+
private void updateKeyAssignments() {
final boolean hasMenu = (mDeviceHardwareKeys & KEY_MASK_MENU) != 0;
final boolean hasHome = (mDeviceHardwareKeys & KEY_MASK_HOME) != 0;
这时事件传递到了StatusBarManagerService中,我们来看看StatusBarManagerService.java如何实现showNavigationBar:
+++ frameworks/base/services/core/java/com/android/server/statusbar/StatusBarManagerService.java
@@ -366,6 +366,27 @@ public class StatusBarManagerService extends IStatusBarService.Stub {
"WindowManager.LayoutParams");
}
}
+
+ @Override
+ public void showNavigationBar() {
+ enforceStatusBar();
+
+ android.util.Log.d("way", TAG + " showNavigationBar...");
+
+ synchronized(mLock) {
+ mHandler.post(new Runnable() {
+ public void run() {
+ if (mBar != null) {
+ try {
+ mBar.showNavigationBar();
+ } catch (RemoteException ex) {
+ }
+ }
+ }
+ });
+ }
+ }
+
+
private void updateUiVisibilityLocked(final int vis, final int mask) {
if (mSystemUiVisibility != vis) {
从上述代码可以看出,StatusBarManagerService只是起到一个传递作用,将消息传递到StatusBar中,最终的实现是在SystemUI模块的frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java,如下所示:
+++ b/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java
@@ -56,6 +56,7 @@ public class CommandQueue extends IStatusBar.Stub {
private static final int MSG_BUZZ_BEEP_BLINKED = 15 << MSG_SHIFT;
private static final int MSG_NOTIFICATION_LIGHT_OFF = 16 << MSG_SHIFT;
private static final int MSG_NOTIFICATION_LIGHT_PULSE = 17 << MSG_SHIFT;
+ private static final int MSG_SHOW_NAVIGATIONBAR = 19<< MSG_SHIFT;//ADD cheng
public static final int FLAG_EXCLUDE_NONE = 0;
public static final int FLAG_EXCLUDE_SEARCH_PANEL = 1 << 0;
public class CommandQueue extends IStatusBar.Stub {
public void animateCollapsePanels(int flags);
public void animateExpandSettingsPanel();
public void setSystemUiVisibility(int vis, int mask);
+ public void showNavigationBar();//ADD cheng
public void topAppWindowChanged(boolean visible);
public void setImeWindowStatus(IBinder token, int vis, int backDisposition,
boolean showImeSwitcher);
public class CommandQueue extends IStatusBar.Stub {
mHandler.obtainMessage(MSG_SET_SYSTEMUI_VISIBILITY, vis, mask, null).sendToTarget();
}
}
+
+ public void showNavigationBar() {
+ synchronized (mList) {
+ mHandler.removeMessages(MSG_SHOW_NAVIGATIONBAR);
+ mHandler.sendEmptyMessage(MSG_SHOW_NAVIGATIONBAR);
+ }
+ }
+
public void topAppWindowChanged(boolean menuVisible) {
synchronized (mList) {
public class CommandQueue extends IStatusBar.Stub {
case MSG_SET_SYSTEMUI_VISIBILITY:
mCallbacks.setSystemUiVisibility(msg.arg1, msg.arg2);
break;
+
+ case MSG_SHOW_NAVIGATIONBAR:
+ mCallbacks.showNavigationBar();
+ break;
+
case MSG_TOP_APP_WINDOW_CHANGED:
mCallbacks.topAppWindowChanged(msg.arg1 != 0);
break;
CommandQueue.java收到了这个消息之后,又回调给了base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java,绕了大半天,消息终于回来了,我们就是需要在PhoneStatusBar.java实现显示NavigationBar的函数了:
+ @Override // CommandQueue
+ public void showNavigationBar() {
+ Log.i("way", TAG + " showNavigationBar...");
+ forceAddNavigationBar();
+ }
+
+ private void forceAddNavigationBar() {
+ // If we have no Navbar view and we should have one, create it
+ if (mNavigationBarView != null) {
+ return;
+ }
+
+ mNavigationBarView =
+ (NavigationBarView) View.inflate(mContext, R.layout.navigation_bar, null);
+
+ mNavigationBarView.setDisabledFlags(mDisabled);
+ mNavigationBarView.setBar(this);
+ addNavigationBar(true); // dynamically adding nav bar, reset System UI visibility!
+ }
+
+ private void prepareNavigationBarView(boolean forceReset) {
+ mNavigationBarView.reorient();
+ mNavigationBarView.getRecentsButton().setOnClickListener(mRecentsClickListener);
+ mNavigationBarView.getRecentsButton().setOnTouchListener(mRecentsPreloadOnTouchListener);
+ mNavigationBarView.getRecentsButton().setLongClickable(true);
+ mNavigationBarView.getRecentsButton().setOnLongClickListener(mLongPressBackRecentsListener);
+ mNavigationBarView.getBackButton().setLongClickable(true);
+ mNavigationBarView.getBackButton().setOnLongClickListener(mLongPressBackRecentsListener);
+ mNavigationBarView.getHomeButton().setOnTouchListener(mHomeActionListener);
+ mNavigationBarView.getHideBarButton().setOnClickListener(mHideBarClickListener);//ADD liweiping
+
+ if (forceReset) {
+ // Nav Bar was added dynamically - we need to reset the mSystemUiVisibility and call
+ // setSystemUiVisibility so that mNavigationBarMode is set to the correct value
+ Log.i("way", "prepareNavigationBarView mNavigationBarMode = "+ mNavigationBarMode + " mSystemUiVisibility = " + mSystemUiVisibility + " mNavigationIconHints = " + mNavigationIconHints);
+ mNavigationBarMode = 0;
+
+ int newVal = mSystemUiVisibility;
+ mSystemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE;
+ setSystemUiVisibility(newVal, /*SYSTEM_UI_VISIBILITY_MASK*/0xffffffff);
+ int hints = mNavigationIconHints;
+ mNavigationIconHints = 0;
+ setNavigationIconHints(hints);
+ topAppWindowChanged(mShowMenu);
+ }
+
+ updateSearchPanel();
+ }
+
+ // For small-screen devices (read: phones) that lack hardware navigation buttons
+ private void addNavigationBar(boolean forceReset) {
+ if (DEBUG) Log.v(TAG, "addNavigationBar: about to add " + mNavigationBarView);
+ if (mNavigationBarView == null) return;
+
+ prepareNavigationBarView(forceReset);
+
+ mWindowManager.addView(mNavigationBarView, getNavigationBarLayoutParams());
+ }
还需要在frameworks\base\core\java\com\android\internal\statusbar\IStatusBarService.aidl
中加入:
//add by cheng
void showNavigationBar();
frameworks\base\core\java\com\android\internal\statusbar\IStatusBar.aidl中加入:
//add by cheng
void showNavigationBar();
17.解决绕过android下apk使用usb设备权限查询相应问题,自动获取usb权限
查看到这个对话框在UsbPermissionActivity.java中(\frameworks\base
\packages\SystemUI\src\com\android\systemui\usb\UsbPermissionActivity.java)
// add modify by CC 20170922 ----start ----->解决绕过android下apk使用usb设备权限查询相应问题,自动获取usb权限
// setupAlert();
mPermissionGranted = true;
finish();
// add modify by CC 20170922 ----end
其中setupAlert()是弹出对话框的方法;这里函数finish();很重要,如果不加上的话会出现一个空白的框