• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package android.seccomp.cts.app;
17 
18 import android.app.Service;
19 import android.content.Intent;
20 import android.os.Handler;
21 import android.os.IBinder;
22 import android.os.Message;
23 import android.os.Messenger;
24 import android.os.RemoteException;
25 import android.util.Log;
26 
27 public class IsolatedService extends Service {
28     static final String TAG = "IsolatedService";
29 
30     static final int MSG_GET_SECCOMP_RESULT = 1;
31 
32     static final int MSG_SECCOMP_RESULT = 2;
33     final Messenger mMessenger = new Messenger(new ServiceHandler());
34 
35     @Override
onBind(Intent intent)36     public IBinder onBind(Intent intent) {
37         return mMessenger.getBinder();
38     }
39 
40     static class ServiceHandler extends Handler {
41         @Override
handleMessage(Message msg)42         public void handleMessage(Message msg) {
43             switch (msg.what) {
44                 case (MSG_GET_SECCOMP_RESULT):
45                     int result = ZygotePreload.getSeccomptestResult() ? 1 : 0;
46                     try {
47                         msg.replyTo.send(Message.obtain(null, MSG_SECCOMP_RESULT, result, 0));
48                     } catch (RemoteException e) {
49                         Log.e(TAG, "Failed to send seccomp test result", e);
50                     }
51                     break;
52                 default:
53                     super.handleMessage(msg);
54             }
55         }
56     }
57 }
58