Android系统之路(初识MTK) ------ make update-api长按Power键添加Reboot项/内置默认Ringtone/SMS/Notification/Alarm删除系统铃声

Android系统之路(初识MTK) ------ make update-api长按Power键添加Reboot项/内置默认Ringtone/SMS/Notification/Alarm删除系统铃声_第1张图片

上面是今天要分享的一些系统修改,长按power键添加reboot选项,内置所有客服提供的铃声,并且默认客户指定的系统铃声以及铃声音量,全部移除系统的自带铃声

①长按power键,添加重启选项

首先系统是只有关机选项的,所以我们要先添加布局和标签,在写逻辑代码

需要在 frameworks\base\core\res\res\values\strings.xml 添加一个标签,例如博主添加:

<strong><span style="color:#3366ff;"><string name="engineer_jsp_add_power_reboot">Reboot</string></span></strong>

为了保证该标签能被系统编译,需要将其写到另一个地方 symbols.xml 

frameworks\base\core\res\res\values\symbols.xml 

<strong><span style="color:#3366ff;"><java-symbol type="string" name="engineer_jsp_add_power_reboot" /></span></strong>

frameworks\base\core\res\res\drawable-hdpi中添加对应重启选项的图标

修改java文件:

frameworks\base\policy\src\com\android\internal\policy\impl\GlobalAct
ions.java

修改函数:

<strong><span style="color:#3366ff;">           @Override
            protected void changeStateFromPress(boolean buttonOn) {
                if (!mHasTelephony) return;

                // In ECM mode airplane state cannot be changed
                if (!(Boolean.parseBoolean(
                        SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE)))) {
                    mState = buttonOn ? State.TurningOn : State.TurningOff;
                    mAirplaneState = mState;
                }
            }

            public boolean showDuringKeyguard() {
                return true;
            }

            public boolean showBeforeProvisioning() {
                return false;
            }

            public boolean isEnabled() {
                boolean isAirplaneModeAvailable = true;
                //FIXME: for build pass, please help to crrect me
                /*try {
                    final ITelephonyEx phoneEx = ITelephonyEx.Stub.asInterface(ServiceManager.checkService("phoneEx"));
                    if (phoneEx != null) {
                        isAirplaneModeAvailable = phoneEx.isAirplanemodeAvailableNow();
                    }
                } catch (RemoteException e) {
                    Log.d(TAG, "isAirplanemodeAvailableNow exception caught");
                }*/
                return (super.isEnabled() && isAirplaneModeAvailable);
            }
        };
        onAirplaneModeChanged();

        mItems = new ArrayList<Action>();
        String[] defaultActions = mContext.getResources().getStringArray(
                com.android.internal.R.array.config_globalActionsList);

        ArraySet<String> addedKeys = new ArraySet<String>();
        for (int i = 0; i < defaultActions.length; i++) {
            String actionKey = defaultActions[i];
            if (addedKeys.contains(actionKey)) {
                // If we already have added this, don't add it again.
                continue;
            }
            if (GLOBAL_ACTION_KEY_POWER.equals(actionKey)) {
                mItems.add(new PowerAction());
				
				// Engineer-Jsp add longpress power key reboot item start
				if(android.os.SystemProperties.isWalPadVersion()){
				mItems.add(new SinglePressAction(com.android.internal.R.drawable.ic_lock_power_off,R.string.zzzzz_global_action_power_reboot) {
                public void onPress() {
                mWindowManagerFuncs.reboot(true);
               }
                public boolean onLongPress() {
                mWindowManagerFuncs.rebootSafeMode(true);
                return true;
               }
               public boolean showDuringKeyguard() {
                return true;
               }
               public boolean showBeforeProvisioning() {
                return true;
               }
              }
			 );
            }	
			   // Engineer-Jsp add longpress power key reboot item end
			   
            } else if (GLOBAL_ACTION_KEY_AIRPLANE.equals(actionKey)) {
                mItems.add(mAirplaneModeOn);
            } else if (GLOBAL_ACTION_KEY_BUGREPORT.equals(actionKey)) {
                if (Settings.Global.getInt(mContext.getContentResolver(),
				......</span></strong>

修改 
frameworks\base\core\java\android\view\WindowManagerPolicy.java 添加这个新增的接口

在WindowManagerFuncs这个interface的定义,增加如下function声明:

<strong><span style="color:#3366ff;">public interface WindowManagerFuncs {
public void reboot(boolean confirm);
}</span></strong>
还需要在frameworks\base\services\java\com\android\server\wm\WindowManagerService.j
ava
中添加接口函数的实现

在shutdown()函数后面添加reboot()函数

<strong><span style="color:#3366ff;">    // Called by window manager policy.  Not exposed externally.
    @Override
    public void shutdown(boolean confirm) {
        ShutdownThread.shutdown(mContext, confirm);
    }
	
	//Engineer-Jsp add reboot interface method
	// Called by window manager policy. Not exposed externally.
    @Override
    public void reboot(boolean confirm) {
        ShutdownThread.reboot(mContext,null,confirm);
    }</span></strong>

其中 ShutdownThread.reboot(x,x,x)函数意义

<strong><span style="color:#3366ff;">    /**
     * Request a clean shutdown, waiting for subsystems to clean up their
     * state etc.  Must be called from a Looper thread in which its UI
     * is shown.
     *
     * @param context Context used to display the shutdown progress dialog.
     * @param reason code to pass to the kernel (e.g. "recovery"), or null.
     * @param confirm true if user confirmation is needed before shutting down.
     */
    public static void reboot(final Context context, String reason, boolean confirm) {
        mReboot = true;
        mRebootSafeMode = false;
        mRebootReason = reason;
        Log.d(TAG, "reboot");

        if (mSpew) {
            StackTraceElement[] stack = new Throwable().getStackTrace();
            for (StackTraceElement element : stack)
            {
                Log.d(TAG, " 	|----" + element.toString());
            }
        }

        shutdownInner(context, confirm);
    }</span></strong>

make 工程之后,出现如下错误

<strong><span style="color:#3366ff;">R.string.engineer_jsp_add_power_reboot not defind...

Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

#### make failed to build some targets (01:40 (mm:ss)) ####</span></strong>

原来是我忘记更新系统api了,失误,操作如下命令即可:

<strong><span style="color:#3366ff;">make update-api;make -j24</span></strong>

编译成功后烧录固件,查看效果

Android系统之路(初识MTK) ------ make update-api长按Power键添加Reboot项/内置默认Ringtone/SMS/Notification/Alarm删除系统铃声_第2张图片

②内置铃声

需要内置的铃声文件:

notifications & SMS:

Android系统之路(初识MTK) ------ make update-api长按Power键添加Reboot项/内置默认Ringtone/SMS/Notification/Alarm删除系统铃声_第3张图片

ringtones:


alarms:

Android系统之路(初识MTK) ------ make update-api长按Power键添加Reboot项/内置默认Ringtone/SMS/Notification/Alarm删除系统铃声_第4张图片

我们需要把这些文件分别通过mk编译到 system/的media/audio等目录下

\frameworks\base\data\sounds 编写mk文件如下:

<strong><span style="color:#3366ff;"># Engineer-Jsp Edit Makefile add system default audio
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Engineer-Jsp Edit Makefile add system default audio
LOCAL_PATH := frameworks/base/data/sounds
PRODUCT_COPY_FILES += \
    $(LOCAL_PATH)/alarms/mp3/Celedon.mp3:system/media/audio/alarms/Celedon.mp3 \
    $(LOCAL_PATH)/alarms/mp3/Chartreuse.mp3:system/media/audio/alarms/Chartreuse.mp3 \
    $(LOCAL_PATH)/alarms/mp3/Extreme.mp3:system/media/audio/alarms/Extreme.mp3 \
    $(LOCAL_PATH)/alarms/mp3/Gold.mp3:system/media/audio/alarms/Gold.mp3 \
    $(LOCAL_PATH)/alarms/mp3/Metal.mp3:system/media/audio/alarms/Metal.mp3 \
    $(LOCAL_PATH)/alarms/mp3/Solo_Up.mp3:system/media/audio/alarms/Solo_Up.mp3 \
	$(LOCAL_PATH)/alarms/mp3/Topaz.mp3:system/media/audio/alarms/Topaz.mp3 \
    $(LOCAL_PATH)/alarms/mp3/Turquoise.mp3:system/media/audio/alarms/Turquoise.mp3\
	$(LOCAL_PATH)/alarms/ogg/Beep.ogg:system/media/audio/alarms/Beep.ogg \
	$(LOCAL_PATH)/alarms/ogg/Clock.ogg:system/media/audio/alarms/Clock.ogg \
	$(LOCAL_PATH)/alarms/ogg/Osmium.ogg:system/media/audio/alarms/Osmium.ogg \
    $(LOCAL_PATH)/alarms/ogg/Buzzer.ogg:system/media/audio/alarms/Buzzer.ogg \
    $(LOCAL_PATH)/alarms/ogg/Charman.ogg:system/media/audio/alarms/Charman.ogg \
    $(LOCAL_PATH)/alarms/ogg/Classic.ogg:system/media/audio/alarms/Classic.ogg \
    $(LOCAL_PATH)/alarms/ogg/Flickering.ogg:system/media/audio/alarms/Flickering.ogg \
    $(LOCAL_PATH)/alarms/ogg/Good_Morning.ogg:system/media/audio/alarms/Good_Morning.ogg \
    $(LOCAL_PATH)/alarms/ogg/Helium.ogg:system/media/audio/alarms/Helium.ogg \
    $(LOCAL_PATH)/alarms/ogg/Lustre.ogg:system/media/audio/alarms/Lustre.ogg \
    $(LOCAL_PATH)/alarms/ogg/Morning.ogg:system/media/audio/alarms/Morning.ogg \
	$(LOCAL_PATH)/alarms/ogg/Open_Forest.ogg:system/media/audio/alarms/Open_Forest.ogg \
	$(LOCAL_PATH)/alarms/ogg/Scandium.ogg:system/media/audio/alarms/Scandium.ogg \
	$(LOCAL_PATH)/alarms/ogg/Twilight.ogg:system/media/audio/alarms/Twilight.ogg \
	$(LOCAL_PATH)/alarms/ogg/Ease_Up.ogg:system/media/audio/alarms/Ease_Up.ogg \
	$(LOCAL_PATH)/notifications/ogg/Ariel.ogg:system/media/audio/notifications/Ariel.ogg \
	$(LOCAL_PATH)/notifications/ogg/Attraction.ogg:system/media/audio/notifications/Attraction.ogg \
	$(LOCAL_PATH)/notifications/ogg/BentMallets.ogg:system/media/audio/notifications/BentMallets.ogg \
    $(LOCAL_PATH)/notifications/ogg/DingDong.ogg:system/media/audio/notifications/DingDong.ogg \
    $(LOCAL_PATH)/notifications/ogg/Castor.ogg:system/media/audio/notifications/Castor.ogg \
    $(LOCAL_PATH)/notifications/ogg/Clean.ogg:system/media/audio/notifications/Clean.ogg \
	$(LOCAL_PATH)/notifications/ogg/DingDong.ogg:system/media/audio/notifications/DingDong.ogg \
	$(LOCAL_PATH)/notifications/ogg/Europa.ogg:system/media/audio/notifications/Europa.ogg \
	$(LOCAL_PATH)/notifications/ogg/Heaven.ogg:system/media/audio/notifications/Heaven.ogg \
	$(LOCAL_PATH)/notifications/ogg/Lapetus.ogg:system/media/audio/notifications/Lapetus.ogg \
	$(LOCAL_PATH)/notifications/ogg/Liquids.ogg:system/media/audio/notifications/Liquids.ogg \
	$(LOCAL_PATH)/notifications/ogg/Message01.ogg:system/media/audio/notifications/Message01.ogg \
	$(LOCAL_PATH)/notifications/ogg/Message02.ogg:system/media/audio/notifications/Message02.ogg \
	$(LOCAL_PATH)/notifications/ogg/Message03.ogg:system/media/audio/notifications/Message03.ogg \
	$(LOCAL_PATH)/notifications/ogg/Message04.ogg:system/media/audio/notifications/Message04.ogg \
	$(LOCAL_PATH)/notifications/ogg/Message05.ogg:system/media/audio/notifications/Message05.ogg \
	$(LOCAL_PATH)/notifications/ogg/Notification.ogg:system/media/audio/notifications/Notification.ogg \
	$(LOCAL_PATH)/notifications/ogg/Tethys.ogg:system/media/audio/notifications/Tethys.ogg \
	$(LOCAL_PATH)/notifications/ogg/Titan.ogg:system/media/audio/notifications/Titan.ogg \
	$(LOCAL_PATH)/notifications/ogg/Rhea.ogg:system/media/audio/notifications/Rhea.ogg \
	$(LOCAL_PATH)/notifications/ogg/Elara.ogg:system/media/audio/notifications/Elara.ogg \
	$(LOCAL_PATH)/notifications/wav/SMS1.wav:system/media/audio/notifications/SMS1.wav \
	$(LOCAL_PATH)/notifications/wav/SMS2.wav:system/media/audio/notifications/SMS2.wav \
	$(LOCAL_PATH)/notifications/wav/SMS3.wav:system/media/audio/notifications/SMS3.wav \
	$(LOCAL_PATH)/notifications/wav/SMS4.wav:system/media/audio/notifications/SMS4.wav \
	$(LOCAL_PATH)/notifications/mp3/Airport.mp3:system/media/audio/notifications/Airport.mp3 \
	$(LOCAL_PATH)/notifications/mp3/SMS_Tone.mp3:system/media/audio/notifications/SMS_Tone.mp3 \
	$(LOCAL_PATH)/ringtones/ogg/Amber.ogg:system/media/audio/ringtones/Amber.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Beat_Plucker.ogg:system/media/audio/ringtones/Beat_Plucker.ogg \
    $(LOCAL_PATH)/ringtones/ogg/Beyond_Star.ogg:system/media/audio/ringtones/Beyond_Star.ogg \
    $(LOCAL_PATH)/ringtones/ogg/Birds_Flute.ogg:system/media/audio/ringtones/Birds_Flute.ogg \
    $(LOCAL_PATH)/ringtones/ogg/Brightness_Beats.ogg:system/media/audio/ringtones/Brightness_Beats.ogg \
    $(LOCAL_PATH)/ringtones/ogg/Callisto.ogg:system/media/audio/ringtones/Callisto.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Champagne.ogg:system/media/audio/ringtones/Champagne.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Corning_Star.ogg:system/media/audio/ringtones/Corning_Star.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Digital_Ring.ogg:system/media/audio/ringtones/Digital_Ring.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Drops.ogg:system/media/audio/ringtones/Drops.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Echo.ogg:system/media/audio/ringtones/Echo.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Electronic.ogg:system/media/audio/ringtones/Electronic.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Enthusiastic.ogg:system/media/audio/ringtones/Enthusiastic.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Exciting.ogg:system/media/audio/ringtones/Exciting.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Exotic.ogg:system/media/audio/ringtones/Exotic.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Friendly_Ghost.ogg:system/media/audio/ringtones/Friendly_Ghost.ogg \
	$(LOCAL_PATH)/ringtones/ogg/FunTime.ogg:system/media/audio/ringtones/FunTime.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Gimme_Town.ogg:system/media/audio/ringtones/Gimme_Town.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Harmony.ogg:system/media/audio/ringtones/Harmony.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Harp_Bell.ogg:system/media/audio/ringtones/Harp_Bell.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Ice_World.ogg:system/media/audio/ringtones/Ice_World.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Joyful_Dolls.ogg:system/media/audio/ringtones/Joyful_Dolls.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Kuma.ogg:system/media/audio/ringtones/Kuma.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Little_Joy.ogg:system/media/audio/ringtones/Little_Joy.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Luna.ogg:system/media/audio/ringtones/Luna.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Music_Box.ogg:system/media/audio/ringtones/Music_Box.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Oberon.ogg:system/media/audio/ringtones/Oberon.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Orange.ogg:system/media/audio/ringtones/Orange.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Organ_Dub.ogg:system/media/audio/ringtones/Organ_Dub.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Phobos.ogg:system/media/audio/ringtones/Phobos.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Radio_Groove.ogg:system/media/audio/ringtones/Radio_Groove.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Rhythm.ogg:system/media/audio/ringtones/Rhythm.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Ringtone_Pro.ogg:system/media/audio/ringtones/Ringtone_Pro.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Robot_Envy.ogg:system/media/audio/ringtones/Robot_Envy.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Sail.ogg:system/media/audio/ringtones/Sail.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Sceptrum.ogg:system/media/audio/ringtones/Sceptrum.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Sunshine.ogg:system/media/audio/ringtones/Sunshine.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Synth.ogg:system/media/audio/ringtones/Synth.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Themos.ogg:system/media/audio/ringtones/Themos.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Triton.ogg:system/media/audio/ringtones/Triton.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Twirl_Away.ogg:system/media/audio/ringtones/Twirl_Away.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Umbriel.ogg:system/media/audio/ringtones/Umbriel.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Vivacious_Clang.ogg:system/media/audio/ringtones/Vivacious_Clang.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Voice.ogg:system/media/audio/ringtones/Voice.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Wooden.ogg:system/media/audio/ringtones/Wooden.ogg \
	$(LOCAL_PATH)/ringtones/ogg/XtremeTone.ogg:system/media/audio/ringtones/XtremeTone.ogg \
	$(LOCAL_PATH)/ringtones/ogg/Xylophone.ogg:system/media/audio/ringtones/Xylophone.ogg \
	$(LOCAL_PATH)/ringtones/wav/Aktara.wav:system/media/audio/ringtones/Aktara.wav \
	$(LOCAL_PATH)/ringtones/wav/Electric_Piano.wav:system/media/audio/ringtones/Electric_Piano.wav \
	$(LOCAL_PATH)/ringtones/wav/Guitar.wav:system/media/audio/ringtones/ringtonesGuitar.wav \
	$(LOCAL_PATH)/ringtones/wav/Short01.wav:system/media/audio/ringtones/Short01.wav \
	$(LOCAL_PATH)/ringtones/wav/Short02.wav:system/media/audio/ringtones/Short02.wav \
	$(LOCAL_PATH)/ringtones/wav/Short03.wav:system/media/audio/ringtones/Short03.wav \
	$(LOCAL_PATH)/ringtones/wav/Short04.wav:system/media/audio/ringtones/Short04.wav \
	$(LOCAL_PATH)/ringtones/wav/Vocal.wav:system/media/audio/ringtones/Vocal.wav \
	$(LOCAL_PATH)/ringtones/wav/Rong_Master.wav:system/media/audio/ringtones/Rong_Master.wav \
	$(LOCAL_PATH)/ringtones/mp3/Banshi_Fusion.mp3:system/media/audio/ringtones/Banshi_Fusion.mp3 \
	$(LOCAL_PATH)/ringtones/mp3/Banshi.mp3:system/media/audio/ringtones/Banshi.mp3 \
	$(LOCAL_PATH)/ringtones/mp3/Humor.mp3:system/media/audio/ringtones/Humor.mp3 \
	$(LOCAL_PATH)/ringtones/mp3/Mobile_Guitar.mp3:system/media/audio/ringtones/Mobile_Guitar.mp3 \
	$(LOCAL_PATH)/ringtones/mp3/Rain_Drops.mp3:system/media/audio/ringtones/Rain_Drops.mp3 \
	$(LOCAL_PATH)/ringtones/mp3/Splash.mp3:system/media/audio/ringtones/Splash.mp3 \
	$(LOCAL_PATH)/ringtones/mp3/Ultramarine.mp3:system/media/audio/ringtones/Ultramarine.mp3</span></strong>

删除之前的全部系统铃声,或者取消预编译,在编译命令前添加#号即可,注意加了#前的那个语句最后面需要去掉 \ 符号,否则后面的都会被注释掉了

make clean;make -jxx 工程,给错如下错误提示:

<strong><span style="color:#3366ff;">frameworks/base/data/sounds/Audio.mk:62: *** commands commence before first target.  Stop.

#### make failed to build some targets  ####</span></strong>
我详细的检查自己写的mk之后,发现没有任何路径或者其他明显错误,于是考虑是不是格式问题

使用命令检查mk文件格式是否合法:

<strong><span style="color:#3366ff;">$vi frameworks\base\data\sounds\Audio.mk</span></strong>
发现确实存在格式错误:



然后进行正确的格式处理:

Android系统之路(初识MTK) ------ make update-api长按Power键添加Reboot项/内置默认Ringtone/SMS/Notification/Alarm删除系统铃声_第5张图片

修改默认的铃声:

通知和铃声:build\target\product\core_base.mk

<strong><span style="color:#3366ff;">PRODUCT_PROPERTY_OVERRIDES := \
    ro.config.notification_sound=Rong Master.wav \
    ro.config.alarm_alert=Osmium.ogg</span></strong>
来电、通知、sms:build\target\product\full_base.mk
<strong><span style="color:#3366ff;"># Additional settings used in all AOSP builds
PRODUCT_PROPERTY_OVERRIDES := \
    ro.config.ringtone=Rong_Master.wav \
    ro.config.notification_sound=Elara.ogg\
    ro.config.sms_sound=Reha.ogg
# Put en_US first in the list, so make it default.</span></strong>

修改系统默认音量:
frameworks\base\media\java\android\media\AudioManager

修改对应的默认值数组即可!

make clean;make -jxx 工程,烧录新的固件,即可看到效果,谢谢观博

你可能感兴趣的:(Make,内置铃声,update-api)