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"/>
+               
+        
 


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 @@
        1.00 GB
        8.00 GB
     
+       
+       boot sound
 

 

控制开关初始值可以再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 查看指定属性

 

你可能感兴趣的:(MTK随记)