2 * Copyright (c) 2013 TRUSTONIC LIMITED
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the TRUSTONIC LIMITED nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 package com
.gd
.mobicore
.pa
.service
;
34 import android
.app
.Service
;
35 import android
.content
.Intent
;
36 import android
.os
.IBinder
;
37 import android
.os
.Bundle
;
39 import java
.util
.Random
;
41 import com
.gd
.mobicore
.pa
.jni
.CommonPAWrapper
;
42 import com
.gd
.mobicore
.pa
.ifc
.RootPAProvisioningIntents
;
43 import com
.gd
.mobicore
.pa
.ifc
.RootPADeveloperIfc
;
44 import com
.gd
.mobicore
.pa
.ifc
.RootPAOemIfc
;
45 import com
.gd
.mobicore
.pa
.ifc
.CommandResult
;
46 import com
.gd
.mobicore
.pa
.ifc
.BooleanResult
;
47 import com
.gd
.mobicore
.pa
.ifc
.TrustletContainer
;
48 import com
.gd
.mobicore
.pa
.ifc
.IfcVersion
;
50 public class OemService
extends BaseService
{
51 private static final String TAG
= "RootPA-J";
53 private final RootPAOemIfc
.Stub mBinder
= new ServiceIfc();
54 private static final int OEM_UID_FOR_LOCK
=0x33330000;
56 private class ServiceIfc
extends RootPAOemIfc
.Stub
{
61 private CommonPAWrapper
commonPAWrapper(){
62 return OemService
.this.commonPAWrapper();
65 public CommandResult
unregisterRootContainer(){
66 Log
.d(TAG
,">>RootPAServiceIfc.Stub.unregisterRootContainer");
68 int tmpSuid
=OEM_UID_FOR_LOCK
+new Random().nextInt(); // this may override the uid used in lock, which means it will not be
70 if(!OemService
.this.acquireLock(tmpSuid
, false).isOk()){
71 return new CommandResult(CommandResult
.ROOTPA_ERROR_LOCK
);
74 doProvisioningLockSuid_
=tmpSuid
;
75 Log
.d(TAG
,"RootPAServiceIfc.Stub.unregisterRootContainer calling JNI");
77 int ret
=CommandResult
.ROOTPA_OK
;
81 ret
=commonPAWrapper().unregisterRootContainer(se_
);
83 Log
.e(TAG
,"CommonPAWrapper().unregisterRootContainer exception: ", e
);
84 ret
=CommandResult
.ROOTPA_ERROR_INTERNAL
;
87 CommandResult res
=OemService
.this.releaseLock(doProvisioningLockSuid_
, false);
89 Log
.e(TAG
,"releasing lock failed, res: "+res
.result());
90 // this return code is not returned to the client since
91 // the command may have succeeded and there is just something wrong with the lock
92 // we leave it the the next command if the problem remains
95 Log
.d(TAG
,"<<RootPAServiceIfc.Stub.unregisterRootContainer");
96 return new CommandResult(ret
);
102 public void onCreate() {
103 Log
.d(TAG
,"Hello, OemService onCreate");
108 public void onLowMemory() {
109 Log
.d(TAG
,"OemService onLowMemory");
113 public void onDestroy(){
115 Log
.d(TAG
,"OemService being destroyed");
119 public IBinder
onBind(Intent intent
){
121 se_
= intent
.getByteArrayExtra("SE");
123 Log
.i(TAG
,"OemService something wrong in the given ip "+e
);
127 Log
.setLoggingLevel(intent
.getIntExtra("LOG",0));
129 Log
.i(TAG
,"OemService something wrong in the given logging level "+e
);
131 Log
.i(TAG
,"OemService binding, IfcVersion: " +IfcVersion
.ROOTPA_ANDROID_API_VERSION_MAJOR
+"."+IfcVersion
.ROOTPA_ANDROID_API_VERSION_MINOR
);
132 if(se_
!=null) Log
.d(TAG
,new String(se_
));
137 public int onStartCommand(Intent i
, int flags
, int startid
){
138 Log
.d(TAG
,"OemService starting");