前面从 framework层控制和 实现 led 提醒, APP 层面其实可以的 , 源码环境下开发系统界别app
static String RED_LED_DEV = "/sys/class/leds/red/brightness";
static String GREEN_LED_DEV = "/sys/class/leds/green/brightness";
static String BLUE_LED_DEV = "/sys/class/leds/blue/brightness";
or more
//根据驱动而定
//static String RED_LED_DEV = "/sys/class/leds/red/blink";
//static String GREEN_LED_DEV = "/sys/class/leds/green/blink";
//static String BLUE_LED_DEV = "/sys/class/leds/blue/blink";
or
0 - 255
/android/frameworks/base/core/java/android/app/
INotificationManager.aidl
/frameworks/base/services/core/java/com/android/server/notification/NotificationManagerService.java
private final IBinder mService = new INotificationManager.Stub() {
// 还有炒鸡多方法
....
....
/**
* System-only API for getting a list of current (i.e. not cleared) notifications.
*
* Requires ACCESS_NOTIFICATIONS which is signature|system.
* @returns A list of all the notifications, in natural order.
*/
@Override
public StatusBarNotification[] getActiveNotifications(String callingPkg) {
// enforce() will ensure the calling uid has the correct permission
getContext().enforceCallingOrSelfPermission(
android.Manifest.permission.ACCESS_NOTIFICATIONS,
"NotificationManagerService.getActiveNotifications");
StatusBarNotification[] tmp = null;
int uid = Binder.getCallingUid();
// noteOp will check to make sure the callingPkg matches the uid
if (mAppOps.noteOpNoThrow(AppOpsManager.OP_ACCESS_NOTIFICATIONS, uid, callingPkg)
== AppOpsManager.MODE_ALLOWED) {
synchronized (mNotificationList) {
tmp = new StatusBarNotification[mNotificationList.size()];
final int N = mNotificationList.size();
for (int i=0; ireturn tmp;
}
/**
* Public API for getting a list of current notifications for the calling package/uid.
*
* @returns A list of all the package's notifications, in natural order.
*/
@Override
public ParceledListSlice getAppActiveNotifications(String pkg,
int incomingUserId) {
checkCallerIsSystemOrSameApp(pkg);
int userId = ActivityManager.handleIncomingUser(Binder.getCallingPid(),
Binder.getCallingUid(), incomingUserId, true, false,
"getAppActiveNotifications", pkg);
final int N = mNotificationList.size();
final ArrayList list = new ArrayList(N);
synchronized (mNotificationList) {
for (int i = 0; i < N; i++) {
final StatusBarNotification sbn = mNotificationList.get(i).sbn;
if (sbn.getPackageName().equals(pkg) && sbn.getUserId() == userId) {
// We could pass back a cloneLight() but clients might get confused and
// try to send this thing back to notify() again, which would not work
// very well.
final StatusBarNotification sbnOut = new StatusBarNotification(
sbn.getPackageName(),
sbn.getOpPkg(),
sbn.getId(), sbn.getTag(), sbn.getUid(), sbn.getInitialPid(),
0, // hide score from apps
sbn.getNotification().clone(),
sbn.getUser(), sbn.getPostTime());
list.add(sbnOut);
}
}
}
}
android/frameworks/base/core/java/android/service/notification/NotificationListenerService.java
import android.app.INotificationManager;
private INotificationManager mNoMan;
private final INotificationManager getNotificationInterface() {
if (mNoMan == null) {
mNoMan = INotificationManager.Stub.asInterface(
ServiceManager.getService(Context.NOTIFICATION_SERVICE));
}
return mNoMan;
}
public final void cancelNotification(String pkg, String tag, int id) {
if (!isBound()) return;
try {
getNotificationInterface().cancelNotificationFromListener(
mWrapper, pkg, tag, id);
} catch (android.os.RemoteException ex) {
Log.v(TAG, "Unable to contact notification manager", ex);
}
}
@SystemApi
public StatusBarNotification[] getActiveNotifications(String[] keys, int trim) {
if (!isBound())
return null;
try {
ParceledListSlice parceledList = getNotificationInterface()
.getActiveNotificationsFromListener(mWrapper, keys, trim);
List list = parceledList.getList();
ArrayList corruptNotifications = null;
int N = list.size();
for (int i = 0; i < N; i++) {
StatusBarNotification sbn = list.get(i);
Notification notification = sbn.getNotification();
try {
Builder.rebuild(getContext(), notification);
// convert icon metadata to legacy format for older clients
createLegacyIconExtras(notification);
} catch (IllegalArgumentException e) {
if (corruptNotifications == null) {
corruptNotifications = new ArrayList<>(N);
}
corruptNotifications.add(sbn);
Log.w(TAG, "onNotificationPosted: can't rebuild notification from " +
sbn.getPackageName());
}
}
if (corruptNotifications != null) {
list.removeAll(corruptNotifications);
}
return list.toArray(new StatusBarNotification[list.size()]);
} catch (android.os.RemoteException ex) {
Log.v(TAG, "Unable to contact notification manager", ex);
}
return null;
}
/Settings/src/com/android/settings/notification/NotificationStation.java
private NotificationListenerService mListener = new NotificationListenerService() {
@Override
public void onNotificationPosted(StatusBarNotification notification) {
logd("onNotificationPosted: %s", notification);
final Handler h = getListView().getHandler();
h.removeCallbacks(mRefreshListRunnable);
h.postDelayed(mRefreshListRunnable, 100);
}
@Override
public void onNotificationRemoved(StatusBarNotification notification) {
final Handler h = getListView().getHandler();
h.removeCallbacks(mRefreshListRunnable);
h.postDelayed(mRefreshListRunnable, 100);
}
};
........
........
mContext = activity;
mPm = mContext.getPackageManager();
mNoMan = INotificationManager.Stub.asInterface(
ServiceManager.getService(Context.NOTIFICATION_SERVICE));
try {
mListener.registerAsSystemService(mContext, new ComponentName(mContext.getPackageName(),
this.getClass().getCanonicalName()), ActivityManager.getCurrentUser());
} catch (RemoteException e) {
Log.e(TAG, "Cannot register listener", e);
}
private List loadNotifications() {
final int currentUserId = ActivityManager.getCurrentUser();
try {
/** 调用 getActiveNotifications提供数据 **/
StatusBarNotification[] active = mNoMan.getActiveNotifications(
mContext.getPackageName());
StatusBarNotification[] dismissed = mNoMan.getHistoricalNotifications(
mContext.getPackageName(), 50);
List list
= new ArrayList(active.length + dismissed.length);
for (StatusBarNotification[] resultset
: new StatusBarNotification[][] { active, dismissed }) {
for (StatusBarNotification sbn : resultset) {
final HistoricalNotificationInfo info = new HistoricalNotificationInfo();
info.pkg = sbn.getPackageName();
info.user = sbn.getUserId();
info.icon = loadIconDrawable(info.pkg, info.user, sbn.getNotification().icon);
info.pkgicon = loadPackageIconDrawable(info.pkg, info.user);
info.pkgname = loadPackageName(info.pkg);
if (sbn.getNotification().extras != null) {
info.title = sbn.getNotification().extras.getString(
Notification.EXTRA_TITLE);
if (info.title == null || "".equals(info.title)) {
info.title = sbn.getNotification().extras.getString(
Notification.EXTRA_TEXT);
}
}
if (info.title == null || "".equals(info.title)) {
info.title = sbn.getNotification().tickerText;
}
// still nothing? come on, give us something!
if (info.title == null || "".equals(info.title)) {
info.title = info.pkgname;
}
info.timestamp = sbn.getPostTime();
info.priority = sbn.getNotification().priority;
logd(" [%d] %s: %s", info.timestamp, info.pkg, info.title);
info.active = (resultset == active);
if (info.user == UserHandle.USER_ALL
|| info.user == currentUserId) {
list.add(info);
}
}
}
return list;
} catch (RemoteException e) {
Log.e(TAG, "Cannot load Notifications: ", e);
}
return null;
}