diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java index 5ee72f4daa..8675c8af89 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java @@ -44,6 +44,8 @@ public class Device { private List features; + private List properties; + public int getId() { return id; } @@ -140,4 +142,11 @@ public class Device { this.type = type; } + public List getProperties() { + return properties; + } + + public void setProperties(List properties) { + this.properties = properties; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Property.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Property.java new file mode 100644 index 0000000000..399ee67077 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Property.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.wso2.carbon.device.mgt.common; + +public class Property { + + private String name; + private String value; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagerService.java index 319acca3c8..bc3cc6d270 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagerService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagerService.java @@ -62,8 +62,9 @@ public interface DeviceManagerService { * Method to retrieve the status of the registration process of a particular device. * * @param deviceId Fully qualified device identifier - * @return Status of enrollment - * @throws DeviceManagementException If some unusual behaviour is observed while enrolling a device + * @return Status of enrollment + * @throws DeviceManagementException If some unusual behaviour is observed while checking the enrollment + * status of the device */ boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException; @@ -71,8 +72,9 @@ public interface DeviceManagerService { * Method to retrieve the status of a particular device. * * @param deviceId Fully qualified device identifier - * @return Returns if the device is active - * @throws DeviceManagementException If some unusual behaviour is observed while enrolling a device + * @return Returns if the device is active + * @throws DeviceManagementException If some unusual behaviour is observed while checking the status + * of the device */ boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException; @@ -82,7 +84,8 @@ public interface DeviceManagerService { * * @param deviceId Fully qualified device identifier * @param status Indicates whether the device is active - * @throws DeviceManagementException If some unusual behaviour is observed while enrolling a device + * @throws DeviceManagementException If some unusual behaviour is observed while updating the active status + * of the device */ boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException; @@ -90,7 +93,8 @@ public interface DeviceManagerService { * Method to retrieve metadata of all devices registered within CDM corresponding to a particular device type. * * @param type Device Type - * @return List of metadata corresponding to all devices registered within CDM + * @return List of metadata corresponding to all devices registered within CDM + * @throws DeviceManagementException If some unusual behaviour is observed while obtaining the enrolled device list */ List getAllDevices(String type) throws DeviceManagementException; @@ -99,14 +103,14 @@ public interface DeviceManagerService { * * @param deviceId Fully qualified device identifier * @return Metadata corresponding to a particular device - * @throws DeviceManagementException If some unusual behaviour is observed while enrolling a device + * @throws DeviceManagementException If some unusual behaviour is observed obtaining the device object */ Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException; /** * Method to update device information. * @param device Updated device information related data - * @throws DeviceManagementException If some unusual behaviour is observed while enrolling a device + * @throws DeviceManagementException If some unusual behaviour is observed while updating the device info */ boolean updateDeviceInfo(Device device) throws DeviceManagementException; @@ -115,7 +119,8 @@ public interface DeviceManagerService { * * @param deviceId Fully qualified device identifier * @param ownershipType Type of ownership - * @throws DeviceManagementException If some unusual behaviour is observed while enrolling a device + * @throws DeviceManagementException If some unusual behaviour is observed while setting the ownership + * of the device */ boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java index d7508fb784..93cb7f18bc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java @@ -25,59 +25,64 @@ import java.util.List; public class DeviceManagementService implements DeviceManagerService { - @Override - public String getProviderType() { - return null; - } + @Override + public String getProviderType() { + return null; + } - @Override - public boolean enrollDevice(Device device) throws DeviceManagementException { - return DeviceManagementDataHolder.getInstance().getDeviceManager().enrollDevice(device); - } + @Override + public boolean enrollDevice(Device device) throws DeviceManagementException { + return DeviceManagementDataHolder.getInstance().getDeviceManager().enrollDevice(device); + } - @Override - public boolean modifyEnrollment(Device device) throws DeviceManagementException { - return DeviceManagementDataHolder.getInstance().getDeviceManager().modifyEnrollment(device); - } + @Override + public boolean modifyEnrollment(Device device) throws DeviceManagementException { + return DeviceManagementDataHolder.getInstance().getDeviceManager().modifyEnrollment(device); + } - @Override - public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { - return DeviceManagementDataHolder.getInstance().getDeviceManager().disenrollDevice(deviceId); - } + @Override + public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + return DeviceManagementDataHolder.getInstance().getDeviceManager() + .disenrollDevice(deviceId); + } - @Override - public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { - return DeviceManagementDataHolder.getInstance().getDeviceManager().isEnrolled(deviceId); - } + @Override + public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { + return DeviceManagementDataHolder.getInstance().getDeviceManager().isEnrolled(deviceId); + } - @Override - public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { - return DeviceManagementDataHolder.getInstance().getDeviceManager().isActive(deviceId); - } + @Override + public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { + return DeviceManagementDataHolder.getInstance().getDeviceManager().isActive(deviceId); + } - @Override - public boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException { - return DeviceManagementDataHolder.getInstance().getDeviceManager().setActive(deviceId, status); - } + @Override + public boolean setActive(DeviceIdentifier deviceId, boolean status) + throws DeviceManagementException { + return DeviceManagementDataHolder.getInstance().getDeviceManager() + .setActive(deviceId, status); + } - @Override - public List getAllDevices(String type) throws DeviceManagementException { - return DeviceManagementDataHolder.getInstance().getDeviceManager().getAllDevices(type); - } + @Override + public List getAllDevices(String type) throws DeviceManagementException { + return DeviceManagementDataHolder.getInstance().getDeviceManager().getAllDevices(type); + } - @Override - public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { - return DeviceManagementDataHolder.getInstance().getDeviceManager().getDevice(deviceId); - } + @Override + public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + return DeviceManagementDataHolder.getInstance().getDeviceManager().getDevice(deviceId); + } - @Override - public boolean updateDeviceInfo(Device device) throws DeviceManagementException { - return DeviceManagementDataHolder.getInstance().getDeviceManager().updateDeviceInfo(device); - } + @Override + public boolean updateDeviceInfo(Device device) throws DeviceManagementException { + return DeviceManagementDataHolder.getInstance().getDeviceManager().updateDeviceInfo(device); + } - @Override - public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException { - return DeviceManagementDataHolder.getInstance().getDeviceManager().setOwnership(deviceId, ownershipType); - } + @Override + public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) + throws DeviceManagementException { + return DeviceManagementDataHolder.getInstance().getDeviceManager() + .setOwnership(deviceId, ownershipType); + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagementSchemaInitializer.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagementSchemaInitializer.java index 4ed4e8ad5d..448ae42007 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagementSchemaInitializer.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagementSchemaInitializer.java @@ -27,18 +27,19 @@ import java.io.File; public final class DeviceManagementSchemaInitializer extends DatabaseCreator { private static final Log log = LogFactory.getLog(DeviceManagementSchemaInitializer.class); - private static final String setupSQLScriptLocation = CarbonUtils.getCarbonHome() + File.separator + "dbscripts" ; + private static final String setupSQLScriptBaseLocation = + CarbonUtils.getCarbonHome() + File.separator + "dbscripts" + File.separator + "cdm" + File.separator; public DeviceManagementSchemaInitializer(DataSourceConfig config) { super(DeviceManagerUtil.resolveDataSource(config)); } protected String getDbScriptLocation(String databaseType) { - String scriptName = "wso2_cdm_" + databaseType + ".sql"; + String scriptName = databaseType + ".sql"; if (log.isDebugEnabled()) { log.debug("Loading database script from :" + scriptName); } - return setupSQLScriptLocation.replaceFirst("DBTYPE", databaseType) + scriptName; + return setupSQLScriptBaseLocation.replaceFirst("DBTYPE", databaseType) + scriptName; } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/pom.xml index 043e0dd60e..8dd8ef138c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/pom.xml @@ -35,6 +35,7 @@ ${project.artifactId} ${project.version} Device Management Mobile Impl Bundle + org.wso2.carbon.device.mgt.mobile.impl.internal.MobileDeviceManagementBundleActivator org.wso2.carbon.device.mgt.mobile.impl.internal org.osgi.framework, diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/internal/MobileDeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/internal/MobileDeviceManagementBundleActivator.java similarity index 96% rename from components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/internal/MobileDeviceManagementServiceComponent.java rename to components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/internal/MobileDeviceManagementBundleActivator.java index 7978214969..e614119492 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/internal/MobileDeviceManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/internal/MobileDeviceManagementBundleActivator.java @@ -26,9 +26,9 @@ import org.wso2.carbon.device.mgt.mobile.impl.android.AndroidDeviceManagerServic import org.wso2.carbon.device.mgt.mobile.impl.ios.IOSDeviceManagerService; import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManagerService; -public class MobileDeviceManagementServiceComponent implements BundleActivator { +public class MobileDeviceManagementBundleActivator implements BundleActivator { - private static final Log log = LogFactory.getLog(MobileDeviceManagementServiceComponent.class); + private static final Log log = LogFactory.getLog(MobileDeviceManagementBundleActivator.class); private ServiceRegistration androidServiceRegRef; private ServiceRegistration iOSServiceRegRef; private ServiceRegistration windowsServiceRegRef; diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml index 381ad434a2..1f7bca1d93 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml @@ -18,7 +18,7 @@ - WSO2DEVICE_DB + jdbc/WSO2DEVICE_DB diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/p2.inf b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/p2.inf index e69de29bb2..b5222094b3 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/p2.inf +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/p2.inf @@ -0,0 +1,3 @@ +instructions.configure = \ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/conf/cdm-config.xml,target:${installFolder}/../../conf/cdm-config.xml,overwrite:true);\ + diff --git a/product/modules/agents/android/client/bin/R.txt b/product/modules/agents/android/client/bin/R.txt index 43fe3e2fc8..6e3120ce0f 100644 --- a/product/modules/agents/android/client/bin/R.txt +++ b/product/modules/agents/android/client/bin/R.txt @@ -379,6 +379,7 @@ int id setting_invite_email_edittext 0x7f06002f int id setting_invite_email_imageview 0x7f060031 int id setting_invite_email_layout 0x7f06002e int id setting_invite_email_textview 0x7f060032 +int id severAddressLabel 0x7f060089 int id sg_button1 0x7f060039 int id sg_button2 0x7f06003a int id sg_button3 0x7f06003b @@ -425,7 +426,6 @@ int id txtPinCode 0x7f060086 int id txtRegText 0x7f060066 int id txtRoot 0x7f06007b int id txtSDK 0x7f060079 -int id txtVw 0x7f060089 int id useLogo 0x7f060004 int id user_edit_location 0x7f060033 int id username 0x7f06006b @@ -518,12 +518,12 @@ int string abs__shareactionprovider_share_with_application 0x7f0b0009 int string action_settings 0x7f0b0023 int string already_registered 0x7f0b0010 int string app_name 0x7f0b0021 -int string application_mgr_download_file_name 0x7f0b0091 -int string application_mgr_download_location 0x7f0b0090 -int string application_mgr_mime 0x7f0b0092 -int string application_package_launcher_action 0x7f0b0094 -int string application_package_prefix 0x7f0b0093 -int string button_ok 0x7f0b008f +int string application_mgr_download_file_name 0x7f0b0092 +int string application_mgr_download_location 0x7f0b0091 +int string application_mgr_mime 0x7f0b0093 +int string application_package_launcher_action 0x7f0b0095 +int string application_package_prefix 0x7f0b0094 +int string button_ok 0x7f0b0090 int string device_admin_disabled 0x7f0b002e int string device_admin_enable_alert 0x7f0b003d int string device_admin_enabled 0x7f0b002d @@ -537,17 +537,18 @@ int string dialog_authenticate 0x7f0b0071 int string dialog_checking_reg 0x7f0b0073 int string dialog_enrolling 0x7f0b0076 int string dialog_init_confirmation 0x7f0b0079 -int string dialog_init_end 0x7f0b007b -int string dialog_init_end_general 0x7f0b007c +int string dialog_init_device_type 0x7f0b007b +int string dialog_init_end 0x7f0b007c +int string dialog_init_end_general 0x7f0b007d int string dialog_init_middle 0x7f0b007a int string dialog_license_agreement 0x7f0b0075 -int string dialog_message_please_wait 0x7f0b0084 -int string dialog_message_unregistering 0x7f0b0083 +int string dialog_message_please_wait 0x7f0b0085 +int string dialog_message_unregistering 0x7f0b0084 int string dialog_pin_confirmation 0x7f0b0077 int string dialog_pin_confirmation_end 0x7f0b0078 int string dialog_please_wait 0x7f0b0072 int string dialog_sender_id 0x7f0b0074 -int string dialog_unregister 0x7f0b007d +int string dialog_unregister 0x7f0b007e int string empty_app_title 0x7f0b0022 int string error_auth_failed_detail 0x7f0b0068 int string error_authentication_failed 0x7f0b0069 @@ -574,16 +575,14 @@ int string gcm_registered 0x7f0b0011 int string gcm_unregistered 0x7f0b0012 int string hello_world 0x7f0b0024 int string hint_new_pin 0x7f0b0042 -int string info_label_device 0x7f0b0086 -int string info_label_imei 0x7f0b0085 -int string info_label_imsi 0x7f0b008a -int string info_label_model 0x7f0b0087 -int string info_label_no_sim 0x7f0b0088 -int string info_label_operator 0x7f0b0089 -int string info_label_os 0x7f0b008b -int string info_label_rooted 0x7f0b008c -int string info_label_rooted_answer_no 0x7f0b008e -int string info_label_rooted_answer_yes 0x7f0b008d +int string info_label_device 0x7f0b0087 +int string info_label_imei 0x7f0b0086 +int string info_label_imsi 0x7f0b008b +int string info_label_model 0x7f0b0088 +int string info_label_no_sim 0x7f0b0089 +int string info_label_operator 0x7f0b008a +int string info_label_os 0x7f0b008c +int string info_label_rooted 0x7f0b008d int string intent_extra_fresh_reg_flag 0x7f0b004c int string intent_extra_from_activity 0x7f0b0048 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_regid 0x7f0b0049 int string intent_extra_username 0x7f0b004d -int string menu_item_change_ip 0x7f0b0082 -int string menu_item_change_pin 0x7f0b0081 +int string menu_item_change_ip 0x7f0b0083 +int string menu_item_change_pin 0x7f0b0082 int string menu_item_ip 0x7f0b003a int string menu_item_log 0x7f0b003b 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 no 0x7f0b008f int string options_clear 0x7f0b001f int string options_exit 0x7f0b0020 int string options_register 0x7f0b001c int string options_unregister 0x7f0b001d -int string register_button_text 0x7f0b007e -int string register_text_view_text_unregister 0x7f0b007f -int string registration_heading 0x7f0b0098 +int string register_button_text 0x7f0b007f +int string register_text_view_text_unregister 0x7f0b0080 +int string registration_heading 0x7f0b0099 int string server_register_error 0x7f0b001a int string server_registered 0x7f0b0018 int string server_registering 0x7f0b0017 int string server_unregister_error 0x7f0b001b int string server_unregistered 0x7f0b0019 -int string server_util_req_type_get 0x7f0b0096 -int string server_util_req_type_post 0x7f0b0095 +int string server_util_req_type_get 0x7f0b0097 +int string server_util_req_type_post 0x7f0b0096 int string shared_pref_client_id 0x7f0b005f int string shared_pref_client_secret 0x7f0b0060 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_display_device_info 0x7f0b0025 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_notify 0x7f0b0035 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_success 0x7f0b0043 int string url 0x7f0b0026 +int string yes 0x7f0b008e int style AppBaseTheme 0x7f0c0059 int style AppTheme 0x7f0c005a int style ButtonText 0x7f0c005f diff --git a/product/modules/agents/android/client/bin/cdm-agent.apk b/product/modules/agents/android/client/bin/cdm-agent.apk new file mode 100644 index 0000000000..3771e2436d Binary files /dev/null and b/product/modules/agents/android/client/bin/cdm-agent.apk differ diff --git a/product/modules/agents/android/client/bin/classes.dex b/product/modules/agents/android/client/bin/classes.dex new file mode 100644 index 0000000000..6f0921ffde Binary files /dev/null and b/product/modules/agents/android/client/bin/classes.dex differ diff --git a/product/modules/agents/android/client/bin/dexedLibs/android-support-v4-ac241410a4abbf80a4b32bc9c83281a0.jar b/product/modules/agents/android/client/bin/dexedLibs/android-support-v4-ac241410a4abbf80a4b32bc9c83281a0.jar new file mode 100644 index 0000000000..a12962c9d6 Binary files /dev/null and b/product/modules/agents/android/client/bin/dexedLibs/android-support-v4-ac241410a4abbf80a4b32bc9c83281a0.jar differ diff --git a/product/modules/agents/android/client/bin/dexedLibs/commons-codec-1.2-8ab7bcad84afcfb11444785a20fab16a.jar b/product/modules/agents/android/client/bin/dexedLibs/commons-codec-1.2-8ab7bcad84afcfb11444785a20fab16a.jar new file mode 100644 index 0000000000..492e62a5bc Binary files /dev/null and b/product/modules/agents/android/client/bin/dexedLibs/commons-codec-1.2-8ab7bcad84afcfb11444785a20fab16a.jar differ diff --git a/product/modules/agents/android/client/bin/dexedLibs/gcm-9a0931d46c58ab74a433ccfc2b28f225.jar b/product/modules/agents/android/client/bin/dexedLibs/gcm-9a0931d46c58ab74a433ccfc2b28f225.jar new file mode 100644 index 0000000000..86ff9d1320 Binary files /dev/null and b/product/modules/agents/android/client/bin/dexedLibs/gcm-9a0931d46c58ab74a433ccfc2b28f225.jar differ diff --git a/product/modules/agents/android/client/bin/dexedLibs/json-simple-1.1.1-b2941873388ec1326a64a93caf86e8ae.jar b/product/modules/agents/android/client/bin/dexedLibs/json-simple-1.1.1-b2941873388ec1326a64a93caf86e8ae.jar new file mode 100644 index 0000000000..b5452950ae Binary files /dev/null and b/product/modules/agents/android/client/bin/dexedLibs/json-simple-1.1.1-b2941873388ec1326a64a93caf86e8ae.jar differ diff --git a/product/modules/agents/android/client/bin/dexedLibs/library-33cf4968ac75ef373184aa60c48ed2e2.jar b/product/modules/agents/android/client/bin/dexedLibs/library-33cf4968ac75ef373184aa60c48ed2e2.jar new file mode 100644 index 0000000000..258787fe22 Binary files /dev/null and b/product/modules/agents/android/client/bin/dexedLibs/library-33cf4968ac75ef373184aa60c48ed2e2.jar differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-hdpi/ic_bookmark.png b/product/modules/agents/android/client/bin/res/crunch/drawable-hdpi/ic_bookmark.png new file mode 100644 index 0000000000..e39a023452 Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-hdpi/ic_bookmark.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-hdpi/ic_check_default.png b/product/modules/agents/android/client/bin/res/crunch/drawable-hdpi/ic_check_default.png new file mode 100644 index 0000000000..74c9a0d459 Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-hdpi/ic_check_default.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-hdpi/ic_check_selected.png b/product/modules/agents/android/client/bin/res/crunch/drawable-hdpi/ic_check_selected.png new file mode 100644 index 0000000000..5482cfb175 Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-hdpi/ic_check_selected.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-hdpi/ic_launcher.png b/product/modules/agents/android/client/bin/res/crunch/drawable-hdpi/ic_launcher.png new file mode 100644 index 0000000000..dc581a5c3a Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-hdpi/ic_launcher.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-hdpi/ic_logo.png b/product/modules/agents/android/client/bin/res/crunch/drawable-hdpi/ic_logo.png new file mode 100644 index 0000000000..731d461bd4 Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-hdpi/ic_logo.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-hdpi/ic_logo_dark.png b/product/modules/agents/android/client/bin/res/crunch/drawable-hdpi/ic_logo_dark.png new file mode 100644 index 0000000000..731d461bd4 Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-hdpi/ic_logo_dark.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-hdpi/ic_stat_gcm.png b/product/modules/agents/android/client/bin/res/crunch/drawable-hdpi/ic_stat_gcm.png new file mode 100644 index 0000000000..c031369cc7 Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-hdpi/ic_stat_gcm.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-hdpi/option_icon.png b/product/modules/agents/android/client/bin/res/crunch/drawable-hdpi/option_icon.png new file mode 100644 index 0000000000..c06067326a Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-hdpi/option_icon.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-hdpi/repeat_bg.png b/product/modules/agents/android/client/bin/res/crunch/drawable-hdpi/repeat_bg.png new file mode 100644 index 0000000000..70274e215f Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-hdpi/repeat_bg.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-hdpi/top_bar.png b/product/modules/agents/android/client/bin/res/crunch/drawable-hdpi/top_bar.png new file mode 100644 index 0000000000..79621a1269 Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-hdpi/top_bar.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-mdpi/ic_bookmark.png b/product/modules/agents/android/client/bin/res/crunch/drawable-mdpi/ic_bookmark.png new file mode 100644 index 0000000000..6f3192e8dd Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-mdpi/ic_bookmark.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-mdpi/ic_check_default.png b/product/modules/agents/android/client/bin/res/crunch/drawable-mdpi/ic_check_default.png new file mode 100644 index 0000000000..2e04208666 Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-mdpi/ic_check_default.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-mdpi/ic_check_selected.png b/product/modules/agents/android/client/bin/res/crunch/drawable-mdpi/ic_check_selected.png new file mode 100644 index 0000000000..51cc587f23 Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-mdpi/ic_check_selected.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-mdpi/ic_launcher.png b/product/modules/agents/android/client/bin/res/crunch/drawable-mdpi/ic_launcher.png new file mode 100644 index 0000000000..096b26b45f Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-mdpi/ic_launcher.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-mdpi/ic_logo.png b/product/modules/agents/android/client/bin/res/crunch/drawable-mdpi/ic_logo.png new file mode 100644 index 0000000000..846d41318a Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-mdpi/ic_logo.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-mdpi/ic_logo_dark.png b/product/modules/agents/android/client/bin/res/crunch/drawable-mdpi/ic_logo_dark.png new file mode 100644 index 0000000000..846d41318a Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-mdpi/ic_logo_dark.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-mdpi/option_icon.png b/product/modules/agents/android/client/bin/res/crunch/drawable-mdpi/option_icon.png new file mode 100644 index 0000000000..bbcd11bde0 Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-mdpi/option_icon.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-mdpi/top_bar.png b/product/modules/agents/android/client/bin/res/crunch/drawable-mdpi/top_bar.png new file mode 100644 index 0000000000..1a10ae8e0b Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-mdpi/top_bar.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/appinstall.png b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/appinstall.png new file mode 100644 index 0000000000..540a3132de Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/appinstall.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/applist.png b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/applist.png new file mode 100644 index 0000000000..639d648523 Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/applist.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/appuninstall.png b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/appuninstall.png new file mode 100644 index 0000000000..8f6ffef13e Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/appuninstall.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/camera.png b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/camera.png new file mode 100644 index 0000000000..a4900b9292 Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/camera.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/changepassword.png b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/changepassword.png new file mode 100644 index 0000000000..e1bde62f55 Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/changepassword.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/encrypt.png b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/encrypt.png new file mode 100644 index 0000000000..21c3c0ef86 Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/encrypt.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/ic_bookmark.png b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/ic_bookmark.png new file mode 100644 index 0000000000..f72001d8ec Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/ic_bookmark.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/ic_check_default.png b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/ic_check_default.png new file mode 100644 index 0000000000..aa466a928e Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/ic_check_default.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/ic_check_selected.png b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/ic_check_selected.png new file mode 100644 index 0000000000..3a7b7f9fad Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/ic_check_selected.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/ic_launcher.png b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/ic_launcher.png new file mode 100644 index 0000000000..39b9a8f217 Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/ic_launcher.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/ic_logo.png b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/ic_logo.png new file mode 100644 index 0000000000..380beb5a90 Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/ic_logo.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/ic_logo_dark.png b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/ic_logo_dark.png new file mode 100644 index 0000000000..380beb5a90 Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/ic_logo_dark.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/info.png b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/info.png new file mode 100644 index 0000000000..ec33699635 Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/info.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/location.png b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/location.png new file mode 100644 index 0000000000..7df708d9b6 Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/location.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/lock.png b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/lock.png new file mode 100644 index 0000000000..9537c9a8df Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/lock.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/mute.png b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/mute.png new file mode 100644 index 0000000000..94c0417e2a Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/mute.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/notification.png b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/notification.png new file mode 100644 index 0000000000..f41ba8bef0 Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/notification.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/repeat_bg.png b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/repeat_bg.png new file mode 100644 index 0000000000..5984849fbe Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/repeat_bg.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/wifi.png b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/wifi.png new file mode 100644 index 0000000000..217d097604 Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/wifi.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/wipe.png b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/wipe.png new file mode 100644 index 0000000000..e48edc69c2 Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-xhdpi/wipe.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-xxhdpi/ic_bookmark.png b/product/modules/agents/android/client/bin/res/crunch/drawable-xxhdpi/ic_bookmark.png new file mode 100644 index 0000000000..b3cc1456a1 Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-xxhdpi/ic_bookmark.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-xxhdpi/ic_check_default.png b/product/modules/agents/android/client/bin/res/crunch/drawable-xxhdpi/ic_check_default.png new file mode 100644 index 0000000000..6401f3a7a7 Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-xxhdpi/ic_check_default.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-xxhdpi/ic_check_selected.png b/product/modules/agents/android/client/bin/res/crunch/drawable-xxhdpi/ic_check_selected.png new file mode 100644 index 0000000000..6a07c92553 Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-xxhdpi/ic_check_selected.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-xxhdpi/ic_launcher.png b/product/modules/agents/android/client/bin/res/crunch/drawable-xxhdpi/ic_launcher.png new file mode 100644 index 0000000000..12fe35986b Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-xxhdpi/ic_launcher.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-xxhdpi/ic_logo.png b/product/modules/agents/android/client/bin/res/crunch/drawable-xxhdpi/ic_logo.png new file mode 100644 index 0000000000..0a305fefe7 Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-xxhdpi/ic_logo.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-xxhdpi/ic_logo_dark.png b/product/modules/agents/android/client/bin/res/crunch/drawable-xxhdpi/ic_logo_dark.png new file mode 100644 index 0000000000..0a305fefe7 Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-xxhdpi/ic_logo_dark.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable-xxhdpi/repeat_bg.png b/product/modules/agents/android/client/bin/res/crunch/drawable-xxhdpi/repeat_bg.png new file mode 100644 index 0000000000..4b43a1295f Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable-xxhdpi/repeat_bg.png differ diff --git a/product/modules/agents/android/client/bin/res/crunch/drawable/dot.png b/product/modules/agents/android/client/bin/res/crunch/drawable/dot.png new file mode 100644 index 0000000000..9b8761da4a Binary files /dev/null and b/product/modules/agents/android/client/bin/res/crunch/drawable/dot.png differ diff --git a/product/modules/agents/android/client/bin/resources.ap_ b/product/modules/agents/android/client/bin/resources.ap_ new file mode 100644 index 0000000000..3e13d80784 Binary files /dev/null and b/product/modules/agents/android/client/bin/resources.ap_ differ diff --git a/product/modules/agents/android/client/lint.xml b/product/modules/agents/android/client/lint.xml new file mode 100644 index 0000000000..ee0eead5bb --- /dev/null +++ b/product/modules/agents/android/client/lint.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/product/modules/agents/android/client/res/layout/activity_settings.xml b/product/modules/agents/android/client/res/layout/activity_settings.xml index 5a064438b5..465aa2cb7d 100644 --- a/product/modules/agents/android/client/res/layout/activity_settings.xml +++ b/product/modules/agents/android/client/res/layout/activity_settings.xml @@ -71,7 +71,7 @@ - - - - + \ No newline at end of file diff --git a/product/modules/agents/android/client/res/values/strings.xml b/product/modules/agents/android/client/res/values/strings.xml index 2f424b2201..bdb36b4edc 100644 --- a/product/modules/agents/android/client/res/values/strings.xml +++ b/product/modules/agents/android/client/res/values/strings.xml @@ -124,6 +124,7 @@ as your PIN code? You have set your domain to Your device is a + Device type device, are you sure you want to proceed ? are you sure you want to proceed ? You are trying to unregister from EMM. Are you sure you want to proceed ? @@ -150,8 +151,8 @@ IMSI: OS: Rooted: - Yes - No + Yes + No OK diff --git a/product/modules/agents/android/client/src/org/wso2/cdm/agent/AlertActivity.java b/product/modules/agents/android/client/src/org/wso2/cdm/agent/AlertActivity.java index f02dd9c0f8..2d49e4ec2c 100644 --- a/product/modules/agents/android/client/src/org/wso2/cdm/agent/AlertActivity.java +++ b/product/modules/agents/android/client/src/org/wso2/cdm/agent/AlertActivity.java @@ -1,18 +1,18 @@ -/* - ~ Copyright (c) 2014, WSO2 Inc. (http://wso2.com/) All Rights Reserved. - ~ - ~ Licensed under the Apache License, Version 2.0 (the "License"); - ~ you may not use this file except in compliance with the License. - ~ You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, software - ~ distributed under the License is distributed on an "AS IS" BASIS, - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - ~ See the License for the specific language governing permissions and - ~ limitations under the License. -*/ +/** + * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.wso2.cdm.agent; import android.os.Bundle; diff --git a/product/modules/agents/android/client/src/org/wso2/cdm/agent/AlreadyRegisteredActivity.java b/product/modules/agents/android/client/src/org/wso2/cdm/agent/AlreadyRegisteredActivity.java index ec30e8fe5c..7e53e0eafa 100644 --- a/product/modules/agents/android/client/src/org/wso2/cdm/agent/AlreadyRegisteredActivity.java +++ b/product/modules/agents/android/client/src/org/wso2/cdm/agent/AlreadyRegisteredActivity.java @@ -1,18 +1,18 @@ -/* - ~ Copyright (c) 2014, WSO2 Inc. (http://wso2.com/) All Rights Reserved. - ~ - ~ Licensed under the Apache License, Version 2.0 (the "License"); - ~ you may not use this file except in compliance with the License. - ~ You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, software - ~ distributed under the License is distributed on an "AS IS" BASIS, - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - ~ See the License for the specific language governing permissions and - ~ limitations under the License. -*/ +/** + * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.wso2.cdm.agent; import java.util.HashMap; @@ -176,8 +176,8 @@ public class AlreadyRegisteredActivity extends SherlockActivity implements APIRe AlertDialog.Builder builder = new AlertDialog.Builder( AlreadyRegisteredActivity.this); builder.setMessage(getResources().getString(R.string.dialog_unregister)) - .setNegativeButton(getResources().getString(R.string.info_label_rooted_answer_yes), dialogClickListener) - .setPositiveButton(getResources().getString(R.string.info_label_rooted_answer_no), dialogClickListener).show(); + .setNegativeButton(getResources().getString(R.string.yes), dialogClickListener) + .setPositiveButton(getResources().getString(R.string.no), dialogClickListener).show(); break; case TAG_BTN_OPTIONS: @@ -418,7 +418,6 @@ public class AlreadyRegisteredActivity extends SherlockActivity implements APIRe R.string.error_internal_server), getResources().getString(R.string.button_ok), null); - alertDialog.show(); } else { Log.e(TAG, "The result is : " + result); Log.e(TAG, "The responseStatus is : " + responseStatus); diff --git a/product/modules/agents/android/client/src/org/wso2/cdm/agent/AuthenticationActivity.java b/product/modules/agents/android/client/src/org/wso2/cdm/agent/AuthenticationActivity.java index 18a973ee91..6620526626 100644 --- a/product/modules/agents/android/client/src/org/wso2/cdm/agent/AuthenticationActivity.java +++ b/product/modules/agents/android/client/src/org/wso2/cdm/agent/AuthenticationActivity.java @@ -17,6 +17,7 @@ package org.wso2.cdm.agent; import java.util.HashMap; import java.util.Map; + import org.json.JSONException; import org.json.JSONObject; 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.CommonUtilities; import org.wso2.cdm.agent.utils.HTTPConnectorUtils; +import org.wso2.cdm.agent.utils.Preference; import org.wso2.cdm.agent.utils.ServerUtils; -import android.annotation.SuppressLint; -import android.app.Activity; + import android.app.AlarmManager; import android.app.AlertDialog; import android.app.Dialog; @@ -64,6 +65,9 @@ import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.MenuItem; import com.google.android.gcm.GCMRegistrar; +/** + * Activity that captures username, password and device ownership details + */ public class AuthenticationActivity extends SherlockActivity implements APIAccessCallBack, APIResultCallBack { @@ -73,19 +77,16 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces EditText username; EditText txtDomain; EditText password; - // TextView txtLoadingEULA; RadioButton radioBYOD, radioCOPE; String deviceType; Context context; - String isAgreed = ""; String senderId = ""; - String eula = ""; String usernameForRegister = ""; + String usernameVal; + String passwordVal; ProgressDialog progressDialog; AlertDialog.Builder alertDialog; - private final int TAG_BTN_AUTHENTICATE = 0; - @SuppressLint("NewApi") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -94,10 +95,11 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces getSupportActionBar().setCustomView(R.layout.custom_sherlock_bar); getSupportActionBar().setTitle(R.string.empty_app_title); View homeIcon = - findViewById(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB - ? android.R.id.home - : R.id.abs__home); - ((View) homeIcon.getParent()).setVisibility(View.GONE); + (View) findViewById( + Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB + ? android.R.id.home + : R.id.abs__home).getParent(); + homeIcon.setVisibility(View.GONE); context = AuthenticationActivity.this; deviceType = getResources().getString(R.string.device_enroll_type_byod); @@ -110,8 +112,8 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces txtDomain.requestFocus(); authenticate = (Button) findViewById(R.id.btnRegister); authenticate.setEnabled(false); - authenticate.setTag(TAG_BTN_AUTHENTICATE); authenticate.setOnClickListener(onClickAuthenticate); + // change button color background till user enters a valid input authenticate.setBackground(getResources().getDrawable(R.drawable.btn_grey)); authenticate.setTextColor(getResources().getColor(R.color.black)); @@ -155,19 +157,37 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces public void onClick(View view) { if (username.getText() != null && !username.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()) { deviceType = getResources().getString(R.string.device_enroll_type_byod); } else { deviceType = getResources().getString(R.string.device_enroll_type_cope); } - AlertDialog.Builder builder = new AlertDialog.Builder(AuthenticationActivity.this); - builder.setMessage(getResources().getString(R.string.dialog_init_middle) + " " + - deviceType + " " + - getResources().getString(R.string.dialog_init_end)) - .setNegativeButton(getResources().getString(R.string.info_label_rooted_answer_yes), - dialogClickListener) - .setPositiveButton(getResources().getString(R.string.info_label_rooted_answer_no), - dialogClickListener).show(); + alertDialog = + CommonDialogUtils.getAlertDialogWithTwoButtonAndTitle(context, + getResources().getString(R.string.dialog_init_device_type), + getResources().getString(R.string.dialog_init_middle) + + " " + + deviceType + + " " + + getResources().getString(R.string.dialog_init_end), + getResources().getString(R.string.yes), + + getResources().getString(R.string.no), + dialogClickListener, + dialogClickListener); + alertDialog.show(); } else { if (username.getText() != null && !username.getText().toString().trim().equals("")) { 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> mLicenseTask = + new AsyncTask>() { + + @Override + protected Map doInBackground(Void... params) { + Map response = + null; + + Map requestParametres = + new HashMap(); + + 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 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 requestParams = new HashMap(); + 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> mLicenseTask = + new AsyncTask>() { + + @Override + protected Map doInBackground(Void... params) { + Map response = + null; + response = + HTTPConnectorUtils.postData(context, + CommonUtilities.SERVER_URL + + CommonUtilities.LICENSE_ENDPOINT, + null); + return response; + } + + @Override + protected void onPreExecute() { + }; + + @Override + protected void onPostExecute(Map 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 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) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setMessage(message); @@ -199,7 +478,7 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces alert.show(); } - public void showAlert(String message, String title) { + public void showAgreement(String message, String title) { final Dialog dialog = new Dialog(context); dialog.setContentView(R.layout.custom_terms_popup); dialog.setTitle(CommonUtilities.EULA_TITLE); @@ -218,12 +497,8 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces dialogButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - 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_isagreed), "1"); - editor.commit(); + Preference.put(context, getResources().getString(R.string.shared_pref_isagreed), + "1"); dialog.dismiss(); loadPincodeAcitvity(); } @@ -253,6 +528,13 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces 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() { SharedPreferences mainPref = 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) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setMessage(message); @@ -333,166 +599,8 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces } /** - * Start Authentication. - */ - 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> mLicenseTask = - new AsyncTask>() { - - @Override - protected Map doInBackground(Void... params) { - Map 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 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. + * Initialize the Android IDP sdk by passing user credentials,client ID and + * client secret. */ private void initializeIDPLib(String clientKey, String clientSecret) { Log.e("", "initializeIDPLib"); @@ -523,7 +631,6 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces } } - @SuppressLint("NewApi") public void enableSubmitIfReady() { 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 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 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() { CommonDialogUtils.stopProgressDialog(progressDialog); alertDialog = @@ -726,7 +726,6 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces getResources().getString(R.string.error_enrollment_failed_detail), getResources().getString(R.string.button_ok), senderIdFailedClickListener); - alertDialog.show(); } 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 requestParams = new HashMap(); - 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 public void onAPIAccessRecive(String status) { 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.button_ok), dialogClickListener); - alertDialog.show(); } else if (status.trim().equals(CommonUtilities.INTERNAL_SERVER_ERROR)) { showInternalServerErrorMessage(); @@ -889,7 +812,6 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces getResources().getString(R.string.error_internal_server), getResources().getString(R.string.button_ok), 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.button_ok), 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 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(); + } + + } + } diff --git a/product/modules/agents/android/client/src/org/wso2/cdm/agent/AuthenticationErrorActivity.java b/product/modules/agents/android/client/src/org/wso2/cdm/agent/AuthenticationErrorActivity.java index 0b32a585a3..f5df4fc266 100644 --- a/product/modules/agents/android/client/src/org/wso2/cdm/agent/AuthenticationErrorActivity.java +++ b/product/modules/agents/android/client/src/org/wso2/cdm/agent/AuthenticationErrorActivity.java @@ -1,18 +1,18 @@ -/* - ~ Copyright (c) 2014, WSO2 Inc. (http://wso2.com/) All Rights Reserved. - ~ - ~ Licensed under the Apache License, Version 2.0 (the "License"); - ~ you may not use this file except in compliance with the License. - ~ You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, software - ~ distributed under the License is distributed on an "AS IS" BASIS, - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - ~ See the License for the specific language governing permissions and - ~ limitations under the License. -*/ +/** + * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.wso2.cdm.agent; import android.app.Activity; diff --git a/product/modules/agents/android/client/src/org/wso2/cdm/agent/DisplayDeviceInfoActivity.java b/product/modules/agents/android/client/src/org/wso2/cdm/agent/DisplayDeviceInfoActivity.java index f771d6507d..edc7a39ce8 100644 --- a/product/modules/agents/android/client/src/org/wso2/cdm/agent/DisplayDeviceInfoActivity.java +++ b/product/modules/agents/android/client/src/org/wso2/cdm/agent/DisplayDeviceInfoActivity.java @@ -1,18 +1,18 @@ -/* - ~ Copyright (c) 2014, WSO2 Inc. (http://wso2.com/) All Rights Reserved. - ~ - ~ Licensed under the Apache License, Version 2.0 (the "License"); - ~ you may not use this file except in compliance with the License. - ~ You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, software - ~ distributed under the License is distributed on an "AS IS" BASIS, - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - ~ See the License for the specific language governing permissions and - ~ limitations under the License. -*/ +/** + * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.wso2.cdm.agent; import org.json.JSONArray; @@ -78,7 +78,7 @@ public class DisplayDeviceInfoActivity extends Activity { sdk.setText(getResources().getString(R.string.info_label_imsi)+" "+operators); } 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(); if (extras != null) { diff --git a/product/modules/agents/android/client/src/org/wso2/cdm/agent/GCMIntentService.java b/product/modules/agents/android/client/src/org/wso2/cdm/agent/GCMIntentService.java index 451360b156..2cc95e2a72 100644 --- a/product/modules/agents/android/client/src/org/wso2/cdm/agent/GCMIntentService.java +++ b/product/modules/agents/android/client/src/org/wso2/cdm/agent/GCMIntentService.java @@ -1,18 +1,18 @@ -/* - ~ Copyright (c) 2014, WSO2 Inc. (http://wso2.com/) All Rights Reserved. - ~ - ~ Licensed under the Apache License, Version 2.0 (the "License"); - ~ you may not use this file except in compliance with the License. - ~ You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, software - ~ distributed under the License is distributed on an "AS IS" BASIS, - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - ~ See the License for the specific language governing permissions and - ~ limitations under the License. -*/ +/** + * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.wso2.cdm.agent; diff --git a/product/modules/agents/android/client/src/org/wso2/cdm/agent/LogActivity.java b/product/modules/agents/android/client/src/org/wso2/cdm/agent/LogActivity.java index d0963f25f6..9440fd4ca1 100644 --- a/product/modules/agents/android/client/src/org/wso2/cdm/agent/LogActivity.java +++ b/product/modules/agents/android/client/src/org/wso2/cdm/agent/LogActivity.java @@ -1,18 +1,18 @@ -/* - ~ Copyright (c) 2014, WSO2 Inc. (http://wso2.com/) All Rights Reserved. - ~ - ~ Licensed under the Apache License, Version 2.0 (the "License"); - ~ you may not use this file except in compliance with the License. - ~ You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, software - ~ distributed under the License is distributed on an "AS IS" BASIS, - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - ~ See the License for the specific language governing permissions and - ~ limitations under the License. -*/ +/** + * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.wso2.cdm.agent; import org.wso2.cdm.agent.R; diff --git a/product/modules/agents/android/client/src/org/wso2/cdm/agent/NotifyActivity.java b/product/modules/agents/android/client/src/org/wso2/cdm/agent/NotifyActivity.java index 514090bcc1..a723e836d8 100644 --- a/product/modules/agents/android/client/src/org/wso2/cdm/agent/NotifyActivity.java +++ b/product/modules/agents/android/client/src/org/wso2/cdm/agent/NotifyActivity.java @@ -1,18 +1,18 @@ -/* - ~ Copyright (c) 2014, WSO2 Inc. (http://wso2.com/) All Rights Reserved. - ~ - ~ Licensed under the Apache License, Version 2.0 (the "License"); - ~ you may not use this file except in compliance with the License. - ~ You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, software - ~ distributed under the License is distributed on an "AS IS" BASIS, - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - ~ See the License for the specific language governing permissions and - ~ limitations under the License. -*/ +/** + * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.wso2.cdm.agent; diff --git a/product/modules/agents/android/client/src/org/wso2/cdm/agent/PinCodeActivity.java b/product/modules/agents/android/client/src/org/wso2/cdm/agent/PinCodeActivity.java index ec2330ac75..6b9ec77ebf 100644 --- a/product/modules/agents/android/client/src/org/wso2/cdm/agent/PinCodeActivity.java +++ b/product/modules/agents/android/client/src/org/wso2/cdm/agent/PinCodeActivity.java @@ -1,18 +1,18 @@ -/* - ~ Copyright (c) 2014, WSO2 Inc. (http://wso2.com/) All Rights Reserved. - ~ - ~ Licensed under the Apache License, Version 2.0 (the "License"); - ~ you may not use this file except in compliance with the License. - ~ You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, software - ~ distributed under the License is distributed on an "AS IS" BASIS, - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - ~ See the License for the specific language governing permissions and - ~ limitations under the License. -*/ +/** + * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.wso2.cdm.agent; @@ -35,7 +35,9 @@ import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; + import org.wso2.cdm.agent.R; +import org.wso2.cdm.agent.utils.Preference; public class PinCodeActivity extends Activity { private TextView lblPin; @@ -47,13 +49,14 @@ public class PinCodeActivity extends Activity { private final int TAG_BTN_SET_PIN = 0; private String FROM_ACTIVITY = null; private String MAIN_ACTIVITY = null; + Context context; @SuppressLint("NewApi") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_pin_code); - + context=PinCodeActivity.this; Bundle extras = getIntent().getExtras(); if (extras != null) { 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); txtPin = (EditText) findViewById(R.id.txtPinCode); 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() { @Override @@ -177,8 +163,8 @@ public class PinCodeActivity extends Activity { getResources().getString(R.string.dialog_pin_confirmation) + " " +txtPin.getText().toString() + " " + getResources().getString(R.string.dialog_pin_confirmation_end)) - .setPositiveButton(getResources().getString(R.string.info_label_rooted_answer_yes), dialogClickListener) - .setNegativeButton(getResources().getString(R.string.info_label_rooted_answer_no), dialogClickListener).show(); + .setPositiveButton(getResources().getString(R.string.yes), dialogClickListener) + .setNegativeButton(getResources().getString(R.string.no), dialogClickListener).show(); break; default: break; @@ -203,12 +189,7 @@ public class PinCodeActivity extends Activity { }; public void savePin() { - - 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(); + Preference.put(context, getResources().getString(R.string.shared_pref_pin), txtPin.getText().toString().trim()); 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(); diff --git a/product/modules/agents/android/client/src/org/wso2/cdm/agent/RegistrationActivity.java b/product/modules/agents/android/client/src/org/wso2/cdm/agent/RegistrationActivity.java index 12c47286bf..4b005e1fcc 100644 --- a/product/modules/agents/android/client/src/org/wso2/cdm/agent/RegistrationActivity.java +++ b/product/modules/agents/android/client/src/org/wso2/cdm/agent/RegistrationActivity.java @@ -1,19 +1,20 @@ -/* - ~ Copyright (c) 2014, WSO2 Inc. (http://wso2.com/) All Rights Reserved. - ~ - ~ Licensed under the Apache License, Version 2.0 (the "License"); - ~ you may not use this file except in compliance with the License. - ~ You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, software - ~ distributed under the License is distributed on an "AS IS" BASIS, - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - ~ See the License for the specific language governing permissions and - ~ limitations under the License. -*/ +/** + * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.wso2.cdm.agent; + import java.util.HashMap; 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.PhoneState; 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.CommonUtilities; +import org.wso2.cdm.agent.utils.HTTPConnectorUtils; +import org.wso2.cdm.agent.utils.Preference; import org.wso2.cdm.agent.utils.ServerUtils; import android.app.Activity; import android.app.AlertDialog; import android.app.ProgressDialog; import android.app.admin.DevicePolicyManager; -import android.content.ComponentName; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; -import android.content.SharedPreferences.Editor; +import android.os.AsyncTask; import android.os.Bundle; import android.util.Log; import android.view.KeyEvent; import android.view.Menu; 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; public class RegistrationActivity extends Activity implements APIResultCallBack { - + private String TAG = RegistrationActivity.class.getSimpleName(); - - String regId = ""; - String username = ""; - TextView mDisplay; - Context context; - boolean regState = false; - boolean successFlag = false; - 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; - + String regId = ""; + String username = ""; + Context context; + boolean regState = false; + ProgressDialog progressDialog; + AlertDialog.Builder alertDialog; + + + @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(); - - - 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() { - progressDialog = CommonDialogUtils.showPrgressDialog( - RegistrationActivity.this, - getResources().getString(R.string.dialog_enrolling), - getResources().getString(R.string.dialog_please_wait), null); + progressDialog = + CommonDialogUtils.showPrgressDialog(RegistrationActivity.this, + getResources().getString(R.string.dialog_enrolling), + getResources().getString(R.string.dialog_please_wait), + null); progressDialog.show(); DeviceInfo deviceInfo = new DeviceInfo(RegistrationActivity.this); JSONObject jsObject = new JSONObject(); String osVersion = ""; - SharedPreferences mainPref = RegistrationActivity.this - .getSharedPreferences(RegistrationActivity.this.getResources() - .getString(R.string.shared_pref_package), - Context.MODE_PRIVATE); - String type = mainPref.getString(RegistrationActivity.this - .getResources().getString(R.string.shared_pref_reg_type), ""); + SharedPreferences mainPref = + RegistrationActivity.this.getSharedPreferences(RegistrationActivity.this.getResources() + .getString(R.string.shared_pref_package), + Context.MODE_PRIVATE); + String type = + mainPref.getString(RegistrationActivity.this.getResources() + .getString(R.string.shared_pref_reg_type), + ""); osVersion = deviceInfo.getOsVersion(); try { @@ -146,15 +107,15 @@ public class RegistrationActivity extends Activity implements APIResultCallBack // Check network connection availability before calling the API. if (PhoneState.isNetworkAvailable(context)) { // Call device registration API. - ServerUtils.callSecuredAPI(RegistrationActivity.this, - CommonUtilities.REGISTER_ENDPOINT, - CommonUtilities.POST_METHOD, requestParams, - RegistrationActivity.this, - CommonUtilities.REGISTER_REQUEST_CODE); + sendDeviceDetails(requestParams); +// ServerUtils.callSecuredAPI(RegistrationActivity.this, +// CommonUtilities.REGISTER_ENDPOINT, +// CommonUtilities.POST_METHOD, requestParams, +// RegistrationActivity.this, +// CommonUtilities.REGISTER_REQUEST_CODE); } else { CommonDialogUtils.stopProgressDialog(progressDialog); - CommonDialogUtils - .showNetworkUnavailableMessage(RegistrationActivity.this); + CommonDialogUtils.showNetworkUnavailableMessage(RegistrationActivity.this); } } catch (JSONException e) { @@ -163,38 +124,116 @@ public class RegistrationActivity extends Activity implements APIResultCallBack } - @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; + private void sendDeviceDetails(final Map requestParams) { + + AsyncTask> mLicenseTask = + new AsyncTask>() { + + @Override + protected Map doInBackground(Void... params) { + Map response; + response = + HTTPConnectorUtils.postData(context,CommonUtilities.SERVER_URL+CommonUtilities.REGISTER_ENDPOINT,requestParams + ); + return response; + } + + @Override + protected void onPreExecute() {}; + + @Override + protected void onPostExecute(Map result) { + CommonDialogUtils.stopProgressDialog(progressDialog); + manipulateDeviceDetails(result); + } + + }; + + mLicenseTask.execute(); + + } + + private void manipulateDeviceDetails(Map 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) { return super.onOptionsItemSelected(item); } - - DialogInterface.OnClickListener registrationFailedOKBtnClickListerner = new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface arg0, int arg1) { - loadAuthenticationErrorActivity(); - } - }; + + DialogInterface.OnClickListener registrationFailedOKBtnClickListerner = + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface arg0, + int arg1) { + loadAuthenticationErrorActivity(); + } + }; @Override public void onReceiveAPIResult(Map result, int requestCode) { @@ -202,69 +241,47 @@ public class RegistrationActivity extends Activity implements APIResultCallBack String responseStatus = ""; if (result != null) { responseStatus = result.get(CommonUtilities.STATUS_KEY); - - if (requestCode == CommonUtilities.REGISTER_REQUEST_CODE) { + 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); - //finish(); - } else if (responseStatus - .equals(CommonUtilities.INTERNAL_SERVER_ERROR)) { + 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); + // finish(); + } 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); + 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); alertDialog.show(); - } else { - Log.e(TAG, "The value of status is : " + responseStatus); + } 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 : " + 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(); - } + 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); + } + } 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 = + 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(); - + } } @@ -273,11 +290,11 @@ public class RegistrationActivity extends Activity implements APIResultCallBack * */ private void loadAuthenticationErrorActivity() { - Intent intent = new Intent(RegistrationActivity.this,AuthenticationErrorActivity.class); - intent.putExtra(getResources().getString(R.string.intent_extra_from_activity), RegistrationActivity.class.getSimpleName()); + Intent intent = new Intent(RegistrationActivity.this, AuthenticationErrorActivity.class); + intent.putExtra(getResources().getString(R.string.intent_extra_from_activity), + RegistrationActivity.class.getSimpleName()); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); - } + } - } diff --git a/product/modules/agents/android/client/src/org/wso2/cdm/agent/ServerDetails.java b/product/modules/agents/android/client/src/org/wso2/cdm/agent/ServerDetails.java index 54269e8e77..5643b791e9 100644 --- a/product/modules/agents/android/client/src/org/wso2/cdm/agent/ServerDetails.java +++ b/product/modules/agents/android/client/src/org/wso2/cdm/agent/ServerDetails.java @@ -15,18 +15,6 @@ */ 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.AlertDialog; import android.app.ProgressDialog; @@ -35,34 +23,38 @@ import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.util.Log; -import android.view.KeyEvent; -import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; 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; Button startRegistration; - String fromActivity; Context context; + DialogInterface.OnClickListener dialogClickListener; DeviceInfo info; - TextView incompatibleError; - String errorMessage = ""; + TextView severAddressLabel; String senderID = null; - boolean accessFlag = true; ProgressDialog progressDialog; String regId; AlertDialog.Builder alertDialog; boolean alreadyRegisteredActivityFlag = false; boolean authenticationActivityFlag = false; + private String TAG = ServerDetails.class.getSimpleName(); @Override protected void onCreate(Bundle savedInstanceState) { @@ -70,50 +62,39 @@ public class ServerDetails extends Activity implements APIResultCallBack, TokenC setContentView(R.layout.activity_settings); context = ServerDetails.this; info = new DeviceInfo(ServerDetails.this); - incompatibleError = (TextView) findViewById(R.id.incompatibleError); serverIP = (TextView) findViewById(R.id.etServerIP); + severAddressLabel = (TextView) findViewById(R.id.severAddressLabel); 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 - if (!info.isCompatible(context).getCode()) { - accessFlag = false; - incompatibleError.setText(errorMessage); + Responce compatibility = info.isCompatible(); + if (!compatibility.getCode()) { startRegistration.setVisibility(View.GONE); + severAddressLabel.setVisibility(View.GONE); serverIP.setVisibility(View.GONE); - incompatibleError.setVisibility(View.VISIBLE); - CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context, - errorMessage, - getResources().getString(R.string.error_authorization_failed), - getResources().getString(R.string.button_ok), - null); + alertDialog = + CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context.getApplicationContext(), + getResources().getString(R.string.error_authorization_failed), + getResources().getString(compatibility.getDescriptionResourceID()), + getResources().getString(R.string.button_ok), + onRootedClickListner); } else { startRegistration.setVisibility(View.VISIBLE); serverIP.setVisibility(View.VISIBLE); - incompatibleError.setVisibility(View.GONE); - String ipSaved = - Preference.get(context, + Preference.get(context.getApplicationContext(), 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) { serverIP.setText(ipSaved); CommonUtilities.setServerURL(ipSaved); - Intent intent = new Intent(ServerDetails.this, AuthenticationActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - startActivity(intent); + startAuthenticationActivity(); } else { serverIP.setText(CommonUtilities.SERVER_IP); } + // on click handler for start registration startRegistration.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { @@ -123,211 +104,246 @@ public class ServerDetails extends Activity implements APIResultCallBack, TokenC serverIP.getText().toString() + " " + 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) - .setNegativeButton(getResources().getString(R.string.info_label_rooted_answer_no), + .setNegativeButton(getResources().getString(R.string.no), dialogClickListener).show(); } }); - // String clientKey = - // Preference.get(context, - // getResources().getString(R.string.shared_pref_client_id)); - // String clientSecret = - // Preference.get(context, - // getResources().getString(R.string.shared_pref_client_secret)); - // if (!clientKey.equals("") && !clientSecret.equals("")) { - // CommonUtilities.CLIENT_ID = clientKey; - // CommonUtilities.CLIENT_SECRET = clientSecret; - // } - // - // 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(); - // } - } - } + dialogClickListener = new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + switch (which) { + case DialogInterface.BUTTON_POSITIVE: + if (!serverIP.getText().toString().trim().equals("")) { + CommonUtilities.setServerURL(serverIP.getText().toString().trim()); + Preference.put(context.getApplicationContext(), + getResources().getString(R.string.shared_pref_ip), + serverIP.getText().toString().trim()); + startAuthenticationActivity(); - DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - switch (which) { - case DialogInterface.BUTTON_POSITIVE: - if (!serverIP.getText().toString().trim().equals("")) { - 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 { + Toast.makeText(context.getApplicationContext(), + getResources().getString(R.string.toast_message_enter_server_address), + Toast.LENGTH_LONG).show(); + } + break; - } else { - Toast.makeText(context, - getResources().getString(R.string.toast_message_enter_server_address), - Toast.LENGTH_LONG).show(); + case DialogInterface.BUTTON_NEGATIVE: + dialog.dismiss(); + break; } - break; - - case DialogInterface.BUTTON_NEGATIVE: - dialog.dismiss(); - break; - } + } + }; } - }; - - @Override - public void onBackPressed() { - Intent i = new Intent(); - i.setAction(Intent.ACTION_MAIN); - i.addCategory(Intent.CATEGORY_HOME); - this.startActivity(i); - super.onBackPressed(); + Log.d(TAG, "Server details activity started"); } - @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; + DialogInterface.OnClickListener onRootedClickListner = new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + finish(); } - 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 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(); - } + private void startAuthenticationActivity() { + Intent intent = new Intent(ServerDetails.this, AuthenticationActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + startActivity(intent); } + /* + * (non-Javadoc) + * + * @see android.app.Activity#onDestroy() + */ @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); - } - } + protected void onDestroy() { + //Avoiding memory leaks by destroying context object + context = null; + super.onDestroy(); } - /** - * Checks whether device is registered or NOT. - */ - private void isRegistered() { - Log.e("isReg", "isReg"); - Map requestParams = new HashMap(); - 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); - } - - } + // Old API manager communication code. + // + // 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)); + // } + // } + // + // + // public class ServerDetails extends Activity implements APIResultCallBack, + // TokenCallBack { + // @Override + // 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 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 requestParams = new HashMap(); + // 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); + // } + // + // } } diff --git a/product/modules/agents/android/client/src/org/wso2/cdm/agent/api/DeviceInfo.java b/product/modules/agents/android/client/src/org/wso2/cdm/agent/api/DeviceInfo.java index 71fc201651..140474944a 100644 --- a/product/modules/agents/android/client/src/org/wso2/cdm/agent/api/DeviceInfo.java +++ b/product/modules/agents/android/client/src/org/wso2/cdm/agent/api/DeviceInfo.java @@ -23,7 +23,7 @@ import java.util.List; import org.json.JSONArray; import org.wso2.cdm.agent.R; 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.SharedPreferences; @@ -303,17 +303,17 @@ public class DeviceInfo { return amount; } - public Errors isCompatible(Context c) { + public Responce isCompatible() { if (!(getSdkVersion() >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) && isRooted()) { - return Errors.INCOMPATIBLE; + return Responce.INCOMPATIBLE; } else if (getSdkVersion() < android.os.Build.VERSION_CODES.FROYO) { - return Errors.INCOMPATIBLE; + return Responce.INCOMPATIBLE; } else if (isRooted()) { - return Errors.INCOMPATIBLE; + return Responce.INCOMPATIBLE; } - return Errors.COMPATIBLE; + return Responce.COMPATIBLE; } /* diff --git a/product/modules/agents/android/client/src/org/wso2/cdm/agent/utils/CommonDialogUtils.java b/product/modules/agents/android/client/src/org/wso2/cdm/agent/utils/CommonDialogUtils.java index 0f91db07bf..e6ec351079 100644 --- a/product/modules/agents/android/client/src/org/wso2/cdm/agent/utils/CommonDialogUtils.java +++ b/product/modules/agents/android/client/src/org/wso2/cdm/agent/utils/CommonDialogUtils.java @@ -1,18 +1,18 @@ -/* - ~ Copyright (c) 2014, WSO2 Inc. (http://wso2.com/) All Rights Reserved. - ~ - ~ Licensed under the Apache License, Version 2.0 (the "License"); - ~ you may not use this file except in compliance with the License. - ~ You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, software - ~ distributed under the License is distributed on an "AS IS" BASIS, - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - ~ See the License for the specific language governing permissions and - ~ limitations under the License. -*/ +/** + * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.wso2.cdm.agent.utils; import org.wso2.cdm.agent.R; @@ -124,7 +124,7 @@ public abstract class CommonDialogUtils { builder.setTitle(title); builder.setMessage(message) .setPositiveButton(positiveBtnLabel, positiveClickListener); - + builder.show(); return builder; } diff --git a/product/modules/agents/android/client/src/org/wso2/cdm/agent/utils/CommonUtilities.java b/product/modules/agents/android/client/src/org/wso2/cdm/agent/utils/CommonUtilities.java index 07a9d40a9b..2ec7def0d6 100644 --- a/product/modules/agents/android/client/src/org/wso2/cdm/agent/utils/CommonUtilities.java +++ b/product/modules/agents/android/client/src/org/wso2/cdm/agent/utils/CommonUtilities.java @@ -1,17 +1,17 @@ -/* - ~ Copyright (c) 2014, WSO2 Inc. (http://wso2.com/) All Rights Reserved. - ~ - ~ Licensed under the Apache License, Version 2.0 (the "License"); - ~ you may not use this file except in compliance with the License. - ~ You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, software - ~ distributed under the License is distributed on an "AS IS" BASIS, - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - ~ See the License for the specific language governing permissions and - ~ limitations under the License. +/** + * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.wso2.cdm.agent.utils; @@ -37,12 +37,14 @@ public class CommonUtilities { public static String SERVER_PROTOCOL = "http://"; 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 SENDER_ID_ENDPOINT = "devices/sender_id/"; 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 NOTIFICATION_ENDPOINT = "notifications/pendingOperations/"; @@ -82,8 +84,6 @@ public class CommonUtilities { public static void setServerURL(String serverIP) { SERVER_IP = serverIP; - /*SERVER_URL = SERVER_PROTOCOL + sERVER_URL + ":" + SERVER_PORT - + "/mdm/api/";*/ SERVER_URL = SERVER_PROTOCOL + serverIP + ":" + SERVER_PORT +SERVER_APP_ENDPOINT; diff --git a/product/modules/agents/android/client/src/org/wso2/cdm/agent/utils/HTTPConnectorUtils.java b/product/modules/agents/android/client/src/org/wso2/cdm/agent/utils/HTTPConnectorUtils.java index 4f182f4e43..3f8d5afdcd 100644 --- a/product/modules/agents/android/client/src/org/wso2/cdm/agent/utils/HTTPConnectorUtils.java +++ b/product/modules/agents/android/client/src/org/wso2/cdm/agent/utils/HTTPConnectorUtils.java @@ -24,7 +24,6 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; - import org.apache.http.HeaderElement; import org.apache.http.HttpEntity; 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.protocol.HTTP; import org.wso2.cdm.agent.R; - import android.content.Context; import android.content.SharedPreferences; import android.net.ParseException; @@ -56,39 +54,38 @@ public class HTTPConnectorUtils { private static final int MAX_ATTEMPTS = 2; - public static Map getClientKey(String username, String password, Context context) { - Map params = new HashMap(); - Map response = new HashMap(); - - params.put("username", username); - params.put("password", password); - - try { - response = - sendWithTimeWait("services/register/authenticate/device", params, "POST", - context); - } catch (Exception ex) { - ex.printStackTrace(); - return response; - } - return response; - } + // public static Map getClientKey(String username, String + // password, Context context) { + // Map params = new HashMap(); + // Map response = new HashMap(); + // + // params.put("username", username); + // params.put("password", password); + // + // try { + // response = + // postData("services/register/authenticate/device", params, + // context); + // } catch (Exception ex) { + // ex.printStackTrace(); + // return response; + // } + // return response; + // } - public static Map sendWithTimeWait(String epPostFix, - Map params, String option, - Context context) { + public static Map postData(Context context, String url, + Map params) { Map response = null; Map responseFinal = null; for (int i = 1; i <= MAX_ATTEMPTS; i++) { - Log.d(TAG, "Attempt #" + i + " to register"); + Log.d(TAG, "Attempt #" + i + " to register " + url); try { - response = postData(context, epPostFix, params); + response = postToServer(context, url, params); if (response != null && !response.equals(null)) { responseFinal = response; } - String message = context.getString(R.string.server_registered); - Log.v("Check Reg Success", message.toString()); + Log.d("Success", "Check Reg Success"); return responseFinal; } catch (Exception e) { @@ -100,49 +97,34 @@ public class HTTPConnectorUtils { return responseFinal; } } - String message = context.getString(R.string.server_register_error, MAX_ATTEMPTS); return responseFinal; } - public static Map postData(Context context, String url, - Map params) { + public static Map postToServer(Context context, String url, + Map params) { // Create a new HttpClient and Post Header Map response_params = new HashMap(); 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(); - Iterator> iterator = params.entrySet().iterator(); - // constructs the POST body using the parameters - while (iterator.hasNext()) { - Entry param = iterator.next(); - bodyBuilder.append(param.getKey()).append('=').append(param.getValue()); - if (iterator.hasNext()) { - bodyBuilder.append('&'); + if (params != null) { + Iterator> iterator = params.entrySet().iterator(); + // constructs the POST body using the parameters + while (iterator.hasNext()) { + Entry param = iterator.next(); + bodyBuilder.append(param.getKey()).append('=').append(param.getValue()); + if (iterator.hasNext()) { + bodyBuilder.append('&'); + } } } String body = bodyBuilder.toString(); - Log.v(TAG, "Posting '" + body + "' to " + endpoint); + Log.v(TAG, "Posting '" + body + "' to " + url); 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("Accept", "*/*"); httppost.setHeader("User-Agent", "Mozilla/5.0 ( compatible ), Android"); @@ -185,13 +167,12 @@ public class HTTPConnectorUtils { new ThreadSafeClientConnManager(params, schemeRegistry); client = new DefaultHttpClient(cm, params); } else { - Log.e("", "out"); client = new DefaultHttpClient(); } return client; } catch (Exception e) { - e.printStackTrace(); + return null; } } diff --git a/product/modules/agents/android/client/src/org/wso2/cdm/agent/utils/Preference.java b/product/modules/agents/android/client/src/org/wso2/cdm/agent/utils/Preference.java index 0eef47d605..4433c85a37 100644 --- a/product/modules/agents/android/client/src/org/wso2/cdm/agent/utils/Preference.java +++ b/product/modules/agents/android/client/src/org/wso2/cdm/agent/utils/Preference.java @@ -1,29 +1,46 @@ package org.wso2.cdm.agent.utils; -import org.wso2.cdm.agent.R; - import android.content.Context; import android.content.SharedPreferences; 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 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 = - c.getSharedPreferences(c.getResources() - .getString(R.string.shared_pref_package), - Context.MODE_PRIVATE); + context.getSharedPreferences(context.getResources() + .getString(R.string.shared_pref_package), + Context.MODE_PRIVATE + ); Editor editor = mainPref.edit(); editor.putString(key, value); 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 = - c.getSharedPreferences(c.getResources() - .getString(R.string.shared_pref_package), - Context.MODE_PRIVATE); + context.getSharedPreferences(context.getResources() + .getString(R.string.shared_pref_package), + Context.MODE_PRIVATE + ); return mainPref.getString(key, null); } diff --git a/product/modules/agents/android/client/src/org/wso2/cdm/agent/utils/Errors.java b/product/modules/agents/android/client/src/org/wso2/cdm/agent/utils/Responce.java similarity index 94% rename from product/modules/agents/android/client/src/org/wso2/cdm/agent/utils/Errors.java rename to product/modules/agents/android/client/src/org/wso2/cdm/agent/utils/Responce.java index c37a618857..7b390aa28d 100644 --- a/product/modules/agents/android/client/src/org/wso2/cdm/agent/utils/Errors.java +++ b/product/modules/agents/android/client/src/org/wso2/cdm/agent/utils/Responce.java @@ -21,7 +21,7 @@ import org.wso2.cdm.agent.R; * Describes the errors and their relevant error messages. * In order to internationalize the message is the res */ -public enum Errors { +public enum Responce { INCOMPATIBLE(false, R.string.device_not_compatible_error), INCOMPATIBLE_OS(false, 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 int descriptionResourceID; - private Errors(boolean code, int description) { + private Responce(boolean code, int description) { this.code = code; this.descriptionResourceID = description; } diff --git a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Device.java b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Device.java index abca85290d..4bf8c21685 100644 --- a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Device.java +++ b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Device.java @@ -16,33 +16,151 @@ package cdm.api.android; +import cdm.api.android.util.AndroidAPIUtils; +import com.google.gson.Gson; import com.google.gson.JsonObject; -import org.wso2.carbon.context.CarbonContext; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.core.service.DeviceManagementService; +import org.wso2.carbon.utils.multitenancy.MultitenantConstants; import javax.ws.rs.*; import javax.ws.rs.core.Response; +import java.util.List; /** * Android Device Management REST-API implementation. */ -@Path("/devices") public class Device { + private static Log log = LogFactory.getLog(Device.class); + @GET - public String getAllDevices() { - return "License Agreement"; + public Response getAllDevices() { + List result = null; + int status = 0; + String msg = ""; + DeviceManagementService dmService; + try { + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); + ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID); + dmService = (DeviceManagementService) ctx + .getOSGiService(DeviceManagementService.class, null); + } finally { + PrivilegedCarbonContext.endTenantFlow(); + } + try { + if(dmService!=null){ + result = dmService.getAllDevices(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + status = 1; + }else{ + status = -1; + msg = "Device Manager service not available"; + } + + } catch (DeviceManagementException e) { + msg = "Error occurred while fetching the device list"; + log.error(msg, e); + status = -1; + } + switch (status) { + case 1: + String response = new Gson().toJson(result); + return Response.status(200).entity(response).build(); + case -1: + return Response.status(500).entity(msg).build(); + } + return Response.status(400).entity("Unable to fetch device list").build(); } @GET @Path("{id}") - public String getDevice(@PathParam("id") String id) { - return "License Agreement"; + public Response getDevice(@PathParam("id") String id) { + int status = 0; + String msg = ""; + DeviceManagementService dmService; + org.wso2.carbon.device.mgt.common.Device device = new org.wso2.carbon.device.mgt.common.Device(); + try { + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); + ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID); + dmService = (DeviceManagementService) ctx + .getOSGiService(DeviceManagementService.class, null); + } finally { + PrivilegedCarbonContext.endTenantFlow(); + } + DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); + try { + if(dmService!=null){ + device = dmService.getDevice(deviceIdentifier); + status = 1; + }else{ + status = -1; + msg = "Device Manager service not available"; + } + + } catch (DeviceManagementException e) { + msg = "Error occurred while fetching the device information"; + log.error(msg, e); + status = -1; + } + switch (status) { + case 1: + String response = new Gson().toJson(device); + return Response.status(200).entity(response).build(); + case -1: + return Response.status(500).entity(msg).build(); + } + return Response.status(400).entity("Unable to fetch device information").build(); } @PUT @Path("{id}") - public Response updateDevice(@PathParam("id") String id) { - return Response.status(201).entity("Registration Successful").build(); + public Response updateDevice(@PathParam("id") String id, String jsonPayload) { + boolean result = false; + int status = 0; + String msg = ""; + DeviceManagementService dmService; + try { + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); + ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID); + dmService = (DeviceManagementService) ctx + .getOSGiService(DeviceManagementService.class, null); + } finally { + PrivilegedCarbonContext.endTenantFlow(); + } + org.wso2.carbon.device.mgt.common.Device device = AndroidAPIUtils.convertToDeviceObject(jsonPayload); + try { + if(dmService!=null){ + result = dmService.updateDeviceInfo(device); + status = 1; + }else{ + status = -1; + msg = "Device Manager service not available"; + } + } catch (DeviceManagementException e) { + msg = "Error occurred while modifying the device information"; + log.error(msg, e); + status = -1; + } + switch (status) { + case 1: + if (result) { + return Response.status(200).entity("Device has modified").build(); + } + break; + case -1: + return Response.status(500).entity(msg).build(); + } + return Response.status(400).entity("Update device has failed").build(); } } diff --git a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Enrollment.java b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Enrollment.java index 866bae0cf2..98501e3bdd 100644 --- a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Enrollment.java +++ b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Enrollment.java @@ -16,11 +16,9 @@ package cdm.api.android; -import cdm.api.android.util.AndroidAPIUtil; -import com.google.gson.JsonObject; +import cdm.api.android.util.AndroidAPIUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; @@ -34,13 +32,12 @@ import javax.ws.rs.core.Response; /** * Android Device Enrollment REST-API implementation. */ -@Path("/enrollment") public class Enrollment { private static Log log = LogFactory.getLog(Enrollment.class); @POST - public Response enrollDevice() { + public Response enrollDevice(String jsonPayload) { boolean result = false; int status = 0; String msg = ""; @@ -50,16 +47,21 @@ public class Enrollment { PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID); - dmService = (DeviceManagementService) ctx .getOSGiService(DeviceManagementService.class, null); } finally { PrivilegedCarbonContext.endTenantFlow(); } - Device device = AndroidAPIUtil.convertToDeviceObject(null); + Device device = AndroidAPIUtils.convertToDeviceObject(jsonPayload); try { - result = dmService.enrollDevice(device); - status = 1; + if(dmService!=null){ + result = dmService.enrollDevice(device); + status = 1; + }else{ + status = -1; + msg = "Device Manager service not available"; + } + } catch (DeviceManagementException e) { msg = "Error occurred while enrolling the device"; log.error(msg, e); @@ -83,13 +85,26 @@ public class Enrollment { boolean result = false; int status = 0; String msg = ""; - CarbonContext context = CarbonContext.getThreadLocalCarbonContext(); - DeviceManagementService dmService = (DeviceManagementService) context - .getOSGiService(DeviceManagementService.class, null); + DeviceManagementService dmService; + try { + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); + ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID); + dmService = (DeviceManagementService) ctx + .getOSGiService(DeviceManagementService.class, null); + } finally { + PrivilegedCarbonContext.endTenantFlow(); + } + DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); try { - DeviceIdentifier deviceIdentifier = AndroidAPIUtil.convertToDeviceIdentifierObject(id); - result = dmService.isEnrolled(deviceIdentifier); - status = 1; + if(dmService!=null){ + result = dmService.isEnrolled(deviceIdentifier); + status = 1; + }else{ + status = -1; + msg = "Device Manager service not available"; + } } catch (DeviceManagementException e) { msg = "Error occurred while checking enrollment of the device"; log.error(msg, e); @@ -108,19 +123,31 @@ public class Enrollment { } @PUT - @Consumes("application/json") @Path("{id}") - public Response modifyEnrollment(@PathParam("id") String id) { + public Response modifyEnrollment(@PathParam("id") String id,String jsonPayload) { boolean result = false; int status = 0; String msg = ""; - CarbonContext context = CarbonContext.getThreadLocalCarbonContext(); - DeviceManagementService dmService = (DeviceManagementService) context - .getOSGiService(DeviceManagementService.class, null); - Device device = AndroidAPIUtil.convertToDeviceObject(null); + DeviceManagementService dmService; try { - result = dmService.modifyEnrollment(device); - status = 1; + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); + ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID); + dmService = (DeviceManagementService) ctx + .getOSGiService(DeviceManagementService.class, null); + } finally { + PrivilegedCarbonContext.endTenantFlow(); + } + Device device = AndroidAPIUtils.convertToDeviceObject(jsonPayload); + try { + if(dmService!=null){ + result = dmService.modifyEnrollment(device); + status = 1; + }else{ + status = -1; + msg = "Device Manager service not available"; + } } catch (DeviceManagementException e) { msg = "Error occurred while modifying enrollment of the device"; log.error(msg, e); @@ -144,13 +171,26 @@ public class Enrollment { boolean result = false; int status = 0; String msg = ""; - CarbonContext context = CarbonContext.getThreadLocalCarbonContext(); - DeviceManagementService dmService = (DeviceManagementService) context - .getOSGiService(DeviceManagementService.class, null); + DeviceManagementService dmService; + try { + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); + ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID); + dmService = (DeviceManagementService) ctx + .getOSGiService(DeviceManagementService.class, null); + } finally { + PrivilegedCarbonContext.endTenantFlow(); + } + DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); try { - DeviceIdentifier deviceIdentifier = AndroidAPIUtil.convertToDeviceIdentifierObject(id); - result = dmService.disenrollDevice(deviceIdentifier); - status = 1; + if(dmService!=null){ + result = dmService.disenrollDevice(deviceIdentifier); + status = 1; + }else{ + status = -1; + msg = "Device Manager service not available"; + } } catch (DeviceManagementException e) { msg = "Error occurred while disenrolling the device"; log.error(msg, e); diff --git a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/util/AndroidAPIUtil.java b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/util/AndroidAPIUtil.java deleted file mode 100644 index 01c384de6d..0000000000 --- a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/util/AndroidAPIUtil.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cdm.api.android.util; - -import com.google.gson.JsonObject; -import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; - - -/** - * AndroidAPIUtil class provides utility function used by Android REST-API classes. - */ -public class AndroidAPIUtil { - - public static Device convertToDeviceObject(JsonObject json){ - Device device = new Device(); - device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); - device.setName("Test Device"); - device.setOwner("harshan"); - return device; - } - - public static DeviceIdentifier convertToDeviceIdentifierObject(String deviceId){ - DeviceIdentifier identifier = new DeviceIdentifier(); - identifier.setId(deviceId); - identifier.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); - return identifier; - } -} diff --git a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/util/AndroidAPIUtils.java b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/util/AndroidAPIUtils.java new file mode 100644 index 0000000000..94391d40ae --- /dev/null +++ b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/util/AndroidAPIUtils.java @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cdm.api.android.util; + +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import org.wso2.carbon.device.mgt.common.*; + +import java.util.*; + +/** + * AndroidAPIUtil class provides utility function used by Android REST-API classes. + */ +public class AndroidAPIUtils { + + public static Device convertToDeviceObject(String jsonString) { + JsonObject obj = new Gson().fromJson(jsonString, JsonObject.class); + Device device = new Device(); + device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + if (obj.get(AndroidConstants.DeviceConstants.DEVICE_MAC_KEY) != null) { + device.setDeviceIdentifier( + obj.get(AndroidConstants.DeviceConstants.DEVICE_MAC_KEY).getAsString()); + } + if (obj.get(AndroidConstants.DeviceConstants.DEVICE_DESCRIPTION_KEY) != null) { + device.setDescription( + obj.get(AndroidConstants.DeviceConstants.DEVICE_DESCRIPTION_KEY).getAsString()); + } + if (obj.get(AndroidConstants.DeviceConstants.DEVICE_OWNERSHIP_KEY) != null) { + device.setOwnership( + obj.get(AndroidConstants.DeviceConstants.DEVICE_OWNERSHIP_KEY).getAsString()); + } + + if (obj.get(AndroidConstants.DeviceConstants.DEVICE_PROPERTIES_KEY) != null) { + JsonObject properties = + new Gson().fromJson( + obj.get(AndroidConstants.DeviceConstants.DEVICE_PROPERTIES_KEY) + , JsonObject.class); + if (properties.get(AndroidConstants.DeviceProperties.PROPERTY_USER_KEY) != null) { + device.setOwner(properties.get(AndroidConstants.DeviceProperties.PROPERTY_USER_KEY) + .getAsString()); + } + if (properties.get(AndroidConstants.DeviceProperties.PROPERTY_DEVICE_KEY) != null) { + device.setName(properties.get(AndroidConstants.DeviceProperties.PROPERTY_DEVICE_KEY) + .getAsString()); + } + device.setProperties(parseProperties(properties)); + }else{ + device.setProperties(new ArrayList(0)); + } + + if (obj.get(AndroidConstants.DeviceConstants.DEVICE_FEATURES_KEY) != null) { + JsonObject features = + new Gson().fromJson( + obj.get(AndroidConstants.DeviceConstants.DEVICE_FEATURES_KEY), + JsonObject.class); + device.setFeatures(parseFeatures(features)); + }else{ + device.setFeatures(new ArrayList(0)); + } + return device; + } + + private static List parseProperties(JsonObject properties) { + List propertyList = new ArrayList(0); + for (Map.Entry entry : properties.entrySet()) { + propertyList.add(parseProperty(entry.getKey(), entry.getValue())); + } + // propertyList.add(parseProperty("regid", properties.get("regid").getAsString())); + // propertyList.add(parseProperty("osversion", properties.get("osversion").getAsString())); + // propertyList.add(parseProperty("vendor", properties.get("vendor").getAsString())); + // propertyList.add(parseProperty("imei", properties.get("imei").getAsString())); + // propertyList.add(parseProperty("imsi", properties.get("imsi").getAsString())); + // propertyList.add(parseProperty("model", properties.get("model").getAsString())); + return propertyList; + } + + private static List parseFeatures(JsonObject features) { + List featureList = new ArrayList(0); + return featureList; + } + + private static Property parseProperty(String property, JsonElement value) { + Property prop = new Property(); + prop.setName(property); + prop.setValue(value.getAsString()); + return prop; + } + + private static Feature parseFeature(JsonElement featureElement) { + Feature feature = new Feature(); + return feature; + } + + public static DeviceIdentifier convertToDeviceIdentifierObject(String deviceId) { + DeviceIdentifier identifier = new DeviceIdentifier(); + identifier.setId(deviceId); + identifier.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + return identifier; + } +} diff --git a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/util/AndroidConstants.java b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/util/AndroidConstants.java new file mode 100644 index 0000000000..b76820fc52 --- /dev/null +++ b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/util/AndroidConstants.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cdm.api.android.util; + +/** + * Defines constants used in Android-REST API bundle. + */ +public final class AndroidConstants { + + public final class DeviceProperties{ + private DeviceProperties() { + throw new AssertionError(); + } + public static final String PROPERTY_USER_KEY = "username"; + public static final String PROPERTY_DEVICE_KEY = "device"; + } + + public final class DeviceFeatures{ + private DeviceFeatures() { + throw new AssertionError(); + } + } + + public final class DeviceConstants{ + private DeviceConstants() { + throw new AssertionError(); + } + public static final String DEVICE_MAC_KEY = "mac"; + public static final String DEVICE_DESCRIPTION_KEY = "description"; + public static final String DEVICE_OWNERSHIP_KEY = "ownership"; + public static final String DEVICE_PROPERTIES_KEY = "properties"; + public static final String DEVICE_FEATURES_KEY = "features"; + } +} diff --git a/product/modules/agents/android/jax-rs/src/main/webapp/WEB-INF/cxf-servlet.xml b/product/modules/agents/android/jax-rs/src/main/webapp/WEB-INF/cxf-servlet.xml index 230a2b45e1..a75cad3590 100644 --- a/product/modules/agents/android/jax-rs/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/product/modules/agents/android/jax-rs/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -38,6 +38,7 @@ + diff --git a/product/modules/distribution/src/assembly/bin.xml b/product/modules/distribution/src/assembly/bin.xml index eee52239eb..6b06f312f5 100644 --- a/product/modules/distribution/src/assembly/bin.xml +++ b/product/modules/distribution/src/assembly/bin.xml @@ -153,7 +153,7 @@ **/api-manager.xml **/sso-idp-config.xml - **/emm-config.xml + @@ -170,6 +170,7 @@ wso2cdm-${project.version}/repository/conf/datasources **/master-datasources.xml + **/cdm-datasources.xml @@ -358,6 +359,16 @@ true 644 + + + + ../p2-profile-gen/target/wso2carbon-core-${carbon.kernel.version}/repository/conf/cdm-config.xml + ${pom.artifactId}-${pom.version}/repository/conf + true + 644 + + + ../p2-profile-gen/target/wso2carbon-core-${carbon.kernel.version}/repository/conf/tomcat/webapp-classloading-environments.xml ${pom.artifactId}-${pom.version}/repository/conf/tomcat diff --git a/product/modules/distribution/src/repository/conf/datasources/cdm-datasources.xml b/product/modules/distribution/src/repository/conf/datasources/cdm-datasources.xml new file mode 100755 index 0000000000..e24759f81b --- /dev/null +++ b/product/modules/distribution/src/repository/conf/datasources/cdm-datasources.xml @@ -0,0 +1,28 @@ + + + org.wso2.carbon.ndatasource.rdbms.RDBMSDataSourceReader + + + + + WSO2DEVICE_DB + The datasource used for EMM + + jdbc/WSO2DEVICE_DB + + + + jdbc:h2:repository/database/WSO2DEVICE_DB;DB_CLOSE_ON_EXIT=FALSE + wso2carbon + wso2carbon + org.h2.Driver + 50 + 60000 + true + SELECT 1 + 30000 + + + + + diff --git a/product/modules/distribution/src/repository/conf/datasources/master-datasources.xml b/product/modules/distribution/src/repository/conf/datasources/master-datasources.xml index a16e93a69c..da376108ce 100755 --- a/product/modules/distribution/src/repository/conf/datasources/master-datasources.xml +++ b/product/modules/distribution/src/repository/conf/datasources/master-datasources.xml @@ -4,26 +4,6 @@ - - WSO2DEVICE_DB - The datasource used for EMM - - jdbc/WSO2DEVICE_DB - - - - jdbc:h2:repository/database/WSO2DEVICE_DB;DB_CLOSE_ON_EXIT=FALSE - wso2carbon - wso2carbon - org.h2.Driver - 50 - 60000 - true - SELECT 1 - 30000 - - - WSO2_CARBON_DB The datasource used for registry and user manager diff --git a/product/modules/p2-profile-gen/pom.xml b/product/modules/p2-profile-gen/pom.xml index 97d4a18cdd..5418904a50 100644 --- a/product/modules/p2-profile-gen/pom.xml +++ b/product/modules/p2-profile-gen/pom.xml @@ -107,7 +107,7 @@ org.wso2.carbon:org.wso2.carbon.device.mgt.server.feature:${project.version} - + org.wso2.carbon:org.wso2.carbon.device.mgt.mobile.feature:${project.version} @@ -164,7 +164,7 @@ org.wso2.carbon.device.mgt.server.feature.group ${project.version} - + org.wso2.carbon.device.mgt.mobile.feature.group ${project.version}