OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.webapk.shell_apk; | 5 package org.chromium.webapk.shell_apk; |
6 | 6 |
7 import android.app.Service; | 7 import android.app.Service; |
8 import android.content.Context; | 8 import android.content.Context; |
9 import android.content.Intent; | 9 import android.content.Intent; |
10 import android.os.IBinder; | 10 import android.os.IBinder; |
11 import android.util.Log; | 11 import android.util.Log; |
12 | 12 |
| 13 import java.lang.reflect.InvocationTargetException; |
13 import java.lang.reflect.Method; | 14 import java.lang.reflect.Method; |
14 | 15 |
15 /** | 16 /** |
16 * Child process service hosted by WebAPKs. This class uses Chrome's ClassLoader
to create a | 17 * Child process service hosted by WebAPKs. This class uses Chrome's ClassLoader
to create a |
17 * {@link ChildProcessServiceImpl} object which loads Chrome's native libraries,
initializes JNI | 18 * {@link ChildProcessServiceImpl} object which loads Chrome's native libraries,
initializes JNI |
18 * and creates the renderer. | 19 * and creates the renderer. |
19 */ | 20 */ |
20 public class WebApkSandboxedProcessService extends Service { | 21 public class WebApkSandboxedProcessService extends Service { |
21 // Note: the {@link CHILD_PROCESS_SERVICE_IMPL_CLASS_NAME} must sync with th
e class name | 22 // Note: the {@link CHILD_PROCESS_SERVICE_IMPL_CLASS_NAME} must sync with th
e class name |
22 // of Chrome's {@link ChildProcessServiceImpl}. | 23 // of Chrome's {@link ChildProcessServiceImpl}. |
(...skipping 26 matching lines...) Expand all Loading... |
49 } | 50 } |
50 | 51 |
51 @Override | 52 @Override |
52 public IBinder onBind(Intent intent) { | 53 public IBinder onBind(Intent intent) { |
53 // We call stopSelf() to request that this service be stopped as soon as
the client | 54 // We call stopSelf() to request that this service be stopped as soon as
the client |
54 // unbinds. Otherwise the system may keep it around and available for a
reconnect. The | 55 // unbinds. Otherwise the system may keep it around and available for a
reconnect. The |
55 // child processes do not currently support reconnect; they must be init
ialized from | 56 // child processes do not currently support reconnect; they must be init
ialized from |
56 // scratch every time. | 57 // scratch every time. |
57 stopSelf(); | 58 stopSelf(); |
58 try { | 59 try { |
59 Method bindMethod = mChildProcessServiceImplClass.getMethod( | 60 Method bindMethod = |
60 "bind", Intent.class, int.class); | 61 mChildProcessServiceImplClass.getMethod("bind", Intent.class
, int.class); |
61 int hostBrowserUid = WebApkUtils.getHostBrowserUid(this); | 62 int hostBrowserUid = WebApkUtils.getHostBrowserUid(this); |
62 assert hostBrowserUid >= 0; | 63 assert hostBrowserUid >= 0; |
63 return (IBinder) bindMethod.invoke( | 64 return (IBinder) bindMethod.invoke( |
64 mChildProcessServiceImplInstance, intent, hostBrowserUid); | 65 mChildProcessServiceImplInstance, intent, hostBrowserUid); |
65 } catch (Exception e) { | 66 } catch (NoSuchMethodException | IllegalAccessException | InvocationTarg
etException e) { |
66 Log.v(TAG, "Unable to bind to the WebApkSandboxedProcessService.", e
); | 67 throw new RuntimeException(e); |
67 } | 68 } |
68 return null; | |
69 } | 69 } |
70 | 70 |
71 @Override | 71 @Override |
72 public void onDestroy() { | 72 public void onDestroy() { |
73 super.onDestroy(); | 73 super.onDestroy(); |
74 try { | 74 try { |
75 Method destroyMethod = mChildProcessServiceImplClass.getMethod("dest
roy"); | 75 Method destroyMethod = mChildProcessServiceImplClass.getMethod("dest
roy"); |
76 destroyMethod.invoke(mChildProcessServiceImplInstance); | 76 destroyMethod.invoke(mChildProcessServiceImplInstance); |
77 } catch (Exception e) { | 77 } catch (Exception e) { |
78 Log.v(TAG, "Unable to destroy the WebApkSandboxedProcessService.", e
); | 78 Log.v(TAG, "Unable to destroy the WebApkSandboxedProcessService.", e
); |
79 } | 79 } |
80 } | 80 } |
81 } | 81 } |
OLD | NEW |