1、android 静音与马达振动流程1,设置静音和振动静音和振动都属于来电后的动作.所以在设置静音和振动时都只是设置一些标识,并往数据库写入相应标识.文件:packages/apps/settings/src/com/android/settings/SoundAndDisplaySettings.javaprivate CheckBoxPreference mSilent;private CheckBoxPreference mVibrate;private void setRingerMode(boolean silent, boolean vibrate) if (silent) mAud
2、ioManager.setRingerMode(vibrate ? AudioManager.RINGER_MODE_VIBRATE :AudioManager.RINGER_MODE_SILENT); else mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);mAudioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER,vibrate ? AudioManager.VIBRATE_SETTING_ON: AudioManager.VIBRATE_SET
3、TING_OFF);public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) if (preference = mSilent | preference = mVibrate) setRingerMode(mSilent.isChecked(), mVibrate.isChecked();if (preference = mSilent) updateState(false);.静音和振动是复选框按钮,两个中有一个发生变化时调用 setRingerMode 对状态
4、进行设置;如下状态描术:RINGER_MODE_SILENT 静音,且无振动RINGER_MODE_VIBRATE 静音,但有振动RINGER_MODE_NORMAL 正常声音,振动开关由 setVibrateSetting 决定.铃响模式的设置是通过 mAudioManager(音频管理器) 来实现的.2 音频管理器服务mAudioManager 所在服务如下:文件: frameworks/base/media/java/android/media/AudioManager.javapublic static final int RINGER_MODE_SILENT = 0;public s
5、tatic final int RINGER_MODE_VIBRATE = 1;public static final int RINGER_MODE_NORMAL = 2;public void setRingerMode(int ringerMode) IAudioService service = getService();try service.setRingerMode(ringerMode); catch (RemoteException e) Log.e(TAG, “Dead object in setRingerMode“, e);将铃响模式值传给音频接口服务 IaudioSe
6、rvicepublic static final int VIBRATE_TYPE_RINGER = 0;public static final int VIBRATE_TYPE_NOTIFICATION = 1;public static final int VIBRATE_SETTING_OFF = 0;public static final int VIBRATE_SETTING_ON = 1;public static final int VIBRATE_SETTING_ONLY_SILENT = 2;public void setVibrateSetting(int vibrateT
7、yp , int vibrateSetting) IAudioService service = getService();try service.setVibrateSetting(vibrateType, vibrateSetting); catch (RemoteException e) Log.e(TAG, “Dead object in setVibrateSetting“, e);将振动类型和振动设置传给音频接口服务 IaudioService,IaudioService 的定义如下:frameworks/base/media/java/android/media/IAudioSe
8、rvice.aidlframeworks/base/media/java/android/media/AudioService.java文件: frameworks/base/media/java/android/media/AudioService.java文件: frameworks/base/core/java/android/provider/Settings.javapublic void setRingerMode(int ringerMode) synchronized (mSettingsLock) if (ringerMode != mRingerMode) setRinge
9、rModeInt(ringerMode, true);/ Send sticky broadcastbroadcastRingerMode();将对应模式下的音量写入数据库,并将该模式广播.public void setVibrateSetting(int vibrateType, int vibrateSetting) mVibrateSetting = getValueForVibrateSetting(mVibrateSetting, vibrateType, vibrateSetting);/ Broadcast changebroadcastVibrateSetting(vibrat
10、eType);/ Post message to set ringer mode (it in turn will post a message/ to persist)sendMsg(mAudioHandler, MSG_PERSIST_VIBRATE_SETTING, SHARED_MSG, SENDMSG_NOOP, 0, 0,null, 0);同样将振动模式写入数据库,并广播该模式.3 硬件服务文件:frameworks/base/services/java/com/android/server/HardwareService.java开始振动:public void vibrate(
11、long milliseconds, IBinder token) if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.VIBRATE)!= PackageManager.PERMISSION_GRANTED) throw new SecurityException(“Requires VIBRATE permission“);/ Were running in the system server so we cannot crash. Check for a/ timeout of 0 or negati
12、ve. This will ensure that a vibration has/ either a timeout of 0 or a non-null pattern.if (milliseconds dev, 在 sys/class/timed_output 子目录创建文件 enablestatic int create_timed_output_class(void)if (!timed_output_class) timed_output_class = class_create(THIS_MODULE, “timed_output“);if (IS_ERR(timed_outpu
13、t_class)return PTR_ERR(timed_output_class);atomic_set(return 0;int timed_output_dev_register(struct timed_output_dev *tdev)int ret;if (!tdev | !tdev-name | !tdev-enable | !tdev-get_time)return -EINVAL;ret = create_timed_output_class();if (ret index = atomic_inc_return(tdev-dev = device_create(timed_output_class, NULL,MKDEV(0, tdev-index), NULL, tdev-name);if (IS_ERR(tdev-dev)return PTR_ERR(tdev-dev);ret = device_create_file(tdev-dev, if (ret dev, tdev);tdev-state = 0;
Copyright © 2018-2021 Wenke99.com All rights reserved
工信部备案号:浙ICP备20026746号-2
公安局备案号:浙公网安备33038302330469号
本站为C2C交文档易平台,即用户上传的文档直接卖给下载用户,本站只是网络服务中间平台,所有原创文档下载所得归上传人所有,若您发现上传作品侵犯了您的权利,请立刻联系网站客服并提供证据,平台将在3个工作日内予以改正。