Study on the study of ANDROIDPN (iii) Source flow analysis

Source: Internet
Author: User

In the client, we find the program entry in the Androidmanifest.xml file, which is the following demoappactivity class ,

The main code in this class is as follows

ServiceManager ServiceManager = Newservicemanager (this);

Servicemanager.setnotificationicon (r.drawable.notification);

Servicemanager.startservice ();

Along the way, there is a call to the Xmppmanager class in the Notificationservice (Xmppmanager.connect ();), and the Xmppmanager class is the class that the client is more important, and there are several methods

public void Connect () {

LOG.D (LogTag, "Connect () ...");

Submitlogintask ();

}


private void Submitconnecttask () {

LOG.D (LogTag, "submitconnecttask () ...");

AddTask (New Connecttask ());

}


Private Voidsubmitregistertask () {

LOG.D (LogTag, "submitregistertask () ...");

Submitconnecttask ();

AddTask (New Registertask ());

}


Private Voidsubmitlogintask () {

LOG.D (LogTag, "submitlogintask () ...");

Submitregistertask ();

AddTask (New Logintask ());

}


There is a thread queue in the AddTask method, which adds connection, register, and login tasks in turn. Perform these tasks with the Runtask method

There are three internal classes in the Xmppmanager class, namely connection (Connecttask), registration (registertask), and login (Logintask) three thread classes.

The connection class is responsible for the connection to the server.


Register the class, using the UUID to generate unique username and password, and then save them in sharedpreferences

Final String newusername = Newrandomuuid ();

Final String newpassword = Newrandomuuid ();

.....

Editor editor = Sharedprefs.edit ();

Editor.putstring (Constants.xmpp_username, newusername);

Editor.putstring (Constants.xmpp_password, NewPassword);

Editor.commit ();

In the landing class, the first connection to the login, the client's information updated to the server, that is

Xmppmanager.getconnection (). Login (

Xmppmanager.getusername (),

Xmppmanager.getpassword (), xmpp_resource_name);

This operation may be performed several times until the server is actually updated.

The server will receive the message when the connection is executed.

On the service side, The class that accepts the message is the Packetrouter class under the router package (org.androidpn.server.xmpp.router), where the type of the message is parsed, and then the specific router is invoked, such as responding to the iqrouter of the login.

If it is a login (that is, the session obtained through a unique client ID is null), then the package is processed. The operation to process the message packet is performed under the Org.androidpn.server.xmpp.handler package. After the message packet is processed, the message packet is passed to the client in the connection class under the Org.androidpn.server.xmpp.net package that maintains the connection.

XMLWriter XmlSerializer = new XMLWriter (Newiobufferwriter (

Buffer, (Charsetencoder) Encoder.get ()),

Newoutputformat ());

Xmlserializer.write (Packet.getelement ());

Xmlserializer.flush ();

Buffer.flip ();

Iosession.write (buffer);


If the login fails, get this exception and re-login to connect until the login is successful.


The process of registering login is as follows, the following is how to send a message to the client on the server, how the client sends the message to the server, how the client receives the message from the server (the message received from the client on the server is already spoken at the following login)


On the server side of the Push Message page (form.jsp), is through the notification.do?action=send to jump backstage, then this background is which class, In Web. XML, we can see that interceptors are spring classes, which are managed by spring, so we can open the Dispatcher-servlet.xml spring configuration file and see

class= "Org.springframework.web.servlet.handler.SimpleUrlHandlerMapping" >

/index.do=filenamecontroller

/user.do=usercontroller

/session.do=sessioncontroller

/notification.do=notificationcontroller


notification.do Jump to the page is Notificationcontroller is Org.androidpn.server.console.controller.NotificationController This class

class= "Org.androidpn.server.console.controller.NotificationController" >


Open the Notificationcontroller class to find out that it was called Notificationmanager

if (Broadcast.equalsignorecase ("Y")) {

Notificationmanager.sendbroadcast (ApiKey, title, Message,uri);

} else {

Notificationmanager.sendnotifcationtouser (ApiKey, Username,title,

message, URI);

}


Along the way, you can find the class that eventually sends the message or the connection deliver method. And the middle of the process is to parse and generate the message operation


So the client how to accept the message, this class should be a listener, from the class name and the client in the process of follow-up, we can probably know is the Notificationpacketlistener class, in this class to get the value of each node, and then send a notification on the client


Then the client sends the message class is in which class, we can refer to the server to send the message of the class is where, yes, in the connection class, then we find in the client's connection class whether there is a class to send the message. Sure enough, there is a way to send messages sendpacket the xmppconection in this class under the Org.jivesoftware.smack package. We can get the connection through Xmppmanager.getconnection ().


This article is from the "Old GE Technology Learning" blog, please be sure to keep this source http://ptghb.blog.51cto.com/3902848/1665155

Study on the study of ANDROIDPN (iii) Source flow analysis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.