Mobile Systems and Smartphone Security�(MOBISEC 2020)
Prof: Yanick Fratantonio�EURECOM
1
More on Key Android Aspects
More info on important Android aspects
2
More on Activity
3
Get replies from activities
Intent i = new Intent(...);
int requestCode = 400;
startActivityForResult(i, requestCode);
onCreate() {
Intent resInt = new Intent();
...
setResult(Activity.RESULT_OK, resInt);
finish();
}
4
A.X
B.Y
Get replies from activities
Intent i = new Intent(...);
int requestCode = 400;
startActivityForResult(i, requestCode);
onActivityResult(int requestCode, int resultCode, Intent data) {
// check requestCode and resultCode
...
}
onCreate() {
Intent resInt = new Intent();
...
setResult(Activity.RESULT_OK, resInt);
finish();
}
5
A.X
B.Y
Caller can use requestCode to distinguish replies from different requests
More on Service
6
Why not a problem for activities?�Chooser dialog!
Services: The Full Story
7
Background Service
8
Foreground Service
9
Bound Services (doc)
10
Three ways of implementing them
11
Inter-Process Services via Messengers
public IBinder onBind(Intent intent) {
mMessenger = new Messenger(new IncomingHandler(this));
return mMessenger.getBinder();
}
static class IncomingHandler extends Handler {
IncomingHandler(Context context) { ... }
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MSG_SAY_HELLO:
...
}
}
12
The service returns an Handler (wrapped in a Messenger)
Inter-Process Services via Messengers
private ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
mService = new Messenger(service);
mBound = true;
}
...
};
13
Inter-Process Services via Messengers
private ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
mService = new Messenger(service);
mBound = true;
}
...
};
bindService(new Intent(...), mConnection, Context.BIND_AUTO_CREATE);
14
Inter-Process Services via Messengers
private ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
mService = new Messenger(service);
mBound = true;
}
...
};
bindService(new Intent(...), mConnection, Context.BIND_AUTO_CREATE);
Message msg = Message.obtain(null, MessengerService.MSG_SAY_HELLO, 0, 0);
mService.send(msg);
15
Bound Services
16
Broadcast Intents and Receivers
17
Broadcast Receiver "registration"
MyReceiver customRec = new MyReceiver();�IntentFilter intFil = new IntentFilter("com.some.action");�registerReceiver(customRec, intFil);
18
More info on Bundles
19
More info on Bundles
20
Which app can do what?
PackageManager pm = context.getPackageManager();
List<ResolveInfo> list = pm.queryIntentServices(implicitIntent, 0);
ResolveInfo serviceInfo = list.get(0); // if any
ComponentName component = new ComponentName(� serviceInfo.serviceInfo.packageName,� serviceInfo.serviceInfo.name);
21