Android rom Development: HDMI monitor state can realize the control box of the network?

Happy New Year! This year set a small goal: academy, a blog update at least monthly.

Departure departure!
Here Insert Picture Description

============================= gorgeous dividing line ================ =============

2019 first blog, turned out to be a record needs a little egg pain ... the
Here Insert Picture Description
problem scenario: Internet traffic in limited circumstances, in order to save traffic, after the TV standby or turned off, the box automatically disconnected, or turned on the TV after wake , the box automatically restore the network.
(Limited traffic you what box ......)

For Android box, whether it is TV standby / wake-up, power on / off, or plug the HDMI cable, triggers broadcast "android.intent.action.HDMI_PLUGGED", and the broadcast will carry a key for the "state" Boolean flag value is used to HDMI equipment is connected, true for the connection, false unconnected.

Network Control logic cassette can be placed framework layer, it may be apk layer.

wifi control, direct calls setWifiEnabled WifiManager interfaces provided. WifiManager not hidden class, can be called directly and in the framework apk layer.

Controlling the wired network, and the need to use ServiceManager INetworkManagementService. Both classes are hidden class, the framework can be called directly, reflecting the need to call in the apk which, relatively speaking, would be more troublesome.

Optimal manner, on the service framework layer processing, such as PowerManagerService.

So, we have the following code:
Here Insert Picture Description

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction("android.intent.action.HDMI_PLUGGED");
    mContext.registerReceiver(new HdmiStateBroadcastReceiver(), intentFilter);
 
private final class HdmiStateBroadcastReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d(TAG, "forlan debug action is " + intent.getAction() + " hdmi state is " + intent.getBooleanExtra("state", false));
        if (intent.getAction() != null) {
            IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE);
            INetworkManagementService nMService = INetworkManagementService.Stub.asInterface(b);
            WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
            try {
                nMService.setInterfaceDown("eth0");
                wifiManager.setWifiEnabled(intent.getBooleanExtra("state", false));
                if (intent.getBooleanExtra("state", false)) {
                    nMService.setInterfaceUp("eth0");
                }
            } catch (RemoteException e) {
                Log.e(TAG, "Error upping interface eth0: " + e);
            }
        }
    }
};

Avoid taking cycle timer value read node hdmi way, consumption performance.

==================== =============== 2019.1.11 update
Here Insert Picture Description
after using a different TV, find support hdmi cec and does not support hdmi cec TV, the number of transmissions broadcast will be different, and even support hdmi cec different models of the same brand of TV, the number of broadcasts sent is not the same. Do not tell me what to take timer loop reads hdmi node values, support hdmi cec TV, read hdmi node value or 1 after the shutdown. In this case not only consumption performance is not accurate.

Naturally, it is several attempts to modify the code still can not be unified with a different logic to determine whether TV power on / off / standby / wake, so in fact this demand is not achieved, the principle does not work! ! Shouted out: fail to realize the principle, not the ability to question the old lady! What could be more straightforward than this it? !
Here Insert Picture Description
It is a pit. 2019 The first step on.

Published 42 original articles · won praise 24 · views 60000 +

Guess you like

Origin blog.csdn.net/u010725171/article/details/85697936
Recommended