Android设置默认8时区和默认24小时制

1、写在前面

不同的产品开发有不同的需求对于默认的时间

2设置默认8时区和默认24小时制的核心类

build/make/tools/buildinfo_common.sh
framework/base/packages/apps/SettingsProvider/res/values/defaults.xml
framework/base/packages/apps/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java 	

3.设置默认时区的功能实现

在buildinfo_common.sh 中添加时区属性persist.sys.timezone
android 默认时区 为GMT 0时区,默认设置为北京或者上海

#!/bin/bash
 
 partition="$1"
 
 if [ "$#" -ne 1 ]; then
   echo "Usage: $0 " 1>&2
   exit 1
 fi
 
 echo "# begin common build properties"
 echo "# autogenerated by $0"
 
 echo "ro.${partition}.build.date=`$DATE`"
 echo "ro.${partition}.build.date.utc=`$DATE +%s`"
 echo "ro.${partition}.build.fingerprint=$BUILD_FINGERPRINT"
 echo "ro.${partition}.build.id=$BUILD_ID"
 echo "ro.${partition}.build.tags=$BUILD_VERSION_TAGS"
 echo "ro.${partition}.build.type=$TARGET_BUILD_TYPE"
 echo "ro.${partition}.build.version.incremental=$BUILD_NUMBER"
 echo "ro.${partition}.build.version.release=$PLATFORM_VERSION_LAST_STABLE"
 echo "ro.${partition}.build.version.release_or_codename=$PLATFORM_VERSION"
 echo "ro.${partition}.build.version.sdk=$PLATFORM_SDK_VERSION"
 
 echo "ro.product.${partition}.brand=$PRODUCT_BRAND"
 echo "ro.product.${partition}.device=$PRODUCT_DEVICE"
 echo "ro.product.${partition}.manufacturer=$PRODUCT_MANUFACTURER"
 echo "ro.product.${partition}.model=$PRODUCT_MODEL"
 echo "ro.product.${partition}.name=$PRODUCT_NAME"
+ echo "persist.sys.timezone=Asia/Shanghai"
 echo "# end common build properties"

4、在SettingsProvider的defaults.xml中添加24小时的系统属性值

   <resources>
     <bool name="def_dim_screen">truebool>
     <integer name="def_screen_off_timeout">300000integer>
     <integer name="def_sleep_timeout">-1integer>
     <bool name="def_airplane_mode_on">falsebool>
     <bool name="def_theater_mode_on">falsebool>
     
     <string name="def_airplane_mode_radios" translatable="false">cell,bluetooth,wifi,nfc,wimaxstring>
     <string name="airplane_mode_toggleable_radios" translatable="false">bluetooth,wifi,nfcstring>
     <string name="def_bluetooth_disabled_profiles" translatable="false">0string>
     <bool name="def_auto_time">truebool>
     <bool name="def_auto_time_zone">truebool>
    + <string name="def_time_12_24">24string>
     <bool name="def_accelerometer_rotation">falsebool>
     
     <integer name="def_screen_brightness">102integer>
     <bool name="def_screen_brightness_automatic_mode">falsebool>
     <fraction name="def_window_animation_scale">100%fraction>
     <fraction name="def_window_transition_scale">100%fraction>
     <bool name="def_haptic_feedback">truebool>
     <integer name="def_show_battery_percent">1integer>
     <bool name="def_bluetooth_on">falsebool>
     <bool name="def_wifi_display_on">falsebool>
     <bool name="def_install_non_market_apps">falsebool>
     
     <integer name="def_location_mode">3integer>
     <bool name="assisted_gps_enabled">truebool>
     <bool name="def_netstats_enabled">truebool>
     <bool name="def_usb_mass_storage_enabled">truebool>
     <bool name="def_wifi_on">falsebool>
     
     <integer name="def_wifi_sleep_policy">2integer>
     <bool name="def_wifi_wakeup_enabled">truebool>
     <bool name="def_networks_available_notification_on">truebool>
	 ...
 resources>

5、在DatabaseHelper.java中设置默认时间属性

  private void loadSystemSettings(SQLiteDatabase db) {
         SQLiteStatement stmt = null;
         try {
             stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
                     + " VALUES(?,?);");
 
             loadBooleanSetting(stmt, Settings.System.DIM_SCREEN,
                     R.bool.def_dim_screen);
             loadIntegerSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT,
                     R.integer.def_screen_off_timeout);
 
             // Set default cdma DTMF type
             loadSetting(stmt, Settings.System.DTMF_TONE_TYPE_WHEN_DIALING, 0);
       +      loadStringSetting(stmt, Settings.System.TIME_12_24, R.string.def_time_12_24);
             // Set default hearing aid
             loadSetting(stmt, Settings.System.HEARING_AID, 0);
 
             // Set default tty mode
             loadSetting(stmt, Settings.System.TTY_MODE, 0);
 
             loadIntegerSetting(stmt, Settings.System.SCREEN_BRIGHTNESS,
                     R.integer.def_screen_brightness);
 
             loadIntegerSetting(stmt, Settings.System.SCREEN_BRIGHTNESS_FOR_VR,
                     com.android.internal.R.integer.config_screenBrightnessForVrSettingDefault);
 
             loadBooleanSetting(stmt, Settings.System.SCREEN_BRIGHTNESS_MODE,
                     R.bool.def_screen_brightness_automatic_mode);
 
             loadBooleanSetting(stmt, Settings.System.ACCELEROMETER_ROTATION,
                     R.bool.def_accelerometer_rotation);
 
             loadDefaultHapticSettings(stmt);
 
             loadBooleanSetting(stmt, Settings.System.NOTIFICATION_LIGHT_PULSE,
                     R.bool.def_notification_pulse);
 
             loadUISoundEffectsSettings(stmt);
 
             loadIntegerSetting(stmt, Settings.System.POINTER_SPEED,
                     R.integer.def_pointer_speed);
             loadIntegerSetting(stmt, Settings.System.SHOW_BATTERY_PERCENT, R.integer.def_show_battery_percent);
             /// M: Load MTK added System providers before Android M.
             mUtils.loadCustomSystemSettings(stmt);
 
             /*
              * IMPORTANT: Do not add any more upgrade steps here as the global,
              * secure, and system settings are no longer stored in a database
              * but are kept in memory and persisted to XML.
              *
              * See: SettingsProvider.UpgradeController#onUpgradeLocked
              */
         } finally {
             if (stmt != null) stmt.close();
         }

你可能感兴趣的:(Android,ROM,定制,android,linux,chrome,framework,时区,安卓系统)