PA1 Specification
PA1 Specification
Programming Assignment 1
Introduction
In this assignment, you will write a simple messenger app on Android. The goal of this app is
simple: enabling two Android devices to send messages to each other. The purpose of this
assignment is to help you see if you have the right background for this course. If you can finish
this all by yourself without getting any help from others, then it is probably the case that you
have the right background. Please see for yourself!
So here we go!
The project requirements are below. You must follow everything below exactly. Otherwise, you
will get no point on this assignment. And when we say no point, we actually mean it :-)
1. There should be only one app that you develop and need to install for grading. If you just
use the project template and add your code there, you will be able to satisfy this
requirement.
2. When creating your new Android application project in Android Studio, use the following:
○ Application Name: SimpleMessenger
○ Project Name: SimpleMessenger
○ Package Name: edu.buffalo.cse.cse486586.simplemessenger
○ API level 21 19 as the minimum & target SDK.
○ If you just use the project template, you will be able to satisfy this requirement.
3. There should be only one text box on screen where a user of the device can write a text
message to the other device. If you just use the project template, you will satisfy this
requirement.
4. The other device should be able to display on screen what was received and vice versa.
The project template contains basic code for displaying messages on screen.
5. You need to use the Java Socket API.
6. All communication should be over TCP.
7. You can assume that the size of a message will never exceed 128 bytes (characters).
As mentioned above, the Android emulator environment is not flexible for networking among
multiple AVDs. Although set_redir.py enables networking among multiple AVDs, it is very
different from a typical networking setup. When you write your socket code, you have the
following restrictions:
● In your app, you can open only one server socket that listens on port 10000 regardless
of which AVD your app runs on.
● The app on avd0 can connect to the listening server socket of the app on avd1 by
connecting to <ip>:<port> == 10.0.2.2:11112.
● The app on avd1 can connect to the listening server socket of the app on avd0 by
connecting to <ip>:<port> == 10.0.2.2:11108.
● Your app knows which AVD it is running on via the following code snippet. If portStr is
“5554”, then it is avd0. If portStr is “5556”, then it is avd1:
TelephonyManager tel =
(TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
String portStr = tel.getLine1Number().substring(tel.getLine1Number().length() - 4);
● The project template already implements the above, but you are expected to understand
the code as this is critical for the rest of the programming assignments.
● This document explains the Android emulator networking environment in more detail.
● In general, set_redir.py creates an emulated, port-redirected network like this (VR stands
for Virtual Router):
Testing
We have testing programs to help you see how your code does with our grading criteria. If you
find any rough edge with the testing programs, please report it on Piazza so the teaching staff
can fix it. The instructions are the following:
1. Download a testing program for your platform. If your platform does not run it, please
report it on Piazza.
a. Windows: We’ve tested it on 64-bit Windows 8.
b. Linux: We’ve tested it on 64-bit Ubuntu 12.04.
c. OS X: We’ve tested it on 64-bit OS X 10.9 Mavericks.
2. Before you run the program, please make sure that you are running two AVDs (avd0 &
avd1). python run_avd.py 2 will do it.
3. Please also make sure that you have installed your SimpleMessenger on those two
AVDs.
4. Run the testing program from the command line.
5. At the end of the run, it will give you one of the three outputs.
a. No communication verified: if SimpleMessenger instances cannot communicate
with each other. This is 0 point.
b. One-way communication verified: if SimpleMessenger on avd0 can send a
message to SimpleMessenger on avd1. This is 2 points.
c. Two-way communication verified: if both AVDs can communicate with each
other. This is additional 3 points.
Submission
We use the CSE submit script. You need to use either “submit_cse486” or “submit_cse586”,
depending on your registration status. If you haven’t used it, the instructions on how to use it is
here: https://wiki.cse.buffalo.edu/services/content/submit-script
You need to submit one file described below. Once again, you must follow everything below
exactly. Otherwise, you will get no point on this assignment.
● Your entire Android Studio project source code tree zipped up in .zip: The name should
be SimpleMessenger.zip.
a. Never create your zip file from inside “SimpleMessenger” directory.
b. Instead, make sure to zip “SimpleMessenger” directory itself. This means that
you need to go to the directory that contains “SimpleMessenger” directory and
zip it from there.
c. Please do not use any other compression tool other than zip, i.e., no 7-Zip, no
RAR, etc.
Grading
This assignment is 5% of your final grade. The breakdown for this assignment is:
● 2%: if your messenger app can send one-way messages from avd0 to avd1.
● (additional) 3%: if your messenger app can send two-way messages between avd0 and
avd1.
Notes
● There is a cap on the number of AsyncTasks that can run at the same time, even when
you use THREAD_POOL_EXECUTOR. The limit is "roughly" 5. Thus, if you need to
create more than 5 AsyncTasks (roughly, once again), then you will have to use
something else like Thread. However, I really do not think that it is necessary to create
that many AsyncTasks for the PAs in this course. Thus, if your code doesn't work
because you hit the AsyncTask limit, then please think hard why you're creating that
many threads in the first place.
This document gives you more details on the limit and you might (or might not,
depending on your background) understand why I say it's "roughly" 5.
http://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.html
(Read "Core and maximum pool sizes.")
● For Windows users: In the past, it was discovered that sometimes you cannot run a
grader and Android Studio at the same time. As far as I know, this happens rarely, but
there is no guarantee that you will not encounter this issue. Thus, if you think that a
grader is not running properly and you don't know why, first try closing Android Studio
and run the grader.