public ResultCallbacks(IDIResultCallbacks resultCallbacks, Context context, Android.Net.Uri uri, Action <ICursor, Android.Net.Uri, IDIResultCallbacks> getUriValue)
 {
     callbackInterface = resultCallbacks;
     _context          = context;
     _uri         = uri;
     _getUriValue = getUriValue;
 }
 public static bool GetURIValue(ICursor cursor, Android.Net.Uri uri, IDIResultCallbacks resultCallbacks)
 {
     while (cursor.MoveToNext())
     {
         if (cursor.ColumnCount == 0)
         {
             //  No data in the cursor.  I have seen this happen on non-WAN devices
             String errorMsg = "Error: " + uri + " does not exist on this device";
             resultCallbacks.OnDebugStatus(errorMsg);
         }
         else
         {
             for (int i = 0; i < cursor.ColumnCount; i++)
             {
                 try
                 {
                     String data = cursor.GetString(cursor.GetColumnIndex(cursor.GetColumnName(i)));
                     resultCallbacks.OnSuccess(data);
                     cursor.Close();
                     return(true);
                 }
                 catch (Exception e)
                 {
                     resultCallbacks.OnDebugStatus(e.Message);
                 }
             }
         }
     }
     cursor.Close();
     resultCallbacks.OnError("Data not found in Uri:" + uri);
     return(true);
 }
Пример #3
0
 public void execute(String mxProfile, String mxProfileName, IDIResultCallbacks resutCallback)
 {
     // Let's start the timeout mechanism
     base.execute(mSettings);
     idiProfileManagerCommandResult = resutCallback;
     msProfileData = mxProfile;
     msProfileName = mxProfileName;
     initializeEMDK();
 }
        private static void RetrieveOEMInfo(Context context, Android.Net.Uri uri, IDIResultCallbacks callbackInterface)
        {
            //  For clarity, this code calls ContentResolver.query() on the UI thread but production code should perform queries asynchronously.
            //  See https://developer.android.com/guide/topics/providers/content-provider-basics.html for more information
            var cursor = context.ContentResolver.Query(uri, null, null, null, null);

            if (cursor == null || cursor.Count < 1)
            {
                if (callbackInterface != null)
                {
                    callbackInterface.OnDebugStatus("App not registered to call OEM Service:" + uri.ToString() + "\nRegistering current application using profile manger, this may take a couple of seconds...");
                }
                // Let's register the application
                RegisterCurrentApplication(context, uri, new ResultCallbacks(callbackInterface, context, uri, (cursor, uri, callbacks) => { GetURIValue(cursor, uri, callbacks); }));
            }
            else
            {
                // We have the right to call this service, and we obtained some data to parse...
                GetURIValue(cursor, uri, callbackInterface);
            }
        }
        private static void RegisterCurrentApplication(Context context, Android.Net.Uri serviceIdentifier, IDIResultCallbacks callbackInterface)
        {
            var profileName = "AccessMgr-1";
            var profileData = "";

            try
            {
                var packageInfo = context.PackageManager.GetPackageInfo(context.PackageName, PackageInfoFlags.SigningCertificates);
                var path        = context.ApplicationInfo.SourceDir;
                var strName     = packageInfo.ApplicationInfo.LoadLabel(context.PackageManager).ToString();
                var strVendor   = packageInfo.PackageName;
                var sig         = DIHelper.apkCertificate;

                // Let's check if we have a custom certificate
                if (sig == null)
                {
                    // Nope, we will get the first apk signing certificate that we find
                    // You can copy/paste this snippet if you want to provide your own
                    // certificate
                    // TODO: use the following code snippet to extract your custom certificate if necessary
                    var arrSignatures = packageInfo.SigningInfo.GetApkContentsSigners();
                    if (arrSignatures == null || arrSignatures.Length == 0)
                    {
                        if (callbackInterface != null)
                        {
                            callbackInterface.OnError("Error : Package has no signing certificates... how's that possible ?");
                            return;
                        }
                    }
                    sig = arrSignatures[0];
                }

                /*
                 * Get the X.509 certificate.
                 */
                var rawCert = sig.ToByteArray();

                // Get the certificate as a base64 string
                var encoded = Base64.EncodeToString(rawCert, Base64Flags.Default);

                profileData =
                    "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                    "<characteristic type=\"Profile\">" +
                    "<parm name=\"ProfileName\" value=\"" + profileName + "\"/>" +
                    "<characteristic type=\"AccessMgr\" version=\"9.2\">" +
                    "<parm name=\"OperationMode\" value=\"1\" />" +
                    "<parm name=\"ServiceAccessAction\" value=\"4\" />" +
                    "<parm name=\"ServiceIdentifier\" value=\"" + serviceIdentifier + "\" />" +
                    "<parm name=\"CallerPackageName\" value=\"" + context.PackageName.ToString() + "\" />" +
                    "<parm name=\"CallerSignature\" value=\"" + encoded + "\" />" +
                    "</characteristic>" +
                    "</characteristic>";
                DIProfileManagerCommand profileManagerCommand = new DIProfileManagerCommand(context);
                profileManagerCommand.execute(profileData, profileName, callbackInterface);
            }
            catch (Exception e)
            {
                if (callbackInterface != null)
                {
                    callbackInterface.OnError("Error on profile: " + profileName + "\nError:" + e.Message + "\nProfileData:" + profileData);
                }
            }
        }
 public ResultCallbacks(IDIResultCallbacks resultCallbacks)
 {
     callbackInterface = resultCallbacks;
 }
Пример #7
0
 // This method will return the imei number in the string passed through the onSuccess method
 public static void getIMEINumber(Context context, IDIResultCallbacks callbackInterface)
 {
     new RetrieveOEMInfoTask().Execute(context, Android.Net.Uri.Parse("content://oem_info/wan/imei"), callbackInterface);
 }
Пример #8
0
 // This method will return the serial number in the string passed through the onSuccess method
 public static void getSerialNumber(Context context, IDIResultCallbacks callbackInterface)
 {
     new RetrieveOEMInfoTask().Execute(context, Android.Net.Uri.Parse("content://oem_info/oem.zebra.secure/build_serial"), callbackInterface);
 }