我正在尝试调用 samsung knox SDK 来访问 TIMA 密钥库。
但是,设备会引发以下异常:
Caused by: java.lang.SecurityException: uid 10207 does not have com.samsung.android.knox.permission.KNOX_TIMA_KEYSTORE.
at android.os.Parcel.createException(Parcel.java:1966)
at android.os.Parcel.readException(Parcel.java:1934)
at android.os.Parcel.readException(Parcel.java:1884)
at com.samsung.android.knox.keystore.ITimaKeystore$Stub$Proxy.enableTimaKeystore(ITimaKeystore.java:253)
at com.samsung.android.knox.keystore.TimaKeystore.enableTimaKeystore(TimaKeystore.java:123)
at com.samsung.knox.example.knoxsdk.MainActivity.enableKeystore(MainActivity.java:163)
at com.samsung.knox.example.knoxsdk.MainActivity.onRequestPermissionsResult(MainActivity.java:157)
at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:7957)
at android.app.Activity.dispatchActivityResult(Activity.java:7779)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4615)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4664)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:49)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1960)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7094)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)
我需要做什么才能使其工作?我正在研究三星 SM-A705FN,它确实有 knox
示例代码
private void enableTimaKeystore() {
activateLicense();
int checkKeystore = getApplicationContext().checkCallingOrSelfPermission(KNOX_KEYSTORE_PERMISSION);
int checkKeystorePerApp = getApplicationContext().checkCallingOrSelfPermission(KNOX_KEYSTORE_PERMISSION_PER_APP);
if (checkKeystore == PackageManager.PERMISSION_GRANTED) {
Toast.makeText(getApplicationContext(), KNOX_KEYSTORE_PERMISSION + " is granted", Toast.LENGTH_LONG).show();
enableKeystore();
} else if (checkKeystorePerApp == PackageManager.PERMISSION_GRANTED) {
Toast.makeText(getApplicationContext(), KNOX_KEYSTORE_PERMISSION_PER_APP + " is granted", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), KNOX_KEYSTORE_PERMISSION + " and " + KNOX_KEYSTORE_PERMISSION_PER_APP + " are not granted. You can't use TimaKeystorePerApp ", Toast.LENGTH_LONG).show();
requestPermissions(new String[]{KNOX_KEYSTORE_PERMISSION}, 100);
}
}
private void activateLicense() {
// Instantiate the EnterpriseLicenseManager class to use the activateLicense method
KnoxEnterpriseLicenseManager klmManager = KnoxEnterpriseLicenseManager.getInstance(this.getApplicationContext());
try {
// KPE License Activation TODO Add license key to Constants.java
klmManager.activateLicense(Constants.KPE_LICENSE_KEY);
mUtils.log(getResources().getString(R.string.activate_license_progress));
} catch (Exception e) {
mUtils.processException(e, TAG);
}
}
private void enableKeystore() {
/* get CCM Policy */
TimaKeystore mTimaKeyStorePolicyHandler = EnterpriseKnoxManager.getInstance(this).getTimaKeystorePolicy();
mTimaKeyStorePolicyHandler.enableTimaKeystore(true);
/* To enable TimaKeystore for all the apps on the device (both inside and outside container). */
boolean isEnabled = mTimaKeyStorePolicyHandler.isTimaKeystoreEnabled();
mUtils.log("is keystore enabled: " + isEnabled);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
enableKeystore();
}
和清单文件
<?xml version="1.0" encoding="utf-8"?>
<!-- Permissions TODO List permissions used by application -->
<uses-permission android:name="com.samsung.android.knox.permission.KNOX_HW_CONTROL" />
<uses-permission android:name="com.samsung.android.knox.permission.KNOX_TIMA_KEYSTORE" />
<uses-permission android:name="com.samsung.android.knox.permission.KNOX_KEYSTORE_PER_APP" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="com.samsung.knox.example.knoxsdk.MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- SampleAdminReceiver TODO Provide receiver for device admin receiver class -->
<receiver
android:name="com.samsung.knox.example.knoxsdk.SampleAdminReceiver"
android:description="@string/enterprise_device_admin_description"
android:label="@string/enterprise_device_admin"
android:permission="android.permission.BIND_DEVICE_ADMIN" >
<meta-data
android:name="android.app.device_admin"
android:resource="@xml/device_admin_receiver" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>
<!-- Activate License TODO Provide receiver for Knox license activation results -->
<receiver android:name="com.samsung.knox.example.knoxsdk.SampleLicenseReceiver" >
<intent-filter>
<action android:name="com.samsung.android.knox.intent.action.KNOX_LICENSE_STATUS" />
</intent-filter>
</receiver>
</application>