alert dialogs are invoked from the decleared once in dialog util

revert-dabc3590
inosh-perera 10 years ago
parent 9697c1fa99
commit ac3bd52260

@ -379,6 +379,7 @@ int id setting_invite_email_edittext 0x7f06002f
int id setting_invite_email_imageview 0x7f060031 int id setting_invite_email_imageview 0x7f060031
int id setting_invite_email_layout 0x7f06002e int id setting_invite_email_layout 0x7f06002e
int id setting_invite_email_textview 0x7f060032 int id setting_invite_email_textview 0x7f060032
int id severAddressLabel 0x7f060089
int id sg_button1 0x7f060039 int id sg_button1 0x7f060039
int id sg_button2 0x7f06003a int id sg_button2 0x7f06003a
int id sg_button3 0x7f06003b int id sg_button3 0x7f06003b
@ -425,7 +426,6 @@ int id txtPinCode 0x7f060086
int id txtRegText 0x7f060066 int id txtRegText 0x7f060066
int id txtRoot 0x7f06007b int id txtRoot 0x7f06007b
int id txtSDK 0x7f060079 int id txtSDK 0x7f060079
int id txtVw 0x7f060089
int id useLogo 0x7f060004 int id useLogo 0x7f060004
int id user_edit_location 0x7f060033 int id user_edit_location 0x7f060033
int id username 0x7f06006b int id username 0x7f06006b
@ -518,12 +518,12 @@ int string abs__shareactionprovider_share_with_application 0x7f0b0009
int string action_settings 0x7f0b0023 int string action_settings 0x7f0b0023
int string already_registered 0x7f0b0010 int string already_registered 0x7f0b0010
int string app_name 0x7f0b0021 int string app_name 0x7f0b0021
int string application_mgr_download_file_name 0x7f0b0091 int string application_mgr_download_file_name 0x7f0b0092
int string application_mgr_download_location 0x7f0b0090 int string application_mgr_download_location 0x7f0b0091
int string application_mgr_mime 0x7f0b0092 int string application_mgr_mime 0x7f0b0093
int string application_package_launcher_action 0x7f0b0094 int string application_package_launcher_action 0x7f0b0095
int string application_package_prefix 0x7f0b0093 int string application_package_prefix 0x7f0b0094
int string button_ok 0x7f0b008f int string button_ok 0x7f0b0090
int string device_admin_disabled 0x7f0b002e int string device_admin_disabled 0x7f0b002e
int string device_admin_enable_alert 0x7f0b003d int string device_admin_enable_alert 0x7f0b003d
int string device_admin_enabled 0x7f0b002d int string device_admin_enabled 0x7f0b002d
@ -537,17 +537,18 @@ int string dialog_authenticate 0x7f0b0071
int string dialog_checking_reg 0x7f0b0073 int string dialog_checking_reg 0x7f0b0073
int string dialog_enrolling 0x7f0b0076 int string dialog_enrolling 0x7f0b0076
int string dialog_init_confirmation 0x7f0b0079 int string dialog_init_confirmation 0x7f0b0079
int string dialog_init_end 0x7f0b007b int string dialog_init_device_type 0x7f0b007b
int string dialog_init_end_general 0x7f0b007c int string dialog_init_end 0x7f0b007c
int string dialog_init_end_general 0x7f0b007d
int string dialog_init_middle 0x7f0b007a int string dialog_init_middle 0x7f0b007a
int string dialog_license_agreement 0x7f0b0075 int string dialog_license_agreement 0x7f0b0075
int string dialog_message_please_wait 0x7f0b0084 int string dialog_message_please_wait 0x7f0b0085
int string dialog_message_unregistering 0x7f0b0083 int string dialog_message_unregistering 0x7f0b0084
int string dialog_pin_confirmation 0x7f0b0077 int string dialog_pin_confirmation 0x7f0b0077
int string dialog_pin_confirmation_end 0x7f0b0078 int string dialog_pin_confirmation_end 0x7f0b0078
int string dialog_please_wait 0x7f0b0072 int string dialog_please_wait 0x7f0b0072
int string dialog_sender_id 0x7f0b0074 int string dialog_sender_id 0x7f0b0074
int string dialog_unregister 0x7f0b007d int string dialog_unregister 0x7f0b007e
int string empty_app_title 0x7f0b0022 int string empty_app_title 0x7f0b0022
int string error_auth_failed_detail 0x7f0b0068 int string error_auth_failed_detail 0x7f0b0068
int string error_authentication_failed 0x7f0b0069 int string error_authentication_failed 0x7f0b0069
@ -574,16 +575,14 @@ int string gcm_registered 0x7f0b0011
int string gcm_unregistered 0x7f0b0012 int string gcm_unregistered 0x7f0b0012
int string hello_world 0x7f0b0024 int string hello_world 0x7f0b0024
int string hint_new_pin 0x7f0b0042 int string hint_new_pin 0x7f0b0042
int string info_label_device 0x7f0b0086 int string info_label_device 0x7f0b0087
int string info_label_imei 0x7f0b0085 int string info_label_imei 0x7f0b0086
int string info_label_imsi 0x7f0b008a int string info_label_imsi 0x7f0b008b
int string info_label_model 0x7f0b0087 int string info_label_model 0x7f0b0088
int string info_label_no_sim 0x7f0b0088 int string info_label_no_sim 0x7f0b0089
int string info_label_operator 0x7f0b0089 int string info_label_operator 0x7f0b008a
int string info_label_os 0x7f0b008b int string info_label_os 0x7f0b008c
int string info_label_rooted 0x7f0b008c int string info_label_rooted 0x7f0b008d
int string info_label_rooted_answer_no 0x7f0b008e
int string info_label_rooted_answer_yes 0x7f0b008d
int string intent_extra_fresh_reg_flag 0x7f0b004c int string intent_extra_fresh_reg_flag 0x7f0b004c
int string intent_extra_from_activity 0x7f0b0048 int string intent_extra_from_activity 0x7f0b0048
int string intent_extra_main_activity 0x7f0b004a int string intent_extra_main_activity 0x7f0b004a
@ -591,27 +590,28 @@ int string intent_extra_message 0x7f0b004b
int string intent_extra_notification 0x7f0b004e int string intent_extra_notification 0x7f0b004e
int string intent_extra_regid 0x7f0b0049 int string intent_extra_regid 0x7f0b0049
int string intent_extra_username 0x7f0b004d int string intent_extra_username 0x7f0b004d
int string menu_item_change_ip 0x7f0b0082 int string menu_item_change_ip 0x7f0b0083
int string menu_item_change_pin 0x7f0b0081 int string menu_item_change_pin 0x7f0b0082
int string menu_item_ip 0x7f0b003a int string menu_item_ip 0x7f0b003a
int string menu_item_log 0x7f0b003b int string menu_item_log 0x7f0b003b
int string menu_item_operations 0x7f0b0038 int string menu_item_operations 0x7f0b0038
int string menu_item_phone_info 0x7f0b0080 int string menu_item_phone_info 0x7f0b0081
int string menu_item_pin 0x7f0b0039 int string menu_item_pin 0x7f0b0039
int string no 0x7f0b008f
int string options_clear 0x7f0b001f int string options_clear 0x7f0b001f
int string options_exit 0x7f0b0020 int string options_exit 0x7f0b0020
int string options_register 0x7f0b001c int string options_register 0x7f0b001c
int string options_unregister 0x7f0b001d int string options_unregister 0x7f0b001d
int string register_button_text 0x7f0b007e int string register_button_text 0x7f0b007f
int string register_text_view_text_unregister 0x7f0b007f int string register_text_view_text_unregister 0x7f0b0080
int string registration_heading 0x7f0b0098 int string registration_heading 0x7f0b0099
int string server_register_error 0x7f0b001a int string server_register_error 0x7f0b001a
int string server_registered 0x7f0b0018 int string server_registered 0x7f0b0018
int string server_registering 0x7f0b0017 int string server_registering 0x7f0b0017
int string server_unregister_error 0x7f0b001b int string server_unregister_error 0x7f0b001b
int string server_unregistered 0x7f0b0019 int string server_unregistered 0x7f0b0019
int string server_util_req_type_get 0x7f0b0096 int string server_util_req_type_get 0x7f0b0097
int string server_util_req_type_post 0x7f0b0095 int string server_util_req_type_post 0x7f0b0096
int string shared_pref_client_id 0x7f0b005f int string shared_pref_client_id 0x7f0b005f
int string shared_pref_client_secret 0x7f0b0060 int string shared_pref_client_secret 0x7f0b0060
int string shared_pref_device_active 0x7f0b005e int string shared_pref_device_active 0x7f0b005e
@ -637,7 +637,7 @@ int string title_activity_authentication_error 0x7f0b0033
int string title_activity_available_operations 0x7f0b0037 int string title_activity_available_operations 0x7f0b0037
int string title_activity_display_device_info 0x7f0b0025 int string title_activity_display_device_info 0x7f0b0025
int string title_activity_entry 0x7f0b0028 int string title_activity_entry 0x7f0b0028
int string title_activity_log 0x7f0b0097 int string title_activity_log 0x7f0b0098
int string title_activity_notification 0x7f0b0034 int string title_activity_notification 0x7f0b0034
int string title_activity_notify 0x7f0b0035 int string title_activity_notify 0x7f0b0035
int string title_activity_register_successful 0x7f0b0027 int string title_activity_register_successful 0x7f0b0027
@ -653,6 +653,7 @@ int string toast_message_enter_server_address 0x7f0b0045
int string toast_message_pin_change_failed 0x7f0b0044 int string toast_message_pin_change_failed 0x7f0b0044
int string toast_message_pin_change_success 0x7f0b0043 int string toast_message_pin_change_success 0x7f0b0043
int string url 0x7f0b0026 int string url 0x7f0b0026
int string yes 0x7f0b008e
int style AppBaseTheme 0x7f0c0059 int style AppBaseTheme 0x7f0c0059
int style AppTheme 0x7f0c005a int style AppTheme 0x7f0c005a
int style ButtonText 0x7f0c005f int style ButtonText 0x7f0c005f

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1015 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 B

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<lint>
</lint>

@ -71,7 +71,7 @@
</LinearLayout> </LinearLayout>
<!-- Login Form Ends --> <!-- Login Form Ends -->
<TextView android:id="@+id/txtVw" <TextView android:id="@+id/severAddressLabel"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_below="@+id/linearLayout1" android:layout_below="@+id/linearLayout1"
android:layout_marginLeft="10dp" android:layout_marginLeft="10dp"
@ -87,7 +87,7 @@
android:id="@+id/etServerIP" android:id="@+id/etServerIP"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/txtVw" android:layout_below="@+id/severAddressLabel"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:layout_marginLeft="22dp" android:layout_marginLeft="22dp"
android:ems="10" android:ems="10"
@ -106,17 +106,6 @@
android:layout_below="@+id/etServerIP" android:layout_below="@+id/etServerIP"
android:text="Start Registration" /> android:text="Start Registration" />
<TextView
android:id="@+id/incompatibleError"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="gone"
android:layout_margin="10dp"
android:textColor="@android:color/background_dark"
android:gravity="center"
android:text="Welcome" />
</RelativeLayout> </RelativeLayout>
</ScrollView> </ScrollView>

@ -124,6 +124,7 @@
<string name="dialog_pin_confirmation_end"> as your PIN code?</string> <string name="dialog_pin_confirmation_end"> as your PIN code?</string>
<string name="dialog_init_confirmation">You have set your domain to </string> <string name="dialog_init_confirmation">You have set your domain to </string>
<string name="dialog_init_middle">Your device is a </string> <string name="dialog_init_middle">Your device is a </string>
<string name="dialog_init_device_type">Device type</string>
<string name="dialog_init_end"> device, are you sure you want to proceed ?</string> <string name="dialog_init_end"> device, are you sure you want to proceed ?</string>
<string name="dialog_init_end_general"> are you sure you want to proceed ?</string> <string name="dialog_init_end_general"> are you sure you want to proceed ?</string>
<string name="dialog_unregister">You are trying to unregister from EMM. Are you sure you want to proceed ?</string> <string name="dialog_unregister">You are trying to unregister from EMM. Are you sure you want to proceed ?</string>
@ -150,8 +151,8 @@
<string name="info_label_imsi">IMSI:</string> <string name="info_label_imsi">IMSI:</string>
<string name="info_label_os">OS:</string> <string name="info_label_os">OS:</string>
<string name="info_label_rooted">Rooted:</string> <string name="info_label_rooted">Rooted:</string>
<string name="info_label_rooted_answer_yes">Yes</string> <string name="yes">Yes</string>
<string name="info_label_rooted_answer_no">No</string> <string name="no">No</string>
<!-- BUTTON TITLES --> <!-- BUTTON TITLES -->
<string name="button_ok">OK</string> <string name="button_ok">OK</string>

@ -1,18 +1,18 @@
/* /**
~ Copyright (c) 2014, WSO2 Inc. (http://wso2.com/) All Rights Reserved. * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~ *
~ Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at * You may obtain a copy of the License at
~ *
~ http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
~ *
~ Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
~ limitations under the License. * limitations under the License.
*/ */
package org.wso2.cdm.agent; package org.wso2.cdm.agent;
import android.os.Bundle; import android.os.Bundle;

@ -1,18 +1,18 @@
/* /**
~ Copyright (c) 2014, WSO2 Inc. (http://wso2.com/) All Rights Reserved. * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~ *
~ Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at * You may obtain a copy of the License at
~ *
~ http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
~ *
~ Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
~ limitations under the License. * limitations under the License.
*/ */
package org.wso2.cdm.agent; package org.wso2.cdm.agent;
import java.util.HashMap; import java.util.HashMap;
@ -176,8 +176,8 @@ public class AlreadyRegisteredActivity extends SherlockActivity implements APIRe
AlertDialog.Builder builder = new AlertDialog.Builder( AlertDialog.Builder builder = new AlertDialog.Builder(
AlreadyRegisteredActivity.this); AlreadyRegisteredActivity.this);
builder.setMessage(getResources().getString(R.string.dialog_unregister)) builder.setMessage(getResources().getString(R.string.dialog_unregister))
.setNegativeButton(getResources().getString(R.string.info_label_rooted_answer_yes), dialogClickListener) .setNegativeButton(getResources().getString(R.string.yes), dialogClickListener)
.setPositiveButton(getResources().getString(R.string.info_label_rooted_answer_no), dialogClickListener).show(); .setPositiveButton(getResources().getString(R.string.no), dialogClickListener).show();
break; break;
case TAG_BTN_OPTIONS: case TAG_BTN_OPTIONS:
@ -418,7 +418,6 @@ public class AlreadyRegisteredActivity extends SherlockActivity implements APIRe
R.string.error_internal_server), R.string.error_internal_server),
getResources().getString(R.string.button_ok), getResources().getString(R.string.button_ok),
null); null);
alertDialog.show();
} else { } else {
Log.e(TAG, "The result is : " + result); Log.e(TAG, "The result is : " + result);
Log.e(TAG, "The responseStatus is : " + responseStatus); Log.e(TAG, "The responseStatus is : " + responseStatus);

@ -17,6 +17,7 @@ package org.wso2.cdm.agent;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.wso2.cdm.agent.R; import org.wso2.cdm.agent.R;
@ -28,9 +29,9 @@ import org.wso2.cdm.agent.services.AlarmReceiver;
import org.wso2.cdm.agent.utils.CommonDialogUtils; import org.wso2.cdm.agent.utils.CommonDialogUtils;
import org.wso2.cdm.agent.utils.CommonUtilities; import org.wso2.cdm.agent.utils.CommonUtilities;
import org.wso2.cdm.agent.utils.HTTPConnectorUtils; import org.wso2.cdm.agent.utils.HTTPConnectorUtils;
import org.wso2.cdm.agent.utils.Preference;
import org.wso2.cdm.agent.utils.ServerUtils; import org.wso2.cdm.agent.utils.ServerUtils;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlarmManager; import android.app.AlarmManager;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
@ -64,6 +65,9 @@ import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem; import com.actionbarsherlock.view.MenuItem;
import com.google.android.gcm.GCMRegistrar; import com.google.android.gcm.GCMRegistrar;
/**
* Activity that captures username, password and device ownership details
*/
public class AuthenticationActivity extends SherlockActivity implements APIAccessCallBack, public class AuthenticationActivity extends SherlockActivity implements APIAccessCallBack,
APIResultCallBack { APIResultCallBack {
@ -73,19 +77,16 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces
EditText username; EditText username;
EditText txtDomain; EditText txtDomain;
EditText password; EditText password;
// TextView txtLoadingEULA;
RadioButton radioBYOD, radioCOPE; RadioButton radioBYOD, radioCOPE;
String deviceType; String deviceType;
Context context; Context context;
String isAgreed = "";
String senderId = ""; String senderId = "";
String eula = "";
String usernameForRegister = ""; String usernameForRegister = "";
String usernameVal;
String passwordVal;
ProgressDialog progressDialog; ProgressDialog progressDialog;
AlertDialog.Builder alertDialog; AlertDialog.Builder alertDialog;
private final int TAG_BTN_AUTHENTICATE = 0;
@SuppressLint("NewApi")
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -94,10 +95,11 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces
getSupportActionBar().setCustomView(R.layout.custom_sherlock_bar); getSupportActionBar().setCustomView(R.layout.custom_sherlock_bar);
getSupportActionBar().setTitle(R.string.empty_app_title); getSupportActionBar().setTitle(R.string.empty_app_title);
View homeIcon = View homeIcon =
findViewById(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB (View) findViewById(
? android.R.id.home Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB
: R.id.abs__home); ? android.R.id.home
((View) homeIcon.getParent()).setVisibility(View.GONE); : R.id.abs__home).getParent();
homeIcon.setVisibility(View.GONE);
context = AuthenticationActivity.this; context = AuthenticationActivity.this;
deviceType = getResources().getString(R.string.device_enroll_type_byod); deviceType = getResources().getString(R.string.device_enroll_type_byod);
@ -110,8 +112,8 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces
txtDomain.requestFocus(); txtDomain.requestFocus();
authenticate = (Button) findViewById(R.id.btnRegister); authenticate = (Button) findViewById(R.id.btnRegister);
authenticate.setEnabled(false); authenticate.setEnabled(false);
authenticate.setTag(TAG_BTN_AUTHENTICATE);
authenticate.setOnClickListener(onClickAuthenticate); authenticate.setOnClickListener(onClickAuthenticate);
// change button color background till user enters a valid input
authenticate.setBackground(getResources().getDrawable(R.drawable.btn_grey)); authenticate.setBackground(getResources().getDrawable(R.drawable.btn_grey));
authenticate.setTextColor(getResources().getColor(R.color.black)); authenticate.setTextColor(getResources().getColor(R.color.black));
@ -155,19 +157,37 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces
public void onClick(View view) { public void onClick(View view) {
if (username.getText() != null && !username.getText().toString().trim().equals("") && if (username.getText() != null && !username.getText().toString().trim().equals("") &&
password.getText() != null && !password.getText().toString().trim().equals("")) { password.getText() != null && !password.getText().toString().trim().equals("")) {
passwordVal = password.getText().toString().trim();
if (txtDomain.getText() != null &&
!txtDomain.getText().toString().trim().equals("")) {
usernameVal =
username.getText().toString().trim() + "@" +
txtDomain.getText().toString().trim();
} else {
usernameVal = username.getText().toString().trim();
}
if (radioBYOD.isChecked()) { if (radioBYOD.isChecked()) {
deviceType = getResources().getString(R.string.device_enroll_type_byod); deviceType = getResources().getString(R.string.device_enroll_type_byod);
} else { } else {
deviceType = getResources().getString(R.string.device_enroll_type_cope); deviceType = getResources().getString(R.string.device_enroll_type_cope);
} }
AlertDialog.Builder builder = new AlertDialog.Builder(AuthenticationActivity.this); alertDialog =
builder.setMessage(getResources().getString(R.string.dialog_init_middle) + " " + CommonDialogUtils.getAlertDialogWithTwoButtonAndTitle(context,
deviceType + " " + getResources().getString(R.string.dialog_init_device_type),
getResources().getString(R.string.dialog_init_end)) getResources().getString(R.string.dialog_init_middle) +
.setNegativeButton(getResources().getString(R.string.info_label_rooted_answer_yes), " " +
dialogClickListener) deviceType +
.setPositiveButton(getResources().getString(R.string.info_label_rooted_answer_no), " " +
dialogClickListener).show(); getResources().getString(R.string.dialog_init_end),
getResources().getString(R.string.yes),
getResources().getString(R.string.no),
dialogClickListener,
dialogClickListener);
alertDialog.show();
} else { } else {
if (username.getText() != null && !username.getText().toString().trim().equals("")) { if (username.getText() != null && !username.getText().toString().trim().equals("")) {
Toast.makeText(context, Toast.makeText(context,
@ -183,6 +203,265 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces
} }
}; };
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
dialog.dismiss();
break;
case DialogInterface.BUTTON_NEGATIVE:
dialog.dismiss();
startAuthentication();
break;
}
}
};
/**
* Start authentication process.
*/
public void startAuthentication() {
Preference.put(context, getResources().getString(R.string.shared_pref_reg_type), deviceType);
// Check network connection availability before calling the API.
if (PhoneState.isNetworkAvailable(context)) {
authenticate();
} else {
CommonDialogUtils.stopProgressDialog(progressDialog);
CommonDialogUtils.showNetworkUnavailableMessage(context);
}
}
/**
* Communicating with the server to authenticate user.
*/
private void authenticate() {
AsyncTask<Void, Void, Map<String, String>> mLicenseTask =
new AsyncTask<Void, Void, Map<String, String>>() {
@Override
protected Map<String, String> doInBackground(Void... params) {
Map<String, String> response =
null;
Map<String, String> requestParametres =
new HashMap<String, String>();
requestParametres.put("username",
usernameVal);
requestParametres.put("password",
passwordVal);
response =
HTTPConnectorUtils.postData(context,
CommonUtilities.SERVER_URL +
CommonUtilities.SERVER_AUTHENTICATION_ENDPOINT,
requestParametres);
return response;
}
@Override
protected void onPreExecute() {
progressDialog =
ProgressDialog.show(context,
getResources().getString(R.string.dialog_authenticate),
getResources().getString(R.string.dialog_please_wait),
true);
};
@Override
protected void onPostExecute(Map<String, String> result) {
JSONObject response =
null;
if (result != null) {
String responseStatus =
result.get("status");
try {
if (responseStatus != null) {
if (responseStatus.equalsIgnoreCase(CommonUtilities.REQUEST_SUCCESSFUL)) {
response =
new JSONObject(
result.get("response"));
senderId =
response.getString("senderId");
getLicense();
} else if (responseStatus.equalsIgnoreCase(CommonUtilities.UNAUTHORIZED_ACCESS)) {
CommonDialogUtils.stopProgressDialog(progressDialog);
alertDialog =
CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context,
getResources().getString(R.string.title_head_authentication_error),
getResources().getString(R.string.error_authentication_failed),
getResources().getString(R.string.button_ok),
dialogClickListener);
} else if (responseStatus.trim()
.equals(CommonUtilities.INTERNAL_SERVER_ERROR)) {
CommonDialogUtils.stopProgressDialog(progressDialog);
showInternalServerErrorMessage();
} else {
Log.e(TAG,
"Status: " +
responseStatus);
showAuthCommonErrorMessage();
}
} else {
Log.e(TAG,
"The value of status is null in authenticate()");
showAuthCommonErrorMessage();
}
} catch (JSONException e) {
Log.e(TAG,
e.getMessage());
showAuthCommonErrorMessage();
}
} else {
Log.e(TAG,
"The result is null in authenticate()");
showAuthCommonErrorMessage();
}
}
};
mLicenseTask.execute();
}
/**
* Initialize get device license agreement. Check if the user has already
* agreed
* to license agreement
*/
private void getLicense() {
String isAgreed =
Preference.get(context,
getResources().getString(R.string.shared_pref_isagreed));
String type =
Preference.get(context,
getResources().getString(R.string.shared_pref_reg_type));
// No need to display license for COPE devices
if (type.trim().equals(getResources().getString(R.string.device_enroll_type_byod))) {
if (isAgreed == null) {
Map<String, String> requestParams = new HashMap<String, String>();
requestParams.put("domain", txtDomain.getText().toString().trim());
// Get License
OnCancelListener cancelListener = new OnCancelListener() {
@Override
public void onCancel(DialogInterface arg0) {
CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context,
getResources().getString(R.string.error_enrollment_failed_detail),
getResources().getString(R.string.error_enrollment_failed),
getResources().getString(R.string.button_ok),
null);
}
};
progressDialog =
CommonDialogUtils.showPrgressDialog(context,
getResources().getString(R.string.dialog_license_agreement),
getResources().getString(R.string.dialog_please_wait),
cancelListener);
// Check network connection availability before calling the API.
if (PhoneState.isNetworkAvailable(context)) {
getLicenseFromServer();
} else {
CommonDialogUtils.stopProgressDialog(progressDialog);
CommonDialogUtils.showNetworkUnavailableMessage(context);
}
} else {
loadPincodeAcitvity();
}
} else {
loadPincodeAcitvity();
}
}
/**
* Retriever license agreement details from the server
*/
private void getLicenseFromServer() {
AsyncTask<Void, Void, Map<String, String>> mLicenseTask =
new AsyncTask<Void, Void, Map<String, String>>() {
@Override
protected Map<String, String> doInBackground(Void... params) {
Map<String, String> response =
null;
response =
HTTPConnectorUtils.postData(context,
CommonUtilities.SERVER_URL +
CommonUtilities.LICENSE_ENDPOINT,
null);
return response;
}
@Override
protected void onPreExecute() {
};
@Override
protected void onPostExecute(Map<String, String> result) {
CommonDialogUtils.stopProgressDialog(progressDialog);
manipulateLicenseResponse(result);
}
};
mLicenseTask.execute();
}
/**
* Manipulates the License agreement response received from server.
*
* @param result
* the result of the license agreement request
*/
private void manipulateLicenseResponse(Map<String, String> result) {
String responseStatus;
CommonDialogUtils.stopProgressDialog(progressDialog);
String licenseAgreement = "";
if (result != null) {
responseStatus = result.get(CommonUtilities.STATUS_KEY);
if (responseStatus.equals(CommonUtilities.REQUEST_SUCCESSFUL)) {
licenseAgreement = result.get("response");
if (licenseAgreement != null) {
Preference.put(context, getResources().getString(R.string.shared_pref_eula),
licenseAgreement);
showAgreement(licenseAgreement, CommonUtilities.EULA_TITLE);
} else {
showErrorMessage(getResources().getString(R.string.error_enrollment_failed_detail),
getResources().getString(R.string.error_enrollment_failed));
}
} else if (responseStatus.equals(CommonUtilities.INTERNAL_SERVER_ERROR)) {
Log.e(TAG, "The result is : " + result);
showInternalServerErrorMessage();
} else {
showEnrollementFailedErrorMessage();
}
} else {
Log.e(TAG, "The result is null in manipulateLicenseResponse()");
showEnrollementFailedErrorMessage();
}
}
public void showErrorMessage(String message, String title) { public void showErrorMessage(String message, String title) {
AlertDialog.Builder builder = new AlertDialog.Builder(context); AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage(message); builder.setMessage(message);
@ -199,7 +478,7 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces
alert.show(); alert.show();
} }
public void showAlert(String message, String title) { public void showAgreement(String message, String title) {
final Dialog dialog = new Dialog(context); final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.custom_terms_popup); dialog.setContentView(R.layout.custom_terms_popup);
dialog.setTitle(CommonUtilities.EULA_TITLE); dialog.setTitle(CommonUtilities.EULA_TITLE);
@ -218,12 +497,8 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces
dialogButton.setOnClickListener(new OnClickListener() { dialogButton.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
SharedPreferences mainPref = Preference.put(context, getResources().getString(R.string.shared_pref_isagreed),
AuthenticationActivity.this.getSharedPreferences(getResources().getString(R.string.shared_pref_package), "1");
Context.MODE_PRIVATE);
Editor editor = mainPref.edit();
editor.putString(getResources().getString(R.string.shared_pref_isagreed), "1");
editor.commit();
dialog.dismiss(); dialog.dismiss();
loadPincodeAcitvity(); loadPincodeAcitvity();
} }
@ -253,6 +528,13 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces
dialog.show(); dialog.show();
} }
private void loadPincodeAcitvity() {
Intent intent = new Intent(AuthenticationActivity.this, PinCodeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra(getResources().getString(R.string.intent_extra_username), usernameVal);
startActivity(intent);
}
public void cancelEntry() { public void cancelEntry() {
SharedPreferences mainPref = SharedPreferences mainPref =
context.getSharedPreferences(getResources().getString(R.string.shared_pref_package), context.getSharedPreferences(getResources().getString(R.string.shared_pref_package),
@ -273,22 +555,6 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces
} }
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
dialog.dismiss();
break;
case DialogInterface.BUTTON_NEGATIVE:
dialog.dismiss();
startAuthentication();
break;
}
}
};
public void showAlertSingle(String message, String title) { public void showAlertSingle(String message, String title) {
AlertDialog.Builder builder = new AlertDialog.Builder(context); AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage(message); builder.setMessage(message);
@ -333,166 +599,8 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces
} }
/** /**
* Start Authentication. * Initialize the Android IDP sdk by passing user credentials,client ID and
*/ * client secret.
public void startAuthentication() {
final Context context = AuthenticationActivity.this;
SharedPreferences mainPref =
context.getSharedPreferences(getResources().getString(R.string.shared_pref_package),
Context.MODE_PRIVATE);
Editor editor = mainPref.edit();
editor.putString(getResources().getString(R.string.shared_pref_reg_type), deviceType);
editor.commit();
// Check network connection availability before calling the API.
if (PhoneState.isNetworkAvailable(context)) {
getOauthClientInfo();
} else {
CommonDialogUtils.stopProgressDialog(progressDialog);
CommonDialogUtils.showNetworkUnavailableMessage(AuthenticationActivity.this);
}
}
private void getOauthClientInfo() {
AsyncTask<Void, Void, Map<String, String>> mLicenseTask =
new AsyncTask<Void, Void, Map<String, String>>() {
@Override
protected Map<String, String> doInBackground(Void... params) {
Map<String, String> response =
null;
if (txtDomain.getText() != null &&
!txtDomain.getText()
.toString()
.trim()
.equals("")) {
response =
HTTPConnectorUtils.getClientKey(username.getText()
.toString()
.trim() +
"@" +
txtDomain.getText()
.toString()
.trim(),
password.getText()
.toString()
.trim(),
context);
} else {
response =
HTTPConnectorUtils.getClientKey(username.getText()
.toString()
.trim(),
password.getText()
.toString()
.trim(),
context);
}
return response;
}
@Override
protected void onPreExecute() {
progressDialog =
ProgressDialog.show(AuthenticationActivity.this,
getResources().getString(R.string.dialog_authenticate),
getResources().getString(R.string.dialog_please_wait),
true);
};
@Override
protected void onPostExecute(Map<String, String> result) {
JSONObject response =
null;
String clienKey = "";
String clientSecret = "";
if (result != null) {
String responseStatus =
result.get("status");
try {
if (responseStatus != null) {
if (responseStatus.equalsIgnoreCase(CommonUtilities.REQUEST_SUCCESSFUL)) {
response =
new JSONObject(
result.get("response"));
clienKey =
response.getString("clientkey");
clientSecret =
response.getString("clientsecret");
SharedPreferences mainPref =
AuthenticationActivity.this.getSharedPreferences(getResources().getString(R.string.shared_pref_package),
Context.MODE_PRIVATE);
Editor editor =
mainPref.edit();
editor.putString(getResources().getString(R.string.shared_pref_client_id),
clienKey);
editor.putString(getResources().getString(R.string.shared_pref_client_secret),
clientSecret);
editor.commit();
CommonUtilities.CLIENT_ID =
clienKey;
CommonUtilities.CLIENT_SECRET =
clientSecret;
initializeIDPLib(clienKey,
clientSecret);
} else if (responseStatus.equalsIgnoreCase(CommonUtilities.UNAUTHORIZED_ACCESS)) {
CommonDialogUtils.stopProgressDialog(progressDialog);
alertDialog =
CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context,
getResources().getString(R.string.title_head_authentication_error),
getResources().getString(R.string.error_authentication_failed),
getResources().getString(R.string.button_ok),
dialogClickListener);
alertDialog.show();
} else if (responseStatus.trim()
.equals(CommonUtilities.INTERNAL_SERVER_ERROR)) {
CommonDialogUtils.stopProgressDialog(progressDialog);
showInternalServerErrorMessage();
} else {
Log.e(TAG,
"Status: " +
responseStatus);
showAuthCommonErrorMessage();
}
} else {
Log.e(TAG,
"The value of status is null in getOauthClientInfo()");
showAuthCommonErrorMessage();
}
} catch (JSONException e) {
Log.e(TAG,
e.getMessage());
showAuthCommonErrorMessage();
}
} else {
Log.e(TAG,
"The result is null in getOauthClientInfo()");
showAuthCommonErrorMessage();
}
}
};
mLicenseTask.execute();
}
/**
* Initialize the Android IDP sdk by passing user credentials,client ID and
* client secret.
*/ */
private void initializeIDPLib(String clientKey, String clientSecret) { private void initializeIDPLib(String clientKey, String clientSecret) {
Log.e("", "initializeIDPLib"); Log.e("", "initializeIDPLib");
@ -523,7 +631,6 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces
} }
} }
@SuppressLint("NewApi")
public void enableSubmitIfReady() { public void enableSubmitIfReady() {
boolean isReady = false; boolean isReady = false;
@ -611,113 +718,6 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces
} }
} }
/**
* Manipulates the License agreement response.
*
* @param result
* the result of the license agreement request
*/
private void manipulateLicenseResponse(Map<String, String> result) {
String responseStatus;
CommonDialogUtils.stopProgressDialog(progressDialog);
Log.e("get licence", "res");
String licenseAgreement = "";
if (result != null) {
responseStatus = result.get(CommonUtilities.STATUS_KEY);
if (responseStatus.equals(CommonUtilities.REQUEST_SUCCESSFUL)) {
licenseAgreement = result.get("response");
SharedPreferences mainPref =
AuthenticationActivity.this.getSharedPreferences(getResources().getString(R.string.shared_pref_package),
Context.MODE_PRIVATE);
Editor editor = mainPref.edit();
editor.putString(getResources().getString(R.string.shared_pref_eula),
licenseAgreement);
editor.commit();
if (licenseAgreement != null &&
(!licenseAgreement.equals(CommonUtilities.EMPTY_STRING) && !licenseAgreement.equals(CommonUtilities.NULL_STRING))) {
showAlert(licenseAgreement, CommonUtilities.EULA_TITLE);
} else {
showErrorMessage(getResources().getString(R.string.error_enrollment_failed_detail),
getResources().getString(R.string.error_enrollment_failed));
}
} else if (responseStatus.equals(CommonUtilities.INTERNAL_SERVER_ERROR)) {
Log.e(TAG, "The result is : " + result);
showInternalServerErrorMessage();
} else {
showEnrollementFailedErrorMessage();
}
} else {
Log.e(TAG, "The result is null in manipulateLicenseResponse()");
showEnrollementFailedErrorMessage();
}
}
/**
* Manipulates the sender ID response.
*
* @param result
* the result of the sender ID request
*/
private void manipulateSenderIdResponse(Map<String, String> result) {
String responseStatus;
JSONObject response;
String mode = "";
Float interval = (float) 1.0;
CommonDialogUtils.stopProgressDialog(progressDialog);
if (result != null) {
responseStatus = result.get(CommonUtilities.STATUS_KEY);
if (responseStatus.equals(CommonUtilities.REQUEST_SUCCESSFUL)) {
try {
response = new JSONObject(result.get("response"));
senderId = response.getString("sender_id");
mode = response.getString("notifier");
interval = (float) Float.parseFloat(response.getString("notifierInterval"));
} catch (JSONException e) {
e.printStackTrace();
}
SharedPreferences mainPref =
context.getSharedPreferences(getResources().getString(R.string.shared_pref_package),
Context.MODE_PRIVATE);
Editor editor = mainPref.edit();
if (senderId != null && !senderId.equals("")) {
CommonUtilities.setSENDER_ID(senderId);
GCMRegistrar.register(context, senderId);
editor.putString(getResources().getString(R.string.shared_pref_sender_id),
senderId);
}
editor.putString(getResources().getString(R.string.shared_pref_message_mode), mode);
editor.putFloat(getResources().getString(R.string.shared_pref_interval), interval);
editor.commit();
managePushNotification(mode, interval, editor);
getLicense();
} else if (responseStatus.equals(CommonUtilities.INTERNAL_SERVER_ERROR)) {
Log.e(TAG, "The result is : " + result);
showInternalServerErrorMessage();
} else {
Log.e(TAG, "The result is : " + result);
showEnrollementFailedErrorMessage();
}
} else {
Log.e(TAG, "The result is null in manipulateSenderIdResponse()");
showEnrollementFailedErrorMessage();
}
}
private void showEnrollementFailedErrorMessage() { private void showEnrollementFailedErrorMessage() {
CommonDialogUtils.stopProgressDialog(progressDialog); CommonDialogUtils.stopProgressDialog(progressDialog);
alertDialog = alertDialog =
@ -726,7 +726,6 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces
getResources().getString(R.string.error_enrollment_failed_detail), getResources().getString(R.string.error_enrollment_failed_detail),
getResources().getString(R.string.button_ok), getResources().getString(R.string.button_ok),
senderIdFailedClickListener); senderIdFailedClickListener);
alertDialog.show();
} }
private void managePushNotification(String mode, float interval, Editor editor) { private void managePushNotification(String mode, float interval, Editor editor) {
@ -753,81 +752,6 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces
// } // }
} }
/**
* Gets device License agreement.
*
*/
private void getLicense() {
Log.e("get licence", "get licence");
SharedPreferences mainPref =
context.getSharedPreferences(getResources().getString(R.string.shared_pref_package),
Context.MODE_PRIVATE);
isAgreed = mainPref.getString(getResources().getString(R.string.shared_pref_isagreed), "");
String eula = mainPref.getString(getResources().getString(R.string.shared_pref_eula), "");
String type =
mainPref.getString(getResources().getString(R.string.shared_pref_reg_type),
"");
if (type.trim().equals(getResources().getString(R.string.device_enroll_type_byod))) {
if (!isAgreed.equals("1")) {
Map<String, String> requestParams = new HashMap<String, String>();
requestParams.put("domain", txtDomain.getText().toString().trim());
// Get License
OnCancelListener cancelListener = new OnCancelListener() {
@Override
public void onCancel(DialogInterface arg0) {
showAlertSingle(getResources().getString(R.string.error_enrollment_failed_detail),
getResources().getString(R.string.error_enrollment_failed));
// finish();
}
};
progressDialog =
CommonDialogUtils.showPrgressDialog(AuthenticationActivity.this,
getResources().getString(R.string.dialog_license_agreement),
getResources().getString(R.string.dialog_please_wait),
cancelListener);
// Check network connection availability before calling the API.
if (PhoneState.isNetworkAvailable(context)) {
// Call device license agreement API.
ServerUtils.callSecuredAPI(AuthenticationActivity.this,
CommonUtilities.LICENSE_ENDPOINT,
CommonUtilities.GET_METHOD, requestParams,
AuthenticationActivity.this,
CommonUtilities.LICENSE_REQUEST_CODE);
} else {
CommonDialogUtils.stopProgressDialog(progressDialog);
CommonDialogUtils.showNetworkUnavailableMessage(AuthenticationActivity.this);
}
} else {
loadPincodeAcitvity();
}
} else {
loadPincodeAcitvity();
}
}
private void loadPincodeAcitvity() {
Intent intent = new Intent(AuthenticationActivity.this, PinCodeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
if (txtDomain.getText() != null && !txtDomain.getText().toString().trim().equals("")) {
intent.putExtra(getResources().getString(R.string.intent_extra_username),
username.getText().toString().trim() + "@" +
txtDomain.getText().toString().trim());
} else {
intent.putExtra(getResources().getString(R.string.intent_extra_username),
username.getText().toString().trim());
}
startActivity(intent);
}
@Override @Override
public void onAPIAccessRecive(String status) { public void onAPIAccessRecive(String status) {
if (status != null) { if (status != null) {
@ -865,7 +789,6 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces
getResources().getString(R.string.error_authentication_failed), getResources().getString(R.string.error_authentication_failed),
getResources().getString(R.string.button_ok), getResources().getString(R.string.button_ok),
dialogClickListener); dialogClickListener);
alertDialog.show();
} else if (status.trim().equals(CommonUtilities.INTERNAL_SERVER_ERROR)) { } else if (status.trim().equals(CommonUtilities.INTERNAL_SERVER_ERROR)) {
showInternalServerErrorMessage(); showInternalServerErrorMessage();
@ -889,7 +812,6 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces
getResources().getString(R.string.error_internal_server), getResources().getString(R.string.error_internal_server),
getResources().getString(R.string.button_ok), getResources().getString(R.string.button_ok),
null); null);
alertDialog.show();
} }
/** /**
@ -904,7 +826,6 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces
getResources().getString(R.string.error_for_all_unknown_authentication_failures), getResources().getString(R.string.error_for_all_unknown_authentication_failures),
getResources().getString(R.string.button_ok), getResources().getString(R.string.button_ok),
null); null);
alertDialog.show();
} }
@ -931,4 +852,65 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces
} }
/**
* Manipulates the sender ID response.
*
* @param result
* the result of the sender ID request
*/
private void manipulateSenderIdResponse(Map<String, String> result) {
String responseStatus;
JSONObject response;
String mode = "";
Float interval = (float) 1.0;
CommonDialogUtils.stopProgressDialog(progressDialog);
if (result != null) {
responseStatus = result.get(CommonUtilities.STATUS_KEY);
if (responseStatus.equals(CommonUtilities.REQUEST_SUCCESSFUL)) {
try {
response = new JSONObject(result.get("response"));
senderId = response.getString("sender_id");
mode = response.getString("notifier");
interval = (float) Float.parseFloat(response.getString("notifierInterval"));
} catch (JSONException e) {
e.printStackTrace();
}
SharedPreferences mainPref =
context.getSharedPreferences(getResources().getString(R.string.shared_pref_package),
Context.MODE_PRIVATE);
Editor editor = mainPref.edit();
if (senderId != null && !senderId.equals("")) {
CommonUtilities.setSENDER_ID(senderId);
GCMRegistrar.register(context, senderId);
editor.putString(getResources().getString(R.string.shared_pref_sender_id),
senderId);
}
editor.putString(getResources().getString(R.string.shared_pref_message_mode), mode);
editor.putFloat(getResources().getString(R.string.shared_pref_interval), interval);
editor.commit();
managePushNotification(mode, interval, editor);
getLicense();
} else if (responseStatus.equals(CommonUtilities.INTERNAL_SERVER_ERROR)) {
Log.e(TAG, "The result is : " + result);
showInternalServerErrorMessage();
} else {
Log.e(TAG, "The result is : " + result);
showEnrollementFailedErrorMessage();
}
} else {
Log.e(TAG, "The result is null in manipulateSenderIdResponse()");
showEnrollementFailedErrorMessage();
}
}
} }

@ -1,18 +1,18 @@
/* /**
~ Copyright (c) 2014, WSO2 Inc. (http://wso2.com/) All Rights Reserved. * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~ *
~ Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at * You may obtain a copy of the License at
~ *
~ http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
~ *
~ Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
~ limitations under the License. * limitations under the License.
*/ */
package org.wso2.cdm.agent; package org.wso2.cdm.agent;
import android.app.Activity; import android.app.Activity;

@ -1,18 +1,18 @@
/* /**
~ Copyright (c) 2014, WSO2 Inc. (http://wso2.com/) All Rights Reserved. * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~ *
~ Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at * You may obtain a copy of the License at
~ *
~ http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
~ *
~ Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
~ limitations under the License. * limitations under the License.
*/ */
package org.wso2.cdm.agent; package org.wso2.cdm.agent;
import org.json.JSONArray; import org.json.JSONArray;
@ -78,7 +78,7 @@ public class DisplayDeviceInfoActivity extends Activity {
sdk.setText(getResources().getString(R.string.info_label_imsi)+" "+operators); sdk.setText(getResources().getString(R.string.info_label_imsi)+" "+operators);
} }
os.setText(getResources().getString(R.string.info_label_os)+" "+deviceInfo.getOsVersion()); os.setText(getResources().getString(R.string.info_label_os)+" "+deviceInfo.getOsVersion());
root.setText(getResources().getString(R.string.info_label_rooted)+" "+(deviceInfo.isRooted()?getResources().getString(R.string.info_label_rooted_answer_yes):getResources().getString(R.string.info_label_rooted_answer_no))); root.setText(getResources().getString(R.string.info_label_rooted)+" "+(deviceInfo.isRooted()?getResources().getString(R.string.yes):getResources().getString(R.string.no)));
Bundle extras = getIntent().getExtras(); Bundle extras = getIntent().getExtras();
if (extras != null) { if (extras != null) {

@ -1,18 +1,18 @@
/* /**
~ Copyright (c) 2014, WSO2 Inc. (http://wso2.com/) All Rights Reserved. * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~ *
~ Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at * You may obtain a copy of the License at
~ *
~ http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
~ *
~ Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
~ limitations under the License. * limitations under the License.
*/ */
package org.wso2.cdm.agent; package org.wso2.cdm.agent;

@ -1,18 +1,18 @@
/* /**
~ Copyright (c) 2014, WSO2 Inc. (http://wso2.com/) All Rights Reserved. * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~ *
~ Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at * You may obtain a copy of the License at
~ *
~ http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
~ *
~ Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
~ limitations under the License. * limitations under the License.
*/ */
package org.wso2.cdm.agent; package org.wso2.cdm.agent;
import org.wso2.cdm.agent.R; import org.wso2.cdm.agent.R;

@ -1,18 +1,18 @@
/* /**
~ Copyright (c) 2014, WSO2 Inc. (http://wso2.com/) All Rights Reserved. * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~ *
~ Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at * You may obtain a copy of the License at
~ *
~ http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
~ *
~ Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
~ limitations under the License. * limitations under the License.
*/ */
package org.wso2.cdm.agent; package org.wso2.cdm.agent;

@ -1,18 +1,18 @@
/* /**
~ Copyright (c) 2014, WSO2 Inc. (http://wso2.com/) All Rights Reserved. * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~ *
~ Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at * You may obtain a copy of the License at
~ *
~ http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
~ *
~ Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
~ limitations under the License. * limitations under the License.
*/ */
package org.wso2.cdm.agent; package org.wso2.cdm.agent;
@ -35,7 +35,9 @@ import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import org.wso2.cdm.agent.R; import org.wso2.cdm.agent.R;
import org.wso2.cdm.agent.utils.Preference;
public class PinCodeActivity extends Activity { public class PinCodeActivity extends Activity {
private TextView lblPin; private TextView lblPin;
@ -47,13 +49,14 @@ public class PinCodeActivity extends Activity {
private final int TAG_BTN_SET_PIN = 0; private final int TAG_BTN_SET_PIN = 0;
private String FROM_ACTIVITY = null; private String FROM_ACTIVITY = null;
private String MAIN_ACTIVITY = null; private String MAIN_ACTIVITY = null;
Context context;
@SuppressLint("NewApi") @SuppressLint("NewApi")
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pin_code); setContentView(R.layout.activity_pin_code);
context=PinCodeActivity.this;
Bundle extras = getIntent().getExtras(); Bundle extras = getIntent().getExtras();
if (extras != null) { if (extras != null) {
if (extras.containsKey(getResources().getString(R.string.intent_extra_username))) { if (extras.containsKey(getResources().getString(R.string.intent_extra_username))) {
@ -73,7 +76,6 @@ public class PinCodeActivity extends Activity {
} }
} }
//initializeComponents();
lblPin = (TextView) findViewById(R.id.lblPin); lblPin = (TextView) findViewById(R.id.lblPin);
txtPin = (EditText) findViewById(R.id.txtPinCode); txtPin = (EditText) findViewById(R.id.txtPinCode);
txtOldPin = (EditText) findViewById(R.id.txtOldPinCode); txtOldPin = (EditText) findViewById(R.id.txtOldPinCode);
@ -146,22 +148,6 @@ public class PinCodeActivity extends Activity {
} }
} }
/**
* Initializes UI components.
*
*/
private void initializeComponents() {
lblPin = (TextView) findViewById(R.id.lblPin);
txtPin = (EditText) findViewById(R.id.txtPinCode);
txtOldPin = (EditText) findViewById(R.id.txtOldPinCode);
btnPin = (Button) findViewById(R.id.btnSetPin);
btnPin.setTag(TAG_BTN_SET_PIN);
btnPin.setOnClickListener(onClickListener_BUTTON_CLICKED);
btnPin.setEnabled(false);
btnPin.setBackground(getResources().getDrawable(R.drawable.btn_grey));
btnPin.setTextColor(getResources().getColor(R.color.black));
}
OnClickListener onClickListener_BUTTON_CLICKED = new OnClickListener() { OnClickListener onClickListener_BUTTON_CLICKED = new OnClickListener() {
@Override @Override
@ -177,8 +163,8 @@ public class PinCodeActivity extends Activity {
getResources().getString(R.string.dialog_pin_confirmation) getResources().getString(R.string.dialog_pin_confirmation)
+ " " +txtPin.getText().toString() + " " + " " +txtPin.getText().toString() + " "
+ getResources().getString(R.string.dialog_pin_confirmation_end)) + getResources().getString(R.string.dialog_pin_confirmation_end))
.setPositiveButton(getResources().getString(R.string.info_label_rooted_answer_yes), dialogClickListener) .setPositiveButton(getResources().getString(R.string.yes), dialogClickListener)
.setNegativeButton(getResources().getString(R.string.info_label_rooted_answer_no), dialogClickListener).show(); .setNegativeButton(getResources().getString(R.string.no), dialogClickListener).show();
break; break;
default: default:
break; break;
@ -203,12 +189,7 @@ public class PinCodeActivity extends Activity {
}; };
public void savePin() { public void savePin() {
Preference.put(context, getResources().getString(R.string.shared_pref_pin), txtPin.getText().toString().trim());
SharedPreferences mainPref = this.getSharedPreferences(getResources().getString(R.string.shared_pref_package),
Context.MODE_PRIVATE);
Editor editor = mainPref.edit();
editor.putString(getResources().getString(R.string.shared_pref_pin), txtPin.getText().toString().trim());
editor.commit();
if(FROM_ACTIVITY != null && (FROM_ACTIVITY.equals(AlreadyRegisteredActivity.class.getSimpleName()))){ if(FROM_ACTIVITY != null && (FROM_ACTIVITY.equals(AlreadyRegisteredActivity.class.getSimpleName()))){
Toast.makeText(getApplicationContext(), getResources().getString(R.string.toast_message_pin_change_success), Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(), getResources().getString(R.string.toast_message_pin_change_success), Toast.LENGTH_SHORT).show();

@ -1,19 +1,20 @@
/* /**
~ Copyright (c) 2014, WSO2 Inc. (http://wso2.com/) All Rights Reserved. * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~ *
~ Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at * You may obtain a copy of the License at
~ *
~ http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
~ *
~ Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
~ limitations under the License. * limitations under the License.
*/ */
package org.wso2.cdm.agent; package org.wso2.cdm.agent;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -23,108 +24,68 @@ import org.wso2.cdm.agent.R;
import org.wso2.cdm.agent.api.DeviceInfo; import org.wso2.cdm.agent.api.DeviceInfo;
import org.wso2.cdm.agent.api.PhoneState; import org.wso2.cdm.agent.api.PhoneState;
import org.wso2.cdm.agent.proxy.APIResultCallBack; import org.wso2.cdm.agent.proxy.APIResultCallBack;
import org.wso2.cdm.agent.services.WSO2DeviceAdminReceiver;
import org.wso2.cdm.agent.utils.CommonDialogUtils; import org.wso2.cdm.agent.utils.CommonDialogUtils;
import org.wso2.cdm.agent.utils.CommonUtilities; import org.wso2.cdm.agent.utils.CommonUtilities;
import org.wso2.cdm.agent.utils.HTTPConnectorUtils;
import org.wso2.cdm.agent.utils.Preference;
import org.wso2.cdm.agent.utils.ServerUtils; import org.wso2.cdm.agent.utils.ServerUtils;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.app.admin.DevicePolicyManager; import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
public class RegistrationActivity extends Activity implements APIResultCallBack { public class RegistrationActivity extends Activity implements APIResultCallBack {
private String TAG = RegistrationActivity.class.getSimpleName(); private String TAG = RegistrationActivity.class.getSimpleName();
String regId = ""; String regId = "";
String username = ""; String username = "";
TextView mDisplay; Context context;
Context context; boolean regState = false;
boolean regState = false; ProgressDialog progressDialog;
boolean successFlag = false; AlertDialog.Builder alertDialog;
Button btnEnroll = null;
RelativeLayout btnLayout = null;
ProgressDialog progressDialog;
AlertDialog.Builder alertDialog;
static final int ACTIVATION_REQUEST = 47; // identifies our request id
DevicePolicyManager devicePolicyManager;
ComponentName demoDeviceAdmin;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
demoDeviceAdmin = new ComponentName(this, WSO2DeviceAdminReceiver.class);
context = this;
Bundle extras = getIntent().getExtras();
if (extras != null) {
if (extras.containsKey(getResources().getString(
R.string.intent_extra_username))) {
username = extras.getString(getResources().getString(
R.string.intent_extra_username));
}
}
SharedPreferences mainPref = this.getSharedPreferences( getResources().getString(R.string.shared_pref_package), Context.MODE_PRIVATE);
regId = mainPref.getString(getResources().getString(R.string.shared_pref_regId), "");
//Enroll automatically
final Context context = RegistrationActivity.this;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
context = this;
regId = Preference.get(context,getResources().getString(R.string.shared_pref_regId));
registerDevice(); registerDevice();
}
btnEnroll = (Button)findViewById(R.id.btnEnroll);
btnLayout = (RelativeLayout)findViewById(R.id.enrollPanel);
//ImageView optionBtn = (ImageView) findViewById(R.id.option_button);
btnEnroll.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//registrateDevice();
}
});
}
private void registerDevice() { private void registerDevice() {
progressDialog = CommonDialogUtils.showPrgressDialog( progressDialog =
RegistrationActivity.this, CommonDialogUtils.showPrgressDialog(RegistrationActivity.this,
getResources().getString(R.string.dialog_enrolling), getResources().getString(R.string.dialog_enrolling),
getResources().getString(R.string.dialog_please_wait), null); getResources().getString(R.string.dialog_please_wait),
null);
progressDialog.show(); progressDialog.show();
DeviceInfo deviceInfo = new DeviceInfo(RegistrationActivity.this); DeviceInfo deviceInfo = new DeviceInfo(RegistrationActivity.this);
JSONObject jsObject = new JSONObject(); JSONObject jsObject = new JSONObject();
String osVersion = ""; String osVersion = "";
SharedPreferences mainPref = RegistrationActivity.this SharedPreferences mainPref =
.getSharedPreferences(RegistrationActivity.this.getResources() RegistrationActivity.this.getSharedPreferences(RegistrationActivity.this.getResources()
.getString(R.string.shared_pref_package), .getString(R.string.shared_pref_package),
Context.MODE_PRIVATE); Context.MODE_PRIVATE);
String type = mainPref.getString(RegistrationActivity.this String type =
.getResources().getString(R.string.shared_pref_reg_type), ""); mainPref.getString(RegistrationActivity.this.getResources()
.getString(R.string.shared_pref_reg_type),
"");
osVersion = deviceInfo.getOsVersion(); osVersion = deviceInfo.getOsVersion();
try { try {
@ -146,15 +107,15 @@ public class RegistrationActivity extends Activity implements APIResultCallBack
// Check network connection availability before calling the API. // Check network connection availability before calling the API.
if (PhoneState.isNetworkAvailable(context)) { if (PhoneState.isNetworkAvailable(context)) {
// Call device registration API. // Call device registration API.
ServerUtils.callSecuredAPI(RegistrationActivity.this, sendDeviceDetails(requestParams);
CommonUtilities.REGISTER_ENDPOINT, // ServerUtils.callSecuredAPI(RegistrationActivity.this,
CommonUtilities.POST_METHOD, requestParams, // CommonUtilities.REGISTER_ENDPOINT,
RegistrationActivity.this, // CommonUtilities.POST_METHOD, requestParams,
CommonUtilities.REGISTER_REQUEST_CODE); // RegistrationActivity.this,
// CommonUtilities.REGISTER_REQUEST_CODE);
} else { } else {
CommonDialogUtils.stopProgressDialog(progressDialog); CommonDialogUtils.stopProgressDialog(progressDialog);
CommonDialogUtils CommonDialogUtils.showNetworkUnavailableMessage(RegistrationActivity.this);
.showNetworkUnavailableMessage(RegistrationActivity.this);
} }
} catch (JSONException e) { } catch (JSONException e) {
@ -163,38 +124,116 @@ public class RegistrationActivity extends Activity implements APIResultCallBack
} }
@Override private void sendDeviceDetails(final Map<String, String> requestParams) {
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) { AsyncTask<Void, Void, Map<String, String>> mLicenseTask =
Intent i = new Intent(); new AsyncTask<Void, Void, Map<String, String>>() {
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME); @Override
this.startActivity(i); protected Map<String, String> doInBackground(Void... params) {
finish(); Map<String, String> response;
return true; response =
} HTTPConnectorUtils.postData(context,CommonUtilities.SERVER_URL+CommonUtilities.REGISTER_ENDPOINT,requestParams
else if (keyCode == KeyEvent.KEYCODE_HOME) { );
finish(); return response;
return true; }
}
return super.onKeyDown(keyCode, event); @Override
} protected void onPreExecute() {};
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { protected void onPostExecute(Map<String, String> result) {
return true; CommonDialogUtils.stopProgressDialog(progressDialog);
manipulateDeviceDetails(result);
}
};
mLicenseTask.execute();
}
private void manipulateDeviceDetails(Map<String, String> result){
CommonDialogUtils.stopProgressDialog(progressDialog);
String responseStatus = "";
if (result != null) {
responseStatus = result.get(CommonUtilities.STATUS_KEY);
if (responseStatus.equals(CommonUtilities.REGISTERATION_SUCCESSFUL)) {
Intent intent =
new Intent(RegistrationActivity.this,
AlreadyRegisteredActivity.class);
intent.putExtra(getResources().getString(R.string.intent_extra_fresh_reg_flag),
true);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
} else if (responseStatus.equals(CommonUtilities.INTERNAL_SERVER_ERROR)) {
Log.e(TAG, "The value of status is : " + responseStatus);
alertDialog =
CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context,
getResources().getString(R.string.title_head_connection_error),
getResources().getString(R.string.error_internal_server),
getResources().getString(R.string.button_ok),
registrationFailedOKBtnClickListerner);
} else {
Log.e(TAG, "The value of status is : " + responseStatus);
Log.e(TAG, "The responseStatus is : " + responseStatus);
alertDialog =
CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context,
getResources().getString(R.string.title_head_registration_error),
getResources().getString(R.string.error_for_all_unknown_registration_failures),
getResources().getString(R.string.button_ok),
registrationFailedOKBtnClickListerner);
alertDialog.show();
}
} else {
Log.e(TAG, "The result is null in onReceiveAPIResult(). ");
Log.e(TAG, "The responseStatus is : " + responseStatus);
alertDialog =
CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context,
getResources().getString(R.string.title_head_registration_error),
getResources().getString(R.string.error_for_all_unknown_registration_failures),
getResources().getString(R.string.button_ok),
registrationFailedOKBtnClickListerner);
alertDialog.show();
}
} }
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
Intent i = new Intent();
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
this.startActivity(i);
finish();
return true;
} else if (keyCode == KeyEvent.KEYCODE_HOME) {
finish();
return true;
}
return super.onKeyDown(keyCode, event);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return true;
}
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
DialogInterface.OnClickListener registrationFailedOKBtnClickListerner = new DialogInterface.OnClickListener() { DialogInterface.OnClickListener registrationFailedOKBtnClickListerner =
@Override new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) { @Override
loadAuthenticationErrorActivity(); public void onClick(DialogInterface arg0,
} int arg1) {
}; loadAuthenticationErrorActivity();
}
};
@Override @Override
public void onReceiveAPIResult(Map<String, String> result, int requestCode) { public void onReceiveAPIResult(Map<String, String> result, int requestCode) {
@ -203,66 +242,44 @@ public class RegistrationActivity extends Activity implements APIResultCallBack
if (result != null) { if (result != null) {
responseStatus = result.get(CommonUtilities.STATUS_KEY); responseStatus = result.get(CommonUtilities.STATUS_KEY);
if (requestCode == CommonUtilities.REGISTER_REQUEST_CODE) {
if (responseStatus.equals(CommonUtilities.REGISTERATION_SUCCESSFUL)) { if (responseStatus.equals(CommonUtilities.REGISTERATION_SUCCESSFUL)) {
Intent intent = new Intent(RegistrationActivity.this,AlreadyRegisteredActivity.class); Intent intent =
intent.putExtra(getResources().getString(R.string.intent_extra_fresh_reg_flag), true); new Intent(RegistrationActivity.this,
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); AlreadyRegisteredActivity.class);
startActivity(intent); intent.putExtra(getResources().getString(R.string.intent_extra_fresh_reg_flag),
//finish(); true);
} else if (responseStatus intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
.equals(CommonUtilities.INTERNAL_SERVER_ERROR)) { startActivity(intent);
// finish();
} else if (responseStatus.equals(CommonUtilities.INTERNAL_SERVER_ERROR)) {
Log.e(TAG, "The value of status is : " + responseStatus); Log.e(TAG, "The value of status is : " + responseStatus);
alertDialog = CommonDialogUtils alertDialog =
.getAlertDialogWithOneButtonAndTitle( CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context,
context, getResources().getString(R.string.title_head_connection_error),
getResources().getString( getResources().getString(R.string.error_internal_server),
R.string.title_head_connection_error), getResources().getString(R.string.button_ok),
getResources().getString( registrationFailedOKBtnClickListerner);
R.string.error_internal_server),
getResources().getString(R.string.button_ok),
registrationFailedOKBtnClickListerner);
alertDialog.show(); alertDialog.show();
} else { } else {
Log.e(TAG, "The value of status is : " + responseStatus); Log.e(TAG, "The value of status is : " + responseStatus);
Log.e(TAG, "The responseStatus is : " + responseStatus); Log.e(TAG, "The responseStatus is : " + responseStatus);
alertDialog = CommonDialogUtils alertDialog =
.getAlertDialogWithOneButtonAndTitle( CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context,
context, getResources().getString(R.string.title_head_registration_error),
getResources().getString( getResources().getString(R.string.error_for_all_unknown_registration_failures),
R.string.title_head_registration_error), getResources().getString(R.string.button_ok),
getResources().getString( registrationFailedOKBtnClickListerner);
R.string.error_for_all_unknown_registration_failures), }
getResources().getString(R.string.button_ok),
registrationFailedOKBtnClickListerner);
alertDialog.show();
}
} else {
Log.e(TAG, "The result is : " + result);
Log.e(TAG, "The responseStatus is : " + responseStatus);
alertDialog = CommonDialogUtils
.getAlertDialogWithOneButtonAndTitle(
context,
getResources().getString(
R.string.title_head_registration_error),
getResources().getString(
R.string.error_for_all_unknown_registration_failures),
getResources().getString(R.string.button_ok),
registrationFailedOKBtnClickListerner);
alertDialog.show();
}
} else { } else {
Log.e(TAG, "The result is null in onReceiveAPIResult(). "); Log.e(TAG, "The result is null in onReceiveAPIResult(). ");
Log.e(TAG, "The responseStatus is : " + responseStatus); Log.e(TAG, "The responseStatus is : " + responseStatus);
alertDialog = CommonDialogUtils alertDialog =
.getAlertDialogWithOneButtonAndTitle( CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context,
context, getResources().getString(R.string.title_head_registration_error),
getResources().getString( getResources().getString(R.string.error_for_all_unknown_registration_failures),
R.string.title_head_registration_error), getResources().getString(R.string.button_ok),
getResources().getString( registrationFailedOKBtnClickListerner);
R.string.error_for_all_unknown_registration_failures),
getResources().getString(R.string.button_ok),
registrationFailedOKBtnClickListerner);
alertDialog.show(); alertDialog.show();
} }
@ -273,11 +290,11 @@ public class RegistrationActivity extends Activity implements APIResultCallBack
* *
*/ */
private void loadAuthenticationErrorActivity() { private void loadAuthenticationErrorActivity() {
Intent intent = new Intent(RegistrationActivity.this,AuthenticationErrorActivity.class); Intent intent = new Intent(RegistrationActivity.this, AuthenticationErrorActivity.class);
intent.putExtra(getResources().getString(R.string.intent_extra_from_activity), RegistrationActivity.class.getSimpleName()); intent.putExtra(getResources().getString(R.string.intent_extra_from_activity),
RegistrationActivity.class.getSimpleName());
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent); startActivity(intent);
} }
} }

@ -15,18 +15,6 @@
*/ */
package org.wso2.cdm.agent; package org.wso2.cdm.agent;
import java.util.HashMap;
import java.util.Map;
import org.wso2.cdm.agent.R;
import org.wso2.cdm.agent.api.DeviceInfo;
import org.wso2.cdm.agent.api.PhoneState;
import org.wso2.cdm.agent.proxy.APIResultCallBack;
import org.wso2.cdm.agent.proxy.Token;
import org.wso2.cdm.agent.proxy.TokenCallBack;
import org.wso2.cdm.agent.utils.CommonDialogUtils;
import org.wso2.cdm.agent.utils.CommonUtilities;
import org.wso2.cdm.agent.utils.Preference;
import org.wso2.cdm.agent.utils.ServerUtils;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.ProgressDialog; import android.app.ProgressDialog;
@ -35,34 +23,38 @@ import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.widget.Button; import android.widget.Button;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
public class ServerDetails extends Activity implements APIResultCallBack, TokenCallBack { import org.wso2.cdm.agent.api.DeviceInfo;
import org.wso2.cdm.agent.utils.CommonDialogUtils;
import org.wso2.cdm.agent.utils.CommonUtilities;
import org.wso2.cdm.agent.utils.Preference;
import org.wso2.cdm.agent.utils.Responce;
private String TAG = ServerDetails.class.getSimpleName(); /**
* This the the activity that is used to capture the server's host name.
*/
public class ServerDetails extends Activity {
TextView serverIP; TextView serverIP;
Button startRegistration; Button startRegistration;
String fromActivity;
Context context; Context context;
DialogInterface.OnClickListener dialogClickListener;
DeviceInfo info; DeviceInfo info;
TextView incompatibleError; TextView severAddressLabel;
String errorMessage = "";
String senderID = null; String senderID = null;
boolean accessFlag = true;
ProgressDialog progressDialog; ProgressDialog progressDialog;
String regId; String regId;
AlertDialog.Builder alertDialog; AlertDialog.Builder alertDialog;
boolean alreadyRegisteredActivityFlag = false; boolean alreadyRegisteredActivityFlag = false;
boolean authenticationActivityFlag = false; boolean authenticationActivityFlag = false;
private String TAG = ServerDetails.class.getSimpleName();
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -70,50 +62,39 @@ public class ServerDetails extends Activity implements APIResultCallBack, TokenC
setContentView(R.layout.activity_settings); setContentView(R.layout.activity_settings);
context = ServerDetails.this; context = ServerDetails.this;
info = new DeviceInfo(ServerDetails.this); info = new DeviceInfo(ServerDetails.this);
incompatibleError = (TextView) findViewById(R.id.incompatibleError);
serverIP = (TextView) findViewById(R.id.etServerIP); serverIP = (TextView) findViewById(R.id.etServerIP);
severAddressLabel = (TextView) findViewById(R.id.severAddressLabel);
startRegistration = (Button) findViewById(R.id.startRegistration); startRegistration = (Button) findViewById(R.id.startRegistration);
Bundle extras = getIntent().getExtras();
if (extras != null) {
if (extras.containsKey(getResources().getString(R.string.intent_extra_from_activity))) {
fromActivity =
extras.getString(getResources().getString(R.string.intent_extra_from_activity));
}
}
// Checking if the device meets minimum requirements // Checking if the device meets minimum requirements
if (!info.isCompatible(context).getCode()) { Responce compatibility = info.isCompatible();
accessFlag = false; if (!compatibility.getCode()) {
incompatibleError.setText(errorMessage);
startRegistration.setVisibility(View.GONE); startRegistration.setVisibility(View.GONE);
severAddressLabel.setVisibility(View.GONE);
serverIP.setVisibility(View.GONE); serverIP.setVisibility(View.GONE);
incompatibleError.setVisibility(View.VISIBLE); alertDialog =
CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context, CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context.getApplicationContext(),
errorMessage, getResources().getString(R.string.error_authorization_failed),
getResources().getString(R.string.error_authorization_failed), getResources().getString(compatibility.getDescriptionResourceID()),
getResources().getString(R.string.button_ok), getResources().getString(R.string.button_ok),
null); onRootedClickListner);
} else { } else {
startRegistration.setVisibility(View.VISIBLE); startRegistration.setVisibility(View.VISIBLE);
serverIP.setVisibility(View.VISIBLE); serverIP.setVisibility(View.VISIBLE);
incompatibleError.setVisibility(View.GONE);
String ipSaved = String ipSaved =
Preference.get(context, Preference.get(context.getApplicationContext(),
getResources().getString(R.string.shared_pref_ip)); getResources().getString(R.string.shared_pref_ip));
regId = Preference.get(context, getResources().getString(R.string.shared_pref_regId)); regId = Preference.get(context.getApplicationContext().getApplicationContext(), getResources().getString(R.string.shared_pref_regId));
if (ipSaved != null) { if (ipSaved != null) {
serverIP.setText(ipSaved); serverIP.setText(ipSaved);
CommonUtilities.setServerURL(ipSaved); CommonUtilities.setServerURL(ipSaved);
Intent intent = new Intent(ServerDetails.this, AuthenticationActivity.class); startAuthenticationActivity();
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
} else { } else {
serverIP.setText(CommonUtilities.SERVER_IP); serverIP.setText(CommonUtilities.SERVER_IP);
} }
// on click handler for start registration
startRegistration.setOnClickListener(new OnClickListener() { startRegistration.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -123,211 +104,246 @@ public class ServerDetails extends Activity implements APIResultCallBack, TokenC
serverIP.getText().toString() + serverIP.getText().toString() +
" " + " " +
getResources().getString(R.string.dialog_init_end_general)) getResources().getString(R.string.dialog_init_end_general))
.setPositiveButton(getResources().getString(R.string.info_label_rooted_answer_yes), .setPositiveButton(getResources().getString(R.string.yes),
dialogClickListener) dialogClickListener)
.setNegativeButton(getResources().getString(R.string.info_label_rooted_answer_no), .setNegativeButton(getResources().getString(R.string.no),
dialogClickListener).show(); dialogClickListener).show();
} }
}); });
// String clientKey = dialogClickListener = new DialogInterface.OnClickListener() {
// Preference.get(context, @Override
// getResources().getString(R.string.shared_pref_client_id)); public void onClick(DialogInterface dialog, int which) {
// String clientSecret = switch (which) {
// Preference.get(context, case DialogInterface.BUTTON_POSITIVE:
// getResources().getString(R.string.shared_pref_client_secret)); if (!serverIP.getText().toString().trim().equals("")) {
// if (!clientKey.equals("") && !clientSecret.equals("")) { CommonUtilities.setServerURL(serverIP.getText().toString().trim());
// CommonUtilities.CLIENT_ID = clientKey; Preference.put(context.getApplicationContext(),
// CommonUtilities.CLIENT_SECRET = clientSecret; getResources().getString(R.string.shared_pref_ip),
// } serverIP.getText().toString().trim());
// startAuthenticationActivity();
// try {
// if (fromActivity == null) {
// IdentityProxy.getInstance().getToken(this.getApplicationContext(),
// ServerDetails.this,
// CommonUtilities.CLIENT_ID,
// CommonUtilities.CLIENT_SECRET);
// }
//
// } catch (TimeoutException e) {
// e.printStackTrace();
// } catch (Exception e) {
// e.printStackTrace();
// }
}
}
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { } else {
@Override Toast.makeText(context.getApplicationContext(),
public void onClick(DialogInterface dialog, int which) { getResources().getString(R.string.toast_message_enter_server_address),
switch (which) { Toast.LENGTH_LONG).show();
case DialogInterface.BUTTON_POSITIVE: }
if (!serverIP.getText().toString().trim().equals("")) { break;
CommonUtilities.setServerURL(serverIP.getText().toString().trim());
Preference.put(context, getResources().getString(R.string.shared_pref_ip),
serverIP.getText().toString().trim());
Intent intent =
new Intent(ServerDetails.this, AuthenticationActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
} else { case DialogInterface.BUTTON_NEGATIVE:
Toast.makeText(context, dialog.dismiss();
getResources().getString(R.string.toast_message_enter_server_address), break;
Toast.LENGTH_LONG).show();
} }
break; }
};
case DialogInterface.BUTTON_NEGATIVE:
dialog.dismiss();
break;
}
} }
}; Log.d(TAG, "Server details activity started");
@Override
public void onBackPressed() {
Intent i = new Intent();
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
this.startActivity(i);
super.onBackPressed();
} }
@Override DialogInterface.OnClickListener onRootedClickListner = new DialogInterface.OnClickListener() {
public boolean onKeyDown(int keyCode, KeyEvent event) { @Override
if (keyCode == KeyEvent.KEYCODE_BACK && fromActivity != null && public void onClick(DialogInterface dialog, int which) {
fromActivity.equals(AlreadyRegisteredActivity.class.getSimpleName())) { finish();
Intent i = new Intent();
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
this.startActivity(i);
this.finish();
return true;
} else if (keyCode == KeyEvent.KEYCODE_BACK && fromActivity != null &&
fromActivity.equals(AuthenticationActivity.class.getSimpleName())) {
int pid = android.os.Process.myPid();
android.os.Process.killProcess(pid);
return true;
} else if (keyCode == KeyEvent.KEYCODE_BACK) {
Intent i = new Intent();
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
this.startActivity(i);
this.finish();
return true;
} }
return super.onKeyDown(keyCode, event); };
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.settings, menu);
return true;
}
public void onReceiveAPIResult(Map<String, String> result, int requestCode) {
String responseStatus = CommonUtilities.EMPTY_STRING;
if (result != null) {
responseStatus = result.get(CommonUtilities.STATUS_KEY);
if (responseStatus.equals(CommonUtilities.REQUEST_SUCCESSFUL) &&
requestCode == CommonUtilities.IS_REGISTERED_REQUEST_CODE) {
Intent intent = null;
if (progressDialog != null) {
progressDialog.dismiss();
}
intent = new Intent(ServerDetails.this, AlreadyRegisteredActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
} else if (responseStatus.equals(CommonUtilities.INTERNAL_SERVER_ERROR)) {
Log.e(TAG, "The value of status is null in onAPIAccessRecive()");
String isRegistered =
CommonUtilities.getPref(context,
context.getResources()
.getString(R.string.shared_pref_registered));
if (isRegistered.equals("1")) {
Intent intent = null;
intent = new Intent(ServerDetails.this, AlreadyRegisteredActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
} else {
alertDialog =
CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context,
getResources().getString(R.string.title_head_connection_error),
getResources().getString(R.string.error_internal_server),
getResources().getString(R.string.button_ok),
null);
Log.e("null", alertDialog.getClass().getPackage().toString());
alertDialog.show();
}
// ServerUtils.clearAppData(context);
} else {
Log.e(TAG, "The value of status is : " + responseStatus);
ServerUtils.clearAppData(context);
alertDialog =
CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context,
getResources().getString(R.string.title_head_registration_error),
getResources().getString(R.string.error_internal_server),
getResources().getString(R.string.button_ok),
null);
alertDialog.show();
}
} else {
Log.e(TAG, "The result is null in onReceiveAPIResult()");
ServerUtils.clearAppData(context);
alertDialog = private void startAuthenticationActivity() {
CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context, Intent intent = new Intent(ServerDetails.this, AuthenticationActivity.class);
getResources().getString(R.string.title_head_registration_error), intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
getResources().getString(R.string.error_for_all_unknown_registration_failures), startActivity(intent);
getResources().getString(R.string.button_ok),
null);
alertDialog.show();
}
} }
/*
* (non-Javadoc)
*
* @see android.app.Activity#onDestroy()
*/
@Override @Override
public void onReceiveTokenResult(Token token, String status) { protected void onDestroy() {
if (token != null) { //Avoiding memory leaks by destroying context object
if (regId != null && !regId.equals("")) { context = null;
// Check registration. super.onDestroy();
isRegistered();
progressDialog =
ProgressDialog.show(ServerDetails.this,
getResources().getString(R.string.dialog_sender_id),
getResources().getString(R.string.dialog_please_wait),
true);
}
}
} }
/** // Old API manager communication code.
* Checks whether device is registered or NOT. //
*/ // Bundle extras = getIntent().getExtras();
private void isRegistered() { //
Log.e("isReg", "isReg"); // if (extras != null) {
Map<String, String> requestParams = new HashMap<String, String>(); // if
requestParams.put("regid", regId); // (extras.containsKey(getResources().getString(R.string.intent_extra_from_activity)))
Log.e("regID", regId); // {
// fromActivity =
// Check network connection availability before calling the API. // extras.getString(
if (PhoneState.isNetworkAvailable(context)) { // getResources().getString(R.string.intent_extra_from_activity));
// Call isRegistered API. // }
ServerUtils.callSecuredAPI(ServerDetails.this, CommonUtilities.IS_REGISTERED_ENDPOINT, // }
CommonUtilities.POST_METHOD, requestParams, //
ServerDetails.this, //
CommonUtilities.IS_REGISTERED_REQUEST_CODE); // public class ServerDetails extends Activity implements APIResultCallBack,
} else { // TokenCallBack {
CommonDialogUtils.stopProgressDialog(progressDialog); // @Override
CommonDialogUtils.showNetworkUnavailableMessage(ServerDetails.this); // public void onBackPressed() {
} // Intent i = new Intent();
// i.setAction(Intent.ACTION_MAIN);
} // i.addCategory(Intent.CATEGORY_HOME);
// this.startActivity(i);
// super.onBackPressed();
// }
//
// @Override
// public boolean onKeyDown(int keyCode, KeyEvent event) {
// if (keyCode == KeyEvent.KEYCODE_BACK && fromActivity != null &&
// fromActivity.equals(AlreadyRegisteredActivity.class.getSimpleName())) {
// Intent i = new Intent();
// i.setAction(Intent.ACTION_MAIN);
// i.addCategory(Intent.CATEGORY_HOME);
// this.startActivity(i);
// this.finish();
// return true;
// } else if (keyCode == KeyEvent.KEYCODE_BACK && fromActivity != null &&
// fromActivity.equals(AuthenticationActivity.class.getSimpleName())) {
// int pid = android.os.Process.myPid();
// android.os.Process.killProcess(pid);
// return true;
// } else if (keyCode == KeyEvent.KEYCODE_BACK) {
// Intent i = new Intent();
// i.setAction(Intent.ACTION_MAIN);
// i.addCategory(Intent.CATEGORY_HOME);
// this.startActivity(i);
// this.finish();
// return true;
// }
// return super.onKeyDown(keyCode, event);
// }
//
// @Override
// public boolean onCreateOptionsMenu(Menu menu) {
// // Inflate the menu; this adds items to the action bar if it is present.
// getMenuInflater().inflate(R.menu.settings, menu);
// return true;
// }
//
// public void onReceiveAPIResult(Map<String, String> result, int
// requestCode) {
// String responseStatus = CommonUtilities.EMPTY_STRING;
// if (result != null) {
// responseStatus = result.get(CommonUtilities.STATUS_KEY);
//
// if (responseStatus.equals(CommonUtilities.REQUEST_SUCCESSFUL) &&
// requestCode == CommonUtilities.IS_REGISTERED_REQUEST_CODE) {
// Intent intent = null;
// if (progressDialog != null) {
// progressDialog.dismiss();
// }
// intent = new Intent(ServerDetails.this, AlreadyRegisteredActivity.class);
// intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// startActivity(intent);
//
// } else if (responseStatus.equals(CommonUtilities.INTERNAL_SERVER_ERROR))
// {
// Log.e(TAG, "The value of status is null in onAPIAccessRecive()");
//
// String isRegistered =
// CommonUtilities.getPref(context,
// context.getResources()
// .getString(R.string.shared_pref_registered)
// );
// if (isRegistered.equals("1")) {
// Intent intent = null;
// intent = new Intent(ServerDetails.this, AlreadyRegisteredActivity.class);
// intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// startActivity(intent);
// } else {
// alertDialog =
// CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context,
// getResources()
// .getString(
// R.string.title_head_connection_error),
// getResources()
// .getString(
// R.string.error_internal_server),
// getResources()
// .getString(
// R.string.button_ok),
// null);
// Log.e("null", alertDialog.getClass().getPackage().toString());
// alertDialog.show();
// }
// // ServerUtils.clearAppData(context);
// } else {
// Log.e(TAG, "The value of status is : " + responseStatus);
// ServerUtils.clearAppData(context);
//
// alertDialog =
// CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context,
// getResources()
// .getString(
// R.string.title_head_registration_error),
// getResources()
// .getString(
// R.string.error_internal_server),
// getResources()
// .getString(
// R.string.button_ok),
// null);
// alertDialog.show();
// }
// } else {
// Log.e(TAG, "The result is null in onReceiveAPIResult()");
// ServerUtils.clearAppData(context);
//
// alertDialog =
// CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context,
// getResources().getString(
// R.string.title_head_registration_error),
// getResources().getString(
// R.string.error_for_all_unknown_registration_failures),
// getResources().getString(
// R.string.button_ok),
// null);
// alertDialog.show();
// }
// }
//
// @Override
// public void onReceiveTokenResult(Token token, String status) {
// if (token != null) {
// if (regId != null && !regId.equals("")) {
// // Check registration.
// isRegistered();
//
// progressDialog =
// ProgressDialog.show(ServerDetails.this,
// getResources().getString(R.string.dialog_sender_id),
// getResources().getString(R.string.dialog_please_wait),
// true);
// }
// }
// }
//
// /**
// * Checks whether device is registered or NOT.
// */
// private void isRegistered() {
// Log.e("isReg", "isReg");
// Map<String, String> requestParams = new HashMap<String, String>();
// requestParams.put("regid", regId);
// Log.e("regID", regId);
//
// // Check network connection availability before calling the API.
// if (PhoneState.isNetworkAvailable(context)) {
// // Call isRegistered API.
// ServerUtils.callSecuredAPI(ServerDetails.this,
// CommonUtilities.IS_REGISTERED_ENDPOINT,
// CommonUtilities.POST_METHOD, requestParams,
// ServerDetails.this,
// CommonUtilities.IS_REGISTERED_REQUEST_CODE);
// } else {
// CommonDialogUtils.stopProgressDialog(progressDialog);
// CommonDialogUtils.showNetworkUnavailableMessage(ServerDetails.this);
// }
//
// }
} }

@ -23,7 +23,7 @@ import java.util.List;
import org.json.JSONArray; import org.json.JSONArray;
import org.wso2.cdm.agent.R; import org.wso2.cdm.agent.R;
import org.wso2.cdm.agent.utils.CommonUtilities; import org.wso2.cdm.agent.utils.CommonUtilities;
import org.wso2.cdm.agent.utils.Errors; import org.wso2.cdm.agent.utils.Responce;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
@ -303,17 +303,17 @@ public class DeviceInfo {
return amount; return amount;
} }
public Errors isCompatible(Context c) { public Responce isCompatible() {
if (!(getSdkVersion() >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) && if (!(getSdkVersion() >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) &&
isRooted()) { isRooted()) {
return Errors.INCOMPATIBLE; return Responce.INCOMPATIBLE;
} else if (getSdkVersion() < android.os.Build.VERSION_CODES.FROYO) { } else if (getSdkVersion() < android.os.Build.VERSION_CODES.FROYO) {
return Errors.INCOMPATIBLE; return Responce.INCOMPATIBLE;
} else if (isRooted()) { } else if (isRooted()) {
return Errors.INCOMPATIBLE; return Responce.INCOMPATIBLE;
} }
return Errors.COMPATIBLE; return Responce.COMPATIBLE;
} }
/* /*

@ -1,18 +1,18 @@
/* /**
~ Copyright (c) 2014, WSO2 Inc. (http://wso2.com/) All Rights Reserved. * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~ *
~ Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at * You may obtain a copy of the License at
~ *
~ http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
~ *
~ Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
~ limitations under the License. * limitations under the License.
*/ */
package org.wso2.cdm.agent.utils; package org.wso2.cdm.agent.utils;
import org.wso2.cdm.agent.R; import org.wso2.cdm.agent.R;
@ -124,7 +124,7 @@ public abstract class CommonDialogUtils {
builder.setTitle(title); builder.setTitle(title);
builder.setMessage(message) builder.setMessage(message)
.setPositiveButton(positiveBtnLabel, positiveClickListener); .setPositiveButton(positiveBtnLabel, positiveClickListener);
builder.show();
return builder; return builder;
} }

@ -1,17 +1,17 @@
/* /**
~ Copyright (c) 2014, WSO2 Inc. (http://wso2.com/) All Rights Reserved. * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~ *
~ Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at * You may obtain a copy of the License at
~ *
~ http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
~ *
~ Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
~ limitations under the License. * limitations under the License.
*/ */
package org.wso2.cdm.agent.utils; package org.wso2.cdm.agent.utils;
@ -37,12 +37,14 @@ public class CommonUtilities {
public static String SERVER_PROTOCOL = "http://"; public static String SERVER_PROTOCOL = "http://";
public static String API_VERSION = "1.0.0"; public static String API_VERSION = "1.0.0";
public static String SERVER_APP_ENDPOINT = "/emm/api/"; public static String SERVER_APP_ENDPOINT = "/cdm-android-api/";
public static String SERVER_AUTHENTICATION_ENDPOINT="register/authenticate/device";
public static String LICENSE_ENDPOINT = "register/authenticate/device/license";
public static String REGISTER_ENDPOINT = "enrollment/authenticate/device/enroll";
public static String OAUTH_ENDPOINT = "/oauth2/token"; public static String OAUTH_ENDPOINT = "/oauth2/token";
public static String SENDER_ID_ENDPOINT = "devices/sender_id/"; public static String SENDER_ID_ENDPOINT = "devices/sender_id/";
public static String IS_REGISTERED_ENDPOINT = "devices/isregistered/"; public static String IS_REGISTERED_ENDPOINT = "devices/isregistered/";
public static String LICENSE_ENDPOINT = "devices/license/";
public static String REGISTER_ENDPOINT = "devices/register/";
public static String UNREGISTER_ENDPOINT = "devices/unregister/"; public static String UNREGISTER_ENDPOINT = "devices/unregister/";
public static String NOTIFICATION_ENDPOINT = "notifications/pendingOperations/"; public static String NOTIFICATION_ENDPOINT = "notifications/pendingOperations/";
@ -82,8 +84,6 @@ public class CommonUtilities {
public static void setServerURL(String serverIP) { public static void setServerURL(String serverIP) {
SERVER_IP = serverIP; SERVER_IP = serverIP;
/*SERVER_URL = SERVER_PROTOCOL + sERVER_URL + ":" + SERVER_PORT
+ "/mdm/api/";*/
SERVER_URL = SERVER_PROTOCOL + serverIP + ":" + SERVER_PORT SERVER_URL = SERVER_PROTOCOL + serverIP + ":" + SERVER_PORT
+SERVER_APP_ENDPOINT; +SERVER_APP_ENDPOINT;

@ -24,7 +24,6 @@ import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.apache.http.HeaderElement; import org.apache.http.HeaderElement;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
@ -44,7 +43,6 @@ import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpParams; import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HTTP; import org.apache.http.protocol.HTTP;
import org.wso2.cdm.agent.R; import org.wso2.cdm.agent.R;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.net.ParseException; import android.net.ParseException;
@ -56,39 +54,38 @@ public class HTTPConnectorUtils {
private static final int MAX_ATTEMPTS = 2; private static final int MAX_ATTEMPTS = 2;
public static Map<String, String> getClientKey(String username, String password, Context context) { // public static Map<String, String> getClientKey(String username, String
Map<String, String> params = new HashMap<String, String>(); // password, Context context) {
Map<String, String> response = new HashMap<String, String>(); // Map<String, String> params = new HashMap<String, String>();
// Map<String, String> response = new HashMap<String, String>();
params.put("username", username); //
params.put("password", password); // params.put("username", username);
// params.put("password", password);
try { //
response = // try {
sendWithTimeWait("services/register/authenticate/device", params, "POST", // response =
context); // postData("services/register/authenticate/device", params,
} catch (Exception ex) { // context);
ex.printStackTrace(); // } catch (Exception ex) {
return response; // ex.printStackTrace();
} // return response;
return response; // }
} // return response;
// }
public static Map<String, String> sendWithTimeWait(String epPostFix, public static Map<String, String> postData(Context context, String url,
Map<String, String> params, String option, Map<String, String> params) {
Context context) {
Map<String, String> response = null; Map<String, String> response = null;
Map<String, String> responseFinal = null; Map<String, String> responseFinal = null;
for (int i = 1; i <= MAX_ATTEMPTS; i++) { for (int i = 1; i <= MAX_ATTEMPTS; i++) {
Log.d(TAG, "Attempt #" + i + " to register"); Log.d(TAG, "Attempt #" + i + " to register " + url);
try { try {
response = postData(context, epPostFix, params); response = postToServer(context, url, params);
if (response != null && !response.equals(null)) { if (response != null && !response.equals(null)) {
responseFinal = response; responseFinal = response;
} }
String message = context.getString(R.string.server_registered); Log.d("Success", "Check Reg Success");
Log.v("Check Reg Success", message.toString());
return responseFinal; return responseFinal;
} catch (Exception e) { } catch (Exception e) {
@ -100,49 +97,34 @@ public class HTTPConnectorUtils {
return responseFinal; return responseFinal;
} }
} }
String message = context.getString(R.string.server_register_error, MAX_ATTEMPTS);
return responseFinal; return responseFinal;
} }
public static Map<String, String> postData(Context context, String url, public static Map<String, String> postToServer(Context context, String url,
Map<String, String> params) { Map<String, String> params) {
// Create a new HttpClient and Post Header // Create a new HttpClient and Post Header
Map<String, String> response_params = new HashMap<String, String>(); Map<String, String> response_params = new HashMap<String, String>();
HttpClient httpclient = getCertifiedHttpClient(context); HttpClient httpclient = getCertifiedHttpClient(context);
String endpoint = CommonUtilities.SERVER_URL + url;
SharedPreferences mainPref = context.getSharedPreferences("com.mdm", Context.MODE_PRIVATE);
String ipSaved = mainPref.getString("ip", "");
if (ipSaved != null && ipSaved != "") {
endpoint =
CommonUtilities.SERVER_PROTOCOL + ipSaved + ":" +
CommonUtilities.SERVER_PORT + CommonUtilities.SERVER_APP_ENDPOINT +
url;
}
endpoint =
"http://10.100.5.70:9763/wso2appserver-cxf-samples/services/register/authenticate/device";
Log.v(TAG, ipSaved + "Posting '" + params.toString() + "' to " + endpoint);
StringBuilder bodyBuilder = new StringBuilder(); StringBuilder bodyBuilder = new StringBuilder();
Iterator<Entry<String, String>> iterator = params.entrySet().iterator(); if (params != null) {
// constructs the POST body using the parameters Iterator<Entry<String, String>> iterator = params.entrySet().iterator();
while (iterator.hasNext()) { // constructs the POST body using the parameters
Entry<String, String> param = iterator.next(); while (iterator.hasNext()) {
bodyBuilder.append(param.getKey()).append('=').append(param.getValue()); Entry<String, String> param = iterator.next();
if (iterator.hasNext()) { bodyBuilder.append(param.getKey()).append('=').append(param.getValue());
bodyBuilder.append('&'); if (iterator.hasNext()) {
bodyBuilder.append('&');
}
} }
} }
String body = bodyBuilder.toString(); String body = bodyBuilder.toString();
Log.v(TAG, "Posting '" + body + "' to " + endpoint); Log.v(TAG, "Posting '" + body + "' to " + url);
byte[] postData = body.getBytes(); byte[] postData = body.getBytes();
HttpPost httppost = new HttpPost(endpoint); HttpPost httppost = new HttpPost(url);
httppost.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8"); httppost.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
httppost.setHeader("Accept", "*/*"); httppost.setHeader("Accept", "*/*");
httppost.setHeader("User-Agent", "Mozilla/5.0 ( compatible ), Android"); httppost.setHeader("User-Agent", "Mozilla/5.0 ( compatible ), Android");
@ -185,13 +167,12 @@ public class HTTPConnectorUtils {
new ThreadSafeClientConnManager(params, schemeRegistry); new ThreadSafeClientConnManager(params, schemeRegistry);
client = new DefaultHttpClient(cm, params); client = new DefaultHttpClient(cm, params);
} else { } else {
Log.e("", "out");
client = new DefaultHttpClient(); client = new DefaultHttpClient();
} }
return client; return client;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
return null; return null;
} }
} }

@ -1,29 +1,46 @@
package org.wso2.cdm.agent.utils; package org.wso2.cdm.agent.utils;
import org.wso2.cdm.agent.R;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor; import android.content.SharedPreferences.Editor;
import org.wso2.cdm.agent.R;
/**
* Data retrieval and saving to shared preferences is done here.
*/
public class Preference { public class Preference {
public static String pack = "com.inosh.jwnotes"; public static String pack = "com.wso2.cdm.agent";
public static void put(Context c, String key, String value) { /**
* Put data to shared preferences in private mode.
*
* @param context the context of activity which is requesting to put data
* @param key is used to identify the value.
* @param value is the actual value to be saved.
*/
public static void put(Context context, String key, String value) {
SharedPreferences mainPref = SharedPreferences mainPref =
c.getSharedPreferences(c.getResources() context.getSharedPreferences(context.getResources()
.getString(R.string.shared_pref_package), .getString(R.string.shared_pref_package),
Context.MODE_PRIVATE); Context.MODE_PRIVATE
);
Editor editor = mainPref.edit(); Editor editor = mainPref.edit();
editor.putString(key, value); editor.putString(key, value);
editor.commit(); editor.commit();
} }
public static String get(Context c, String key) { /**
* Retrieve data from shared preferences in private mode.
*
* @param context the context of activity which is requesting to put data
* @param key is used to identify the value to to be retrieved.
*/
public static String get(Context context, String key) {
SharedPreferences mainPref = SharedPreferences mainPref =
c.getSharedPreferences(c.getResources() context.getSharedPreferences(context.getResources()
.getString(R.string.shared_pref_package), .getString(R.string.shared_pref_package),
Context.MODE_PRIVATE); Context.MODE_PRIVATE
);
return mainPref.getString(key, null); return mainPref.getString(key, null);
} }

@ -21,7 +21,7 @@ import org.wso2.cdm.agent.R;
* Describes the errors and their relevant error messages. * Describes the errors and their relevant error messages.
* In order to internationalize the message is the res * In order to internationalize the message is the res
*/ */
public enum Errors { public enum Responce {
INCOMPATIBLE(false, R.string.device_not_compatible_error), INCOMPATIBLE(false, R.string.device_not_compatible_error),
INCOMPATIBLE_OS(false, R.string.device_not_compatible_error_os), INCOMPATIBLE_OS(false, R.string.device_not_compatible_error_os),
COMPATIBLE(true,R.string.device_not_compatible_error_os); COMPATIBLE(true,R.string.device_not_compatible_error_os);
@ -29,7 +29,7 @@ public enum Errors {
private final boolean code; private final boolean code;
private final int descriptionResourceID; private final int descriptionResourceID;
private Errors(boolean code, int description) { private Responce(boolean code, int description) {
this.code = code; this.code = code;
this.descriptionResourceID = description; this.descriptionResourceID = description;
} }
Loading…
Cancel
Save