Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Using Android DevicePolicyManager with C++ Builder to install cert!!!


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 3 - Last Post: Oct 27, 2017 4:29 PM Last Post By: Ahmed Sayed
Ahmed Sayed

Posts: 173
Registered: 8/9/07
Using Android DevicePolicyManager with C++ Builder to install cert!!!  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 24, 2017 11:19 AM
Hi

I am trying to use Android DevicePolicyManager in c++
builder to install a self-signed root certificate in user store.

I have managed to export the DevicePolicyManager.pas
file from DevicePolicyManager.java file in Android SDK.

But whenever i try to use any function from
_di_JDevicePolicyManager interface i get run-time
error message "Invoke error: method not found."

"Invoke error: method not found."


I get this error when I call any of these methods

hasCaCertInstalled
installCaCert


//DevicePolicyManager.pas 
 
 
unit DevicePolicyManager;
 
interface
 
uses
  Androidapi.JNIBridge,
  Androidapi.JNI.GraphicsContentViewText,
  Androidapi.JNI.Java.Security,
  Androidapi.JNI.JavaUtil,
  Androidapi.JNI.JavaTypes,
  Androidapi.JNI.Net,
  Androidapi.JNI.Os;
 
type
// ===== Forward declarations =====
 
  JAccount = interface;//android.accounts.Account
  JDevicePolicyManager = interface;//android.app.admin.DevicePolicyManager
  JSystemUpdatePolicy = interface;//android.app.admin.SystemUpdatePolicy
//  JStringBuffer = interface;//java.lang.StringBuffer
//  JStringBuilder = interface;//java.lang.StringBuilder
 
// ===== Interface declarations =====
 
  JAccountClass = interface(JObjectClass)
    ['{94EE6861-F326-489F-8919-E20B39E3D9C1}']
    {class} function _GetCREATOR: JParcelable_Creator; cdecl;
    {class} function _Gettype: JString; cdecl;
    {class} function init(name: JString; type_: JString): JAccount; cdecl; overload;//Deprecated
    {class} function init(in_: JParcel): JAccount; cdecl; overload;//Deprecated
    {class} function equals(o: JObject): Boolean; cdecl;//Deprecated
    {class} function hashCode: Integer; cdecl;//Deprecated
    {class} function toString: JString; cdecl;//Deprecated
    {class} property CREATOR: JParcelable_Creator read _GetCREATOR;
    {class} property &type: JString read _Gettype;
  end;
 
  [JavaSignature('android/accounts/Account')]
  JAccount = interface(JObject)
    ['{71476381-8B6E-471F-9189-9857ECD7508C}']
    function _Getname: JString; cdecl;
    function describeContents: Integer; cdecl;//Deprecated
    procedure writeToParcel(dest: JParcel; flags: Integer); cdecl;//Deprecated
    property name: JString read _Getname;
  end;
  TJAccount = class(TJavaGenericImport<JAccountClass, JAccount>) end;
 
  JDevicePolicyManagerClass = interface(JObjectClass)
    ['{CBE483A2-6687-45BB-8503-C79415DDC80D}']
    {class} function _GetACTION_ADD_DEVICE_ADMIN: JString; cdecl;
    {class} function _GetACTION_DEVICE_OWNER_CHANGED: JString; cdecl;
    {class} function _GetACTION_MANAGED_PROFILE_PROVISIONED: JString; cdecl;
    {class} function _GetACTION_PROVISION_MANAGED_DEVICE: JString; cdecl;
    {class} function _GetACTION_PROVISION_MANAGED_PROFILE: JString; cdecl;
    {class} function _GetACTION_SET_NEW_PASSWORD: JString; cdecl;
    {class} function _GetACTION_START_ENCRYPTION: JString; cdecl;
    {class} function _GetACTION_SYSTEM_UPDATE_POLICY_CHANGED: JString; cdecl;
    {class} function _GetENCRYPTION_STATUS_ACTIVATING: Integer; cdecl;
    {class} function _GetENCRYPTION_STATUS_ACTIVE: Integer; cdecl;
    {class} function _GetENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY: Integer; cdecl;
    {class} function _GetENCRYPTION_STATUS_INACTIVE: Integer; cdecl;
    {class} function _GetENCRYPTION_STATUS_UNSUPPORTED: Integer; cdecl;
    {class} function _GetEXTRA_ADD_EXPLANATION: JString; cdecl;
    {class} function _GetEXTRA_DEVICE_ADMIN: JString; cdecl;
    {class} function _GetEXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE: JString; cdecl;
    {class} function _GetEXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE: JString; cdecl;
    {class} function _GetEXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME: JString; cdecl;
    {class} function _GetEXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE: JString; cdecl;
    {class} function _GetEXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM: JString; cdecl;
    {class} function _GetEXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER: JString; cdecl;
    {class} function _GetEXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION: JString; cdecl;
    {class} function _GetEXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME: JString; cdecl;
    {class} function _GetEXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM: JString; cdecl;
    {class} function _GetEXTRA_PROVISIONING_EMAIL_ADDRESS: JString; cdecl;
    {class} function _GetEXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED: JString; cdecl;
    {class} function _GetEXTRA_PROVISIONING_LOCALE: JString; cdecl;
    {class} function _GetEXTRA_PROVISIONING_LOCAL_TIME: JString; cdecl;
    {class} function _GetEXTRA_PROVISIONING_SKIP_ENCRYPTION: JString; cdecl;
    {class} function _GetEXTRA_PROVISIONING_TIME_ZONE: JString; cdecl;
    {class} function _GetEXTRA_PROVISIONING_WIFI_HIDDEN: JString; cdecl;
    {class} function _GetEXTRA_PROVISIONING_WIFI_PAC_URL: JString; cdecl;
    {class} function _GetEXTRA_PROVISIONING_WIFI_PASSWORD: JString; cdecl;
    {class} function _GetEXTRA_PROVISIONING_WIFI_PROXY_BYPASS: JString; cdecl;
    {class} function _GetEXTRA_PROVISIONING_WIFI_PROXY_HOST: JString; cdecl;
    {class} function _GetEXTRA_PROVISIONING_WIFI_PROXY_PORT: JString; cdecl;
    {class} function _GetEXTRA_PROVISIONING_WIFI_SECURITY_TYPE: JString; cdecl;
    {class} function _GetEXTRA_PROVISIONING_WIFI_SSID: JString; cdecl;
    {class} function _GetFLAG_MANAGED_CAN_ACCESS_PARENT: Integer; cdecl;
    {class} function _GetFLAG_PARENT_CAN_ACCESS_MANAGED: Integer; cdecl;
    {class} function _GetKEYGUARD_DISABLE_FEATURES_ALL: Integer; cdecl;
    {class} function _GetKEYGUARD_DISABLE_FEATURES_NONE: Integer; cdecl;
    {class} function _GetKEYGUARD_DISABLE_FINGERPRINT: Integer; cdecl;
    {class} function _GetKEYGUARD_DISABLE_SECURE_CAMERA: Integer; cdecl;
    {class} function _GetKEYGUARD_DISABLE_SECURE_NOTIFICATIONS: Integer; cdecl;
    {class} function _GetKEYGUARD_DISABLE_TRUST_AGENTS: Integer; cdecl;
    {class} function _GetKEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS: Integer; cdecl;
    {class} function _GetKEYGUARD_DISABLE_WIDGETS_ALL: Integer; cdecl;
    {class} function _GetMIME_TYPE_PROVISIONING_NFC: JString; cdecl;
    {class} function _GetPASSWORD_QUALITY_ALPHABETIC: Integer; cdecl;
    {class} function _GetPASSWORD_QUALITY_ALPHANUMERIC: Integer; cdecl;
    {class} function _GetPASSWORD_QUALITY_BIOMETRIC_WEAK: Integer; cdecl;
    {class} function _GetPASSWORD_QUALITY_COMPLEX: Integer; cdecl;
    {class} function _GetPASSWORD_QUALITY_NUMERIC: Integer; cdecl;
    {class} function _GetPASSWORD_QUALITY_NUMERIC_COMPLEX: Integer; cdecl;
    {class} function _GetPASSWORD_QUALITY_SOMETHING: Integer; cdecl;
    {class} function _GetPASSWORD_QUALITY_UNSPECIFIED: Integer; cdecl;
    {class} function _GetPERMISSION_GRANT_STATE_DEFAULT: Integer; cdecl;
    {class} function _GetPERMISSION_GRANT_STATE_DENIED: Integer; cdecl;
    {class} function _GetPERMISSION_GRANT_STATE_GRANTED: Integer; cdecl;
    {class} function _GetPERMISSION_POLICY_AUTO_DENY: Integer; cdecl;
    {class} function _GetPERMISSION_POLICY_AUTO_GRANT: Integer; cdecl;
    {class} function _GetPERMISSION_POLICY_PROMPT: Integer; cdecl;
    {class} function _GetRESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT: Integer; cdecl;
    {class} function _GetRESET_PASSWORD_REQUIRE_ENTRY: Integer; cdecl;
    {class} function _GetWIPE_EXTERNAL_STORAGE: Integer; cdecl;
    {class} function _GetWIPE_RESET_PROTECTION_DATA: Integer; cdecl;
    {class} procedure addPersistentPreferredActivity(admin: JComponentName; filter: JIntentFilter; activity: JComponentName); cdecl;//Deprecated
    {class} procedure addUserRestriction(admin: JComponentName; key: JString); cdecl;//Deprecated
    {class} procedure clearUserRestriction(admin: JComponentName; key: JString); cdecl;//Deprecated
    {class} function createAndInitializeUser(admin: JComponentName; name: JString; ownerName: JString; profileOwnerComponent: JComponentName; adminExtras: JBundle): JUserHandle; cdecl;//Deprecated
    {class} function createUser(admin: JComponentName; name: JString): JUserHandle; cdecl;//Deprecated
    {class} function getActiveAdmins: JList; cdecl;//Deprecated
    {class} function getApplicationRestrictions(admin: JComponentName; packageName: JString): JBundle; cdecl;//Deprecated
    {class} function getAutoTimeRequired: Boolean; cdecl;//Deprecated
    {class} function getCrossProfileCallerIdDisabled(admin: JComponentName): Boolean; cdecl;//Deprecated
    {class} function getCrossProfileWidgetProviders(admin: JComponentName): JList; cdecl;//Deprecated
    {class} function getCurrentFailedPasswordAttempts: Integer; cdecl;//Deprecated
    {class} function getMaximumTimeToLock(admin: JComponentName): Int64; cdecl;
    {class} function getPasswordExpiration(admin: JComponentName): Int64; cdecl;
    {class} function getPasswordExpirationTimeout(admin: JComponentName): Int64; cdecl;
    {class} function getPasswordMinimumLetters(admin: JComponentName): Integer; cdecl;
    {class} function getPasswordMinimumLowerCase(admin: JComponentName): Integer; cdecl;
    {class} function getPasswordMinimumNonLetter(admin: JComponentName): Integer; cdecl;
    {class} function getPasswordMinimumUpperCase(admin: JComponentName): Integer; cdecl;
    {class} function getPasswordQuality(admin: JComponentName): Integer; cdecl;
    {class} function getPermissionGrantState(admin: JComponentName; packageName: JString; permission: JString): Integer; cdecl;
    {class} function getScreenCaptureDisabled(admin: JComponentName): Boolean; cdecl;
    {class} function getStorageEncryption(admin: JComponentName): Boolean; cdecl;
    {class} function getStorageEncryptionStatus: Integer; cdecl;
    {class} function hasGrantedPolicy(admin: JComponentName; usesPolicy: Integer): Boolean; cdecl;//Deprecated
    {class} function installCaCert(admin: JComponentName; certBuffer: TJavaArray<Byte>): Boolean; cdecl;//Deprecated
    {class} function installKeyPair(admin: JComponentName; privKey: JPrivateKey; cert: JCertificate; alias: JString): Boolean; cdecl;//Deprecated
    {class} function isDeviceOwnerApp(packageName: JString): Boolean; cdecl;//Deprecated
    {class} function isLockTaskPermitted(pkg: JString): Boolean; cdecl;//Deprecated
    {class} function isMasterVolumeMuted(admin: JComponentName): Boolean; cdecl;//Deprecated
    {class} procedure removeActiveAdmin(admin: JComponentName); cdecl;//Deprecated
    {class} function removeCrossProfileWidgetProvider(admin: JComponentName; packageName: JString): Boolean; cdecl;//Deprecated
    {class} function removeUser(admin: JComponentName; userHandle: JUserHandle): Boolean; cdecl;//Deprecated
    {class} procedure setApplicationRestrictions(admin: JComponentName; packageName: JString; settings: JBundle); cdecl;//Deprecated
    {class} procedure setAutoTimeRequired(admin: JComponentName; required: Boolean); cdecl;//Deprecated
    {class} procedure setCrossProfileCallerIdDisabled(admin: JComponentName; disabled: Boolean); cdecl;
    {class} procedure setGlobalSetting(admin: JComponentName; setting: JString; value: JString); cdecl;
    {class} function setKeyguardDisabled(admin: JComponentName; disabled: Boolean): Boolean; cdecl;
    {class} procedure setMaximumFailedPasswordsForWipe(admin: JComponentName; num: Integer); cdecl;
    {class} procedure setMaximumTimeToLock(admin: JComponentName; timeMs: Int64); cdecl;
    {class} procedure setPasswordExpirationTimeout(admin: JComponentName; timeout: Int64); cdecl;
    {class} procedure setPasswordMinimumLowerCase(admin: JComponentName; length: Integer); cdecl;
    {class} procedure setPasswordMinimumNonLetter(admin: JComponentName; length: Integer); cdecl;
    {class} procedure setPasswordMinimumNumeric(admin: JComponentName; length: Integer); cdecl;
    {class} function setPermissionGrantState(admin: JComponentName; packageName: JString; permission: JString; grantState: Integer): Boolean; cdecl;
    {class} procedure setPermissionPolicy(admin: JComponentName; policy: Integer); cdecl;
    {class} function setPermittedAccessibilityServices(admin: JComponentName; packageNames: JList): Boolean; cdecl;
    {class} procedure setRecommendedGlobalProxy(admin: JComponentName; proxyInfo: JProxyInfo); cdecl;//Deprecated
    {class} procedure setRestrictionsProvider(admin: JComponentName; provider: JComponentName); cdecl;//Deprecated
    {class} procedure setScreenCaptureDisabled(admin: JComponentName; disabled: Boolean); cdecl;//Deprecated
    {class} function setStorageEncryption(admin: JComponentName; encrypt: Boolean): Integer; cdecl;//Deprecated
    {class} procedure setSystemUpdatePolicy(admin: JComponentName; policy: JSystemUpdatePolicy); cdecl;//Deprecated
    {class} procedure setTrustAgentConfiguration(admin: JComponentName; target: JComponentName; configuration: JPersistableBundle); cdecl;//Deprecated
    {class} procedure uninstallAllUserCaCerts(admin: JComponentName); cdecl;//Deprecated
    {class} procedure uninstallCaCert(admin: JComponentName; certBuffer: TJavaArray<Byte>); cdecl;//Deprecated
    {class} procedure wipeData(flags: Integer); cdecl;//Deprecated
    {class} property ACTION_ADD_DEVICE_ADMIN: JString read _GetACTION_ADD_DEVICE_ADMIN;
    {class} property ACTION_DEVICE_OWNER_CHANGED: JString read _GetACTION_DEVICE_OWNER_CHANGED;
    {class} property ACTION_MANAGED_PROFILE_PROVISIONED: JString read _GetACTION_MANAGED_PROFILE_PROVISIONED;
    {class} property ACTION_PROVISION_MANAGED_DEVICE: JString read _GetACTION_PROVISION_MANAGED_DEVICE;
    {class} property ACTION_PROVISION_MANAGED_PROFILE: JString read _GetACTION_PROVISION_MANAGED_PROFILE;
    {class} property ACTION_SET_NEW_PASSWORD: JString read _GetACTION_SET_NEW_PASSWORD;
    {class} property ACTION_START_ENCRYPTION: JString read _GetACTION_START_ENCRYPTION;
    {class} property ACTION_SYSTEM_UPDATE_POLICY_CHANGED: JString read _GetACTION_SYSTEM_UPDATE_POLICY_CHANGED;
    {class} property ENCRYPTION_STATUS_ACTIVATING: Integer read _GetENCRYPTION_STATUS_ACTIVATING;
    {class} property ENCRYPTION_STATUS_ACTIVE: Integer read _GetENCRYPTION_STATUS_ACTIVE;
    {class} property ENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY: Integer read _GetENCRYPTION_STATUS_ACTIVE_DEFAULT_KEY;
    {class} property ENCRYPTION_STATUS_INACTIVE: Integer read _GetENCRYPTION_STATUS_INACTIVE;
    {class} property ENCRYPTION_STATUS_UNSUPPORTED: Integer read _GetENCRYPTION_STATUS_UNSUPPORTED;
    {class} property EXTRA_ADD_EXPLANATION: JString read _GetEXTRA_ADD_EXPLANATION;
    {class} property EXTRA_DEVICE_ADMIN: JString read _GetEXTRA_DEVICE_ADMIN;
    {class} property EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE: JString read _GetEXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE;
    {class} property EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE: JString read _GetEXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE;
    {class} property EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME: JString read _GetEXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME;
    {class} property EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE: JString read _GetEXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE;
    {class} property EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM: JString read _GetEXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM;
    {class} property EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER: JString read _GetEXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER;
    {class} property EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION: JString read _GetEXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION;
    {class} property EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME: JString read _GetEXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME;
    {class} property EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM: JString read _GetEXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM;
    {class} property EXTRA_PROVISIONING_EMAIL_ADDRESS: JString read _GetEXTRA_PROVISIONING_EMAIL_ADDRESS;
    {class} property EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED: JString read _GetEXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED;
    {class} property EXTRA_PROVISIONING_LOCALE: JString read _GetEXTRA_PROVISIONING_LOCALE;
    {class} property EXTRA_PROVISIONING_LOCAL_TIME: JString read _GetEXTRA_PROVISIONING_LOCAL_TIME;
    {class} property EXTRA_PROVISIONING_SKIP_ENCRYPTION: JString read _GetEXTRA_PROVISIONING_SKIP_ENCRYPTION;
    {class} property EXTRA_PROVISIONING_TIME_ZONE: JString read _GetEXTRA_PROVISIONING_TIME_ZONE;
    {class} property EXTRA_PROVISIONING_WIFI_HIDDEN: JString read _GetEXTRA_PROVISIONING_WIFI_HIDDEN;
    {class} property EXTRA_PROVISIONING_WIFI_PAC_URL: JString read _GetEXTRA_PROVISIONING_WIFI_PAC_URL;
    {class} property EXTRA_PROVISIONING_WIFI_PASSWORD: JString read _GetEXTRA_PROVISIONING_WIFI_PASSWORD;
    {class} property EXTRA_PROVISIONING_WIFI_PROXY_BYPASS: JString read _GetEXTRA_PROVISIONING_WIFI_PROXY_BYPASS;
    {class} property EXTRA_PROVISIONING_WIFI_PROXY_HOST: JString read _GetEXTRA_PROVISIONING_WIFI_PROXY_HOST;
    {class} property EXTRA_PROVISIONING_WIFI_PROXY_PORT: JString read _GetEXTRA_PROVISIONING_WIFI_PROXY_PORT;
    {class} property EXTRA_PROVISIONING_WIFI_SECURITY_TYPE: JString read _GetEXTRA_PROVISIONING_WIFI_SECURITY_TYPE;
    {class} property EXTRA_PROVISIONING_WIFI_SSID: JString read _GetEXTRA_PROVISIONING_WIFI_SSID;
    {class} property FLAG_MANAGED_CAN_ACCESS_PARENT: Integer read _GetFLAG_MANAGED_CAN_ACCESS_PARENT;
    {class} property FLAG_PARENT_CAN_ACCESS_MANAGED: Integer read _GetFLAG_PARENT_CAN_ACCESS_MANAGED;
    {class} property KEYGUARD_DISABLE_FEATURES_ALL: Integer read _GetKEYGUARD_DISABLE_FEATURES_ALL;
    {class} property KEYGUARD_DISABLE_FEATURES_NONE: Integer read _GetKEYGUARD_DISABLE_FEATURES_NONE;
    {class} property KEYGUARD_DISABLE_FINGERPRINT: Integer read _GetKEYGUARD_DISABLE_FINGERPRINT;
    {class} property KEYGUARD_DISABLE_SECURE_CAMERA: Integer read _GetKEYGUARD_DISABLE_SECURE_CAMERA;
    {class} property KEYGUARD_DISABLE_SECURE_NOTIFICATIONS: Integer read _GetKEYGUARD_DISABLE_SECURE_NOTIFICATIONS;
    {class} property KEYGUARD_DISABLE_TRUST_AGENTS: Integer read _GetKEYGUARD_DISABLE_TRUST_AGENTS;
    {class} property KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS: Integer read _GetKEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS;
    {class} property KEYGUARD_DISABLE_WIDGETS_ALL: Integer read _GetKEYGUARD_DISABLE_WIDGETS_ALL;
    {class} property MIME_TYPE_PROVISIONING_NFC: JString read _GetMIME_TYPE_PROVISIONING_NFC;
    {class} property PASSWORD_QUALITY_ALPHABETIC: Integer read _GetPASSWORD_QUALITY_ALPHABETIC;
    {class} property PASSWORD_QUALITY_ALPHANUMERIC: Integer read _GetPASSWORD_QUALITY_ALPHANUMERIC;
    {class} property PASSWORD_QUALITY_BIOMETRIC_WEAK: Integer read _GetPASSWORD_QUALITY_BIOMETRIC_WEAK;
    {class} property PASSWORD_QUALITY_COMPLEX: Integer read _GetPASSWORD_QUALITY_COMPLEX;
    {class} property PASSWORD_QUALITY_NUMERIC: Integer read _GetPASSWORD_QUALITY_NUMERIC;
    {class} property PASSWORD_QUALITY_NUMERIC_COMPLEX: Integer read _GetPASSWORD_QUALITY_NUMERIC_COMPLEX;
    {class} property PASSWORD_QUALITY_SOMETHING: Integer read _GetPASSWORD_QUALITY_SOMETHING;
    {class} property PASSWORD_QUALITY_UNSPECIFIED: Integer read _GetPASSWORD_QUALITY_UNSPECIFIED;
    {class} property PERMISSION_GRANT_STATE_DEFAULT: Integer read _GetPERMISSION_GRANT_STATE_DEFAULT;
    {class} property PERMISSION_GRANT_STATE_DENIED: Integer read _GetPERMISSION_GRANT_STATE_DENIED;
    {class} property PERMISSION_GRANT_STATE_GRANTED: Integer read _GetPERMISSION_GRANT_STATE_GRANTED;
    {class} property PERMISSION_POLICY_AUTO_DENY: Integer read _GetPERMISSION_POLICY_AUTO_DENY;
    {class} property PERMISSION_POLICY_AUTO_GRANT: Integer read _GetPERMISSION_POLICY_AUTO_GRANT;
    {class} property PERMISSION_POLICY_PROMPT: Integer read _GetPERMISSION_POLICY_PROMPT;
    {class} property RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT: Integer read _GetRESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT;
    {class} property RESET_PASSWORD_REQUIRE_ENTRY: Integer read _GetRESET_PASSWORD_REQUIRE_ENTRY;
    {class} property WIPE_EXTERNAL_STORAGE: Integer read _GetWIPE_EXTERNAL_STORAGE;
    {class} property WIPE_RESET_PROTECTION_DATA: Integer read _GetWIPE_RESET_PROTECTION_DATA;
  end;
 
  [JavaSignature('android/app/admin/DevicePolicyManager')]
  JDevicePolicyManager = interface(JObject)
    ['{830D2517-B421-4C44-BAD6-8F907A4B2B6D}']
    procedure addCrossProfileIntentFilter(admin: JComponentName; filter: JIntentFilter; flags: Integer); cdecl;//Deprecated
    function addCrossProfileWidgetProvider(admin: JComponentName; packageName: JString): Boolean; cdecl;//Deprecated
    procedure clearCrossProfileIntentFilters(admin: JComponentName); cdecl;//Deprecated
    procedure clearDeviceOwnerApp(packageName: JString); cdecl;//Deprecated
    procedure clearPackagePersistentPreferredActivities(admin: JComponentName; packageName: JString); cdecl;//Deprecated
    procedure enableSystemApp(admin: JComponentName; packageName: JString); cdecl; overload;//Deprecated
    function enableSystemApp(admin: JComponentName; intent: JIntent): Integer; cdecl; overload;//Deprecated
    function getAccountTypesWithManagementDisabled: TJavaObjectArray<JString>; cdecl;//Deprecated
    function getBluetoothContactSharingDisabled(admin: JComponentName): Boolean; cdecl;//Deprecated
    function getCameraDisabled(admin: JComponentName): Boolean; cdecl;//Deprecated
    function getCertInstallerPackage(admin: JComponentName): JString; cdecl;//Deprecated
    function getInstalledCaCerts(admin: JComponentName): TJavaObjectArray<JList>; cdecl;
    function getKeyguardDisabledFeatures(admin: JComponentName): Integer; cdecl;
    function getMaximumFailedPasswordsForWipe(admin: JComponentName): Integer; cdecl;
    function getPasswordHistoryLength(admin: JComponentName): Integer; cdecl;
    function getPasswordMaximumLength(quality: Integer): Integer; cdecl;
    function getPasswordMinimumLength(admin: JComponentName): Integer; cdecl;
    function getPasswordMinimumNumeric(admin: JComponentName): Integer; cdecl;
    function getPasswordMinimumSymbols(admin: JComponentName): Integer; cdecl;
    function getPermissionPolicy(admin: JComponentName): Integer; cdecl;
    function getPermittedAccessibilityServices(admin: JComponentName): JList; cdecl;
    function getPermittedInputMethods(admin: JComponentName): JList; cdecl;
    function getSystemUpdatePolicy: JSystemUpdatePolicy; cdecl;//Deprecated
    function getTrustAgentConfiguration(admin: JComponentName; agent: JComponentName): JList; cdecl;//Deprecated
    function hasCaCertInstalled(admin: JComponentName; certBuffer: TJavaArray<Byte>): Boolean; cdecl;//Deprecated
    function isActivePasswordSufficient: Boolean; cdecl;//Deprecated
    function isAdminActive(admin: JComponentName): Boolean; cdecl;//Deprecated
    function isApplicationHidden(admin: JComponentName; packageName: JString): Boolean; cdecl;//Deprecated
    function isProfileOwnerApp(packageName: JString): Boolean; cdecl;//Deprecated
    function isUninstallBlocked(admin: JComponentName; packageName: JString): Boolean; cdecl;//Deprecated
    procedure lockNow; cdecl;//Deprecated
    function resetPassword(password: JString; flags: Integer): Boolean; cdecl;//Deprecated
    procedure setAccountManagementDisabled(admin: JComponentName; accountType: JString; disabled: Boolean); cdecl;//Deprecated
    function setApplicationHidden(admin: JComponentName; packageName: JString; hidden: Boolean): Boolean; cdecl;//Deprecated
    procedure setBluetoothContactSharingDisabled(admin: JComponentName; disabled: Boolean); cdecl;
    procedure setCameraDisabled(admin: JComponentName; disabled: Boolean); cdecl;
    procedure setCertInstallerPackage(admin: JComponentName; installerPackage: JString); cdecl;
    procedure setKeyguardDisabledFeatures(admin: JComponentName; which: Integer); cdecl;
    procedure setLockTaskPackages(admin: JComponentName; packages: TJavaObjectArray<JString>); cdecl;
    procedure setMasterVolumeMuted(admin: JComponentName; on: Boolean); cdecl;
    procedure setPasswordHistoryLength(admin: JComponentName; length: Integer); cdecl;
    procedure setPasswordMinimumLength(admin: JComponentName; length: Integer); cdecl;
    procedure setPasswordMinimumLetters(admin: JComponentName; length: Integer); cdecl;
    procedure setPasswordMinimumSymbols(admin: JComponentName; length: Integer); cdecl;
    procedure setPasswordMinimumUpperCase(admin: JComponentName; length: Integer); cdecl;
    procedure setPasswordQuality(admin: JComponentName; quality: Integer); cdecl;
    function setPermittedInputMethods(admin: JComponentName; packageNames: JList): Boolean; cdecl;//Deprecated
    procedure setProfileEnabled(admin: JComponentName); cdecl;//Deprecated
    procedure setProfileName(admin: JComponentName; profileName: JString); cdecl;//Deprecated
    procedure setSecureSetting(admin: JComponentName; setting: JString; value: JString); cdecl;//Deprecated
    function setStatusBarDisabled(admin: JComponentName; disabled: Boolean): Boolean; cdecl;//Deprecated
    procedure setUninstallBlocked(admin: JComponentName; packageName: JString; uninstallBlocked: Boolean); cdecl;//Deprecated
    procedure setUserIcon(admin: JComponentName; icon: JBitmap); cdecl;//Deprecated
    function switchUser(admin: JComponentName; userHandle: JUserHandle): Boolean; cdecl;//Deprecated
  end;
  TJDevicePolicyManager = class(TJavaGenericImport<JDevicePolicyManagerClass, JDevicePolicyManager>) end;
 
  JSystemUpdatePolicyClass = interface(JObjectClass)
    ['{1A355CFD-33D8-4E57-A045-02F173C26060}']
    {class} function _GetCREATOR: JParcelable_Creator; cdecl;
    {class} function _GetTYPE_INSTALL_AUTOMATIC: Integer; cdecl;
    {class} function _GetTYPE_INSTALL_WINDOWED: Integer; cdecl;
    {class} function _GetTYPE_POSTPONE: Integer; cdecl;
    {class} function createAutomaticInstallPolicy: JSystemUpdatePolicy; cdecl;//Deprecated
    {class} function createPostponeInstallPolicy: JSystemUpdatePolicy; cdecl;//Deprecated
    {class} function createWindowedInstallPolicy(startTime: Integer; endTime: Integer): JSystemUpdatePolicy; cdecl;//Deprecated
    {class} function getInstallWindowStart: Integer; cdecl;//Deprecated
    {class} function getPolicyType: Integer; cdecl;//Deprecated
    {class} function toString: JString; cdecl;//Deprecated
    {class} property CREATOR: JParcelable_Creator read _GetCREATOR;
    {class} property TYPE_INSTALL_AUTOMATIC: Integer read _GetTYPE_INSTALL_AUTOMATIC;
    {class} property TYPE_INSTALL_WINDOWED: Integer read _GetTYPE_INSTALL_WINDOWED;
    {class} property TYPE_POSTPONE: Integer read _GetTYPE_POSTPONE;
  end;
 
  [JavaSignature('android/app/admin/SystemUpdatePolicy')]
  JSystemUpdatePolicy = interface(JObject)
    ['{A1B4DDD5-5AAD-4275-9295-279751DFDDB4}']
    function describeContents: Integer; cdecl;//Deprecated
    function getInstallWindowEnd: Integer; cdecl;//Deprecated
    procedure writeToParcel(dest: JParcel; flags: Integer); cdecl;//Deprecated
  end;
  TJSystemUpdatePolicy = class(TJavaGenericImport<JSystemUpdatePolicyClass, JSystemUpdatePolicy>) end;
 
  // java.lang.StringBuffer
  // java.lang.StringBuilder
implementation
 
procedure RegisterTypes;
begin
  TRegTypes.RegisterType('DevicePolicyManager.JAccount', TypeInfo(DevicePolicyManager.JAccount));
  TRegTypes.RegisterType('DevicePolicyManager.JDevicePolicyManager', TypeInfo(DevicePolicyManager.JDevicePolicyManager));
  TRegTypes.RegisterType('DevicePolicyManager.JSystemUpdatePolicy', TypeInfo(DevicePolicyManager.JSystemUpdatePolicy));
//  TRegTypes.RegisterType('DevicePolicyManager.JStringBuffer', TypeInfo(DevicePolicyManager.JStringBuffer));
//  TRegTypes.RegisterType('DevicePolicyManager.JStringBuilder', TypeInfo(DevicePolicyManager.JStringBuilder));
end;
 
initialization
  RegisterTypes;
end.
 
//----------------------------------------------------------------------------
Testing code
 
void __fastcall TForm1::DeviceMgrClick(TObject *Sender)
{
DocPath = System::Ioutils::TPath::GetDocumentsPath();
CertFile = System::Ioutils::TPath::Combine( DocPath, "Cluster5_Root_CA.crt");
 
if (!FileExists(CertFile))
	{
	ShowMessage("File not found");
	return;
	}
 
try
	{
	_di_JFileInputStream FileStream = TJFileInputStream::JavaClass->init(StringToJString(CertFile));
 
	if (FileStream == nullptr)
		return;
 
	_di_JDevicePolicyManager DPM = TJDevicePolicyManager::Wrap((_di_IJavaInstance)SharedActivityContext()->getSystemService(TJContext::JavaClass->DEVICE_POLICY_SERVICE));
 
	if (DPM == nullptr)
		return;
 
	TJavaArray__1<Byte> *certBuffer = new TJavaArray__1<Byte>(FileStream->getChannel()->size());
 
	FileStream->getChannel()->position(0);
	FileStream->read(certBuffer,0,certBuffer->Length);
 
	if (DPM->hasCaCertInstalled(0,certBuffer))       //i get error here
		throw Exception("Cert already on device?");
 
	if (!TJDevicePolicyManager::JavaClass->installCaCert(0,certBuffer))   //i get error here
		throw Exception("installCaCert returned false.");
 
	if (DPM->hasCaCertInstalled(0,certBuffer))    //i get error here
		throw Exception("Cannot find cert after installation.");
 
	FileStream->close();
	delete certBuffer;
	}
catch(const Exception &E)
	{
	throw Exception(E.Message);
	}
}
//---------------------------------------------------------------------------
 
//I also get the error here in this line in pas file Android.JNIMarshal.pas
 
begin
  if InvokeData.MethodID = nil then
    raise EJNIFatal.CreateRes(@SJNIUnknownMethod); // error here
  CntJArraySrc := 0;
  JNIEnv := TJNIResolver.GetJNIEnv;
 


I need this as I learned that this way i can install certificates
silently without user interaction.

--
The limits of my language mean the limits of my world
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Using Android DevicePolicyManager with C++ Builder to install cert!!!  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 24, 2017 12:27 PM   in response to: Ahmed Sayed in response to: Ahmed Sayed
Ahmed Sayed wrote:

I have managed to export the DevicePolicyManager.pas
file from DevicePolicyManager.java file in Android SDK.

But whenever i try to use any function from
_di_JDevicePolicyManager interface i get run-time
error message "Invoke error: method not found."

"Invoke error: method not found."

You have a bad import. There are instance methods that have been
declared as static class methods instead. You need to fix your
imported unit.

if (DPM->hasCaCertInstalled(0,certBuffer))

This line is correct, and should not be crashing.

if (!TJDevicePolicyManager::JavaClass->installCaCert(0,certBuffer))

This line, however, is wrong. installCaCert() is not a static class
method, it is an instance method. You need to call it via your DPM
object pointer.

if (!DPM->installCaCert(0,certBuffer))


Which you can't do until you fix your imported unit.

//I also get the error here in this line in pas file
Android.JNIMarshal.pas

begin
if InvokeData.MethodID = nil then
raise EJNIFatal.CreateRes(@SJNIUnknownMethod); // error here
CntJArraySrc := 0;
JNIEnv := TJNIResolver.GetJNIEnv;

{code}

What Android API level is your project targetting?
hasCaCertInstalled() and installCaCert() were hidden functions until
API level 21 (Android 5).

--
Remy Lebeau (TeamB)
Ahmed Sayed

Posts: 173
Registered: 8/9/07
Re: Using Android DevicePolicyManager with C++ Builder to install cert!!!  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 24, 2017 12:53 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
My Android API level is 25.2.5

Also, in my text code if i commented the last 2 methods

I still get the same error.


	if (DPM->hasCaCertInstalled(0,certBuffer))    // I still get the error here
		throw Exception("Cert already on device?");
 
//	if (!TJDevicePolicyManager::JavaClass->installCaCert(0,certBuffer))
//		throw Exception("installCaCert returned false.");
 
//	if (DPM->hasCaCertInstalled(0,certBuffer))
//		throw Exception("Cannot find cert after installation.");


--
The limits of my language mean the limits of my world
Ahmed Sayed

Posts: 173
Registered: 8/9/07
Re: Using Android DevicePolicyManager with C++ Builder to install cert!!!  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 27, 2017 4:29 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Could anyone help me please!!

--
The limits of my language mean the limits of my world
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02