import exynos 7570 bsp
[GitHub/LineageOS/android_hardware_samsung_slsi_exynos7580.git] / mobicore / rootpa / Code / Android / app / src / com / gd / mobicore / pa / service / OemService.java
1 /*
2 * Copyright (c) 2013 TRUSTONIC LIMITED
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
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.
14 *
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.
18 *
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.
30 */
31
32 package com.gd.mobicore.pa.service;
33
34 import android.app.Service;
35 import android.content.Intent;
36 import android.os.IBinder;
37 import android.os.Bundle;
38
39 import java.util.Random;
40
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;
49
50 public class OemService extends BaseService {
51 private static final String TAG = "RootPA-J";
52
53 private final RootPAOemIfc.Stub mBinder = new ServiceIfc();
54 private static final int OEM_UID_FOR_LOCK=0x33330000;
55
56 private class ServiceIfc extends RootPAOemIfc.Stub {
57 public ServiceIfc(){
58 super();
59 }
60
61 private CommonPAWrapper commonPAWrapper(){
62 return OemService.this.commonPAWrapper();
63 }
64
65 public CommandResult unregisterRootContainer(){
66 Log.d(TAG,">>RootPAServiceIfc.Stub.unregisterRootContainer");
67
68 int tmpSuid=OEM_UID_FOR_LOCK+new Random().nextInt(); // this may override the uid used in lock, which means it will not be
69
70 if(!OemService.this.acquireLock(tmpSuid, false).isOk()){
71 return new CommandResult(CommandResult.ROOTPA_ERROR_LOCK);
72 }
73
74 doProvisioningLockSuid_=tmpSuid;
75 Log.d(TAG,"RootPAServiceIfc.Stub.unregisterRootContainer calling JNI");
76
77 int ret=CommandResult.ROOTPA_OK;
78
79 try{
80 setupProxy();
81 ret=commonPAWrapper().unregisterRootContainer(se_);
82 }catch(Exception e){
83 Log.e(TAG,"CommonPAWrapper().unregisterRootContainer exception: ", e);
84 ret=CommandResult.ROOTPA_ERROR_INTERNAL;
85 }
86
87 CommandResult res=OemService.this.releaseLock(doProvisioningLockSuid_, false);
88 if(!res.isOk()){
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
93 }
94
95 Log.d(TAG,"<<RootPAServiceIfc.Stub.unregisterRootContainer");
96 return new CommandResult(ret);
97 }
98
99 }
100
101 @Override
102 public void onCreate() {
103 Log.d(TAG,"Hello, OemService onCreate");
104 super.onCreate();
105 }
106
107 @Override
108 public void onLowMemory() {
109 Log.d(TAG,"OemService onLowMemory");
110 super.onLowMemory();
111 }
112
113 public void onDestroy(){
114 super.onDestroy();
115 Log.d(TAG,"OemService being destroyed");
116 }
117
118 @Override
119 public IBinder onBind(Intent intent){
120 try{
121 se_ = intent.getByteArrayExtra("SE");
122 }catch(Exception e){
123 Log.i(TAG,"OemService something wrong in the given ip "+e );
124 }
125
126 try{
127 Log.setLoggingLevel(intent.getIntExtra("LOG",0));
128 }catch(Exception e){
129 Log.i(TAG,"OemService something wrong in the given logging level "+e );
130 }
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_));
133 return mBinder;
134 }
135
136 @Override
137 public int onStartCommand(Intent i, int flags, int startid){
138 Log.d(TAG,"OemService starting");
139 return START_STICKY;
140 }
141 }
142
143