Tuesday, August 30, 2016

Android - How to Kill the application on back button press.

The easiest way to do this is to clear all the top activities and call the finish() on the activities. The below code needs to be done by overriding the onBackPressed method.

    Intent intent = new Intent(this, LaunchActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra("Exit", true);
    startActivity(intent);
    finish();

On the launch activity, now we need to have the below code at the end of onCreate, note that should not spin any new thread in the OnCreate method.

    if( getIntent().getBooleanExtra("Exit", false)){
        finish();
    }

In some cases, we may not want to have back traces left for specific activity on the activity stack. In such cases, we can just have the below code for each activity in the Android Manifest xml. for e.g. SplashScreen , Login Screen etc.

android:noHistory="true"

One another way is to have the homescreen shown while the app activity is not forcefully finished. The code below should be placed on OnBackPressed overriden method.

Intent a = new Intent(Intent.ACTION_MAIN);
a.addCategory(Intent.CATEGORY_HOME);
a.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(a);


references:
http://stackoverflow.com/questions/3226495/how-to-exit-from-the-application-and-show-the-home-screen

Over the Air Profile Delivery concepts

There are three phases involved in this:

1. authentication
2. enrollment
3. device configuration 

Authentication Phase (Phase 1):

Two main aims of this step are

1. Ensure the enrolment request is from valid entity 
2. It captures info about user’s device for use in the certificate enrolment process. 

The steps involved in this are: 

1. User visits the root URL and receives a welcome message. 
2. The user visits the certificate authority URL (/CA) to get the root cert. 
3. The user visits the enrolment URL (/enroll) to start the enrolment process. In this step, user is prompted to authenticate himself or herself using HTTP basic authentication or using existing directory services. 
4. The server’s enrolment handler determines whether the user is allowed to enrol the device. If allowed, server sends a profile service payload. The service payload (.mobileconfig) contains a request for additional device-specific information that device must provide in next step. The payload may include a Challenge token (optional) so that the server can associate the request with the original user. This allows one to customise the configuration process for each user, if desired. 

The device attributes that the service can request are the iOS version, WiFi device ID, product type, phone equipment ID, and SIM card Identifier.  

Certificate Enrolment (X.509 Identities and SCEP) - Phase 2
In the enrolment phase, device contacts the CA and obtains a signed X.509 identify cert, which is used for encryption. 
To acquire an identity, a device first generates an asymmetric key and stores it in its keychain. The secret in this keychain can be read only by that specific device
The device then sends it public key to CA and sends back the signed X.509 certificate. This certificate then combined with the private key on device forms the identify.

The above exchange is possible because iOS supports SCEP. SCEP is a communication protocol that provides a networked front end to a private certificate authority. Support for SCEP is provided by a number of CAs and there are complete open source software of certificate authorities with SCEP support. 

Below are the steps in enrolment phase
1. The user accepts the installation of the profile from phase 1 
2. The device looks up the requested attributes, adds the challenge response (if provided), signs the response using Apple’s built in identity and sends it back to the profile distribution service using POST .
3. The server’s profile request handler sends back a configuration profile that instructs the device to enrol using SCEP.
4. The device Enrolls using SCEP, resulting in a valid identity certificate installed on device. 

Device Configuration and Encrypted Profiles (Phase 3)
This is the phase where the actual profile itself is delivered. The profile that is delivered will be customised for the requested device. To provide protection, iOS allows to encrypt the profile so that they can be installed only on single device. 
An encrypted profile is just like a normal profile except the configuration profile is encrypted with the public key associated with the device’s X.509 identity. 

For encryption and and signing, iOS uses the Cryptographic Message Syntax (CMS) a standard that is also used in S/MIME. Payloads are encrypted using PKCS#7 enveloped data. Profiles are signed using PKCS#7 signed data. 

The steps in the device configuration phase are: 

1. The device sends a signed request for the /profile handler again to request the final profile. The request is signed with the identity certificate obtained in the previous step. 
2. The server profile handler sends the final encrypted profile to the device. 

references:

Friday, August 5, 2016

Android, ImageView Does not fill the parent

Below needs to be done so that the ImageView scales appropriately. scaleXY is important 
<imageview android:id="@+id/image_tag&#8221; android:layout_width=" android:layout_height="wrap_content" android:layout_marginleft="20dp" android:layout_marginright="20dp" android:src="@drawable/bg_image&#8221; android:scaleType=" fill_parent="" fitxy=""> </imageview>




references:

Tuesday, July 19, 2016

iOS Unit Test case

Below are some of the disadvantages

More code: In projects with high test coverage it’s possible to have more test code than functional code.
More to maintain: When there is more code, there is more to maintain.
No silver bullet: Unit tests don’t (and can’t) ensure that your code is free of bugs.
Takes longer: Writing tests takes time — time you could spend learning new exciting stuff on raywenderlich.com!

Below are some of the advantages however

Confidence: You can demonstrate that your code works.
Quick feedback: You can use unit tests to quickly validate code that is buried many layers deep in your app navigation — things that are cumbersome to test manually.
Modularity: Unit tests help keep you focused on writing more modular code.
Focus: Writing tests for micro features keep you focused on the small details.
Regression: Be sure that the bugs you fixed stay fixed — and aren’t broken by subsequent fixes.
Refactoring: Until Xcode gets smart enough to refactor your code on its own, you’ll need unit tests to validate your refactoring.
Documentation: Unit tests describe what you think the code should do; they serve as another way to document your code.


references:

Monday, July 18, 2016

iOS Localization

Normally, below are the items localized

The text in the storyboards
The cover image
The dynamic message displayed by code
The name of the app as displayed in home screen

The "Message" given here is optional. "BOOK_PURCHASE" is checked in the Localizable string and they are substituted here. If not found, "BOOK_PURCHASE" itself will be displayed. 

- (IBAction)buy:(id)sender
{
    [[[UIAlertView alloc] initWithTitle:@"Confirmation"
                                message:NSLocalizedString(@"BOOK_PURCHASE", @"Message")
                               delegate:nil
                      cancelButtonTitle:@"OK"
                      otherButtonTitles:nil] show];
}

references:

iOS Using Unit Tests

Xcode supports three main types of testing. Functional tests focus on code functionality. Performance tests focus on measuring execution time. User Interface tests focus on flows through the user interface. Functional and performances tests are functions that you write. Each function sets up an environment for the test, executes the targeted parts of the app, and tears down the test environment. User interface tests are recordings you make as you use your app.

A test case exercises a unit of code in a specific way or measures a specific part of your app’s performance; if the result of the test is different from the expected result, the test case fails. A test suite is made up of a set of test cases

When you create a project or a target, Xcode includes a unit test target in the scheme that builds the app. The implementation file for the target includes stubs for the setUp, tearDown, and testExample methods. Complete these stub implementations and add other code as necessary to perform unit tests on your app.

references:

Wednesday, July 13, 2016

How Does the AAAA DNS response look like?


It looks like below

Frame 514: 182 bytes on wire (1456 bits), 182 bytes captured (1456 bits) on interface 0
Ethernet II, Src: 00:6c:bc:3c:e3:d6 (00:6c:bc:3c:e3:d6), Dst: Apple_c3:e1:a2 (78:31:c1:c3:e1:a2)
Internet Protocol Version 4, Src: 10.238.35.20, Dst: 10.238.64.113
User Datagram Protocol, Src Port: 53 (53), Dst Port: 49184 (49184)
Domain Name System (response)
    [Request In: 512]
    [Time: 0.007250000 seconds]
    Transaction ID: 0x81b7
    Flags: 0x8180 Standard query response, No error
    Questions: 1
    Answer RRs: 2
    Authority RRs: 0
    Additional RRs: 0
    Queries
        dualstack.pr-my-78232.us-east-1.elb.amazonaws.com: type AAAA, class IN
            Name: dualstack.pr-my-78232.us-east-1.elb.amazonaws.com
            [Name Length: 66]
            [Label Count: 6]
            Type: AAAA (IPv6 Address) (28)
            Class: IN (0x0001)
    Answers
        dualstack.pr-my-78232.us-east-1.elb.amazonaws.com: type AAAA, class IN, addr 9404:ba00:dd00::36b1:9f98
            Name: dualstack.pr-my-78232.us-east-1.elb.amazonaws.com
            Type: AAAA (IPv6 Address) (28)
            Class: IN (0x0001)
            Time to live: 59
            Data length: 16
            AAAA Address: 9404:ba00:dd00::36b1:9f98
        ddualstack.pr-my-78232.us-east-1.elb.amazonaws.com: type AAAA, class IN, addr 9404:ba00:dd00::36b1:9f97
            Name: dualstack.pr-my-78232.us-east-1.elb.amazonaws.com
            Type: AAAA (IPv6 Address) (28)
            Class: IN (0x0001)
            Time to live: 59
            Data length: 16

            AAAA Address: 9404:ba00:dd00::36b1:9f97