Files
notes/docs/lectures/mdp/practice_tests.md
T

8.6 KiB
Raw Blame History

Practice Test

2018-19

Question 1

a)

Describe the concept of System on a Chip and Package-on-Package

  • System on a chip is where the chip is divided into multiple regions, each of which deals with a different task, and is built block by block from descriptions of separate parts.
  • Package-on-package is where different components are stacked on top of one another to save space

b)

Describe the concept of ARM big.LITTLE and ARM Thumb

  • The ARM processor contains a low-performance and a high-performance core. These two cores are architecturally consistent, so the system can switch between the two as appropriate for the task.
  • ARM Thumb is a 16-bit-long ARM instruction set; these Thumb instructions can run 2 instructions in parallel, as registers in the processor are 32 bits.

c)

Android applications run in an implementation of the Java virtual machine

i.

Java virtual machine (VM) is stack-based and the Dalvik VM is register-based. List an advantage and a disadvantage of the register-based VM compared to the stack-based VM.

Stack-based often has shorter instructions, whereas register-based has fewer instructions to execute and is optimised to use less space.

ii.

Describe the role of the Zygote process as part of Dalvik and how it aims to make efficient use of memory.

Zygote initialises all the processes that use core libraries, loads all Java and Android classes and creates the Android VM process.

iii.

Dalvik has been replaced by Android Runtime (ART) from Android version 5.0. Dalvik uses a trace-based just-in-time compiler. State the type of compiler that ART uses.

iv.

State an advantage and a disadvantage of ART over Dalvik.

d)

The Android operating system was developed based on Linux kernels. Describe three Android-specific modifications to the Linux kernel.

  1. Wake locks have been added to keep the phone awake in certain situations
  2. Binders were added to facilitate inter-process communication, so that apps can communicate with other apps
  3. ashmem was added for shared memory between apps
  4. oom was added to save memory resources when memory is low
  5. alarm manager was added to add alarm functionality and to wake the phone when necessary

Question 2

a)

The projected capacitive screens support multiple point touches. Explain the working principle behind the multiple touches

For multi-touch functionality, there is a grid of capacitance sensors. These are arranged in rows and columns, and when a finger is pressed against the glass, the sensors record a decrease in capacitance and register a touch.

If multiple sensors record a drop in capacitance, it is registered as multiple touches.

b)

Explain how a high-resolution touch can be achieved based on the grid of electrodes

High-resolution touch can be achieved without adding more sensors. When a touch is registered by one sensor, the surrounding sensors will register a smaller drop in capacitance. By summing these drops and taking the average, a more accurate location can be found.

c)

@Overrides
public boolean onTouchEvent(MotionEvent event) {
    int maskedAction = event.getActionMasked();
    
    switch (maskedAction)
    {
        case MotionEvent.ACTION_DOWN:
            int finger1 = event.getPointerID();
            float f1x_start = event.getX(finger1);
            float f1y_start = event.getY(finger1);
            break;
        case MotionEvent.ACTION_POINTER_DOWN:
            int finger2 = event.getPointerID();
            float f2x_start = event.getX(finger2);
            float f2y_start = event.getY(finger2);
            break;
        case MotionEvent.ACTION_MOVE:
            break;
        case MotionEvent.ACTION_UP:
            float f1x_end = event.getX(finger1);
            float f1y_end = event.getY(finger1);
            float f2x_end = event.getX(finger2);
            float f2y_end = event.getY(finger2);
    }
    
    init_ang = 180 - Math.arctan(f2x_start - f1x_start / 
                                f2y_start - f1y_start);
    
    end_ang = 180 - Math.arctan(f2x_end - f1x_end / 
                                f2y_end - f1y_end);
    
    rotation_ang = init_ang - end_ang  
}

Question 3

a)

State when it would be appropriate to use a Service component in an Android application, specifically contrasting to the creation of a new thread within an Activity.

When the task is long and needs to happen independently of the app.

b)

The Proxy design pattern is used to structure inter-process method invocation between a client and a remote service. In the context of an AIDL interface:

i.

Describe the role of the Proxy and Stub classes, providing the apparent use of each one, and describing how they make use of the system binder for communication.

ii.

Describe how the binder enables synchronous method calls between a client and a remote service

Binder is a kernel driver; this means it has access to kernel space in memory. When a client requests the binder driver, it uses a thread to speak to the service.

iii.

State how communication with a remote service could be optimised by modifying the AIDL interface definition.

c)

2016-17

Question 1

a)

A simple Android application consists of two Activity components. The first, MainActivity, contains a String and an Integer. It also displays a button that, when pressed, launches SecondActivity via an explicit Intent. The user launches the application, then presses the button, and then presses the back button.

i.

Describe the life-cycle calls that these two Activities would receive, and in what order they would receive them. You should illustrate your answer with a diagram of the Activity stack as it changes over time.

onCreate -> onStart -> onResume -> onPause -> onCreate -> onStart -> onResume -> onPause -> onResume 
ii.

When the user is interacting with SecondActivity, the system becomes low on memory and decides that it should remove MainActivity to free up memory. State how this changes your answer to part (i). Describe how MainActivity should maintain its internal state during this process.

onCreate -> onStart -> onResume -> onPause -> onCreate -> onStart -> onResume -> onDestroy

b)

An Activity can be started by a remote component using an implicit Intent. ==Describe== how an application could be integrated into a task using this method, and why it could be considered advantageous.

Question 3

a)

One of the major drains on the battery of a mobile device is the 3G radio. A badly written application uses a started Service that persists in memory and regularly polls a remote website for updates. Explain how this might cause an increased drain on the battery, and describe how you might restructure the application’s components to preserve battery life.

This would drain the battery as the service would continually use the 3G radio to poll the web server. To improve this, Work Manager should be used. Work Manager would allow time windows for this to happen, which are synchronised with the other apps needing 3G. This means 3G does not need to stay on all of the time.

  • The service might keep the phone awake
  • The question is about incorrectly doing stuff in the background

b)

Android applications run in an implementation of the Java virtual machine Dalvik, or more recently the Android Runtime (ART).

i.

Describe the role of the Zygote process as part of Dalvik and how it aims to make efficient use of memory.

Zygote initialises all core libraries and loads all Java and Android classes. When a user runs an application, it creates a copy of a reference to itself in a separate address space. This way, all applications can use the same shared memory.

ii.

State an advantage of ART over Dalvik.

  • Apps run faster; bytecode is already translated to machine code during installation
  • Reduces startup time of apps as native code is directly executed
  • Improves battery performance as it produces more optimised code

c)

The majority of modern Android devices make use of the ARM CPU core. State two advantages of using ARM in a mobile device, and describe one of the key differences of the RISC instruction set when compared to X86.

  1. An ARM chip consumes less power than an x86 chip; this is especially useful in battery-powered phones
  2. ARM chips are sold as a design and are more easily integrated onto a system on a chip, instead of buying a pre-bought Intel chip

The RISC instruction set aims to complete each instruction set in one FDE cycle, whereas x86 instructions can take many cycles