notification led

前面从 framework层控制和 实现 led 提醒, APP 层面其实可以的 , 源码环境下开发系统界别app

  1. selinxu 权限节点
  2. 应用层获取节点控制
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; i<N; i++) {
                        tmp[i] = mNotificationList.get(i).sbn;
                    }
                }
            }
            return 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<StatusBarNotification> 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<StatusBarNotification> list = new ArrayList<StatusBarNotification>(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<StatusBarNotification> parceledList = getNotificationInterface()
                    .getActiveNotificationsFromListener(mWrapper, keys, trim);
            List<StatusBarNotification> list = parceledList.getList();
            ArrayList<StatusBarNotification> 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<HistoricalNotificationInfo> loadNotifications() {
        final int currentUserId = ActivityManager.getCurrentUser();
        try {
  /** 调用 getActiveNotifications提供数据 **/
            StatusBarNotification[] active = mNoMan.getActiveNotifications(
                    mContext.getPackageName());
            StatusBarNotification[] dismissed = mNoMan.getHistoricalNotifications(
                    mContext.getPackageName(), 50);

            List<HistoricalNotificationInfo> list
                    = new ArrayList<HistoricalNotificationInfo>(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;
    }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

空白的泡

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值