• (OK) Android Settings和SettingsProvider源码分析与修改



    http://www.cncoders.net/article/11633/


    2015年04月16日


    习惯了,看源码从AndroidManifest文件看起,先对工程有个大致的认识。

    Settings也是经常需要改动的部分之一,包名:com.android.settings,工程名:Settings,代码量也不小,慢慢啃。


    4.4 SDK的Settings的AndroidManifest文件有2100+行,用ADT格式化后变成2600+行,好吧。

    首先是权限,直接把注释写在里面了:

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /><!--读取外部存储 -->
        <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /><!--写外部存储 -->
        <uses-permission android:name="android.permission.WRITE_SETTINGS" /><!--写设置信息 -->
        <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" /><!-- 写安全级别设置信息-->
        <uses-permission android:name="android.permission.DEVICE_POWER" /><!--电源键 -->
        <uses-permission android:name="android.permission.CHANGE_CONFIGURATION" /><!-- 改变配置-->
        <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" /><!--挂载和卸载文件系统 -->
        <uses-permission android:name="android.permission.VIBRATE" /><!--震动 -->
        <uses-permission android:name="android.permission.BLUETOOTH" /><!--蓝牙基础服务,连接已配对的设备 -->
        <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /><!-- 蓝牙管理,附加蓝牙功能,比如搜索并配对设备-->
        <uses-permission android:name="android.permission.BLUETOOTH_PRIVILEGED" /><!--蓝牙高级 -->
        <uses-permission android:name="android.permission.NFC" /><!--NFC近场通讯 -->
        <uses-permission android:name="android.permission.HARDWARE_TEST" /><!--硬件检测 -->
        <uses-permission android:name="android.permission.CALL_PHONE" /><!--拨打电话 -->
        <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /><!--修改音频设置 -->
        <uses-permission android:name="android.permission.MASTER_CLEAR" /><!--恢复出厂设置 -->
        <uses-permission android:name="android.permission.USE_CREDENTIALS" /><!-- 读取用户授权码-->
        <uses-permission android:name="com.google.android.googleapps.permission.GOOGLE_AUTH" /><!-- 谷歌应用授权-->
        <uses-permission android:name="android.permission.ACCESS_DOWNLOAD_MANAGER" /><!--管理下载管理 -->
        <uses-permission android:name="android.permission.READ_CONTACTS" /><!--读取联系人 -->
        <uses-permission android:name="android.permission.WRITE_CONTACTS" /><!--写入联系人信息 -->
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /><!--访问网络状态 -->
        <uses-permission android:name="android.permission.ACCESS_WIMAX_STATE" /><!--读取wimax无线局域网状态 -->
        <uses-permission android:name="android.permission.CHANGE_WIMAX_STATE" /><!--修改wimax无线局域网状态 -->
        <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /><!--读取wifi状态 -->
        <uses-permission android:name="com.android.certinstaller.INSTALL_AS_USER" /><!--以User状态安装 -->
        <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /><!--修改WiFi状态 -->
        <uses-permission android:name="android.permission.INTERNET" /><!--互联网 -->
        <uses-permission android:name="android.permission.CLEAR_APP_USER_DATA" /><!--清除用户的应用信息 -->
        <uses-permission android:name="android.permission.READ_PHONE_STATE" /><!--获取手机状态 -->
        <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" /><!--修改手机状态 -->
        <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/><!--获取大致位置 -->
        <uses-permission android:name="android.permission.WRITE_APN_SETTINGS"/><!--写入APN信息 -->
        <uses-permission android:name="android.permission.ACCESS_CHECKIN_PROPERTIES"/><!--GoogleMap的一个功能,自动记录到过的地方 -->
        <uses-permission android:name="android.permission.READ_USER_DICTIONARY"/><!--读取用户目录 -->
        <uses-permission android:name="android.permission.WRITE_USER_DICTIONARY"/><!-- 写入用户目录-->
        <uses-permission android:name="android.permission.FORCE_STOP_PACKAGES"/><!--强制停止应用 -->
        <uses-permission android:name="android.permission.PACKAGE_USAGE_STATS"/><!--打包用户状态 -->
        <uses-permission android:name="android.permission.BATTERY_STATS"/><!--读取电池状态 -->
        <uses-permission android:name="com.android.launcher.permission.READ_SETTINGS" /><!--读取设置信息 -->
        <uses-permission android:name="com.android.launcher.permission.WRITE_SETTINGS" /><!--写入设置信息 -->
        <uses-permission android:name="android.permission.MOVE_PACKAGE" /><!--移动应用 -->
        <uses-permission android:name="android.permission.USE_CREDENTIALS" /><!--获取用户授权码 -->
        <uses-permission android:name="android.permission.BACKUP" /><!--备份 -->
        <uses-permission android:name="android.permission.READ_SYNC_SETTINGS" /><!--读取同步设置 -->
        <uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" /><!--写入同步设置 -->
        <uses-permission android:name="android.permission.READ_SYNC_STATS" /><!--读取同步状态 -->
        <uses-permission android:name="android.permission.READ_SYNC_SETTINGS" /><!--读取同步设置 -->
        <uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" /><!-- 写入同步设置-->
        <uses-permission android:name="android.permission.STATUS_BAR" /><!-- 状态栏-->
        <uses-permission android:name="android.permission.MANAGE_USB" /><!--管理USB -->
        <uses-permission android:name="android.permission.SET_POINTER_SPEED" /><!--设置指针速度 -->
        <uses-permission android:name="android.permission.SET_KEYBOARD_LAYOUT" /><!--设置键盘布局 -->
        <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" /><!--允许不同用户间的应用可以交互 -->
        <uses-permission android:name="android.permission.COPY_PROTECTED_DATA" /><!--复制保护资料 -->
        <uses-permission android:name="android.permission.MANAGE_USERS" /><!--管理用户 -->
        <uses-permission android:name="android.permission.READ_PROFILE" /><!--读取用户资料 -->
        <uses-permission android:name="android.permission.CONFIGURE_WIFI_DISPLAY" /><!--配置WiFi显示设备 -->
        <uses-permission android:name="android.permission.SET_TIME" /><!--设置时间 -->
        <uses-permission android:name="android.permission.ACCESS_NOTIFICATIONS" /><!--获取通知 -->
        <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /><!--接收启动完成广播 -->
        <uses-permission android:name="android.permission.WAKE_LOCK"/><!-- 唤醒-->
        <uses-permission android:name="android.permission.REBOOT" /><!--重启 -->
        <uses-permission android:name="android.permission.MANAGE_DEVICE_ADMINS" />
        <uses-permission android:name="android.permission.HOTKNOT" /><!-- MTK的一个类似于NFC的技术,可参照TCL的么么哒-->


    Setting显示开发者选项的逻辑

    默认User版本没有“开发者选项”,我们可以通过点击版本号7次来显示开发者模式,今天来看下代码中是如何处理的:

    首先是packages/apps/Settings/src/com/android/settings/Settings.java的初始化处理:

    布尔值showDev是否默认显示“开发者选项”:

     final boolean showDev = mDevelopmentPreferences.getBoolean(
                    DevelopmentSettings.PREF_SHOW,
                    android.os.Build.TYPE.equals("eng"));

    如果想让开发者选项默认显示,不需要点击7次版本号,可直接将showDev置为true即可:
    final boolean showDev = true; 

    如果showDev为false,则在如下代码中隐藏“开发者选项”:
    if (id == R.id.development_settings) {
                    if (!showDev) {
                        target.remove(i);
                    }
                } 


    下面看一下点击版本号显示开发者选项的部分:

    代码路径:packages/apps/Settings/src/com/android/settings/DeviceInfoSettings.java

    首先是定义点击次数:

    static final int TAPS_TO_BE_A_DEVELOPER = 7;


    点击版本号的处理逻辑,若mDevHitCountdown小于0,则表示”开发者选项“已经显示,参考Resume函数的处理:

    if (preference.getKey().equals(KEY_BUILD_NUMBER)) {
                // Don't enable developer options for secondary users.
                if (UserHandle.myUserId() != UserHandle.USER_OWNER) return true;
    
                if (mDevHitCountdown > 0) {
                    if (mDevHitCountdown == 1) {
                        if (super.ensurePinRestrictedPreference(preference)) {
                            return true;
                        }
                    }
                    mDevHitCountdown--;
                    if (mDevHitCountdown == 0) {
                        getActivity().getSharedPreferences(DevelopmentSettings.PREF_FILE,
                                Context.MODE_PRIVATE).edit().putBoolean(
                                        DevelopmentSettings.PREF_SHOW, true).apply();
                        if (mDevHitToast != null) {
                            mDevHitToast.cancel();
                        }
                        mDevHitToast = Toast.makeText(getActivity(), R.string.show_dev_on,
                                Toast.LENGTH_LONG);
                        mDevHitToast.show();
                    } else if (mDevHitCountdown > 0
                            && mDevHitCountdown < (TAPS_TO_BE_A_DEVELOPER-2)) {
                        if (mDevHitToast != null) {
                            mDevHitToast.cancel();
                        }
                        mDevHitToast = Toast.makeText(getActivity(), getResources().getQuantityString(
                                R.plurals.show_dev_countdown, mDevHitCountdown, mDevHitCountdown),
                                Toast.LENGTH_SHORT);
                        mDevHitToast.show();
                    }
                } else if (mDevHitCountdown < 0) {
                    if (mDevHitToast != null) {
                        mDevHitToast.cancel();
                    }
                    mDevHitToast = Toast.makeText(getActivity(), R.string.show_dev_already,
                            Toast.LENGTH_LONG); 
                    mDevHitToast.show();
                }
            } 

    Resume函数:
    @Override
        public void onResume() {
            super.onResume();
            PreferenceGroup parentPreference = getPreferenceScreen();
            mDevHitCountdown = getActivity().getSharedPreferences(DevelopmentSettings.PREF_FILE,
                    Context.MODE_PRIVATE).getBoolean(DevelopmentSettings.PREF_SHOW,
                            android.os.Build.TYPE.equals("eng")) ? -1 : TAPS_TO_BE_A_DEVELOPER;
            mDevHitToast = null;
        }



    Setting的默认初始配置

    frameworks/base/packages/SettingsProvider/res/values/default.xml
    这里貌似可以修改很多东西,但要在
    frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java

    中初始化才会生效:


    <resources>
    <!-- 是否显示截屏按钮-->
    <!-- should show the screenshot button default -->
    <bool name="def_screenshot_button_show">true</bool>
    <!-- 截屏图片保存位置-->
    <!-- the store location of screen capture by default-->
    <string name="def_screenshot_location">/mnt/sdcard</string>
    <bool name="def_dim_screen">true</bool>
    <!-- 屏幕默认休眠时间-->
    <integer name="def_screen_off_timeout">60000</integer>
    
    <!-- 飞行模式默认是否打开-->
    <bool name="def_airplane_mode_on">false</bool>
    <!-- Comma-separated list of bluetooth, wifi, and cell. -->
    <string name="def_airplane_mode_radios" translatable="false">cell,bluetooth,wifi,nfc,wimax</string>
    <string name="airplane_mode_toggleable_radios" translatable="false">bluetooth,wifi,nfc</string>
    <bool name="def_auto_time">true</bool>
    <bool name="def_auto_time_zone">true</bool>
    <bool name="def_accelerometer_rotation">true</bool>
    <!-- 默认屏幕背光-->
    <!-- Default screen brightness, from 0 to 255. 102 is 40%. -->
    <integer name="def_screen_brightness">102</integer>
    <bool name="def_screen_brightness_automatic_mode">false</bool>
    <fraction name="def_window_animation_scale">100%</fraction>
    <fraction name="def_window_transition_scale">100%</fraction>
    <bool name="def_haptic_feedback">true</bool>
    <!--蓝牙是否默认打开 -->
    <bool name="def_bluetooth_on">false</bool>
    <bool name="def_wifi_display_on">false</bool>
    <!-- 允许安装未知来源的应用-->
    <bool name="def_install_non_market_apps">false</bool>
    <bool name="def_package_verifier_enable">true</bool>
    <!-- Comma-separated list of location providers.
    Network location is off by default because it requires
    user opt-in via Setup Wizard or Settings.
    -->
    <!--M: set gps default is off.-->
    <string name="def_location_providers_allowed" translatable="false"></string>
    <bool name="assisted_gps_enabled">true</bool>
    <bool name="def_netstats_enabled">true</bool>
    <bool name="def_usb_mass_storage_enabled">true</bool>
    <bool name="def_wifi_on">false</bool>
    <!-- 0 == never, 1 == only when plugged in, 2 == always -->
    <integer name="def_wifi_sleep_policy">0</integer>
    <bool name="def_networks_available_notification_on">true</bool>
    
    <bool name="def_backup_enabled">false</bool>
    <!--string name="def_backup_transport" translatable="false">android/com.android.internal.backup.LocalTransport</string-->
    <string name="def_backup_transport" translatable="false">com.google.android.backup/.BackupTransportService</string>
    
    <!-- Default value for whether or not to pulse the notification LED when there is a
    pending notification -->
    <bool name="def_notification_pulse">true</bool>
    
    <bool name="def_mount_play_notification_snd">true</bool>
    <bool name="def_mount_ums_autostart">false</bool>
    <bool name="def_mount_ums_prompt">true</bool>
    <bool name="def_mount_ums_notify_enabled">true</bool>
    
    <!-- user interface sound effects -->
    <integer name="def_power_sounds_enabled">1</integer>
    <string name="def_low_battery_sound" translatable="false">/system/media/audio/ui/LowBattery.ogg</string>
    <integer name="def_dock_sounds_enabled">0</integer>
    <string name="def_desk_dock_sound" translatable="false">/system/media/audio/ui/Dock.ogg</string>
    <string name="def_desk_undock_sound" translatable="false">/system/media/audio/ui/Undock.ogg</string>
    <string name="def_car_dock_sound" translatable="false">/system/media/audio/ui/Dock.ogg</string>
    <string name="def_car_undock_sound" translatable="false">/system/media/audio/ui/Undock.ogg</string>
    <integer name="def_lockscreen_sounds_enabled">1</integer>
    <string name="def_lock_sound" translatable="false">/system/media/audio/ui/Lock.ogg</string>
    <string name="def_unlock_sound" translatable="false">/system/media/audio/ui/Unlock.ogg</string>
    <string name="def_wireless_charging_started_sound" translatable="false">/system/media/audio/ui/WirelessChargingStarted.ogg</string>
    
    <bool name="def_lockscreen_disabled">false</bool>
    <bool name="def_device_provisioned">false</bool>
    <integer name="def_dock_audio_media_enabled">1</integer>
    
    <!-- Notifications use ringer volume -->
    <bool name="def_notifications_use_ring_volume">true</bool>
    
    <!-- Default for Settings.System.VIBRATE_IN_SILENT -->
    <bool name="def_vibrate_in_silent">true</bool>
    
    <!-- Default for Settings.Secure.ACCESSIBILITY_SCRIPT_INJECTION -->
    <bool name="def_accessibility_script_injection">false</bool>
    
    <!-- Default for Settings.Secure.ACCESSIBILITY_SPEAK_PASSWORD -->
    <bool name="def_accessibility_speak_password">false</bool>
    
    <!-- Default for Settings.Secure.ACCESSIBILITY_WEB_CONTENT_KEY_BINDINGS -->
    <string name="def_accessibility_web_content_key_bindings" translatable="false">
    <!-- DPAD/Trackball UP - traverse previous on current axis and send an event. -->
    0x13=0x01000100;
    <!-- DPAD/Trackball DOWN - traverse next on current axis and send an event. -->
    0x14=0x01010100;
    <!-- DPAD/Trackball LEFT - traverse previous on the character navigation axis and send event. -->
    0x15=0x02000001;
    <!-- DPAD/Trackball RIGHT - traverse next on the character navigation axis end send event. -->
    0x16=0x02010001;
    <!-- Alt+DPAD/Trackball UP - go to the top of the document. -->
    0x200000013=0x02000601;
    <!-- Alt+DPAD/Trackball DOWN - go to the bottom of the document. -->
    0x200000014=0x02010601;
    <!-- Alt+DPAD/Trackball LEFT - transition from an axis to another and sends an event.-->
    <!-- Axis transitions: 2 -> 1; -->
    0x200000015=0x03020101;
    <!-- Alt+DPAD/Trackball RIGHT - transition from an axis to another and sends an event. -->
    <!-- Axis transitions: 1 -> 2; -->
    0x200000016=0x03010201;
    <!-- Alt+g - go to the previous heading and send an event. -->
    0x200000023=0x02000301;
    <!-- Alt+h - go to the next heading and send an event. -->
    0x200000024=0x02010301;
    <!-- Alt+COMMA - transition to sentence navigation axis and send an event. -->
    <!-- Axis transitions: 7 -> 2; -->
    0x200000037=0x03070201;
    <!-- Alt+PERIOD - transition to default web view behavior axis and send an event. -->
    <!-- Axis transitions: 0 -> 7; 1 - > 7; 2 -> 7; -->
    0x200000038=0x03000701:0x03010701:0x03020701;
    </string>
    
    <!-- Default for Settings.Secure.ACCESSIBILITY_SCRIPT_INJECTION_URL -->
    <string name="def_accessibility_screen_reader_url" translatable="false">
    https://ssl.gstatic.com/accessibility/javascript/android/AndroidVox_v1.js
    </string>
    
    <!-- Default for Settings.Secure.TOUCH_EXPLORATION_ENABLED -->
    <bool name="def_touch_exploration_enabled">false</bool>
    
    <!-- Default value for Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE -->
    <fraction name="def_accessibility_display_magnification_scale">200%</fraction>
    
    <!-- Default value for Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED -->
    <bool name="def_accessibility_display_magnification_enabled">false</bool>
    
    <!-- Default value for Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_AUTO_UPDATE -->
    <bool name="def_accessibility_display_magnification_auto_update">true</bool>
    
    <!-- Default for Settings.System.USER_ROTATION -->
    <integer name="def_user_rotation">0</integer>
    
    <!-- Default for Settings.Secure.DOWNLOAD_MAX_BYTES_OVER_MOBILE. <=0 if no limit -->
    <integer name="def_download_manager_max_bytes_over_mobile">-1</integer>
    <!-- Default for Settings.Secure.DOWNLOAD_RECOMMENDED_MAX_BYTES_OVER_MOBILE. <=0 if no limit -->
    <integer name="def_download_manager_recommended_max_bytes_over_mobile">-1</integer>
    
    <!-- Default for Settings.Secure.LONG_PRESS_TIMEOUT_MILLIS -->
    <integer name="def_long_press_timeout_millis">500</integer>
    
    <!-- Default for Settings.System.POINTER_SPEED -->
    <integer name="def_pointer_speed">0</integer>
    
    <!-- Default for DTMF tones enabled -->
    <bool name="def_dtmf_tones_enabled">true</bool>
    <!-- M: Default for UI touch sounds disabled ,google defaulit is enable -->
    <bool name="def_sound_effects_enabled">false</bool>
    
    <!-- Development settings -->
    <bool name="def_stay_on_while_plugged_in">false</bool>
    
    <!-- Number of retries for connecting to DHCP.
    Value here is the same as WifiStateMachine.DEFAULT_MAX_DHCP_RETRIES -->
    <integer name="def_max_dhcp_retries">9</integer>
    
    <!-- Default for Settings.Secure.USER_SETUP_COMPLETE -->
    <bool name="def_user_setup_complete">false</bool>
    
    <!-- Default for Settings.Global.LOW_BATTERY_SOUND_TIMEOUT.
    0 means no timeout; battery sounds will always play
    >0 is milliseconds of screen-off time after which battery sounds will not play -->
    <integer name="def_low_battery_sound_timeout">0</integer>
    </resources>
    


    当然还有mtk_default.xml
    修改完成后,在
    frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
    中的 private void loadGlobalSettings(SQLiteDatabase db) { ... ... }函数中增加初始化数据库的值:


    然后执行:
    ./mk -t mm frameworks/base/packages/SettingsProvider/
    生成目录:
    out/target/product/esky82_tb_cn_kk/system/priv-app/SettingsProvider.apk



    删除设置中情景模式的震动选项(会议模式和户外模式)


    packages/apps/Settings/res/xml/audioprofile_settings.xml

    注释掉会议模式和户外模式

    packages/apps/Settings/res/xml/edit_profile_prefs.xml
    注释掉:
    <PreferenceCategory
    android:key="general"
    android:title="@string/sound_category_sound_title"/>
    <!-- <CheckBoxPreference 
    android:key="phone_vibrate" 
    android:title="@string/vibrate_title"
    android:summary="@string/Phone_vibrate_summary"/>-->
    <com.mediatek.audioprofile.RingerVolumePreference
    android:key="ring_volume"
    android:title="@string/all_volume_title"
    android:dialogTitle="@string/all_volume_title"
    android:persistent="false"/>

    packages/apps/Settings/src/com/medietek/audrioprofile/AduioProfileSettings.java
    注释掉public void onCreate(Bundle icicle) {}中以下几行代码:
    //pref = (AudioProfilePreference) findPreference(MEETING_PREF_KEY);
    //pref.setOnSettingsClickListener(mProfileSettingListener);
    //pref = (AudioProfilePreference) findPreference(OUTDOOR_PREF_KEY);
    //pref.setOnSettingsClickListener(mProfileSettingListener);

    或者改成以下:
    这个方案得:import android.os.SystemProperties;
    if (!SystemProperties.get("ro.project.target").equals("es706")) {
    // Do nothing
    } else {
    pref = (AudioProfilePreference) findPreference(MEETING_PREF_KEY);
    pref.setOnSettingsClickListener(mProfileSettingListener);
    pref = (AudioProfilePreference) findPreference(OUTDOOR_PREF_KEY);
    pref.setOnSettingsClickListener(mProfileSettingListener);
    }

    packages/apps/Settings/src/com/medietek/audrioprofile/Editprofile.java
    private void initPreference() {}中注释以下:
     
        //   mVibrat = (CheckBoxPreference) findPreference(KEY_VIBRATE);
        ... ...
           //  mVibrat.setEnabled(false);

    还有这里,总之搜索mVibrat的结果都注释掉或者加个判断:
    if (!isSmsCapable()) {
    // parent.removePreference(mVibrat);
    }
    
    private void updatePreference() {
    // mVibrat.setChecked(mProfileManager.getVibrationEnabled(mKey));
    ... ...

    还有这一大段:
    // if (mVibrat != null) {
    // final String name = AudioProfileManager.getVibrationKey(mKey);
    // Xlog.d(TAG,"name " + name);
    // String vibrateEnabled = Settings.System.getString(
    // getContentResolver(), name);
    // if (vibrateEnabled != null) {
    // mVibrat.setChecked("true"
    // .equals(vibrateEnabled));
    // Xlog.d(TAG,
    // "vibrate setting is "
    // + "true".equals(vibrateEnabled));
    // }
    //
    // }

    还有:
    public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
    Preference preference) {
    Xlog.d(TAG, "Key :" + preference.getKey());
    // if ((preference.getKey()).equals(KEY_VIBRATE)) {
    // boolean isVibrate = mVibrat.isChecked();
    // Xlog.d(TAG, "set vibrate" + isVibrate);
    // mProfileManager.setVibrationEnabled(mKey, isVibrate);
    // } else


    显示设置中增加“永不休眠”功能

    首先在frameworksasepackagesSettingsProvider esvaluesdefaults.xml中设置def_screen_off_timeout为-1,即
    <integer name="def_screen_off_timeout">-1</integer>
    然后修改alpspackagesappsSettings esvaluesarrays.xml:

     <!-- Display settings.  The delay in inactivity before the screen is turned off. These are shown ain a list dialog. -->
        <string-array name="screen_timeout_entries">
            <item>15 seconds</item>
            <item>30 seconds</item>
            <item>1 minute</item>
            <item>2 minutes</item>
            <item>10 minutes</item>
            <item>30 minutes</item>
            <item>never</item>
        </string-array>
     
        <!-- Do not translate. -->
       <string-array  name="screen_timeout_values" translatable="false">
            <!-- Do not translate. -->
            <item>15000</item>
            <!-- Do not translate. -->
            <item>30000</item>
            <!-- Do not translate. -->
            <item>60000</item>
            <!-- Do not translate. -->
            <item>120000</item>
            <!-- Do not translate. -->
            <item>600000</item>
            <!-- Do not translate. -->
            <item>1800000</item>
             <item>-1</item>
        </string-array>

    接着修改对比语言value文件夹下的arrays.xml, 修改screen_timeout_entries对应的翻译。不用管那个msgid,只是google用来表示是他自己的资源而已,直接添加<item >"永不休眠"</item>即可。

    然后是代码的改动:

    frameworks/base/services/java/com/android/server/power/PowerManagerService.java

    private void updateUserActivitySummaryLocked(long now, int dirty) {
    .....
     
    //change code here ==============
                          Slog.d(TAG,"mScreenOffTimeoutSetting ="+mScreenOffTimeoutSetting);
                          //if (mUserActivitySummary != 0 ) {
                    if (mUserActivitySummary != 0 && mScreenOffTimeoutSetting > 0) {
    //change code here  end ==============
                        Message msg = mHandler.obtainMessage(MSG_USER_ACTIVITY_TIMEOUT);
                        msg.setAsynchronous(true);
                        mHandler.sendMessageAtTime(msg, nextTimeout);
                    }
    Android修改应用的默认安装位置

    Google默认的PackageManager,会读取应用AndroidManifest.xml的对应定义

    installLocation规则如下:

    1.如果没有定义安装位置,表示安装在手机内存上;

    2.android:installLocation ="auto" :先查看手机内存是否足够,如果够就安装在手机内存上,不够就安装在T 卡上;

    3.android:installLocation = "internalOnly":表示安装在手机内存上;

    4.android:installLocation = "preferExternal":表示安装在 T 卡上;

    如何在设置中增加“选取应用安装位置”的功能,让用户选择默认的安装位置?

    修改如下文件:frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java

    loadSetting(stmt, Global.SET_INSTALL_LOCATION, 0);

    改为:
    loadSetting(stmt, Secure.SET_INSTALL_LOCATION, 1);

    并将

    loadSetting(stmt, Settings.Secure.SET_INSTALL_LOCATION, 0);
    改为:
    loadSetting(stmt, Settings.Secure.SET_INSTALL_LOCATION, 1);

    这样修改之后,在设置>应用中会出现“选取应用安装位置”的功能,不过无论在这里选择什么,对于应用中AndroidManifest.xml文件中声明

    android:installLocation = "internalOnly"
    的,该apk 都会安装到手机上,这样做的好处是避免程序运行错误,因为定义android:installLocation = "internalOnly" 的 apk 一般要安装到手机内存上才能正常运行。


    默认输入法勾选多国语言,并默认其中一种语言

    1.首先在设备上调整输入法

    设置>语言输入法>Android键盘(AOSP),在输入语言里勾选要选择的语言,比如选“英语(美国)”和“西班牙文”两种:


    2.选择系统输入法的默认语言(默认为两种语言中的“西班牙文”)

    打开一个能能调出输入法的应用,下拉通知栏里,“选择输入法”调整为“西班牙文”


    3.查看Setting数据库文件

    adb pull data/data/com.android.providers.settings/databases/settings.db C:

    打开Secure表,查看default_input_method,enabled_input_methods和selected_input_method_subtype三个字段内容,并记录:

    default_input_method       com.android.inputmethod.latin/.LatinIME

    enabled_input_methods    com.android.inputmethod.latin/.LatinIME;816242702;-921088104

    selected_input_method_subtype    816242702


    4.修改SettingsProvider文件

    frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java

    将函数private void loadSecureSettings(SQLiteDatabase db) 中的以下两行(注意是loadSecureSettings函数,不是loadSystemSettings):

               

     loadSetting(stmt, Settings.Secure.ENABLED_INPUT_METHODS, defaultIme);
                loadSetting(stmt, Settings.Secure.DEFAULT_INPUT_METHOD, defaultIme);

    修改为以下三行:

    loadSetting(stmt, Settings.Secure.ENABLED_INPUT_METHODS,"com.android.inputmethod.latin/.LatinIME;816242702;-921088104");//选中的输入法
    loadSetting(stmt, Settings.Secure.DEFAULT_INPUT_METHOD, "com.android.inputmethod.latin/.LatinIME");// 默认输入法为系统输入法
    loadSetting(stmt, Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE, "816242702"); // 默认输入法的默认语言

    android.provider.Settings的Secure和System常量

    android.provider.Settings.Secure常量

    String ACCESSIBILITY_DISPLAY_INVERSION_ENABLEDSetting that specifies whether display color inversion is enabled.

    String ACCESSIBILITY_ENABLED If accessibility is enabled.
    String ACCESSIBILITY_SPEAK_PASSWORD Whether to speak passwords while in accessibility mode.
    String ADB_ENABLED This constant was deprecated in API level 17. Use ADB_ENABLED instead
    String ALLOWED_GEOLOCATION_ORIGINS Origins for which browsers should allow geolocation by default.
    String ALLOW_MOCK_LOCATION Setting to allow mock locations and location provider status to be injected into the LocationManager service for testing purposes during application development.
    String ANDROID_ID A 64-bit number (as a hex string) that is randomly generated when the user first sets up the device and should remain constant for the lifetime of the user's device.
    String BACKGROUND_DATA This constant was deprecated in API level 14. As of ICE_CREAM_SANDWICH, availability of background data depends on several combined factors. When background data is unavailable, getActiveNetworkInfo() will now appear disconnected.
    String BLUETOOTH_ON This constant was deprecated in API level 17. Use BLUETOOTH_ON instead
    String DATA_ROAMING This constant was deprecated in API level 17. Use DATA_ROAMING instead
    String DEFAULT_INPUT_METHOD Setting to record the input method used by default, holding the ID of the desired method.
    String DEVELOPMENT_SETTINGS_ENABLED This constant was deprecated in API level 17. Use DEVELOPMENT_SETTINGS_ENABLED instead
    String DEVICE_PROVISIONED This constant was deprecated in API level 17. Use DEVICE_PROVISIONED instead
    String ENABLED_ACCESSIBILITY_SERVICES
  • 相关阅读:
    mysql5.7创建用户授权删除用户撤销授权
    什么是分表和分区 MySql数据库分区和分表方法
    linux命令大全之watch命令详解(监测命令运行结果)
    netstat统计的tcp连接数与⁄proc⁄pid⁄fd下socket类型fd数量不一致的分析
    ss is one another utility to investigate sockets(特适合大规模tcp链接)
    /proc/net/sockstat 里的信息是什么意思?
    linux平台下server运维问题分析与定位
    strace命令解析
    MySQL常见错误代码及代码说明
    自动化部署必备技能—定制化RPM包
  • 原文地址:https://www.cnblogs.com/ztguang/p/12644805.html
Copyright © 2020-2023  润新知