Android设置界面添加开关控制开关机铃声

平台:MTK

Android 6.0

Desired:在设置里面做一个开关,可以选择性的打开或关闭开机铃声,默认打开

通过SystemProperties.java来取得\设置系统属性的值

修改开关机动画无法再上层做开关机动画的控制,该方法通过系统属性来控制

Path:frameworks/base/cmds/bootanimation/bootanimation_main.cpp

 

--- a/alps/frameworks/base/cmds/bootanimation/bootanimation_main.cpp
+++ b/alps/frameworks/base/cmds/bootanimation/bootanimation_main.cpp
@@ -56,6 +56,15 @@ int main(int argc, char** argv)
         bool setBoot = true;
         bool setRotated = false;
         bool sePaly = true;
+               //add 20170727
+               char audio[PROPERTY_VALUE_MAX];
+               property_get("persist.sys.poweronoff_audio", audio, "1");
+               if (atoi(audio) == 1){
+                       sePaly = true;
+               }else{
+                       sePaly = false;
+               }
+               //end
         if(argc > 1){
            if(!strcmp(argv[1],"shut"))
                setBoot = false;


Path:packages/apps/Settings/src/com/mediatek/audioprofile/Editprofile.java

 

 

--- a/alps/packages/apps/Settings/src/com/mediatek/audioprofile/Editprofile.java
+++ b/alps/packages/apps/Settings/src/com/mediatek/audioprofile/Editprofile.java
@@ -69,6 +69,8 @@ import com.mediatek.settings.FeatureOption;
 
 import java.util.Observable;
 import java.util.Observer;
+//add 20170727
+import android.os.SystemProperties;
 
 /**
  * Edit profile fragment, started when one profile setting button is clicked.
@@ -88,6 +90,9 @@ public class Editprofile extends SettingsPreferenceFragment {
     public static final String KEY_SOUND_EFFECTS = "audible_selection";
     public static final String KEY_LOCK_SOUNDS = "screen_lock_sounds";
     public static final String KEY_HAPTIC_FEEDBACK = "haptic_feedback";
+	// add 20170725
+	public static final String KEY_BOOT_SOUND = "boot_sound";
+	
     private static final String ACTION_SIM_SETTINGS = "com.android.settings.sim.SELECT_SUB";
 
     private static final String TAG = "AudioProfile/EditProfile";
@@ -97,6 +102,8 @@ public class Editprofile extends SettingsPreferenceFragment {
     private TwoStatePreference mSoundEffects;
     private TwoStatePreference mHapticFeedback;
     private TwoStatePreference mLockSounds;
+	// add 20170725
+	private TwoStatePreference mBootSounds;
 
     //private RingerVolumePreference mVolumePref;
     private DefaultRingtonePreference mVoiceRingtone;
@@ -302,11 +309,15 @@ public class Editprofile extends SettingsPreferenceFragment {
         mSoundEffects = (TwoStatePreference) findPreference(KEY_SOUND_EFFECTS);
         mLockSounds = (TwoStatePreference) findPreference(KEY_LOCK_SOUNDS);
         mHapticFeedback = (TwoStatePreference) findPreference(KEY_HAPTIC_FEEDBACK);
+		// add 20170725
+		mBootSounds = (TwoStatePreference) findPreference(KEY_BOOT_SOUND);
         setPreferenceListener(KEY_VIBRATE, mVibrat);
         setPreferenceListener(KEY_DTMF_TONE, mDtmfTone);
         setPreferenceListener(KEY_SOUND_EFFECTS, mSoundEffects);
         setPreferenceListener(KEY_LOCK_SOUNDS, mLockSounds);
         setPreferenceListener(KEY_HAPTIC_FEEDBACK, mHapticFeedback);
+		// add 20170725
+		setPreferenceListener(KEY_BOOT_SOUND, mBootSounds);
     }
 
     private void removePrefWhenSilentOrMeeting(PreferenceScreen parent) {
@@ -317,6 +328,8 @@ public class Editprofile extends SettingsPreferenceFragment {
         parent.removePreference(mVideoRingtone);
         parent.removePreference(mSipRingtone);
         parent.removePreference(mNotify);
+		// add 20170725
+		parent.removePreference(mBootSounds);
         mVibrat.setEnabled(false);
     }
 
@@ -371,6 +384,8 @@ public class Editprofile extends SettingsPreferenceFragment {
         mSoundEffects.setChecked(mProfileManager.isSoundEffectEnabled(mKey));
         mLockSounds.setChecked(mProfileManager.isLockScreenEnabled(mKey));
         mHapticFeedback.setChecked(mProfileManager.isVibrateOnTouchEnabled(mKey));
+		//add 20170727
+		mBootSounds.setChecked(SystemProperties.get("persist.sys.poweronoff_audio","0").equals("1")? true : false);
     }
 
     /**
@@ -502,7 +517,11 @@ public class Editprofile extends SettingsPreferenceFragment {
             mProfileManager.setLockScreenEnabled(mKey, isChecked);
         } else if (preferenceType.equals(KEY_HAPTIC_FEEDBACK)) {
             mProfileManager.setVibrateOnTouchEnabled(mKey, isChecked);
-        }
+        } else if (preferenceType.equals(KEY_BOOT_SOUND)){
+			// add 20170725
+			Log.d("lds","isChecked:"+isChecked);
+			SystemProperties.set("persist.sys.poweronoff_audio",isChecked?"1":"0");
+		}
     }
 
     private void setRingtongTypeAndStartSIMSelector(int keyIndex) {

Path:packages/apps/Settings/res_ext/xml/edit_profile_prefs.xml

--- a/alps/packages/apps/Settings/res_ext/xml/edit_profile_prefs.xml
+++ b/alps/packages/apps/Settings/res_ext/xml/edit_profile_prefs.xml
@@ -112,4 +112,11 @@
             android:switchTextOff=""
             android:switchTextOn=""
             android:persistent="false"/>
+               <!--add 20170727 Boot sound -->
+        <SwitchPreference 
+            android:key="boot_sound" 
+            android:title="@string/boot_sound_enable_title"
+            android:switchTextOff=""
+            android:switchTextOn=""
+            android:persistent="false"/>
 </PreferenceScreen>


Path:packages/apps/Settings/res/values/strings.xml

 

 

--- a/alps/packages/apps/Settings/res/values/strings.xml
+++ b/alps/packages/apps/Settings/res/values/strings.xml
@@ -7030,4 +7030,6 @@
        <string name="ram_size">1.00 GB</string>
        <string name="phone_store_size">8.00 GB</string>
     <!-- add end -->
+       <!-- add 20170727 -->
+       <string name="boot_sound_enable_title">boot sound</string>
 </resources>

 

控制开关初始值可以再system.prop文件中添加属性persist.sys.poweronoff_audio = 1 设置一个默认值即可

如果是关机动画的话需在:frameworks/base/services/core/Java/com/android/server/power/ShutdownThread.java

在此文件中找到bPlayaudio属性,通过控制该属性的值来决定开关机时是否播放开关机铃声。
注:1.adb shell查看系统属性

getprop 查看所有系统属性

getprop|grep xxx.xxx.xx 查看指定属性

 

发布了86 篇原创文章 · 获赞 33 · 访问量 17万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览