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.
33 // Wrapper class for common C part of the Root Provisioning Agent, the C
34 // files under Android/jni
37 package com
.gd
.mobicore
.pa
.jni
;
39 import com
.gd
.mobicore
.pa
.service
.Log
;
40 import android
.os
.Build
;
41 import android
.os
.Build
.VERSION
;
42 import android
.telephony
.TelephonyManager
;
43 import android
.content
.Context
;
45 import java
.util
.List
;
46 import com
.gd
.mobicore
.pa
.service
.BaseService
;
47 import com
.gd
.mobicore
.pa
.ifc
.CmpCommand
;
48 import com
.gd
.mobicore
.pa
.ifc
.CmpResponse
;
50 public class CommonPAWrapper
{
51 private static final String TAG
= "RootPA-J";
52 private BaseService service_
;
54 public CommonPAWrapper(BaseService service
){
56 Log
.d(TAG
,"CommonPAWrapper.java: constructor");
59 public native int openSession();
60 public native void closeSession();
61 public native int executeCmpCommands(int uid
, List
<CmpCommand
> commands
, List
<CmpResponse
> responses
);
62 public native int getVersion(byte[] productId
, List
<String
> keys
, List
<Integer
> values
);
63 public native int getSuid(byte[] suid
);
64 public native int isRootContainerRegistered(boolean[] result
);
65 public native int isSpContainerRegistered(int spid
, boolean[] result
);
66 public native int getSPContainerState(int spid
, int[] state
);
67 public native int getSPContainerStructure(int spid
, int[] ints
, byte[][] uuidArray
, int[] trustletStates
);
68 public native int doProvisioning(int uid
, int spid
, byte[] seAddress
);
69 public native int installTrustlet(int spid
,
76 int numberOfInstances
,
79 public native int unregisterRootContainer(byte[] seAddress
);
80 public native int storeTA(int spid
, byte[] uuid
, byte[] taBinary
);
81 public native void setEnvironmentVariable(byte[] variable
, byte[] value
);
84 Log
.d(TAG
,"CommonPAWrapper.java: static");
86 System
.loadLibrary("commonpawrapper");
87 } catch (Throwable e
) {
88 Log
.d(TAG
,"loading common wrapper failed, trying to load test");
89 System
.loadLibrary("commonpawrapper_test");
93 // callbacks from C code
95 public String
getFilesDirPath(){
96 Log
.d(TAG
,"CommonPAWrapper.getFilesDirPath");
97 return service_
.getFilesDirPath();
100 public void provisioningStateCallback(int state
, int ret
){
101 Log
.d(TAG
,"CommonPAWrapper.provisioningStateCallback");
102 service_
.provisioningStateCallback(state
, ret
);
105 private static final int IMEI_ESN_INDEX
=0;
106 private static final int MNO_INDEX
=1;
107 private static final int BRAND_INDEX
=2;
108 private static final int MANUFACTURER_INDEX
=3;
109 private static final int HARDWARE_INDEX
=4;
110 private static final int MODEL_INDEX
=5;
111 private static final int VERSION_INDEX
=6;
112 private static final int RESPONSE_ARRAY_SIZE
=7;
114 public String
[] getSystemInfo(){
115 Log
.d(TAG
,">>CommonPAWrapper.getSystemInfo");
116 String
[] response
= new String
[RESPONSE_ARRAY_SIZE
];
117 response
[IMEI_ESN_INDEX
]="";
118 response
[MNO_INDEX
]="";
119 response
[BRAND_INDEX
]=Build
.BRAND
;
120 response
[MANUFACTURER_INDEX
]=Build
.MANUFACTURER
;
121 response
[HARDWARE_INDEX
]=Build
.HARDWARE
;
122 response
[MODEL_INDEX
]=Build
.MODEL
;
123 response
[VERSION_INDEX
]=Build
.VERSION
.CODENAME
+" "+Build
.VERSION
.INCREMENTAL
+" "+Build
.VERSION
.RELEASE
+" "+Integer
.toString(Build
.VERSION
.SDK_INT
);
125 Log
.d(TAG
,"<<CommonPAWrapper.getSystemInfo "+response
[IMEI_ESN_INDEX
]+" "+response
[MANUFACTURER_INDEX
]+" "+response
[VERSION_INDEX
]);
130 public void trustletInstallCallback(byte[] trustlet
){
131 Log
.d(TAG
,">>CommonPAWrapper.trustletInstallCallback "+trustlet
.length
);
132 service_
.trustletInstallCallback(trustlet
);
133 Log
.d(TAG
,"<<CommonPAWrapper.trustletInstallCallback");