|
|
|
Modern Operating Systems by Herbert Bos and Andrew S. Tanenb...
Modern_Operating_Systems_by_Herbert_Bos_and_Andrew_S._Tanenbaum_4th_Ed.pdf
Showing 863-864 out of 1137
Modern Operating Systems by Herbert Bos and Andrew...
Modern_Operating_Systems_by_Herbert_Bos_and_Andrew_S._Tanenbaum_4th_Ed.pdf-M ODERN O PERATING S YSTEMS
Modern Operating Systems by Herbert...
Modern_Operating_Systems_by_Herbert_Bos_and_Andrew_S._Tanenbaum_4th_Ed.pdf-M ODERN O PERATING S YSTEMS
Page 863
832
CASE STUDY 1: UNIX, LINUX, AND ANDROID
CHAP. 10
2.
It can serve as a connection point for other applications or the system
to perform rich interaction with the application.
This can be used by
applications to provide secure APIs for other applications, such as to
perform image or audio processing, provide a text to speech, etc.
The example email manifest shown in Fig. 10-51 contains a service that is used
to perform synchronization of the user’s mailbox. A common implementation
would schedule the service to run at a regular interval, such as every 15 minutes,
starting
the service when it is time to run, and
stopping
itself when done.
This is a typical use of the first style of service, a long-running background op-
eration. Figure 10-57 shows the state of the system in this case, which is quite
simple. The activity manager has created a
ServiceRecord
to keep track of the ser-
vice, noting that it has been
started
, and thus created its
SyncService
instance in the
application’s process. While in this state the service is fully active (barring the en-
tire system going to sleep if not holding a wake lock) and free to do what it wants.
It is possible for the application’s process to go away while in this state, such as if
the process crashes, but the activity manager will continue to maintain its
Ser-
viceRecord
and can at that point decide to restart the service if desired.
Activity manager in system_server process
Email app process
SyncService
ServiceRecord
(SyncService)
STARTED
Figure 10-57.
Starting an application service.
To see how one can use a service as a connection point for interaction with
other applications, let us say that we want to extend our existing
SyncService
to
have an API that allows other applications to control its sync interval. We will
need to define an AIDL interface for this API,
like the one shown in Fig. 10-58.
package com.example.email
interface ISyncControl {
int getSyncInterval();
void setSyncInterval(int seconds);
}
Figure 10-58.
Interface for controlling a sync service’s sync interval.
To use this, another process can
bind
to our application service, getting access
to its interface. This creates a connection between the two applications, shown in
Fig. 10-59.
The steps of this process are:
Page 864
SEC. 10.8
ANDROID
833
1.
The client application tells the activity manager that it would like to
bind to the service.
2.
If the service is not already created, the activity manager creates it in
the service application’s process.
3. The service returns the
IBinder
for its interface back to the activity
manager, which now holds that
IBinder
in its
ServiceRecord
.
4.
Now that the activity manager has the service
IBinder
, it can be sent
back to the original client application.
5. The client application now having the service’s
IBinder
may proceed
to make any direct calls it would like on its interface.
Activity manager in system_server process
Email app process
2. Create
3. Return
4. Send
1. Bind
Client app process
5. Call service
SyncService
IBinder
IBinder
IBinder
IBinder
IBinder
ServiceRecord
(SyncService)
STOPPED
Figure 10-59.
Binding to an application service.
Receivers
A
receiver
is the recipient of (typically external) events that happen, generally
in the background and outside of normal user interaction.
Receivers conceptually
are the same as an application explicitly registering for a callback when something
interesting happens (an alarm goes off, data connectivity changes, etc), but do not
require that the application be running in order to receive the event.
The example email manifest shown in Fig. 10-51 contains a receiver for the
application to find out when the device’s storage becomes low in order for it to
stop synchronizing email (which may consume more storage).
When the device’s
storage becomes low, the system will send a
broadcast
with the low storage code,
to be delivered to all receivers interested in the event.
Figure 10-60 illustrates how such a broadcast is processed by the activity man-
ager in order to deliver it to interested receivers. It first asks the package manager
Ace your assessments! Get Better Grades
Browse thousands of Study Materials & Solutions from your Favorite Schools
Concordia University
Concordia_University
School:
Operating_Systems
Course:
Introducing Study Plan
Using AI Tools to Help you understand and remember your course concepts better and faster than any other resource.
Find the best videos to learn every concept in that course from Youtube and Tiktok without searching.
Save All Relavent Videos & Materials and access anytime and anywhere
Prepare Smart and Guarantee better grades
Students also viewed documents
lab 18.docx
lab_18.docx
Course
Course
3
Module5QuizSTA2023.d...
Module5QuizSTA2023.docx.docx
Course
Course
10
Week 7 Test Math302....
Week_7_Test_Math302.docx.docx
Course
Course
30
Chapter 1 Assigment ...
Chapter_1_Assigment_Questions.docx.docx
Course
Course
5
Week 4 tests.docx.do...
Week_4_tests.docx.docx
Course
Course
23
Week 6 tests.docx.do...
Week_6_tests.docx.docx
Course
Course
106