USB充电插拔与USB Debugging connect提示
在 packages/apps/Settings/src/com/android/settings/DevelopmentSettings.java 找到关于 USB Debug Enable 的代码:
Java代码
- Settings.Secure.putInt(getContentResolver(), Settings.Secure.ADB_ENABLED,0);
此文件中,将根据用户设置将其值保存到 Settings 数据库中。别处将根据其值动态变化做出相应动作
经搜索,在 frameworks/base/services/java/com/android/server/NotificationManagerService.java 中存在利用该值判断是否在状态栏中进行通知。代码如下:
别处将根据其值动态变化做出相应动作如状态栏消息提示。
Java代码
- void observe() {
- ContentResolver resolver = mContext.getContentResolver();
- resolver.registerContentObserver(Settings.Secure.getUriFor(
- Settings.Secure.ADB_ENABLED), false, this);
- update();
- }
- @Override public void onChange(boolean selfChange) {
- update();
- }
- public void update() {
- ContentResolver resolver = mContext.getContentResolver();
- mAdbEnabled = Settings.Secure.getInt(resolver,
- Settings.Secure.ADB_ENABLED, 0) !=0;
- updateAdbNotification();
- }
当激活时,在状态栏中给出通知提示:
C-sharp代码
- notificationManager.notify(
- com.android.internal.R.string.adb_active_notification_title,
- mAdbNotification);
通知的内容在资源字符串(英文)在字符串资源文件 frameworks/base/core/res/res/values/strings.xml 中,定义如下:
Xhtml代码